= GNU Make [[http://www.gnu.org/software/make/manual/html_node/|Manual]] == Anatomy of a Make Rule {{{ target: prerequisite prerequisite prerequisite ... recipe }}} [[https://www.gnu.org/software/make/manual/html_node/Rule-Introduction.html|Source]] == Misc * A line beginning with ''#'' is a comment * '@' at the beginning of a command runs the command but does not copy the line to stdout * '-' at the beginning of a command runs the command but does not abort make if command fails * ''%%make -n%%'' or ''%%make --dry-run%%'' - Don't actually run any commands; just print them. * If a target begins with ''%'', the whole rule is a definition of an implicit rule, called //pattern rule// == Automatic variables * ''$@'' contains the name of the target. It does oviously not work in prerequsites, only in recipie! * ''$<'' The name of the first prerequisite. Useful in the recipe * ''$^'' The names of all prerequisites, with spaces between them * ''$*'' is useful for constructing names of related files. FIXME See [[https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html|Automatic-Variables]] == Rules for overwriting variables # Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value. # An explicit assignment in the makefile overrides the environment # An assignment in the makefile can be overridden by the command line argument, eg {{{make CFLAGS='-g -O' [target] }}} Sources: [[https://www.gnu.org/software/make/manual/html_node/Overriding.html|1]] [[https://www.gnu.org/software/make/manual/html_node/DESTDIR.html|2]] == Variable assignment a = Peter c = $(a) d := $(a) a = Franz test: @echo c expands to $(c) # Franz @echo d expands to $(d) # Peter == CFLAGS usage > If there are C compiler options that must be used for proper compilation of certain files, do not include them in CFLAGS. **Users expect to be able to specify CFLAGS freely themselves**. Instead, arrange to pass the necessary options to the C compiler independently of CFLAGS, by writing them explicitly in the compilation commands or by defining an implicit rule. See also: [[https://www.gnu.org/software/make/manual/html_node/Command-Variables.html|See Command-Variables]], [[gnu_gcc]] == Implicit rules Example: ''file.o'' is made automatically from ''file.c'' with a command of the form `$(CC) -c $(CPPFLAGS) $(CFLAGS)'