# =============================================================================
# Makefile for Stanford CS149 Lecture 17 demos (transactional memory, part I)
# =============================================================================
#
# [What this builds]
#   04_bank_stm   bank transfers with locks vs. the small STM in norec.h
#   Demos 01-03 are Python (standard library only) on top of tmsim.py.
#
# [How to use]
#   make            # build
#   make run        # run all demos in lecture order (~4 s)
#   make selftest   # self-check of tmsim.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 norec.h
BINS     := 04_bank_stm

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

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

run: all
	@echo; $(PYTHON) 01_tm_policies.py
	@echo; $(PYTHON) 02_tm_workloads.py
	@echo; $(PYTHON) 03_tm_semantics.py
	@echo; ./04_bank_stm

selftest:
	$(PYTHON) tmsim.py

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