-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile.engine.linux.mak
More file actions
97 lines (79 loc) · 3.48 KB
/
Makefile.engine.linux.mak
File metadata and controls
97 lines (79 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Makefile.engine.linux.mak
# Purpose: Build the Koru engine shared library (.so) on Linux using Clang and Make.
# This file defines how to compile and link the engine module as a shared library.
# Output directories
BUILD_DIR := bin
OBJ_DIR := obj
ASSEMBLY := engine
EXTENSION := .so
# Compiler flags
COMPILER_FLAGS := -g -MD -Werror=vla -fdeclspec -fPIC
# -g : Enable debugging info (GDB)
# -MD : Generate dependency files (.d) for header tracking
# -Werror=vla : Treat variable-length arrays as errors (enforces strict C99 compliance)
# This is useful for catching potential issues early.
# -fdeclspec : Allow __declspec(dllexport/dllimport) for symbol visibility
# -fPIC : Position Independent Code (required for shared libraries)
# Include paths
INCLUDE_FLAGS := -Iengine/src -I$(VULKAN_SDK)/include
# -I : Adds include directories for header resolution
# Linker flags
LINKER_FLAGS := -g -shared -lvulkan -lxcb -lX11 -lX11-xcb -lxkbcommon -L$(VULKAN_SDK)/lib -L/usr/X11R6/lib
# -shared : Builds a shared object (.so)
# -lvulkan : Links against Vulkan SDK
# -lxcb : XCB support for windowing
# -lX11 : X11 compatibility layer
# -lX11-xcb : X11/XCB interop
# -lxkbcommon : For keyboard handling
# -L... : Library search paths
# Defines
DEFINES := -D_DEBUG -DKEXPORT
# -D_DEBUG : Enables debug logging and asserts
# -DKEXPORT : Marks engine functions as exported (for shared lib)
# Recursive wildcard function
# Usage: $(call rwildcard,<dir>,<pattern>)
# rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
# Source files
SRC_FILES := $(shell find $(ASSEMBLY) -name *.c) # Get all .c files
# Recursively finds all C source files under 'engine/'
# Directories (for scaffolding)
DIRECTORIES := $(shell find $(ASSEMBLY) -type d)
# Used to create matching obj/ directory structure
# Object files
OBJ_FILES := $(SRC_FILES:%=$(OBJ_DIR)/%.o)
# Compiles each .c file into a .o file in obj/
# Targets
all: log-start scaffold compile link log-finish
# Default target — runs log start time, scaffold, compile, link and log finish time
.PHONY: log-start
log-start: # Logs build start time (EAT)
@echo "===== Build started at $$(TZ=Africa/Nairobi date +'%Y-%m-%d %H:%M:%S.%3N %Z') ====="
.PHONY: log-finish
log-finish: # Logs build finish time (EAT)
@echo "===== Build finished at $$(TZ=Africa/Nairobi date +'%Y-%m-%d %H:%M:%S.%3N %Z') ====="
.PHONY: scaffold
scaffold: # Creates the folder structure needed for compilation
@echo Scaffolding folder structure...
@mkdir -p $(addprefix $(OBJ_DIR)/,$(DIRECTORIES))
@echo Done.
.PHONY: link
link: scaffold $(OBJ_FILES) # Links the engine shared library
@echo Linking $(ASSEMBLY)...
@clang $(OBJ_FILES) -o $(BUILD_DIR)/lib$(ASSEMBLY)$(EXTENSION) $(LINKER_FLAGS)
# clang compiles object files into a shared library
# -shared ensures libengine.so is created
.PHONY: compile
compile: # Compiles all .c files into .o objects
@echo Compiling...
.PHONY: clean
clean: # Cleans up build artifacts
rm -rf $(BUILD_DIR)\$(ASSEMBLY)
rm -rf $(OBJ_DIR)\$(ASSEMBLY)
# Rule to compile .c -> .o
$(OBJ_DIR)/%.c.o: %.c # Compile each .c file into an object
@echo $<...
@clang $< $(COMPILER_FLAGS) -c -o $@ $(DEFINES) $(INCLUDE_FLAGS)
# Compiles individual C files with correct flags, includes, and defines
-include $(OBJ_FILES:.o=.d)
# Include dependency files generated by -MD
# This allows Make to track header dependencies and rebuild as needed