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
30 SOURCE=$(BASENAME).tex
32 EXTRAFILES=souvenir.sty
34 EXTRAFILES=ac1.tex crtneg.tex ac2.tex crtpos.tex random.tex ac3.tex \
35 souvenir.sty souverbt.sty
39 # Generate the LaTeX file from the XML file
40 $(SOURCE): $(XMLFILE) $(XML2LATEX) $(LATEXXSL) tweak.diff
41 AONPATH="$(AONROOTDIR)" perl $(XML2LATEX) $(BASENAME) $(BLANG) $@
42 $(AT)if ! test -s $(SOURCE) ; then \
43 echo "ERROR: Empty file $(SOURCE), check for errors above." >&2 ; \
47 $(AT)cp $(SOURCE) $(BASENAME)-untweaked.tex
48 $(AT)if test -f tweak.diff; then \
49 patch $(SOURCE) <tweak.diff ; \
52 # Extra TeX files needed for the PDFs
54 # This is for english content:
66 # This is for other translated content:
68 ln -s ../../shared/$(BLANG)/$@
70 ln -s ../../shared/$(BLANG)/$@
72 ln -s ../../shared/$(BLANG)/$@
74 ln -s ../../shared/$(BLANG)/$@
76 ln -s ../../shared/$(BLANG)/$@
78 # Shared across all languages
85 # Create empty tweak.diff if it does not exist
89 # Symlink the images needed for the PDF; unused images and HTML-specific images are ignored
91 $(AT)[ -n "$(SERIES)" ] || { echo "Error: SERIES variable not defined. Hint: Review the Makefile"; exit 1; }
92 $(AT)[ -n "$(SUBSERIES)" ] || { echo "Error: SUBSERIES variable not defined. Hint: Review the Makefile"; exit 1; }
93 $(AT)[ -n "$(BASENAME)" ] || { echo "Error: BASENAME variable not defined. Hint: Review the Makefile"; exit 1; }
94 $(AT)echo "Linking images for the book to working directory"
95 $(AT)[ -n "$(ILLUSTRATOR)" ] || { echo "Warning: ILLUSTRATOR variable not defined. Some illustrations might be missing. Hint: Review the Makefile"; }
96 $(AT)[ ! -n "$(ILLUSTRATOR)" ] || [ -d "$(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR)" ] || \
97 { echo "Warning: Folder $(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR) not found. Some illustrations might be missing."; }
98 $(AT)[ ! -n "$(ILLUSTRATOR)" ] || [ ! -d "$(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR)" ] || \
99 find $(AONROOTREL)/common/pdf/$(ORIGSERIES)/common/ill/$(ILLUSTRATOR)/ -name "*.pdf" | \
100 while read file ; do \
101 [ -e "`basename $$file`" ] || ln -s $$file . ; \
104 $(AT)for images in jpeg png ; do \
105 [ ! -d "$(AONROOTREL)/en/$$images/$(SERIES)/$(BASENAME)/" ] || find $(AONROOTREL)/en/$$images/$(SERIES)/$(BASENAME)/ \( -name "*.jpg" -o -name "*.png" \) | \
106 while read file ; do \
107 [ -e "`basename $$file`" ] || \
108 case "`basename $$file`" in \
109 back*|bckgrnd*|brdr*|forward*|left*|right*|title*|toc*) ;; \
110 ac*|crt*|random*) ;; \
111 *) ln -s $$file . ;; \
115 $(AT)[ ! -d "$(AONROOTREL)/en/pdf/$(SERIES)/$(SUBSERIES)" ] || find $(AONROOTREL)/en/pdf/$(SERIES)/$(SUBSERIES)/ -name "*.pdf" | \
116 while read file ; do \
117 [ -e "`basename $$file`" ] || ln -s $$file . ; \
120 $(AT)[ -n "$(ORIGSERIES)" ] || { echo "Error: ORIGSERIES variable not defined. Hint: Review the Makefile"; exit 1; }
121 $(AT)[ -n "$(ORIGBASENAME)" ] || { echo "Error: ORIGBASENAME variable not defined. Hint: Review the Makefile"; exit 1; }
122 $(AT)for images in jpeg png ; do \
123 [ ! -d "$(AONROOTREL)/$(BLANG)/$$images/$(SERIES)/$(BASENAME)/" ] || find $(AONROOTREL)/$(BLANG)/$$images/$(SERIES)/$(BASENAME)/ \( -name "*.jpg" -o -name "*.png" \) | \
124 while read file ; do \
125 [ -e "`basename $$file`" ] || ln -s $$file . ; \
127 [ ! -d "$(AONROOTREL)/en/$$images/$(ORIGSERIES)/$(ORIGBASENAME)/" ] || find $(AONROOTREL)/en/$$images/$(ORIGSERIES)/$(ORIGBASENAME)/ \( -name "*.jpg" -o -name "*.png" \) | \
128 while read file ; do \
129 rootname=`basename $$file | sed -e 's/\..*//'`; \
130 [ -e "$$rootname.jpg" ] || [ -e "$$rootname.png" ] || ln -s $$file . ; \
133 $(AT)[ ! -d "$(AONROOTREL)/$(BLANG)/pdf/$(SERIES)/$(SUBSERIES)" ] || find $(AONROOTREL)/$(BLANG)/pdf/$(SERIES)/$(SUBSERIES)/ -name "*.pdf" | \
134 while read file ; do \
135 [ -e "`basename $$file`" ] || ln -s $$file . ; \
137 $(AT)[ ! -d "$(AONROOTREL)/en/pdf/$(ORIGSERIES)/$(SUBSERIES)" ] || find $(AONROOTREL)/en/pdf/$(ORIGSERIES)/$(SUBSERIES)/ -name "*.pdf" | \
138 while read file ; do \
139 [ -e "`basename $$file`" ] || ln -s $$file . ; \
144 # Convert them using the appropiate script
145 convert-images: link-images
146 $(AT)echo "Converting images to PDF format"
147 $(AT)sh ../../convert-images.sh
151 install: $(INSTALLDIR) all
152 $(AT)echo "Copying $(BASENAME).pdf to $(INSTALLDIR)"
153 $(AT)cp $(BASENAME).pdf $(INSTALLDIR)
160 %.dvi: %.tex $(EXTRAFILES)
162 latex -interaction batch $<
163 # Regenerate Contents
173 %.pdf: %.tex $(EXTRAFILES) convert-images
174 # Convert to UTF-8 if required
175 $(AT)if file $< | grep -q ISO-8859 ; then \
176 echo "WARNING: $< is encoded in ISO-8859-1, converting to UTF-8" ; \
178 iconv -f latin1 -t utf-8 < $<.lat1 >$<; \
180 -xelatex -interaction batchmode $<
181 # # Remove everything except for chapter entries from the toc file
182 $(AT)[ -e "$(BASENAME).toc" ] || { echo "ERROR: Generated file does not include table of contents file, please review $(BASENAME).log" ; false ; }
183 -$(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
184 # # Run xelatex a second time to get correct page numbers in the toc
185 -xelatex -interaction batchmode $<
186 # # Remove everything except for chapter entries from the toc file
187 -$(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
188 # # Tweak the PDF bookmarks file
189 $(AT)[ -e "$(BASENAME).out" ] || { echo "ERROR: Required file $(BASENAME).out does not exist, please review $(BASENAME).log" ; false ; }
190 $(AT)sed 's/\\ellipsis@one =,//' $(BASENAME).out >temp.out && \
191 echo '\let\WriteBookmarks\relax' >>temp.out && \
192 mv -f temp.out $(BASENAME).out
193 # # Run xelatex a third time to get correct PDF bookmarks
194 -xelatex -interaction batchmode $<
195 # Restore the original ISO-8859-1 file if we used iconf
196 $(AT)[ ! -e "$<.lat1" ] || mv $<.lat1 $<
198 pdflatex: $(BASENAME).tex $(EXTRAFILES) convert-images
199 # # Remove old PDF bookmarks file (.out file)
200 -rm -f $(BASENAME).out
201 # # Use pdflatex for generation:
202 -pdflatex -interaction batchmode $<
203 # # Remove everything except for chapter entries from the toc file
204 $(AT)[ -e "$(BASENAME).toc" ] || { echo "ERROR: Generated file does not include table of contents file, please review $(BASENAME).log" ; false ; }
205 $(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
206 # # Run pdflatex a second time to get correct page numbers in the toc
207 -pdflatex -interaction batchmode $<
208 # # Remove everything except for chapter entries from the toc file
209 $(AT)grep '{chapter}' $(BASENAME).toc >temp.toc && mv -f temp.toc $(BASENAME).toc
210 # # Tweak the PDF bookmarks file
211 $(AT)[ -e "$(BASENAME).out" ] || { echo "ERROR: Required file $(BASENAME).out does not exist, please review $(BASENAME).log" ; false ; }
212 $(AT)sed 's/\\ellipsis@one =,//' $(BASENAME).out >temp.out && \
213 echo '\let\WriteBookmarks\relax' >>temp.out && \
214 mv -f temp.out $(BASENAME).out
215 # # Run pdflatex a third time to get correct PDF bookmarks
216 -pdflatex -interaction batchmode $<
219 -rm -f $(BASENAME).pdf $(BASENAME).ps
220 -rm -f *.aux *.toc *.log *.lof *.dvi *.ps *.bbl *.blg *.lot *.out
223 -rm -f $(BASENAME).tex $(BASENAME)-untweaked.tex $(BASENAME).tex.orig $(BASENAME).tex.lat1 $(BASENAME).tex.rej
225 -rm -f ac1.tex ac2.tex ac3.tex crtneg.tex crtpos.tex random.tex souvenir.sty souverbt.sty
226 $(AT)for gif in *.gif ; do [ -e $$gif ] && [ -L $$gif ] && rm -f $$gif ; done || true
227 # Remove tweak file if empty
228 $(AT)test -s tweak.diff || rm -f tweak.diff
232 -rm -f *.png *.jpeg *.jpg *.pdf
233 -rm -f convert-images link-images
235 # Update tweak.diff with the current difference between untweaked and tweaked tex file
237 $(AT)if [ -e $(BASENAME)-untweaked.tex -a -e $(BASENAME).tex ] ; then \
238 if ! diff -q $(BASENAME)-untweaked.tex $(BASENAME).tex; then \
239 diff -u $(BASENAME)-untweaked.tex $(BASENAME).tex >tweak.diff || echo Updated tweak.diff; \
241 echo "Tweak file not updated, no changes"; \
244 echo "Tweak file not updated, missing files"; \