-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
68 lines (50 loc) · 1.63 KB
/
Makefile
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
# Load environment variables from .env
include .env
# Target executable name
TARGET_EXEC := vulkanGameEngine
# Build, source, and shader directories
BUILD_DIR := ./build
SRC_DIRS := ./src
SHADER_DIR := ./shaders
# Find all C and C++ source files
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
# Generate object file names
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
# Generate dependency file names
DEPS := $(OBJS:.o=.d)
# Find all shader files
SHADERS := $(shell find $(SHADER_DIR) -name '*.vert' -or -name '*.frag')
# Generate SPIR-V file names
SPVS := $(SHADERS:%=$(BUILD_DIR)/%.spv)
# Include directories
INC_DIRS := $(shell find $(SRC_DIRS) -type d) external/
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# Compiler flags
CXXFLAGS := -ggdb -std=c++20 -pedantic -Wall -Wextra -Werror
CPPFLAGS := $(INC_FLAGS) -MMD -MP
# Linker flags (including GLFW, Vulkan, and other libraries)
LDFLAGS := -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
# Build the final executable
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) $(SPVS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
# Build rule for C source files
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# Build rule for C++ source files
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# Compiles shader files into SPIR-V binaries
$(BUILD_DIR)/%.spv: %
mkdir -p $(dir $@)
${GLSLC} $< -o $@
.PHONY: test clean
# Runs the compiled executable
test: $(BUILD_DIR)/$(TARGET_EXEC)
@echo "Running $(TARGET_EXEC)..."
$(BUILD_DIR)/$(TARGET_EXEC)
clean:
rm -r $(BUILD_DIR)
# Include dependency files
-include $(DEPS)