Commit f69237e1 authored by Greg Thelen's avatar Greg Thelen Committed by Shuah Khan

selftests: more general make nesting support

selftests can be built from the toplevel kernel makefile (e.g. make
kselftest-all) or directly (make -C tools/testing/selftests all).

The toplevel kernel makefile explicitly disables implicit rules with
"MAKEFLAGS += -rR", which is passed to tools/testing/selftests.  Some
selftest makefiles require implicit make rules, which is why
commit 67d8712d ("selftests: Fix build failures when invoked from
kselftest target") reenables implicit rules by clearing MAKEFLAGS if
MAKELEVEL=1.

So far so good.  However, if the toplevel makefile is called from an
outer makefile then MAKELEVEL will be elevated, which breaks the
MAKELEVEL equality test.
Example wrapped makefile error:
  $ cat ~/Makefile
  all:
  	$(MAKE) defconfig
  	$(MAKE) kselftest-all
  $ make -sf ~/Makefile
    futex_wait_timeout.c /src/tools/testing/selftests/kselftest_harness.h   /src/tools/testing/selftests/kselftest.h ../include/futextest.h ../include/atomic.h ../include/logging.h -lpthread -lrt -o /src/tools/testing/selftests/futex/functional/futex_wait_timeout
  make[4]: futex_wait_timeout.c: Command not found

Rather than checking $(MAKELEVEL), check for $(LINK.c), which is a more
direct side effect of "make -R".  This enables arbitrary makefile
nesting.
Signed-off-by: default avatarGreg Thelen <gthelen@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 75fa6772
...@@ -88,10 +88,10 @@ endif ...@@ -88,10 +88,10 @@ endif
# of the targets gets built. # of the targets gets built.
FORCE_TARGETS ?= FORCE_TARGETS ?=
# Clear LDFLAGS and MAKEFLAGS if called from main # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
# Makefile to avoid test build failures when test # implicit rules to sub-test Makefiles which avoids build failures in test
# Makefile doesn't have explicit build rules. # Makefile that don't have explicit build rules.
ifeq (1,$(MAKELEVEL)) ifeq (,$(LINK.c))
override LDFLAGS = override LDFLAGS =
override MAKEFLAGS = override MAKEFLAGS =
endif endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment