Skip to content

Commit 5ad51ab

Browse files
Muhammad Usama Anjumshuahkh
authored andcommitted
selftests: set the BUILD variable to absolute path
The build of kselftests fails if relative path is specified through KBUILD_OUTPUT or O=<path> method. BUILD variable is used to determine the path of the output objects. When make is run from other directories with relative paths, the exact path of the build objects is ambiguous and build fails. make[1]: Entering directory '/home/usama/repos/kernel/linux_mainline2/tools/testing/selftests/alsa' gcc mixer-test.c -L/usr/lib/x86_64-linux-gnu -lasound -o build/kselftest/alsa/mixer-test /usr/bin/ld: cannot open output file build/kselftest/alsa/mixer-test Set the BUILD variable to the absolute path of the output directory. Make the logic readable and easy to follow. Use spaces instead of tabs for indentation as if with tab indentation is considered recipe in make. Signed-off-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent cef7578 commit 5ad51ab

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

tools/testing/selftests/Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,27 @@ ifdef building_out_of_srctree
114114
override LDFLAGS =
115115
endif
116116

117-
ifneq ($(O),)
118-
BUILD := $(O)/kselftest
117+
top_srcdir ?= ../../..
118+
119+
ifeq ("$(origin O)", "command line")
120+
KBUILD_OUTPUT := $(O)
121+
endif
122+
123+
ifneq ($(KBUILD_OUTPUT),)
124+
# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
125+
# expand a shell special character '~'. We use a somewhat tedious way here.
126+
abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
127+
$(if $(abs_objtree),, \
128+
$(error failed to create output directory "$(KBUILD_OUTPUT)"))
129+
# $(realpath ...) resolves symlinks
130+
abs_objtree := $(realpath $(abs_objtree))
131+
BUILD := $(abs_objtree)/kselftest
119132
else
120-
ifneq ($(KBUILD_OUTPUT),)
121-
BUILD := $(KBUILD_OUTPUT)/kselftest
122-
else
123-
BUILD := $(shell pwd)
124-
DEFAULT_INSTALL_HDR_PATH := 1
125-
endif
133+
BUILD := $(CURDIR)
134+
DEFAULT_INSTALL_HDR_PATH := 1
126135
endif
127136

128137
# Prepare for headers install
129-
top_srcdir ?= ../../..
130138
include $(top_srcdir)/scripts/subarch.include
131139
ARCH ?= $(SUBARCH)
132140
export KSFT_KHDR_INSTALL_DONE := 1

0 commit comments

Comments
 (0)