From 52fcae82e16c06c7f60e93f8908ea3090f0a86f9 Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Tue, 23 Jan 2024 15:57:49 +0000
Subject: [PATCH] Makefile.am: Add target 'shellcheck'.

git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@5596 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/ChangeLog   |  4 ++++
 smartmontools/Makefile.am | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog
index 2b2e7da0a..8a2c6968b 100644
--- a/smartmontools/ChangeLog
+++ b/smartmontools/ChangeLog
@@ -1,5 +1,9 @@
 $Id$
 
+2024-01-23  Christian Franke  <franke@computer.org>
+
+	Makefile.am: Add target 'shellcheck'.
+
 2024-01-19  Christian Franke  <franke@computer.org>
 
 	os_win32/installer.nsi: Avoid that code signing invalidates the
diff --git a/smartmontools/Makefile.am b/smartmontools/Makefile.am
index b6e255852..53ecf1761 100644
--- a/smartmontools/Makefile.am
+++ b/smartmontools/Makefile.am
@@ -450,6 +450,8 @@ EXTRA_DIST = \
         $(examples_SCRIPTS)
 
 CLEANFILES = \
+        cppcheck.txt \
+        shellcheck.txt \
         smartd.8 \
         smartd.1m \
         smartd.8.html \
@@ -736,7 +738,7 @@ FIXHTML = sed -e '1s,^Content-type.*,,' \
               -e '/^Time: [012][0-9]:[0-5][0-9]:[0-5][0-9] [^<]*$$/d'
 
 # Avoid automake warning: '.PHONY was already defined in condition ...'
-phony = htmlman pdfman
+phony = cppcheck htmlman pdfman shellcheck
 .PHONY: $(phony)
 
 htmlman: smartctl.8.html smartd.8.html smartd.conf.5.html update-smart-drivedb.8.html
@@ -792,6 +794,28 @@ cppcheck.txt: $(smartctl_SOURCES) $(EXTRA_smartctl_SOURCES) \
               $(smartd_SOURCES) $(EXTRA_smartd_SOURCES)
 	$(srcdir)/cppcheck.sh $(CPPCHECKFLAGS) > $@
 
+# Create shellcheck report
+shellcheck: shellcheck.txt
+
+SHELLCHECK=shellcheck
+
+# Exclude "SC3043 (warning): In POSIX sh, 'local' is undefined."
+# Virtually all relevant /bin/sh shells support 'local'
+SHELLCHECKFLAGS=-S warning -e SC3043
+
+SHELLSCRIPTS= \
+    $(srcdir)/autogen.sh \
+    $(srcdir)/cppcheck.sh \
+    $(srcdir)/do_release \
+    $(srcdir)/getversion.sh \
+    $(srcdir)/os_win32/pe32edit.sh \
+    smartd_warning.sh \
+    update-smart-drivedb
+
+shellcheck.txt: $(SHELLSCRIPTS)
+	$(ECHO_V_GEN) '  $(SHELLCHECK) $(SHELLCHECKFLAGS) $(SHELLSCRIPTS) > $@'
+	@$(SHELLCHECK) $(SHELLCHECKFLAGS) $(SHELLSCRIPTS) > $@ || \
+	if [ $$? = 1 ]; then echo "$@: issues found"; else rm -f $@; exit 1; fi
 
 if REPRODUCIBLE_BUILD
 # The default 'dist-*' rules generated by automake allow to override the
-- 
GitLab