[kvm-unit-tests PATCH] Makefile: fix use of PWD in target "all"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Ricardo Koller <ricarkol@xxxxxxxxxx>
Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>
Reviewed-by: Oliver Upton <oupton@xxxxxxxxxx>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 0e21a49..e0828fe 100644
--- a/Makefile
+++ b/Makefile
@@ -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
-- 
2.29.2.576.ga3fc446d84-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux