为什么.SECONDARY不能与模式(%)一起使用,而.PRECIOUS可以呢? [英] Why .SECONDARY does not work with patterns (%) while .PRECIOUS does?

查看:96
本文介绍了为什么.SECONDARY不能与模式(%)一起使用,而.PRECIOUS可以呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是更好地了解我在制作过程中以及.SECONDARY用途与.PRECIOUS遗漏的内容,而不是让我的脚本正常工作,因为它已经可以正常工作了.

My question is to understand better what i missed in make process and .SECONDARY purpose vs .PRECIOUS, not to get my script working, since it does work already.

我正在使用make在文件上打开emacs编辑器(java,但与此问题无关),或者使用模板创建它(如果不存在).

I am using make to either open a emacs editor on a file ( java but irrelevant for purpose of this question ) or to create it with a template if not existing.

如果它与现有文件配合得很好,在使用生成的文件时,该文件将在最后被删除.

If it works well with existing files, when using generated file it is removed at the end.

我在.SECONDARY中添加了先决条件,但没有帮助,我不得不在.PRECIOUS中添加它.

I added prerequisite in .SECONDARY but didn't help, i had to add it in .PRECIOUS.

这是一个问题,为什么它不能在.SECONDARY中工作?.

根据我在SO上的发现 .SECONDARY不适用于模式(%),但是即使知道我想知道它是设计使然还是制造中的错误,也是如此. (.SECONDARY用于使用GNU Make的图案规则 Makefile模式规则要么忽略假音规则或自发删除输出文件)

From what i found on SO .SECONDARY does not work with patterns ( % ), but even with knowing that i wonder if it is by design or if it is a bug in make. ( .SECONDARY for a pattern rule with GNU Make and Makefile pattern rule either ignores phony rule or spontaneously deletes output file )

以下是我的Makefile的精简内容,以重现我的问题(请创建com/stackoverflow/question目录进行测试).

Here a stripped down content of my Makefile to reproduce my problem ( please create a com/stackoverflow/question directory to test it ).

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)/,,$@))\n{\n /** TODO */ \n}" >$@ 

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

我知道这是标记为中间的.

I understand this is flagged intermediate.

然后在SO中寻找,我尝试将其设置为.SECONDARY:目标列表:也不起作用.

then looking in SO i tried to set it in .SECONDARY: target list : does not work either.

查看我发现的make源代码,该代码在此上下文中完成了对make中间文件的删除:

looking at make source code i spotted that make intermediate files removal is done within this context :

if (f->intermediate && (f->dontcare || !f->precious)
    && !f->secondary && !f->cmd_target)

所以我将文件设置为.PRECIOUS:现在可以使用了.

so i set my file in .PRECIOUS: and now it works.

它显示到控制台:

com/stackoverflow/question/SoTest.java

com/stackoverflow/question/SoTest.java

它使用正确的模板运行emacs,因此可以正常创建 在这里我退出emacs

并在末尾删除文件

and it removes the file at the end

rm com/stackoverflow/question/SoTest.java

rm com/stackoverflow/question/SoTest.java

最后的删除是由于中间文件,可以在make的-d选项中看到

Removal at end is due to intermediate file, this can be seen with -d option on make

LANG = C使-d正常工作/SoTest

LANG=C make -d work/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段落的注释.

To have it working i need to uncomment the .PRECIOUS paragraph.

制作--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.

推荐答案

为什么.SECONDARY不能与模式(%)一起使用而.PRECIOUS可以呢?"的答案是 此处 :文件显示

The answer to "Why .SECONDARY does not work with patterns (%) while .PRECIOUS does?" is here: the document says

您还可以将隐式规则的目标模式(例如'%.o')列出为特殊目标.PRECIOUS的必备文件

You can also list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite file of the special target .PRECIOUS

,但关于.SECONDARY则不这样说.但是对于少数显式例外,没有一个特殊的目标接受模式.

but does not say this about .SECONDARY. But for the few explicit exceptions, none of the special targets accept patterns.

这篇关于为什么.SECONDARY不能与模式(%)一起使用,而.PRECIOUS可以呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆