如何从另一个Makefile调用Makefile? [英] How to call Makefile from another Makefile?

查看:2139
本文介绍了如何从另一个Makefile调用Makefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一些意外的结果,从另一个调用一个生成文件.我有两个makefile,一个叫/path/to/project/makefile,另一个叫/path/to/project/gtest-1.4.0/make/Makefile.我试图让前者称呼后者.在/path/to/project/makefile中,我有

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

/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'

但是,当我发出以下命令时:

However, when I issue these commands:

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(而不是/path/to/makefile/gtest-1.4.0/make/)中运行rm命令.

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/.

我是否缺少一些相互调用makefile的基本知识?我是否犯了严重的概念错误,还是遇到了常见的陷阱?如何有效地更改目录并从第一个生成文件中调用第二个生成文件?我的理解是,只需调用make -f <name>就足够了.

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.

这是bash中的make/gmake 3.81.

This is make/gmake 3.81 in bash.

推荐答案

我不太清楚您要问的是什么,但是使用-f命令行选项只是指定一个文件-它不会告诉make更改目录.如果要在另一个目录中进行工作,则需要cd到目录:

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 to cd to the directory:

clean:
    cd gtest-1.4.0 && $(MAKE) clean

请注意,Makefile中的每一行都在单独的外壳程序中运行,因此无需将目录改回.

Note that each line in Makefile runs in a separate shell, so there is no need to change the directory back.

这篇关于如何从另一个Makefile调用Makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆