From 327131c4c7e41d57aca9f54fd2706ae59d735aaa Mon Sep 17 00:00:00 2001 From: Leonardo Sandoval Date: Thu, 10 Sep 2020 12:18:27 -0500 Subject: build_macros.mk: include assert and define loop macros Loop macros make it easier for developers to include new variables to assert or define and also help code code readability on makefiles. Change-Id: I0d21d6e67b3eca8976c4d856ac8ccc02c8bb5ffa Signed-off-by: Leonardo Sandoval --- make_helpers/build_macros.mk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'make_helpers/build_macros.mk') diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 1c3d14d057..613fca23f6 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -44,6 +44,13 @@ define add_define DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) endef + +# Convenience function for addding multiple build definitions +# $(eval $(call add_defines,FOO BOO)) +define add_defines + $(foreach def,$1,$(eval $(call add_define,$(def)))) +endef + # Convenience function for adding build definitions # $(eval $(call add_define_val,FOO,BAR)) will have: # -DFOO=BAR @@ -57,6 +64,12 @@ define assert_boolean $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) endef +# Convenience function for verifying options have boolean values +# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values +define assert_booleans + $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) +endef + 0-9 := 0 1 2 3 4 5 6 7 8 9 # Function to verify that a given option $(1) contains a numeric value @@ -67,6 +80,12 @@ $(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) $(if $(__numeric),$(error $(1) must be numeric)) endef +# Convenience function for verifying options have numeric values +# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values +define assert_numerics + $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) +endef + # CREATE_SEQ is a recursive function to create sequence of numbers from 1 to # $(2) and assign the sequence to $(1) define CREATE_SEQ -- cgit v1.2.3