
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

VERSION_STRING := $(shell git describe --always --tags --long)
# chapter subdir cwd, thesis repo root, system tex distribution
TEXINPUTS := .:..:
export TEXINPUTS

all: clean chapter.pdf

# We need three runs for biblatex's defernumbers
%.pdf: ../chapter-template.tex %.tex ../common-packages.tex ../common-defs.tex ../main.bib version.tex
	pdflatex -shell-escape -jobname chapter $<
	biber --input-directory=.. $*
	pdflatex -shell-escape -jobname chapter $<
	biber --input-directory=.. $*
	pdflatex -shell-escape -jobname chapter $<

.PHONY: preview
preview:
	biber --input-directory=.. chapter || true
	pdflatex -shell-escape -jobname chapter ../chapter-template.tex

version.tex: chapter.tex
	echo "${VERSION_STRING}" > $@

.PHONY: update-figures
update-figures:
	@python ../update_figures.py figures

.PHONY: clean
clean:
	rm -f **.aux **.bbl **.bcf **.log **.blg
	rm -f **.mtc **.mtc*
	rm -f **.out **.run.xml **/texput.log 

