Pergunta

I am developing a GNU Make file to allow me to compile all my LaTeX documents using a single command. To date I've been specifying the target on the command line but am tired of it.

My LaTex files are stored in a subfolder of the folder where I keep my PDF files.

My script is able to assemble the lists I need, but the code for the target and its rule list only processes the first LaTeX file found. I've been searching for hours now for an explanation on how to iterate through my file list in the target/rule section. My script is below:

rwildcard=${foreach d,${wildcard $1*},${call rwildcard,$d/,$2} ${filter ${subst *,%,$2},$d}}

# Sub-folder containing my LaTeX files
TEX_DIR=TeX

# Build a list of LaTeX files with the relative path included
TEX_SRCS_IN = ${call rwildcard, ${TEX_DIR}/, *.tex}
# Build a list of LaTeX files w/o paths
TEX_SRCS = $(TEX_SRCS_IN:$(TEX_DIR)/%=%)

# Build a list of PDF files that need to be generated
TEX_PDF_IN = ${foreach a, ${TEX_IN}, ${a:.tex=.pdf}}
# Then remove the path information
TEX_PDF = $(TEX_PDFIN:$(TEX_DIR)/%=%)

.PHONY: all
all: ${TEX_PDF}

${TEX_PDF} : ${TEX_SRCS_IN}
    clear &&                    \
    echo "Input List=${TEX_SRCS_IN}" &&         \
    echo "LaTeX Files=${TEX_SRCS}" &&       \
    echo "PDFs=${TEX_PDF}" &&           \
    cd ${TEX_DIR} &&                \
    pdflatex ${TEX_SRCS} &&             \
    cd ../ &&                   \
    mv $(TEX_DIR)/${TEX_PDF} .

I tried using a $(foreach doc,$(TEX_SRCS),pdflatex $(doc) && ) for the pdflatex processor and a similar statement for the move command, perhaps I didn't get the formatting right?

Below is the output I get from running the above. As can be seen, there are 6 files and the make file always makes the first file (GettingStarted.tex) but none of the rest. If I remove the lines: .PHONY: all all: ${TEX_PDF} then, once the first file is made, if it's up to date, the script tells me so and stops.

        user@mars:~/Desktop/Project/Docs$ make -f Makefile
clear &&                    \
    echo "Input List=                        TeX/GettingStarted.tex          TeX/GettingStarted_inst_Project_usb_Bridge.tex      TeX/GettingToUse.tex      TeX/DriverGettingStarted.tex  TeX/RaspberryPiGettingStarted.tex    TeX/instGettingStarted.tex" &&                    \
    echo "LaTeX Files=GettingStarted.tex GettingStarted_inst_Project_usb_Bridge.tex GettingToUse.tex DriverGettingStarted.tex RaspberryPiGettingStarted.tex instGettingStarted.tex" &&                  \
    echo "PDFs=GettingStarted.pdf GettingStarted_inst_Project_usb_Bridge.pdf GettingToUse.pdf DriverGettingStarted.pdf RaspberryPiGettingStarted.pdf instGettingStarted.pdf" &&                 \
    cd TeX &&                   \
    pdflatex GettingStarted.tex GettingStarted_inst_Project_usb_Bridge.tex GettingToUse.tex DriverGettingStarted.tex RaspberryPiGettingStarted.tex instGettingStarted.tex &&                    \
    cd ../ &&                       \
    mv TeX/GettingStarted.pdf GettingStarted_inst_Project_usb_Bridge.pdf GettingToUse.pdf DriverGettingStarted.pdf RaspberryPiGettingStarted.pdf instGettingStarted.pdf .

Input List=                        TeX/GettingStarted.tex          TeX/GettingStarted_inst_Project_usb_Bridge.tex      TeX/GettingToUse.tex      TeX/DriverGettingStarted.tex  TeX/RaspberryPiGettingStarted.tex    TeX/instGettingStarted.tex
LaTeX Files=GettingStarted.tex GettingStarted_inst_Project_usb_Bridge.tex GettingToUse.tex DriverGettingStarted.tex RaspberryPiGettingStarted.tex instGettingStarted.tex
PDFs=GettingStarted.pdf GettingStarted_inst_Project_usb_Bridge.pdf GettingToUse.pdf DriverGettingStarted.pdf RaspberryPiGettingStarted.pdf instGettingStarted.pdf
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)
 restricted \write18 enabled.
entering extended mode
(./GettingStarted.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./FillAFour.sty)
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty)
(/usr/share/texlive/texmf-dist/tex/latex/upquote/upquote.sty)
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.def))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg)

Package hyperref Warning: Option `a4paper' is no longer used.

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/backref.sty
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty)))

Package hyperref Message: Driver: hpdftex.

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def)
(./GettingStarted.aux)
(/usr/share/texlive/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./GettingStarted.out) (./GettingStarted.out)
(/usr/share/texlive/texmf-dist/tex/latex/base/omscmr.fd)
(/usr/share/texlive/texmf-dist/tex/latex/base/t1cmtt.fd) (./GettingStarted.toc
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]) [2]
Overfull \hbox (26.10161pt too wide) in paragraph at lines 207--207
\T1/cmtt/m/n/10 sudo apt-get install libavahi-cil-dev libavahi-compat-libdnssd1
 python-dev libicu-dev 


[25] [26] [27] [28] [29] [30] (./GettingStarted.aux) )

kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 ecbi1200
mktexpk: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1+0/600; nonstopmode; input ecbi1200
This is METAFONT, Version 2.718281 (TeX Live 2013/Debian)

(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/ecbi1200.mf
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exbase.mf)
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/ecbi.mf
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/extextit.mf
 Ok (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exaccess.mf
 Ok) (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/expseudo.mf
 Ok) (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exileast.mf
 Ok [158] [160] [161] [162] [163] [164] [165] [166] [167] [168] [169] [170]
[171] [172] [173] [174] [175] [176] [177] [178] [179] [180] [181] [182]
[183] [184] [185] [186] [187] [188])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exilwest.mf
 Ok [224] [225] [226] [227] [228] [229] [230] [231] [232] [233] [234] [235]
[236] [237] [238] [239] [240] [241] [242] [243] [244] [245] [246] [247]
[248] [249] [250] [251] [252] [253] [254] [255])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exruwest.mf
 Ok [192] [193] [194] [195] [196] [197] [198] [199] [200] [201] [202] [203]
[204] [205] [206] [207] [208] [209] [210] [211] [212] [213] [214] [215]
[216] [217] [218] [219] [220] [221] [222] [223])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrueast.mf
 Ok [128] [129] [130] [131] [132] [133] [134] [135] [136] [137] [138] [139]
[140] [141] [142] [143] [144] [145] [146] [147] [148] [149] [150] [151]
[152] [153] [154] [155] [156] [157])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exbraces.mf
 Ok [94] [126] [23] [40] [41] [60] [124] [62] [91] [93] [92] [123] [125]
[95] [127] [32])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/expunct.mf
 Ok [14] [15] [19] [20] [13] [18] [33] [39] [42] [43] [44] [46] [47] [58]
[59] [61] [96] [189] [17] [45] [16] [21] [22])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exaccent.mf
 Ok [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exsign.mf
 Ok [24] [34] [35] [36] [37] [64] [191] [159])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exilig.mf
 Ok [25] [26] [27] [28] [29] [30] [31])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exitalp.mf
 Ok [38] [63] [190])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrulett.mf
 Ok [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78]
[79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exillett.mf
 Ok [97] [98] [99] [100] [101] [102] [103] [104] [105] [106] [107] [108]
[109] [110] [111] [112] [113] [114] [115] [116] [117] [118] [119] [120]
[121] [122])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exidigit.mf
 Ok [48] [49] [50] [51] [52] [53] [54] [55] [56] [57])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exiligtb.mf
 Ok) ) ) )
(some charht values had to be adjusted by as much as 0.09164pt)
Font metrics written on ecbi1200.tfm.
Output written on ecbi1200.600gf (256 characters, 62216 bytes).
Transcript written on ecbi1200.log.
mktexpk: /tmp/texfonts/pk/ljfour/jkuserpen/ec/ecbi1200.600pk: successfully generated.
(see the transcript file for additional information) </tmp/texfonts/pk/ljfour/j
kuserpen/ec/ecbi1200.600pk>
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 0+525/600 --dpi 525 ectt0800
mktexpk: Running mf-nowin -progname=mf \mode:=ljfour; mag:=0+525/600; nonstopmode; input ectt0800
This is METAFONT, Version 2.718281 (TeX Live 2013/Debian)

(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/ecrm1200.mf
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exbase.mf)
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/ecrm.mf
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exroman.mf
 Ok (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exaccess.mf
 Ok) (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/expseudo.mf
 Ok) (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exruwest.mf
 Ok [192] [193] [194] [195] [196] [197] [198] [199] [200] [201] [202] [203]
[204] [205] [206] [207] [208] [209] [210] [211] [212] [213] [214] [215]
[216] [217] [218] [219] [220] [221] [222] [223])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrlwest.mf
 Ok [224] [225] [226] [227] [228] [229] [230] [231] [232] [233] [234] [235]
[236] [237] [238] [239] [240] [241] [242] [243] [244] [245] [246] [247]
[248] [249] [250] [251] [252] [253] [254] [255])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrueast.mf
 Ok [128] [129] [130] [131] [132] [133] [134] [135] [136] [137] [138] [139]
[140] [141] [142] [143] [144] [145] [146] [147] [148] [149] [150] [151]
[152] [153] [154] [155] [156] [157])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrleast.mf
 Ok [158] [160] [161] [162] [163] [164] [165] [166] [167] [168] [169] [170]
[171] [172] [173] [174] [175] [176] [177] [178] [179] [180] [181] [182]
[183] [184] [185] [186] [187] [188])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exbraces.mf
 Ok [94] [126] [23] [40] [41] [60] [124] [62] [91] [93] [92] [123] [125]
[95] [127] [32])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/expunct.mf
 Ok [14] [15] [19] [20] [13] [18] [33] [39] [42] [43] [44] [46] [47] [58]
[59] [61] [96] [189] [17] [45] [16] [21] [22])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exaccent.mf
 Ok [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exsign.mf
 Ok [24] [34] [35] [36] [37] [64] [191] [159])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrlig.mf
 Ok [25] [26] [28] [27] [29] [30] [31])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exromp.mf
 Ok [38] [63] [190])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrulett.mf
 Ok [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78]
[79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrllett.mf
 Ok [97] [98] [99] [100] [101] [102] [103] [104] [105] [106] [107] [108]
[109] [110] [111] [112] [113] [114] [115] [116] [117] [118] [119] [120]
[121] [122])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrdigit.mf
 Ok [48] [49] [50] [51] [52] [53] [54] [55] [56] [57])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrligtb.mf
 Ok) ) ) )
(some charht values had to be adjusted by as much as 0.07143pt)
Font metrics written on ecrm1200.tfm.
Output written on ecrm1200.600gf (256 characters, 60320 bytes).
Transcript written on ecrm1200.log.
mktexpk: /tmp/texfonts/pk/ljfour/jkuserpen/ec/ecrm1200.600pk: successfully generated.
 </tmp/texfonts/pk/ljfour/jkuserpen/ec/ecrm1200.600pk>
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 ecrm1728
mktexpk: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1+0/600; nonstopmode; input ecrm1728
This is METAFONT, Version 2.718281 (TeX Live 2013/Debian)

(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/ecrm1728.mf
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exbase.mf)
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/ecrm.mf
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exroman.mf
 Ok (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exaccess.mf
 Ok) (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/expseudo.mf
 Ok) (/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exruwest.mf
 Ok [192] [193] [194] [195] [196] [197] [198] [199] [200] [201] [202] [203]
[204] [205] [206] [207] [208] [209] [210] [211] [212] [213] [214] [215]
[216] [217] [218] [219] [220] [221] [222] [223])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrlwest.mf
 Ok [224] [225] [226] [227] [228] [229] [230] [231] [232] [233] [234] [235]
[236] [237] [238] [239] [240] [241] [242] [243] [244] [245] [246] [247]
[248] [249] [250] [251] [252] [253] [254] [255])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrueast.mf
 Ok [128] [129] [130] [131] [132] [133] [134] [135] [136] [137] [138] [139]
[140] [141] [142] [143] [144] [145] [146] [147] [148] [149] [150] [151]
[152] [153] [154] [155] [156] [157])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrleast.mf
 Ok [158] [160] [161] [162] [163] [164] [165] [166] [167] [168] [169] [170]
[171] [172] [173] [174] [175] [176] [177] [178] [179] [180] [181] [182]
[183] [184] [185] [186] [187] [188])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exbraces.mf
 Ok [94] [126] [23] [40] [41] [60] [124] [62] [91] [93] [92] [123] [125]
[95] [127] [32])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/expunct.mf
 Ok [14] [15] [19] [20] [13] [18] [33] [39] [42] [43] [44] [46] [47] [58]
[59] [61] [96] [189] [17] [45] [16] [21] [22])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exaccent.mf
 Ok [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exsign.mf
 Ok [24] [34] [35] [36] [37] [64] [191] [159])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrlig.mf
 Ok [25] [26] [28] [27] [29] [30] [31])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exromp.mf
 Ok [38] [63] [190])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrulett.mf
 Ok [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78]
[79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrllett.mf
 Ok [97] [98] [99] [100] [101] [102] [103] [104] [105] [106] [107] [108]
[109] [110] [111] [112] [113] [114] [115] [116] [117] [118] [119] [120]
[121] [122])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrdigit.mf
 Ok [48] [49] [50] [51] [52] [53] [54] [55] [56] [57])
(/usr/share/texlive/texmf-dist/fonts/source/jkuserpen/ec/exrligtb.mf
 Ok) ) ) )
(some charht values had to be adjusted by as much as 0.0972pt)
Font metrics written on ecrm1728.tfm.
Output written on ecrm1728.600gf (256 characters, 84608 bytes).
Transcript written on ecrm1728.log.
mktexpk: /tmp/texfonts/pk/ljfour/jkuserpen/ec/ecrm1728.600pk: successfully generated.
 </tmp/texfonts/pk/lj
four/jkuserpen/ec/ecrm1728.600pk></usr/share/texlive/texmf-dist/fonts/type1/publ
ic/amsfonts/cm/cmmi10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/ams
fonts/cm/cmsy10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/
cm/cmsy9.pfb>
Output written on GettingStarted.pdf (30 pages, 282962 bytes).
Transcript written on GettingStarted.log.
mv: cannot stat ‘GettingStarted_inst_Project_usb_Bridge.pdf’: No such file or directory
mv: cannot stat ‘GettingToUse.pdf’: No such file or directory
mv: cannot stat ‘DriverGettingStarted.pdf’: No such file or directory
mv: cannot stat ‘RaspberryPiGettingStarted.pdf’: No such file or directory
mv: cannot stat ‘instGettingStarted.pdf’: No such file or directory
make: *** [GettingStarted_inst_Project_usb_Bridge.pdf] Error 1
user@mars:~/Desktop/Project/Docs$ 

Looks to me like the .PHONY: all all: ${TEX_PDF} lines aren't producing the behaviour I want, but the main problem for me is that still; only the first file is processed.

How do I make the target and its rule list iterate through the whole list of files?

UPDATED

Almost fixed now, The problem was with the dependencies of ${TEX_PDF}.

It's making all the files now, however the dependency calculation is not working correctly.

Removing ${TEX_IN} and leaving it blank, and changing the way the dependency is referenced inside the rule (using the target's name ($@) and substituting the extension) made it work for a one shot run.

Changing the dependency to $(TEX_DIR)/$(@:.pdf=.tex) causes it to make ALL the files each run.

I've added a line to clean up the pdflatex auto-generated files ( .out, .log, .toc, and .aux) as a convenience. It can be edited or removed if not required.

rwildcard=${foreach d,${wildcard $1*},${call rwildcard,$d/,$2} ${filter ${subst *,%,$2},$d}}

TEX_DIR=TeX # Sub-folder containing TEX files
TEX_SRCS_IN = ${call rwildcard, ${TEX_DIR}/, *.tex} # 'TEX' List with paths
TEX_PDF_IN = ${foreach a, ${TEX_SRCS_IN}, ${a:.tex=.pdf} }  # 'PDF' List with paths
TEX_PDF = $(TEX_PDF_IN:$(TEX_DIR)/%=%)  # 'PDF' List without paths


.PHONY: all
all: ${TEX_PDF}

${TEX_PDF} : $(TEX_DIR)/$(@:.pdf=.tex)
    cd ${TEX_DIR} &&    \
    pdflatex $(@:.pdf=.tex) &&  \
    rm $(@:.pdf=.out) $(@:.pdf=.log) $(@:.pdf=.toc) $(@:.pdf=.aux) &&   \
    cd ../ &&   \
    mv $(TEX_DIR)/$@ .
Foi útil?

Solução 2

Finally fixed. Working now as I intended it to.

Changed the target definition to the generic form %.pdf with dependency defined similarly but in a subfolder ${TEX_DIR}/%.tex. Added a target/rule for the dependency using a NO-OP command.

# Usage:
#   From the ./Docs folder
#
#   Scan the TeX folder and make all necessary PDF's
#           make -f Makefile
#
#   Make a specific TEX file
#               make -f Makefile TEX_SRCS_IN=<filename>.tex
#
#
rwildcard=${foreach d,${wildcard $1*},${call rwildcard,$d/,$2} ${filter ${subst *,%,$2},$d}}

TEX_DIR=TeX # Sub-folder containing TEX files
TEX_SRCS_IN = ${call rwildcard, ${TEX_DIR}/, *.tex} # 'TEX' List with paths
TEX_PDF_IN = ${foreach a, ${TEX_SRCS_IN}, ${a:.tex=.pdf} }  # 'PDF' List with paths
TEX_PDF = $(TEX_PDF_IN:$(TEX_DIR)/%=%)  # 'PDF' List without paths


.PHONY: all
all: ${TEX_PDF}

%.pdf : ${TEX_DIR}/%.tex
    cd ${TEX_DIR} &&    \
    pdflatex $(@:.pdf=.tex) &&  \
    rm $(@:.pdf=.out) $(@:.pdf=.log) $(@:.pdf=.toc) $(@:.pdf=.aux) &&   \
    cd ../ &&   \
    mv $(TEX_DIR)/$@ .

${TEX_DIR}/%.tex:
    @:

Outras dicas

This is probably one of the top 3 most commonly asked questions about make. When you run make with no arguments it only builds the first target listed in the makefile. If you want it to build more than one target, you need to put a new target at the beginning of your makefile that depends on the other targets you want built.

So, add this line before the first target:

.PHONY: all
all: ${TEX_PDF}

ETA:

Only the first file is processed, because the end result of the processing the first file is a failure: make: *** [GettingStarted_inst_Project_usb_Bridge.pdf] Error 1. By default, make will stop after the first failure and won't build anything more. If you want it to keep going, you can run make -k.

But, I recommend you fix your failure, then it will continue.

The problem is the end of your rule, where you say:

mv $(TEX_DIR)/${TEX_PDF} .

TEX_PDF contains a list of files, so this expands to (as you can see from the output):

mv TeX/GettingStarted.pdf GettingStarted_inst_Project_usb_Bridge.pdf GettingToUse.pdf DriverGettingStarted.pdf RaspberryPiGettingStarted.pdf instGettingStarted.pdf .

which is obviously not what you want. You want to move just the one file that you're creating, which is given to you as an automatic variable $@.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top