Fri 02 Jul 2010 09:43:41 PM UTC, comment #8:
A few things. First, I cannot reproduce at all the behavior you show in your original bug description, where sometimes using a pattern rule make will rebuild file.o. If you use a pattern rule, make should NEVER rebuild file.o (if it's declared .PHONY) and that's exactly the behavior I see. If you can reproduce that behavior, that would indeed be a bug. Please provide more details in that case.
Second, the behavior difference you see is a direct consequence of one of the primary purposes of the .PHONY feature, and is described clearly in the manual:
So, in your examples with pattern rules, no pattern rule search is done and thus there is no recipe to build file.o so make doesn't build it. This is identical to the behavior you'd see if there were no pattern rule at all. If you define a target explicitly for file.o, then make will see that and try to build it (every time, because it's marked PHONY).
Because this is behaving exactly as described in the manual I'm marking this as "Not a Bug". However, if you have an alternative behavior that you think would make more sense please feel free to comment here; if you convince me I'll be happy to reopen this and make it an enhancement request instead.
|
Sat 08 May 2010 12:10:10 AM UTC, comment #7:
The following tests show that .PHONY's pre-requisites are normally rebuilt regardless of existence of a file with the same name.
This works,
And this works,
But this does not,
This allows me to think that my expectation in the original bug report was valid. And a pattern rule should not be affected by the phoniness of a target.
|
Sat 08 May 2010 12:08:10 AM UTC, comment #6:
The following tests show that .PHONY's pre-requisites are normally rebuilt regardless of existence of a file with the same name.
This works,
|
Fri 07 May 2010 11:11:45 PM UTC, comment #5:
I don't understand how the second quote defeats my statement. The point is that marking the "clean" target phony prevents the accidental existence of a file by that name from confusing the build system. If you're trying to argue from that quote that marking a target phony is a general way to force it to be rebuilt, you're wrong.
I don't understand your objection to the FORCE idiom either. Here is your makefile rewritten to use FORCE:
The only "pre-requisite of .PHONY" (let's just call it a phony target) is FORCE itself, and the purpose of marking it phony is to not be affected by a file of the that name, though such a file should never exist anyway. What is the potential name clash you mention?
|
Fri 07 May 2010 06:08:58 PM UTC, comment #4:
The GNU make manual both supports and defeats Matt's statement.
"A phony target is one that is not really the name of a file."
[..]
"Once this is done, `make clean' will run the commands regardless of whether there is a file named clean."
It would be a nuisance for the builds of pre-requisites of .PHONY to depend on existence of the files by the same name.
Introducing an intermediate dependency can only reduce but not completely eliminate the possibility of a name clash.
|
Fri 07 May 2010 04:33:49 PM UTC, comment #3:
The technique in comment #1 is actually the recommended solution, with the dummy target named FORCE. Phoniness is only for targets that are not files.
|
Mon 22 Feb 2010 09:57:06 PM UTC, comment #2:
Correction: the semicolon at the end of the work-around lines should be removed because it assigned an empty set of actions to the artificial target. GNU make will complain if another rule assigns any actions to the same target,
.PHONY: foo.o ;
.PHONY: bar.o ;
makefile:XXX: warning: overriding commands for target `.PHONY'
|
Mon 22 Feb 2010 08:47:27 PM UTC, comment #1:
The work-around, as I see it in one build system, is to add an extra dummy target,
=================================
ALWAYS-BUILD: ;
file.o: ALWAYS-BUILD
=================================
Same with the explicit noisy target,
=================================
.PHONY: ALWAYS-BUILD ;
file.o: ALWAYS-BUILD
=================================
|
Mon 22 Feb 2010 08:35:05 PM UTC, original submission:
With the makefile piece below I could get file.o only once. If I remove it from the file system, the .PHONY rule seems to shadow the pattern rule. I could not find a stipulation justifying this behavior in the GNU make documentation. Using a Cygwin build 3.81-2 here.
=====================================================
default: file.o
.PHONY: file.o
file.c:
echo Auto-generating "$@"...
touch "$@"
%.o: %.c
echo Making "$@" from "$^"...
touch "$@"
=====================================================
$ make -f force-build-of-a-target-matching-a-pattern-rule.mak
echo Auto-generating "file.c"...
Auto-generating file.c...
touch "file.c"
echo Making "file.o" from "file.c"...
Making file.o from file.c...
touch "file.o"
$ rm file.o
$ make -f force-build-of-a-target-matching-a-pattern-rule.mak
make: Nothing to be done for `default'.
|