-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakefile
More file actions
88 lines (67 loc) · 3.44 KB
/
Copy pathmakefile
File metadata and controls
88 lines (67 loc) · 3.44 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
# Makefile for Nimonspoli — supports 'make' (CLI) and 'make gui' (GUI)
CXX := g++
CXXFLAGS := -Wall -Wextra -std=c++17 -I include -I .
SRC_DIR := src
OBJ_DIR := build
BIN_DIR := bin
DATA_DIR := data
CONFIG_DIR := config
# ── Platform detection ────────────────────────────────────────────────────────
UNAME := $(shell uname -s)
ifeq ($(UNAME), Darwin)
# macOS: raylib via Homebrew
RAYLIB_INC := -I/opt/homebrew/include
RAYLIB_LIB := -L/opt/homebrew/lib -lraylib
RAYLIB_FRAMEWORKS := -framework CoreVideo -framework IOKit -framework Cocoa \
-framework GLUT -framework OpenGL
GUI_LDFLAGS := $(RAYLIB_LIB) $(RAYLIB_FRAMEWORKS)
else
# Linux: raylib via system package (libraylib-dev) or pkg-config
RAYLIB_INC := $(shell pkg-config --cflags raylib 2>/dev/null || echo "")
RAYLIB_LIB := $(shell pkg-config --libs raylib 2>/dev/null || echo "-lraylib")
# raylib on Linux needs these additional system libs
GUI_LDFLAGS := $(RAYLIB_LIB) -lGL -lm -lpthread -ldl -lrt -lX11
endif
# ── CLI Build (excludes gui_main.cpp and src/views/gui/) ─────────────────────
CLI_SRCS := $(shell find $(SRC_DIR) -name '*.cpp' \
! -name 'gui_main.cpp' \
! -path '$(SRC_DIR)/views/gui/*')
CLI_OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/cli/%.o, $(CLI_SRCS))
CLI_DEPS := $(CLI_OBJS:.o=.d)
CLI_TARGET := $(BIN_DIR)/game
# ── GUI Build (all sources + gui_main.cpp, excludes main.cpp) ────────────────
GUI_SRCS := $(shell find $(SRC_DIR) -name '*.cpp' \
! -name 'main.cpp')
GUI_OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/gui/%.o, $(GUI_SRCS))
GUI_DEPS := $(GUI_OBJS:.o=.d)
GUI_TARGET := $(BIN_DIR)/game_gui
# ─────────────────────────────────────────────────────────────────────────────
all: directories $(CLI_TARGET)
gui: directories $(GUI_TARGET)
directories:
@mkdir -p $(OBJ_DIR)/cli $(OBJ_DIR)/gui $(BIN_DIR) $(DATA_DIR) $(CONFIG_DIR)
# ── CLI compile ───────────────────────────────────────────────────────────────
$(OBJ_DIR)/cli/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
$(CLI_TARGET): $(CLI_OBJS)
$(CXX) $(CXXFLAGS) $^ -o $@
@echo "CLI build OK → $(CLI_TARGET)"
# ── GUI compile ───────────────────────────────────────────────────────────────
$(OBJ_DIR)/gui/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(RAYLIB_INC) -DGUI_MODE -MMD -MP -c $< -o $@
$(GUI_TARGET): $(GUI_OBJS)
$(CXX) $(CXXFLAGS) $^ $(GUI_LDFLAGS) -o $@
@echo "GUI build OK → $(GUI_TARGET)"
# Include auto-generated header deps (ignored if missing on first build)
-include $(CLI_DEPS)
-include $(GUI_DEPS)
run: all ; ./$(CLI_TARGET)
run-gui: gui ; ./$(GUI_TARGET)
clean:
rm -rf $(OBJ_DIR) $(BIN_DIR)
@echo "Cleaned."
rebuild: clean all
rebuild-gui: clean gui
.PHONY: all gui directories run run-gui clean rebuild rebuild-gui