如何调用其他目录中的Makefile? [英] How to call Makefile located in other directory?
问题描述
我正在尝试这样做:
我想从其他目录中的shell脚本调用make(其他目录中存在Makefile
,可以使用abc
路径).我该怎么做呢?
I want to call a make (Makefile
exists in some other directory, abc
path can be used) from a shell script located in a different directory. How do I do this?
由于shell脚本不允许我cd
进入Makefile
目录并执行make
,因此我该如何编写shell命令(通过提供要执行的Makefile
的路径)来执行
Since shell scripting does not allow me to cd
into the Makefile
directory and execute make
, how can I write the shell command (by giving path to the Makefile
to be executed) to execute make
?
推荐答案
GNU make
接受许多选项,尤其是-C
在运行前更改目录,而-f
用于跟随Makefile
.
GNU make
accepts many options, notably -C
to change directory before running, and -f
for giving the Makefile
to follow.
适当组合它们.
考虑使用 remake 来简化与Makefile
相关的调试(特别是使用-x
)问题.对于GNU make版本4或更高版本,还请使用make --trace
...
Consider using remake to ease debugging (notably with -x
) of Makefile
related issues. With GNU make version 4 or better, also use make --trace
...
您可以拥有自己的可执行Shell脚本(例如,在$HOME/bin/
中的$PATH
中),该脚本同时使用cd
和make
.
You could have your own executable shell script (e.g. in your $HOME/bin/
which would be in your $PATH
) which uses both cd
and make
).
您可以考虑使用其他构建自动化工具(
You could consider other build automation tools (ninja perhaps)
也请阅读P.Miller的论文 递归使之被视为有害
Read also P.Miller's paper Recursive Make considered harmful
这篇关于如何调用其他目录中的Makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!