Update makefile
This commit is contained in:
177
makefile
177
makefile
@@ -1,110 +1,99 @@
|
|||||||
|
.POSIX:
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -std=c17 \
|
CFLAGS = -std=c17 \
|
||||||
-pedantic \
|
-pedantic -pedantic-errors -Werror -Wall -Wextra -Wshadow \
|
||||||
-pedantic-errors \
|
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition \
|
||||||
-Werror \
|
-Wformat=2 -Wcast-qual -Wwrite-strings -Winit-self -Wnull-dereference \
|
||||||
-Wall \
|
-Wdouble-promotion -Wconversion -Wsign-conversion -Wsign-compare \
|
||||||
-Wextra \
|
-Wtype-limits -Wunreachable-code -Wswitch-enum -Wswitch-default \
|
||||||
-Wshadow \
|
-Wundef -Wendif-labels -Wpointer-arith -Wredundant-decls \
|
||||||
-Wstrict-prototypes \
|
-Wbad-function-cast -Wmissing-noreturn -Wnested-externs -Wlogical-op \
|
||||||
-Wmissing-prototypes \
|
-Wclobbered -Wfloat-equal -Wrestrict -Wsequence-point -Waddress \
|
||||||
-Wold-style-definition \
|
-Wvla -Wduplicated-cond -Wduplicated-branches -fno-common -ftrapv \
|
||||||
-Wformat=2 \
|
|
||||||
-Wcast-qual \
|
|
||||||
-Wwrite-strings \
|
|
||||||
-Winit-self \
|
|
||||||
-Wnull-dereference \
|
|
||||||
-Wdouble-promotion \
|
|
||||||
-Wconversion \
|
|
||||||
-Wsign-conversion \
|
|
||||||
-Wsign-compare \
|
|
||||||
-Wtype-limits \
|
|
||||||
-Wunreachable-code \
|
|
||||||
-Wswitch-enum \
|
|
||||||
-Wswitch-default \
|
|
||||||
-Wundef \
|
|
||||||
-Wendif-labels \
|
|
||||||
-Wpointer-arith \
|
|
||||||
-Wredundant-decls \
|
|
||||||
-Wbad-function-cast \
|
|
||||||
-Wmissing-noreturn \
|
|
||||||
-Wnested-externs \
|
|
||||||
-Wlogical-op \
|
|
||||||
-Wclobbered \
|
|
||||||
-Wfloat-equal \
|
|
||||||
-Wrestrict \
|
|
||||||
-Wsequence-point \
|
|
||||||
-Waddress \
|
|
||||||
-Wvla \
|
|
||||||
-Wduplicated-cond \
|
|
||||||
-Wduplicated-branches \
|
|
||||||
-fno-common \
|
|
||||||
-ftrapv \
|
|
||||||
-fstack-protector-strong
|
-fstack-protector-strong
|
||||||
|
|
||||||
DEBUG_FLAGS = -g3 -O0 -fsanitize=undefined -fno-omit-frame-pointer
|
DEBUG_FLAGS = -g3 -O0 -fsanitize=undefined
|
||||||
RELEASE_FLAGS = -O2 -D NDEBUG
|
RELEASE_FLAGS = -O2 -s -D NDEBUG
|
||||||
TEST_FLAGS = -g
|
|
||||||
|
|
||||||
PROJECT_NAME != basename "$$(pwd)"
|
all: help
|
||||||
VERSION != cat config/version 2>/dev/null
|
|
||||||
SOURCE_FILES != cat config/source_code_list 2>/dev/null
|
|
||||||
INCLUDES != cat config/header_list 2>/dev/null
|
|
||||||
|
|
||||||
# --- INCREMENTAL BUILD SETUP ---
|
|
||||||
# Map source files (.c) to object files (.o) in isolated directories
|
|
||||||
DEBUG_OBJ_FILES = $(patsubst %.c, output/obj_debug/%.o, $(SOURCE_FILES))
|
|
||||||
RELEASE_OBJ_FILES = $(patsubst %.c, output/obj_release/%.o, $(SOURCE_FILES))
|
|
||||||
|
|
||||||
# Map object files to dependency files (.d) generated by the compiler
|
|
||||||
DEP_FILES = $(DEBUG_OBJ_FILES:.o=.d) $(RELEASE_OBJ_FILES:.o=.d)
|
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo "Please use: 'make init' 'make debug', 'make fast', 'make release', 'make synch', or 'make clean'"
|
@echo "Please use: 'make init', 'make debug', 'make fast', 'make release', or 'make clean'"
|
||||||
|
@echo "Supports parallel builds (e.g., 'make -j8 debug')"
|
||||||
|
|
||||||
init:
|
init:
|
||||||
@mkdir -p output source_code includes config
|
@mkdir -p output source_code includes config
|
||||||
@touch config/source_code_list config/version config/header_list source_code/main.c
|
@touch config/version source_code/main.c
|
||||||
@date +_%y.%j.%H.%M%S > config/version
|
@echo "_00.000.00.0000" > config/version
|
||||||
@echo source_code/main.c > config/source_code_list
|
@echo "Project initialized."
|
||||||
|
|
||||||
|
|
||||||
synch:
|
|
||||||
@echo "Synchronizing source code files..."
|
|
||||||
@find source_code -type f -name '*.c' | sort > config/source_code_list
|
|
||||||
@echo "Synchronizing header files..."
|
|
||||||
@find includes -type f -name '*.h' | sort > config/header_list
|
|
||||||
@echo "Synchronization complete."
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf output/obj_debug output/obj_release output/$(PROJECT_NAME)*
|
@rm -rf output/obj_debug output/obj_release config/*.mk
|
||||||
|
@rm -f output/*
|
||||||
@echo "Project Cleaned"
|
@echo "Project Cleaned"
|
||||||
|
|
||||||
debug: $(DEBUG_OBJ_FILES)
|
# ------------------------------
|
||||||
$(CC) $(CFLAGS) $(DEBUG_FLAGS) -o output/$(PROJECT_NAME)$(VERSION) $(DEBUG_OBJ_FILES)
|
# Dynamic Build Graph Generators
|
||||||
|
debug:
|
||||||
|
@mkdir -p config output/obj_debug
|
||||||
|
@PROJ_NAME=$$(basename "$$(pwd)"); \
|
||||||
|
VERS=$$(cat config/version 2>/dev/null || echo "_00.000.00.0000"); \
|
||||||
|
OUT="output/$${PROJ_NAME}$${VERS}"; \
|
||||||
|
MK="config/debug.mk"; \
|
||||||
|
echo ".POSIX:" > $$MK; \
|
||||||
|
HEADERS=$$(find includes -type f -name '*.h' | tr '\n' ' '); \
|
||||||
|
OBJS=""; \
|
||||||
|
for SRC in $$(find source_code -type f -name '*.c'); do \
|
||||||
|
OBJ="output/obj_debug/$${SRC}.o"; \
|
||||||
|
OBJS="$$OBJS $$OBJ"; \
|
||||||
|
echo "$$OBJ: $$SRC $$HEADERS" >> $$MK; \
|
||||||
|
echo " @mkdir -p $$(dirname $$OBJ)" >> $$MK; \
|
||||||
|
echo " $(CC) $(CFLAGS) $(DEBUG_FLAGS) -I includes -c $$SRC -o $$OBJ" >> $$MK; \
|
||||||
|
done; \
|
||||||
|
echo "$$OUT: $$OBJS" >> $$MK; \
|
||||||
|
echo " $(CC) $(CFLAGS) $(DEBUG_FLAGS) -o $$OUT $$OBJS" >> $$MK; \
|
||||||
|
$(MAKE) -f $$MK "$$OUT"
|
||||||
|
|
||||||
fast: $(RELEASE_OBJ_FILES)
|
fast:
|
||||||
$(CC) $(CFLAGS) $(RELEASE_FLAGS) -o output/$(PROJECT_NAME)$(VERSION) $(RELEASE_OBJ_FILES)
|
@mkdir -p config output/obj_release
|
||||||
|
@PROJ_NAME=$$(basename "$$(pwd)"); \
|
||||||
|
VERS=$$(cat config/version 2>/dev/null || echo "_00.000.00.0000"); \
|
||||||
|
OUT="output/$${PROJ_NAME}$${VERS}"; \
|
||||||
|
MK="config/fast.mk"; \
|
||||||
|
echo ".POSIX:" > $$MK; \
|
||||||
|
HEADERS=$$(find includes -type f -name '*.h' | tr '\n' ' '); \
|
||||||
|
OBJS=""; \
|
||||||
|
for SRC in $$(find source_code -type f -name '*.c'); do \
|
||||||
|
OBJ="output/obj_release/$${SRC}.o"; \
|
||||||
|
OBJS="$$OBJS $$OBJ"; \
|
||||||
|
echo "$$OBJ: $$SRC $$HEADERS" >> $$MK; \
|
||||||
|
echo " @mkdir -p $$(dirname $$OBJ)" >> $$MK; \
|
||||||
|
echo " $(CC) $(CFLAGS) $(RELEASE_FLAGS) -I includes -c $$SRC -o $$OBJ" >> $$MK; \
|
||||||
|
done; \
|
||||||
|
echo "$$OUT: $$OBJS" >> $$MK; \
|
||||||
|
echo " $(CC) $(CFLAGS) $(RELEASE_FLAGS) -o $$OUT $$OBJS" >> $$MK; \
|
||||||
|
$(MAKE) -f $$MK "$$OUT"
|
||||||
|
|
||||||
release: $(RELEASE_OBJ_FILES)
|
release:
|
||||||
@echo "Project version updated from: $(VERSION)"
|
@mkdir -p config output/obj_release
|
||||||
@date +_%y.%j.%H.%M%S > config/version
|
@DATE_STR=$$(date +_%y.%j.%H.%M%S); \
|
||||||
@echo "To: $$(cat config/version)"
|
echo "$$DATE_STR" > config/version; \
|
||||||
@echo ""
|
echo "Project version updated to: $$DATE_STR"
|
||||||
$(CC) $(CFLAGS) $(RELEASE_FLAGS) -o output/$(PROJECT_NAME)$$(cat config/version) $(RELEASE_OBJ_FILES)
|
@PROJ_NAME=$$(basename "$$(pwd)"); \
|
||||||
|
VERS=$$(cat config/version 2>/dev/null); \
|
||||||
# --- COMPILATION PATTERN RULES ---
|
OUT="output/$${PROJ_NAME}$${VERS}"; \
|
||||||
# Compile Debug Objects
|
MK="config/release.mk"; \
|
||||||
output/obj_debug/%.o: %.c
|
echo ".POSIX:" > $$MK; \
|
||||||
@mkdir -p $(dir $@)
|
HEADERS=$$(find includes -type f -name '*.h' | tr '\n' ' '); \
|
||||||
$(CC) $(CFLAGS) $(DEBUG_FLAGS) -I includes -MMD -MP -c $< -o $@
|
OBJS=""; \
|
||||||
|
for SRC in $$(find source_code -type f -name '*.c'); do \
|
||||||
# Compile Release/Fast Objects
|
OBJ="output/obj_release/$${SRC}.o"; \
|
||||||
output/obj_release/%.o: %.c
|
OBJS="$$OBJS $$OBJ"; \
|
||||||
@mkdir -p $(dir $@)
|
echo "$$OBJ: $$SRC $$HEADERS" >> $$MK; \
|
||||||
$(CC) $(CFLAGS) $(RELEASE_FLAGS) -I includes -MMD -MP -c $< -o $@
|
echo " @mkdir -p $$(dirname $$OBJ)" >> $$MK; \
|
||||||
|
echo " $(CC) $(CFLAGS) $(RELEASE_FLAGS) -I includes -c $$SRC -o $$OBJ" >> $$MK; \
|
||||||
# Automatically pull in header dependencies
|
done; \
|
||||||
-include $(DEP_FILES)
|
echo "$$OUT: $$OBJS" >> $$MK; \
|
||||||
|
echo " $(CC) $(CFLAGS) $(RELEASE_FLAGS) -o $$OUT $$OBJS" >> $$MK; \
|
||||||
.PHONY: help synch clean debug fast release
|
$(MAKE) -f $$MK "$$OUT"
|
||||||
|
|||||||
Reference in New Issue
Block a user