Thanks so much for all of the help. It not only fixed my problem but lets me understand what I did wrong and how to develop gmake.

For reference, here is what I came up with to make targets based on
either wildcard search of target names or a findstring of the target
values.  Others might find this useful.

Scott


On 10/20/16 3:39 PM, Philip Guenther wrote:
On Thu, Oct 20, 2016 at 2:22 PM, Scott Kruger <kru...@txcorp.com> wrote:
I am trying to construct a simple list of variables
whose values match certain patterns.  It seems
straightforward, but I can't get the righ t

The makefile is:
----------
RUNTESTS=runex1 runex2 runex3
RUNTESTS_ARGS=$(foreach runtest, $(RUNTESTS), $(runtest)_ARGS)

ifdef argsearch
  FOO:=$(foreach rarg, $(RUNTESTS_ARGS), $(if $(findstring
$(argsearch),$(eval $(value rarg))), $(rarg)))

You use := here so this will be evaluated *IMMEDIATELY*, before the
rest of the Makefile is parsed and therefore before the runex*_ARGS
variables are set.  Either put those assignments before this
assignment, or use '=' instead of ':='.

Next, you don't want $(eval).  That's for creating rules or doing
assignments while in the middle of an expansion.  You don't need that,
you just need to get the value of the variable whose name is $(rarg).
You just need two levels of $(), though using $(value $(rarg)) is
probably best.

So:

FOO=$(foreach rarg,$(RUNTESTS_ARGS),$(if $(findstring
$(argsearch),$(value $(rarg))),$(rarg)))


With that:
$ gmake argsearch=foo
runex1_ARGS runex2_ARGS
$


Philip Guenther
###
##  Simple file for selecting targets by wildcard search on either 
##  the target names or by the values of the targets
##   make                  => runex1 runex2 runex3
##   make search='%2'      => runex2
##           Note that search uses a glob like filtering with % as wildcard
##   make argsearch='foo'  => runex1 runex3
##           Note that search uses no wildcard but is a simple findstring
#
RUNTESTS=runex1 runex2 runex3 
runex1="foo"
runex2="bar"
runex3="foo bar"

ifdef search
  NEW_RUNTESTS = $(filter $(search),$(RUNTESTS))
  ACTUAL_RUN=$(NEW_RUNTESTS)
else
  ifdef argsearch
    NEW_RUNTESTS=$(foreach rarg, $(RUNTESTS), $(if $(findstring 
$(argsearch),$(value $(rarg))), $(rarg)))
    ACTUAL_RUN=$(NEW_RUNTESTS)
  else
    ACTUAL_RUN=$(RUNTESTS)
  endif
endif

all:
        -@echo ">"$(ACTUAL_RUN)
_______________________________________________
Help-make mailing list
Help-make@gnu.org
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to