diff options
author | Chris Sarbora <sarbs@cyngn.com> | 2014-12-17 14:41:04 -0800 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-06 18:04:03 -0700 |
commit | c295a2f7d175dc9b17efabb777599029a6243012 (patch) | |
tree | 5c2f5c6d7160fc08053da94d6206600019df6dfd /core/product.mk | |
parent | f5839e68470e9d7dc4e6f251b8f75783625aa6d3 (diff) | |
download | build-c295a2f7d175dc9b17efabb777599029a6243012.zip build-c295a2f7d175dc9b17efabb777599029a6243012.tar.gz build-c295a2f7d175dc9b17efabb777599029a6243012.tar.bz2 |
Allow finer control over how product variables are inherited.
Change-Id: I3abc22eea94293d1d0ebf0a81b396ebea0baf5a8
(cherry picked from commit 29357f5ea1dd8507f70efc330b2e5966d13504e8)
Diffstat (limited to 'core/product.mk')
-rw-r--r-- | core/product.mk | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/core/product.mk b/core/product.mk index be0e219..03490ca 100644 --- a/core/product.mk +++ b/core/product.mk @@ -127,23 +127,65 @@ $(foreach p,$(PRODUCTS),$(call dump-product,$(p))) endef # +# Internal function. Appends inherited product variables to an existing one. +# +# $(1): Product variable to operate on +# $(2): Value to append +# +define inherit-product_append-var + $(eval $(1) := $($(1)) $(INHERIT_TAG)$(strip $(2))) +endef + +# +# Internal function. Prepends inherited product variables to an existing one. +# +# $(1): Product variable to operate on +# $(2): Value to prepend +# +define inherit-product_prepend-var + $(eval $(1) := $(INHERIT_TAG)$(strip $(2)) $($(1))) +endef + +# +# Internal function. Tracks visited notes during inheritance resolution. +# +# $(1): Product being inherited +# +define inherit-product_track-node + $(eval inherit_var := \ + PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \ + $(eval $(inherit_var) := $(sort $($(inherit_var)) $(strip $(1)))) \ + $(eval inherit_var:=) \ + $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack)))) +endef + +# # $(1): product to inherit # # Does three things: -# 1. Inherits all of the variables from $1. +# 1. Inherits all of the variables from $1, prioritizing existing settings. # 2. Records the inheritance in the .INHERITS_FROM variable # 3. Records that we've visited this node, in ALL_PRODUCTS # define inherit-product $(foreach v,$(_product_var_list), \ - $(eval $(v) := $($(v)) $(INHERIT_TAG)$(strip $(1)))) \ - $(eval inherit_var := \ - PRODUCTS.$(strip $(word 1,$(_include_stack))).INHERITS_FROM) \ - $(eval $(inherit_var) := $(sort $($(inherit_var)) $(strip $(1)))) \ - $(eval inherit_var:=) \ - $(eval ALL_PRODUCTS := $(sort $(ALL_PRODUCTS) $(word 1,$(_include_stack)))) + $(call inherit-product_append-var,$(v),$(1))) \ + $(call inherit-product_track-node,$(1)) endef +# +# $(1): product to inherit +# +# Does three things: +# 1. Inherits all of the variables from $1, prioritizing inherited settings. +# 2. Records the inheritance in the .INHERITS_FROM variable +# 3. Records that we've visited this node, in ALL_PRODUCTS +# +define prepend-product + $(foreach v,$(_product_var_list), \ + $(call inherit-product_prepend-var,$(v),$(1))) \ + $(call inherit-product_track-node,$(1)) +endef # # Do inherit-product only if $(1) exists @@ -153,6 +195,13 @@ define inherit-product-if-exists endef # +# Do inherit-product-prepend only if $(1) exists +# +define prepend-product-if-exists + $(if $(wildcard $(1)),$(call prepend-product,$(1)),) +endef + +# # $(1): product makefile list # #TODO: check to make sure that products have all the necessary vars defined |