Bulk filter undef vars to support makefile target lint-make
makefiles/include.mk
makefiles/lint/make/include.mk
makefiles/lint/make/makefile.mk
-------------------------------
o Move lint-make target logic into makefiles/lint/make/
makefiles/lint/make/warn-undef-vars.mk
--------------------------------------
o Volume undef warnings plague makefile linting.
o Makefile logic cleanup needed but in the interim valid-but-undef
vars are defined as "var := $(null)". This helps shorten the
error log so lint-make can be used as a default lint target.
Change-Id: I48a0c6b2c71cf1dd5a6554cc5823502ed88482d0
diff --git a/makefiles/lint/make/include.mk b/makefiles/lint/make/include.mk
new file mode 100644
index 0000000..2f49e88
--- /dev/null
+++ b/makefiles/lint/make/include.mk
@@ -0,0 +1,33 @@
+# -*- 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-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# https://gerrit.opencord.org/plugins/gitiles/onf-make
+# ONF.makefile.version = 1.2
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+## Bleeding early import handled by makefiles/include.mk
+# include $(ONF_MAKEDIR)/lint/make/warn-undef-vars.mk
+
+include $(ONF_MAKEDIR)/lint/make/makefile.mk
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/lint/make/makefile.mk b/makefiles/lint/make/makefile.mk
new file mode 100644
index 0000000..27206e0
--- /dev/null
+++ b/makefiles/lint/make/makefile.mk
@@ -0,0 +1,65 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-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.
+# -----------------------------------------------------------------------
+
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
+xargs-n1-local := $(subst -t,$(null),$(xargs-n1))# inhibit cmd display
+
+# Gather sources to check
+# TODO: implement deps, only check modified files
+make-check-find := find . -name 'vendor' -prune
+make-check-find += -o \( -iname makefile -o -name '*.mk' \)
+make-check-find += -type f -print0
+
+make-check := $(MAKE)
+
+make-check-args += --dry-run
+make-check-args += --keep-going
+make-check-args += --warn-undefined-variables
+make-check-args += --no-print-directory
+
+# Quiet internal undef vars
+make-check-args += DEBUG=
+
+##-------------------##
+##---] TARGETS [---##
+##-------------------##
+ifndef NO-LINT-MAKEFILE
+ lint : lint-make
+endif
+
+## -----------------------------------------------------------------------
+## Intent: Perform a lint check on makefile sources
+## -----------------------------------------------------------------------
+lint-make-ignore += JSON_FILES=
+lint-make-ignore += YAML_FILES=
+lint-make:
+ @echo
+ @echo "** -----------------------------------------------------------------------"
+ @echo "** Makefile syntax checking"
+ @echo "** -----------------------------------------------------------------------"
+ $(HIDE)$(env-clean) $(make-check-find) \
+ | $(xargs-n1-local) $(make-check) $(make-check-args) $(lint-make-ignore)
+
+## -----------------------------------------------------------------------
+## Intent: Display command help
+## -----------------------------------------------------------------------
+help-summary ::
+ @echo ' lint-make Syntax check [Mm]akefile and *.mk'
+
+# [EOF]
diff --git a/makefiles/lint/make/warn-undef-vars.mk b/makefiles/lint/make/warn-undef-vars.mk
new file mode 100644
index 0000000..048d56d
--- /dev/null
+++ b/makefiles/lint/make/warn-undef-vars.mk
@@ -0,0 +1,71 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 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: 2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+## -----------------------------------------------------------------------
+## Intent: Target lint-make* undef var warnings:
+## o This helper makefile defines var := $(null) for known variables.
+## o Definitions only exist for lint target use.
+## o Decrease warning volume until undef sources can be cleaned up.
+## -----------------------------------------------------------------------
+$(if $(findstring --warn-undefined-variables,$(MAKEFLAGS)),\
+ $(eval IS-WARN-UNDEFINED-VARIABLES := true))
+
+ifdef IS-WARN-UNDEFINED-VARIABLES
+ export null :=#
+
+ # ----------------------------------------
+ # Helper macro
+ # Usage: $(call define-if-undef,{varname})
+ # ----------------------------------------
+ define-if-undef =\
+ $(if $(findstring undef,$(flavor $(1))),\
+ $(if $(DEBUG),$(info ** $$(eval export $(1) := $$(null))))\
+ $(eval export $(1) := $(null))\
+ )
+
+ # ----------------------------------------------
+ # Faux defines used to shorten lint error volume
+ # ----------------------------------------------
+ $(call define-if-undef,WORKSPACE)# Jenkins: yes, interactive: no
+ $(call define-if-undef,NULL)# s/NULL/null
+ $(call define-if-undef,UNSTABLE)# enable raw bulk warnings for pylint
+ $(call define-if-undef,JJB_DEBUG)
+
+ # Helpers for transition of local makefiles to repo:onf-make
+ $(call define-if-undef,USE-ONF-DOCKER-MK)
+ $(call define-if-undef,USE-ONF-GERRIT-MK)
+ $(call define-if-undef,USE-VOLTHA-RELEASE-MK)
+
+ # ------------------------------------------------------------------
+ # Future make:
+ # o detect available sources
+ # o enable features based on source detection
+ # o conditional makefile library loading based on source detection
+ # ------------------------------------------------------------------
+ $(call define-if-undef,DOC8_SOURCE)
+ $(call define-if-undef,have-python-files)
+
+endif # IS-WARN-UNDEFINED-VARIABLES
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]