.PHONY: all book epub assets frames tex clean distclean private shareable

all: book epub

assets:            ## download openly-licensed imagery from Wikimedia Commons
	python3 tools/fetch_open.py

private:           ## OPT-IN: personal-use only, writes to gitignored assets/private/
	python3 tools/fetch_private.py

frames:            ## explode GIFs into the frame sequences animategraphics needs
	python3 tools/extract_frames.py

tex:               ## regenerate the data-driven chapters
	python3 tools/gen_tex.py

book: tex          ## build build/workbook.pdf
	@mkdir -p build
	cd book && tectonic -X compile main.tex --outdir ../build --keep-logs
	@mv -f build/main.pdf build/workbook.pdf 2>/dev/null || true
	@echo "-> build/workbook.pdf"

epub: tex          ## build build/workbook.epub, in which the GIFs animate
	python3 tools/gen_epub.py

shareable:         ## drop every all-rights-reserved asset, then rebuild both editions
	rm -rf assets/private assets/frames/private
	$(MAKE) book epub
	@echo "-> builds contain openly-licensed imagery only; safe to distribute"

clean:
	rm -rf build

distclean: clean
	rm -rf assets/frames assets/muscles assets/skills data/commons-*.json data/credits.json
