From 6b13ea53aeedb646b082a13bf16f67f8556087ae Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Sun, 25 Aug 2024 00:18:42 -0500 Subject: core: refactor entire project root Reorganize the project root such that each subsystem is placed into its own subdirectory. This allows the build system to select which subsystems to enable for a particular build. Signed-off-by: Danny Holman --- .gitignore | 1 + Makefile | 36 ++++++++++++++++++++---------------- core/logging.c | 40 ++++++++++++++++++++++++++++++++++++++++ core/make.config | 6 ++++++ include/rune_logging.h | 2 +- render-vulkan/make.config | 7 +++++++ src/logging.c | 40 ---------------------------------------- 7 files changed, 75 insertions(+), 57 deletions(-) create mode 100644 core/logging.c create mode 100644 core/make.config create mode 100644 render-vulkan/make.config delete mode 100644 src/logging.c diff --git a/.gitignore b/.gitignore index 29cd635..add216e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ *.out *.patch *.so +*.sym *.tar *.xz *.zstd diff --git a/Makefile b/Makefile index b6c0086..6839dd9 100644 --- a/Makefile +++ b/Makefile @@ -2,41 +2,45 @@ CC?=gcc INCLUDE?=-Iinclude CFLAGS?=-O0 LDFLAGS?= -LIBS?=-lglfw -lvulkan +RENDER?=render-vulkan +PLATFORM?=linux # -- Do not edit below this line -- VERSION:="$(shell git describe --abbrev=4 --dirty --always --tags)" +CC:=$(CC) INCLUDE:=$(INCLUDE) -CFLAGS:=$(CFLAGS) -Wall -Wextra -DVERSION=\"$(VERSION)\" -ggdb -fstack-protector-all -fPIC +CFLAGS:=$(CFLAGS) $(INCLUDE) -Wall -Wextra -DVERSION=\"$(VERSION)\" -ggdb -fstack-protector-all -fPIC LDFLAGS:=$(LDFLAGS) -shared -LIBS:=$(LIBS) -ENGINE=librune.so -ENGINE_OBJS=src/init.o \ - src/graphics.o \ - src/callbacks.o \ +COREDIR:=core +RENDERDIR:=$(RENDER) +ENGINE:=librune.so -LINK_LIST=$(LDFLAGS) \ - $(ENGINE_OBJS) \ - $(LIBS) \ +include $(COREDIR)/make.config $(RENDERDIR)/make.config + +LDFLAGS:=$(LDFLAGS) $(RENDER_LDFLAGS) $(CORE_LDFLAGS) +LIBS:=$(LIBS) $(RENDER_LIBS) $(CORE_LIBS) +OBJS:=$(RENDER_OBJS) $(CORE_OBJS) .PHONY: all clean install install-headers .SUFFIXES: .o .c all: $(ENGINE) -$(ENGINE): $(ENGINE_OBJS) - @$(CC) -o $@ $(LINK_LIST) +$(ENGINE): $(OBJS) + @$(CC) -o $@ $(LIBS) $(LDFLAGS) $? @echo [LD] $@ + @objcopy --only-keep-debug $(ENGINE) $(ENGINE:.so=.sym) + @strip -s $(ENGINE) + @objcopy --add-gnu-debuglink=$(ENGINE:.so=.sym) $(ENGINE) + @echo [strip] $(ENGINE) .c.o: @$(CC) -MD -c $< -o $@ $(CFLAGS) $(INCLUDE) @echo [CC] $@ clean: - $(RM) $(ENGINE) - $(RM) $(ENGINE_OBJS) *.o */*.o */*/*.o - $(RM) $(ENGINE_OBJS:.o=.d) *.d */*.d */*/*.d + $(RM) $(OBJS) $(OBJS:o=.d) --include $(ENGINE_OBJS:.o=.d) +-include $(OBJS:.o=.d) diff --git a/core/logging.c b/core/logging.c new file mode 100644 index 0000000..e755710 --- /dev/null +++ b/core/logging.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#define LSTR_FATAL "[FATAL]" +#define LSTR_ERROR "[ERROR]" +#define LSTR_WARN "[WARNING]" +#define LSTR_INFO "[INFO]" +#define LSTR_DEBUG "[DEBUG]" + +void log_output(int level, const char *fmt, ...) { + char out[8192]; + memset(out, 0, sizeof(out)); + + va_list arg_ptr; + va_start(arg_ptr, fmt); + vsnprintf(out, 8192, fmt, arg_ptr); + va_end(arg_ptr); + + char *lvl_str; + switch (level) { + case LOG_FATAL: + lvl_str = LSTR_FATAL; + break; + case LOG_ERROR: + lvl_str = LSTR_ERROR; + break; + case LOG_WARN: + lvl_str = LSTR_WARN; + break; + case LOG_INFO: + lvl_str = LSTR_INFO; + break; + case LOG_DEBUG: + lvl_str = LSTR_DEBUG; + break; + } + printf("%s %s\n", lvl_str, out); +} diff --git a/core/make.config b/core/make.config new file mode 100644 index 0000000..94dce85 --- /dev/null +++ b/core/make.config @@ -0,0 +1,6 @@ +CORE_LDFLAGS= +CORE_LIBS=-lglfw + +CORE_OBJS=$(COREDIR)/graphics.o \ + $(COREDIR)/init.o \ + $(COREDIR)/logging.o \ diff --git a/include/rune_logging.h b/include/rune_logging.h index a0b9e29..f8876db 100644 --- a/include/rune_logging.h +++ b/include/rune_logging.h @@ -11,6 +11,6 @@ enum log_level { LOG_DEBUG }; -void log_output(int level, const char *fmt, ...); +RAPI void log_output(int level, const char *fmt, ...); #endif diff --git a/render-vulkan/make.config b/render-vulkan/make.config new file mode 100644 index 0000000..1999079 --- /dev/null +++ b/render-vulkan/make.config @@ -0,0 +1,7 @@ +RENDER_LDFLAGS= +RENDER_LIBS=-lvulkan + +RENDER_OBJS=$(RENDERDIR)/vulkan_context.o \ + $(RENDERDIR)/vulkan_debug.o \ + $(RENDERDIR)/vulkan_device.o \ + $(RENDERDIR)/vulkan_swapchain.o \ diff --git a/src/logging.c b/src/logging.c deleted file mode 100644 index e755710..0000000 --- a/src/logging.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include - -#define LSTR_FATAL "[FATAL]" -#define LSTR_ERROR "[ERROR]" -#define LSTR_WARN "[WARNING]" -#define LSTR_INFO "[INFO]" -#define LSTR_DEBUG "[DEBUG]" - -void log_output(int level, const char *fmt, ...) { - char out[8192]; - memset(out, 0, sizeof(out)); - - va_list arg_ptr; - va_start(arg_ptr, fmt); - vsnprintf(out, 8192, fmt, arg_ptr); - va_end(arg_ptr); - - char *lvl_str; - switch (level) { - case LOG_FATAL: - lvl_str = LSTR_FATAL; - break; - case LOG_ERROR: - lvl_str = LSTR_ERROR; - break; - case LOG_WARN: - lvl_str = LSTR_WARN; - break; - case LOG_INFO: - lvl_str = LSTR_INFO; - break; - case LOG_DEBUG: - lvl_str = LSTR_DEBUG; - break; - } - printf("%s %s\n", lvl_str, out); -} -- cgit v1.2.3