Added library helper functions. Docker is-tty, append semi-colon so bash will not complain about an incomplete line
Change-Id: I94d1b39910b8b437788438fd38931866763d0508
diff --git a/makefiles/bootstrap.mk b/makefiles/bootstrap.mk
new file mode 100644
index 0000000..eec469b
--- /dev/null
+++ b/makefiles/bootstrap.mk
@@ -0,0 +1,80 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Intent: Dependency-free macros used to source library makefiles
+# and define the build environment.
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG-bootstrap_mk),$(warning ENTER))
+
+##---------------------##
+##---] CONSTANTS [---##
+##---------------------##
+is-false = $(if $(1),true,$(null))
+is-true = $(if $(1),$(null),true)
+
+##--------------------------##
+##---] LIBRARY MACROS [---##
+##--------------------------##
+is-null = $(if $(1),$(null),$(error $(1)= is undef))
+# is-null-var = $(if $($(1)),$(null),$(error $(1)= is undef))
+
+## [origin]
+## foreach: var=automatic, origin=undef
+is-null-var-orig = $(strip \
+ $(foreach varname,$(1),\
+ $(warning ** is-null-var: varname=$(varname), origin=$(origin 1), origin=$(origin var))\
+ )\
+)
+# $(if $(1),$(call is-null-var-indirect,$($(1))),$(error $(1)= is undef)))\
+
+is-null-var-indirect = $(if $(1),$(null),$(error $(1)= is undef))
+
+# origin - undefned
+# default
+# environment
+# environment override
+# automatic
+# null(blah) ? - true
+
+## -----------------------------------------------------------------------
+## Intent: Given an indirect var containing varname of a makefile *_ROOT
+## parent director, derive a *_MKDIR variable and conditionally
+## include the makefile hierarchy.
+## -----------------------------------------------------------------------
+## Given:
+## o var containing OPT_ROOT=path
+## Return:
+## o OPT_MKDIR=$(OPT_ROOT)/makefiles
+## o If exists include $(OPT_MKDIR)/include.mk
+## -----------------------------------------------------------------------
+# library-include := $(call mk-library-include,blah)
+
+mk-library-include=$(strip \
+ $(warning mk-library-include: $$1[$(1)] = [$($(1))]))\
+ $(call is-null-var,1)\
+ $(foreach var,$($(1)),\
+ $(info var=$(var) is-null=$(call is-null-var,var))\
+ $(foreach val,$$(var),\
+ $(info val=$(val))\
+ $(foreach makedir,$(subst _ROOT,_MKDIR,$(var)),\
+$(warning makedir=$(makedir))\
+)\
+)\
+)\
+)
+
+
+# $(warning makedir=$(makedir))\
+ $(if $($(makedir)),$(null),\
+ $(eval $(makedir)=$$$$($(var))/makefiles)\
+$(warning $(makedir) = $($($(makedir))))\
+$(info $$(wildcard $(val)/makefiles/include.mk) = $(wildcard $(val)/makefiles/include.mk))\
+ $(foreach mf,$(wildcard $(wildcard $(val)/makefiles/include.mk)),\
+$(warning $$(eval include $(mf)))\
+ $(eval include $(mf)))\
+))))\
+)
+
+$(if $(DEBUG-bootstrap_mk),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/consts.mk b/makefiles/consts.mk
index c1306ac..8961b3a 100644
--- a/makefiles/consts.mk
+++ b/makefiles/consts.mk
@@ -31,13 +31,21 @@
export quote-double := $(null)"$(null)#"
# [DEBUG] make {target} HIDE=
-HIDE ?= @
+HIDE ?= @
env-clean ?= /usr/bin/env --ignore-environment
xargs-n1 := xargs -0 -t -n1 --no-run-if-empty
xargs-n1-clean := $(env-clean) $(xargs-n1)
## -----------------------------------------------------------------------
+## Intent: NOP command for targets whose dependencies do all heavy lifting
+## -----------------------------------------------------------------------
+## usage: foo bar tans
+## <tab>$(nop-command)
+## -----------------------------------------------------------------------
+nop-cmd := :
+
+## -----------------------------------------------------------------------
## Default shell:
## o set -e enable error checking
## o set -u report undefined errors
diff --git a/makefiles/docker/include.mk b/makefiles/docker/include.mk
index 48e20ca..0e53629 100644
--- a/makefiles/docker/include.mk
+++ b/makefiles/docker/include.mk
@@ -26,7 +26,13 @@
docker-run = docker run --rm $(docker-iam)# # Docker command stem
docker-run-is = $(docker-run) $(is-stdin) # Attach streams when interactive
docker-run-app = $(docker-run-is) -v ${CURDIR}:/app# # w/filesystem mount
-is-stdin = $(shell test -t 0 && echo "-it")
+
+# -----------------------------------------------------------------------
+# --interactive: Attach streams when stdout (fh==0) defined
+# --tty : Always create a pseudo-tty else jenkins:docker is silent
+# -----------------------------------------------------------------------
+is-stdin = $(shell test -t 0 && { echo '--interactive'; })
+is-stdin += --tty
voltha-protos-v5 ?= /go/src/github.com/opencord/voltha-protos/v5
diff --git a/makefiles/etc/include.mk b/makefiles/etc/include.mk
new file mode 100644
index 0000000..a48b42c
--- /dev/null
+++ b/makefiles/etc/include.mk
@@ -0,0 +1,48 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-2023 Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-FileCopyrightText: 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Usage:
+#
+# mytarget:
+# $(call banner-enter,target $@)
+# @echo "Hello World"
+# $(call banner-leave,target $@)
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+target-banner = ** ---------------------------------------------------------------------------
+
+## -----------------------------------------------------------------------
+## Intent: Return a command line able to display a banner hilighting
+## make target processing within a logfile.
+## -----------------------------------------------------------------------
+banner-enter=\
+ @echo -e \
+ "\n"\
+ "$(target-banner)\n"\
+ "** $(MAKE) ENTER: $(1)\n"\
+ "$(target-banner)"\
+
+banner-leave=\
+ @echo -e "** $(MAKE) LEAVE: $(1)"
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/help/header.mk b/makefiles/help/header.mk
new file mode 100644
index 0000000..021ac0d
--- /dev/null
+++ b/makefiles/help/header.mk
@@ -0,0 +1,6 @@
+# -*- makefile -*-
+
+help :
+ @echo "Usage: make [options] [target] ..."
+ @echo "Targets:"
+ @echo " help This message"
diff --git a/makefiles/include.mk b/makefiles/include.mk
index 2f2e422..806020a 100644
--- a/makefiles/include.mk
+++ b/makefiles/include.mk
@@ -18,19 +18,23 @@
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
+ifndef mk-include--onf-make
+
$(if $(DEBUG),$(warning ENTER))
TOP ?= .
MAKEDIR ?= $(TOP)/makefiles
ONF_ROOT ?= $(TOP)/../onf-make/makefiles
-ONF_MAKEDIR := $(ONF_ROOT)/makefiles
+ONF_MAKEDIR ?= $(ONF_ROOT)/makefiles
ONF_MAKE ?= $(MAKEDIR)# fix this -- two distinct makefiles/ directories are needed
ONF_MAKE ?= $(error ONF_MAKE= is required)
include $(ONF_MAKE)/consts.mk
-include $(ONF_MAKE)/help/include.mk
+include $(ONF_MAKE)/help/include.mk # render target help
+include $(ONF_MAKE)/utils/include.mk # dependency-less helper macros
+include $(ONF_MAKE)/etc/include.mk # banner macros
include $(ONF_MAKE)/virtualenv.mk# # lint-{jjb,python} depends on venv
include $(ONF_MAKE)/lint/include.mk
@@ -40,6 +44,11 @@
include $(ONF_MAKE)/todo.mk
include $(ONF_MAKE)/help/variables.mk
+##---------------------##
+##---] ON_DEMAND [---##
+##---------------------##
+$(if $(USE_DOCKER_MK),$(eval $(ONF_MAKE)/docker/include.mk))
+
##-------------------##
##---] TARGETS [---##
##-------------------##
@@ -58,4 +67,8 @@
## [... include *.mk ...]
## include makefiles/main/leave.mk
+mk-include--onf-make := true
+
+endif # mk-include--onf-make
+
# [EOF]
diff --git a/makefiles/utils/include.mk b/makefiles/utils/include.mk
new file mode 100644
index 0000000..84f684b
--- /dev/null
+++ b/makefiles/utils/include.mk
@@ -0,0 +1,29 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-FileCopyrightText: 2022 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+# usage: $(call if-not,false,5)
+if-not = $(info 1=$(1), 2=$(2), 3=$(3))\
+ $(if $(1),$(null),$(2))
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/utils/test/makefile b/makefiles/utils/test/makefile
new file mode 100644
index 0000000..a148cfa
--- /dev/null
+++ b/makefiles/utils/test/makefile
@@ -0,0 +1,9 @@
+# -*- makefile -*-
+
+include ../include.mk
+
+all:
+
+test ::
+ @echo "Testing if-not"
+ @echo $(call if-not,$(null),true,false)