-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
221 lines (203 loc) · 8.91 KB
/
Makefile
File metadata and controls
221 lines (203 loc) · 8.91 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# MIT License
# Copyright (c) 2024 Lecrapouille <lecrapouille@gmail.com>
#
# Prologot - SWI-Prolog integration for Godot 4
#
# Makefile for building and managing the Prologot GDExtension
# Terminal colors
ECHO := echo -e
CYAN := \033[0;36m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m
# Read Prologot GDExtension version from VERSION file
VERSION := $(shell cat VERSION 2>/dev/null || echo "0.1.1")
# Godot godot-cpp tag or branch (e.g., "4.6", "godot-4.3-stable")
# SConstruct will parse this to extract version and determine if it's a tag or branch
# Note: Use 4.5 for Godot 4.6 until godot-cpp 4.6 is released
GODOT_CPP ?= 4.5
# Build output directory for the GDExtension library
BIN ?= bin
# Detect architecture
UNAME_M := $(shell uname -m)
# Default target
.PHONY: help
help:
@$(ECHO) "$(CYAN)╔════════════════════════════════════════════════════════╗$(NC)"
@$(ECHO) "$(CYAN)║ Prologot GDExtension v$(VERSION) ║$(NC)"
@$(ECHO) "$(CYAN)║ Using godot-cpp: $(GODOT_CPP) ║$(NC)"
@$(ECHO) "$(CYAN)╚════════════════════════════════════════════════════════╝$(NC)"
@$(ECHO) ""
@$(ECHO) "$(GREEN)Prerequisites commands:$(NC)"
@$(ECHO) " $(YELLOW)make install-swi$(NC) - Install SWI-Prolog on the operating system"
@$(ECHO) " $(YELLOW)make check-deps$(NC) - Check dependencies for building"
@$(ECHO) ""
@$(ECHO) "$(GREEN)Main commands:$(NC)"
@$(ECHO) " $(YELLOW)make all$(NC) - Build debug + release"
@$(ECHO) " $(YELLOW)make debug$(NC) - Compile the Prologot in debug mode"
@$(ECHO) " $(YELLOW)make release$(NC) - Compile the Prologot in release mode"
@$(ECHO) ""
@$(ECHO) "$(GREEN)Advanced commands:$(NC)"
@$(ECHO) " $(YELLOW)make tests$(NC) - Run unit tests"
@$(ECHO) " $(YELLOW)make clean$(NC) - Clean compiled files"
@$(ECHO) " $(YELLOW)make format$(NC) - Format C++ sources"
@$(ECHO) ""
@$(ECHO) "$(GREEN)Demo commands:$(NC)"
@$(ECHO) " $(YELLOW)make setup-demos$(NC) - Set up demo and test projects"
@$(ECHO) " $(YELLOW)make run-demo$(NC) - Run demo in Godot"
@$(ECHO) " $(YELLOW)make run-galactic$(NC) - Run galactic_customs game in Godot"
@$(ECHO) ""
@$(ECHO) "$(GREEN)Configuration:$(NC)"
@$(ECHO) " $(YELLOW)GODOT_CPP$(NC) - Godot godot-cpp ref (default: $(GODOT_CPP))"
@$(ECHO) ""
@$(ECHO) "$(GREEN)Examples:"
@$(ECHO) " $(YELLOW)make GODOT_CPP=4.5 all"
@$(ECHO) " $(YELLOW)make GODOT_CPP=4.3.1 debug"
@$(ECHO) " $(YELLOW)make run-galactic"
@$(ECHO) "$(NC)"
# Install SWI-Prolog only
.PHONY: install-swi
install-swi:
@$(ECHO) "$(CYAN)▶ Installing SWI-Prolog...$(NC)"
@if command -v swipl >/dev/null 2>&1 && [ -z "$(FORCE)" ]; then \
$(ECHO) "$(GREEN)✓ SWI-Prolog already installed$(NC)"; \
swipl --version; \
exit 0; \
fi
@UNAME_S=$$(uname -s); \
if [ "$$UNAME_S" = "Linux" ]; then \
if [ -f /etc/debian_version ]; then \
$(ECHO) "$(YELLOW)Installing via apt-get...$(NC)"; \
sudo apt-get install -y swi-prolog swi-prolog-nox; \
elif [ -f /etc/fedora-release ]; then \
$(ECHO) "$(YELLOW)Installing via dnf...$(NC)"; \
sudo dnf install -y pl pl-devel; \
elif [ -f /etc/arch-release ]; then \
$(ECHO) "$(YELLOW)Installing via pacman...$(NC)"; \
sudo pacman -S --noconfirm swi-prolog; \
else \
$(ECHO) "$(YELLOW)Unknown Linux distro, trying apt-get...$(NC)"; \
sudo apt-get install -y swi-prolog swi-prolog-nox || true; \
fi; \
elif [ "$$UNAME_S" = "Darwin" ]; then \
if ! command -v brew >/dev/null 2>&1; then \
$(ECHO) "$(RED)✗ Homebrew required. Install from https://brew.sh$(NC)"; \
exit 1; \
fi; \
$(ECHO) "$(YELLOW)Installing via Homebrew...$(NC)"; \
brew install swi-prolog; \
elif echo "$$UNAME_S" | grep -qE "^(MINGW|MSYS|CYGWIN)"; then \
$(ECHO) "$(YELLOW)Windows: Please install SWI-Prolog manually$(NC)"; \
$(ECHO) "$(YELLOW)Download from: https://www.swi-prolog.org/download/stable$(NC)"; \
$(ECHO) "$(YELLOW)Or use: choco install swi-prolog$(NC)"; \
exit 1; \
else \
$(ECHO) "$(RED)✗ Unsupported system: $$UNAME_S$(NC)"; \
exit 1; \
fi
@if command -v swipl >/dev/null 2>&1; then \
$(ECHO) "$(GREEN)✓ SWI-Prolog installed successfully$(NC)"; \
swipl --version; \
else \
$(ECHO) "$(RED)✗ Installation failed$(NC)"; \
exit 1; \
fi
# Check dependencies
.PHONY: check-deps
check-deps:
@$(ECHO) "$(CYAN)▶ Checking dependencies...$(NC)"
@command -v python3 >/dev/null 2>&1 || { $(ECHO) "$(RED)✗ python3 missing$(NC)"; exit 1; }
@command -v git >/dev/null 2>&1 || { $(ECHO) "$(RED)✗ git missing$(NC)"; exit 1; }
@command -v scons >/dev/null 2>&1 || { $(ECHO) "$(RED)✗ scons missing (pip install scons)$(NC)"; exit 1; }
@command -v swipl >/dev/null 2>&1 || { $(ECHO) "$(RED)✗ swipl missing. Call make install-swi first!$(NC)"; exit 1; }
@command -v pkg-config >/dev/null 2>&1 || { $(ECHO) "$(RED)✗ pkg-config missing$(NC)"; exit 1; }
@pkg-config --exists swipl 2>/dev/null || { $(ECHO) "$(RED)✗ pkg-config cannot find swipl$(NC)"; exit 1; }
@$(ECHO) "$(GREEN)✓ All dependencies present$(NC)"
# Build both debug and release + setup projects
.PHONY: all
all: check-deps debug release setup-demos
@$(ECHO) "$(CYAN)▶ Building release version...$(NC)"
@scons --godot-cpp=$(GODOT_CPP) target=template_release arch=$(UNAME_M)
@$(ECHO) "$(CYAN)▶ Building debug version...$(NC)"
@scons --godot-cpp=$(GODOT_CPP) target=template_debug arch=$(UNAME_M)
@$(MAKE) setup-demos
# Debug build
.PHONY: debug
debug: check-deps
@$(ECHO) "$(CYAN)▶ Building debug version...$(NC)"
@scons --godot-cpp=$(GODOT_CPP) target=template_debug arch=$(UNAME_M)
@$(MAKE) setup-demos
# Release build
.PHONY: release
release: check-deps
@$(ECHO) "$(CYAN)▶ Building release version...$(NC)"
@scons --godot-cpp=$(GODOT_CPP) target=template_release arch=$(UNAME_M)
@$(MAKE) setup-demos
# Clean build artifacts
.PHONY: clean
clean:
@$(ECHO) "$(YELLOW)▶ Cleaning...$(NC)"
@rm -fr $(BIN) .sconsign.dblite src/*.os godot-cpp-* .scons_cache
@for project in demos/showcases demos/galactic_customs tests; do \
rm -rf $$project/$(BIN); \
done
@$(ECHO) "$(GREEN)✓ Clean completed$(NC)"
@$(ECHO) "$(YELLOW)Note: .godot/ directories are preserved for faster project loading$(NC)"
# Set up demo and test projects (creates symbolic links to $(BIN)/ and prologot.gdextension)
.PHONY: setup-demos
setup-demos:
@$(ECHO) "$(CYAN)▶ Setting up demo and test projects...$(NC)"
@if [ ! -d $(BIN) ]; then \
$(ECHO) "$(RED)✗ Error: $(BIN)/ directory not found. Run 'make debug' or 'make release' first$(NC)"; \
exit 1; \
fi
@for project in demos/showcases demos/galactic_customs; do \
rm -rf $$project/$(BIN); \
[ -d $(BIN) ] && ln -sf ../../$(BIN) $$project/$(BIN) || true; \
done
@rm -rf tests/$(BIN); \
[ -d $(BIN) ] && ln -sf ../$(BIN) tests/$(BIN) || true
@$(ECHO) "$(YELLOW)▶ Initializing Godot projects (creating .godot cache)...$(NC)"
@for project in demos/showcases demos/galactic_customs tests; do \
if [ -f $$project/project.godot ] && [ ! -d $$project/.godot ]; then \
$(ECHO) "$(CYAN) Initializing $$project...$(NC)"; \
godot --headless --quit --path $$project 2>&1 | grep -v "^Godot Engine" || true; \
fi; \
done
@$(ECHO) ""
@$(ECHO) "$(GREEN)╔════════════════════════════════════════════════════════╗$(NC)"
@$(ECHO) "$(GREEN)║ ✓ Demo and test projects ready! ║$(NC)"
@$(ECHO) "$(GREEN)╚════════════════════════════════════════════════════════╝$(NC)"
@$(ECHO) ""
@$(ECHO) "$(CYAN)▶ To run the demo:$(NC)"
@$(ECHO) " $(YELLOW)make run-demo$(NC)"
@$(ECHO) ""
@$(ECHO) "$(CYAN)▶ To run galactic_customs:$(NC)"
@$(ECHO) " $(YELLOW)make run-galactic_customs$(NC)"
@$(ECHO) ""
@$(ECHO) "$(CYAN)▶ To run tests:$(NC)"
@$(ECHO) " $(YELLOW)make tests$(NC)"
@$(ECHO) ""
# Run tests
.PHONY: tests
tests: setup-demos
@$(ECHO) "$(CYAN)▶ Running tests...$(NC)"
@$(ECHO) "$(YELLOW)Note: Tests require Godot to be installed$(NC)"
@godot --headless --path tests -s run_tests.gd
# Run demo project
.PHONY: run-demo
run-demo: setup-demos
@$(ECHO) "$(CYAN)▶ Running demo project...$(NC)"
@godot --path demos/showcases
# Run galactic_customs game
.PHONY: run-galactic
run-galactic: setup-demos
@$(ECHO) "$(CYAN)▶ Running galactic_customs game...$(NC)"
@godot --path demos/galactic_customs
# Format C++ sources with clang-format
.PHONY: format
format:
@$(ECHO) "$(CYAN)▶ Formatting C++ sources...$(NC)"
@find src/ -name "*.cpp" -o -name "*.hpp" -o -name "*.h" | xargs clang-format -i
@$(ECHO) "$(GREEN)✓ Formatting completed$(NC)"