]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
test: add shellcheck to Makefile
authorHarald Hoyer <harald@redhat.com>
Fri, 12 Mar 2021 09:27:31 +0000 (10:27 +0100)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 26 Mar 2021 08:35:30 +0000 (09:35 +0100)
Makefile

index c3fbd95b87834174c56049311c8594dd7b6a1dfe..0d082fec6965d02e4d9452e7333df14d51eba9c9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ ifeq ($(DRACUT_FULL_VERSION),)
 DRACUT_FULL_VERSION = $(DRACUT_VERSION)
 endif
 
+HAVE_SHELLCHECK ?= $(shell which shellcheck >/dev/null 2>&1 && echo yes)
 HAVE_SHFMT ?= $(shell which shfmt >/dev/null  2>&1 && echo yes)
 
 -include Makefile.inc
@@ -207,7 +208,7 @@ endif
 
 dracut-version.sh:
        @rm -f dracut-version.sh
-       @echo "DRACUT_VERSION=$(DRACUT_FULL_VERSION)" > dracut-version.sh
+       @printf "#!/bin/sh\n# shellcheck disable=SC2034\nDRACUT_VERSION=%s\n" "$(DRACUT_FULL_VERSION)" > dracut-version.sh
 
 clean:
        $(RM) *~
@@ -270,6 +271,13 @@ syncheck:
                        modules.d/*/module-setup.sh; do \
                [ $$V ] && echo "bash syntax check: $$i"; bash -n "$$i" ; ret=$$(($$ret+$$?)); \
        done;exit $$ret
+ifeq ($(HAVE_SHELLCHECK),yes)
+ifeq ($(HAVE_SHFMT),yes)
+       shellcheck $$(shfmt -f .)
+else
+       find . -name '*.sh' -print0 | xargs -0 shellcheck
+endif
+endif
 
 check: all syncheck rpm
        @[ "$$EUID" == "0" ] || { echo "'check' must be run as root! Please use 'sudo'."; exit 1; }