2024-07-07 03:18:23 +05:30
|
|
|
CC ?= gcc
|
|
|
|
DEBUG ?= 0
|
|
|
|
|
2024-07-07 03:38:41 +05:30
|
|
|
CFLAGS = -Wall -Werror -Wextra -Wpedantic -std=c99 -Ofast \
|
|
|
|
-D_POSIX_C_SOURCE=200809L
|
2024-07-07 03:18:23 +05:30
|
|
|
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
CFLAGS += -g -DDEBUG
|
|
|
|
endif
|
|
|
|
|
|
|
|
SRCDIR = ./src
|
|
|
|
INCDIR = ./include
|
|
|
|
OBJDIR = ./obj
|
|
|
|
BINDIR = ./bin
|
|
|
|
|
|
|
|
SRC = $(wildcard $(SRCDIR)/*.c)
|
|
|
|
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
|
|
|
|
DEP = $(OBJ:.o=.d)
|
|
|
|
|
2024-07-08 23:20:46 +05:30
|
|
|
PROGNAME_BASE = polonium
|
|
|
|
PROGNAME_SUFFIX_DEBUG = debug
|
2024-07-07 03:18:23 +05:30
|
|
|
|
2024-07-08 23:20:46 +05:30
|
|
|
EXECUTABLE = $(PROGNAME_BASE)
|
2024-07-07 03:18:23 +05:30
|
|
|
ifeq ($(DEBUG), 1)
|
2024-07-08 23:20:46 +05:30
|
|
|
EXECUTABLE := $(EXECUTABLE)_$(PROGNAME_SUFFIX_DEBUG)
|
2024-07-07 03:18:23 +05:30
|
|
|
endif
|
|
|
|
|
|
|
|
EXECPATH = $(BINDIR)/$(EXECUTABLE)
|
|
|
|
|
|
|
|
all: $(EXECPATH)
|
|
|
|
|
|
|
|
$(EXECPATH): $(OBJ)
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CC) $(CFLAGS) $^ -o $@
|
|
|
|
ifeq ($(DEBUG), 0)
|
|
|
|
strip $@*
|
|
|
|
endif
|
|
|
|
|
|
|
|
-include $(DEP)
|
|
|
|
|
|
|
|
$(OBJDIR)/%.o: $(SRCDIR)/%.c
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
$(CC) $(CFLAGS) -I$(INCDIR) -MMD -MP -c $< -o $@
|
|
|
|
|
|
|
|
define rmfiles_if_exist
|
|
|
|
@for file in $1; do \
|
|
|
|
if [ -e $$file ]; then \
|
|
|
|
echo "Removing file $$file"; \
|
|
|
|
rm $$file; \
|
|
|
|
fi; \
|
|
|
|
done
|
|
|
|
endef
|
|
|
|
|
|
|
|
define rmdir_if_empty
|
|
|
|
@if [ -d "$1" ]; then \
|
|
|
|
if [ -z "$$(find "$1" -mindepth 1 -maxdepth 1 -print -quit)" ]; then \
|
|
|
|
echo "Removing empty directory $1"; \
|
|
|
|
rm -r $1; \
|
|
|
|
fi; \
|
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
|
|
|
clean:
|
2024-07-08 23:20:46 +05:30
|
|
|
$(call rmfiles_if_exist,$(EXECPATH) $(DEP) $(OBJ))
|
2024-07-07 03:18:23 +05:30
|
|
|
$(call rmdir_if_empty,$(BINDIR))
|
|
|
|
$(call rmdir_if_empty,$(OBJDIR))
|
|
|
|
|
|
|
|
.PHONY: all clean
|