Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 3 | # Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 4 | # |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the "License") |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ----------------------------------------------------------------------- |
| 17 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 18 | $(if $(DEBUG),$(warning ENTER)) |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 19 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
| 23 | .PHONY: lint-shell lint-shell-all lint-shell-modified |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 24 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 25 | have-shell-sources := $(if $(strip $(SHELL_SOURCES)),true) |
| 26 | SHELL_SOURCES ?= $(error SHELL_SOURCES= required) |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 27 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 28 | ## ----------------------------------------------------------------------- |
| 29 | ## Intent: Use the shell command to perform syntax checking. |
| 30 | ## % make lint |
| 31 | ## % make lint-shell-all |
| 32 | ## ----------------------------------------------------------------------- |
| 33 | ifndef NO-LINT-SHELL |
| 34 | lint-shell-mode := $(if $(have-shell-sources),modified,all) |
| 35 | lint : lint-shell-$(lint-shell-mode) |
| 36 | endif# NO-LINT-SHELL |
| 37 | |
| 38 | ## ----------------------------------------------------------------------- |
| 39 | ## Intent: exhaustive shell syntax checking |
| 40 | ## ----------------------------------------------------------------------- |
| 41 | shellcheck-find-args := $(null) |
| 42 | shellcheck-find-args += -name '$(venv-name)' |
| 43 | shellcheck-find-args += -o -name 'staging' |
| 44 | lint-shell-all: |
| 45 | $(MAKE) --no-print-directory lint-shellcheck-install |
| 46 | |
| 47 | find . \( $(shellcheck-find-args) \) -prune -name '*.sh' -print0 \ |
| 48 | | $(xargs-n1-clean) shellcheck |
| 49 | |
| 50 | ## ----------------------------------------------------------------------- |
| 51 | ## Intent: check deps for format and python3 cleanliness |
| 52 | ## Note: |
| 53 | ## shell --py3k option no longer supported |
| 54 | ## ----------------------------------------------------------------------- |
| 55 | lint-shell-modified: |
| 56 | $(MAKE) --no-print-directory lint-shell-install |
| 57 | |
| 58 | shellcheck $(SHELL_SOURCES) |
| 59 | |
| 60 | ## ----------------------------------------------------------------------- |
| 61 | ## Intent: |
| 62 | ## ----------------------------------------------------------------------- |
| 63 | .PHONY: lint-shellcheck-install |
| 64 | lint-shellcheck-install: |
| 65 | @echo |
| 66 | @echo "** -----------------------------------------------------------------------" |
| 67 | @echo '** command shell syntax checking' |
| 68 | @echo "** -----------------------------------------------------------------------" |
| 69 | |
| 70 | # {apt-get,rpm,yum} install shellcheck |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 71 | shellcheck --version |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 72 | @echo |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 73 | |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 74 | ## ----------------------------------------------------------------------- |
| 75 | ## Intent: Display command usage |
| 76 | ## ----------------------------------------------------------------------- |
Joey Armstrong | a8bc8e1 | 2022-12-04 07:06:59 -0500 | [diff] [blame] | 77 | help:: |
Joey Armstrong | 4de98b7 | 2023-02-09 14:51:38 -0500 | [diff] [blame] | 78 | @echo ' lint-shell Syntax check sources using shellcheck' |
| 79 | ifdef VERBOSE |
| 80 | @echo ' $(MAKE) lint-shell SHELL_SOURCES=...' |
| 81 | @echo ' lint-shell-modified shell checking: only modified' |
| 82 | @echo ' lint-shell-all shell checking: exhaustive' |
| 83 | endif |
| 84 | |
| 85 | $(if $(DEBUG),$(warning LEAVE)) |
Joey Armstrong | 36592e3 | 2022-11-28 09:00:28 -0500 | [diff] [blame] | 86 | |
| 87 | # [EOF] |