子目录和Makefile [英] Subdirectories and Makefiles
问题描述
我认为这是一个已被问过很多次的问题,但我找不到正确的方法.
I think this is a question that has been asked many times but I cannot find the right way to do it.
我具有以下结构:
project/
project/Makefile
project/code
project/code/*.cc
project/code/Makefile
当我进入目录"project/code"并调用"make project_code"时,我的代码正在正确编译.
When I am in the directory 'project/code' and call "make project_code" my code is compiling correctly.
我想在项目/"中执行此操作,就像在项目/代码"中一样只是调用"make project_code".
I would like to do that when I am in 'project/', just calling "make project_code" as if I was in 'project/code'.
makefile项目/Makefile"将包含其他规则(例如安装")和一些规则,就像我在项目/代码"中一样.为此,我正在请求您的帮助...谢谢.
The makefile 'project/Makefile' will contain other rules (such as 'install') and some rules to compile as if I was in 'project/code'. And for that, I am requesting your help... Thanks.
推荐答案
最简单的方法是:
CODE_DIR = code
.PHONY: project_code
project_code:
$(MAKE) -C $(CODE_DIR)
.PHONY
规则表示project_code
不是需要构建的文件,并且-C
标志指示目录更改(等同于在调用make
之前运行cd code
).您可以使用相同的方法来调用code
Makefile中的其他目标.
The .PHONY
rule means that project_code
is not a file that needs to be built, and the -C
flag indicates a change in directory (equivalent to running cd code
before calling make
). You can use the same approach for calling other targets in the code
Makefile.
例如:
clean:
$(MAKE) -C $(CODE_DIR) clean
这篇关于子目录和Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!