Makefile: refactor detection and use of tools
authorTomáš Golembiovský <tgolembi@redhat.com>
Tue, 5 Dec 2017 13:57:55 +0000 (14:57 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 5 Dec 2017 15:59:28 +0000 (15:59 +0000)
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
.gitignore
Makefile

index b99d5f8..5dd3503 100644 (file)
@@ -5,4 +5,5 @@ nbdkit-1.*.tar.gz
 *.rpm
 
 /BUILDROOT
+/Makefile.tools
 /x86_64
index 534d058..7a22647 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,8 +36,10 @@ PWD := $(shell pwd)
 VERSION := $(shell grep ^Version: nbdkit-plugin-vddk.spec | awk '{print $$2}')
 VDDK_DIR := $(shell grep '^%global vddkdir' nbdkit-plugin-vddk.spec | awk '{print $$3}')
 
-all: check-tools check-vddk check-source
-       rpmbuild -ba \
+include Makefile.tools
+
+all: check-vddk check-source
+       $(RPMBUILD) -ba \
            --define "_topdir $(PWD)" \
            --define "_builddir $(PWD)" \
            --define "_rpmdir $(PWD)" \
@@ -46,9 +48,23 @@ all: check-tools check-vddk check-source
            --define "_srcrpmdir $(PWD)" \
            nbdkit-plugin-vddk.spec
 
-check-tools:
-       @if ! rpmbuild --help >/dev/null 2>&1; then echo "‘rpmbuild’ not installed or not working.  Install the ‘rpm-build’ package."; exit 1; fi
-       @if ! wget --help >/dev/null 2>&1; then echo "‘wget’ not installed or not working.  Install the ‘wget’ package."; exit 1; fi
+Makefile.tools:
+       @rm -rf $@ $@-t
+       @if ! rpmbuild --help >/dev/null 2>&1; then \
+           echo -n "‘rpmbuild’ not installed or not working. "; \
+           echo "Install the ‘rpm-build’ package."; \
+           exit 1; \
+       else \
+           echo 'RPMBUILD=rpmbuild' >> $@-t; \
+       fi
+       @if wget --help >/dev/null 2>&1; then \
+           echo 'DOWNLOAD=wget -O -' >> $@-t; \
+       else \
+           echo -n "‘wget’ not installed or not working."; \
+           echo "Install the ‘wget’ package."; \
+           exit 1; \
+       fi
+       @mv $@-t $@
 
 check-vddk:
        @if ! [ -d $(VDDK_DIR) ] || ! [ -d $(VDDK_DIR)/include ]; then echo -e "You must download VDDK and edit ‘nbdkit-plugin-vddk.spec’ to point ‘vddkdir’\nto the location where you unpacked VDDK."; exit 1; fi
@@ -57,7 +73,7 @@ check-source: nbdkit-$(VERSION).tar.gz
 
 nbdkit-$(VERSION).tar.gz:
        rm -rf $@ $@-t
-       wget -O $@-t http://libguestfs.org/download/nbdkit/$@
+       $(DOWNLOAD) http://libguestfs.org/download/nbdkit/$@ > $@-t
        mv $@-t $@
 
 clean:
@@ -66,4 +82,4 @@ clean:
        rm -rf x86_64
        rm -rf BUILDROOT
 
-.PHONY: all check-source check-tools check-vddk clean
+.PHONY: all check-source check-vddk clean