github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/Makefile (about)

     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-17
     5  STRIP ?= llvm-strip-17
     6  OBJCOPY ?= llvm-objcopy-17
     7  CFLAGS := -O2 -g -Wall -Werror $(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  UIDGID := $(shell stat -c '%u:%g' ${REPODIR})
    15  
    16  # Prefer podman if installed, otherwise use docker.
    17  # Note: Setting the var at runtime will always override.
    18  CONTAINER_ENGINE ?= $(if $(shell command -v podman), podman, docker)
    19  CONTAINER_RUN_ARGS ?= $(if $(filter ${CONTAINER_ENGINE}, podman), --log-driver=none, --user "${UIDGID}")
    20  
    21  IMAGE := $(shell cat ${REPODIR}/testdata/docker/IMAGE)
    22  VERSION := $(shell cat ${REPODIR}/testdata/docker/VERSION)
    23  
    24  TARGETS := \
    25  	testdata/loader-clang-11 \
    26  	testdata/loader-clang-14 \
    27  	testdata/loader-$(CLANG) \
    28  	testdata/manyprogs \
    29  	testdata/btf_map_init \
    30  	testdata/invalid_map \
    31  	testdata/raw_tracepoint \
    32  	testdata/invalid_map_static \
    33  	testdata/invalid_btf_map_init \
    34  	testdata/strings \
    35  	testdata/freplace \
    36  	testdata/fentry_fexit \
    37  	testdata/iproute2_map_compat \
    38  	testdata/map_spin_lock \
    39  	testdata/subprog_reloc \
    40  	testdata/fwd_decl \
    41  	testdata/kconfig \
    42  	testdata/kconfig_config \
    43  	testdata/kfunc \
    44  	testdata/invalid-kfunc \
    45  	testdata/kfunc-kmod \
    46  	testdata/constants \
    47  	testdata/errors \
    48  	btf/testdata/relocs \
    49  	btf/testdata/relocs_read \
    50  	btf/testdata/relocs_read_tgt \
    51  	btf/testdata/relocs_enum \
    52  	cmd/bpf2go/testdata/minimal
    53  
    54  .PHONY: all clean container-all container-shell generate
    55  
    56  .DEFAULT_TARGET = container-all
    57  
    58  # Build all ELF binaries using a containerized LLVM toolchain.
    59  container-all:
    60  	+${CONTAINER_ENGINE} run --rm -t ${CONTAINER_RUN_ARGS} \
    61  		-v "${REPODIR}":/ebpf -w /ebpf --env MAKEFLAGS \
    62  		--env HOME="/tmp" \
    63  		--env BPF2GO_CC="$(CLANG)" \
    64  		--env BPF2GO_FLAGS="-fdebug-prefix-map=/ebpf=. $(CFLAGS)" \
    65  		"${IMAGE}:${VERSION}" \
    66  		make all
    67  
    68  # (debug) Drop the user into a shell inside the container as root.
    69  # Set BPF2GO_ envs to make 'make generate' just work.
    70  container-shell:
    71  	${CONTAINER_ENGINE} run --rm -ti \
    72  		-v "${REPODIR}":/ebpf -w /ebpf \
    73  		--env BPF2GO_CC="$(CLANG)" \
    74  		--env BPF2GO_FLAGS="-fdebug-prefix-map=/ebpf=. $(CFLAGS)" \
    75  		"${IMAGE}:${VERSION}"
    76  
    77  clean:
    78  	find "$(CURDIR)" -name "*.elf" -delete
    79  	find "$(CURDIR)" -name "*.o" -delete
    80  
    81  format:
    82  	find . -type f -name "*.c" | xargs clang-format -i
    83  
    84  all: format $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) generate
    85  	ln -srf testdata/loader-$(CLANG)-el.elf testdata/loader-el.elf
    86  	ln -srf testdata/loader-$(CLANG)-eb.elf testdata/loader-eb.elf
    87  
    88  generate:
    89  	go generate -run "internal/cmd/gentypes" ./...
    90  	go generate -skip "internal/cmd/gentypes" ./...
    91  
    92  testdata/loader-%-el.elf: testdata/loader.c
    93  	$* $(CFLAGS) -target bpfel -c $< -o $@
    94  	$(STRIP) -g $@
    95  
    96  testdata/loader-%-eb.elf: testdata/loader.c
    97  	$* $(CFLAGS) -target bpfeb -c $< -o $@
    98  	$(STRIP) -g $@
    99  
   100  %-el.elf: %.c
   101  	$(CLANG) $(CFLAGS) -target bpfel -c $< -o $@
   102  	$(STRIP) -g $@
   103  
   104  %-eb.elf : %.c
   105  	$(CLANG) $(CFLAGS) -target bpfeb -c $< -o $@
   106  	$(STRIP) -g $@
   107  
   108  .PHONY: update-kernel-deps
   109  update-kernel-deps: export KERNEL_VERSION?=6.8
   110  update-kernel-deps:
   111  	./testdata/sh/update-kernel-deps.sh
   112  	$(MAKE) container-all