make: Multiple Rules

1 
1 4.11 Multiple Rules for One Target
1 ==================================
1 
1 One file can be the target of several rules.  All the prerequisites
1 mentioned in all the rules are merged into one list of prerequisites for
1 the target.  If the target is older than any prerequisite from any rule,
1 the recipe is executed.
1 
1    There can only be one recipe to be executed for a file.  If more than
1 one rule gives a recipe for the same file, 'make' uses the last one
1 given and prints an error message.  (As a special case, if the file's
1 name begins with a dot, no error message is printed.  This odd behavior
1 is only for compatibility with other implementations of 'make'... you
1 should avoid using it).  Occasionally it is useful to have the same
1 target invoke multiple recipes which are defined in different parts of
1 your makefile; you can use "double-colon rules" (⇒Double-Colon)
1 for this.
1 
1    An extra rule with just prerequisites can be used to give a few extra
1 prerequisites to many files at once.  For example, makefiles often have
1 a variable, such as 'objects', containing a list of all the compiler
1 output files in the system being made.  An easy way to say that all of
1 them must be recompiled if 'config.h' changes is to write the following:
1 
1      objects = foo.o bar.o
1      foo.o : defs.h
1      bar.o : defs.h test.h
1      $(objects) : config.h
1 
1    This could be inserted or taken out without changing the rules that
1 really specify how to make the object files, making it a convenient form
1 to use if you wish to add the additional prerequisite intermittently.
1 
1    Another wrinkle is that the additional prerequisites could be
1 specified with a variable that you set with a command line argument to
1 'make' (⇒Overriding Variables Overriding.).  For example,
1 
1      extradeps=
1      $(objects) : $(extradeps)
1 
1 means that the command 'make extradeps=foo.h' will consider 'foo.h' as a
1 prerequisite of each object file, but plain 'make' will not.
1 
1    If none of the explicit rules for a target has a recipe, then 'make'
11 searches for an applicable implicit rule to find one ⇒Using
 Implicit Rules Implicit Rules.).
1