Newsgroups: comp.unix.programmer Date: 22 Mar 2007 14:50:48 GMT
I have the following make file:
all: something else .PHONY: MakeAppleJuice MakeOrangeJuice MakeTomatoJuice MakeAppleJuice: make_juice Apple.in.source Apple.in.condition MakeOrangeJuice: make_juice Orange.in.source Orange.in.condition MakeTomatoJuice: make_juice Tomato.in.source Tomato.in.condition
Is there anyway to combine the 3 rules into one? I hope there is, because the 3 rules only different in what files they use and what juices then make (but I still need the 3 phony targets). I tried the following but it didn't work:
Make%Juice: %.in.source make_juice $*.in.source $*.in.condition
Is it possible to have such generic phony rule?
Pattern rules and phonies don't play well. You can't have a rule like this:
.PHONY: %.o
Also, it seems when you define:
.PHONY: AppleJuice
Then make looks for an *explicit* rule to make "AppleJuice". It doesn't do the pattern rule.
Interestingly, I haven't seen this anywhere in the documentation.
> Which shouldn't be, because AppleJuice is a phony target.
Quite the opposite. In light of the above, if you remove the target from the phonies, I mean delete the .PHONY *rule* from your makefile, it works.
If you want to get the effect of .PHONY, there's another trick:
FORCE: Make%Juice: %.in.source FORCE make_juice $*.in.source $*.in.condition
And your original command line works.
info make --index='force'
Jean-Rene David
> Thanks for the reply. I still can't get it working: > > $ cat Makefile > make_juice := echo > > all: something else > > .PHONY: MakeAppleJuice MakeOrangeJuice MakeTomatoJuice > > FORCE: > Make%Juice: %.in.source FORCE > make_juice $*.in.source $*.in.condition > > #MakeAppleJuice: > > $ make MakeAppleJuice > make: Nothing to be done for `MakeAppleJuice'.
The "FORCE" trick is meant to *replace* the .PHONY rule. It's not exactly the same thing, but in your case it will allow you to do what you want with a similar overall effect (only performance is affected).
Delete the .PHONY *rule* from your makefile:
% cat Makefile all: something else FORCE: Make%Juice: %.in.source FORCE @echo $*.in.source $*.in.condition % ls *.in.source Apple.in.source Orange.in.source Tomato.in.source % make MakeAppleJuice Apple.in.source Apple.in.condition % touch MakeAppleJuice % make MakeAppleJuice Apple.in.source Apple.in.condition
Without "FORCE":
% cat Makefile all: something else Make%Juice: %.in.source @echo $*.in.source $*.in.condition % touch MakeAppleJuice % make MakeAppleJuice make: `MakeAppleJuice' is up to date.
Jean-Rene David