This repository was archived by the owner on Jul 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
139 lines (121 loc) · 5.02 KB
/
Copy pathmakefile
File metadata and controls
139 lines (121 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
APP_NAME := ld_preload
SRC := .
SO_NAME := ld_preload.so
GOFMT_FILES := $(shell find . -name '*.go' -not -path './vendor/*')
C_FILES := $(shell find . \( -name '*.c' -o -name '*.h' \) -not -path './vendor/*')
GOLANGCI_LINT_VERSION := v2.4.0
STATICCHECK_VERSION := 2025.1.1
LEFTHOOK_VERSION := v1.12.4
GOBIN ?= $(or $(shell go env GOBIN),$(firstword $(subst :, ,$(shell go env GOPATH)))/bin)
GOLANGCI_LINT := $(GOBIN)/golangci-lint
STATICCHECK := $(GOBIN)/staticcheck
LEFTHOOK := $(GOBIN)/lefthook
SMOKE_IMAGE_BOOKWORM := golang:1.26-bookworm
SMOKE_IMAGE_BULLSEYE := golang:1.24-bullseye
SMOKE_TAG_BOOKWORM := ld_preload-smoke:bookworm
SMOKE_TAG_BULLSEYE := ld_preload-smoke:bullseye
.DEFAULT_GOAL := help
.PHONY: help
help:
@printf "Usage:\n"
@printf " make %-12s %s\n" "build" "Build the executable and shared object"
@printf " make %-12s %s\n" "fmt" "Format Go and C sources"
@printf " make %-12s %s\n" "fmt-check" "Verify formatting without changing files"
@printf " make %-12s %s\n" "lint" "Run Go linters and tests"
@printf " make %-12s %s\n" "lint-fix" "Apply supported auto-fixes"
@printf " make %-12s %s\n" "docker-smoke" "Run Linux LD_PRELOAD smoke tests in both Docker images"
@printf " make %-12s %s\n" "docker-audit" "Run syscall-audit workloads in both Docker images"
@printf " make %-12s %s\n" "docker-smoke-bookworm" "Run smoke tests in Debian bookworm"
@printf " make %-12s %s\n" "docker-audit-bookworm" "Run audit workloads in Debian bookworm"
@printf " make %-12s %s\n" "docker-smoke-bullseye" "Run smoke tests in Debian bullseye"
@printf " make %-12s %s\n" "docker-audit-bullseye" "Run audit workloads in Debian bullseye"
@printf " make %-12s %s\n" "hooks" "Install local git hooks with lefthook"
@printf " make %-12s %s\n" "tools" "Install Go-based developer tools"
@printf " make %-12s %s\n" "clean" "Remove build artifacts"
.PHONY: all
all: build
.PHONY: build
build:
go build -o $(APP_NAME) $(SRC)
@if [ "$$(uname -s)" = "Linux" ]; then \
go build -o $(SO_NAME) -buildmode=c-shared $(SRC); \
else \
printf '%s\n' 'Skipping shared object build on non-Linux host.'; \
fi
.PHONY: run
run: build
./$(APP_NAME)
.PHONY: tools
tools:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
go install github.com/evilmartians/lefthook@$(LEFTHOOK_VERSION)
.PHONY: hooks
hooks:
$(LEFTHOOK) install
.PHONY: fmt
fmt:
gofmt -w $(GOFMT_FILES)
@if command -v clang-format >/dev/null 2>&1; then \
clang-format -i $(C_FILES); \
else \
printf '%s\n' 'clang-format not found; Go files formatted, C files skipped.'; \
fi
.PHONY: fmt-check
fmt-check:
@test -z "$$(gofmt -l $(GOFMT_FILES))" || \
(printf '%s\n' 'Go files need formatting:'; gofmt -l $(GOFMT_FILES); exit 1)
@if command -v clang-format >/dev/null 2>&1; then \
tmpdir=$$(mktemp -d); \
failed=0; \
for file in $(C_FILES); do \
out="$$tmpdir/$$(basename "$$file")"; \
clang-format "$$file" > "$$out"; \
if ! cmp -s "$$file" "$$out"; then \
printf '%s\n' "$$file"; \
failed=1; \
fi; \
done; \
rm -rf "$$tmpdir"; \
test $$failed -eq 0 || (printf '%s\n' 'C files need formatting.'; exit 1); \
else \
printf '%s\n' 'clang-format not found; skipping C format check.'; \
fi
.PHONY: lint
lint:
$(GOLANGCI_LINT) run
$(STATICCHECK) ./...
go test ./...
.PHONY: lint-fix
lint-fix:
$(GOLANGCI_LINT) run --fix
$(MAKE) fmt
.PHONY: docker-smoke
docker-smoke: docker-smoke-bookworm docker-smoke-bullseye
.PHONY: docker-audit
docker-audit: docker-audit-bookworm docker-audit-bullseye
.PHONY: docker-smoke-bookworm
docker-smoke-bookworm:
chmod +x smoke/run.sh
docker build --build-arg GO_BASE_IMAGE=$(SMOKE_IMAGE_BOOKWORM) -f Dockerfile.smoke -t $(SMOKE_TAG_BOOKWORM) .
mkdir -p smoke-artifacts/bookworm
docker run --rm -e SMOKE_SUITE=bookworm -v "$(CURDIR)/smoke-artifacts:/workspace/smoke-artifacts" $(SMOKE_TAG_BOOKWORM)
.PHONY: docker-audit-bookworm
docker-audit-bookworm:
docker build --build-arg GO_BASE_IMAGE=$(SMOKE_IMAGE_BOOKWORM) -f Dockerfile.smoke -t $(SMOKE_TAG_BOOKWORM) .
mkdir -p smoke-artifacts/audit-bookworm
docker run --rm -e AUDIT_SUITE=bookworm -v "$(CURDIR)/smoke-artifacts:/workspace/smoke-artifacts" $(SMOKE_TAG_BOOKWORM) sh -lc 'sh /workspace/smoke/audit_workloads.sh'
.PHONY: docker-smoke-bullseye
docker-smoke-bullseye:
chmod +x smoke/run.sh
docker build --build-arg GO_BASE_IMAGE=$(SMOKE_IMAGE_BULLSEYE) -f Dockerfile.smoke -t $(SMOKE_TAG_BULLSEYE) .
mkdir -p smoke-artifacts/bullseye
docker run --rm -e SMOKE_SUITE=bullseye -v "$(CURDIR)/smoke-artifacts:/workspace/smoke-artifacts" $(SMOKE_TAG_BULLSEYE)
.PHONY: docker-audit-bullseye
docker-audit-bullseye:
docker build --build-arg GO_BASE_IMAGE=$(SMOKE_IMAGE_BULLSEYE) -f Dockerfile.smoke -t $(SMOKE_TAG_BULLSEYE) .
mkdir -p smoke-artifacts/audit-bullseye
docker run --rm -e AUDIT_SUITE=bullseye -v "$(CURDIR)/smoke-artifacts:/workspace/smoke-artifacts" $(SMOKE_TAG_BULLSEYE) sh -lc 'sh /workspace/smoke/audit_workloads.sh'
.PHONY: clean
clean:
rm -f $(APP_NAME) $(SO_NAME) ld_preload.h