blob: 6670254f8cb980e2124c728af80d2a9591973db4 [file] [log] [blame]
Joey Armstrong0205d332023-04-11 17:29:23 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrong6f046d02024-04-22 13:29:56 -04003# Copyright 2022-2024 Open Networking Foundation Contributors
Joey Armstrong0205d332023-04-11 17:29:23 -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#
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 Armstrong6f046d02024-04-22 13:29:56 -040016# -----------------------------------------------------------------------
17# SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
Joey Armstrong0205d332023-04-11 17:29:23 -040018# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
Joey Armstrong6f046d02024-04-22 13:29:56 -040020# Intent: Defined constants for makefile use
Joey Armstrong0205d332023-04-11 17:29:23 -040021# -----------------------------------------------------------------------
22
23$(if $(DEBUG),$(warning ENTER))
24
Joey Armstrong6f046d02024-04-22 13:29:56 -040025##-------------------##
26##---] GLOBALS [---## # export(s) are visible to sub-make calls
27##-------------------##
Joey Armstrong0205d332023-04-11 17:29:23 -040028export dot :=.
29export null :=#
Joey Armstrong6f046d02024-04-22 13:29:56 -040030export comma := $(null),$(null)
Joey Armstrong0205d332023-04-11 17:29:23 -040031export space := $(null) $(null)
Joey Armstronge98239c2023-05-08 17:10:07 -040032export quote-single := $(null)'$(null)#'
33export quote-double := $(null)"$(null)#"
Joey Armstrong0205d332023-04-11 17:29:23 -040034
Joey Armstrongc2094fc2023-11-17 15:16:27 -050035## -----------------------------
36## Macro definition for tab stop
37## Usage:
38## o $(info white$(\t)space
39## o @echo "white$(tab)space"
40## -----------------------------
Joey Armstrong6f046d02024-04-22 13:29:56 -040041\t := $(null) $(null)
Joey Armstrongc2094fc2023-11-17 15:16:27 -050042tab := $(\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## -----------------------------------------------
52define crlf :=
53
54
55endef
56newline := $(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 Armstrong7ad5c362023-07-09 19:10:16 -040067HIDE ?= @
Joey Armstrong0205d332023-04-11 17:29:23 -040068
Joey Armstrongc2094fc2023-11-17 15:16:27 -050069# -----------------------------------------------------------------------
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 Armstrong0205d332023-04-11 17:29:23 -040078env-clean ?= /usr/bin/env --ignore-environment
Joey Armstrongf128de82023-09-08 17:05:18 -040079
Joey Armstrongc2094fc2023-11-17 15:16:27 -050080# -----------------------------------------------------------------------
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 Armstronga5325392024-04-02 13:22:12 -040091xargs-cmd0 := xargs -0 --no-run-if-empty
92xargs-cmd := $(xargs-cmd0) -t
Joey Armstrongf128de82023-09-08 17:05:18 -040093xargs-n1 := $(xargs-cmd) -n1
94xargs-n1-clean := $(env-clean) $(xargs-n1)
95xargs-cmd-clean := $(env-clean) $(xargs-cmd)
Joey Armstrong0205d332023-04-11 17:29:23 -040096
97## -----------------------------------------------------------------------
Joey Armstrong7ad5c362023-07-09 19:10:16 -040098## Intent: NOP command for targets whose dependencies do all heavy lifting
99## -----------------------------------------------------------------------
100## usage: foo bar tans
101## <tab>$(nop-command)
102## -----------------------------------------------------------------------
103nop-cmd := :
104
105## -----------------------------------------------------------------------
Joey Armstrong0205d332023-04-11 17:29:23 -0400106## 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## -----------------------------------------------------------------------
111SHELL ?= /bin/bash
112have-shell-bash := $(filter bash,$(subst /,$(space),$(SHELL)))
113$(if $(have-shell-bash),$(null),\
114 $(eval export SHELL := bash -euo pipefail))
115
116export SHELL ?= bash -euo pipefail
117
118$(if $(DEBUG),$(warning LEAVE))
119
120# [EOF]