On Mon, 2017-01-02 at 09:51 -0900, Britton Kerin wrote: > This may be at least mostly true for the particular case of the clean > target, which is generally invoked explicitly. However, its not true > for the common case of an object file that one wants to always > rebuild.
I'm not sure anyone would say object files that one wants to always rebuild could be considered a "common case". In fact, I've never written (or seen) a (correct) makefile like that in my life: if you declare an object file to be phony, or forced, then you can never have a "do nothing" build; every time you run make the object file will always be rebuilt and the binary will always be re-linked, even if no code changes have happened. That's not something I've ever known to be desirable in a makefile; certainly it's not common. Anyway... > This Makefile: > > %.o: %.c > cp $< $@ # Simulate compile > > #.PHONY: test.o > > test.o: FORCE > FORCE: > > test.o: Makefile > > fooprog: test.o > cp $< $@ # Simulate link > > Will always recompile test.c into test.o as it is, but if the test.o: > FORCE and FORCE: rules are replaced with the .PHONY: test.o rule > (commented out above), then test.o will never be built at all. That's because of this feature of .PHONY, described in the section of the GNU make manual about Phony Targets: > The implicit rule search (*note Implicit Rules::) is skipped for > '.PHONY' targets. This is why declaring a target as '.PHONY' is good > for performance, even if you are not worried about the actual file > existing. Because your test.o has no explicit rule and .PHONY disables implicit rule lookup, when make goes to try to build "test.o" it finds no recipe for that target and simply declares it to be up to date. > I think the description in 4.7 goes too far in implying equivalency. > Either it shouldn't say the two are equivalent, or it should be more > careful to qualify that that they are equivalent only in the > particular case of the explicitly invoked phony target which doesn't > have additional dependencies expressed in other rules. It doesn't have anything to do with additional dependencies, as I mention above. If you were to rewrite your test.o rule so that it was explicit instead of implicit: test.o: test.c Makefile cp $< $@ You'd see that the .PHONY and FORCE variants worked identically in all senses. It may be worth alluding to this difference in the section on FORCE, just to be clear. _______________________________________________ Help-make mailing list Help-make@gnu.org https://lists.gnu.org/mailman/listinfo/help-make