# =============================================================================
# Makefile for Stanford CS149 Lecture 4 demos
# =============================================================================
#
# [What this builds]
#   Three C++ programs (the two-step image, the grid solver, x++ from many
#   threads) and runs two Python demos (Amdahl's law, dependency analysis).
#
# [How to use]
#   make            # build the C++ demos
#   make run        # build, then run all demos in lecture order (~12 s in total)
#   make clean      # remove built files
#
# [Why these flags] -std=c++20 for std::barrier; otherwise as in Lecture 1.
# -----------------------------------------------------------------------------

CXX      ?= c++
CXXFLAGS := -std=c++20 -O2 -g -Wall -Wextra -pthread
PYTHON   ?= python3

HEADERS := ../lecture01/cs149_timer.h ../lecture01/machine_info.h

BINS := 02_two_step_image 03_grid_solver 05_mutual_exclusion

.PHONY: all run clean
all: $(BINS)

$(BINS): %: %.cpp $(HEADERS)
	$(CXX) $(CXXFLAGS) -o $@ $<

run: all
	@echo; $(PYTHON) 01_amdahl.py
	@echo; ./02_two_step_image
	@echo; ./03_grid_solver
	@echo; $(PYTHON) 04_dependencies.py
	@echo; ./05_mutual_exclusion

clean:
	rm -f $(BINS)
	rm -rf *.dSYM __pycache__
