What is the difference between: = and = in a Makefile?

To assign a variable in Make (or Microsoft nmake) I see: = and = operator. What is the difference between the two?

+50
makefile gnu-make nmake
Feb 02 2018-11-02T00:
source share
3 answers

This is described in the GNU Make documentation in a section called 6.2. Two flavors of variables .

In short, variables defined with := are expanded once, but variables defined with = are expanded whenever they are used.

+40
Feb 02 '11 at 20:40
source share

From http://www.gnu.org/software/make/manual/make.html#Flavors :

= defines a recursively extended variable. := defines just an extended variable.

+9
Feb 02 '11 at 20:40
source share

Simple assignment (: =)

A simple assignment expression is evaluated only once, in the very first case. For example, if CC :=${GCC} ${FLAGS} during the first meeting is evaluated as gcc -W , then each time ${CC} it is replaced by gcc -W .

Recursive Assignment (=)

Recursive assignment is assigned every time a variable is encountered in code. For example, an expression of type CC = ${GCC} {FLAGS} will be evaluated only when an action of type ${CC} file.c . However, if the GCC variable is reassigned ie GCC=c++ , then ${CC} will be converted to c++ -W after the reassignment.

Conditional Assignment (? =)

Conditional assignment assigns a value to a variable only if it does not matter

Addition (+ =)

Suppose CC = gcc then the add operator is used as CC += -w
then CC now matters gcc -W

+2
Nov 22 '17 at 16:29
source share



All Articles