我看到一些有趣的行为,传递给Sub-make的变量。我已经制作了一个具有以下布局的玩具示例项目:
./make_test
| -- foo
| \ -- Makefile
\ -- Makefile
make_test/Makefile
.PHONY: deps
deps:
$(MAKE) -C foo
.PHONY: deps2
deps2: export SOME_VAR=something
deps2:
$(MAKE) -C foo
make_test/foo/Makefile
SOME_VAR ?= something
$(info 1 - SOME_VAR=$(SOME_VAR))
SOME_VAR += else
$(info 2 - SOME_VAR=$(SOME_VAR))
all: deps
@$(MAKE) app
.PHONY: deps
deps:
$(info Getting deps)
app: foo_a foo_b
touch app
foo_a:
touch foo_a
foo_b:
touch foo_b
运行make deps
/Library/Developer/CommandLineTools/usr/bin/make -C foo
1 - SOME_VAR=something
2 - SOME_VAR=something else
Getting deps
1 - SOME_VAR=something
2 - SOME_VAR=something else
make[2]: `app' is up to date.
运行make deps2
/Library/Developer/CommandLineTools/usr/bin/make -C foo
1 - SOME_VAR=something
2 - SOME_VAR=something else
Getting deps
1 - SOME_VAR=something else
2 - SOME_VAR=something else else
make[2]: `app' is up to date.
我理解SOME_VAR
被评估两次。但是,对于deps
,最终结果为something else
,而deps2
会产生something else else
。
我的问题是,在调用SOME_VAR
而不是deps
时,为什么deps2
的值会在第二次评估之前“重置”。为什么将初始值传递给sub-make会影响这个?
答案 0 :(得分:0)
如果您export
变量,该变量将以递归方式export
编辑,除非您稍后unexport
。
当您在$(MAKE)
foo/Makefile
export
SOME_VAR
中调用something else
作为export
时,因为您在根文件中告诉它 compile "org.igniterealtime.smack:smack-android-extensions:4.2.0-alpha3"
compile "org.igniterealtime.smack:smack-tcp:4.2.0-alpha3"