如何从另一个Makefile调用Makefile?

发布于 2024-08-20 07:51:06 字数 1684 浏览 7 评论 0原文

我从另一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不知所踪 2024-08-27 07:51:06

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

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

请注意,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 to cd to the directory:

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

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

于我来说 2024-08-27 07:51:06

您可能需要使用 -C 选项,而不是 make-f。首先将 更改为路径“”,然后在那里调用 make

例子:

clean:
  rm -f ./*~ ./gmon.out ./core $(SRC_DIR)/*~ $(OBJ_DIR)/*.o
  rm -f ../svn-commit.tmp~
  rm -f $(BIN_DIR)/$(PROJECT)
  $(MAKE) -C gtest-1.4.0/make clean

Instead of the -f of make you might want to use the -C <path> option. This first changes the to the path '<path>', and then calles make there.

Example:

clean:
  rm -f ./*~ ./gmon.out ./core $(SRC_DIR)/*~ $(OBJ_DIR)/*.o
  rm -f ../svn-commit.tmp~
  rm -f $(BIN_DIR)/$(PROJECT)
  $(MAKE) -C gtest-1.4.0/make clean
若言繁花未落 2024-08-27 07:51:06

http://www.gnu.org/software/make/manual/make.html#Recursion< /a>

 subsystem:
         cd subdir && $(MAKE)

或者,等效地,这个:

 subsystem:
         $(MAKE) -C subdir

http://www.gnu.org/software/make/manual/make.html#Recursion

 subsystem:
         cd subdir && $(MAKE)

or, equivalently, this :

 subsystem:
         $(MAKE) -C subdir
梦途 2024-08-27 07:51:06

看起来很明显 $(TESTS) 是空的,所以你的 1.4.0 makefile 是有效的

all: 

clean:
  rm -f  gtest.a gtest_main.a *.o

事实上,一切都没有关系。 clean 确实如其所说rm -f gtest.a ...

It seems clear that $(TESTS) is empty so your 1.4.0 makefile is effectively

all: 

clean:
  rm -f  gtest.a gtest_main.a *.o

Indeed, all has nothing to do. and clean does exactly what it says rm -f gtest.a ...

风吹雨成花 2024-08-27 07:51:06

在父 makefile 中,

clean:
    cd $(PWD)/path/to/project/gtest-1.4.0 && $(MAKE) clean

为了使其正常工作,在 /path/to/project/gtest-1.4.0 下必须存在一个带有 cleanma​​kefile诸如 follow

child makefile之类的选项

clean:
    rm -f where_you_want

in parent makefile put

clean:
    cd $(PWD)/path/to/project/gtest-1.4.0 && $(MAKE) clean

in order this to work, under /path/to/project/gtest-1.4.0 must exist a makefile with clean option like follow

child makefile

clean:
    rm -f where_you_want
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文