【发布时间】:2011-01-13 10:47:41
【问题描述】:
我从另一个 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 中调用第二个?我的理解是,只需调用make -f <name> 就足够了。
这是 bash 中的 make/gmake 3.81。
【问题讨论】:
-
我认为,与其说
make -f gtest-1.4.0/make/Makefile clean,不如说$(MAKE) -C gtest-1.4.0/make clean。为什么你没有定义虚假目标?