CC := gcc
CFLAGS = -Wall -Wextra -std=gnu99 -pedantic -fPIC
LDFLAGS = -shared -Wl,--version-script=src/libmalloc.version
# Sources directory
BASEDIR = src
SRCDIRS = .

# Getting the files
FTYPE = .c
SOURCES := $(foreach dir, $(addprefix $(BASEDIR)/, $(SRCDIRS)), $(wildcard $(dir)/*$(FTYPE)))
OBJECTS:=$(subst .c,.o,$(SOURCES))

# Target program
TARGET = libmalloc.so

.PHONY: all clean debug check $(TARGET)

all: $(TARGET)

clean: cleancheck
	${RM} $(OBJECTS) $(TARGET)

$(TARGET): $(OBJECTS)
	$(CC) $(CFLAGS) $(OBJECTS) -o $(TARGET) $(LDFLAGS)

check: $(TARGET)
	cd tests && ./suite -b ..

debug: CC = clang
debug: CFLAGS += -g
debug: all

cleancheck: TESTOBJS = $(wildcard tests/TestSuite/*.pyc)
cleancheck:
	${RM} $(TESTOBJS)
