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