define func1
include $(shell pwd)/test/$(strip $1)/component.mk
$(info :::::::${NAME} ::::::::::::::: )
endef
INCLUDES := a b c
$(foreach dir, $(INCLUDES), $(eval $(call func1, $(dir)) ))
all : $(objs)
每个makefile的内容:
cat test/a/component.mk
NAME := AA
cat test/b/component.mk
NAME := BB
cat test/c/component.mk
NAME := CC
输出为
::::::: :::::::::::::::
:::::::AA :::::::::::::::
:::::::BB :::::::::::::::
NAME第一次是空的。
让我们看一下$(foreach dir, ${INCLUDES}, $(eval $(call func1, ${dir}) ))
痛苦细节的扩展。
${INCLUDES}
扩大,给 $(foreach dir,a b c,$(eval $(call func1,${dir})))
dir
设置为a
$(call func1,a)
扩大了
1
被设定为 a
func1
展开:include $(shell pwd)/test/$(strip $1)/component.mk
$(info :::::::${NAME} ::::::::::::::: )
$(shell pwd)
变成HERE
,说(注意${CURDIR}
改为使用)$(strip $1)
变$(strip a)
变a
${NAME}
扩展为空$(info ::::::: ::::::::::::::: )
扩展为空
::::::: :::::::::::::::
出现在标准输出$(eval $(call func1,a))
扩展为$(eval include HERE/test/a/component.mk)
,扩展为无
HERE/test/a/component.mk
存在并且包含有效的make语法,并且该变量NAME
获取一个值。1
设置为b
。泡沫,冲洗,重复。
要获得问题的暗示在这样的代码,始终运行化妆用--warn
:
$ make --warn -Rr
Makefile:8: warning: undefined variable 'NAME'
::::::: :::::::::::::::
⋮
为了得到一些见解,更换$(eval stuff)
用$(error [stuff])
$ make
::::::: :::::::::::::::
Makefile:8: *** [ include /cygdrive/c/Users/somewhere/a/component.mk
]. Stop.
在这里,我们看到$(info …)
甚至在到达评估之前就已经消失了。天真的修补程序非常可怕。
define func1
include $(shell pwd)/test/$(strip $1)/component.mk
$$(info :::::::$${NAME} ::::::::::::::: )
endef
$(error …)
在适当的位置运行该命令
$ make
Makefile:8: *** [ include /cygdrive/c/Users/somewhere/a/component.mk
$(info :::::::${NAME} ::::::::::::::: )]. Stop.
[
和之间的内容]
是有效的make语法。整理起来看起来像:
include /cygdrive/c/Users/somewhere/a/component.mk
$(info :::::::${NAME} ::::::::::::::: )
任务完成。有更清洁的方法,但是您首先需要了解痛苦!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句