COMPILER := pdflatex TEXINPUTS := ./styles/:$(TEXINPUTS) COMPILER := TEXINPUTS=$(TEXINPUTS) $(COMPILER) ifndef VERBOSE PIPE := 1>/dev/null 2>/dev/null INDENT := 2>&1 | sed 's/^/ /' COMPILER := $(COMPILER) -interaction=nonstopmode endif check_error = \ if [ ! $(1) -eq 0 ]; then \ cat '../out/$(2).log' | \ perl -0777 -ne 'print m/\n! .*?\nl\.\d.*?\n.*?(?=\n)/gs' $(INDENT); \ exit 1; \ fi createout = mkdir -p out && mkdir -p out/chapters compile = cd src && ${COMPILER} -shell-escape -file-line-error -synctex=1 \ -output-format=pdf -output-directory=../out .formats/${1}.tex ${PIPE} || \ $(call check_error, $$?,$(1)) .PHONY: clean book .PRECIOUS: %.pdf .SECONDEXPANSION: %.pdf: src/.formats/%.tex @echo "Building $*.pdf" @$(call createout) @echo " Compiling $*.tex" @$(call compile,$*) %.odt: src/%.tex @echo "Building $*.odt" @echo " Compiling $*.tex" @cd src && pandoc -f latex -t odt -o ../out/book.odt book.tex %.epub: src/%.tex @echo "Building $*.epub" @echo " Compiling $*.tex" @cd src && pandoc -f latex -o ../out/book.epub book.tex %.clean: @echo "cleaning" @rm -rfd out/*.4ct out/*.4tc out/*.dvi out/*.idv out/*.tex out/*.tmp out/*.xref out/*.svg out/*.lg out/*.4og out/*.aux out/*.bbl out/*.blg out/*.log out/*.out out/*.synctex.gz out/**/*.png \ out/*.nav out/*.run.xml out/*.snm out/*.toc out/*.vrb out/*-blx.bib out/**/ clean: @rm -rf out book: oneside.pdf twosides.pdf ebook.pdf $$@.odt $$@.epub $$@.clean