Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 6f046d0 | 2024-04-22 13:29:56 -0400 | [diff] [blame] | 3 | # Copyright 2022-2024 Open Networking Foundation Contributors |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -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 | # |
| 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. |
Joey Armstrong | 6f046d0 | 2024-04-22 13:29:56 -0400 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
| 17 | # SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ----------------------------------------------------------------------- |
Joey Armstrong | 6f046d0 | 2024-04-22 13:29:56 -0400 | [diff] [blame] | 20 | # Intent: Defined constants for makefile use |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 21 | # ----------------------------------------------------------------------- |
| 22 | |
| 23 | $(if $(DEBUG),$(warning ENTER)) |
| 24 | |
Joey Armstrong | 6f046d0 | 2024-04-22 13:29:56 -0400 | [diff] [blame] | 25 | ##-------------------## |
| 26 | ##---] GLOBALS [---## # export(s) are visible to sub-make calls |
| 27 | ##-------------------## |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 28 | export dot :=. |
| 29 | export null :=# |
Joey Armstrong | 6f046d0 | 2024-04-22 13:29:56 -0400 | [diff] [blame] | 30 | export comma := $(null),$(null) |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 31 | export space := $(null) $(null) |
Joey Armstrong | e98239c | 2023-05-08 17:10:07 -0400 | [diff] [blame] | 32 | export quote-single := $(null)'$(null)#' |
| 33 | export quote-double := $(null)"$(null)#" |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 34 | |
Joey Armstrong | c2094fc | 2023-11-17 15:16:27 -0500 | [diff] [blame] | 35 | ## ----------------------------- |
| 36 | ## Macro definition for tab stop |
| 37 | ## Usage: |
| 38 | ## o $(info white$(\t)space |
| 39 | ## o @echo "white$(tab)space" |
| 40 | ## ----------------------------- |
Joey Armstrong | 6f046d0 | 2024-04-22 13:29:56 -0400 | [diff] [blame] | 41 | \t := $(null) $(null) |
Joey Armstrong | c2094fc | 2023-11-17 15:16:27 -0500 | [diff] [blame] | 42 | tab := $(\t) |
| 43 | |
| 44 | ## ----------------------------------------------- |
| 45 | ## Macro definition for newline |
| 46 | ## Usage: |
| 47 | ## - Format output: |
| 48 | ## $(info two$(crlf)lines) |
| 49 | ## - Generate dynamic makefile rules: |
| 50 | ## $(eval mytarget:$(newline)$(tab)echo FOO) |
| 51 | ## ----------------------------------------------- |
| 52 | define crlf := |
| 53 | |
| 54 | |
| 55 | endef |
| 56 | newline := $(crlf) |
| 57 | |
| 58 | # ------------------------------------------------------ |
| 59 | # [DEBUG] - Define HIDE=<null> to display shell commands |
| 60 | # ------------------------------------------------------ |
| 61 | # Target rule definition: |
| 62 | # show: |
| 63 | # <tab>$(HIDE)echo "Display rule when HIDE != '@' |
| 64 | # ------------------------------------------------------ |
| 65 | # Usage: make show HIDE= |
| 66 | # ------------------------------------------------------ |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 67 | HIDE ?= @ |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 68 | |
Joey Armstrong | c2094fc | 2023-11-17 15:16:27 -0500 | [diff] [blame] | 69 | # ----------------------------------------------------------------------- |
| 70 | # Intent: Define a prefix macro for shell commands that will inhibit |
| 71 | # loading user defined environment vars (consistent command use w/o |
| 72 | # potential for per-user tainting of command behavior). |
| 73 | # ----------------------------------------------------------------------- |
| 74 | # Target usage: |
| 75 | # mytarget: |
| 76 | # <tab>$(env-clean) ls |
| 77 | # ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 78 | env-clean ?= /usr/bin/env --ignore-environment |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 79 | |
Joey Armstrong | c2094fc | 2023-11-17 15:16:27 -0500 | [diff] [blame] | 80 | # ----------------------------------------------------------------------- |
| 81 | # Intent: Define convenience xargs macros to shorten target command lines |
| 82 | # ----------------------------------------------------------------------- |
| 83 | # Target usage: |
| 84 | # mytarget: |
| 85 | # <tab>$(env-clean) ls |
| 86 | # ----------------------------------------------------------------------- |
| 87 | # Usage: |
| 88 | # lint-shell: |
| 89 | # <tab>find . -name '*.sh' -print0 | $(xargs-n1-clean) shellcheck $(args) |
| 90 | # ----------------------------------------------------------------------- |
Joey Armstrong | a532539 | 2024-04-02 13:22:12 -0400 | [diff] [blame] | 91 | xargs-cmd0 := xargs -0 --no-run-if-empty |
| 92 | xargs-cmd := $(xargs-cmd0) -t |
Joey Armstrong | f128de8 | 2023-09-08 17:05:18 -0400 | [diff] [blame] | 93 | xargs-n1 := $(xargs-cmd) -n1 |
| 94 | xargs-n1-clean := $(env-clean) $(xargs-n1) |
| 95 | xargs-cmd-clean := $(env-clean) $(xargs-cmd) |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 96 | |
| 97 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7ad5c36 | 2023-07-09 19:10:16 -0400 | [diff] [blame] | 98 | ## Intent: NOP command for targets whose dependencies do all heavy lifting |
| 99 | ## ----------------------------------------------------------------------- |
| 100 | ## usage: foo bar tans |
| 101 | ## <tab>$(nop-command) |
| 102 | ## ----------------------------------------------------------------------- |
| 103 | nop-cmd := : |
| 104 | |
| 105 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 0205d33 | 2023-04-11 17:29:23 -0400 | [diff] [blame] | 106 | ## Default shell: |
| 107 | ## o set -e enable error checking |
| 108 | ## o set -u report undefined errors |
| 109 | ## o set -o pipefail propogate shell pipeline failures. |
| 110 | ## ----------------------------------------------------------------------- |
| 111 | SHELL ?= /bin/bash |
| 112 | have-shell-bash := $(filter bash,$(subst /,$(space),$(SHELL))) |
| 113 | $(if $(have-shell-bash),$(null),\ |
| 114 | $(eval export SHELL := bash -euo pipefail)) |
| 115 | |
| 116 | export SHELL ?= bash -euo pipefail |
| 117 | |
| 118 | $(if $(DEBUG),$(warning LEAVE)) |
| 119 | |
| 120 | # [EOF] |