1716fd348SMartin Matuska# Global ShellCheck exclusions: 2c03c5b1cSMartin Matuska# 3c03c5b1cSMartin Matuska# ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090] 4c03c5b1cSMartin Matuska# Not following: a was not specified as input (see shellcheck -x). [SC1091] 5c03c5b1cSMartin Matuska# Prefer putting braces around variable references even when not strictly required. [SC2250] 6bb2d13b6SMartin Matuska# Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore). [SC2312] 7*315ee00fSMartin Matuska# Command appears to be unreachable. Check usage (or ignore if invoked indirectly). [SC2317] 8c03c5b1cSMartin Matuska# In POSIX sh, 'local' is undefined. [SC2039] # older ShellCheck versions 9c03c5b1cSMartin Matuska# In POSIX sh, 'local' is undefined. [SC3043] # newer ShellCheck versions 1016038816SMartin Matuska 11716fd348SMartin MatuskaSHELLCHECKSCRIPTS = 12716fd348SMartin Matuska 13716fd348SMartin MatuskaJUST_SHELLCHECK_OPTS = $(addprefix shellcheck-here-,$(subst /,^,$(1))) 14716fd348SMartin MatuskaJUST_CHECKBASHISMS_OPTS = $(addprefix checkbashisms-here-,$(subst /,^,$(1))) 15716fd348SMartin MatuskaSHELLCHECK_OPTS = $(call JUST_SHELLCHECK_OPTS,$(1)) $(call JUST_CHECKBASHISMS_OPTS,$(1)) 16716fd348SMartin Matuska 17716fd348SMartin MatuskaPHONY += shellcheck 18716fd348SMartin Matuska 19716fd348SMartin Matuska_STGT = $(subst ^,/,$(subst shellcheck-here-,,$@)) 20716fd348SMartin Matuskashellcheck-here-%: 21716fd348SMartin Matuskaif HAVE_SHELLCHECK 22*315ee00fSMartin Matuska shellcheck --format=gcc --enable=all --exclude=SC1090,SC1091,SC2039,SC2250,SC2312,SC2317,SC3043 $$([ -n "$(SHELLCHECK_SHELL)" ] && echo "--shell=$(SHELLCHECK_SHELL)") "$$([ -e "$(_STGT)" ] || echo "$(srcdir)/")$(_STGT)" 23716fd348SMartin Matuskaelse 24716fd348SMartin Matuska @echo "skipping shellcheck of" $(_STGT) "because shellcheck is not installed" 25716fd348SMartin Matuskaendif 26716fd348SMartin Matuska 27716fd348SMartin Matuskashellcheck: $(SHELLCHECKSCRIPTS) $(call JUST_SHELLCHECK_OPTS,$(SHELLCHECKSCRIPTS)) 28716fd348SMartin Matuska 29716fd348SMartin Matuska 30716fd348SMartin MatuskaPHONY += checkbashisms 3116038816SMartin Matuska 3216038816SMartin Matuska# command -v *is* specified by POSIX and every shell in existence supports it 33716fd348SMartin Matuska_BTGT = $(subst ^,/,$(subst checkbashisms-here-,,$@)) 34716fd348SMartin Matuskacheckbashisms-here-%: 3516038816SMartin Matuskaif HAVE_CHECKBASHISMS 36716fd348SMartin Matuska ! { [ -n "$(SHELLCHECK_SHELL)" ] && echo '#!/bin/$(SHELLCHECK_SHELL)'; cat "$$([ -e "$(_BTGT)" ] || echo "$(srcdir)/")$(_BTGT)"; } | \ 37716fd348SMartin Matuska checkbashisms -npx 2>&1 | grep -vFe "'command' with option other than -p" -e 'command -v' -e 'any possible bashisms' $(CHECKBASHISMS_IGNORE) >&2 3816038816SMartin Matuskaelse 39716fd348SMartin Matuska @echo "skipping checkbashisms of" $(_BTGT) "because checkbashisms is not installed" 4016038816SMartin Matuskaendif 41716fd348SMartin Matuska 42716fd348SMartin Matuskacheckbashisms: $(SHELLCHECKSCRIPTS) $(call JUST_CHECKBASHISMS_OPTS,$(SHELLCHECKSCRIPTS)) 43