From 3aecb6c685d9d6104bd8d13bd54320a02fc2b14f Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 19 Jun 2026 12:48:16 +0200 Subject: [PATCH] rules.mk: Add targets to check shell syntax Add the target sh-syntax-check, which triggers bash syntax linting with shellcheck This commit stops short of making target all depend on it, because the fallout is impressive. Signed-off-by: Jan Lindemann --- make/defs.mk | 8 ++++++++ make/rules.mk | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/make/defs.mk b/make/defs.mk index 5e7eaf26..5127b63b 100644 --- a/make/defs.mk +++ b/make/defs.mk @@ -98,6 +98,14 @@ endif ifndef PRISTINE_MAKE PRISTINE_MAKE := umask $(MINIMAL_UMASK) && MAKEFLAGS=$(MINIMAL_MAKEFLAGS) LD_LIBRARY_PATH=$(MINIMAL_LD_LIBRARY_PATH) PATH=$(MINIMAL_PATH) $(MAKE) endif +ifndef SHELLCHECK + SHELLCHECK := $(shell $(WHICH) shellcheck) +endif +ifdef SHELLCHECK + SHELLCHECK += -f gcc +else + SHELLCHECK := bash -n +endif # ----- Function definitions diff --git a/make/rules.mk b/make/rules.mk index a0157556..fca1258a 100644 --- a/make/rules.mk +++ b/make/rules.mk @@ -16,6 +16,7 @@ distclean: clean %.this \ allclean \ checkroot \ + check-syntax \ collect \ coreclean \ depclean \ @@ -39,6 +40,7 @@ distclean: clean rccclean \ remake \ runclean \ + sh-check-syntax \ textclean \ tmpclean \ uicclean \ @@ -430,4 +432,19 @@ find: collect: bash $(JWB_SCRIPT_DIR)/collect-installed-pkg-changes.sh -t $(TOPDIR) +check: check-syntax +check-syntax: sh-check-syntax +sh-check-syntax: + +ifneq ($(strip $(EXE_SH)),) +$(info EXE_SH=>$(EXE_SH)<) +sh-check-syntax: sh-check-syntax-rule +sh-check-syntax-rule: $(EXE_SH) + $(SHELLCHECK) $^ + set -e; for script in $^; do \ + echo "Checking $$script" ;\ + $(SHELLCHECK) $$script ;\ + done +endif + endif # ifndef JW_PKG_RULES_MK_INCLUDED