help-make
[Top][All Lists]
Advanced

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

FORCE: ; sometimes better than .PHONY


From: gk
Subject: FORCE: ; sometimes better than .PHONY
Date: Tue, 05 Nov 2002 16:58:18 -0800

In reading the manual, I assumed that .PHONY was a better way to force building phony targets. But I have found a case where it is not and I am inclined to stop using .PHONY altogether because of this.

I want a general purpose 'clean' target for different source file types:
%.clean:
        @rm *.$*

I have files: foo.c, foo.h

$make c.clean
should remove only foo.c
$make h.clean
should remove only foo.h

I want this to work even if the files 'c.clean' and 'h.clean' exist

You cannot add the pattern rule target to .PHONY with:
.PHONY: %.clean

If I add c.clean, h.clean to .PHONY however, the pattern rule will not match since there are no explicit rules for these targets
.PHONY: c.clean h.clean

address@hidden junk]$ make c.clean
make: Nothing to be done for `c.clean'

So in this case using FORCE: ; is a better solution:

FORCE: ;

%.clean: FORCE
        rm *.$*

It might be good to add this to the manual.
- Greg Keraunen





reply via email to

[Prev in Thread] Current Thread [Next in Thread]