GNU-make check if element exists in list/array -
i have list defined in make file , user supposed set environment variable need find in list. there way using gnu make this? want outside recipe, before make starts building targets. qa check make sure user sets env. variable value within range/list.
on terminal:
setenv env_param x
in makefile:
params := b c if ${env_param} exists in $(params) true else false endif
@madscientist's answer works. there way wrap if block foreach loop test multiple parameters?
keys := params factors params := b c factors := x y z foreach v in ($(keys)) { ifneq ($(filter $(env_$(v)),$(v)),) $(info $(env_$(v)) exists in $(v)) else $(info $(env_$(v)) not exist in $(v)) endif }
you can use filter
function this:
params := b c ifneq ($(filter $(env_param),$(params)),) $(info $(env_param) exists in $(params)) else $(info $(env_param) not exist in $(params)) endif
read: "if result of searching env_param value in params not empty, run 'true' block else run 'false' block".
update
your second question cannot answered information you've provided. in order know best way need know going inside if-statement, when condition true , when false. going declare more variables? create rules? else? there many ways want , cleanest 1 may different depending on want do.
however, general solution involve using define
create content of loop, using foreach
, eval
, this:
keys := params factors params := b c factors := x y z define loopbody ifneq ($$(filter $$(env_$(v)),$(v)),) $$(info $$(env_$(v)) exists in $(v)) else $$(info $$(env_$(v)) not exist in $(v)) endif endef $(foreach v,$(keys),$(eval $(loopbody)))
you might interested in set of posts made regarding metaprogramming in gnu make: http://make.mad-scientist.net/category/metaprogramming/
Comments
Post a Comment