What is the difference between := and += in make file? What is the difference between := and += in make file? unix unix

What is the difference between := and += in make file?


  • := (Simply Expanded Variable ) The value is scanned for once and for all expanding any
    references to other variables and functions, when variable is defined. e.g. x:=foo
    y:=$(x) bar
    x:=later
    so above is equivalent to
    y:=foo bar
    x:=later

  • += is used for appending more text to variables e.g.
    objects=main.o foo.o bar.o
    objects+=new.o
    which will set objects to 'main.o foo.o bar.o new.o'

  • = is for recursively expanded variable.The value is install verbatim; if it contains reference to other variables these variables are expanded whenever this variable is substituted.And this is known as recursive expansion.


"=" is for defining recursively expanded variable. The follow make file will print out "y is later bar"

x = fooy = $(x) barx = laterall:;echo "y is" $(y)

":=" is for defining simply expanded variable, which is expanded once and for all. The following make file will print out "y is foo bar"

x := fooy := $(x) barx := laterall:;echo "y is" $(y)

Also, as other people pointed earlier, you can get more details in Using Variables section of the GNU make manual.

Hope this helps :-)


:= Defines the variable here to be the left hand side, += adds the right hand side to the existing value of the variable. Compare := with = which evaluates the right hand side at the place of use (rather than in this particular line)

You can look at the manual here (Assuming that you are using GNU make)