CC ?= cc
CFLAGS ?= -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Werror
CPPFLAGS ?= -D_POSIX_C_SOURCE=200809L
PROGRAMS = bits cache_sim allocator process_demo sync_demo tiny_shell

all: $(PROGRAMS)

%: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@

sync_demo: sync_demo.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@ -pthread

test: all
	sh verify.sh

sanitize:
	$(MAKE) clean
	$(MAKE) CFLAGS='-std=c11 -O1 -g -Wall -Wextra -Wpedantic -Werror -fsanitize=address,undefined -fno-omit-frame-pointer' test

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

.PHONY: all test sanitize clean
