Joey Armstrong | 79bce36 | 2023-09-28 16:58:22 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 3 | # Copyright 2022-2024 Open Networking Foundation Contributors |
Joey Armstrong | 79bce36 | 2023-09-28 16:58:22 -0400 | [diff] [blame] | 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 | # |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
Joey Armstrong | 79bce36 | 2023-09-28 16:58:22 -0400 | [diff] [blame] | 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 | # ----------------------------------------------------------------------- |
Joey Armstrong | dc04c93 | 2024-04-01 12:14:21 -0400 | [diff] [blame] | 17 | # SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
| 20 | # Intent: |
| 21 | # ----------------------------------------------------------------------- |
Joey Armstrong | 79bce36 | 2023-09-28 16:58:22 -0400 | [diff] [blame] | 22 | |
| 23 | ##-------------------## |
| 24 | ##---] GLOBALS [---## |
| 25 | ##-------------------## |
| 26 | lint-shell-dflt := $(venv-activate-bin)/shellcheck |
| 27 | |
| 28 | lint-shell-cmds += $(shell which shellcheck) |
| 29 | lint-shell-cmds += $(lint-shell-dflt) |
| 30 | lint-shell-cmds += /usr/bin/shellcheck |
| 31 | |
| 32 | lint-shell-cmd = \ |
| 33 | $(strip \ |
| 34 | $(firstword \ |
| 35 | $(wildcard $(lint-shell-cmds)) \ |
| 36 | $(lint-shell-dflt) \ |
| 37 | )) |
| 38 | lint-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 |
| 51 | lint-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 | |
| 66 | lint-shell-download = https://github.com/koalaman/shellcheck/releases/download/$(1)/shellcheck-$(1).$(2).x86_64.tar.xz |
| 67 | |
| 68 | lint-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 |
| 82 | lint-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 | ## ----------------------------------------------------------------------- |
| 103 | sterile :: |
Joey Armstrong | f2f0a3f | 2024-04-04 15:50:09 -0400 | [diff] [blame] | 104 | $(RM) $(notdir $(lint-shell-downloads)) |
Joey Armstrong | 79bce36 | 2023-09-28 16:58:22 -0400 | [diff] [blame] | 105 | |
| 106 | ## ----------------------------------------------------------------------- |
| 107 | ## Intent: Display command help |
| 108 | ## ----------------------------------------------------------------------- |
| 109 | lint-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] |