Writing Makefiles

Posted by Beetle B. on Wed 05 June 2019

You can include other makefiles into the current one:

include FILENAMES

You can include variables and globs as filenames:

include foo *.mk $(somevar)

It will look for the files in the directories specified (or the current directory if none is specified). If not there, then -I directories. Then ‘PREFIX/include’ (normally ‘/usr/local/include’ (1)) ‘/usr/gnu/include’, ‘/usr/local/include’, ‘/usr/include’.

If a file is not found, it is a warning, not an error - initially. It will try to reread at the end (in the chance that one of the targets will build the make file). If it still can’t find it, it will be an error.

If you want it to ignore any files it doesn’t find, do this:

-include FILENAMES

This one will not even give a warning.

Don’t use the MAKEFILES environment variable. It adds it to the list of makefiles to be read, and is primarily used for communicating between recursive make invocations.

Makefiles can be “remade”. If a makefile changes in the middle, make starts over with a clean slate. I didn’t read the details.

Make has two phases. In the first phase, it reads all the makefiles, parses the variables, and builds a dependency graph. Int he second phase, it figures out what needs to be (re)built. This can impact variable expansion. Read the section if you want more details.

tags : make