History

selftests/landlock: Fix out-of-tree builds

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.

Mickaël Salaün committed 4 years ago

Commit a5254051 parent 80e78fc2 files · +14 −9Browse files

Unified · Split

2 files
  1. tools/testing/selftests/landlock/Makefile +10 −9
  2. tools/testing/selftests/lib.mk +4 −0
tools/testing/selftests/landlock/Makefile+10−9
@@ -1,6 +1,11 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2#
3# First run: make -C ../../../.. headers_install
2 4
3CFLAGS += -Wall -O2 $(KHDR_INCLUDES)5CFLAGS += -Wall -O2 $(KHDR_INCLUDES)
6LDLIBS += -lcap
7
8LOCAL_HDRS += common.h
4 9
5src_test := $(wildcard *_test.c)10src_test := $(wildcard *_test.c)
6 11
@@ -8,14 +13,10 @@ TEST_GEN_PROGS := $(src_test:.c=) · 1 unmodified line
8 13
9TEST_GEN_PROGS_EXTENDED := true14TEST_GEN_PROGS_EXTENDED := true
10 15
11OVERRIDE_TARGETS := 116# Static linking for short targets:
12top_srcdir := ../../../..17$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
13include ../lib.mk
14
15khdr_dir = $(top_srcdir)/usr/include
16 18
17$(OUTPUT)/true: true.c19include ../lib.mk
18 $(LINK.c) $< $(LDLIBS) -o $@ -static
19 20
20$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h21# Static linking for targets with $(OUTPUT)/ prefix:
21 $(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)22$(TEST_GEN_PROGS_EXTENDED): LDFLAGS += -static
tools/testing/selftests/lib.mk+4−0
@@ -42,6 +42,10 @@ endif · 41 unmodified lines
42selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))42selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
43top_srcdir = $(selfdir)/../../..43top_srcdir = $(selfdir)/../../..
44 44
45ifeq ($(KHDR_INCLUDES),)
46KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
47endif
48
45# The following are built by lib.mk common compile rules.49# The following are built by lib.mk common compile rules.
46# TEST_CUSTOM_PROGS should be used by tests that require50# TEST_CUSTOM_PROGS should be used by tests that require
47# custom build rule and prevent common build rule use.51# custom build rule and prevent common build rule use.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t