add LM 5 hw, caryatid
[light-and-matter.git] / lm.make
blob9a412c07d3b0bbad4be905103c88827cd2292e17
1 # This file is meant to be included from the
2 # makefiles in the individual books' directories.
4 NICE = nice ionice -n7
5 GS = $(NICE) gs
6 DIST_DIR = $(BOOK)
7 DIST_ARCHIVE = $(BOOK).tar.gz
8 MODE = nonstopmode
9 TERMINAL_OUTPUT = err
10 MYSELF = Makefile
11 CLS_FILES = "lmseries.cls","lmcommon.sty","lmfigs.sty","lmlayout.sty","lmmath.sty","lm.make","mytocloft.sty","lmlanguage.sty","lmenvironments.sty","fullembed.map","learn-cmd-syntax.sty","custom_html.yaml","shaddap.sty"
12 # ... a list of files that's assumed to exist in the parent dir, which we
13 # copy into the working dir when building the book; "CLS_" is really a misnomer
14 GET_CLS = perl -e 'foreach $$f($(CLS_FILES)) {$$cmd="cp $(FILE_PREFIX)../$$f ."; system $$cmd}'
15 RM_CLS = perl -e 'foreach $$f($(CLS_FILES)) {system "rm -f $$f"}'
16 RM_TEMP = rm -f *.pos */*temp.* */*.bak eruby_complaints
17 RUN_ERUBY = $(NICE) perl -I../scripts ../scripts/run_eruby.pl
18 HARVEST_AUX_FILES = ../scripts/harvest_aux_files.rb
19 SPLIT_BOOK = ../scripts/split_book.pl
20 HANDHELD_TEMP = handheld_temp
21 GENERIC_OPTIONS_FOR_CALIBRE = --authors "Benjamin Crowell" --language en --toc-filter="[0-9]\.[0-9]"
22 PROBLEMS_CSV = ../data/problems.csv
24 MAKEINDEX = makeindex $(BOOK).idx >/dev/null
26 TEX_INTERPRETER = pdflatex
27 #TEX_INTERPRETER = lualatex
28 # ... lualatex sometimes segfaults on Mechanics, but not always reproducible
29 DO_PDFLATEX_RAW = $(NICE) $(TEX_INTERPRETER) -shell-escape -interaction=$(MODE) $(BOOK) >$(TERMINAL_OUTPUT)
30 # -shell-escape is so that write18 will be allowed
31 # environment variable openout_any=a is so that we can write to ../share/end
32 SHOW_ERRORS = \
33 system("../scripts/filter_latex_messages.rb <$(TERMINAL_OUTPUT) >a.a && mv a.a $(TERMINAL_OUTPUT)")
34 print "========error========\n"; \
35 open(F,"$(TERMINAL_OUTPUT)"); \
36 while ($$line = <F>) { \
37 if ($$line=~m/^\! / || $$line=~m/^l.\d+ /) { \
38 print $$line \
39 } \
40 } \
41 close F; \
42 exit(1)
43 DO_PDFLATEX = echo "$(DO_PDFLATEX_RAW)" ; perl -e 'if (system("$(DO_PDFLATEX_RAW)")) {$(SHOW_ERRORS)};'
44 DO_MAKEFILEPREAMBLE = perl -e 'open(F,">makefilepreamble.tex"); if ("$(POPT)"=~/only(\d+)/) {print F "\\includeonly{ch$$1/ch$$1temp}"} close F'
46 # Since book1 comes first, it's the default target --- you can just do ``make'' to make it.
48 export GIT_DIR = "~/Git_LM/$(BOOK_LABEL)"
49 # export makes it set the actual environment variable (not just the makefile macro) for all processes run by the makefile
51 book1:
52 @make preflight
53 @../scripts/before_each.rb
54 @../scripts/translate_to_html.rb --write_config_and_exit
55 #@rm -f marg.pos ### might want to do this the very first time, or just make a habit of doing a make clean
56 $(RUN_ERUBY) - $(FIRST_CHAPTER) $(DIRECTORIES)
57 @../scripts/harvest_code_listings.pl
58 @$(GET_CLS)
59 @$(DO_MAKEFILEPREAMBLE)
60 @$(DO_PDFLATEX)
61 @../scripts/translate_to_html.rb --util="learn_commands:$(BOOK).cmd"
62 @$(HARVEST_AUX_FILES)
63 @rm -f $(TERMINAL_OUTPUT) # If pdflatex has a nonzero exit code, we don't get here, so the output file is available for inspection.
64 @../process_geom_file.pl <geom.pos >temp.pos
65 @mv temp.pos geom.pos
66 @$(RM_CLS)
67 @perl -e 'if (-e "eruby_complaints") {system "cat eruby_complaints"}'
69 index:
70 $(MAKEINDEX)
72 book:
73 @make preflight
74 @../scripts/before_each.rb
75 @make clean
76 @../scripts/translate_to_html.rb --write_config_and_exit
77 @rm -f geom.pos
78 @rm -f marg.pos
79 @$(RUN_ERUBY) - $(FIRST_CHAPTER) $(DIRECTORIES)
80 @../scripts/harvest_code_listings.pl
81 @$(GET_CLS)
82 @$(DO_MAKEFILEPREAMBLE)
83 @$(DO_PDFLATEX)
84 @../scripts/translate_to_html.rb --util="learn_commands:$(BOOK).cmd"
85 @$(HARVEST_AUX_FILES)
86 @../process_geom_file.pl <geom.pos >temp.pos
87 @mv temp.pos geom.pos
88 @$(RUN_ERUBY) - $(FIRST_CHAPTER) $(DIRECTORIES)
89 @$(DO_MAKEFILEPREAMBLE)
90 @../scripts/before_each.rb
91 @$(DO_PDFLATEX)
92 @$(HARVEST_AUX_FILES)
93 @../process_geom_file.pl <geom.pos >temp.pos
94 @mv temp.pos geom.pos
95 @$(RUN_ERUBY) - $(FIRST_CHAPTER) $(DIRECTORIES)
96 $(MAKEINDEX)
97 @$(DO_MAKEFILEPREAMBLE)
98 @../scripts/before_each.rb
99 @$(DO_PDFLATEX)
100 @$(HARVEST_AUX_FILES)
101 @perl -e 'open(F,"<$(TERMINAL_OUTPUT)"); while ($$l=<F>) {if ($$l=~/LaTeX Warning: Reference/) {print "****** $$l"}}; close F'
102 @../process_geom_file.pl <geom.pos >temp.pos
103 @mv temp.pos geom.pos
104 @../check_for_colliding_figures.rb
105 @../scripts/before_each.rb
106 @$(DO_PDFLATEX) # a fourth time, because otherwise some references don't work, e.g., ref. in EM 1-2 to back of book
107 @$(HARVEST_AUX_FILES)
108 @rm -f $(TERMINAL_OUTPUT) # If pdflatex has a nonzero exit code, we don't get here, so the output file is available for inspection.
109 @$(RM_CLS)
110 @perl -e 'if (-e "eruby_complaints") {system "cat eruby_complaints"}'
112 web:
113 @[ `which footex` ] || echo "******** footex is not installed, so html cannot be generated; get footex from http://www.lightandmatter.com/footex/footex.html"
114 @[ `which footex` ] || exit 1
115 @make preflight
116 @cp ../custom_html.yaml .
117 @../scripts/translate_to_html.rb --write_config_and_exit
118 WOPT='$(WOPT) --html5' $(RUN_ERUBY) w $(FIRST_CHAPTER) $(DIRECTORIES) #... html 5 with mathml
119 WOPT='$(WOPT) --mathjax' $(RUN_ERUBY) w $(FIRST_CHAPTER) $(DIRECTORIES) #... html 4 with mathjax
120 # To set options, do, e.g., "WOPT='--no_write' make web". Options are documented in translate_to_html.rb.
122 wiki:
123 WOPT='$(WOPT) --wiki' $(RUN_ERUBY) w
125 prepress:
126 PREPRESS=1 make book
127 # Filtering through gs used to be necessary to convince Lulu not to complain about missing fonts.
128 # Now that should no longer be necessary, because recent versions of pdftex embed all fonts, and fullembed.map prevents subsetting.
129 # See meki:computer:apps:ghostscript, scripts/create_fullembed_file, and http://tex.stackexchange.com/questions/24002/turning-off-font-subsetting-in-pdftex
130 ../scripts/preflight_pdf.pl $(BOOK).pdf
131 cd .. ; make preflight_figs ; cd -
132 perl -e 'if ("$(BOOK)" eq 'cp' || "$(BOOK)" eq 'me') {system("make prepress_single_vol")} else {system("make prepress_splits")}'
134 prepress_single_vol:
135 # Don't use this directly; just do a 'make prepress'.
136 pdftk $(BOOK).pdf cat 3-end output lulu_$(BOOK).pdf
137 @rm -f temp.pdf
139 prepress_splits:
140 # Don't use this directly; just do a 'make prepress'.
141 $(NICE) ../scripts/splits.pl $(BOOK).pdf 1 lulu_$(BOOK)_v1.pdf
142 $(NICE) ../scripts/splits.pl $(BOOK).pdf 2 lulu_$(BOOK)_v2.pdf
143 @rm -f temp.pdf
145 test:
146 perl -e 'if (system("pdflatex -interaction=$(MODE) $(BOOK) >$(TERMINAL_OUTPUT)")) {print "error\n"} else {print "no error\n"}'
148 very_clean: clean
149 rm -f $(BOOK).pdf lulu*.pdf *.epub *.mobi *.postm4 *.temp ch*.csv ch*temp.tex brief-toc.tex brief-toc-new.tex
150 rm -Rf $(HANDHELD_TEMP)
151 rm -f learned_commands.json custom_html.yaml declaregraphicsextensions.tex
153 clean:
154 # Cleaning...
155 @$(RM_TEMP)
156 @$(RM_CLS)
157 @rm -f temp.tex
158 @rm -f bk*lulu.pdf simple1.pdf simple2.pdf # lulu files
159 @rm -f */*.pos geom.pos report.pos marg.pos makefilepreamble
160 @rm -f figfeedback*
161 @rm -f */*temp_new */*.postm4 */*.wiki */*temp.tex
162 @rm -f code_listing_* code_listings/* code_listings.zip
163 @rm -Rf code_listings
164 @rm -f temp.* temp_mathml.*
165 @# Sometimes we get into a state where LaTeX is unhappy, and erasing these cures it:
166 @rm -f *aux *idx *ilg *ind *log *toc
167 @rm -f */*aux
168 @# Shouldn't exist in subdirectories:
169 @rm -f */*.log
170 @# Emacs backup files:
171 @rm -f *~
172 @rm -f */*~
173 @rm -f */*/*~
174 @rm -f */*.temp
175 @# Misc:
176 @rm -Rf */figs/.xvpics
177 @rm -f a.a
178 @rm -f */a.a
179 @rm -f */*/a.a
180 @rm -f junk
181 @rm -f err
182 @# ... done.
185 post:
186 cp $(BOOK).pdf save.pdf # save unwatermarked version, so, e.g., if we do a make prepress, we won't inadvertently use the watermarked version
187 # pdftk $(BOOK).pdf background ../watermark/watermark.pdf output temp.pdf
188 # mv temp.pdf $(BOOK).pdf
189 $(SPLIT_BOOK) $(BOOK).pdf
190 # move, e.g., bk1.pdf, bk1a.pdf, ..., but don't move simple1.pdf or simple2.pdf if they exist:
191 perl -e 'foreach $$f(<$(BOOK)?.pdf>) {if ($$f=~/$(BOOK)[a-z].pdf/) {$$c="mv -v $$f $(HOME)/Lightandmatter"; system $$c}}'
192 mv save.pdf $(BOOK).pdf
193 cp $(BOOK).pdf $(HOME)/Lightandmatter
194 perl -e 'if (-e "code_listings.zip") {system("cp code_listings.zip $(HOME)/Lightandmatter/$(BOOK)_code_listings.zip")}'
196 preflight:
197 @perl -e 'foreach $$g("scripts/check_ruby_version.rb","scripts/run_eruby.pl","fruby","mv_silent","scripts/translate_to_html.rb","process_geom_file.pl","scripts/harvest_aux_files.rb","scripts/latex_table_to_html.pl","scripts/equation_to_image.pl","check_for_colliding_figures.rb","scripts/harvest_code_listings.pl") {$$f="../$$g"; die "file $$g is not executable; fix this with chmod +x $$g" unless -e $$f && -x $$f}'
198 @../scripts/check_ruby_version.rb
199 @perl -e 'if (-e "../scripts/custom/enable") {system("chmod +x ../scripts/custom/*"); foreach $$f(<../scripts/custom/*.pl>) {$$c="$$f $(BOOK) $(PROBLEMS_CSV)"; system($$c)}}'
200 @[ `which footex` ] || echo "******** warning: footex is not installed, so html cannot be generated; get footex from http://www.lightandmatter.com/footex/footex.html"
202 handheld:
203 # see meki/zzz_misc/publishing for notes on how far I've progressed with this
204 make preflight
205 @cp ../custom_html.yaml .
206 ../scripts/translate_to_html.rb --write_config_and_exit --modern --override_config_with="../config/handheld.config"
207 rm -f $(HANDHELD_TEMP)/ch*/*html $(HANDHELD_TEMP)/index.*html
208 mkdir -p $(HANDHELD_TEMP)
209 WOPT='$(WOPT) --modern --override_config_with="../config/handheld.config"' $(RUN_ERUBY) w $(FIRST_CHAPTER) $(DIRECTORIES) #... xhtml
210 cp ../standalone.css $(HANDHELD_TEMP)
211 make epub
212 make mobi
213 @echo "To post the books, do 'make post_handheld'."
215 post_handheld:
216 cp $(BOOK).epub $(HOME)/Lightandmatter
217 cp $(BOOK).mobi $(HOME)/Lightandmatter
219 epub:
220 # Before doing this, do a "make handheld".
221 ebook-convert $(HANDHELD_TEMP)/index.html $(BOOK).epub $(GENERIC_OPTIONS_FOR_CALIBRE) --no-default-epub-cover
223 mobi:
224 # Before doing this, do a "make handheld".
225 ebook-convert $(HANDHELD_TEMP)/index.html $(BOOK).mobi $(GENERIC_OPTIONS_FOR_CALIBRE) --rescale-images
227 epubcheck:
228 java -jar /usr/bin/epubcheck/epubcheck.jar $(BOOK).epub 2>err