3 AONROOTREL := ../../../../..
4 AONROOTDIR = $(realpath $(AONROOTREL))
5 INSTALLDIR := ../FINAL/
6 # Relative location of the XML files
7 RELXMLDIR := $(AONROOTDIR)/$(BLANG)/xml/
8 XMLFILE=$(patsubst %.tex,$(RELXMLDIR)/%.xml,$(SOURCE))
9 # Relative location of the scripts
10 RELSCRIPT := $(AONROOTDIR)/common/scripts
12 XML2LATEX = $(RELSCRIPT)/gbtolatex.pl
14 LATEXXSL = $(AONROOTDIR)/common/xsl/latex.xsl
16 # Define ORIGSERIES unless defined
17 ORIGSERIES ?= $(SERIES)
19 # Define ILLUSTRATOR if not defined with a sane default
20 ILLUSTRATOR ?= williams
29 SOURCE=$(BASENAME).tex
31 EXTRAFILES=souvenir.sty
33 EXTRAFILES=ac1.tex crtneg.tex ac2.tex crtpos.tex random.tex ac3.tex \
34 souvenir.sty souverbt.sty
38 # Generate the LaTeX file from the XML file
39 $(SOURCE): $(XMLFILE) $(XML2LATEX) $(LATEXXSL) tweak.diff
40 AONPATH="$(AONROOTDIR)" perl $(XML2LATEX) $(BASENAME) $(BLANG) $@
41 $(AT)if ! test -s $(SOURCE) ; then \
42 echo "ERROR: Empty file $(SOURCE), check for errors above." >&2 ; \
46 $(AT)cp $(SOURCE) $(BASENAME)-untweaked.tex
47 $(AT)if test -f tweak.diff; then \
48 patch $(SOURCE) <tweak.diff ; \
51 # Extra TeX files needed for the PDFs
53 # This is for english content:
65 # This is for other translated content:
67 ln -s ../../shared/$(BLANG)/$@
69 ln -s ../../shared/$(BLANG)/$@
71 ln -s ../../shared/$(BLANG)/$@
73 ln -s ../../shared/$(BLANG)/$@
75 ln -s ../../shared/$(BLANG)/$@
77 # Shared across all languages
84 # Create empty tweak.diff if it does not exist
88 # Symlink the images needed for the PDF; unused images and HTML-specific images are ignored
90 $(AT)[ -n "$(SERIES)" ] || { echo "Error: SERIES variable not defined. Hint: Review the Makefile"; exit 1; }
91 $(AT)[ -n "$(SUBSERIES)" ] || { echo "Error: SUBSERIES variable not defined. Hint: Review the Makefile"; exit 1; }
92 $(AT)[ -n "$(BASENAME)" ] || { echo "Error: BASENAME variable not defined. Hint: Review the Makefile"; exit 1; }
93 $(AT)echo "Linking images for the book to working directory"
94 $(AT)[ -n "$(ILLUSTRATOR)" ] || { echo "Warning: ILLUSTRATOR variable not defined. Some illustrations might be missing. Hint: Review the Makefile"; }
95 $(AT)[ ! -n "$(ILLUSTRATOR)" ] || [ -d "$(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR)" ] || \
96 { echo "Warning: Folder $(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR) not found. Some illustrations might be missing."; }
97 $(AT)[ ! -n "$(ILLUSTRATOR)" ] || [ ! -d "$(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR)" ] || \
98 find $(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR)/ -name "*.pdf" | \
99 while read file ; do \
100 [ -e "`basename $$file`" ] || ln -s $$file . ; \
103 $(AT)for images in jpeg png ; do \
104 [ ! -d "$(AONROOTREL)/en/$$images/$(SERIES)/$(BASENAME)/" ] || find $(AONROOTREL)/en/$$images/$(SERIES)/$(BASENAME)/ \( -name "*.jpg" -o -name "*.png" \) | \
105 while read file ; do \
106 [ -e "`basename $$file`" ] || \
107 case "`basename $$file`" in \
108 back*|bckgrnd*|brdr*|forward*|left*|right*|title*|toc*) ;; \
109 ac*|crt*|random*) ;; \
110 *) ln -s $$file . ;; \
114 $(AT)[ ! -d "$(AONROOTREL)/en/pdf/$(SERIES)/$(SUBSERIES)" ] || find $(AONROOTREL)/en/pdf/$(SERIES)/$(SUBSERIES)/ -name "*.pdf" | \
115 while read file ; do \
116 [ -e "`basename $$file`" ] || ln -s $$file . ; \
119 $(AT)[ -n "$(ORIGSERIES)" ] || { echo "Error: ORIGSERIES variable not defined. Hint: Review the Makefile"; exit 1; }
120 $(AT)[ -n "$(ORIGBASENAME)" ] || { echo "Error: ORIGBASENAME variable not defined. Hint: Review the Makefile"; exit 1; }
121 $(AT)for images in jpeg png ; do \
122 [ ! -d "$(AONROOTREL)/$(BLANG)/$$images/$(SERIES)/$(BASENAME)/" ] || find $(AONROOTREL)/$(BLANG)/$$images/$(SERIES)/$(BASENAME)/ \( -name "*.jpg" -o -name "*.png" \) | \
123 while read file ; do \
124 [ -e "`basename $$file`" ] || ln -s $$file . ; \
126 [ ! -d "$(AONROOTREL)/en/$$images/$(ORIGSERIES)/$(ORIGBASENAME)/" ] || find $(AONROOTREL)/en/$$images/$(ORIGSERIES)/$(ORIGBASENAME)/ \( -name "*.jpg" -o -name "*.png" \) | \
127 while read file ; do \
128 rootname=`basename $$file | sed -e 's/\..*//'`; \
129 [ -e "$$rootname.jpg" ] || [ -e "$$rootname.png" ] || ln -s $$file . ; \
132 $(AT)[ ! -d "$(AONROOTREL)/$(BLANG)/pdf/$(SERIES)/$(SUBSERIES)" ] || find $(AONROOTREL)/$(BLANG)/pdf/$(SERIES)/$(SUBSERIES)/ -name "*.pdf" | \
133 while read file ; do \
134 [ -e "`basename $$file`" ] || ln -s $$file . ; \
136 $(AT)[ ! -d "$(AONROOTREL)/en/pdf/$(ORIGSERIES)/$(SUBSERIES)" ] || find $(AONROOTREL)/en/pdf/$(ORIGSERIES)/$(SUBSERIES)/ -name "*.pdf" | \
137 while read file ; do \
138 [ -e "`basename $$file`" ] || ln -s $$file . ; \
143 # Convert them using the appropiate script
144 convert-images: link-images
145 $(AT)echo "Converting images to PDF format"
146 $(AT)sh ../../convert-images.sh
150 install: $(INSTALLDIR) all
151 $(AT)echo "Copying $(BASENAME).pdf to $(INSTALLDIR)"
152 $(AT)cp $(BASENAME).pdf $(INSTALLDIR)
159 %.dvi: %.tex $(EXTRAFILES)
161 latex -interaction batch $<
162 # Regenerate Contents
172 %.pdf: %.tex $(EXTRAFILES) convert-images
173 # Convert to UTF-8 if required
174 $(AT)if file $< | grep -q ISO-8859 ; then \
175 echo "WARNING: $< is encoded in ISO-8859-1, converting to UTF-8" ; \
177 iconv -f latin1 -t utf-8 < $<.lat1 >$<; \
179 -xelatex -interaction batchmode $<
180 # # Remove everything except for chapter entries from the toc file
181 $(AT)[ -e "$(BASENAME).toc" ] || { echo "ERROR: Generated file does not include table of contents file, please review $(BASENAME).log" ; false ; }
182 -$(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
183 # # Run xelatex a second time to get correct page numbers in the toc
184 -xelatex -interaction batchmode $<
185 # # Remove everything except for chapter entries from the toc file
186 -$(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
187 # # Tweak the PDF bookmarks file
188 $(AT)[ -e "$(BASENAME).out" ] || { echo "ERROR: Required file $(BASENAME).out does not exist, please review $(BASENAME).log" ; false ; }
189 $(AT)sed 's/\\ellipsis@one =,//' $(BASENAME).out >temp.out && \
190 echo '\let\WriteBookmarks\relax' >>temp.out && \
191 mv -f temp.out $(BASENAME).out
192 # # Run xelatex a third time to get correct PDF bookmarks
193 -xelatex -interaction batchmode $<
194 # Restore the original ISO-8859-1 file if we used iconf
195 $(AT)[ ! -e "$<.lat1" ] || mv $<.lat1 $<
197 pdflatex: $(BASENAME).tex $(EXTRAFILES) convert-images
198 # # Remove old PDF bookmarks file (.out file)
199 -rm -f $(BASENAME).out
200 # # Use pdflatex for generation:
201 -pdflatex -interaction batchmode $<
202 # # Remove everything except for chapter entries from the toc file
203 $(AT)[ -e "$(BASENAME).toc" ] || { echo "ERROR: Generated file does not include table of contents file, please review $(BASENAME).log" ; false ; }
204 $(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
205 # # Run pdflatex a second time to get correct page numbers in the toc
206 -pdflatex -interaction batchmode $<
207 # # Remove everything except for chapter entries from the toc file
208 $(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
209 # # Tweak the PDF bookmarks file
210 $(AT)[ -e "$(BASENAME).out" ] || { echo "ERROR: Required file $(BASENAME).out does not exist, please review $(BASENAME).log" ; false ; }
211 $(AT)sed 's/\\ellipsis@one =,//' $(BASENAME).out >temp.out && \
212 echo '\let\WriteBookmarks\relax' >>temp.out && \
213 mv -f temp.out $(BASENAME).out
214 # # Run pdflatex a third time to get correct PDF bookmarks
215 -pdflatex -interaction batchmode $<
218 -rm -f $(BASENAME).pdf $(BASENAME).ps
219 -rm -f *.aux *.toc *.log *.lof *.dvi *.ps *.bbl *.blg *.lot *.out
222 -rm -f $(BASENAME).tex $(BASENAME)-untweaked.tex $(BASENAME).tex.orig $(BASENAME).tex.lat1 $(BASENAME).tex.rej
224 -rm -f ac1.tex ac2.tex ac3.tex crtneg.tex crtpos.tex random.tex souvenir.sty souverbt.sty
225 $(AT)for gif in *.gif ; do [ -e $$gif ] && [ -L $$gif ] && rm -f $$gif ; done || true
226 # Remove tweak file if empty
227 $(AT)test -s tweak.diff || rm -f tweak.diff
231 -rm -f *.png *.jpeg *.jpg *.pdf
232 -rm -f convert-images link-images
234 # Update tweak.diff with the current difference between untweaked and tweaked tex file
236 $(AT)if [ -e $(BASENAME)-untweaked.tex -a -e $(BASENAME).tex ] ; then \
237 if ! diff -q $(BASENAME)-untweaked.tex $(BASENAME).tex; then \
238 diff -u $(BASENAME)-untweaked.tex $(BASENAME).tex >tweak.diff || echo Updated tweak.diff; \
240 echo "Tweak file not updated, no changes"; \
243 echo "Tweak file not updated, missing files"; \