从另一个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
都告诉我它正在进入当前工作目录。在第一种情况下,它认为它没有工作要做(当它有工作时),在第二种情况下,它能够找到适当的指令(当输出告诉我它在错误的目录中查找时)但它会尝试在 中运行rm
命令/path/to/project
,而不是/path/to/makefile/gtest-1.4.0/make/
.
我是否遗漏了一些基本的相互调用 makefile 的东西?我是否犯了一个严重的概念错误,或者遇到了一个常见的陷阱?如何有效地更改目录并从第一个 makefile 中调用第二个?我的理解是,简单地调用make -f <name>
就足够了。
这是 bash 中的 make/gmake 3.81。