My question is to better understand what I missed in the make process and the purpose of .ECECDDARY vs .PRECIOUS, so as not to work with my script work, as it already works.
I use make to either open the emacs editor in a file (java but not relevant for this question), or create it using a template if it does not exist.
If it works well with existing files, when using the generated file, it is deleted at the end .
I added the precondition to .SECONDARY, but it did not help, I had to add it to .PRECIOUS.
This is a question , why didn’t it work in .ECECDDARY? .
From what I found on SO .SECONDARY does not work with templates (%) , but even knowing that I am wondering if this is by design or this is a mistake in make. ( .SECONDARY for a template rule with GNU Make and the Template rule Makefile ignores the fake rule or spontaneously deletes the output file )
Here the contents of my Makefile are cut out to reproduce my problem (create the com / stackoverflow / question directory to check 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/%
try
do the job / SoTest
I understand that this is marked as intermediate.
and then looking in SO, I tried to install it .SECONDARY: target list: doesn't work either.
looking at make source code, I noticed that deleting intermediate files is done in this context:
if (f->intermediate && (f->dontcare || !f->precious) && !f->secondary && !f->cmd_target)
so I install my file in .PRECIOUS: and now it works.
console is displayed:
com / stackoverflow / question / soTest.java
it starts emacs with the correct template, so the creation is ok here i exit emacs
and it deletes the file at the end
rm com / stackoverflow / question / SoTest.java
The removal at the end is associated with an intermediate file, this can be seen using the -d option on make
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
For it to work, I need to uncomment the .PRECIOUS item.
make --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.