CXX ?= g++
CXXFLAGS ?= -std=c++17 -Wall -Wextra -Wpedantic -O2
CORE := $(basename $(notdir $(wildcard examples/0[1-9]_*.cpp)))
OPT := 10_optional_2d_five_point_stencil
CORE_BINS := $(addprefix bin/,$(CORE))
.PHONY: help all standard optional check-standard check-optional check-all plot check-plot clean
all: standard
help:
	@printf 'make standard          build E01--E09\nmake optional          build optional E10\nmake check-standard    independent numerical tests\nmake check-optional    test E10\nmake check-all         test all\nmake plot              E09 toy CSV and Matplotlib plot (no overwrite)\nmake check-plot        check plot and overwrite handling\nmake clean             remove generated binaries only\n'
standard: $(CORE_BINS)
optional: bin/$(OPT)
bin/%: examples/%.cpp
	@mkdir -p bin
	$(CXX) $(CXXFLAGS) "$<" -o "$@"
check-standard: standard
	python3 tests/check_examples.py
check-optional: optional
	python3 tests/check_examples.py --optional
check-all: standard optional
	python3 tests/check_examples.py --all
plot: bin/09_small_sor_history_csv
	@if test -e data/toy_sor_history.csv; then echo 'Using existing data/toy_sor_history.csv (not overwritten)'; else ./bin/09_small_sor_history_csv --output data/toy_sor_history.csv; fi
	@if test -e plots/toy_sor_history.png; then echo 'Using existing plots/toy_sor_history.png (not overwritten)'; else python3 plotting/plot_toy_sor_history.py --input data/toy_sor_history.csv --output plots/toy_sor_history.png; fi
check-plot: bin/09_small_sor_history_csv
	python3 tests/check_plot.py
clean:
	rm -f $(CORE_BINS) bin/$(OPT)
