blob: 86e91c3819b6bef7f2762afb019c28ad6b7c9676 [file] [log] [blame]
Joey Armstrong6b58fd42023-04-12 17:45:53 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
4#
5# Licensed under the Apache License, Version 2.0 (the "License")
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
18$(if $(DEBUG),$(warning ENTER))
19
20##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23.PHONY: lint-shell lint-shell-all lint-shell-modified
24
25have-shell-sources := $(if $(strip $(SHELL_SOURCES)),true)
26SHELL_SOURCES ?= $(error SHELL_SOURCES= required)
27
28## -----------------------------------------------------------------------
29## Intent: Use the shell command to perform syntax checking.
30## % make lint
31## % make lint-shell-all
32## -----------------------------------------------------------------------
33ifndef NO-LINT-SHELL
34 lint-shell-mode := $(if $(have-shell-sources),modified,all)
35 lint : lint-shell-$(lint-shell-mode)
36endif# NO-LINT-SHELL
37
38## -----------------------------------------------------------------------
39## Intent: exhaustive shell syntax checking
40## -----------------------------------------------------------------------
41shellcheck-find-args := $(null)
42shellcheck-find-args += -name '$(venv-name)'
43shellcheck-find-args += -o -name 'staging'
44lint-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## -----------------------------------------------------------------------
55lint-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
64lint-shellcheck-install:
65 @echo
66 @echo "** -----------------------------------------------------------------------"
67 @echo '** command shell syntax checking'
68 @echo "** -----------------------------------------------------------------------"
69
70 # {apt-get,rpm,yum} install shellcheck
71 shellcheck --version
72 @echo
73
74## -----------------------------------------------------------------------
75## Intent: Display command usage
76## -----------------------------------------------------------------------
77help::
78 @echo ' lint-shell Syntax check sources using shellcheck'
79
80help-verbose += help-shell-verbose
81help-shell-verbose:
82 @echo
83 @echo ' $(MAKE) lint-shell SHELL_SOURCES=...'
84 @echo ' lint-shell-modified shell checking: only modified'
85 @echo ' lint-shell-all shell checking: exhaustive'
86
87$(if $(DEBUG),$(warning LEAVE))
88
89# [EOF]