# =============================================================================
# Makefile for CMU 15-213 Lecture 16 (processes and multitasking)
# =============================================================================
#
#   make run      run all demos (01 Python; 02-04 native C)
#   make clean
#
# These are REAL Unix process programs (fork/exec/wait), compiled for the native
# arm64 machine -- process creation is an OS service, not an instruction set, so
# there is nothing to cross-compile here. 01 is a deterministic Python teaching
# tool (identical under Python 3.9 and 3.13).
# -----------------------------------------------------------------------------

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

.PHONY: all run clean
all: build/02_fork build/03_reaper build/04_exec

build:
	mkdir -p build

build/02_fork: 02_fork_two_returns.c | build
	$(CC) $(CFLAGS) -o $@ 02_fork_two_returns.c

build/03_reaper: 03_reaper.c | build
	$(CC) $(CFLAGS) -o $@ 03_reaper.c

build/04_exec: 04_exec.c | build
	$(CC) $(CFLAGS) -o $@ 04_exec.c

run: all
	@python3 01_process_graph.py
	@echo; ./build/02_fork
	@echo; ./build/03_reaper
	@echo; ./build/04_exec

clean:
	rm -rf build __pycache__
