manpagez: man pages & more
info make
Home | html | info | man

File: make.info,  Node: Using Variables,  Next: Conditionals,  Prev: Recipes,  Up: Top

6 How to Use Variables
**********************

A "variable" is a name defined in a makefile to represent a string of
text, called the variable's "value".  These values are substituted by
explicit request into targets, prerequisites, recipes, and other parts
of the makefile.  (In some other versions of 'make', variables are
called "macros".)

   Variables and functions in all parts of a makefile are expanded when
read, except for in recipes, the right-hand sides of variable
definitions using '=', and the bodies of variable definitions using the
'define' directive.  The value a variable expands to is that of its most
recent definition at the time of expansion.  In other words, variables
are dynamically scoped.

   Variables can represent lists of file names, options to pass to
compilers, programs to run, directories to look in for source files,
directories to write output in, or anything else you can imagine.

   A variable name may be any sequence of characters not containing ':',
'#', '=', or whitespace.  However, variable names containing characters
other than letters, numbers, and underscores should be considered
carefully, as in some shells they cannot be passed through the
environment to a sub-'make' (*note Communicating Variables to a
Sub-'make': Variables/Recursion.).  Variable names beginning with '.'
and an uppercase letter may be given special meaning in future versions
of 'make'.

   Variable names are case-sensitive.  The names 'foo', 'FOO', and 'Foo'
all refer to different variables.

   It is traditional to use upper case letters in variable names, but we
recommend using lower case letters for variable names that serve
internal purposes in the makefile, and reserving upper case for
parameters that control implicit rules or for parameters that the user
should override with command options (*note Overriding Variables:
Overriding.).

   A few variables have names that are a single punctuation character or
just a few characters.  These are the "automatic variables", and they
have particular specialized uses.  *Note Automatic Variables::.

* Menu:

* Reference::                   How to use the value of a variable.
* Flavors::                     Variables come in two flavors.
* Advanced::                    Advanced features for referencing a variable.
* Values::                      All the ways variables get their values.
* Setting::                     How to set a variable in the makefile.
* Appending::                   How to append more text to the old value
                                  of a variable.
* Override Directive::          How to set a variable in the makefile even if
                                  the user has set it with a command argument.
* Multi-Line::                  An alternate way to set a variable
                                  to a multi-line string.
* Undefine Directive::          How to undefine a variable so that it appears
                                  as if it was never set.
* Environment::                 Variable values can come from the environment.
* Target-specific::             Variable values can be defined on a per-target
                                  basis.
* Pattern-specific::            Target-specific variable values can be applied
                                  to a group of targets that match a pattern.
* Suppressing Inheritance::     Suppress inheritance of variables.
* Special Variables::           Variables with special meaning or behavior.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.