Makefile 中:= ?= += =的不同之处

Makefile 中:= ?= += =的区别

  • 新建一个Makefile
ifdef DEFINE_VRE
    VRE = “Hello World!”
else
endif
ifeq ($(OPT),define)
    VRE ?= “Hello World! First!”
endif
ifeq ($(OPT),add)
    VRE += “Kelly!”
endif
ifeq ($(OPT),recover)
    VRE := “Hello World! Again!”
endif
all:
    @echo $(VRE)
  • 敲入以下
make DEFINE_VRE=true OPT=define 输出:Hello World!
make DEFINE_VRE=true OPT=add 输出:Hello World! Kelly!
make DEFINE_VRE=true OPT=recover  输出:Hello World! Again!
make DEFINE_VRE= OPT=define 输出:Hello World! First!
make DEFINE_VRE= OPT=add 输出:Kelly!
make DEFINE_VRE= OPT=recover 输出:Hello World! Again!
  • = 是最基本的赋值
  • := 是覆盖之前的值
  • ?= 是如果没有被赋值过就赋予等号后面的值
  • += 是添加等号后面的值

  • 1、“=”
  • make将整个makefile展开后,再决定变量值
  • 是整个makefile中最后被指定的值
  • x = foo
  • y = $(x) bar
  • x = xyz
  • 上例y将是 xyz bar ,不是 foo bar
  • “:=”
  • “:=”决定于它在makefile中的位置,而不是整个makefile展开后的最终值。
  • x := foo
  • y := $(x) bar
  • x := xyz
  • y值是foo bar ,而不是 xyz bar
发布了479 篇原创文章 · 获赞 269 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/zhoutianzi12/article/details/104650870