hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/testing/selftests/Makefile
....@@ -104,19 +104,27 @@
104104 override LDFLAGS =
105105 endif
106106
107
-ifneq ($(O),)
108
- BUILD := $(O)/kselftest
107
+top_srcdir ?= ../../..
108
+
109
+ifeq ("$(origin O)", "command line")
110
+ KBUILD_OUTPUT := $(O)
111
+endif
112
+
113
+ifneq ($(KBUILD_OUTPUT),)
114
+ # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
115
+ # expand a shell special character '~'. We use a somewhat tedious way here.
116
+ abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
117
+ $(if $(abs_objtree),, \
118
+ $(error failed to create output directory "$(KBUILD_OUTPUT)"))
119
+ # $(realpath ...) resolves symlinks
120
+ abs_objtree := $(realpath $(abs_objtree))
121
+ BUILD := $(abs_objtree)/kselftest
109122 else
110
- ifneq ($(KBUILD_OUTPUT),)
111
- BUILD := $(KBUILD_OUTPUT)/kselftest
112
- else
113
- BUILD := $(shell pwd)
114
- DEFAULT_INSTALL_HDR_PATH := 1
115
- endif
123
+ BUILD := $(CURDIR)
124
+ DEFAULT_INSTALL_HDR_PATH := 1
116125 endif
117126
118127 # Prepare for headers install
119
-top_srcdir ?= ../../..
120128 include $(top_srcdir)/scripts/subarch.include
121129 ARCH ?= $(SUBARCH)
122130 export KSFT_KHDR_INSTALL_DONE := 1