[gnu.utils.bug] overriding productions in make

grady@fxgrp.fx.com (Steven Grady) (09/26/89)

The make document says that it's illegal to have different commands
for the same target.  If you want to include a standard makefile,
but you want to override a particular production, you have to use the
".DEFAULT" mechanism.  Well, I set up some makefiles that used this
mechanism.  I didn't need to test it until today.  I suddenly discovered
that it has problems.  For instance:
    Makefile:
	foo:
	    @echo moose
	.DEFAULT:
	@$(MAKE) -f GenericMakefile $@

    GenericMakefile:
	foo:
	    @echo foo
	
	bar: foo
	    @echo bar
	
Now suppose I say "make foo".  OK, fine, the default rule is not
invoked.  But if I say "make bar", there is no rule to make bar in
"Makefile", so it invokes the default rule, which not only gets the
standard production for bar, but (since it's a new invocation) gets the
standard production for foo as well.  (Also, of course, assuming the
majority of makefiles don't have special cases, make must be invoked an
extra time for every production, which is a problem, since make isn't
all that fast to begin with.)  To get the correct behavior out of the
above set of makefiles, it would be necessary to include all the
productions that depend on the special target in the new makefile.

How bad would it be to support an alternate semantics for multiply-
defined targets?  Specifically, instead of them being illegal, have 
the first (or last) one take precedence.  This would allow the above 
Makefile to be simply:
    foo:
	@echo moose

    include GenericMakefile

The make would execute more quickly (since it wouldn't need to re-exec
itself), and it would work correctly for the above case.  Also, other
problems could be avoided -- eg, under the current scheme, saying "make
-p" will print out the rules defined in "Makefile", not
"GenericMakefile", which makes it harder to debug the generic case.

I realize this change would diverge from the exact compatibility with 
standard makes, but it's already divergent (for instance, it passes all
variables into the environment), and this would be a useful feature.

	Steven
	...!ucbvax!grady
	grady@postgres.berkeley.edu

If God had wanted us to be concerned for the plight of the toads, he would
have made them cute and furry.