aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuah Khan <skhan@linuxfoundation.org>2019-04-15 17:51:42 -0400
committerShuah Khan <skhan@linuxfoundation.org>2019-04-19 19:15:27 -0400
commit8ce72dc32578f16942997f041f62759b4c693b6f (patch)
treefa0e4507802177ffd283818ad5984e52741d6648
parentb433a52aa28733e0650c5e83efdccfd0637b981a (diff)
selftests: fix headers_install circular dependency
"make kselftest" fails with "Circular Makefile.o <- prepare dependency dropped." error, when lib.mk invokes "make headers_install". Make level 0: Main make calls selftests run_tests target ... Make level n: selftests lib.mk invokes main make's headers_install The secondary level make inherits builtin-rules which will use the rule to generate Makefile.o and runs into "Circular Makefile.o <- prepare dependency dropped." error, and kselftest compile fails. Invoke headers_install target with --no-builtin-rules to avoid circular error. In addition, lib.mk installs headers in the default HDR_PATH, even when build relocation is requested with O= or export KBUILD_OUTPUT. Fix the problem by passing in INSTALL_HDR_PATH. The headers are installed under the specified output "dir/usr". Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
-rw-r--r--tools/testing/selftests/Makefile52
-rw-r--r--tools/testing/selftests/lib.mk38
2 files changed, 80 insertions, 10 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index e659af3cd643..b43c5f41fb3e 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -75,12 +75,15 @@ ifneq ($(KBUILD_SRC),)
75override LDFLAGS = 75override LDFLAGS =
76endif 76endif
77 77
78BUILD := $(O) 78ifneq ($(O),)
79ifndef BUILD 79 BUILD := $(O)
80 BUILD := $(KBUILD_OUTPUT) 80else
81endif 81 ifneq ($(KBUILD_OUTPUT),)
82ifndef BUILD 82 BUILD := $(KBUILD_OUTPUT)
83 BUILD := $(shell pwd) 83 else
84 BUILD := $(shell pwd)
85 DEFAULT_INSTALL_HDR_PATH := 1
86 endif
84endif 87endif
85 88
86# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header 89# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
@@ -89,8 +92,41 @@ endif
89# with system() call. Export it here to cover override RUN_TESTS defines. 92# with system() call. Export it here to cover override RUN_TESTS defines.
90export KSFT_TAP_LEVEL=`echo 1` 93export KSFT_TAP_LEVEL=`echo 1`
91 94
95# Prepare for headers install
96top_srcdir ?= ../../..
97include $(top_srcdir)/scripts/subarch.include
98ARCH ?= $(SUBARCH)
99export KSFT_KHDR_INSTALL_DONE := 1
92export BUILD 100export BUILD
93all: 101
102# set default goal to all, so make without a target runs all, even when
103# all isn't the first target in the file.
104.DEFAULT_GOAL := all
105
106# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
107# is used to avoid running headers_install from lib.mk.
108# Invoke headers install with --no-builtin-rules to avoid circular
109# dependency in "make kselftest" case. In this case, second level
110# make inherits builtin-rules which will use the rule generate
111# Makefile.o and runs into
112# "Circular Makefile.o <- prepare dependency dropped."
113# and headers_install fails and test compile fails.
114#
115# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
116# invokes them as sub-makes and --no-builtin-rules is not necessary,
117# but doesn't cause any failures. Keep it simple and use the same
118# flags in both cases.
119# Local build cases: "make kselftest", "make -C" - headers are installed
120# in the default INSTALL_HDR_PATH usr/include.
121khdr:
122ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
123 make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
124else
125 make --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
126 ARCH=$(ARCH) -C $(top_srcdir) headers_install
127endif
128
129all: khdr
94 @for TARGET in $(TARGETS); do \ 130 @for TARGET in $(TARGETS); do \
95 BUILD_TARGET=$$BUILD/$$TARGET; \ 131 BUILD_TARGET=$$BUILD/$$TARGET; \
96 mkdir $$BUILD_TARGET -p; \ 132 mkdir $$BUILD_TARGET -p; \
@@ -173,4 +209,4 @@ clean:
173 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 209 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
174 done; 210 done;
175 211
176.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean 212.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 8b0f16409ed7..5979fdc4f36c 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -3,7 +3,16 @@
3CC := $(CROSS_COMPILE)gcc 3CC := $(CROSS_COMPILE)gcc
4 4
5ifeq (0,$(MAKELEVEL)) 5ifeq (0,$(MAKELEVEL))
6OUTPUT := $(shell pwd) 6 ifneq ($(O),)
7 OUTPUT := $(O)
8 else
9 ifneq ($(KBUILD_OUTPUT),)
10 OUTPUT := $(KBUILD_OUTPUT)
11 else
12 OUTPUT := $(shell pwd)
13 DEFAULT_INSTALL_HDR_PATH := 1
14 endif
15 endif
7endif 16endif
8 17
9# The following are built by lib.mk common compile rules. 18# The following are built by lib.mk common compile rules.
@@ -21,9 +30,34 @@ top_srcdir ?= ../../../..
21include $(top_srcdir)/scripts/subarch.include 30include $(top_srcdir)/scripts/subarch.include
22ARCH ?= $(SUBARCH) 31ARCH ?= $(SUBARCH)
23 32
33# set default goal to all, so make without a target runs all, even when
34# all isn't the first target in the file.
35.DEFAULT_GOAL := all
36
37# Invoke headers install with --no-builtin-rules to avoid circular
38# dependency in "make kselftest" case. In this case, second level
39# make inherits builtin-rules which will use the rule generate
40# Makefile.o and runs into
41# "Circular Makefile.o <- prepare dependency dropped."
42# and headers_install fails and test compile fails.
43# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
44# invokes them as sub-makes and --no-builtin-rules is not necessary,
45# but doesn't cause any failures. Keep it simple and use the same
46# flags in both cases.
47# Note that the support to install headers from lib.mk is necessary
48# when test Makefile is run directly with "make -C".
49# When local build is done, headers are installed in the default
50# INSTALL_HDR_PATH usr/include.
24.PHONY: khdr 51.PHONY: khdr
25khdr: 52khdr:
26 make ARCH=$(ARCH) -C $(top_srcdir) headers_install 53ifndef KSFT_KHDR_INSTALL_DONE
54ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
55 make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
56else
57 make --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \
58 ARCH=$(ARCH) -C $(top_srcdir) headers_install
59endif
60endif
27 61
28all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 62all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
29else 63else