linux - 多作业 make 中的 GNU Makefile 依赖

标签 linux gcc makefile gnu-make

我有一个linux下的c++项目。我正在使用 GNU make 和 GCC

我有以下规则:

all: ... 
version:
config:
  rm -f config.h
  @$(MAKE) --no-print-directory config.h
config.h:
 # ..... create the file config.h here

make version 增加内部版本号。 1.1-123,然后1.2-124 ...等。版本写在config.h文件中,config.h包含在项目的所有文件中。

现在的想法是在以下情况之一中重建 config.h: - 发布程序的一个版本时(而不仅仅是开发/测试) - 当它不存在时

所以我不想做这种依赖:

all: config
config: version

因为配置文件将在每次生成时重建,并且每个文件都将被重新编译,而不仅仅是更改的文件。所以我不想在开发时重新构建配置文件,但前提是我这样做了 make release_version 现在。可以说规则是:

release_version: config version all

问题是,当我执行 make release_version -j 3 时,它会同时生成所有 3 个目标(配置、版本、全部),这意味着该版本可能尚未准备好创建 config.h,然后 config.h 可能还没有为 all 准备好。所以我必须建立这种依赖关系:

发布版本:全部 全部:配置 配置:版本

但仅当执行make release_version 时。如果 make all 被执行,我不想有这些依赖。

也许我需要这样的东西:

release_version: version_release config_release all_release

all_release: 配置 config_release: 配置 version_release: 版本

最佳答案

你的例子有点随意。如果你重新阅读你所拥有的并澄清它会很好。 version 目标有什么作用? versionconfig 之间有什么关系?你没有在任何地方显示的这个 release_versionconfigversion 之间有什么关系?

如果我理解正确,你想要 all 规则,该规则将使用现有版本的 config.h 构建代码(如果它不存在则创建它),以及将更新 config.hrelease_version 规则,然后像 all 一样构建代码。我不确定 versionconfig 是做什么的。

你可以这样做,除非我遗漏了什么:

all: ...

release_version:
        @rm -f config.h
        @$(MAKE) config.h
        @$(MAKE) all

config.h:
        ...create config.h...

.PHONY: all release_version

还有很多其他选项。

关于linux - 多作业 make 中的 GNU Makefile 依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16486495/

相关文章:

Linux Centos Web 服务器软链接(soft link)(符号链接(symbolic link))问题

c - GCC编译不同文件夹中的多个文件

c++ - 不能毫无问题地从 auto_ptr 继承

在 solaris 10 sparc 上将 perl 编译为 64 位

c++ - 不在包含路径中搜索

linux - USVN 不工作

linux - 如何防止cmake剥离创建的共享库

linux - 如何提供Qt安装路径进行配置?

linux - 优化 sed 命令以获得更好的性能

c++ - Makefile 找不到包含路径