3.2. Including Other Makefiles

Just as for programs, it is often useful to extract certain parts of a makefile into another file and just include it in other makefiles somehow. Many compilers allow you say something like:

#include "defs.h"

to include the contents of defs.h in the source file. PMake allows you to do the same thing for makefiles, with the added ability to use variables in the filenames. An include directive in a makefile looks either like this:

#include <file>

or this:

#include "file"

The difference between the two is where PMake searches for the file: the first way, PMake will look for the file only in the system makefile directory (or directories) (to find out what that directory is, give PMake the -h flag). The system makefile directory search path can be overridden via the -m option. For files in double-quotes, the search is more complex:

  1. The directory of the makefile that's including the file.

  2. The current directory (the one in which you invoked PMake).

  3. The directories given by you using -I flags, in the order in which you gave them.

  4. Directories given by .PATH dependency lines (see Chapter 4, PMake for Gods).

  5. The system makefile directory.

in that order.

You are free to use PMake variables in the filename – PMake will expand them before searching for the file. You must specify the searching method with either angle brackets or double-quotes outside of a variable expansion. I.e. the following:

SYSTEM    = <command.mk>

#include $(SYSTEM)

will not work.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.