在 makefile 中启动其他 makefile
由于我对 Linux 上的构建过程/makefile 不太有经验,所以我遇到了以下问题:
设置: 我有一个 makefile A,它需要在运行之前设置一些环境变量,这是通过运行 来完成的。 ./set_A_vars.sh
(set_A_vars.sh 包含许多 export
行)在运行 make -f A
之前
现在我需要在 makefile B 中创建项目 A。 我尝试了以下 makefile B 设置:
all: debug release
A_debug:
. ./set_A_vars.sh && make -f A DEBUG=1
A_release:
. ./set_A_vars.sh && make -f A DEBUG=0
debug: A_debug some_B_stuff_debug
release: A_release some_B_stuff_debug
但是我收到了很多错误,这听起来像是 set_A_vars.sh 中的环境变量尚未为 B 中的 make -f A ...
设置。
怎么办?我从 makefile B 调用 makefile A,并使用 makefile B 中设置的 set_A_vars.sh 中的环境变量?
任何帮助表示赞赏。
Since i am not so experienced with the building process / makefiles on linux i ran in follow problem:
the Setup:
i have an makefile A, which needs some enviroment variables set before running, this is done by running . ./set_A_vars.sh
(set_A_vars.sh contains many export
lines) before running make -f A
now i need to make project A within a makefile B.
i tried the following setup for makefile B:
all: debug release
A_debug:
. ./set_A_vars.sh && make -f A DEBUG=1
A_release:
. ./set_A_vars.sh && make -f A DEBUG=0
debug: A_debug some_B_stuff_debug
release: A_release some_B_stuff_debug
however i get lots of errors, which sound like the enviroment variables in set_A_vars.sh have not been set for make -f A ...
in B.
How can i call makefile A from makefile B with the enviroment variables in set_A_vars.sh set in makefile B ??
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过这些附加条件,您的 makefile 看起来不错:
当您从 makefile 调用 make 时,请使用宏调用
${MAKE}
而不是普通的make
。 (这确保了并行 make 工作,并且也意味着即使您的 make 有另一个名称(比如说 GNUmake )它仍然可以工作。)如果您的目标与实际文件不对应,则将它们标记为
.PHONY
(见下文)。some_B_stuff_debug
是否需要先构建 A?然后你必须告诉 make this。这显然是错误的。一种方法是通过 shell 强制执行排序。
尝试这样的事情:
Your makefile looks good with these provisos:
When you call make from a makefile, please use the macro invocation
${MAKE}
rather than plainmake
. (This ensures parallel make works, and also means it still works even if your make has another name (GNUmake
say).)If your targets do not correspond to actual files, then mark them with
.PHONY
(see below).Does
some_B_stuff_debug
require A to be built first? Then you must tell make this.This is clearly wrong. One way is to enforce the ordering via the shell.
Try something like this:
你的 makefile 应该可以工作。我建议您尝试以下操作:
set_A_vars.sh
。make -f MakefileA
,验证MakefileA
确实能够很好地处理这些变量集。MakefileB
中尝试一条规则来测试其中一个变量,例如FOO
:<前><代码>测试变量:
@echo FOO 是 $(FOO)
如果您刚刚运行
set_vars.sh
,这应该可以工作。如果没有,那么有一些事情可能是错误的......FOO
)并在MakefileB
中尝试此规则:<前><代码>A_debug:
./set_A_vars.sh && make -f MakefileA DEBUG=1
(我建议不要将 makefile 称为“A”。)
Your makefiles should work. I suggest you try the following:
set_A_vars.sh
from the command line.make -f MakefileA
, to verify thatMakefileA
really does work nicely with these variables set.MakefileB
that will test one of the variables, sayFOO
:This should work if you have just run
set_vars.sh
. If it doesn't, then there are a couple of things that could be wrong...FOO
) and try this rule inMakefileB
:(I recommend against calling a makefile "A".)