# Build the technical introduction. Needs a LaTeX toolchain; the Docker route needs none installed.
#
#   make            # build rarelens.pdf
#   make figures    # re-capture screenshots and re-render the diagrams (needs the app running)
#   make clean

TEX ?= docker run --rm --platform linux/amd64 -v "$(PWD):/w" -w /w ghcr.io/xu-cheng/texlive-full pdflatex
BASE ?= http://localhost:5173
CHROME ?= /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

rarelens.pdf: rarelens.tex $(wildcard figures/*.png)
	$(TEX) -interaction=nonstopmode rarelens.tex >/dev/null
	$(TEX) -interaction=nonstopmode rarelens.tex | grep -E 'Output written|^!' || true

# Screenshots come from the running app, diagrams from the HTML in diagram-sources/, both through
# one headless browser so the figures and the interface cannot drift apart.
figures:
	cd diagram-sources && npm install --silent playwright && \
	  BASE="$(BASE)" CHROME_PATH="$(CHROME)" \
	  DIAGRAMS=arch,events,pipeline,evidence,benchmark,model node shoot.mjs
	cp diagram-sources/out/*.png figures/

clean:
	rm -f rarelens.aux rarelens.log rarelens.out rarelens.toc preview-*.png

.PHONY: figures clean
