2021-01-30 makefile 中的 =, :=, ?=, += 的区别

Makefile

ifdef DEFINE_STR
    STR = define string
    #这一句中 := 等式中变量引用 当前位置 的值 即 define string
    STR2 := str2 中的 STR = $(STR)
    # = 等式中的变量引用 Makefile展开后 最后 确定的值
    STR3 = str3 中的 STR = $(STR)

    STR = over string
endif

ifeq ($(OPT),option)
    #如果STR 没有赋过值 就将STR赋值为 option string
    STR ?= option string
endif

ifeq ($(OPT),add)
    # 追加字符串 
    STR += add string
endif

all:
    @echo STR=$(STR)
    @echo $(STR2)
    @echo $(STR3)

输出结果:

smart@home:~/code$ make DEFINE_STR=true OPT=option
STR = over string
str2 中的 STR = define string
str3 中的 STR = over string
smart@home:~/code$ make DEFINE_STR=true OPT=add
STR = over string add string
str2 中的 STR = define string
str3 中的 STR = over string add string
smart@home:~/code$ make DEFINE_STR=true OPT=recover
STR = recover string
str2 中的 STR = define string
str3 中的 STR = recover string
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容