| 1 |
# The development version of clang is distributed as the 'clang' binary, |
| 2 |
# while stable/released versions have a version number attached. |
| 3 |
# Pin the default clang to a stable version. |
| 4 |
CLANG ?= clang-20 |
| 5 |
STRIP ?= llvm-strip-20 |
| 6 |
OBJCOPY ?= llvm-objcopy-20 |
| 7 |
CFLAGS := -O2 -g -Wall -Werror -mcpu=v2 $(CFLAGS) |
| 8 |
|
| 9 |
CI_KERNEL_URL ?= https://github.com/cilium/ci-kernels/raw/master/ |
| 10 |
|
| 11 |
# Obtain an absolute path to the directory of the Makefile. |
| 12 |
# Assume the Makefile is in the root of the repository. |
| 13 |
REPODIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) |
| 14 |
|
| 15 |
# Prefer podman if installed, otherwise use docker. |
| 16 |
# Note: Setting the var at runtime will always override. |
| 17 |
CONTAINER_ENGINE ?= $(if $(shell command -v podman),podman,docker) |
| 18 |
|
| 19 |
# Configure container runtime arguments based on the container engine. |
| 20 |
CONTAINER_RUN_ARGS := \ |
| 21 |
--env MAKEFLAGS \ |
| 22 |
--env BPF2GO_CC="$(CLANG)" \ |
| 23 |
--env BPF2GO_CFLAGS="$(CFLAGS)" \ |
| 24 |
--env HOME=/tmp \ |
| 25 |
-v "${REPODIR}":/ebpf -w /ebpf \ |
| 26 |
-v "$(shell go env GOCACHE)":/tmp/.cache/go-build \ |
| 27 |
-v "$(shell go env GOPATH)":/go \ |
| 28 |
-v "$(shell go env GOMODCACHE)":/go/pkg/mod |
| 29 |
|
| 30 |
ifeq ($(CONTAINER_ENGINE), podman) |
| 31 |
CONTAINER_RUN_ARGS += --log-driver=none --security-opt label=disable |
| 32 |
else |
| 33 |
CONTAINER_RUN_ARGS += --user "$(shell stat -c '%u:%g' ${REPODIR})" |
| 34 |
endif |
| 35 |
|
| 36 |
IMAGE := $(shell cat ${REPODIR}/testdata/docker/IMAGE) |
| 37 |
VERSION := $(shell cat ${REPODIR}/testdata/docker/VERSION) |
| 38 |
|
| 39 |
TARGETS_EL := \ |
| 40 |
testdata/linked1 \ |
| 41 |
testdata/linked2 \ |
| 42 |
testdata/linked |
| 43 |
|
| 44 |
TARGETS := \ |
| 45 |
testdata/loader-clang-14 \ |
| 46 |
testdata/loader-clang-17 \ |
| 47 |
testdata/loader-$(CLANG) \ |
| 48 |
testdata/loader_nobtf \ |
| 49 |
testdata/manyprogs \ |
| 50 |
testdata/btf_map_init \ |
| 51 |
testdata/invalid_map \ |
| 52 |
testdata/raw_tracepoint \ |
| 53 |
testdata/invalid_map_static \ |
| 54 |
testdata/invalid_btf_map_init \ |
| 55 |
testdata/strings \ |
| 56 |
testdata/freplace \ |
| 57 |
testdata/fentry_fexit \ |
| 58 |
testdata/iproute2_map_compat \ |
| 59 |
testdata/map_spin_lock \ |
| 60 |
testdata/subprog_reloc \ |
| 61 |
testdata/fwd_decl \ |
| 62 |
testdata/kconfig \ |
| 63 |
testdata/ksym \ |
| 64 |
testdata/kfunc \ |
| 65 |
testdata/invalid-kfunc \ |
| 66 |
testdata/kfunc-kmod \ |
| 67 |
testdata/constants \ |
| 68 |
testdata/errors \ |
| 69 |
testdata/variables \ |
| 70 |
testdata/arena \ |
| 71 |
testdata/struct_ops \ |
| 72 |
btf/testdata/relocs \ |
| 73 |
btf/testdata/relocs_read \ |
| 74 |
btf/testdata/relocs_read_tgt \ |
| 75 |
btf/testdata/relocs_enum \ |
| 76 |
btf/testdata/tags \ |
| 77 |
cmd/bpf2go/testdata/minimal |
| 78 |
|
| 79 |
HEADERS := $(wildcard testdata/*.h) |
| 80 |
|
| 81 |
.PHONY: all clean container-all container-shell generate |
| 82 |
|
| 83 |
.DEFAULT_TARGET = container-all |
| 84 |
|
| 85 |
# Build all ELF binaries using a containerized LLVM toolchain. |
| 86 |
container-all: |
| 87 |
+${CONTAINER_ENGINE} run --rm -ti ${CONTAINER_RUN_ARGS} \ |
| 88 |
"${IMAGE}:${VERSION}" \ |
| 89 |
$(MAKE) all |
| 90 |
|
| 91 |
# (debug) Drop the user into a shell inside the container as root. |
| 92 |
# Set BPF2GO_ envs to make 'make generate' just work. |
| 93 |
container-shell: |
| 94 |
${CONTAINER_ENGINE} run --rm -ti ${CONTAINER_RUN_ARGS} \ |
| 95 |
"${IMAGE}:${VERSION}" |
| 96 |
|
| 97 |
clean: |
| 98 |
find "$(CURDIR)" -name "*.elf" -delete |
| 99 |
find "$(CURDIR)" -name "*.o" -delete |
| 100 |
|
| 101 |
format: |
| 102 |
find . -type f -name "*.c" | xargs clang-format -i |
| 103 |
|
| 104 |
all: format testdata update-external-deps |
| 105 |
ln -srf testdata/loader-$(CLANG)-el.elf testdata/loader-el.elf |
| 106 |
ln -srf testdata/loader-$(CLANG)-eb.elf testdata/loader-eb.elf |
| 107 |
$(MAKE) generate |
| 108 |
|
| 109 |
generate: |
| 110 |
go generate -run "stringer" ./... |
| 111 |
go generate -run "gentypes" ./... |
| 112 |
go generate -skip "(gentypes|stringer)" ./... |
| 113 |
|
| 114 |
testdata: $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) $(addsuffix -el.elf,$(TARGETS_EL)) |
| 115 |
|
| 116 |
testdata/loader-%-el.elf: testdata/loader.c $(HEADERS) |
| 117 |
$* $(CFLAGS) -target bpfel -c $< -o $@ |
| 118 |
$(STRIP) -g $@ |
| 119 |
|
| 120 |
testdata/loader-%-eb.elf: testdata/loader.c $(HEADERS) |
| 121 |
$* $(CFLAGS) -target bpfeb -c $< -o $@ |
| 122 |
$(STRIP) -g $@ |
| 123 |
|
| 124 |
testdata/loader_nobtf-el.elf: testdata/loader.c $(HEADERS) |
| 125 |
$(CLANG) $(CFLAGS) -g0 -D__NOBTF__ -target bpfel -c $< -o $@ |
| 126 |
|
| 127 |
testdata/loader_nobtf-eb.elf: testdata/loader.c $(HEADERS) |
| 128 |
$(CLANG) $(CFLAGS) -g0 -D__NOBTF__ -target bpfeb -c $< -o $@ |
| 129 |
|
| 130 |
%-el.elf: %.c $(HEADERS) |
| 131 |
$(CLANG) $(CFLAGS) -target bpfel -c $< -o $@ |
| 132 |
$(STRIP) -g $@ |
| 133 |
|
| 134 |
%-eb.elf: %.c $(HEADERS) |
| 135 |
$(CLANG) $(CFLAGS) -target bpfeb -c $< -o $@ |
| 136 |
$(STRIP) -g $@ |
| 137 |
|
| 138 |
testdata/linked-el.elf: testdata/linked1-el.elf testdata/linked2-el.elf |
| 139 |
bpftool gen object $@ $^ |
| 140 |
|
| 141 |
.PHONY: update-external-deps |
| 142 |
update-external-deps: |
| 143 |
./scripts/update-kernel-deps.sh |
| 144 |
./scripts/update-efw-deps.sh |