pdftk in Makefile gets executed every time - makefile

when using pdftk to extract pages in a Makefile, the pdftk command always get executed regardless of whether the prerequisite pdf file changed or not.
document.tex:
\documentclass[10pt]{article}
\begin{document}
Page one
\newpage
Page two
\end{document}
Make pdf file:
pdflatex document.tex
Makefile:
all: document page-one
document: document.tex
pdflatex $<
page-one: document
pdftk A=$<.pdf cat A1 output PageOne.pdf
Every time I do
make all
The pdftk command is executed. I would like to only extract the page if the parent document changed. Any ideas? Ultimately the pdflatex command would go in the Makefile as well but in order to highlight the problem I left it out.
Edit:
Please note, I changed the Makefile for clarity. And here are two runs as requested.
The first run produces
$ make -dRr page-one
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
Considering target file `Makefile'.
Looking for an implicit rule for `Makefile'.
No implicit rule found for `Makefile'.
Finished prerequisites of target file `Makefile'.
No need to remake target `Makefile'.
Updating goal targets....
Considering target file `page-one'.
File `page-one' does not exist.
Considering target file `document'.
File `document' does not exist.
Considering target file `document.tex'.
Looking for an implicit rule for `document.tex'.
No implicit rule found for `document.tex'.
Finished prerequisites of target file `document.tex'.
No need to remake target `document.tex'.
Finished prerequisites of target file `document'.
Must remake target `document'.
pdflatex document.tex
Putting child 0x0198c5c0 (document) PID 4347 on the chain.
Live child 0x0198c5c0 (document) PID 4347
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./document.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, ngerman, german, german-x-2009-06-19, ngerman-x-2009-06-19, loaded,
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo)) (./document.aux) [1{/var/
lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] (./document.aux) )</usr/shar
e/texmf-texlive/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on document.pdf (2 pages, 13250 bytes).
Transcript written on document.log.
Reaping winning child 0x0198c5c0 PID 4347
Removing child 0x0198c5c0 PID 4347 from chain.
Successfully remade target file `document'.
Finished prerequisites of target file `page-one'.
Must remake target `page-one'.
pdftk A=document.pdf cat A1 output PageOne.pdf
Putting child 0x0198ea40 (page-one) PID 4348 on the chain.
Live child 0x0198ea40 (page-one) PID 4348
Reaping winning child 0x0198ea40 PID 4348
Removing child 0x0198ea40 PID 4348 from chain.
Successfully remade target file `page-one'.
And the second time:
$ make -dRr page-one
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
Considering target file `Makefile'.
Looking for an implicit rule for `Makefile'.
No implicit rule found for `Makefile'.
Finished prerequisites of target file `Makefile'.
No need to remake target `Makefile'.
Updating goal targets....
Considering target file `page-one'.
File `page-one' does not exist.
Considering target file `document'.
File `document' does not exist.
Considering target file `document.tex'.
Looking for an implicit rule for `document.tex'.
No implicit rule found for `document.tex'.
Finished prerequisites of target file `document.tex'.
No need to remake target `document.tex'.
Finished prerequisites of target file `document'.
Must remake target `document'.
pdflatex document.tex
Putting child 0x019ef5c0 (document) PID 4398 on the chain.
Live child 0x019ef5c0 (document) PID 4398
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./document.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, ngerman, german, german-x-2009-06-19, ngerman-x-2009-06-19, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo)) (./document.aux) [1{/var/
lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] (./document.aux) )</usr/shar
e/texmf-texlive/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on document.pdf (2 pages, 13250 bytes).
Transcript written on document.log.
Reaping winning child 0x019ef5c0 PID 4398
Removing child 0x019ef5c0 PID 4398 from chain.
Successfully remade target file `document'.
Finished prerequisites of target file `page-one'.
Must remake target `page-one'.
pdftk A=document.pdf cat A1 output PageOne.pdf
Putting child 0x019f1a40 (page-one) PID 4399 on the chain.
Live child 0x019f1a40 (page-one) PID 4399
Reaping winning child 0x019f1a40 PID 4399
Removing child 0x019f1a40 PID 4399 from chain.
Successfully remade target file `page-one'.

To get this Makefile working you have to specify existing targets, ie. real filenames (including the suffix). Moreover, you are creating a file called PageOne.pdf but check for a file called page-one which cannot be found.
That's more or less what you posted above:
...
Considering target file `page-one'.
File `page-one' does not exist.
Considering target file `document'.
File `document' does not exist.`
...
A working Makefile would look like
all: document.pdf page-one.pdf
document.pdf: document.tex
pdflatex $<
page-one.pdf: document.pdf
pdftk A=$< cat A1 output page-one.pdf

Related

Why is Make ignoring an explicit pattern rule?

I'm using GNU Make 4.0 to compile code on an IBM i system. Make is inexplicably choosing the wrong rule to build one type of object.
On this platform, program objects are built from modules, which are compiled from source code. There is also a convenience shortcut command that will create a program directly from a single piece of source code by creating a temporary module from the source code and then building a program from that. The problem I'm running into is that Make is using the shortcut command (crtbndrpg) instead of the two-step version (crtrpgmod + crtpgm), even though the target rule specifies that the program should be built from a module and not the shortcut.
There are two makefiles: a generic one that describes how to create IBM i objects, and a project-specific one that describes object dependencies for all items in this project and includes the generic one. My generic makefile looks like this (edited for simplicity):
# `IBMiMake`, a generic makefile that describes how to create IBM i objects.
OBJPATH := $(CURDIR)
override OBJPATH := $(shell echo "$(OBJPATH)" | tr '[:lower:]' '[:upper:]')
%.MODULE: %.RPGLE
$(eval crtcmd := crtrpgmod module($(OBJLIB)/$*) srcstmf('$<') $(CRTRPGMODFLAGS))
#system "$(crtcmd)" > $(LOGPATH)/$(notdir $<).log
%.PGM: %.RPGLE
$(eval crtcmd := crtbndrpg pgm($(OBJLIB)/$*) srcstmf('$<') $(CRTBNDRPGFLAGS))
system "$(crtcmd)" >$(LOGPATH)/$(notdir $<).log 2>&1
%.PGM:
$(eval crtcmd := crtpgm pgm($(OBJLIB)/$*) module($(basename $(filter %.MODULE,$(notdir $^)))) $(CRTPGMFLAGS))
system "$(crtcmd)" >$(LOGPATH)/$#.log 2>&1
The project-specific makefile looks like this (also edited for simplicity):
# `xpmake`, to create objects in this project.
ROOTDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
IBMIMAKE := $(ROOTDIR)/../SDE/IBMiMake
include $(IBMIMAKE)
# AB2001.B.MODULE -- CRTRPGMOD
AB2001.B.MODULE: AB2001.B.RPGLE
# AB2001.B.PGM -- CRTPGM
AB2001.B.PGM: AB2001.B.MODULE
To build the object in question:
bash-4.2$ make AB2001.B.PGM OBJPATH:='/qsys.lib/xp33make.lib' -f xp33make/xpmake -d --no-builtin-rules
What should happen: It should first create the module using the crtrpgmod command, which it does. It should then create the program using the crtpgm command. Instead of creating the program via crtpgm, however, it for some reason tries to use the crtbndrpg command to directly build the program from source code. The only thing I can think of is that perhaps Make is seeing AB2001.B.MODULE as an intermediate file and opting to bypass the crtrpgmod step. Could this be true? How do I get make to follow my rules and not try to overthink things?
Here is the output:
GNU Make 4.0
Built for powerpc-ibm-aix5.3.0.0
Copyright (C) 1988-2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'xp33make/xpmake'...
Reading makefile '/home/SMEEP/Source/xp33make/../SDE/IBMiMake' (search path) (no ~ expansion)...
Updating makefiles....
Considering target file '/home/SMEEP/Source/xp33make/../SDE/IBMiMake'.
Looking for an implicit rule for '/home/SMEEP/Source/xp33make/../SDE/IBMiMake'.
No implicit rule found for '/home/SMEEP/Source/xp33make/../SDE/IBMiMake'.
Finished prerequisites of target file '/home/SMEEP/Source/xp33make/../SDE/IBMiMake'.
No need to remake target '/home/SMEEP/Source/xp33make/../SDE/IBMiMake'.
Considering target file 'xp33make/xpmake'.
Looking for an implicit rule for 'xp33make/xpmake'.
No implicit rule found for 'xp33make/xpmake'.
Finished prerequisites of target file 'xp33make/xpmake'.
No need to remake target 'xp33make/xpmake'.
Updating goal targets....
Considering target file 'AB2001.B.PGM'.
File 'AB2001.B.PGM' does not exist.
Looking for an implicit rule for 'AB2001.B.PGM'.
Trying pattern rule with stem 'AB2001.B'.
Trying implicit prerequisite 'AB2001.B.CLLE'.
Trying pattern rule with stem 'AB2001.B'.
Trying implicit prerequisite 'AB2001.B.RPGLE'.
Found an implicit rule for 'AB2001.B.PGM'.
Considering target file 'AB2001.B.RPGLE'.
Looking for an implicit rule for 'AB2001.B.RPGLE'.
No implicit rule found for 'AB2001.B.RPGLE'.
Finished prerequisites of target file 'AB2001.B.RPGLE'.
No need to remake target 'AB2001.B.RPGLE'; using VPATH name '/home/SMEEP/Source/xp33make/AB2001.B.RPGLE'.
Considering target file 'AB2001.B.MODULE'.
Looking for an implicit rule for 'AB2001.B.MODULE'.
Trying pattern rule with stem 'AB2001.B'.
Trying implicit prerequisite 'AB2001.B.C'.
Trying pattern rule with stem 'AB2001.B'.
Trying implicit prerequisite 'AB2001.B.CLLE'.
Trying pattern rule with stem 'AB2001.B'.
Trying implicit prerequisite 'AB2001.B.RPGLE'.
Found prerequisite 'AB2001.B.RPGLE' as VPATH '/home/SMEEP/Source/xp33make/AB2001.B.RPGLE'
Found an implicit rule for 'AB2001.B.MODULE'.
Pruning file '/home/SMEEP/Source/xp33make/AB2001.B.RPGLE'.
Pruning file '/home/SMEEP/Source/xp33make/AB2001.B.RPGLE'.
Finished prerequisites of target file 'AB2001.B.MODULE'.
Prerequisite '/home/SMEEP/Source/xp33make/AB2001.B.RPGLE' is older than target 'AB2001.B.MODULE'.
Prerequisite '/home/SMEEP/Source/xp33make/AB2001.B.RPGLE' is older than target 'AB2001.B.MODULE'.
No need to remake target 'AB2001.B.MODULE'; using VPATH name '/QSYS.LIB/XP33MAKE.LIB/AB2001.B.MODULE'.
Finished prerequisites of target file 'AB2001.B.PGM'.
Must remake target 'AB2001.B.PGM'.
system "crtbndrpg pgm(XP33MAKE/AB2001.B) srcstmf('/home/SMEEP/Source/xp33make/AB2001.B.RPGLE')" >/home/SMEEP/Source/xp33make/Logs/2016-11-14_11.42.55-Mon/AB2001.B.RPGLE.log 2>&1
Putting child 30016df0 (AB2001.B.PGM) PID 1155363 on the chain.
Live child 30016df0 (AB2001.B.PGM) PID 1155363
Reaping losing child 30016df0 PID 1155363
/home/SMEEP/Source/xp33make/../SDE/IBMiMake:476: recipe for target 'AB2001.B.PGM' failed
Removing child 30016df0 PID 1155363 from chain.
Your example is still difficult to read: creating a minimal example is usually best (that is, construct an example that uses touch etc. to create files, and doesn't depend on your environment).
Also, the use of $(eval ...) inside the recipe to create a make variable assignment is a bit confusing. Don't think that just because you do this in the recipe there's some kind of scoping involved: those variables are still globally assigned.
In any event, the problem is that you have two ways to build a target that matches %.PGM:
%.PGM: %.RPGLE
%.PGM:
You apparently want to use the second one, but if the stem of a matching pattern rule is has equal length (here both have the same stem, .PGM) then make will always choose the first pattern that you define so it will always choose the first one if it can.
So, it will always use crtbndrpg to build that target, as long as make can figure out how to build %.RPGLE, so that pattern rule will match.
I'm not sure if they're omitted in the simplifying process, but your explicit rules lack their recipes.
Pattern rules with no recipe mean canceling any existing implicit rules.
https://www.gnu.org/software/make/manual/html_node/Canceling-Rules.html

make SECONDEXPANSION broken by implicit rule recursion?

I'd like to use .SECONDEXPANSION: as described on http://make.mad-scientist.net/secondary-expansion. I have the following makefile:
.SECONDEXPANSION:
x.deps := y.foo
%.foo: $$($$*.deps)
echo $#
Unfortunately, when I try make x.foo, I get
make: *** No rule to make target `.foo'. Stop.
Running it with -Rd, I get
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
[...]
Updating goal targets....
Considering target file `x.foo'.
File `x.foo' does not exist.
Looking for an implicit rule for `x.foo'.
Trying pattern rule with stem `x'.
Trying rule prerequisite `y.foo'.
Trying pattern rule with stem `x'.
Trying rule prerequisite `y.foo'.
Looking for a rule with intermediate file `y.foo'.
Avoiding implicit rule recursion.
No implicit rule found for `x.foo'.
Finished prerequisites of target file `x.foo'.
Must remake target `x.foo'.
make: *** No rule to make target `x.foo'. Stop.
I guess it's not working because, according to the docs, "No single implicit rule can appear more than once in a chain." But that's exactly what I need -- for x.foo to resolve to y.foo, which resolves to a rule with no dependencies. My application demands the uniform (*.foo) naming scheme. Can anyone suggest a work-around? BTW, unfortunately, I must use make 3.81, not something more recent.

make always remakes PHONY static rule targets

I've been scratching my head for about an hour now, and Google has proved of limited use.
I have a Makefile for a report which contains graphs. The graphs are represented by .plot files inside the directory graphs/, and gnuplot is used to generate .tex and .eps files from them. ps2pdf is then used to generate a pdf from the .eps, and finally an \include command inside report.tex includes the graph .tex into the document, which again includes the graph .pdf to put the graph in the final report.pdf.
I have a Makefile which builds everything correctly, but for some reason, make insists on remaking report.pdf every time I run make. A read through the ouput of make -d reveals that Make says: "Must remake target mp-int-2.4-ni'." and "Must remake targetmp-int-2.4-i'." every run, but these are declared as PHONY, and thus shouldn't be remade unless something they depend on has change. Or at least so I thought?
Any thoughts on what might be causing this and how I might avoid having to remake the final pdf every time?
Makefile
GRAPHS := mp-int-2.4-ni mp-int-2.4-i
.PHONY : $(GRAPHS)
.PRECIOUS : graphs/%.pdf
report.pdf: report.tex $(GRAPHS)
# ...
$(GRAPHS): %: graphs/%.pdf graphs/%.tex
graphs/%.pdf: graphs/%.eps
# ...
graphs/%.tex graphs/%.eps: graphs/%.plot
# ...
make -d after make has already been run
$ make -d | grep -Ev "Trying|Reject|Avoid|intermediate"
Considering target file `report.pdf'.
Considering target file `report.tex'.
Looking for an implicit rule for `report.tex'.
No implicit rule found for `report.tex'.
Finished prerequisites of target file `report.tex'.
No need to remake target `report.tex'.
Considering target file `mp-int-2.4-i'.
File `mp-int-2.4-i' does not exist.
Considering target file `graphs/mp-int-2.4-i.pdf'.
Looking for an implicit rule for `graphs/mp-int-2.4-i.pdf'.
Found an implicit rule for `graphs/mp-int-2.4-i.pdf'.
Considering target file `graphs/mp-int-2.4-i.plot'.
Looking for an implicit rule for `graphs/mp-int-2.4-i.plot'.
No implicit rule found for `graphs/mp-int-2.4-i.plot'.
Finished prerequisites of target file `graphs/mp-int-2.4-i.plot'.
No need to remake target `graphs/mp-int-2.4-i.plot'.
Finished prerequisites of target file `graphs/mp-int-2.4-i.pdf'.
Prerequisite `graphs/mp-int-2.4-i.eps' of target `graphs/mp-int-2.4-i.pdf' does not exist.
No need to remake target `graphs/mp-int-2.4-i.pdf'.
Considering target file `graphs/mp-int-2.4-i.tex'.
Looking for an implicit rule for `graphs/mp-int-2.4-i.tex'.
Found an implicit rule for `graphs/mp-int-2.4-i.tex'.
Pruning file `graphs/mp-int-2.4-i.plot'.
Pruning file `graphs/mp-int-2.4-i.plot'.
Finished prerequisites of target file `graphs/mp-int-2.4-i.tex'.
Prerequisite `graphs/mp-int-2.4-i.plot' is older than target `graphs/mp-int-2.4-i.tex'.
No need to remake target `graphs/mp-int-2.4-i.tex'.
Finished prerequisites of target file `mp-int-2.4-i'.
Must remake target `mp-int-2.4-i'.
Successfully remade target file `mp-int-2.4-i'.
Considering target file `mp-int-2.4-ni'.
File `mp-int-2.4-ni' does not exist.
Considering target file `graphs/mp-int-2.4-ni.pdf'.
Looking for an implicit rule for `graphs/mp-int-2.4-ni.pdf'.
Found an implicit rule for `graphs/mp-int-2.4-ni.pdf'.
Considering target file `graphs/mp-int-2.4-ni.plot'.
Looking for an implicit rule for `graphs/mp-int-2.4-ni.plot'.
No implicit rule found for `graphs/mp-int-2.4-ni.plot'.
Finished prerequisites of target file `graphs/mp-int-2.4-ni.plot'.
No need to remake target `graphs/mp-int-2.4-ni.plot'.
Finished prerequisites of target file `graphs/mp-int-2.4-ni.pdf'.
Prerequisite `graphs/mp-int-2.4-ni.eps' of target `graphs/mp-int-2.4-ni.pdf' does not exist.
No need to remake target `graphs/mp-int-2.4-ni.pdf'.
Considering target file `graphs/mp-int-2.4-ni.tex'.
Looking for an implicit rule for `graphs/mp-int-2.4-ni.tex'.
Found an implicit rule for `graphs/mp-int-2.4-ni.tex'.
Pruning file `graphs/mp-int-2.4-ni.plot'.
Pruning file `graphs/mp-int-2.4-ni.plot'.
Finished prerequisites of target file `graphs/mp-int-2.4-ni.tex'.
Prerequisite `graphs/mp-int-2.4-ni.plot' is older than target `graphs/mp-int-2.4-ni.tex'.
No need to remake target `graphs/mp-int-2.4-ni.tex'.
Finished prerequisites of target file `mp-int-2.4-ni'.
Must remake target `mp-int-2.4-ni'.
Successfully remade target file `mp-int-2.4-ni'.
Finished prerequisites of target file `report.pdf'.
Prerequisite `report.tex' is older than target `report.pdf'.
Prerequisite `mp-int-2.4-i' of target `report.pdf' does not exist.
Prerequisite `mp-int-2.4-ni' of target `report.pdf' does not exist.
Must remake target `report.pdf'.
Working Makefile after answer from Etan Reisner below:
GRAPHS := mp-int-2.4-i mp-int-2.4-ni
GRAPHS_WD := $(addprefix graphs/,$(GRAPHS))
REAL_GRAPHS := $(addsuffix .pdf,$(GRAPHS_WD)) $(addsuffix .tex,$(GRAPH_SWD))
.PHONY : clean
report.pdf: report.tex $(REAL_GRAPHS)
# ...
graphs/%.pdf: graphs/%.eps
# ..
graphs/%.tex graphs/%.eps: graphs/%.plot
# ..
A PHONY rule is one that you have told make doesn't correspond to an actual file so it isn't checking for the files to exist and so it always assumes the rule needs to run and so report.pdf has prerequisites that are newer (which is what that output is telling you).
The make documentation says "A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make goes to update that file." [ref]
What was your purpose in marking those files as PHONY?

GNU make drops target in implicit rule?

If I run the following makefile under GNU Make 3.81 / RHEL5:
all: A1B/C A1B/D A2B/C A2B/D
A%B/C A%B/D: E.%
#echo "Creating '$#' from '$^' with stem '$*'"
E.1 E.2:
#echo "Generate '$#'"
I get the following output:
Generate 'E.1'
Creating 'A1B/C' from 'E.1' with stem '1'
Generate 'E.2'
Creating 'A2B/C' from 'E.2' with stem '2'
Why are files A1B/D and A2B/D not generated?
(files with such names do not exist in my testcase)
If I specify the targets via the command line make states "Nothing to be done":
make A1B/C A1B/D A2B/C A2B/D
Generate 'E.1'
Creating 'A1B/C' from 'E.1' with stem '1'
make: Nothing to be done for `A1B/D'.
Generate 'E.2'
Creating 'A2B/C' from 'E.2' with stem '2'
make: Nothing to be done for `A2B/D'.
If I duplicate the implicit rule into their targets it works:
all: A1B/C A1B/D A2B/C A2B/D
A%B/C: E.%
#echo "Creating '$#' from '$^' with stem '$*'"
A%B/D: E.%
#echo "Creating '$#' from '$^' with stem '$*'"
E.1 E.2:
#echo "Generate '$#'"
Generate 'E.1'
Creating 'A1B/C' from 'E.1' with stem '1'
Creating 'A1B/D' from 'E.1' with stem '1'
Generate 'E.2'
Creating 'A2B/C' from 'E.2' with stem '2'
Creating 'A2B/D' from 'E.2' with stem '2'
According to the documentation this should not make a difference.
Thanks in advance.
Michael
You're not quite right about the documentation saying there's no difference. If you have a pattern rule with multiple targets (and you do), make assumes both will be made in a single execution of the recipe.
From the GNU make manual:
Pattern rules may have more than one target. Unlike normal rules, this does not act as many different rules with the same prerequisites and recipe. If a pattern rule has multiple targets, make knows that the rule's recipe is responsible for making all of the targets. The recipe is executed only once to make all the targets.
You can confirm this behaviour for your case:
$ make -r -d
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
Considering target file `Makefile'.
Looking for an implicit rule for `Makefile'.
No implicit rule found for `Makefile'.
Finished prerequisites of target file `Makefile'.
No need to remake target `Makefile'.
Updating goal targets....
Considering target file `all'.
File `all' does not exist.
Looking for an implicit rule for `all'.
No implicit rule found for `all'.
Considering target file `A1B/C'.
File `A1B/C' does not exist.
Looking for an implicit rule for `A1B/C'.
Trying pattern rule with stem `1'.
Trying implicit prerequisite `E.1'.
Found an implicit rule for `A1B/C'.
Considering target file `E.1'.
File `E.1' does not exist.
Finished prerequisites of target file `E.1'.
Must remake target `E.1'.
Putting child 0x7fcad3c08440 (E.1) PID 34127 on the chain.
Live child 0x7fcad3c08440 (E.1) PID 34127
Generate 'E.1'
Reaping winning child 0x7fcad3c08440 PID 34127
Removing child 0x7fcad3c08440 PID 34127 from chain.
Successfully remade target file `E.1'.
Finished prerequisites of target file `A1B/C'.
Must remake target `A1B/C'.
Putting child 0x7fcad3c08710 (A1B/C) PID 34128 on the chain.
Live child 0x7fcad3c08710 (A1B/C) PID 34128
Creating 'A1B/C' from 'E.1' with stem '1'
Reaping winning child 0x7fcad3c08710 PID 34128
Removing child 0x7fcad3c08710 PID 34128 from chain.
Successfully remade target file `A1B/C'.
Considering target file `A1B/D'.
File `A1B/D' was considered already.
Considering target file `A2B/C'.
File `A2B/C' does not exist.
Looking for an implicit rule for `A2B/C'.
Trying pattern rule with stem `2'.
Trying implicit prerequisite `E.2'.
Found an implicit rule for `A2B/C'.
Considering target file `E.2'.
File `E.2' does not exist.
Finished prerequisites of target file `E.2'.
Must remake target `E.2'.
Putting child 0x7fcad3c08cd0 (E.2) PID 34129 on the chain.
Live child 0x7fcad3c08cd0 (E.2) PID 34129
Generate 'E.2'
Reaping winning child 0x7fcad3c08cd0 PID 34129
Removing child 0x7fcad3c08cd0 PID 34129 from chain.
Successfully remade target file `E.2'.
Finished prerequisites of target file `A2B/C'.
Must remake target `A2B/C'.
Putting child 0x7fcad3c08cd0 (A2B/C) PID 34130 on the chain.
Live child 0x7fcad3c08cd0 (A2B/C) PID 34130
Creating 'A2B/C' from 'E.2' with stem '2'
Reaping winning child 0x7fcad3c08cd0 PID 34130
Removing child 0x7fcad3c08cd0 PID 34130 from chain.
Successfully remade target file `A2B/C'.
Considering target file `A2B/D'.
File `A2B/D' was considered already.
Finished prerequisites of target file `all'.
Must remake target `all'.
Successfully remade target file `all'.
Notice these lines:
File `A1B/D' was considered already.
File `A2B/D' was considered already.

How to undo intermediate file deletion

I have a software stack that creates some intermediate files as a part of build process. There is some problem come up and the build breaks. I want to have a look at those intermediate generated files. To my surprise those files are being deleted as a part of build process.
Removing intermediate files...
rm fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o
I went through the Makefiles I don't see any explicit rules deleting them. Can there be any implicit rules to delete intermediate files. If yes how can I disable those implicit rules ?
I see the print Removing intermediate files... only if make is executed with --debug option.
skmt#tux:~/coding/factorial/ut$ make --debug
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
File `check' does not exist.
File `test_dept_run' does not exist.
File `fact_test' does not exist.
File `fact_using_proxies.o' does not exist.
File `fact_test_without_proxies' does not exist.
File `fact_test_without_proxies.o' does not exist.
File `fact_test_without_proxies.c' does not exist.
File `fact_test_main.c' does not exist.
Must remake target `fact_test_main.c'.
nm -p fact_test.o | build_main_from_symbols >fact_test_main.c
Successfully remade target file `fact_test_main.c'.
Must remake target `fact_test_without_proxies.c'.
cp fact_test_main.c fact_test_without_proxies.c
Successfully remade target file `fact_test_without_proxies.c'.
Must remake target `fact_test_without_proxies.o'.
gcc -I../src -c -o fact_test_without_proxies.o fact_test_without_proxies.c
Successfully remade target file `fact_test_without_proxies.o'.
Must remake target `fact_test_without_proxies'.
gcc fact_test_without_proxies.o fact.o fact_test.o -o fact_test_without_proxies
fact.o: In function `unknown':
fact.c:(.text+0x67): undefined reference to `do_update'
collect2: ld returned 1 exit status
make: *** [fact_test_without_proxies] Error 1
Removing intermediate files...
rm fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o
If you're using GNUMake, you can use the special target .PRECIOUS:
.PRECIOUS: fact_test_without_proxies.c fact_test_main.c fact_test_without_proxies.o
or just
.PRECIOUS: %.c %.o
Its only effect is that these files will not be deleted if Make is killed or interrupted.
You can also use .SECONDARY, which will preserve the specified files even if the build does not break.
e.g.
.SECONDARY:
There is a restriction on the use of targets, which affects the behaviour of .PRECIOUS:
I have targets A/%.foo: and B/%.foo: , so I have set:
.PRECIOUS: %.foo
and this did not work; I don't understand why, but expansion does not work this way; I had to explicitely list targets exactly as they are written:
.PRECIOUS: A/%.foo B/%.foo
But even after reading https://www.gnu.org/software/make/manual/html_node/Special-Targets.html I do not understand the difference between .PRECIOUS: and .SECONDARY: .
It's accepted to use those special targets without depends, but I think this would be very dirty coding and would expect side effects. Some people just put .PRECIOUS: or .SECONDARY: without dep, and later, they complain they have to run make clean after a broken build ...

Resources