我的问题是要更好地理解我在制作过程中错过了什么.SECONDARY目的与PRECIOUS,不要让我的脚本工作,因为它已经工作。为什么.SECONDARY不支持模式(%),而.PRECIOUS呢?
我正在使用make来打开一个文件(java但与此问题无关)的emacs编辑器,或者使用模板(如果不存在)创建它。
如果它与现有文件很好地协作,使用生成的文件时,它将在末尾被删除。
我在.SECONDARY中添加了先决条件,但没有帮助,我不得不将它添加到.PRECIOUS中。
这是问题为什么它不在.SECONDARY中工作?。
从我发现SO .SECONDARY不与模式(%)工作,但即使知道,我不知道这是由设计,或者如果它是在化妆的错误。 (.SECONDARY for a pattern rule with GNU Make和Makefile pattern rule either ignores phony rule or spontaneously deletes output file)
这里是我的Makefile的一个精简的内容来重现我的问题(请创建一个com/stackoverflow/question目录来测试它)。
PACKAGE=com.stackoverflow.question
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
OUT=out
clean:
find $(OUT) -name "*.class" -type f -print0|xargs -0 rm
# does not work : deleted at end due to intermediate file removal.
$(PACKAGE_DIR)/%.java:
@echo "package com.stackoverflow.question;\npublic class $(subst .java,,$(subst $(PACKAGE_DIR)/,,[email protected]))\n{\n /** TODO */ \n}" >[email protected]
work/%: $(PACKAGE_DIR)/$(subst work/,,%).java
emacs $<
.PHONY: clean work/%
# tried to avoid intermediate file removal : does not work
.SECONDARY: $(PACKAGE_DIR)/%.java
# if not commented this does work : once precious intermediate file is not removed.
#.PRECIOUS: $(PACKAGE_DIR)/%.java
尝试
使工作/ SoTest
我明白这是标记中间。
然后看在SO我试图设置它.SECONDARY:目标列表:也不工作。
看着化妆源代码,我发现,使中间文件去除这一背景下完成的:
if (f->intermediate && (f->dontcare || !f->precious)
&& !f->secondary && !f->cmd_target)
,所以我把我的文件中.PRECIOUS:现在它的工作原理。
它显示安慰:
COM /计算器/问题/ SoTest.java
它运行与合适的模板的emacs在这么创作是OK 这里我退出Emacs
并删除文件末尾
rm com/stackoverflow/question/SoTest。java的
去除月底是由于中间文件,这可以用在化妆
-d选项中可以看出LANG = C使-d工作/ SoTest
...
Must remake target 'work/SoTest'.
emacs com/stackoverflow/question/SoTest.java
Putting child 0xc3b580 (work/SoTest) PID 20681 on the chain.
Live child 0xc3b580 (work/SoTest) PID 20681
Reaping winning child 0xc3b580 PID 20681
Removing child 0xc3b580 PID 20681 from chain.
Successfully remade target file 'work/SoTest'.
Removing intermediate files...
rm com/stackoverflow/question/SoTest.java
有它的工作,我需要取消.PRECIOUS段的注释。
使--version
GNU Make 4.0
Construit pour x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
Licence GPLv3+ : GNU GPL version 3 ou ultérieure <http://gnu.org/licenses/gpl.html>
Ceci est un logiciel libre : vous êtes autorisé à le modifier et à la redistribuer.
Il ne comporte AUCUNE GARANTIE, dans la mesure de ce que permet la loi.
http://stackoverflow.com/questions/17625394/secondary-for-a-pattern-rule-with-gnu-make inidicates **。宝贵的作品与模式,但奇怪的是,没有.SECONDARY。**会解释这种行为。 – 2014-11-23 17:05:40
**我们显然不能使用%.out作为.SECONDARY的目标。**看来另一个确认wihtin http://stackoverflow.com/questions/19883282/makefile-pattern-rule-either-ignores-phony-rule-or -spontaneously-deletes-output/19892035#19892035 – 2014-11-23 17:24:39
请注意,.PRECIOUS在作为.SECONDARY的替代方法时有缺点:make不会因信号而删除中断文件,这会打开部分写入的对象文件到达的可能性链接器([source](https://www.gnu.org/software/make/manual/html_node/Interrupts.html))。 – alexei 2015-09-29 00:10:26