Choosing between several rules for a single targed based on prerequisites avaibility

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Choosing between several rules for a single targed based on prerequisites avaibility

Yannick Patois
Hi,

I have a target (A) that can be build either by applying a given rule on
a prerequisites (P1) or another rule on another prerequisites (P2).

I would like a Makefile that does:
- If only one of P1 or P2 exists, use the available rule to build it
- If both exists, use P1

Is there a way to say that in a Makefile?
I couldnt find anything about this.

Thanks,

        Yannick

--
 _/ Yannick Patois _________________ Address (home) __________________
| irc(undernet): Garp on #france25+ | 1, rue de Bale                   |
| http://garp.feelingsurfer.net/    | 67100 Strasbourg                 |
| Tel-home: +(33)(0)3 88 84 88 16   | FRANCE                           |


_______________________________________________
Help-make mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Choosing between several rules for a single targed based on prerequisites avaibility

John Graham-Cumming
On Tue, 2005-06-07 at 11:31 +0200, Yannick Patois wrote:
> I have a target (A) that can be build either by applying a given rule on
> a prerequisites (P1) or another rule on another prerequisites (P2).
>
> I would like a Makefile that does:
> - If only one of P1 or P2 exists, use the available rule to build it
> - If both exists, use P1

If P1/P2 are _not_ being built by the Makefile (i.e. they are files
whose existence is determined before you type Make) then you could do
this:

ifeq ($(wildcard p1),p1)
a: p1
        @echo Making a from p1
else
ifeq ($(wildcard p2),p2)
a: p2
        @echo Making a from p2
else
$(warning Both p1 and p2 missing)
endif
endif

Which will define a rule making a from p1 if p1 (or both p1 and p2)
exists and a rule for making a from p2 if only p2 exists (or outputs a
warning if both are missing).

John.
--
John Graham-Cumming

Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/




_______________________________________________
Help-make mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Choosing between several rules for a single targed based on prerequisites avaibility

Paul Smith-20
In reply to this post by Yannick Patois
%% Yannick Patois <[hidden email]> writes:

  yp> I have a target (A) that can be build either by applying a given rule on
  yp> a prerequisites (P1) or another rule on another prerequisites (P2).

  yp> I would like a Makefile that does:
  yp> - If only one of P1 or P2 exists, use the available rule to build it
  yp> - If both exists, use P1

  yp> Is there a way to say that in a Makefile?
  yp> I couldnt find anything about this.

If you can write it as a pattern rule (or two pattern rules, really)
then it will work exactly as you expect.

--
-------------------------------------------------------------------------------
 Paul D. Smith <[hidden email]>          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
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-make