# Runs every .py in this folder. The C++ examples' Makefile compiles them;
# these need no build, so this just runs them and cleans up what they wrote.
#
# Usage:
#   make            # run all examples
#   make example1   # run a single example
#   make figures    # run all, then refresh the README gallery's images
#   make notebooks  # re-run the notebooks under notebooks/, in place
#   make clean      # remove the generated svg/pdf/ipe files (not figures/)

PYTHON ?= python3

SOURCES := $(wildcard example*.py)
TARGETS := $(SOURCES:.py=)

.PHONY: all figures notebooks clean $(TARGETS)

all: $(TARGETS)

$(TARGETS): %: %.py
	$(PYTHON) $<

# The gallery in README.md shows these outputs, so they are kept (and tracked)
# under figures/ rather than regenerated by whoever reads the page.
figures: all
	cp *.svg *.pdf *.ipe figures/

# The notebooks are committed with their outputs, so GitHub renders their figures
# and a reader gets the whole page without running anything. Re-running them is
# how that stays true across a binding change or a pgl re-pin; a cell that raises
# stops the run. Needs `pip install nbclient nbformat` (the notebooks themselves
# need only pypgl).
notebooks:
	$(PYTHON) notebooks/execute.py

clean:
	$(RM) *.svg *.pdf *.ipe
