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