我的問題是要更好地理解我在製作過程中錯過了什麼.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