Joey Armstrong | 79bce36 | 2023-09-28 16:58:22 -0400 | [diff] [blame] | 1 | # -*- 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 | ##-------------------## |
| 21 | lint-shell-dflt := $(venv-activate-bin)/shellcheck |
| 22 | |
| 23 | lint-shell-cmds += $(shell which shellcheck) |
| 24 | lint-shell-cmds += $(lint-shell-dflt) |
| 25 | lint-shell-cmds += /usr/bin/shellcheck |
| 26 | |
| 27 | lint-shell-cmd = \ |
| 28 | $(strip \ |
| 29 | $(firstword \ |
| 30 | $(wildcard $(lint-shell-cmds)) \ |
| 31 | $(lint-shell-dflt) \ |
| 32 | )) |
| 33 | lint-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 |
| 46 | lint-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 | |
| 61 | lint-shell-download = https://github.com/koalaman/shellcheck/releases/download/$(1)/shellcheck-$(1).$(2).x86_64.tar.xz |
| 62 | |
| 63 | lint-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 |
| 77 | lint-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 | ## ----------------------------------------------------------------------- |
| 98 | sterile :: |
| 99 | $(RM) $(lint-shell-downloads) |
| 100 | |
| 101 | ## ----------------------------------------------------------------------- |
| 102 | ## Intent: Display command help |
| 103 | ## ----------------------------------------------------------------------- |
| 104 | lint-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] |