Search code examples
makefilegnu-makepdftk

pdftk in Makefile gets executed every time


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'.

Solution

  • 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