美文网首页
Makefile中= := ?=的区别

Makefile中= := ?=的区别

作者: 叶迎宪 | 来源:发表于2018-08-26 15:27 被阅读0次

https://stackoverflow.com/questions/4879592/whats-the-difference-between-and-in-makefile

Simple assignment (:=)

A simple assignment expression is evaluated only once, at the very first occurrence. For example, if CC := ${GCC} ${FLAGS} during the first encounter is evaluated to gcc -W then each time ${CC} occurs it will be replaced with gcc -W.

Recursive assignment(=)

A Recursive assignment expression is evaluated everytime the variable is encountered in the code. For example, a statement like CC = ${GCC} {FLAGS} will be evaluated only when an action like ${CC} file.c is executed. However, if the variable GCC is reassigned i.e GCC=c++ then the ${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 have a value

Appending (+=)

Assume that CC = gcc then the appending operator is used like CC += -w
then CC now has the value gcc -W

相关文章

网友评论

      本文标题:Makefile中= := ?=的区别

      本文链接:https://www.haomeiwen.com/subject/lleoiftx.html