# =============================================================================
# Makefile for Stanford CS149 Lecture 5 demos
# =============================================================================
#
# [What this builds]
#   Two C++ programs (static vs dynamic assignment; fork-join programs on a
#   work-stealing runtime) and runs two Python demos (task order in a shared
#   queue; the fork-join scheduler simulator).
#
# [How to use]
#   make            # build the C++ demos
#   make run        # build, then run all demos in lecture order (~8 s in total)
#   make selftest   # self-check of the scheduler simulator
#   make clean      # remove built files
# -----------------------------------------------------------------------------

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

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

.PHONY: all run selftest clean
all: 01_static_vs_dynamic 03_work_stealing

01_static_vs_dynamic: 01_static_vs_dynamic.cpp $(HEADERS)
	$(CXX) $(CXXFLAGS) -o $@ $<

03_work_stealing: 03_work_stealing.cpp ws_runtime.h $(HEADERS)
	$(CXX) $(CXXFLAGS) -o $@ $<

run: all
	@echo; ./01_static_vs_dynamic
	@echo; $(PYTHON) 02_task_order.py
	@echo; ./03_work_stealing
	@echo; $(PYTHON) 04_cilk_scheduling.py

selftest:
	$(PYTHON) cilk_sim.py

clean:
	rm -f 01_static_vs_dynamic 03_work_stealing
	rm -rf *.dSYM __pycache__
