Makefile (7708bd430d88309333b0d0eb7783cddd0874dd14) | Makefile (f3c926a4df2cddf6230c3f56b1f43e439552cdad) |
---|---|
1# SPDX-License-Identifier: GPL-2.0 2include ../../../../scripts/Kbuild.include 3include ../../../scripts/Makefile.arch 4 5CURDIR := $(abspath .) | 1# SPDX-License-Identifier: GPL-2.0 2include ../../../../scripts/Kbuild.include 3include ../../../scripts/Makefile.arch 4 5CURDIR := $(abspath .) |
6LIBDIR := $(abspath ../../../lib) | 6TOOLSDIR := $(abspath ../../..) 7LIBDIR := $(TOOLSDIR)/lib |
7BPFDIR := $(LIBDIR)/bpf | 8BPFDIR := $(LIBDIR)/bpf |
8TOOLSDIR := $(abspath ../../../include) 9APIDIR := $(TOOLSDIR)/uapi | 9TOOLSINCDIR := $(TOOLSDIR)/include 10BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool 11APIDIR := $(TOOLSINCDIR)/uapi |
10GENDIR := $(abspath ../../../../include/generated) 11GENHDR := $(GENDIR)/autoconf.h 12 13ifneq ($(wildcard $(GENHDR)),) 14 GENFLAGS := -DHAVE_GENHDR 15endif 16 17CLANG ?= clang 18LLC ?= llc 19LLVM_OBJCOPY ?= llvm-objcopy 20BPF_GCC ?= $(shell command -v bpf-gcc;) 21CFLAGS += -g -Wall -O2 $(GENFLAGS) -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) \ | 12GENDIR := $(abspath ../../../../include/generated) 13GENHDR := $(GENDIR)/autoconf.h 14 15ifneq ($(wildcard $(GENHDR)),) 16 GENFLAGS := -DHAVE_GENHDR 17endif 18 19CLANG ?= clang 20LLC ?= llc 21LLVM_OBJCOPY ?= llvm-objcopy 22BPF_GCC ?= $(shell command -v bpf-gcc;) 23CFLAGS += -g -Wall -O2 $(GENFLAGS) -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) \ |
22 -I$(GENDIR) -I$(TOOLSDIR) -I$(CURDIR) \ | 24 -I$(GENDIR) -I$(TOOLSINCDIR) -I$(CURDIR) \ |
23 -Dbpf_prog_load=bpf_prog_test_load \ 24 -Dbpf_load_program=bpf_test_load_program 25LDLIBS += -lcap -lelf -lrt -lpthread 26 27# Order correspond to 'make run_tests' order 28TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 29 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ 30 test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \ --- 81 unchanged lines hidden (view full) --- 112$(OUTPUT)/test_sysctl: cgroup_helpers.c 113$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c 114 115.PHONY: force 116 117# force a rebuild of BPFOBJ when its dependencies are updated 118force: 119 | 25 -Dbpf_prog_load=bpf_prog_test_load \ 26 -Dbpf_load_program=bpf_test_load_program 27LDLIBS += -lcap -lelf -lrt -lpthread 28 29# Order correspond to 'make run_tests' order 30TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 31 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ 32 test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \ --- 81 unchanged lines hidden (view full) --- 114$(OUTPUT)/test_sysctl: cgroup_helpers.c 115$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c 116 117.PHONY: force 118 119# force a rebuild of BPFOBJ when its dependencies are updated 120force: 121 |
122DEFAULT_BPFTOOL := $(OUTPUT)/tools/usr/local/sbin/bpftool 123BPFTOOL ?= $(DEFAULT_BPFTOOL) 124 125$(DEFAULT_BPFTOOL): force 126 $(MAKE) -C $(BPFTOOLDIR) DESTDIR=$(OUTPUT)/tools install 127 |
|
120$(BPFOBJ): force 121 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ 122 123BPF_HELPERS := $(BPFDIR)/bpf_helper_defs.h $(wildcard $(BPFDIR)/bpf_*.h) 124$(BPFDIR)/bpf_helper_defs.h: 125 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ bpf_helper_defs.h 126 127# Get Clang's default includes on this system, as opposed to those seen by --- 47 unchanged lines hidden (view full) --- 175 -c $1 -o - || echo "BPF obj compilation failed") | \ 176 $(LLC) -march=bpf -mcpu=probe $4 -filetype=obj -o $2 177endef 178# Build BPF object using GCC 179define GCC_BPF_BUILD_RULE 180 $(BPF_GCC) $3 $4 -O2 -c $1 -o $2 181endef 182 | 128$(BPFOBJ): force 129 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ 130 131BPF_HELPERS := $(BPFDIR)/bpf_helper_defs.h $(wildcard $(BPFDIR)/bpf_*.h) 132$(BPFDIR)/bpf_helper_defs.h: 133 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ bpf_helper_defs.h 134 135# Get Clang's default includes on this system, as opposed to those seen by --- 47 unchanged lines hidden (view full) --- 183 -c $1 -o - || echo "BPF obj compilation failed") | \ 184 $(LLC) -march=bpf -mcpu=probe $4 -filetype=obj -o $2 185endef 186# Build BPF object using GCC 187define GCC_BPF_BUILD_RULE 188 $(BPF_GCC) $3 $4 -O2 -c $1 -o $2 189endef 190 |
191SKEL_BLACKLIST := btf__% test_pinning_invalid.c 192 |
|
183# Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on 184# $eval()) and pass control to DEFINE_TEST_RUNNER_RULES. 185# Parameters: 186# $1 - test runner base binary name (e.g., test_progs) 187# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc) 188define DEFINE_TEST_RUNNER 189 190TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 191TRUNNER_BINARY := $1$(if $2,-)$2 192TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \ 193 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c))) 194TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \ 195 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES))) 196TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES)) 197TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h | 193# Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on 194# $eval()) and pass control to DEFINE_TEST_RUNNER_RULES. 195# Parameters: 196# $1 - test runner base binary name (e.g., test_progs) 197# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc) 198define DEFINE_TEST_RUNNER 199 200TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 201TRUNNER_BINARY := $1$(if $2,-)$2 202TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \ 203 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c))) 204TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \ 205 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES))) 206TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES)) 207TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h |
198TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \ 199 $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))) | 208TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)) 209TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS)) 210TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \ 211 $$(filter-out $(SKEL_BLACKLIST), \ 212 $$(TRUNNER_BPF_SRCS))) |
200 201# Evaluate rules now with extra TRUNNER_XXX variables above already defined 202$$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2)) 203 204endef 205 206# Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and 207# set up by DEFINE_TEST_RUNNER itself, create test runner build rules with: --- 13 unchanged lines hidden (view full) --- 221$(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y 222$(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 223 $(TRUNNER_BPF_PROGS_DIR)/%.c \ 224 $(TRUNNER_BPF_PROGS_DIR)/*.h \ 225 $$(BPF_HELPERS) | $(TRUNNER_OUTPUT) 226 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \ 227 $(TRUNNER_BPF_CFLAGS), \ 228 $(TRUNNER_BPF_LDFLAGS)) | 213 214# Evaluate rules now with extra TRUNNER_XXX variables above already defined 215$$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2)) 216 217endef 218 219# Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and 220# set up by DEFINE_TEST_RUNNER itself, create test runner build rules with: --- 13 unchanged lines hidden (view full) --- 234$(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y 235$(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 236 $(TRUNNER_BPF_PROGS_DIR)/%.c \ 237 $(TRUNNER_BPF_PROGS_DIR)/*.h \ 238 $$(BPF_HELPERS) | $(TRUNNER_OUTPUT) 239 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \ 240 $(TRUNNER_BPF_CFLAGS), \ 241 $(TRUNNER_BPF_LDFLAGS)) |
242 243$(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h: \ 244 $(TRUNNER_OUTPUT)/%.o \ 245 | $(BPFTOOL) $(TRUNNER_OUTPUT) 246 $$(BPFTOOL) gen skeleton $$< > $$@ |
|
229endif 230 231# ensure we set up tests.h header generation rule just once 232ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) 233$(TRUNNER_TESTS_DIR)-tests-hdr := y 234$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c 235 $$(shell ( cd $(TRUNNER_TESTS_DIR); \ 236 echo '/* Generated header, do not edit */'; \ 237 ls *.c 2> /dev/null | \ 238 sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \ 239 ) > $$@) 240endif 241 242# compile individual test files 243# Note: we cd into output directory to ensure embedded BPF object is found 244$(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ 245 $(TRUNNER_TESTS_DIR)/%.c \ 246 $(TRUNNER_EXTRA_HDRS) \ 247 $(TRUNNER_BPF_OBJS) \ | 247endif 248 249# ensure we set up tests.h header generation rule just once 250ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) 251$(TRUNNER_TESTS_DIR)-tests-hdr := y 252$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c 253 $$(shell ( cd $(TRUNNER_TESTS_DIR); \ 254 echo '/* Generated header, do not edit */'; \ 255 ls *.c 2> /dev/null | \ 256 sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \ 257 ) > $$@) 258endif 259 260# compile individual test files 261# Note: we cd into output directory to ensure embedded BPF object is found 262$(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ 263 $(TRUNNER_TESTS_DIR)/%.c \ 264 $(TRUNNER_EXTRA_HDRS) \ 265 $(TRUNNER_BPF_OBJS) \ |
266 $(TRUNNER_BPF_SKELS) \ |
|
248 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 249 cd $$(@D) && $$(CC) $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F) 250 251$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 252 %.c \ 253 $(TRUNNER_EXTRA_HDRS) \ 254 $(TRUNNER_TESTS_HDR) \ 255 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 256 $$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@ 257 | 267 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 268 cd $$(@D) && $$(CC) $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F) 269 270$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 271 %.c \ 272 $(TRUNNER_EXTRA_HDRS) \ 273 $(TRUNNER_TESTS_HDR) \ 274 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 275 $$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@ 276 |
277# only copy extra resources if in flavored build |
|
258$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT) 259ifneq ($2,) | 278$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT) 279ifneq ($2,) |
260 # only copy extra resources if in flavored build | |
261 cp -a $$^ $(TRUNNER_OUTPUT)/ 262endif 263 264$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \ 265 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \ 266 | $(TRUNNER_BINARY)-extras 267 $$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@ 268 --- 49 unchanged lines hidden (view full) --- 318 $(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 319 320# Make sure we are able to include and link libbpf against c++. 321$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ) 322 $(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@ 323 324EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) \ 325 prog_tests/tests.h map_tests/tests.h verifier/tests.h \ | 280 cp -a $$^ $(TRUNNER_OUTPUT)/ 281endif 282 283$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \ 284 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \ 285 | $(TRUNNER_BINARY)-extras 286 $$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@ 287 --- 49 unchanged lines hidden (view full) --- 337 $(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 338 339# Make sure we are able to include and link libbpf against c++. 340$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ) 341 $(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@ 342 343EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) \ 344 prog_tests/tests.h map_tests/tests.h verifier/tests.h \ |
326 feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc | 345 feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc \ 346 tools *.skel.h |