help-make
[Top][All Lists]
Advanced

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

Re: OR rules


From: Daniel Mahler
Subject: Re: OR rules
Date: Wed, 5 Nov 2003 19:20:41 -0600

thanks, that clarifies things

+++++++++++++++++++++++++++++
SUFFIX: .a .b .c .d

%.a : %.b
        : $@ : $?

%.a : %.c
        : $@ : $?


%.a : %.d
        : $@ : $?

%.c :
        : $@
+++++++++++++++++++++++++++++++
does produce

bash-2.04$ make x.a
: x.c
: x.a : x.c
bash-2.04$ 

as desired

D

Paul D. Smith writes:
 > %% Daniel Mahler <address@hidden> writes:
 > 
 >   dm> a : b
 >   dm>        echo a : b
 >   dm> a : c
 >   dm>        echo a : c
 >   dm> a : d
 >   dm>        echo a : d
 >   dm> c :
 >   dm>        echo c
 > 
 > Yes, that's because you can't do that.
 > 
 > But you CAN do this:
 > 
 >   dm> %.tar : %.tar.Z
 >   dm>       unzip $<
 >   dm>
 >   dm> %.tar : %.tar.gz
 >   dm>       gunzip $<
 > 
 > 
 > The difference is that the second one is a pattern rule: a pattern rule
 > might or might not match.  If the pattern rule doesn't match (say
 > because there's no prerequisite that already exists and make can't
 > figure out how to build one) then make will keep looking for another
 > pattern rule that matches.
 > 
 > So you can, and in fact even the builtin GNU make rules do this, have
 > multiple rules where the target is the same pattern.
 > 
 > 
 > But, with an explicit rule you're giving one and only one way to build
 > every target.  In an explicit rule if the prerequisites aren't there, it
 > will fail.  There's no way to change that behavior.
 > 
 > If you have to use explicit rules you'll have to do something like this:
 > 
 >   a.tar: $(wildcard a.tar.gz a.tar.Z)
 >         case "$<" in
 >           *.gz) gunzip $< ;;
 >           *.Z)  unzip $< ;;
 >         esac
 > 
 > Shouldn't that "unzip" really be "uncompress"?  Actually, though, I
 > think gunzip will unzip .Z files as well.
 > 
 > -- 
 > -------------------------------------------------------------------------------
 >  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]