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

你可能感兴趣的:(2021-01-30 makefile 中的 =, :=, ?=, += 的区别)