2022-04-09 05:09:55 +03:00
|
|
|
# Global ShellCheck exclusions:
|
2022-02-07 22:59:09 +03:00
|
|
|
#
|
|
|
|
# ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090]
|
|
|
|
# Not following: a was not specified as input (see shellcheck -x). [SC1091]
|
|
|
|
# Prefer putting braces around variable references even when not strictly required. [SC2250]
|
2022-11-12 15:22:49 +03:00
|
|
|
# Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore). [SC2312]
|
2023-07-21 21:53:06 +03:00
|
|
|
# Command appears to be unreachable. Check usage (or ignore if invoked indirectly). [SC2317]
|
2022-02-07 22:59:09 +03:00
|
|
|
# In POSIX sh, 'local' is undefined. [SC2039] # older ShellCheck versions
|
|
|
|
# In POSIX sh, 'local' is undefined. [SC3043] # newer ShellCheck versions
|
2022-04-09 05:09:55 +03:00
|
|
|
|
|
|
|
SHELLCHECKSCRIPTS =
|
|
|
|
|
|
|
|
JUST_SHELLCHECK_OPTS = $(addprefix shellcheck-here-,$(subst /,^,$(1)))
|
|
|
|
JUST_CHECKBASHISMS_OPTS = $(addprefix checkbashisms-here-,$(subst /,^,$(1)))
|
|
|
|
SHELLCHECK_OPTS = $(call JUST_SHELLCHECK_OPTS,$(1)) $(call JUST_CHECKBASHISMS_OPTS,$(1))
|
|
|
|
|
2022-04-10 03:46:19 +03:00
|
|
|
PHONY += shellcheck
|
2022-04-09 05:09:55 +03:00
|
|
|
|
|
|
|
_STGT = $(subst ^,/,$(subst shellcheck-here-,,$@))
|
|
|
|
shellcheck-here-%:
|
2021-05-22 00:43:38 +03:00
|
|
|
if HAVE_SHELLCHECK
|
2023-07-21 21:53:06 +03:00
|
|
|
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)"
|
2021-05-22 00:43:38 +03:00
|
|
|
else
|
2022-04-09 05:09:55 +03:00
|
|
|
@echo "skipping shellcheck of" $(_STGT) "because shellcheck is not installed"
|
2021-05-22 00:43:38 +03:00
|
|
|
endif
|
2022-04-09 05:09:55 +03:00
|
|
|
|
2022-04-10 03:46:19 +03:00
|
|
|
shellcheck: $(SHELLCHECKSCRIPTS) $(call JUST_SHELLCHECK_OPTS,$(SHELLCHECKSCRIPTS))
|
2021-05-22 02:45:40 +03:00
|
|
|
|
2022-04-09 05:09:55 +03:00
|
|
|
|
2022-04-10 03:46:19 +03:00
|
|
|
PHONY += checkbashisms
|
2022-04-09 05:09:55 +03:00
|
|
|
|
2021-05-22 02:45:40 +03:00
|
|
|
# command -v *is* specified by POSIX and every shell in existence supports it
|
2022-04-09 05:09:55 +03:00
|
|
|
_BTGT = $(subst ^,/,$(subst checkbashisms-here-,,$@))
|
|
|
|
checkbashisms-here-%:
|
2021-05-22 02:45:40 +03:00
|
|
|
if HAVE_CHECKBASHISMS
|
2022-04-09 05:09:55 +03:00
|
|
|
! { [ -n "$(SHELLCHECK_SHELL)" ] && echo '#!/bin/$(SHELLCHECK_SHELL)'; cat "$$([ -e "$(_BTGT)" ] || echo "$(srcdir)/")$(_BTGT)"; } | \
|
|
|
|
checkbashisms -npx 2>&1 | grep -vFe "'command' with option other than -p" -e 'command -v' -e 'any possible bashisms' $(CHECKBASHISMS_IGNORE) >&2
|
2021-05-22 02:45:40 +03:00
|
|
|
else
|
2022-04-09 05:09:55 +03:00
|
|
|
@echo "skipping checkbashisms of" $(_BTGT) "because checkbashisms is not installed"
|
2021-05-22 02:45:40 +03:00
|
|
|
endif
|
2022-04-09 05:09:55 +03:00
|
|
|
|
2022-04-10 03:46:19 +03:00
|
|
|
checkbashisms: $(SHELLCHECKSCRIPTS) $(call JUST_CHECKBASHISMS_OPTS,$(SHELLCHECKSCRIPTS))
|