1# SPDX-License-Identifier: GPL-2.0 2 3LIBDIR := ../../../lib 4BPFDIR := $(LIBDIR)/bpf 5APIDIR := ../../../include/uapi 6GENDIR := ../../../../include/generated 7GENHDR := $(GENDIR)/autoconf.h 8 9ifneq ($(wildcard $(GENHDR)),) 10 GENFLAGS := -DHAVE_GENHDR 11endif 12 13CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include 14LDLIBS += -lcap -lelf -lrt 15 16TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 17 test_align test_verifier_log test_dev_cgroup 18 19TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ 20 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ 21 sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ 22 test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o 23 24TEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh \ 25 test_offload.py 26 27include ../lib.mk 28 29BPFOBJ := $(OUTPUT)/libbpf.a $(OUTPUT)/cgroup_helpers.c 30 31$(TEST_GEN_PROGS): $(BPFOBJ) 32 33.PHONY: force 34 35# force a rebuild of BPFOBJ when its dependencies are updated 36force: 37 38$(BPFOBJ): force 39 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ 40 41CLANG ?= clang 42LLC ?= llc 43 44PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) 45 46# Let newer LLVM versions transparently probe the kernel for availability 47# of full BPF instruction set. 48ifeq ($(PROBE),) 49 CPU ?= probe 50else 51 CPU ?= generic 52endif 53 54CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \ 55 -Wno-compare-distinct-pointer-types 56 57$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline 58$(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline 59 60%.o: %.c 61 $(CLANG) $(CLANG_FLAGS) \ 62 -O2 -target bpf -emit-llvm -c $< -o - | \ 63 $(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@ 64