%% Laird Nelson <[EMAIL PROTECTED]> writes:

  ln> In a pattern rule like this:

  ln> $(SOME_JAR_FILES) : %.jar : Foo Bar Blah

  ln> ...I can't write it to look like this:

  ln> $(SOME_JAR_FILES) : %.jar : $(SOME_VAR_FOR_%_CONTAINING_FILENAMES)

Right.

Variable and function references in target and prerequisite lists are
expanded at makefile read-in.  The value of "%" in pattern rules isn't
computed until runtime--too late.

  ln> ...and I can't write it like this:

  ln> $(SOME_JAR_FILES) : %.jar : $(SOME_VAR_FOR_$(*)_CONTAINING_FILENAMES)

Right.

Automatic variables are _only_ available inside the command script of a
target, not in the target or prerequisites list.  Just like this:

  foo: $(@)_bar

doesn't work.  Again, it's because target and prerequisite lists are
fully expanded at makefile read-in, but automatic variables aren't
calculated until the rule is actually about to be invoked.

  ln> Can I do what I want to here?  Is there another way?

Not easily.  The only way to do this is by creating an included
makefile, and writing the targets and prerequisites out to that.  Since
GNU make will automatically re-invoke itself if it rebuilds an included
makefile, this still looks automatic to the user, although it's more
overhead.

For example:

  # Include .foo.d for each foo.jar
  -include $(SOME_JAR_FILES:%.jar=.%.d)

  # How to build .XXX.d files
  .%.d: Makefile
        @ rm -f $@; \
          echo $*.jar : $(SOME_VAR_FOR_$(*)_CONTAINING_FILENAMES) > $@

Anyway, you get the idea.  You use a prerequisite of "Makefile" because
the contents of the output file change when the value of the
$(SOME_VAR...) variable changes, and that variable is (presumably) set
in the Makefile... so whenever the Makefile changes you have to assume
the value of those variables changed.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[EMAIL PROTECTED]>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
   These are my opinions---Nortel Networks takes no responsibility for them.

Reply via email to