These changes simplify the Makefile and handle these 5 ways to build Landlock tests: - make -C tools/testing/selftests/landlock - make -C tools/testing/selftests TARGETS=landlock gen_tar - make TARGETS=landlock kselftest-gen_tar - make TARGETS=landlock O=build kselftest-gen_tar - make -C /tmp/linux TARGETS=landlock O=/tmp/build kselftest-gen_tar This also makes $(KHDR_INCLUDES) available to other test collections when building in their directory.
Unified · Split
| @@ -1,6 +1,11 @@ | ||
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | +# | |
| 3 | +# First run: make -C ../../../.. headers_install | |
| 2 | 4 | |
| 3 | 5 | CFLAGS += -Wall -O2 $(KHDR_INCLUDES) |
| 6 | +LDLIBS += -lcap | |
| 7 | + | |
| 8 | +LOCAL_HDRS += common.h | |
| 4 | 9 | |
| 5 | 10 | src_test := $(wildcard *_test.c) |
| 6 | 11 | |
| @@ -8,14 +13,10 @@ TEST_GEN_PROGS := $(src_test:.c=) · 1 unmodified line | ||
| 8 | 13 | |
| 9 | 14 | TEST_GEN_PROGS_EXTENDED := true |
| 10 | 15 | |
| 11 | −OVERRIDE_TARGETS := 1 | |
| 12 | −top_srcdir := ../../../.. | |
| 13 | −include ../lib.mk | |
| 14 | − | |
| 15 | −khdr_dir = $(top_srcdir)/usr/include | |
| 16 | +# Static linking for short targets: | |
| 17 | +$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static | |
| 16 | 18 | |
| 17 | −$(OUTPUT)/true: true.c | |
| 18 | − $(LINK.c) $< $(LDLIBS) -o $@ -static | |
| 19 | +include ../lib.mk | |
| 19 | 20 | |
| 20 | −$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h | |
| 21 | − $(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir) | |
| 21 | +# Static linking for targets with $(OUTPUT)/ prefix: | |
| 22 | +$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static | |
| @@ -42,6 +42,10 @@ endif · 41 unmodified lines | ||
| 42 | 42 | selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) |
| 43 | 43 | top_srcdir = $(selfdir)/../../.. |
| 44 | 44 | |
| 45 | +ifeq ($(KHDR_INCLUDES),) | |
| 46 | +KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include | |
| 47 | +endif | |
| 48 | + | |
| 45 | 49 | # The following are built by lib.mk common compile rules. |
| 46 | 50 | # TEST_CUSTOM_PROGS should be used by tests that require |
| 47 | 51 | # custom build rule and prevent common build rule use. |