Are := and += same in Linux Kernel Makefiles and could be used interchangeably? If not, then what is the difference between the two ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As others say,
:=is assignment.But there’s a fine difference between
:=and=. In most cases it doesn’t matter, but it may make a big difference.X = $(Y)definesXas a recursive variable, which is something like a C preprocessor macro.Whenever
Xis referenced, the value ofYwill be used.The expansion happens when
Xis expanded. So you can defineYafter you’ve definedX, and it’s OK.X := $(Y)definesXas a simple variable. This is more like a C assignment.Now,
Yis expanded at the time of definition, so changing it later will do nothing.X += $(Y)appends toX, but keeps its type.If
Xwas previously defined with=,Ywill not be expanded immediately. Same ifXwas never defined.If
Xwas previously defined with:=,Ywill be expanded immediately.You can try this exmaple makefile:
It prints