The kernel build runs make with -rR, which removes make's built-in rules
and variables. tools/testing/selftests/Makefile copes by clearing
MAKEFLAGS for its sub-makes, and lib.mk defines LINK.c, COMPILE.S and
LINK.S again, but only when building_out_of_srctree is set. A selftest
directory built directly by a make that inherited -R gets neither, so
LINK.c is empty and the generic rule tries to execute the source file:

  make[4]: acct_syscall.c: No such file or directory

Define them whenever make does not provide them, as make itself defines
them, so that they are the same with and without -R. The definitions
lib.mk used for O= builds until now differed from make's only in using
TARGET_ARCH instead of TARGET_MACH for assembly, which no selftest sets.

Assisted-by: LLM
Signed-off-by: Sasha Levin <[email protected]>
---
 tools/testing/selftests/lib.mk | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index f02cc8a2e4ae3..4de034f3e9d34 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -207,14 +207,11 @@ CFLAGS += -I${top_srcdir}/tools/testing/selftests
 CFLAGS += $(USERCFLAGS)
 LDFLAGS += $(USERLDFLAGS)
 
-# When make O= with kselftest target from main level
-# the following aren't defined.
-#
-ifdef building_out_of_srctree
-LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
-COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
-LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
-endif
+# Make's built-in variables are not defined when run with -R, which kbuild
+# passes down when a test is built from the main level.
+LINK.c ?= $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
+COMPILE.S ?= $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c
+LINK.S ?= $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)
 
 # Selftest makefiles can override those targets by setting
 # OVERRIDE_TARGETS = 1.
-- 
2.53.0


Reply via email to