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 \
|
2024-08-07 01:19:43 +05:30
|
|
|
-D_POSIX_C_SOURCE=200112L
|
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-09 00:06:53 +05:30
|
|
|
TESTDIR_SAMPLES = ./test_files
|
|
|
|
TESTDIR = $(TESTDIR_SAMPLES)/corrupted
|
2024-07-07 03:18:23 +05:30
|
|
|
|
|
|
|
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 \
|
2024-07-09 02:50:28 +05:30
|
|
|
printf -- "Removing file $$file\n"; \
|
2024-07-07 03:18:23 +05:30
|
|
|
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 \
|
2024-07-09 02:50:28 +05:30
|
|
|
printf -- "Removing empty directory $$dir\n"; \
|
2024-07-08 23:34:41 +05:30
|
|
|
else \
|
2024-07-09 02:50:28 +05:30
|
|
|
printf -- "Removing non-empty directory $$dir\n"; \
|
2024-07-08 23:34:41 +05:30
|
|
|
fi; \
|
|
|
|
rm -r $$dir; \
|
|
|
|
fi; \
|
|
|
|
done
|
|
|
|
endef
|
|
|
|
|
2024-07-08 23:28:22 +05:30
|
|
|
define rmdirs_if_empty
|
|
|
|
@for dir in $1; do \
|
|
|
|
if [ -d "$$dir" ]; then \
|
|
|
|
if [ -z "$$(find "$$dir" -mindepth 1 -maxdepth 1 -print -quit)" ]; \
|
|
|
|
then \
|
2024-07-09 02:50:28 +05:30
|
|
|
printf -- "Removing empty directory $$dir\n"; \
|
2024-07-08 23:28:22 +05:30
|
|
|
rm -r $$dir; \
|
|
|
|
fi; \
|
2024-07-07 03:18:23 +05:30
|
|
|
fi; \
|
2024-07-08 23:28:22 +05:30
|
|
|
done
|
2024-07-07 03:18:23 +05:30
|
|
|
endef
|
|
|
|
|
2024-07-08 23:35:11 +05:30
|
|
|
FILES_TO_REMOVE = $(EXECPATH) $(DEP) $(OBJ)
|
|
|
|
DIRECTORIES_TO_REMOVE = $(BINDIR) $(OBJDIR)
|
|
|
|
|
2024-07-07 03:18:23 +05:30
|
|
|
clean:
|
2024-07-08 23:35:11 +05:30
|
|
|
$(call rmfiles_if_exist,$(FILES_TO_REMOVE))
|
|
|
|
$(call rmdirs_if_empty,$(DIRECTORIES_TO_REMOVE))
|
2024-07-07 03:18:23 +05:30
|
|
|
|
2024-07-09 02:41:13 +05:30
|
|
|
distclean: testclean
|
2024-07-08 23:35:11 +05:30
|
|
|
$(call rmdirs,$(DIRECTORIES_TO_REMOVE))
|
2024-07-08 23:34:41 +05:30
|
|
|
|
2024-07-09 00:06:53 +05:30
|
|
|
# Variables for testing
|
|
|
|
EXEC_LOG = ./exec.log
|
2024-08-06 18:33:57 +05:30
|
|
|
PROGRAM_ARGS := -probability 60 -threshold 2 -passes 2 -noconfirm -contents \
|
|
|
|
-seed 999999999
|
2024-07-09 00:06:53 +05:30
|
|
|
|
|
|
|
test:
|
|
|
|
@if [ ! -e "$(EXECPATH)" ]; then \
|
|
|
|
printf -- "[!] Polonium executable (\`$(EXECUTABLE)\`) is not \
|
|
|
|
available, attempting to build\n"; \
|
|
|
|
$(MAKE) all; \
|
|
|
|
exit 0; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
@printf -- "[*] Generating corrupted versions of test files\n"
|
|
|
|
@mkdir -p $(TESTDIR)
|
|
|
|
@find $(TESTDIR_SAMPLES) -maxdepth 1 -type f -name 'test.*' | while IFS= \
|
|
|
|
read -r file; do \
|
|
|
|
basename=$$(basename "$$file"); \
|
|
|
|
workfile="$(TESTDIR)/$$basename"; \
|
|
|
|
cp "$$file" "$$workfile" || exit 1; \
|
|
|
|
printf -- "--- [*] $(EXECUTABLE) $(basename "$2")$(PROGRAM_ARGS)\n"; \
|
|
|
|
$(EXECPATH) "$$workfile" $(PROGRAM_ARGS) > $(EXEC_LOG) 2>&1; \
|
|
|
|
if [ "$$?" -ne "0" ]; then \
|
|
|
|
printf -- "[!] Polonium failed:\n"; \
|
|
|
|
cat $(EXEC_LOG); \
|
|
|
|
rm $(EXEC_LOG); \
|
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
rm $(EXEC_LOG); \
|
|
|
|
done
|
|
|
|
@printf "[>] All done!\n"
|
|
|
|
|
2024-07-08 23:37:14 +05:30
|
|
|
testclean:
|
|
|
|
$(call rmdirs,$(TESTDIR))
|
|
|
|
|
2024-07-09 00:06:53 +05:30
|
|
|
.PHONY: all clean distclean test testclean
|