Makefile: fix use of PWD in target "all"
PATCH 1/1 Makefile: fix use of PWD in target "all"
The "all" target creates the build-head file in the wrong location when using "make -C" or "sudo make". The reason is that the PWD environment variable gets the value of the current directory when calling "make -C" (before the -C changes directories), or is unset in the case of "sudo make". Note that the PWD is not changed by the previous "cd $(SRCDIR)".
/a/b/c $ make -C ../kvm-unit-tests =====> creates /a/b/c/build-head /a/b/kvm-unit-tests $ sudo make =====> creates /build-head (note the root)
The consequence of this is that the standalone script can't find the build-head file:
/a/b/c $ make -C kvm-unit-tests standalone
cat: build-head: No such file or directory
...
/a/b/kvm-unit-tests $ sudo make standalone
cat: build-head: No such file or directory
...
The fix is to not use PWD. "cd $SRCDIR && git rev-parse" is run in a subshell in order to not break out-of-tree builds, which expect build-head in the current directory (/a/b/c/build-head below).
Tested:
out-of-tree build: /a/b/c $ ../kvm-unit-tests/configure && make standalone sudo make: /a/b/kvm-unit-tests $ ./configure && sudo make standalone make -C: /a/b/c $ (cd ../kvm-unit-tests && ./configure) && \ make -C ../kvm-unit-tests standalone
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -101,7 +101,7 @@ directories: -include */.*.d */*/.*.d -all: directories $(shell cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD >$(PWD)/build-head 2>/dev/null) +all: directories $(shell (cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD) >build-head 2>/dev/null) standalone: all @scripts/mkstandalone.sh
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
Quoted 52 lines · Ricardo Koller
The "all" target creates the build-head file in the wrong location when using "make -C" or "sudo make". The reason is that the PWD environment variable gets the value of the current directory when calling "make -C" (before the -C changes directories), or is unset in the case of "sudo make". Note that the PWD is not changed by the previous "cd $(SRCDIR)".
/a/b/c $ make -C ../kvm-unit-tests =====> creates /a/b/c/build-head /a/b/kvm-unit-tests $ sudo make =====> creates /build-head (note the root)The consequence of this is that the standalone script can't find the build-head file:
/a/b/c $ make -C kvm-unit-tests standalone
cat: build-head: No such file or directory
.../a/b/kvm-unit-tests $ sudo make standalone
cat: build-head: No such file or directory
...The fix is to not use PWD. "cd $SRCDIR && git rev-parse" is run in a subshell in order to not break out-of-tree builds, which expect build-head in the current directory (/a/b/c/build-head below).
Tested:
out-of-tree build: /a/b/c $ ../kvm-unit-tests/configure && make standalone sudo make: /a/b/kvm-unit-tests $ ./configure && sudo make standalone make -C: /a/b/c $ (cd ../kvm-unit-tests && ./configure) && \ make -C ../kvm-unit-tests standaloneSigned-off-by Ricardo Koller <[email protected]>Reviewed-by Jim Mattson <[email protected]>Reviewed-by Oliver Upton <[email protected]>--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +0
-0
Makefile directories: · line 107
Quoted 8 lines
Makefile +1
-1@@ -101,7 +101,7 @@ directories: -include */.*.d */*/.*.d -all: directories $(shell cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD >$(PWD)/build-head 2>/dev/null) +all: directories $(shell (cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD) >build-head 2>/dev/null) standalone: all @scripts/mkstandalone.sh
Queued, thanks.
Paolo