makefile - GNU 使 "Removing intermediate files"

标签 makefile gnu-make

我有以下规则

define compile_c
$(ECHO) "CC $<"
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
@# The following fixes the dependency file.
@# See http://make.paulandlesley.org/autodep.html for details.
@# Regex adjusted from the above to play better with Windows paths, etc.
@$(CP) $(@:.o=.d) $(@:.o=.P); \
  $(SED) -e 's/#.*//' -e 's/^.*:  *//' -e 's/ *\\$$//' \
      -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
  $(RM) -f $(@:.o=.d)
endef

vpath %.c . $(TOP)
$(BUILD)/%.o: %.c $(BUILD)/%.pp
    $(call compile_c)

vpath %.c . $(TOP)

$(BUILD)/%.pp: %.c
    $(ECHO) "PreProcess $<"
    $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<

构建完成后,GNU make 说Removing intermediate files...并删除所有 .pp我做的文件 不是 想。

为什么要这样做?
我该如何阻止?

最佳答案

由于您使用的是 GNU Make,您可以对 Makefile 进行以下调整:

.PRECIOUS: $(BUILD)/%.pp  # ADD THIS LINE
$(BUILD)/%.pp: %.c
    $(ECHO) "PreProcess $<"
    $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<

documentation关于.PRECIOUS有这个说法吗指令:

The targets which .PRECIOUS depends on are given the following special treatment: if make is killed or interrupted during the execution of their recipes, the target is not deleted.

[...]

Also, if the target is an intermediate file, it will not be deleted after it is no longer needed, as is normally done.

[...]

You can also list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite file of the special target .PRECIOUS to preserve intermediate files created by rules whose target patterns match that file's name.



这样做的好处是不会创建不需要的附加规则。您尝试做的事情也更清楚:保留重新创建可能很昂贵的宝贵中间文件。

关于makefile - GNU 使 "Removing intermediate files",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47447369/

相关文章:

makefile - 我们可以在 makefile 中取消定义/取消设置变量吗

linux - 在 Linux 上安装 libs3

makefile - 你能优先考虑 makefile 目标吗?

makefile - 为什么 makefile 惰性求值会在 "parent"配方中找到一个文件,但找不到当前文件?

makefile - 所有 .cpp 文件都依赖于两个 .h 文件?

c++ - Makefile 未链接 .o 文件

makefile - 带有许多目标目录的 GNU make

makefile - 抑制 "make: Nothing to be done for ' 目标'”

c++ - g++ -std=c++11,标志没有生效

c - include_HEADERS 且没有 'all-am' 所需的目标规则