makefile - 强制 Makefile 中先决条件的顺序

标签 makefile gnu-make

我有一个第三方 makefile,我希望在首先构建另一个自定义目标 (T2) 之前不要构建其中一个目标 (T1)。通常,这将通过使 T2 成为 T1 的先决条件来实现。但是,T1 在其规则之一中使用 $^ .. 所以,通过添加先决条件,我最终破坏了构建......我所拥有的是:

T1: x y z T2
    $(MAKE) -j $^;
    # fails because T2 should not be passed to the make!!!

.PHONY: T2

T2:
    #do some linking and prep for T1

有没有好的方法可以确保 T2 在 T1 之前运行? (注:上面的例子其实是简化了一点。T1实际上是Linux内核makefile中的vmlinux目标,所以重写它不仅困难,而且使代码不可移植。另外,我之前不能运行T2由于某些其他依赖关系而在内核上调用 make )。

最佳答案

将 T2 作为 order-only prerequisite :

T1: x y z | T2
    $(MAKE) -j $^;
    # Make will run the T2 rule before this one, but T2 will not appear in $^

关于makefile - 强制 Makefile 中先决条件的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14267123/

相关文章:

ubuntu - make 总是重建所有目标

macos - 没有规则可以制作目标 `/Makefile' ,需要 `Makefile'

makefile - 检查 makefile 中是否定义了变量

c - 从应用程序 makefile 运行库 makefile

gnu-make - 读取makefile中的环境变量值

c - Makefile,添加位于父目录中的头文件(不允许在内部移动!)

c - 目标不知何故没有被创建

bash - 当规则调用脚本时如何定义 Makefile 目标?

linux - 对于 Makefile 变量的每个目标

c++ - KDE 应用程序在 'make install' 之后无法安装