help-make
[Top][All Lists]
Advanced

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

Re: $x //Re: $(value) of function parameters


From: Paul D. Smith
Subject: Re: $x //Re: $(value) of function parameters
Date: Tue, 8 Jun 2004 19:18:12 -0400

%% "Markus Mauhart" <address@hidden> writes:

  >> The problem is that the arguments to $(call ...) are themselves
  >> evaluated before being passed to the function.  So, your '$' is
  >> being expanded before fn gets it.

  mm> But why is the 2nd '$' expanded allone instead of expanding '$)'
  mm> together ?

Because before make can expand a reference to a variable (or function)
it has to know what the reference _IS_.

And it can't know what it is until it finds the closing parenthesis (or
curly brace).

So the parser works like this: given an input string it looks through it
until an unescaped "$" is seen.  Then, the parser looks at the next
char.  If it's at the end of the input string then it's a literal "$".

If it's _NOT_ a "(" or a "{", then this is a single-character variable
reference and it's expanded as such, then the rest of the string is
looked at in the same manner.

If it _IS_ a "(" or a "{" then it looks through the string for the
appropriate closing "}" or ")", doing a count of open/close pairs as it
goes.

Once it finds the closing "}" or ")" it expands that string first as a
function, then (if it's not a function) as a variable.  This may well
involve invoking this same parsing routine recursively, with that
substring as the input string.

Then it continues on with the rest of the original string.

  mm> 1) dont change the implementation, but add to the docu:
  mm>   The effect of using $x with x in ",)}" is deliberately not
  mm>   documented in this manual, it is deprecated and hence may
  mm>   be an error in future versions.

No.  It is well-defined, as above.  It will never be an error to use $x;
that usage is mandated by the POSIX standard and is used by thousands of
makefiles.

  mm> 2) dont change the implementation, but change the docu: document
  mm> the current behaviour, and probably add something like ...
  mm>   Using $x with x in ",)}" is deprecated and hence may be an error
  mm>   in future versions.

No.  Again, it will never be an error to use $x.

  mm> 3) change the implementation according to the following simple
  mm> additional docu:
  mm>   $x with x in "$,)}" is expanded as if x was a simply expanded
  mm>   variable, with value of x = name of x = x; e.g. after line
  mm>   "A := x" (and A never changed elsewhere), $A and $x are completely
  mm>   interchangable.

No.  The current implementation is correct according to the POSIX spec
and is depended on by thousands of makefiles every day.

  mm> 4) change the implementation according to the following simple
  mm> additional docu:
  mm>   $x with x in ",)}" is expanded as if x was a simply expanded
  mm>   variable with empty value; e.g. after line "A :=" (and A never
  mm>   changed elsewhere), $A and $x are completely interchangable.

No.  Ibid.

  mm> Any other suggestions that might help me parsing and implementing
  mm> make-compatible variables and functions ?

Well, you could always examine the code to see how the parser actually
works! :).  In fact, if your project is released under the GPL you could
just rip out the parsing function from GNU make and plop it into your
program... maybe with some vascular surgery around the edges.


I suppose the documentation could be made more clear about some of the
exception cases in this area, but I don't want to make it terribly
confusing for those who just want to use the features.  In general it
just does what you expect it to do... maybe unless you're trying to
implement detailed emulation.  The User's Manual is not meant to be a
technical reference document describing every minute detail of the
implementation of GNU make--it's a user's manual.

The beauty of open source is you don't need minute technical reference
documentation--you have the source!

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

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