# Optional convenience only; every example also has a direct g++ command.
CXX ?= g++
CXXFLAGS ?= -std=c++17 -Wall -Wextra -Wpedantic -O2
BLAS_LIBS ?= -lblas -lm
CORE_NAMES = 01_dot_product 02_vector_norm 03_matrix_storage 04_matrix_vector 05_matrix_products 06_toy_iterations_csv 08_timing_small_example
CORE_BINS = $(addprefix bin/,$(CORE_NAMES))
.PHONY: all core check blas check-blas optional clean help
all: core
core: $(CORE_BINS)
bin:
	mkdir -p bin
bin/%: examples/%.cpp | bin
	$(CXX) $(CXXFLAGS) $< -o $@
bin/07_cblas_small_product: examples/07_cblas_small_product.cpp | bin
	$(CXX) $(CXXFLAGS) $< -o $@ $(BLAS_LIBS)
check: core
	@set -e; for p in 01_dot_product 02_vector_norm 03_matrix_storage 04_matrix_vector 05_matrix_products 08_timing_small_example; do ./bin/$$p; done
	@set -e; tmp=$$(mktemp -d); trap 'rm -rf "$$tmp"' EXIT HUP INT TERM; ./bin/06_toy_iterations_csv "$$tmp/toy.csv"
blas: bin/07_cblas_small_product
	./bin/07_cblas_small_product
check-blas: blas
optional: bin/09_precision_example
	./bin/09_precision_example
clean:
	rm -f $(CORE_BINS) bin/07_cblas_small_product bin/09_precision_example
help:
	@printf '%s\n' 'make core: standard-library examples; no BLAS needed' 'make check: run their built-in numerical checks; toy data in a temporary folder' 'make blas / check-blas: compile, link and run the tiny CBLAS product' 'make optional: compile and run the precision example' 'make clean: remove only these example binaries; preserve data/plots/source' 'Override CXX, CXXFLAGS or BLAS_LIBS only for an actually available toolchain.'
