如何实现makefile共享变量 [英] how to implement makefile shared variable
问题描述
我需要一个变量在makefile可以共享通过subdir makefiles(递归构建策略),最后使用它的一些决策。我以前认为出口是做到这一点,但我没有得到想要的结果。
I need a variable in makefile that can be shared across subdir makefiles ( recursive build strategy), and finally use it for some decision making. I had earlier thought export is the way to do it, but I am not getting desired results.
以下是我的makefile: -
following are my makefiles:-
Target.mk (common include for both Makefile.mk & Subdir.mk)
Makefile.mk
Subdir.mk
FILE:Target.mk
export TARGET_PROPERTIES:=
FILE : Target.mk
export TARGET_PROPERTIES :=
-include Target.mk
.PHONY : all
all :
$(MAKE) -C $(PWD) -f Subdir.mk all
@echo "#------------------------------------------------------------#"
@echo "Target build properties"
@echo $(TARGET_PROPERTIES)
@echo "#------------------------------------------------------------#"
FILE:Subdir.mk
FILE : Subdir.mk
-include Target.mk
TARGET_PROPERTIES+=alpha
TARGET_PROPERTIES+=beta
$(warning $(TARGET_PROPERTIES))
all:
@echo "Subdir.mk......[OK]"
问题: -
我想要从Subdir.mk更新TARGET_PROPERTIES并使用Makefile.mk中的结果
PROBLEM:- I want TARGET_PROPERTIES, to be updated from Subdir.mk and the use the results in Makefile.mk
$ make -f Makefile.mk
make -C /cygdrive/c/make_pf -f Subdir.mk all
make[1]: Entering directory `/cygdrive/c/make_pf'
Subdir.mk:8: alpha beta
Subdir.mk......[OK]
make[1]: Leaving directory `/cygdrive/c/make_pf'
#------------------------------------------------------------#
Target build properties
#------------------------------------------------------------#
Subdir.mk:8: alpha beta
在从Subdir.mk - all target返回后,它将重置为NULL。
不确定我做错了什么
in Makefile.mk after return from "Subdir.mk - all target" it resets to NULL. Not sure what I am doing wrong
我正在使用cygwin环境。
P.S. I am using cygwin environment.
推荐答案
导出的环境变量被复制到子进程,不要传播回父进程。
Exported environment variables are copied to child processes, so changes there do not propagate back into the parent process.
您最好的赌注可能会避免递归makefile,而是包括主Makefile.mk的所有内容。 Google为 指定的
Your best bet would probably to avoid recursive makefiles and instead include everything from the main Makefile.mk. Google for Recursive Make considered harmful for pointers how to do this.
这篇关于如何实现makefile共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!