1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-12-27 23:50:29 +05:30
polonium/Makefile

95 lines
1.8 KiB
Makefile
Raw Normal View History

2024-07-07 03:18:23 +05:30
CC ?= gcc
DEBUG ?= 0
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
2024-07-08 23:37:14 +05:30
TESTDIR = ./test_files/corrupted
2024-07-07 03:18:23 +05:30
SRC = $(wildcard $(SRCDIR)/*.c)
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DEP = $(OBJ:.o=.d)
PROGNAME_BASE = polonium
PROGNAME_SUFFIX_DEBUG = debug
2024-07-07 03:18:23 +05:30
EXECUTABLE = $(PROGNAME_BASE)
2024-07-07 03:18:23 +05:30
ifeq ($(DEBUG), 1)
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
2024-07-08 23:34:41 +05:30
define rmdirs
@for dir in $1; do \
if [ -d "$$dir" ]; then \
if [ -z "$$(find "$$dir" -mindepth 1 -maxdepth 1 -print -quit)" ]; \
then \
echo "Removing empty directory $$dir"; \
else \
echo "Removing non-empty directory $$dir"; \
fi; \
rm -r $$dir; \
fi; \
done
endef
define rmdirs_if_empty
@for dir in $1; do \
if [ -d "$$dir" ]; then \
if [ -z "$$(find "$$dir" -mindepth 1 -maxdepth 1 -print -quit)" ]; \
then \
echo "Removing empty directory $$dir"; \
rm -r $$dir; \
fi; \
2024-07-07 03:18:23 +05:30
fi; \
done
2024-07-07 03:18:23 +05:30
endef
FILES_TO_REMOVE = $(EXECPATH) $(DEP) $(OBJ)
DIRECTORIES_TO_REMOVE = $(BINDIR) $(OBJDIR)
2024-07-07 03:18:23 +05:30
clean:
$(call rmfiles_if_exist,$(FILES_TO_REMOVE))
$(call rmdirs_if_empty,$(DIRECTORIES_TO_REMOVE))
2024-07-07 03:18:23 +05:30
2024-07-08 23:34:41 +05:30
distclean:
$(call rmdirs,$(DIRECTORIES_TO_REMOVE))
2024-07-08 23:34:41 +05:30
2024-07-08 23:37:14 +05:30
testclean:
$(call rmdirs,$(TESTDIR))
.PHONY: all clean distclean testclean