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