mirror of
https://github.com/cs341-illinois/coursebook.git
synced 2026-10-02 08:04:38 +08:00
main.tex \input's order.tex, which is generated from order.yaml, but the per-chapter rule listed only the chapter's own .tex. From a clean tree 'make deadlock/deadlock.pdf' therefore died with "File `order.tex' not found". CI never noticed because _scripts/script.sh builds 'all' first, which builds order.tex on the way to main.pdf. Adding the prerequisite means $^ now expands to both files, which would put a stray 'order' inside \includeonly, so the recipe switches to $<.
71 lines
2.5 KiB
Makefile
71 lines
2.5 KiB
Makefile
# Find all tex files one directory down
|
|
TEX=$(shell find . -path "./.git*" -prune -o -type f -iname "*.tex" -print)
|
|
MAIN_TEX=main_wrapper.tex
|
|
MAIN_TEX_SOURCE=main.tex
|
|
PDF_TEX=$(patsubst %.tex,%.pdf,$(MAIN_TEX))
|
|
MAIN_OUT=main.pdf
|
|
MAIN_EPUB=main.epub
|
|
BASE=$(patsubst %.tex,%,$(MAIN_TEX))
|
|
OTHER_FILES=$(addprefix $(BASE),.aux .log .synctex.gz .toc .out .blg .bbl .glg .gls .ist .glo)
|
|
BIBS=$(shell find . -maxdepth 2 -mindepth 2 -path "./.git*" -prune -o -type f -iname "*.bib" -print)
|
|
OTHER=$$(find . -iname *aux) $$(find . -iname *bbl) $$(find . -iname *blg)
|
|
ORDER_TEX=order.tex
|
|
ORDER_TEX_DEP=order.yaml
|
|
|
|
TEX_ORDER=$(shell sh -c "cat order.yaml | sed 's/^- //'")
|
|
CHAPTER_PDF=$(patsubst %,%.pdf,$(TEX_ORDER))
|
|
|
|
.PHONY: all
|
|
all: pdf epub
|
|
-@latexmk -c
|
|
-@rm *aux *bbl *glg *glo *gls *ist *latexmk *fls
|
|
-@rm **/*aux **/*bbl **/*glg **/*glo **/*gls **/*ist **/*latexmk **/*fls
|
|
|
|
.PHONY: pdf
|
|
pdf: $(MAIN_OUT) chapters
|
|
|
|
.PHONY: chapters
|
|
chapters: $(CHAPTER_PDF)
|
|
|
|
.PHONY: debug
|
|
debug: $(PDF_TEX)-debug
|
|
|
|
.PHONY: epub
|
|
epub: $(MAIN_EPUB)
|
|
|
|
$(MAIN_EPUB): $(ORDER_TEX) $(MAIN_TEX_SOURCE)
|
|
pandoc --toc -s -f latex -t epub --filter pandoc-citeproc --filter _scripts/pandoc_epub_filter.py -M link-citations=true --epub-cover-image _images/cover.png -M author="B. Venkatesh, L. Angrave, et Al." -o $(MAIN_EPUB) $(MAIN_TEX_SOURCE);
|
|
|
|
$(ORDER_TEX): $(ORDER_TEX_DEP)
|
|
python3 _scripts/gen_order.py $^ > $@
|
|
|
|
# order.tex is generated, and main.tex \input's it, so a chapter build from
|
|
# a clean tree needs it too. Note $< rather than $^: the recipe wants only
|
|
# the chapter's own .tex here, not every prerequisite.
|
|
$(CHAPTER_PDF): %.pdf: %.tex $(ORDER_TEX)
|
|
echo '\\let\\cleardoublepage\\clearpage' > $@.tmp
|
|
echo "\includeonly{$(basename $<)}\input{$(MAIN_TEX)}" >> $@.tmp
|
|
@latexmk -interaction=nonstopmode -quiet -pdflatex=lualatex -pdf -jobname="$@" $@.tmp \
|
|
|| { echo "*** latexmk failed for $@"; grep -n -A3 '^! ' $@.log 2>/dev/null; rm -f $@.tmp; false; }
|
|
@mv $@.pdf $@
|
|
@ls $@ > /dev/null
|
|
-@rm $@.tmp
|
|
|
|
$(MAIN_OUT): $(TEX) $(MAIN_TEX) $(BIBS) Makefile $(ORDER_TEX)
|
|
@latexmk -quiet -pdflatex=lualatex -interaction=nonstopmode -pdf $(MAIN_TEX) \
|
|
|| { echo "*** latexmk failed"; grep -n -A3 '^! ' $(basename $(MAIN_TEX)).log 2>/dev/null; false; }
|
|
@ls $(PDF_TEX) > /dev/null
|
|
@mv $(PDF_TEX) $(MAIN_OUT)
|
|
@echo "Finished"
|
|
|
|
$(PDF_TEX)-debug: $(TEX) $(MAIN_TEX) $(BIBS) Makefile
|
|
-@latexmk -interaction=nonstopmode -f -pdf $(MAIN_TEX) > latexmk.out
|
|
@mv $(PDF_TEX)-debug $(MAIN_OUT)
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
-@rm $(PDF_TEX) $(OTHER_FILES) $(OTHER)
|
|
|
|
|
|
|