build: fix make warning if there is no cppcheck
authorBertrand Marquis <bertrand.marquis@arm.com>
Wed, 25 May 2022 09:07:46 +0000 (11:07 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 25 May 2022 09:07:46 +0000 (11:07 +0200)
If cppcheck is not present, the following warning appears during build:
which: no cppcheck in ([...])
/bin/sh: cppcheck: command not found

Fix the problem by using shell code inside the cppcheck-version rule to
also prevent unneeded call of which when something else than cppcheck is
built.

Reported-by: Julien Grall <julien@xen.org>
Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/Makefile

index 15388703bc7020b6b30344ff2ff8e547e80e99a8..82f5310b12266e09c7b2b8fa1d8a75488d767913 100644 (file)
@@ -694,12 +694,14 @@ $(objtree)/%.c.cppcheck: $(srctree)/%.c $(objtree)/include/generated/autoconf.h
        $(call if_changed,cppcheck_xml)
 
 cppcheck-version:
-ifeq ($(shell which $(CPPCHECK)),)
-       $(error Cannot find cppcheck executable: $(CPPCHECK))
-endif
-ifeq ($(shell $(CPPCHECK) --version | awk '{print ($$2 < 2.7)}'),1)
-       $(error Please upgrade your cppcheck to version 2.7 or greater)
-endif
+       $(Q)if ! which $(CPPCHECK) > /dev/null 2>&1; then \
+               echo "Cannot find cppcheck executable: $(CPPCHECK)"; \
+               exit 1; \
+       fi
+       $(Q)if [ "$$($(CPPCHECK) --version | awk '{print ($$2 < 2.7)}')" -eq 1 ]; then \
+               echo "Please upgrade your cppcheck to version 2.7 or greater"; \
+               exit 1; \
+       fi
 
 # Put this in generated headers this way it is cleaned by include/Makefile
 $(objtree)/include/generated/compiler-def.h: