help-make
[Top][All Lists]
Advanced

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

Re: Optional prerequisites


From: Paul D. Smith
Subject: Re: Optional prerequisites
Date: Wed, 31 Aug 2005 14:34:39 -0400

%% Vilar Camara Neto <address@hidden> 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 <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]