File size: 2,109 Bytes
96cca27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# RRT-GPU Rotating Wireframe Box Demo
# =====================================
# Targets:
#   make          - build everything (shaders + demo)
#   make shaders  - compile GLSL shaders to SPIR-V
#   make demo     - compile the C demo
#   make run      - build and run
#   make clean    - remove build artifacts
#   make validate - run with Vulkan validation layers

CC       = gcc
CFLAGS   = -Wall -Wextra -Wpedantic -O2 -std=c11
LDFLAGS  = $(shell pkg-config --libs sdl2 vulkan) -lm
INCLUDES = $(shell pkg-config --cflags sdl2 vulkan)

GLSLANG  = glslangValidator
SHADER_DIR = shaders

VERT_GLSL = $(SHADER_DIR)/vert.glsl
FRAG_GLSL = $(SHADER_DIR)/frag.glsl
VERT_SPV  = $(SHADER_DIR)/vert.spv
FRAG_SPV  = $(SHADER_DIR)/frag.spv

SRC       = rrt_gpu_demo.c
TARGET    = rrt_gpu_demo

# Default target
all: shaders demo

# Compile GLSL shaders to SPIR-V
shaders: $(VERT_SPV) $(FRAG_SPV)

$(VERT_SPV): $(VERT_GLSL)
	@mkdir -p $(SHADER_DIR)
	$(GLSLANG) -V -S vert $< -o $@

$(FRAG_SPV): $(FRAG_GLSL)
	@mkdir -p $(SHADER_DIR)
	$(GLSLANG) -V -S frag $< -o $@

# Compile C demo
demo: $(SRC) $(VERT_SPV) $(FRAG_SPV)
	$(CC) $(CFLAGS) $(INCLUDES) -o $(TARGET) $(SRC) $(LDFLAGS)

# Build and run
run: all
	./$(TARGET)

# Run with Vulkan validation layers enabled
validate: all
	VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ./$(TARGET)

# Clean build artifacts
clean:
	rm -f $(TARGET)
	rm -f $(VERT_SPV) $(FRAG_SPV)

# Check dependencies
check-deps:
	@echo "Checking dependencies..."
	@which $(CC) > /dev/null || (echo "ERROR: gcc not found" && exit 1)
	@which $(GLSLANG) > /dev/null || (echo "ERROR: glslangValidator not found (install vulkan-sdk)" && exit 1)
	@pkg-config --exists sdl2 || (echo "ERROR: SDL2 not found" && exit 1)
	@pkg-config --exists vulkan || (echo "ERROR: Vulkan not found" && exit 1)
	@echo "All dependencies found."

# Print build info
info:
	@echo "Compiler:  $(CC)"
	@echo "CFLAGS:    $(CFLAGS)"
	@echo "LDFLAGS:   $(LDFLAGS)"
	@echo "Includes:  $(INCLUDES)"
	@echo "Shaders:   $(VERT_SPV) $(FRAG_SPV)"
	@echo "Target:    $(TARGET)"

.PHONY: all shaders demo run validate clean check-deps info