xref: /linux/tools/testing/selftests/bpf/Makefile (revision 7fedbb7c5a7c4bda418bc1056c06c81db36e4299)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2618e165bSHendrik Brueckner
3d498f871SMickaël SalaünLIBDIR := ../../../lib
4e8f1f34aSZi Shen LimBPFDIR := $(LIBDIR)/bpf
502ea80b1SDaniel BorkmannAPIDIR := ../../../include/uapi
602ea80b1SDaniel BorkmannGENDIR := ../../../../include/generated
702ea80b1SDaniel BorkmannGENHDR := $(GENDIR)/autoconf.h
8d498f871SMickaël Salaün
902ea80b1SDaniel Borkmannifneq ($(wildcard $(GENHDR)),)
1002ea80b1SDaniel Borkmann  GENFLAGS := -DHAVE_GENHDR
1102ea80b1SDaniel Borkmannendif
1202ea80b1SDaniel Borkmann
13720f228eSDaniel BorkmannCFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
1419c832edSDavid MillerLDLIBS += -lcap -lelf -lrt
155aa5bd14SDaniel Borkmann
1618b3ad90SDavid S. MillerTEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
1737f1ba09SRoman Gushchin	test_align test_verifier_log test_dev_cgroup
186882804cSAlexei Starovoitov
1918f3d6beSYonghong SongTEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
2022c88526SDaniel Borkmann	test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o     \
213bc35c63SAlexei Starovoitov	sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \
22*7fedbb7cSJakub Kicinski	test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \
23*7fedbb7cSJakub Kicinski	sample_map_ret0.o
245aa5bd14SDaniel Borkmann
25417ec264SJakub KicinskiTEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh \
26417ec264SJakub Kicinski	test_offload.py
275aa5bd14SDaniel Borkmann
28e8f1f34aSZi Shen Liminclude ../lib.mk
291da8ac7cSAlexei Starovoitov
309d1f1594SRoman GushchinBPFOBJ := $(OUTPUT)/libbpf.a $(OUTPUT)/cgroup_helpers.c
31e8f1f34aSZi Shen Lim
32e8f1f34aSZi Shen Lim$(TEST_GEN_PROGS): $(BPFOBJ)
33e8f1f34aSZi Shen Lim
34e8f1f34aSZi Shen Lim.PHONY: force
35d498f871SMickaël Salaün
36d498f871SMickaël Salaün# force a rebuild of BPFOBJ when its dependencies are updated
37d498f871SMickaël Salaünforce:
38d498f871SMickaël Salaün
39d498f871SMickaël Salaün$(BPFOBJ): force
40e8f1f34aSZi Shen Lim	$(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
416882804cSAlexei Starovoitov
426882804cSAlexei StarovoitovCLANG ?= clang
4322c88526SDaniel BorkmannLLC   ?= llc
4422c88526SDaniel Borkmann
45cd95a892SQuentin MonnetPROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
4622c88526SDaniel Borkmann
4722c88526SDaniel Borkmann# Let newer LLVM versions transparently probe the kernel for availability
4822c88526SDaniel Borkmann# of full BPF instruction set.
4922c88526SDaniel Borkmannifeq ($(PROBE),)
5022c88526SDaniel Borkmann  CPU ?= probe
5122c88526SDaniel Borkmannelse
5222c88526SDaniel Borkmann  CPU ?= generic
5322c88526SDaniel Borkmannendif
546882804cSAlexei Starovoitov
553bc35c63SAlexei StarovoitovCLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
563bc35c63SAlexei Starovoitov	      -Wno-compare-distinct-pointer-types
573bc35c63SAlexei Starovoitov
583bc35c63SAlexei Starovoitov$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
59b0b04fc4SAlexei Starovoitov$(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline
603bc35c63SAlexei Starovoitov
616882804cSAlexei Starovoitov%.o: %.c
623bc35c63SAlexei Starovoitov	$(CLANG) $(CLANG_FLAGS) \
6322c88526SDaniel Borkmann		 -O2 -target bpf -emit-llvm -c $< -o - |      \
6422c88526SDaniel Borkmann	$(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@
65