make: Suffix Rules

1 
1 10.7 Old-Fashioned Suffix Rules
1 ===============================
1 
1 "Suffix rules" are the old-fashioned way of defining implicit rules for
1 'make'.  Suffix rules are obsolete because pattern rules are more
1 general and clearer.  They are supported in GNU 'make' for compatibility
1 with old makefiles.  They come in two kinds: "double-suffix" and
1 "single-suffix".
1 
1    A double-suffix rule is defined by a pair of suffixes: the target
1 suffix and the source suffix.  It matches any file whose name ends with
1 the target suffix.  The corresponding implicit prerequisite is made by
1 replacing the target suffix with the source suffix in the file name.  A
1 two-suffix rule whose target and source suffixes are '.o' and '.c' is
1 equivalent to the pattern rule '%.o : %.c'.
1 
1    A single-suffix rule is defined by a single suffix, which is the
1 source suffix.  It matches any file name, and the corresponding implicit
1 prerequisite name is made by appending the source suffix.  A
1 single-suffix rule whose source suffix is '.c' is equivalent to the
1 pattern rule '% : %.c'.
1 
1    Suffix rule definitions are recognized by comparing each rule's
1 target against a defined list of known suffixes.  When 'make' sees a
1 rule whose target is a known suffix, this rule is considered a
1 single-suffix rule.  When 'make' sees a rule whose target is two known
1 suffixes concatenated, this rule is taken as a double-suffix rule.
1 
1    For example, '.c' and '.o' are both on the default list of known
1 suffixes.  Therefore, if you define a rule whose target is '.c.o',
1 'make' takes it to be a double-suffix rule with source suffix '.c' and
1 target suffix '.o'.  Here is the old-fashioned way to define the rule
1 for compiling a C source file:
1 
1      .c.o:
1              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
1 
1    Suffix rules cannot have any prerequisites of their own.  If they
1 have any, they are treated as normal files with funny names, not as
1 suffix rules.  Thus, the rule:
1 
1      .c.o: foo.h
1              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
1 
1 tells how to make the file '.c.o' from the prerequisite file 'foo.h',
1 and is not at all like the pattern rule:
1 
1      %.o: %.c foo.h
1              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
1 
1 which tells how to make '.o' files from '.c' files, and makes all '.o'
1 files using this pattern rule also depend on 'foo.h'.
1 
1    Suffix rules with no recipe are also meaningless.  They do not remove
11 previous rules as do pattern rules with no recipe (⇒Canceling
 Implicit Rules Canceling Rules.).  They simply enter the suffix or pair
1 of suffixes concatenated as a target in the data base.
1 
1    The known suffixes are simply the names of the prerequisites of the
1 special target '.SUFFIXES'.  You can add your own suffixes by writing a
1 rule for '.SUFFIXES' that adds more prerequisites, as in:
1 
1      .SUFFIXES: .hack .win
1 
1 which adds '.hack' and '.win' to the end of the list of suffixes.
1 
1    If you wish to eliminate the default known suffixes instead of just
1 adding to them, write a rule for '.SUFFIXES' with no prerequisites.  By
1 special dispensation, this eliminates all existing prerequisites of
1 '.SUFFIXES'.  You can then write another rule to add the suffixes you
1 want.  For example,
1 
1      .SUFFIXES:            # Delete the default suffixes
1      .SUFFIXES: .c .o .h   # Define our suffix list
1 
1    The '-r' or '--no-builtin-rules' flag causes the default list of
1 suffixes to be empty.
1 
1    The variable 'SUFFIXES' is defined to the default list of suffixes
1 before 'make' reads any makefiles.  You can change the list of suffixes
1 with a rule for the special target '.SUFFIXES', but that does not alter
1 this variable.
1