如何从另一个Makefile调用Makefile?
我从另一个 makefile 调用一个 makefile 时得到了一些意想不到的结果。我有两个 makefile,一个名为 /path/to/project/makefile
,另一个名为 /path/to/project/gtest-1.4.0/make/Makefile
。我试图让前者调用后者。在 /path/to/project/makefile 中,我有
dev: $(OBJ_FILES)
$(CPPC) $(LIBS) $(FLAGS_DEV) $(OBJ_FILES) -o $(BIN_DIR)/$(PROJECT)
$(MAKE) -f ./gtest-1.4.0/make/Makefile
clean:
rm -f ./*~ ./gmon.out ./core $(SRC_DIR)/*~ $(OBJ_DIR)/*.o
rm -f ../svn-commit.tmp~
rm -f $(BIN_DIR)/$(PROJECT)
make -f gtest-1.4.0/make/Makefile clean
在 /path/to/project/gtest-1.4.0/make/Makefile
中,我
all: $(TESTS)
clean:
rm -f $(TESTS) gtest.a gtest_main.a *.o
发出以下内容:
cd /path/to/project
make
输出:
make -f ./gtest-1.4.0/make/Makefile
make[1]: Entering directory `/path/to/project'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/path/to/project'
但是,当我发出这些命令:
cd /path/to/project
make clean
我明白:
make -f gtest-1.4.0/make/Makefile clean
make[1]: Entering directory `/path/to/project'
rm -f gtest.a gtest_main.a *.o
make[1]: Leaving directory `/path/to/project'
我不明白: 在这两种情况下, /path/to/project/makefile
告诉我它正在进入当前工作目录。在第一种情况下,它认为它没有工作要做(当它这样做时),在第二种情况下,它能够找到适当的指令(当输出告诉我它正在寻找错误的目录时),但它尝试在 /path/to/project
中运行 rm
命令,而不是 /path/to/makefile/gtest-1.4.0/make/
>。
我是否遗漏了一些相互调用 makefile 的基本知识?我是否犯了严重的概念错误,或者遇到了常见的陷阱?如何有效地更改目录并从第一个 makefile 中调用第二个 makefile?我的理解是,只需调用 make -f
这是 bash 中的 make/gmake 3.81。
I'm getting some unexpected results calling one makefile from another. I have two makefiles, one called /path/to/project/makefile
and one called /path/to/project/gtest-1.4.0/make/Makefile
. I'm attempting to have the former call the latter. In /path/to/project/makefile, I have
dev: $(OBJ_FILES)
$(CPPC) $(LIBS) $(FLAGS_DEV) $(OBJ_FILES) -o $(BIN_DIR)/$(PROJECT)
$(MAKE) -f ./gtest-1.4.0/make/Makefile
clean:
rm -f ./*~ ./gmon.out ./core $(SRC_DIR)/*~ $(OBJ_DIR)/*.o
rm -f ../svn-commit.tmp~
rm -f $(BIN_DIR)/$(PROJECT)
make -f gtest-1.4.0/make/Makefile clean
And in /path/to/project/gtest-1.4.0/make/Makefile
I have
all: $(TESTS)
clean:
rm -f $(TESTS) gtest.a gtest_main.a *.o
Issuing the following:
cd /path/to/project
make
Outputs:
make -f ./gtest-1.4.0/make/Makefile
make[1]: Entering directory `/path/to/project'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/path/to/project'
However, when I issue these commands:
cd /path/to/project
make clean
I see:
make -f gtest-1.4.0/make/Makefile clean
make[1]: Entering directory `/path/to/project'
rm -f gtest.a gtest_main.a *.o
make[1]: Leaving directory `/path/to/project'
I don't understand: In both cases, /path/to/project/makefile
is telling me it's entering the current working directory. In the first case, it doesn't think it has work to do (when it does) and in the second case, it's able to find the appropriate directive (when the output is telling me it's looking in the wrong directory) yet it tries to run the rm
command in /path/to/project
, instead of /path/to/makefile/gtest-1.4.0/make/
.
Am I missing something fundamental to calling makefiles from one another? Have I made an egregious conceptual mistake, or hit a common pitfall? How do I effectively change directories and call a second makefile from within the first? My understanding was that simply calling make -f <name>
would be enough.
This is make/gmake 3.81 in bash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不太清楚你在问什么,但使用
-f
命令行选项只是指定一个文件 - 它不会告诉 make 更改目录。如果您想在另一个目录中完成工作,则需要 cd 到该目录:请注意,Makefile 中的每一行都在单独的 shell 中运行,因此不需要将目录更改回来。
I'm not really too clear what you are asking, but using the
-f
command line option just specifies a file - it doesn't tell make to change directories. If you want to do the work in another directory, you need tocd
to the directory:Note that each line in
Makefile
runs in a separate shell, so there is no need to change the directory back.您可能需要使用
-C
选项,而不是make
的-f
。首先将 更改为路径“
”,然后在那里调用make
。例子:
Instead of the
-f
ofmake
you might want to use the-C <path>
option. This first changes the to the path '<path>
', and then callesmake
there.Example:
http://www.gnu.org/software/make/manual/make.html#Recursion< /a>
或者,等效地,这个:
http://www.gnu.org/software/make/manual/make.html#Recursion
or, equivalently, this :
看起来很明显
$(TESTS)
是空的,所以你的 1.4.0 makefile 是有效的事实上,一切都没有关系。 clean 确实如其所说
rm -f gtest.a ...
It seems clear that
$(TESTS)
is empty so your 1.4.0 makefile is effectivelyIndeed, all has nothing to do. and clean does exactly what it says
rm -f gtest.a ...
在父 makefile 中,
为了使其正常工作,在 /path/to/project/gtest-1.4.0 下必须存在一个带有
clean
的 makefile诸如 followchild makefile之类的选项
in parent makefile put
in order this to work, under /path/to/project/gtest-1.4.0 must exist a makefile with
clean
option like followchild makefile