# =============================================================================
# Makefile for Stanford CS149 Lecture 14 demos (cache coherence)
# =============================================================================
#
# [What this builds]
#   One C++ program: false sharing, the unit of coherence, core-to-core
#   latency and true sharing, measured on real cores. Demos 01-02 are Python
#   (standard library only) on top of the simulator coherence.py.
#
# [How to use]
#   make            # build
#   make run        # run all demos in lecture order (~15 s)
#   make selftest   # self-check of coherence.py
#   make clean
# -----------------------------------------------------------------------------

CXX      ?= c++
CXXFLAGS := -std=c++20 -O2 -g -Wall -Wextra -pthread
PYTHON   ?= python3
HEADERS  := ../lecture01/cs149_timer.h ../lecture01/machine_info.h
BINS     := 03_false_sharing

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

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

run: all
	@echo; $(PYTHON) 01_protocols.py
	@echo; $(PYTHON) 02_sharing_patterns.py
	@echo; ./03_false_sharing

selftest:
	$(PYTHON) coherence.py

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