From 1ce6031a42d22a0f2be566e1873377ab2cda66c8 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Fri, 30 Aug 2024 01:31:27 -0500 Subject: Makefile: retool the build system Retool the build system to be more modular and more flexible. Move all subsystems into separate directories and create make.config files that will conditionally compile based on information from the root Makefile. Signed-off-by: Danny Holman --- Makefile | 72 +++++++++++++++++++++++++++++++++-------------- core/logging.c | 2 +- core/make.config | 6 ---- graphics/make.config | 16 +++++++++++ include/rune/graphics.h | 38 +++++++++++++++++++++++++ include/rune/list.h | 53 ++++++++++++++++++++++++++++++++++ include/rune/logging.h | 37 ++++++++++++++++++++++++ include/rune/types.h | 40 ++++++++++++++++++++++++++ include/rune/util.h | 54 +++++++++++++++++++++++++++++++++++ include/rune_list.h | 32 --------------------- include/rune_logging.h | 16 ----------- include/rune_math.h | 37 ------------------------ include/rune_types.h | 40 -------------------------- include/rune_util.h | 11 -------- network/make.config | 7 +++++ render-vulkan/make.config | 7 ----- sound/make.config | 7 +++++ 17 files changed, 304 insertions(+), 171 deletions(-) delete mode 100644 core/make.config create mode 100644 graphics/make.config create mode 100644 include/rune/graphics.h create mode 100644 include/rune/list.h create mode 100644 include/rune/logging.h create mode 100644 include/rune/types.h create mode 100644 include/rune/util.h delete mode 100644 include/rune_list.h delete mode 100644 include/rune_logging.h delete mode 100644 include/rune_math.h delete mode 100644 include/rune_types.h delete mode 100644 include/rune_util.h create mode 100644 network/make.config delete mode 100644 render-vulkan/make.config create mode 100644 sound/make.config diff --git a/Makefile b/Makefile index 6839dd9..b8f8a08 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +1,76 @@ CC?=gcc +LD?=ld INCLUDE?=-Iinclude CFLAGS?=-O0 LDFLAGS?= -RENDER?=render-vulkan -PLATFORM?=linux +LIBS?= +PREFIX?=/usr/local/ + +HEADLESS?=0 +RENDER_API?=vulkan +NETWORK?=1 # -- Do not edit below this line -- -VERSION:="$(shell git describe --abbrev=4 --dirty --always --tags)" +MAJOR:=0 +MINOR:=55 +REV:= +VERSION:="$(MAJOR).$(MINOR)$(REV)" + +LIBRARY:=librune.so.$(MAJOR).$(MINOR) +SONAME:=librune.so.$(MAJOR) +SYMFILE:=librune.sym + +LIBDIR:=$(DESTDIR)$(PREFIX)lib/ +BINDIR:=$(DESTDIR)$(PREFIX)bin/ +INCLUDEDIR:=$(DESTDIR)$(PREFIX)include/rune/ + CC:=$(CC) INCLUDE:=$(INCLUDE) CFLAGS:=$(CFLAGS) $(INCLUDE) -Wall -Wextra -DVERSION=\"$(VERSION)\" -ggdb -fstack-protector-all -fPIC LDFLAGS:=$(LDFLAGS) -shared -COREDIR:=core -RENDERDIR:=$(RENDER) -ENGINE:=librune.so - -include $(COREDIR)/make.config $(RENDERDIR)/make.config +.PHONY: all check clean install +.SUFFIXES: .o .c -LDFLAGS:=$(LDFLAGS) $(RENDER_LDFLAGS) $(CORE_LDFLAGS) -LIBS:=$(LIBS) $(RENDER_LIBS) $(CORE_LIBS) -OBJS:=$(RENDER_OBJS) $(CORE_OBJS) +OBJS:=core/callbacks.o \ + core/init.o \ + core/logging.o \ -.PHONY: all clean install install-headers -.SUFFIXES: .o .c +-include graphics/make.config +-include sound/make.config +-include network/make.config -all: $(ENGINE) +all: $(LIBRARY) -$(ENGINE): $(OBJS) - @$(CC) -o $@ $(LIBS) $(LDFLAGS) $? +$(LIBRARY): $(OBJS) + @$(LD) -soname $(SONAME) -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) + @objcopy --only-keep-debug $(LIBRARY) $(SYMFILE) + @objcopy --add-gnu-debuglink=$(SYMFILE) $(LIBRARY) + @strip -s $(LIBRARY) + @echo [strip] $(LIBRARY) .c.o: @$(CC) -MD -c $< -o $@ $(CFLAGS) $(INCLUDE) @echo [CC] $@ +check: + clean: - $(RM) $(OBJS) $(OBJS:o=.d) + $(RM) $(OBJS) $(OBJS:.o=.d) $(LIBRARY) $(SYMFILE) tags TAGS + +install: + install -d $(LIBDIR) + install -d $(BINDIR) + install -d $(INCLUDEDIR) + install -d $(INCLUDEDIR)$(RENDER_API) + install -p -m 644 include/rune/*.h $(INCLUDEDIR) + install -p -m 644 include/rune/$(RENDER_API)/*.h $(INCLUDEDIR)$(RENDER_API) + install -p -m 755 $(LIBRARY) $(LIBDIR) + ln -s $(LIBDIR)$(LIBRARY) $(LIBDIR)$(SONAME) + +tags: + ctags -R --kinds-c=+pLl --fields=+S include/ core/ render-vulkan/ -include $(OBJS:.o=.d) diff --git a/core/logging.c b/core/logging.c index e755710..7f127f3 100644 --- a/core/logging.c +++ b/core/logging.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/core/make.config b/core/make.config deleted file mode 100644 index 94dce85..0000000 --- a/core/make.config +++ /dev/null @@ -1,6 +0,0 @@ -CORE_LDFLAGS= -CORE_LIBS=-lglfw - -CORE_OBJS=$(COREDIR)/graphics.o \ - $(COREDIR)/init.o \ - $(COREDIR)/logging.o \ diff --git a/graphics/make.config b/graphics/make.config new file mode 100644 index 0000000..50ef43a --- /dev/null +++ b/graphics/make.config @@ -0,0 +1,16 @@ +ifneq ("$(HEADLESS)", "1") + +LIBS += -lglfw + +ifeq ("$(RENDER_API)", "vulkan") + +LIBS += -lvulkan + +OBJS += graphics/render-vulkan/vulkan_context.o \ + graphics/render-vulkan/vulkan_debug.o \ + graphics/render-vulkan/vulkan_device.o \ + graphics/render-vulkan/vulkan_swapchain.o \ + +endif + +endif diff --git a/include/rune/graphics.h b/include/rune/graphics.h new file mode 100644 index 0000000..8f10b4a --- /dev/null +++ b/include/rune/graphics.h @@ -0,0 +1,38 @@ +/* + * Rune Game Engine + * Copyright 2024 Danny Holman + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef RUNE_GRAPHICS_H +#define RUNE_GRAPHICS_H + +#include +#include + +struct rune_window { + uint32_t winw; + uint32_t winh; + const char *wintitle; + GLFWwindow *window; +}; + +RAPI int rune_gfx_init(struct rune_window *window); +RAPI void rune_gfx_quit(struct rune_window *window); + +#endif diff --git a/include/rune/list.h b/include/rune/list.h new file mode 100644 index 0000000..1107491 --- /dev/null +++ b/include/rune/list.h @@ -0,0 +1,53 @@ +/* + * Rune Game Engine + * Copyright 2024 Danny Holman + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef RUNE_LIST_H +#define RUNE_LIST_H + +#include + +struct list_head { + struct list_head *next; + struct list_head *prev; +}; + +static inline void list_add(struct list_head *new, struct list_head *head) { + struct list_head *temp = head; + while (temp->next != NULL) + temp = temp->next; + + temp->next = new; + new->prev = temp; + new->next = NULL; +} + +static inline void list_del(struct list_head *item) { + struct list_head *next = item->next; + struct list_head *prev = item->prev; + if (next != NULL) + next->prev = prev; + if (prev != NULL) + prev->next = next; + item->next = NULL; + item->prev = NULL; +} + +#endif diff --git a/include/rune/logging.h b/include/rune/logging.h new file mode 100644 index 0000000..5b9aabf --- /dev/null +++ b/include/rune/logging.h @@ -0,0 +1,37 @@ +/* + * Rune Game Engine + * Copyright 2024 Danny Holman + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef RUNE_LOGGING_H +#define RUNE_LOGGING_H + +#include + +enum log_level { + LOG_FATAL, + LOG_ERROR, + LOG_WARN, + LOG_INFO, + LOG_DEBUG +}; + +RAPI void log_output(int level, const char *fmt, ...); + +#endif diff --git a/include/rune/types.h b/include/rune/types.h new file mode 100644 index 0000000..03e3edb --- /dev/null +++ b/include/rune/types.h @@ -0,0 +1,40 @@ +/* + * Rune Game Engine + * Copyright 2024 Danny Holman + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef RUNE_TYPES_H +#define RUNE_TYPES_H + +#include + +STATIC_ASSERT(sizeof(uint8_t) == 1, "Expected uint8_t to be 1 byte"); +STATIC_ASSERT(sizeof(uint16_t) == 2, "Expected uint16_t to be 2 bytes"); +STATIC_ASSERT(sizeof(uint32_t) == 4, "Expected uint32_t to be 4 bytes"); +STATIC_ASSERT(sizeof(uint64_t) == 8, "Expected uint64_t to be 8 bytes"); + +STATIC_ASSERT(sizeof(int8_t) == 1, "Expected int8_t to be 1 byte"); +STATIC_ASSERT(sizeof(int16_t) == 2, "Expected int16_t to be 2 bytes"); +STATIC_ASSERT(sizeof(int32_t) == 4, "Expected int32_t to be 4 bytes"); +STATIC_ASSERT(sizeof(int64_t) == 8, "Expected int64_t to be 8 bytes"); + +STATIC_ASSERT(sizeof(float) == 4, "Expected float to be 4 bytes"); +STATIC_ASSERT(sizeof(double) == 8, "Expected double to be 8 bytes"); + +#endif diff --git a/include/rune/util.h b/include/rune/util.h new file mode 100644 index 0000000..04429c4 --- /dev/null +++ b/include/rune/util.h @@ -0,0 +1,54 @@ +/* + * Rune Game Engine + * Copyright 2024 Danny Holman + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef RUNE_UTIL_H +#define RUNE_UTIL_H + +#include +#include + +#if defined(__clang__) || defined(__gcc__) + #define STATIC_ASSERT _Static_assert +#else + #define STATIC_ASSERT static_assert +#endif + + +#ifdef REXPORT + #ifdef _MSC_VER + #define RAPI __declspec(dllexport) + #else + #define RAPI __attribute__((visibility("default"))) + #endif +#else + #ifdef _MSC_VER + #define RAPI __declspec(dllexport) + #else + #define RAPI + #endif +#endif + +static inline uint32_t clamp(uint32_t value, float min, float max) { + const uint32_t ret = value < min ? min : value; + return ret > max ? max : ret; +} + +#endif diff --git a/include/rune_list.h b/include/rune_list.h deleted file mode 100644 index 9c7c651..0000000 --- a/include/rune_list.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef RUNE_LIST_H -#define RUNE_LIST_H - -#include - -struct list_head { - struct list_head *next; - struct list_head *prev; -}; - -static inline void list_add(struct list_head *new, struct list_head *head) { - struct list_head *temp = head; - while (temp->next != NULL) - temp = temp->next; - - temp->next = new; - new->prev = temp; - new->next = NULL; -} - -static inline void list_del(struct list_head *item) { - struct list_head *next = item->next; - struct list_head *prev = item->prev; - if (next != NULL) - next->prev = prev; - if (prev != NULL) - prev->next = next; - item->next = NULL; - item->prev = NULL; -} - -#endif diff --git a/include/rune_logging.h b/include/rune_logging.h deleted file mode 100644 index f8876db..0000000 --- a/include/rune_logging.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef RUNE_LOGGING_H -#define RUNE_LOGGING_H - -#include - -enum log_level { - LOG_FATAL, - LOG_ERROR, - LOG_WARN, - LOG_INFO, - LOG_DEBUG -}; - -RAPI void log_output(int level, const char *fmt, ...); - -#endif diff --git a/include/rune_math.h b/include/rune_math.h deleted file mode 100644 index 25bf4fd..0000000 --- a/include/rune_math.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RUNE_MATH_H -#define RUNE_MATH_H - -struct vec2 { - float x; - float y; -}; - -struct vec3 { - float x; - float y; - float z; -}; - -struct vec4 { - float x; - float y; - float z; - float w; -}; - -struct mat3 { - struct vec3 v[3]; -}; - -struct mat4 { - struct vec3 v[4]; -}; - -struct quat { - float x; - float y; - float z; - float w; -}; - -#endif diff --git a/include/rune_types.h b/include/rune_types.h deleted file mode 100644 index 8fada14..0000000 --- a/include/rune_types.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef RUNE_TYPES_H -#define RUNE_TYPES_H - -#include -#include - -#if defined(__clang__) || defined(__gcc__) - #define STATIC_ASSERT _Static_assert -#else - #define STATIC_ASSERT static_assert -#endif - -STATIC_ASSERT(sizeof(uint8_t) == 1, "Expected uint8_t to be 1 byte"); -STATIC_ASSERT(sizeof(uint16_t) == 2, "Expected uint16_t to be 2 bytes"); -STATIC_ASSERT(sizeof(uint32_t) == 4, "Expected uint32_t to be 4 bytes"); -STATIC_ASSERT(sizeof(uint64_t) == 8, "Expected uint64_t to be 8 bytes"); - -STATIC_ASSERT(sizeof(int8_t) == 1, "Expected int8_t to be 1 byte"); -STATIC_ASSERT(sizeof(int16_t) == 2, "Expected int16_t to be 2 bytes"); -STATIC_ASSERT(sizeof(int32_t) == 4, "Expected int32_t to be 4 bytes"); -STATIC_ASSERT(sizeof(int64_t) == 8, "Expected int64_t to be 8 bytes"); - -STATIC_ASSERT(sizeof(float) == 4, "Expected float to be 4 bytes"); -STATIC_ASSERT(sizeof(double) == 8, "Expected double to be 8 bytes"); - -#ifdef REXPORT - #ifdef _MSC_VER - #define RAPI __declspec(dllexport) - #else - #define RAPI __attribute__((visibility("default"))) - #endif -#else - #ifdef _MSC_VER - #define RAPI __declspec(dllexport) - #else - #define RAPI - #endif -#endif - -#endif diff --git a/include/rune_util.h b/include/rune_util.h deleted file mode 100644 index f0613c9..0000000 --- a/include/rune_util.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef RUNE_UTIL_H -#define RUNE_UTIL_H - -#include - -static inline uint32_t clamp(uint32_t value, float min, float max) { - const uint32_t ret = value < min ? min : value; - return ret > max ? max : ret; -} - -#endif diff --git a/network/make.config b/network/make.config new file mode 100644 index 0000000..9abce28 --- /dev/null +++ b/network/make.config @@ -0,0 +1,7 @@ +ifeq ("$(NETWORK)", 1) + +LIBS += + +OBJS += + +endif diff --git a/render-vulkan/make.config b/render-vulkan/make.config deleted file mode 100644 index 1999079..0000000 --- a/render-vulkan/make.config +++ /dev/null @@ -1,7 +0,0 @@ -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/sound/make.config b/sound/make.config new file mode 100644 index 0000000..6fe27f5 --- /dev/null +++ b/sound/make.config @@ -0,0 +1,7 @@ +ifneq ("$(HEADLESS)", "1") + +LIBS += -lopenal + +OBJS += sound/sound.o \ + +endif -- cgit v1.2.3