GNU Make

From HaFrWiki
Jump to: navigation, search

Make is a utility for automatic building of executable programs and libraries from source code by performing the rules written in a Makefile. Make is difficult to learn and therefore hatted by programmers/developers. Make is developed by Stuart Feldman in April 1976 at Bell Labs.

Make is particular used in for building (UNIX) C and C++ programs. For Java Ant and Maven are the (basic) make utilities.

Make has many derived tools such as nmake (Microsoft), bmake, GNU Make.

Documentation

GNU Make has a manual [1] describing the basics of GNU make. The way this book is written is more like a reference than a learning book. A free o'Reilly Book [2] is a better way to learn the Make basics.

Automatic variables

Automatic variables are set by make after a rule is matched. They provide access to elements from the target and prerequisite lists so you don’t have to explicitly specify any filenames. They are very useful for avoiding code duplication, but are critical when defining more general pattern rules (discussed later).

There are seven “core” automatic variables:

Variable Description
$@ The filename representing the target.
$% The filename element of an archive member specification.
$< The filename of the first prerequisite.
$? The names of all prerequisites that are newer than the target, separated by spaces.
$^ The filenames of all the prerequisites, separated by spaces. This list has duplicate filenames removed since for most uses, such as compiling, copying, etc., duplicates are not wanted.
$+ Similar to $^, this is the names of all the prerequisites separated by spaces, except that $+ includes duplicates. This variable was created for specific situations such as arguments to linkers where duplicate values have meaning.
$* The stem of the target filename. A stem is typically a filename without its suffix. (We’ll discuss how stems are computed later in the section Pattern Rules.) Its use outside of pattern rules is discouraged.

See also

top

Reference

top