Skip to content

Commit 028568d

Browse files
committed
kbuild: revert $(realpath ...) to $(shell cd ... && /bin/pwd)
I thought commit 8e9b466 ("kbuild: use $(abspath ...) instead of $(shell cd ... && /bin/pwd)") was a safe conversion, but it changed the behavior. $(abspath ...) / $(realpath ...) does not expand shell special characters, such as '~'. Here is a simple Makefile example: ---------------->8---------------- $(info /bin/pwd: $(shell cd ~/; /bin/pwd)) $(info abspath: $(abspath ~/)) $(info realpath: $(realpath ~/)) all: @: ---------------->8---------------- $ make /bin/pwd: /home/masahiro abspath: /home/masahiro/workspace/~ realpath: This can be a real problem if 'make O=~/foo' is invoked from another Makefile or primitive shell like dash. This commit partially reverts 8e9b466. Fixes: 8e9b466 ("kbuild: use $(abspath ...) instead of $(shell cd ... && /bin/pwd)") Reported-by: Julien Grall <julien.grall@arm.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Tested-by: Julien Grall <julien.grall@arm.com>
1 parent 9e66317 commit 028568d

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ endif
130130
ifneq ($(KBUILD_OUTPUT),)
131131
# check that the output directory actually exists
132132
saved-output := $(KBUILD_OUTPUT)
133-
$(shell [ -d $(KBUILD_OUTPUT) ] || mkdir -p $(KBUILD_OUTPUT))
134-
KBUILD_OUTPUT := $(realpath $(KBUILD_OUTPUT))
133+
KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
134+
&& /bin/pwd)
135135
$(if $(KBUILD_OUTPUT),, \
136136
$(error failed to create output directory "$(saved-output)"))
137137

tools/power/cpupower/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ endif
2626

2727
ifneq ($(OUTPUT),)
2828
# check that the output directory actually exists
29-
OUTDIR := $(realpath $(OUTPUT))
29+
OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
3030
$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
3131
endif
3232

tools/scripts/Makefile.include

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ifneq ($(O),)
22
ifeq ($(origin O), command line)
3-
ABSOLUTE_O := $(realpath $(O))
4-
dummy := $(if $(ABSOLUTE_O),,$(error O=$(O) does not exist))
3+
dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
4+
ABSOLUTE_O := $(shell cd $(O) ; pwd)
55
OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
66
COMMAND_O := O=$(ABSOLUTE_O)
77
ifeq ($(objtree),)
@@ -12,7 +12,7 @@ endif
1212

1313
# check that the output directory actually exists
1414
ifneq ($(OUTPUT),)
15-
OUTDIR := $(realpath $(OUTPUT))
15+
OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
1616
$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
1717
endif
1818

0 commit comments

Comments
 (0)