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