help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if function combined with filter or findstring with eval


From: Scott Kruger
Subject: Re: if function combined with filter or findstring with eval
Date: Thu, 20 Oct 2016 22:42:12 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.4.0



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 <address@hidden> 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

Attachment: example.make
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]