Tutorial by Examples

To use the value stored in a variable, use the dollar sign followed by the variable name enclosed by parentheses or curly braces. x = hello y = $(x) # y now contains the value "hello" y = ${x} # parentheses and curly braces are treated exactly the same If a variable's name is only ...
Simply-expanded variables behave like variables from traditional programming languages. The expression on the right-hand side is evaluated, and the result is stored in the variable. If the right-hand side contains a variable reference, that variable is expanded before the assignment takes place. ...
When defining a recursively-expanded variable, the contents of the right-hand side are stored as-is. If a variable reference is present, the reference itself is stored (not the value of the variable). Make waits to expand the variable references until the variable is actually used. x = hello y =...
Within the context of an individual rule, Make automatically defines a number of special variables. These variables can have a different value for each rule in a makefile and are designed to make writing rules simpler. These variables can only be used in the recipe portion of a rule. VariableDesc...
The ?= operator is an extension that behaves like =, except that the assignment only occurs if the variable is not already set. x = hello x ?= world # $(x) will yield "hello"
The += operator is a common extension that adds the specified content to the end of the variable, separated by a space. x = hello x += world Variable references in the right-hand side will be expanded if and only if the original variable was defined as a simply-expanded variable.

Page 1 of 1