blob: 3c04539d67ea2a4cc7358d4c22655dd9135fae0a [file] [log] [blame]
Joey Armstrong36592e32022-11-28 09:00:28 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong4de98b72023-02-09 14:51:38 -05003# Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong36592e32022-11-28 09:00:28 -05004#
Joey Armstrong4de98b72023-02-09 14:51:38 -05005# Licensed under the Apache License, Version 2.0 (the "License")
Joey Armstrong36592e32022-11-28 09:00:28 -05006# 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 Armstrong4de98b72023-02-09 14:51:38 -050018$(if $(DEBUG),$(warning ENTER))
Joey Armstrong36592e32022-11-28 09:00:28 -050019
Joey Armstrong4de98b72023-02-09 14:51:38 -050020##-------------------##
21##---] GLOBALS [---##
22##-------------------##
23.PHONY: lint-shell lint-shell-all lint-shell-modified
Joey Armstronga8bc8e12022-12-04 07:06:59 -050024
Joey Armstrong4de98b72023-02-09 14:51:38 -050025have-shell-sources := $(if $(strip $(SHELL_SOURCES)),true)
26SHELL_SOURCES ?= $(error SHELL_SOURCES= required)
Joey Armstronga8bc8e12022-12-04 07:06:59 -050027
Joey Armstrong4de98b72023-02-09 14:51:38 -050028## -----------------------------------------------------------------------
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
Joey Armstronga8bc8e12022-12-04 07:06:59 -050071 shellcheck --version
Joey Armstrong4de98b72023-02-09 14:51:38 -050072 @echo
Joey Armstronga8bc8e12022-12-04 07:06:59 -050073
Joey Armstrong4de98b72023-02-09 14:51:38 -050074## -----------------------------------------------------------------------
75## Intent: Display command usage
76## -----------------------------------------------------------------------
Joey Armstronga8bc8e12022-12-04 07:06:59 -050077help::
Joey Armstrong4de98b72023-02-09 14:51:38 -050078 @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 Armstrong36592e32022-11-28 09:00:28 -050086
87# [EOF]