shell.mk 906 B

1234567891011121314151617181920212223
  1. SHELL_FILES_DIRECTORIES ?= .
  2. SHELL_FILES_ALL ?= $(shell \
  3. find $(SHELL_FILES_DIRECTORIES) -type f -perm /a+x \
  4. | grep -vE "/(\.git|debian/.*)/" \
  5. | xargs grep -lI '^\#!/bin/.*sh' \
  6. )
  7. SHELL_FILES_DASH ?= $(shell echo "$(SHELL_FILES_ALL)" | xargs grep -l '^\#!/bin/sh$$')
  8. SHELL_FILES_BASH ?= $(shell echo "$(SHELL_FILES_ALL)" | xargs grep -l '^\#!/bin/bash$$')
  9. SHELLCHECK_BIN ?= $(shell which shellcheck)
  10. # we allow external scripts to be sourced
  11. SHELLCHECK_ARGS ?= -x
  12. .PHONY: lint
  13. lint: lint-shell
  14. .PHONY: lint-shell
  15. lint-shell:
  16. @if [ -z "$(SHELLCHECK_BIN)" ]; then echo >&2 "Missing 'shellcheck' command. Maybe you want to disable checks via DISABLE_SHELL_CHECK=1."; false; fi
  17. @if [ -n "$(SHELL_FILES_BASH)" ]; then "$(SHELLCHECK_BIN)" $(SHELLCHECK_ARGS) $(SHELL_FILES_BASH); fi
  18. @if [ -n "$(SHELL_FILES_DASH)" ]; then "$(SHELLCHECK_BIN)" --shell dash $(SHELLCHECK_ARGS) $(SHELL_FILES_DASH); fi