CC 		:= gcc
LD      := $(CC)
LIBS 	:= -lm
LDFLAGS :=
CFLAGS  := -Wall -Wextra -Wno-override-init -std=c2x -include_.h
SRC     := part1.c mylib.c
ifeq ($(PART),2)
    SRC  := part2.c mylib.c
endif
OBJ_DIR := build
OBJ     := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(SRC)))
DIR 	:= .
RAW_NAME:= a.out
NAME    := $(RAW_NAME)

ifeq ($(RELEASE),1)
    CFLAGS += -O3
    LDFLAGS += -O3 -s
else
    CFLAGS += -O0 -g3
    LDFLAGS += -O0 -g
endif

all: $(NAME)

$(NAME): $(OBJ)
	$(LD) $(LDFLAGS) -o $(DIR)/$(NAME) $(OBJ) $(LIBS)

$(OBJ_DIR)/%.o: %.c
	@mkdir -p $(@D)
	$(CC) $(CFLAGS) -c -o $@ $<

clean:
	@rm -rf $(OBJ_DIR)
	@rm -rf $(RAW_NAME)

re:
	@make --no-print clean
	@make --no-print all

.PHONY: all clean re
