blob: fd3e4623175ab7cd1ec8a4dc5a46f06510d6aa3d [file] [log] [blame]
Joey Armstrong79bce362023-09-28 16:58:22 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2022-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##-------------------##
19##---] GLOBALS [---##
20##-------------------##
21lint-shell-dflt := $(venv-activate-bin)/shellcheck
22
23lint-shell-cmds += $(shell which shellcheck)
24lint-shell-cmds += $(lint-shell-dflt)
25lint-shell-cmds += /usr/bin/shellcheck
26
27lint-shell-cmd = \
28 $(strip \
29 $(firstword \
30 $(wildcard $(lint-shell-cmds)) \
31 $(lint-shell-dflt) \
32 ))
33lint-shell-cmd := $(venv-activate-bin)/shellcheck
34
35##-------------------##
36##---] TARGETS [---##
37##-------------------##
38
39## -----------------------------------------------------------------------
40## Intent: Display shellcheck command version string.
41## Note: As a side effect, install shellcheck by dependency
42## -----------------------------------------------------------------------
43## Verified: v0.8.0
44## -----------------------------------------------------------------------
45.PHONY: lint-shellcheck-cmd-version
46lint-shellcheck-cmd-version : $(lint-shell-cmd)
47
48 $(HIDE) echo
49 $< --version
50
51## -----------------------------------------------------------------------
52## Intent: Install shellcheck
53## -----------------------------------------------------------------------
54## Note: .venv/bin is somewhat odd for an install directory but:
55## o avoids existence and conflict problems with ./bin.
56## o auto-exclude from consideration by lint and test targets.
57## -----------------------------------------------------------------------
58## Verified: v0.8.0
59## -----------------------------------------------------------------------
60
61lint-shell-download = https://github.com/koalaman/shellcheck/releases/download/$(1)/shellcheck-$(1).$(2).x86_64.tar.xz
62
63lint-shell-downloads=\
64 $(call lint-shell-download,v0.9.0,darwin)\
65 $(call lint-shell-download,v0.9.0,linux)
66
67## -----------------------------------------------------------------------
68## Intent: Retrieve and install the shellcheck command.
69## -----------------------------------------------------------------------
70## Cannot pass wildcards to wget, download endpoint must be dynamic.
71## Attempts to glob using curl or wget returns "not found".
72## wget -r -l1 --no-parent -A.xz \
73## 'https://github.com/koalaman/shellcheck/releases/download/v0.9.0
74## -----------------------------------------------------------------------
75
76.PHONY: lint-shell-install
77lint-shell-install : $(lint-shell-cmd)
78$(lint-shell-cmd) :
79
80 $(call banner-enter,(Target $@))
81
82 $(call banner,(shellcheck: Download))
83 $(HIDE)wget --quiet --unlink $(lint-shell-downloads)
84 $(HIDE)umask 022 && mkdir -p $(dir $@)
85
86 $(call banner,(shellcheck: Unpack and install))
87 $(HIDE)case "$(uname -s)" in \
88 *arwin*) tar Jxf *darwin*.tar.xz -C $(dir $@) --strip-components=1 ;; \
89 *) tar Jxf *linux*.tar.xz -C $(dir $@) --strip-components=1 ;; \
90 esac
91
92 $(HIDE)$(RM) $(notdir $(lint-shell-downloads))
93
94 $(call banner-leave,(Target $@))
95
96## -----------------------------------------------------------------------
97## -----------------------------------------------------------------------
98sterile ::
99 $(RM) $(lint-shell-downloads)
100
101## -----------------------------------------------------------------------
102## Intent: Display command help
103## -----------------------------------------------------------------------
104lint-shell-help ::
105 @printf ' %-30s %s\n' 'lint-shell-install' \
106 'Install syntax checking tool shellcheck'
107 @printf ' %-30s %s\n' 'lint-shellcheck-cmd-version' \
108 'Library target able to display version of shellcheck command'
109
110# [EOF]