help-make
[Top][All Lists]
Advanced

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

Re: use functions to create rules


From: ogronom
Subject: Re: use functions to create rules
Date: Tue, 12 Jun 2012 09:13:33 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120401 Firefox/11.0 SeaMonkey/2.8

Thanks, Paul. It really helped, but there is still a strange issue.

################################################# BEGIN
tests_SRC=1.c 2.c
tests=$(tests_SRC:.c=.out))

all: $(tests)

define out_template =
$(subst .c,.out,$(1)) : $(1)
        echo $$@ $(1)

endef

$(eval $(call out_template,1.c))

$(eval $(call out_template,2.c))


check: $(tests)
        for f in $(tests) ; do echo ./$$f ; done
################################################ END

This variant produces the following message:

echo 1.out 1.c
1.out 1.c
make: *** No rule to make target `2.out)', needed by `all'.  Stop.

To me it looks like 1.out target is created but 2.out is not, although
the call of the function is identical.

Paul Smith wrote:
> On Mon, 2012-06-11 at 23:53 -0400, ogronom wrote:
>> # --------BEGIN
>> tests_SRC=1.c 2.c
>> tests=$(tests_SRC:.c=.out))
>>
>> define out_template =
>> $(DEST_DIR)/$$($(1):.c=.out) : $(1)
>>      echo $$@ $(1)
>> endef
>>
>> $(eval $(call $(out_template 1.c)))
>> $(eval $(call $(out_template 2.c)))
>>
>> all: $(tests)
>>
>> check: $(tests)
>>      for f in $(tests) ; do ./$$f ; done
>> #---------END
> 
> First, you should put "all" closer to the top.  It should be the first
> target defined.
> 
>> make: *** No rule to make target `1.out', needed by `all'.  Stop.
> 
> Your invocation of the $(call ...) function is wrong, first of all.  It
> should be:
> 
>     $(eval $(call out_template,1.c))
>     $(eval $(call out_template,2.c))
> 
> The first argument to the call function is expanded and the expansion is
> treated as the name of a variable to be used as the user-defined
> function.  The remaining arguments are used to replace $1, $2, etc.
> 
> In your case, where you write $(call $(out_template 1.c)), make
> evaluates the reference $(out_template 1.c); since there's no variable
> by that name it evaluates to empty, which means you're invoking $(eval )
> (on the empty string) and nothing is being defined.
> 
> If you replace $(eval ...) with $(info ...) you'll see what make is
> evaluating; that can be a useful debugging tool.  Running make with
> --warn-undefined-variables would have also helped, but note that gives a
> lot of false positives as well.
> 



reply via email to

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