help-make
[Top][All Lists]
Advanced

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

RE: Pattern rule prereqs are variables with % in them


From: Boucher, Jean
Subject: RE: Pattern rule prereqs are variables with % in them
Date: Wed, 7 Sep 2005 12:52:24 -0700

Paul,

I didn't think one would normally use the '%' character in a variable,
and that Make would discourage it. I tend to limit my variables names to
use alphanumeric characters and '_', thinking others are usually some
sort of operator.

I realize variables & functions references in prerequisite lists are
expanded immediately, but pattern rules offer an opportunity to allow
for deferred expansion without affecting other instances of variable &
function references. I'm not suggesting all variable and function
references be deferred, just those that are part of a static pattern
rule (again, as is the case for '%.o: %.c' rules) and only those parts
of a static pattern rule that are affected by the '%'. In your example
below, 

    DIR = foo

    %.x : $(DIR)/%.y

    DIR = bar

$(DIR) wouldn't change because it is not affected by the '%'. As right
now, the prereq would still be 'foo/%.y' but only the %.y would be
affected to use the stem of x
_everytime_this_rule_is_actually_used_to_update_a_target.  Admittedly,
I've not looked at the Make source code to see how feasable that is, so
you tell me, but I'm suggesting that, when a target needs to be updated
by  your example rule above, that rule would be seen as:

    %.x : foo/%.y

Generally, the variables that do end-up being deferred are only the ones
that _contain_ the '%', like: 

    %.x : $(ABC%GHI)

which would trannslate to mean "target "DEF.x depends on value of
variable ABCDEFGHI", and mean "target "XYZ.x depends on the value of
variable ABCXYZGHI".  I'm assuming that the same thing happens when a
'%.o: %.c' rule is encountered; the prereqs are only evaluated when a
target filename is available, ie: when the rule is executed to update
that specific target. In other words, _evaluation_ of the entire prereqs
portion of pattern rules must always be deferred until they are needed
to update the target, right? If that's true, can't you just defer the
evaluation of all variables in the prereq portion of a rule until that
rule is hit by a target? Once again, not knowing the internals of Make,
this may make it impossible to generate the dependency graph, or
something like that. 

Maybe the solution to my single-list goal is to list the object files,
but let Make find the first %.s, %.c, or %.cpp file matching the %.o
file, as you suggested. I guess I just have to get better at thinking
backwards, from output to source like Make does, instead of thinking
forward, from source to output.

However, how do you write a generic .elf rule that can be told which
(dependent) files to operate on if it doesn't support a variable list of
prerequisites?  If I replace 'x' for 'elf' in your example, and 'y' is
variable, so it's not supported:

        all: foo.elf bar.elf

        foo.elf : foo.o bar.o baz.o boz.o
        bar.elf : b1.o b2.o b3.o

        # Without prereqs (because variable prereq lists aren't
supported) in this 
      # generic rule, how will below link command know which objs & libs
to link?
        %.elf:
                echo 'Hit .elf pattern rule for $@';\
        #       <link command requires list of objs & libs>


        # Same thing for this rule
        %.lib: 
                @echo 'Hit .lib .lib_objs pattern rule for $@,
prereqs=$^';\
        #       <libar command>


        # This should be a problem since the target's stem is all we
need to pass 
        # to the bin command
        %.bin:  %.elf
                echo 'Hit .bin pattern rule for $@, prereqs=$^';\
        #       <bin command>


>From what you mention about "double expansion" in the latest beta, it
sounds like the escaped '$*' in the prereq section would do something
similar to '%', although I'm not sure exactly when you mean by "later".
What triggers them to be re-evaluated? Is it at the same time the
prereqs of static pattern rules are evaluated (in the second phase when
the rule is actually executed for each particular target?  Will we also
be able to defer user-defined variables by escaping them this way, or is
this just for automatic variables?  I currently have the make-3.80-1-src
package installed on my i686-pc-cygwin machine. Is CVS on Savannah the
only way to get my hands on that latest beta? Better yet, when do you
think the official release (3.81, I guess) will be available? 

Jean.

========================================================================
CONFIDENTIALITY NOTICE
----------------------
This message, together with any attachments, may be legally privileged
and is confidential information intended only for the use of the
individual or entity to which it is addressed.  It is exempt from
disclosure under applicable law including court orders.  If you are not
the intended recipient, you are hereby notified that any use,
dissemination, distribution or copy of this message, or any attachment,
is strictly prohibited.  If you have received this message in error,
please notify the original sender and delete this message, along with
any attachments, from your computer.





reply via email to

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