mirror of
https://git.disroot.org/80486DX2-66/polonium.git
synced 2024-11-08 13:42:31 +05:30
72 lines
1.3 KiB
Makefile
72 lines
1.3 KiB
Makefile
CC ?= gcc
|
|
DEBUG ?= 0
|
|
|
|
CFLAGS = -Wall -Werror -Wextra -Wpedantic -std=c99 -Ofast \
|
|
-D_POSIX_C_SOURCE=200809L
|
|
|
|
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)
|
|
|
|
PROGNAME_RELEASE = polonium
|
|
PROGNAME_DEBUG = polonium_debug
|
|
|
|
ifeq ($(DEBUG), 1)
|
|
EXECUTABLE = $(PROGNAME_DEBUG)
|
|
else
|
|
EXECUTABLE = $(PROGNAME_RELEASE)
|
|
endif
|
|
|
|
EXECPATH = $(BINDIR)/$(EXECUTABLE)
|
|
EXECPATH_RELEASE = $(BINDIR)/$(PROGNAME_RELEASE)
|
|
EXECPATH_DEBUG = $(BINDIR)/$(PROGNAME_DEBUG)
|
|
|
|
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:
|
|
$(call rmfiles_if_exist,$(EXECPATH_RELEASE) $(EXECPATH_DEBUG) $(DEP) $(OBJ))
|
|
$(call rmdir_if_empty,$(BINDIR))
|
|
$(call rmdir_if_empty,$(OBJDIR))
|
|
|
|
.PHONY: all clean
|