# =============================================================================
# Makefile for CMU 15-213 Lecture 10 (cache memories)
# =============================================================================
#
#   make          build the C timing demos (native)
#   make run      run all demos (01 Python; 02-04 native timing)
#   make clean
#
# 01_cache_sim.py is a Python teaching simulator (see cachesim.py); it is NOT
# the cachelab csim.c. 02-04 are real measurements, compiled at -O2.
# -----------------------------------------------------------------------------

CC     ?= cc
CFLAGS := -std=c11 -O2 -Wall -Wextra

.PHONY: all run clean
all: build/02_memory_mountain build/03_matmul build/04_blocking

build:
	mkdir -p build

build/02_memory_mountain: 02_memory_mountain.c timer.h | build
	$(CC) $(CFLAGS) -o $@ 02_memory_mountain.c

build/03_matmul: 03_matmul.c timer.h | build
	$(CC) $(CFLAGS) -o $@ 03_matmul.c

build/04_blocking: 04_blocking.c timer.h | build
	$(CC) $(CFLAGS) -o $@ 04_blocking.c

run: all
	@python3 01_cache_sim.py
	@echo; ./build/02_memory_mountain
	@echo; ./build/03_matmul
	@echo; ./build/04_blocking

clean:
	rm -rf build __pycache__
