help-make
[Top][All Lists]
Advanced

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

Re: Named parameters in make?


From: Lane Schwartz
Subject: Re: Named parameters in make?
Date: Fri, 10 Jun 2011 15:08:25 -0400

On Fri, Jun 10, 2011 at 2:27 PM, Philip Guenther <address@hidden> wrote:

> On Fri, Jun 10, 2011 at 10:49 AM, Lane Schwartz <address@hidden>
> wrote:
> > Paul, this needs to be documented. The sections in the manual on call and
> > eval don't talk to this point at all. It seems that an example like this
> > should go in the eval section.
> ...
> > Paul, if you want a volunteer for adding this info to the manual, let me
> > know. :)
>
> You don't need permission to suggest text.  Indeed, since it caught
> you, your thoughts on how to avoid the confusion should be a good
> place to start.  What would have flagged for you that $(eval)'s
> initial expansion is just like all the other variable and function
> expansion in make, and that it doesn't require $(call)?
>
Philip,

Over my time using make I know I've read section 8.8 "The eval Function" a
number of times. But the implication of this sentence didn't hit me until I
saw your example:

"The argument to the eval function is expanded, then the results of that
expansion are parsed as makefile syntax."

This section then goes on to give an excellent example of how to use eval in
conjunction with call. After seeing that example, it simply didn't occur to
me that there might be another way to initialize variable values that would
be referenced within the function define block. Using call makes sense,
because it gives an explicit mechanism for passing parameters that are then
to be used within the function call block.

The idea of calling eval without call seemed silly. When I use eval, it is
typically to dynamically generate new rules with complex patterns that can't
be handled by using %, as in my example above. The only reason I would write
a defined function is if I intend to use it more than once, each time with
different parameters. But the only way that I saw in the manual to pass
parameters was with call.

I would suggest adding something like the following example in the eval
section of the manual, immediately after the first paragraph:

======BEGIN NEW DOCUMENTATION========

define FOO
$A-$B.$C: $A $B
   foobar $A $B -o $$@
endef

A=alpha
B=beta
C=gamma
$(eval ${FOO})

C=delta
$(eval ${FOO})

This use of eval effectively allows the user to construct arbitrarily
complex pattern-like rules that go beyond the pattern-matching offered by
pattern rules using %. Variables referenced within the define block can also
be initialized as automatic variables through the use of foreach:

$(foreach A,alpha aleph,\
    $(foreach B,beta,beth,\
        $(foreach C,gamma,gimmel,\
              $(eval ${FOO})\
         )\
      )\
  )

 ========END NEW DOCUMENTATION==============


I might also add the following for additional clarity:


======BEGIN NEW DOCUMENTATION========

In the following snippet, the value returned by the origin function for the
variable A is "automatic":

 define FOO

$(info $(origin A))

$A-$B.$C: $A $B
   foobar $A $B -o $$@
endef


========END NEW DOCUMENTATION==============


reply via email to

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