%% Vilar Camara Neto <[EMAIL PROTECTED]> writes:

  vcn> I'm trying to build a rule with an "optional" prerequisite, i.e.,
  vcn> something that says that "if a given file doesn't exist, then
  vcn> ignore it, otherwise consider it as a prerequisite".

You can't really do this with pattern rules.

  vcn> Surprisingly, a patterned rule doesn't work as I expect:

  vcn> %.z: %.x $(wildcard %.y)

Not a surprise to me :-).  All functions and variables in a target or
prerequisite list are expanded immediately, as the makefile is parsed.
However, evaluation of patterns like %.y doesn't happen until much
later, when make is trying to find rules to build targets.

The above does a wildcard on the literal string '%.y', which, unless you
have a file by that name in your directory, expands to the empty string.

  vcn> How do I solve it?  Maybe not using "$(wildcard ...)" at all?

All you can do is something like this:

    %.z: %.x
            ...

    all: foo.z bar.z

    foo.z: $(wildcard foo.y)
    bar.z: $(wildcard bar.y)

You can do the latter using a loop and avoid writing it out. if you have
a GNU make sufficiently new to have the $(eval ...) function.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[EMAIL PROTECTED]>          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


_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to