$(@:.o=.P); \ $(RM) -f $(@:.o=.d) endef vpath %.c . $(TOP) -6ren">
gpt4 book ai didi

makefile - GNU 使 "Removing intermediate files"

转载 作者:行者123 更新时间:2023-12-04 11:15:34 34 4
gpt4 key购买 nike

我有以下规则

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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com