CFLAGS=-g -Wall -Wextra -Wno-unused-parameter
LDLIBS=-lpthread
C=$(wildcard *.c)
O=$(C:.c=)
A=$(C:.c=.asan)
L=$(C:.c=.lsan)
U=$(C:.c=.usan)
T=$(C:.c=.tsan)

pframe:
	curl -o pframe.tgz  https://dept-info.labri.fr/~thibault/SecuLog/pframe.tgz && \
		tar -xf pframe.tgz &&\
		rm -rf pframe.tgz

.gdbinit:

configure: pframe .gdbinit
	$(shell echo "python import pframe" > .gdbinit) 

all: $O $A $U $T

%.asan: %.c
	$(CC) -fsanitize=address -fPIC $< -o $@ $(CFLAGS) $(LDLIBS)
%.lsan: %.c
	$(CC) -fsanitize=leak -fPIC $< -o $@ $(CFLAGS) $(LDLIBS)
%.usan: %.c
	$(CC) -fsanitize=undefined -fPIC $< -o $@ $(CFLAGS) $(LDLIBS)
%.tsan: %.c
	$(CC) -fsanitize=thread -fPIC $< -o $@ $(CFLAGS) $(LDLIBS)

PHONY: gdb_% configure
gdb_%: $(subst gdb_,,%)
	PYTHONPATH=${PWD}/pframe${PYTHONPATH:+:${PYTHONPATH}} gdb $<


PHONY: clean
clean:
	rm -f $O $A $L $U $T pframe .gdbinit
