make: Include

1 
1 3.3 Including Other Makefiles
1 =============================
1 
1 The 'include' directive tells 'make' to suspend reading the current
1 makefile and read one or more other makefiles before continuing.  The
1 directive is a line in the makefile that looks like this:
1 
1      include FILENAMES...
1 
1 FILENAMES can contain shell file name patterns.  If FILENAMES is empty,
1 nothing is included and no error is printed.
1 
1    Extra spaces are allowed and ignored at the beginning of the line,
1 but the first character must not be a tab (or the value of
1 '.RECIPEPREFIX')--if the line begins with a tab, it will be considered a
1 recipe line.  Whitespace is required between 'include' and the file
1 names, and between file names; extra whitespace is ignored there and at
1 the end of the directive.  A comment starting with '#' is allowed at the
1 end of the line.  If the file names contain any variable or function
11 references, they are expanded.  ⇒How to Use Variables Using
 Variables.
1 
1    For example, if you have three '.mk' files, 'a.mk', 'b.mk', and
1 'c.mk', and '$(bar)' expands to 'bish bash', then the following
1 expression
1 
1      include foo *.mk $(bar)
1 
1    is equivalent to
1 
1      include foo a.mk b.mk c.mk bish bash
1 
1    When 'make' processes an 'include' directive, it suspends reading of
1 the containing makefile and reads from each listed file in turn.  When
1 that is finished, 'make' resumes reading the makefile in which the
1 directive appears.
1 
1    One occasion for using 'include' directives is when several programs,
1 handled by individual makefiles in various directories, need to use a
1 common set of variable definitions (⇒Setting Variables Setting.)
11 or pattern rules (⇒Defining and Redefining Pattern Rules Pattern
 Rules.).
1 
1    Another such occasion is when you want to generate prerequisites from
1 source files automatically; the prerequisites can be put in a file that
1 is included by the main makefile.  This practice is generally cleaner
1 than that of somehow appending the prerequisites to the end of the main
1 makefile as has been traditionally done with other versions of 'make'.
1 ⇒Automatic Prerequisites.
1 
1    If the specified name does not start with a slash, and the file is
1 not found in the current directory, several other directories are
1 searched.  First, any directories you have specified with the '-I' or
11 '--include-dir' option are searched (⇒Summary of Options Options
 Summary.).  Then the following directories (if they exist) are searched,
1 in this order: 'PREFIX/include' (normally '/usr/local/include' (1))
1 '/usr/gnu/include', '/usr/local/include', '/usr/include'.
1 
1    If an included makefile cannot be found in any of these directories,
1 a warning message is generated, but it is not an immediately fatal
1 error; processing of the makefile containing the 'include' continues.
1 Once it has finished reading makefiles, 'make' will try to remake any
11 that are out of date or don't exist.  ⇒How Makefiles Are Remade
 Remaking Makefiles.  Only after it has tried to find a way to remake a
1 makefile and failed, will 'make' diagnose the missing makefile as a
1 fatal error.
1 
1    If you want 'make' to simply ignore a makefile which does not exist
1 or cannot be remade, with no error message, use the '-include' directive
1 instead of 'include', like this:
1 
1      -include FILENAMES...
1 
1    This acts like 'include' in every way except that there is no error
1 (not even a warning) if any of the FILENAMES (or any prerequisites of
1 any of the FILENAMES) do not exist or cannot be remade.
1 
1    For compatibility with some other 'make' implementations, 'sinclude'
1 is another name for '-include'.
1 
1    ---------- Footnotes ----------
1 
1    (1) GNU Make compiled for MS-DOS and MS-Windows behaves as if PREFIX
1 has been defined to be the root of the DJGPP tree hierarchy.
1