-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile.testbed.linux.mak
More file actions
92 lines (73 loc) · 3.06 KB
/
Makefile.testbed.linux.mak
File metadata and controls
92 lines (73 loc) · 3.06 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
# Makefile.testbed.linux.mak
# Purpose: Build the testbed application that uses the Koru engine.
# Output directories
BUILD_DIR := bin
OBJ_DIR := obj
# Binary name and extension
ASSEMBLY := testbed
EXTENSION :=
# Compiler flags
COMPILER_FLAGS := -g -MD -Werror=vla -fdeclspec -fPIC
# -g : Debug symbols for 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 : Allows dllimport/dlexport syntax
# -fPIC : Required for position-independent code (even for executables)
# Include paths
INCLUDE_FLAGS := -Iengine/src -Itestbed\src
# Includes headers from engine and Vulkan SDK
# Linker flags
LINKER_FLAGS := -L./$(BUILD_DIR)/ -lengine -Wl,-rpath,. -lm
# -L... : Looks for libengine.so in bin/
# -lengine : Links with libengine.so
# -Wl,-rpath,. : Tells the binary where to look for shared libraries at runtime
# Defines
DEFINES := -D_DEBUG -DKIMPORT
# -D_DEBUG : Enables debug logging and asserts
# -DKIMPORT : Treats engine functions as imported (from .so)
# Recursive wildcard function (not used yet but available)
# rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
# Source files
SRC_FILES := $(shell find $(ASSEMBLY) -name *.c)
# Finds all C files inside the testbed directory
# Directories (for scaffolding)
DIRECTORIES := $(shell find $(ASSEMBLY) -type d)
# Used to create obj/testbed directory structure
# Object files
OBJ_FILES := $(SRC_FILES:%=$(OBJ_DIR)/%.o)
# Maps each .c file to a corresponding .o 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: # Create folder structure for object files
@echo Scaffolding folder structure...
@mkdir -p $(addprefix $(OBJ_DIR)/,$(DIRECTORIES))
@echo Done.
.PHONY: link
link: scaffold $(OBJ_FILES) # Link the testbed executable
@echo Linking $(ASSEMBLY)...
clang $(OBJ_FILES) -o $(BUILD_DIR)/$(ASSEMBLY)$(EXTENSION) $(LINKER_FLAGS) -lm
# Links testbed main.c with libengine.so and other dependencies
.PHONY: compile
compile: # Compile all .c files into .o
@echo Compiling...
.PHONY: clean
clean: # Clean 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
@echo $<...
@clang $< $(COMPILER_FLAGS) -c -o $@ $(DEFINES) $(INCLUDE_FLAGS)
# Compiles individual C files with debug info and Vulkan includes
-include $(OBJ_FILES:.o=.d)
# Include dependency files generated by -MD
# This allows Make to track header dependencies and rebuild as needed