misc fixes to LM
[light-and-matter.git] / lm.make
blobda9585102032c7d9dc1783e8ddd7fb893d5d232d
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 @rm -f macros_not_handled
119 WOPT='$(WOPT) --html5' $(RUN_ERUBY) w $(FIRST_CHAPTER) $(DIRECTORIES) #... html 5 with mathml
120 WOPT='$(WOPT) --mathjax' $(RUN_ERUBY) w $(FIRST_CHAPTER) $(DIRECTORIES) #... html 4 with mathjax
121 # To set options, do, e.g., "WOPT='--no_write' make web". Options are documented in translate_to_html.rb.
123 wiki:
124 WOPT='$(WOPT) --wiki' $(RUN_ERUBY) w
126 prepress:
127 PREPRESS=1 make book
128 # Filtering through gs used to be necessary to convince Lulu not to complain about missing fonts.
129 # Now that should no longer be necessary, because recent versions of pdftex embed all fonts, and fullembed.map prevents subsetting.
130 # See meki:computer:apps:ghostscript, scripts/create_fullembed_file, and http://tex.stackexchange.com/questions/24002/turning-off-font-subsetting-in-pdftex
131 ../scripts/preflight_pdf.pl $(BOOK).pdf
132 cd .. ; make preflight_figs ; cd -
133 perl -e 'if ("$(BOOK)" eq 'cp' || "$(BOOK)" eq 'me') {system("make prepress_single_vol")} else {system("make prepress_splits")}'
135 prepress_single_vol:
136 # Don't use this directly; just do a 'make prepress'.
137 pdftk $(BOOK).pdf cat 3-end output lulu_$(BOOK).pdf
138 @rm -f temp.pdf
140 prepress_splits:
141 # Don't use this directly; just do a 'make prepress'.
142 $(NICE) ../scripts/splits.pl $(BOOK).pdf 1 lulu_$(BOOK)_v1.pdf
143 $(NICE) ../scripts/splits.pl $(BOOK).pdf 2 lulu_$(BOOK)_v2.pdf
144 @rm -f temp.pdf
146 test:
147 perl -e 'if (system("pdflatex -interaction=$(MODE) $(BOOK) >$(TERMINAL_OUTPUT)")) {print "error\n"} else {print "no error\n"}'
149 very_clean: clean
150 rm -f $(BOOK).pdf lulu*.pdf *.epub *.mobi *.postm4 *.temp ch*.csv ch*temp.tex brief-toc.tex brief-toc-new.tex
151 rm -Rf $(HANDHELD_TEMP)
152 rm -f learned_commands.json custom_html.yaml declaregraphicsextensions.tex
154 clean:
155 # Cleaning...
156 @$(RM_TEMP)
157 @$(RM_CLS)
158 @rm -f temp.tex
159 @rm -f bk*lulu.pdf simple1.pdf simple2.pdf # lulu files
160 @rm -f */*.pos geom.pos report.pos marg.pos makefilepreamble
161 @rm -f figfeedback*
162 @rm -f */*temp_new */*.postm4 */*.wiki */*temp.tex
163 @rm -f code_listing_* code_listings/* code_listings.zip
164 @rm -Rf code_listings
165 @rm -f temp.* temp_mathml.*
166 @# Sometimes we get into a state where LaTeX is unhappy, and erasing these cures it:
167 @rm -f *aux *idx *ilg *ind *log *toc
168 @rm -f */*aux
169 @# Shouldn't exist in subdirectories:
170 @rm -f */*.log
171 @# Emacs backup files:
172 @rm -f *~
173 @rm -f */*~
174 @rm -f */*/*~
175 @rm -f */*.temp
176 @# Misc:
177 @rm -Rf */figs/.xvpics
178 @rm -f a.a
179 @rm -f */a.a
180 @rm -f */*/a.a
181 @rm -f junk
182 @rm -f err
183 @# ... done.
186 post:
187 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
188 # pdftk $(BOOK).pdf background ../watermark/watermark.pdf output temp.pdf
189 # mv temp.pdf $(BOOK).pdf
190 $(SPLIT_BOOK) $(BOOK).pdf
191 # move, e.g., bk1.pdf, bk1a.pdf, ..., but don't move simple1.pdf or simple2.pdf if they exist:
192 perl -e 'foreach $$f(<$(BOOK)?.pdf>) {if ($$f=~/$(BOOK)[a-z].pdf/) {$$c="mv -v $$f $(HOME)/Lightandmatter"; system $$c}}'
193 mv save.pdf $(BOOK).pdf
194 cp $(BOOK).pdf $(HOME)/Lightandmatter
195 perl -e 'if (-e "code_listings.zip") {system("cp code_listings.zip $(HOME)/Lightandmatter/$(BOOK)_code_listings.zip")}'
197 preflight:
198 @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}'
199 @../scripts/check_ruby_version.rb
200 @perl -e 'if (-e "../scripts/custom/enable") {system("chmod +x ../scripts/custom/*"); foreach $$f(<../scripts/custom/*.pl>) {$$c="$$f $(BOOK) $(PROBLEMS_CSV)"; system($$c)}}'
201 @[ `which footex` ] || echo "******** warning: footex is not installed, so html cannot be generated; get footex from http://www.lightandmatter.com/footex/footex.html"
203 handheld:
204 # see meki/zzz_misc/publishing for notes on how far I've progressed with this
205 make preflight
206 @cp ../custom_html.yaml .
207 ../scripts/translate_to_html.rb --write_config_and_exit --modern --override_config_with="../config/handheld.config"
208 rm -f $(HANDHELD_TEMP)/ch*/*html $(HANDHELD_TEMP)/index.*html
209 mkdir -p $(HANDHELD_TEMP)
210 WOPT='$(WOPT) --modern --override_config_with="../config/handheld.config"' $(RUN_ERUBY) w $(FIRST_CHAPTER) $(DIRECTORIES) #... xhtml
211 cp ../standalone.css $(HANDHELD_TEMP)
212 make epub
213 make mobi
214 @echo "To post the books, do 'make post_handheld'."
216 post_handheld:
217 cp $(BOOK).epub $(HOME)/Lightandmatter
218 cp $(BOOK).mobi $(HOME)/Lightandmatter
220 epub:
221 # Before doing this, do a "make handheld".
222 ebook-convert $(HANDHELD_TEMP)/index.html $(BOOK).epub $(GENERIC_OPTIONS_FOR_CALIBRE) --no-default-epub-cover
224 mobi:
225 # Before doing this, do a "make handheld".
226 ebook-convert $(HANDHELD_TEMP)/index.html $(BOOK).mobi $(GENERIC_OPTIONS_FOR_CALIBRE) --rescale-images
228 epubcheck:
229 java -jar /usr/bin/epubcheck/epubcheck.jar $(BOOK).epub 2>err