summaryrefslogtreecommitdiffstats
path: root/rules
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2019-10-03 17:28:19 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-10-03 18:48:11 +0200
commit013ae54851fa282d6636321f29abc445f2060530 (patch)
tree82b9492af633a27dff4ed7fb2253cddbb226baa5 /rules
parent90162a8149210a6cf883487209c40dc3c3f785d6 (diff)
downloadptxdist-013ae54851fa282d6636321f29abc445f2060530.tar.gz
ptxdist-013ae54851fa282d6636321f29abc445f2060530.tar.xz
ptxdist: improve variable printing
This adds a new 'printnext' command. It prints the value of the value of the variable. The print code is refactored to allow this. The make error must be parsed to determine which variable is undefined. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'rules')
-rw-r--r--rules/other/Toplevel.make48
1 files changed, 46 insertions, 2 deletions
diff --git a/rules/other/Toplevel.make b/rules/other/Toplevel.make
index ef410043d..857500d11 100644
--- a/rules/other/Toplevel.make
+++ b/rules/other/Toplevel.make
@@ -136,9 +136,53 @@ include $(PTX_DGEN_DEPS_POST)
# just the "print" target
# ----------------------------------------------------------------------------
+#
+# expand variable names
+# - if $(1) contains '%' then return all matching variables
+# otherwise if $(1) is a defined variable, then return it
+# - if no match is found generate an error or return $(1) if make is
+# called with '-k'
+#
+define ptx/check-expand
+$(or $(filter $(1),$(.VARIABLES)),$(if $(filter k,$(MAKEFLAGS)),$(1),$(error ##$(1)##)))
+endef
+
+#
+# print the given variable
+# if PTXDIST_VERBOSE=1 then prefix it with '<name>='
+#
+define ptx/print-var
+$(info $(if $(filter 1,$(PTXDIST_VERBOSE)),$(1)=)$(call add_quote,$($(1))))
+endef
+
+#
+# expand $(1) to one or more variables and print each one
+#
+define ptx/print-vars
+$(foreach v,$(call ptx/check-expand,$(1)),$(call ptx/print-var,$(v)))
+endef
+
+#
+# Pattern target to allow printing variable
+# $(filter ..) is used to match against all existing variables so patterns
+# containing '%' can be uses to print multiple variables.
+# In verbose mode, '<name>=<value>' is printed.
+# Trying to print undefined variables results in an error unless '-k' is
+# used. In this case an empty value is printed.
+#
/print-%: FORCE
- @:$(foreach v,$(or $(filter $(*),$(.VARIABLES)),$(if $(filter k,$(MAKEFLAGS)),$(*),$(error $(*) undefined))),\
- $(info $(if $(filter 1,$(PTXDIST_VERBOSE)),$(v)=)$(call add_quote,$($(v)))))
+ @:$(call ptx/print-vars,$(*))
+
+#
+# As above but tread the variable value as another variable and prints
+# the value of this variable.
+# Patterns are expanded as above on both levels.
+# Printing stops at the first error.
+#
+/printnext-%: FORCE
+ @:$(foreach v,$(call ptx/check-expand,$(*)),\
+ $(foreach vv,$($(v)),\
+ $(call ptx/print-vars,$(vv))))
# for backwards compatibility
print-%: /print-%