Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
282 lines (255 loc) · 14.7 KB
/
Copy pathMakefile
File metadata and controls
282 lines (255 loc) · 14.7 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
SHELL := /bin/bash
# Override on machines with a different install path: XPLANE_ROOT="/path/to/X-Plane 12" make install
XPLANE_ROOT ?= /Users/robertw/X-Plane 12
# XPLaunch keeps the plugins in xplaunchData/Plugins and symlinks them into
# Resources/plugins; without it, Resources/plugins is the real thing. Install into
# whichever exists — never into "available plugins", a parking spot X-Plane never reads.
PLUGIN_ROOT := $(shell [ -d "$(XPLANE_ROOT)/xplaunchData/Plugins" ] \
&& echo "$(XPLANE_ROOT)/xplaunchData/Plugins" \
|| echo "$(XPLANE_ROOT)/Resources/plugins")
PLUGIN_DIR := $(PLUGIN_ROOT)/xp_pilot
SKUNK_DIR := build/skunkcrafts
SDK_SENTINEL := sdk/XPLM/XPLMPlugin.h
IMGUI_SENTINEL := vendor/imgui/imgui.h
JSON_SENTINEL := vendor/json.hpp
CATCH2_SENTINEL := vendor/catch2/catch_amalgamated.hpp
CATCH2_VERSION := 3.15.1
.PHONY: help all setup build test install format lint sanitize build-windows skunkcrafts release release-build cleanup-tags cleanup-runs clean distclean
.DEFAULT_GOAL := help
# ── Help ──────────────────────────────────────────────────────────────────────
help:
@echo "xp_pilot — X-Plane 12 plugin (macOS)"
@echo ""
@echo "Usage: make <target>"
@echo ""
@echo "Common:"
@echo " help Show this message (default)"
@echo " setup Download SDK, Dear ImGui, nlohmann/json, Catch2 into sdk/ + vendor/"
@echo " build Configure + compile → build/xp_pilot.xpl"
@echo " test Build and run the Catch2 unit tests"
@echo " install Code-sign and copy the plugin into X-Plane (mac_x64)"
@echo " sanitize Build + run the unit tests under ASan + UBSan"
@echo " clean Remove build/, build-lint/ and build-sanitize/"
@echo " distclean clean + remove sdk/ and vendor/ (everything 'make setup' installed)"
@echo ""
@echo "Code quality:"
@echo " format Run clang-format on src/*.{cpp,hpp}"
@echo " lint Run clang-tidy (uses build-lint/ for compile_commands.json)"
@echo ""
@echo "CI / cross-platform:"
@echo " build-windows Windows x64 build (used by CI)"
@echo " skunkcrafts Stage a SkunkCrafts update tree from the install → build/skunkcrafts/"
@echo ""
@echo "Release:"
@echo " release VERSION=x.y.z Tag + push release (commits VERSION.txt)"
@echo " release-build Local release build (-DRELEASE=ON)"
@echo " cleanup-tags Prune local tags removed on origin"
@echo " cleanup-runs Delete all GitHub Actions runs except the newest per workflow"
all: format build lint test
# ── Setup ─────────────────────────────────────────────────────────────────────
setup: $(SDK_SENTINEL) $(IMGUI_SENTINEL) $(JSON_SENTINEL) $(CATCH2_SENTINEL)
@echo "Setup complete. Run 'make build' to compile."
$(SDK_SENTINEL):
@echo "Downloading X-Plane SDK..."
@set -euo pipefail; \
TMP=$$(mktemp -d); \
trap "rm -rf $$TMP" EXIT; \
curl -fsSL "https://developer.x-plane.com/wp-content/plugins/code-sample-generation/sdk_zip_files/XPSDK430.zip" \
-o "$$TMP/sdk.zip"; \
unzip -q "$$TMP/sdk.zip" -d "$$TMP/sdk_extracted"; \
mkdir -p sdk/XPLM sdk/XPWidgets sdk/Libraries/Win sdk/Libraries/Mac; \
find "$$TMP/sdk_extracted" -path "*/CHeaders/XPLM/*.h" -exec cp {} sdk/XPLM/ \;; \
find "$$TMP/sdk_extracted" -path "*/CHeaders/Widgets/*.h" -exec cp {} sdk/XPWidgets/ \;; \
find "$$TMP/sdk_extracted" -path "*/Libraries/Win/*.lib" -exec cp {} sdk/Libraries/Win/ \;; \
cp -R "$$TMP/sdk_extracted"/*/Libraries/Mac/*.framework sdk/Libraries/Mac/ 2>/dev/null || \
find "$$TMP/sdk_extracted" -name "*.framework" -exec cp -R {} sdk/Libraries/Mac/ \;
@echo "SDK headers installed."
$(IMGUI_SENTINEL):
@echo "Downloading Dear ImGui v1.92.8..."
@set -euo pipefail; \
TMP=$$(mktemp -d); \
trap "rm -rf $$TMP" EXIT; \
mkdir -p vendor/imgui/backends; \
curl -fsSL "https://github.com/ocornut/imgui/archive/refs/tags/v1.92.8.zip" -o "$$TMP/imgui.zip"; \
unzip -q "$$TMP/imgui.zip" -d "$$TMP/"; \
SRC="$$TMP/imgui-1.92.8"; \
cp "$$SRC"/imgui.{h,cpp} vendor/imgui/; \
cp "$$SRC"/imgui_{draw,tables,widgets}.cpp vendor/imgui/; \
cp "$$SRC"/imgui_internal.h "$$SRC"/imconfig.h vendor/imgui/; \
cp "$$SRC"/imstb_textedit.h "$$SRC"/imstb_rectpack.h "$$SRC"/imstb_truetype.h vendor/imgui/ 2>/dev/null || true; \
cp "$$SRC"/backends/imgui_impl_opengl2.{h,cpp} vendor/imgui/backends/
@echo "Dear ImGui installed."
$(JSON_SENTINEL):
@echo "Downloading nlohmann/json v3.12.0..."
@mkdir -p vendor
@curl -fsSL "https://github.com/nlohmann/json/releases/download/v3.12.0/json.hpp" \
-o vendor/json.hpp
@echo "nlohmann/json installed."
$(CATCH2_SENTINEL):
@echo "Downloading Catch2 v$(CATCH2_VERSION) (amalgamated)..."
@set -euo pipefail; \
TMP=$$(mktemp -d); \
trap "rm -rf $$TMP" EXIT; \
mkdir -p vendor/catch2; \
curl -fsSL "https://github.com/catchorg/Catch2/archive/refs/tags/v$(CATCH2_VERSION).tar.gz" \
-o "$$TMP/catch2.tar.gz"; \
tar -xzf "$$TMP/catch2.tar.gz" -C "$$TMP/"; \
cp "$$TMP/Catch2-$(CATCH2_VERSION)/extras/catch_amalgamated.hpp" vendor/catch2/; \
cp "$$TMP/Catch2-$(CATCH2_VERSION)/extras/catch_amalgamated.cpp" vendor/catch2/
@echo "Catch2 installed."
# ── Build ─────────────────────────────────────────────────────────────────────
build: $(SDK_SENTINEL) $(IMGUI_SENTINEL) $(JSON_SENTINEL) $(CATCH2_SENTINEL)
@echo "=== Building xp_pilot ==="
cmake -B build -DCMAKE_BUILD_TYPE=Release -Wno-dev
cmake --build build --parallel
@echo ""
@file build/xp_pilot.xpl
@echo "Done. Run 'make install' to deploy."
# ── Test ──────────────────────────────────────────────────────────────────────
test: build
@echo "=== Running xp_pilot tests ==="
@./build/xp_pilot_tests
# ── Install ───────────────────────────────────────────────────────────────────
install:
@if [ ! -f "build/xp_pilot.xpl" ]; then \
echo "Plugin not built yet. Run 'make build' first."; exit 1; \
fi
@echo "=== Installing xp_pilot ==="
@mkdir -p "$(PLUGIN_DIR)/mac_x64"
@cp build/xp_pilot.xpl "$(PLUGIN_DIR)/mac_x64/"
@xattr -dr com.apple.quarantine "$(PLUGIN_DIR)/mac_x64/xp_pilot.xpl" 2>/dev/null || true
@codesign --force --deep --sign - "$(PLUGIN_DIR)/mac_x64/xp_pilot.xpl"
@echo "Signed: $(PLUGIN_DIR)/mac_x64/xp_pilot.xpl"
@echo "Installed: $(PLUGIN_DIR)/mac_x64/xp_pilot.xpl"
@# Bundled, read-only config: it ships with the plugin, so an update has to reach it.
@# User data lives under Output/x_pilot_reports and is never touched here.
@mkdir -p "$(PLUGIN_DIR)/data"
@cp data/flight_logger_profiles.json "$(PLUGIN_DIR)/data/"
@echo "Installed: $(PLUGIN_DIR)/data/flight_logger_profiles.json"
@# Generated map data, refreshed the same way.
@cp data/coastlines.dat data/cities.dat "$(PLUGIN_DIR)/data/"
@echo "Installed: $(PLUGIN_DIR)/data/coastlines.dat + cities.dat"
@set -euo pipefail; \
OLD_DATA="$(XPLANE_ROOT)/Resources/available plugins/FlyWithLua/Scripts/flight_logger_data"; \
MARKER="$(PLUGIN_DIR)/data/.migrated_from_flywothlua"; \
if [ -d "$$OLD_DATA/flights" ] && [ ! -f "$$MARKER" ]; then \
echo "Migrating FlyWithLua flight logs..."; \
mkdir -p "$(PLUGIN_DIR)/data/flights" "$(PLUGIN_DIR)/data/reports"; \
count=0; \
for f in "$$OLD_DATA/flights/"*.json; do \
[ -f "$$f" ] || continue; \
fname=$$(basename "$$f"); \
if [ ! -f "$(PLUGIN_DIR)/data/flights/$$fname" ]; then \
cp "$$f" "$(PLUGIN_DIR)/data/flights/"; \
count=$$((count + 1)); \
fi; \
done; \
touch "$$MARKER"; \
echo "Migrated $$count flight JSON files."; \
fi
@echo ""
@echo "Plugin installed. Activate via XLauncher, then restart X-Plane."
# ── Lint ──────────────────────────────────────────────────────────────────────
format:
@command -v clang-format >/dev/null 2>&1 || { \
echo "clang-format not found. Install with: brew install llvm"; \
echo "Then add to PATH: export PATH=\"\$$(brew --prefix llvm)/bin:\$$PATH\""; \
exit 1; }
clang-format -i src/*.cpp src/*.hpp
lint: $(SDK_SENTINEL) $(IMGUI_SENTINEL) $(JSON_SENTINEL) $(CATCH2_SENTINEL)
@command -v clang-tidy >/dev/null 2>&1 || { \
echo "clang-tidy not found. Install with: brew install llvm"; \
echo "Then add to PATH: export PATH=\"\$$(brew --prefix llvm)/bin:\$$PATH\""; \
exit 1; }
cmake -B build-lint -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_OSX_ARCHITECTURES=arm64 -Wno-dev
clang-tidy -p build-lint --extra-arg="-isysroot" --extra-arg="$(shell xcrun --show-sdk-path)" src/*.cpp
# ── Sanitize ──────────────────────────────────────────────────────────────────
# Builds + runs only the SDK-free Catch2 tests under AddressSanitizer +
# UndefinedBehaviorSanitizer. The .xpl plugin is intentionally NOT instrumented
# — ASan inside the X-Plane process is fragile on macOS ARM64 (dyld + code
# signing). For leak / heap analysis of the running plugin, attach
# Instruments.app to the X-Plane process.
sanitize: $(SDK_SENTINEL) $(IMGUI_SENTINEL) $(JSON_SENTINEL) $(CATCH2_SENTINEL)
@echo "=== Configuring sanitizer build (ASan + UBSan) ==="
cmake -B build-sanitize -DCMAKE_BUILD_TYPE=Debug -DXP_PILOT_SANITIZE=ON -DCMAKE_OSX_ARCHITECTURES=arm64 -Wno-dev
@echo "=== Building xp_pilot_tests with ASan + UBSan ==="
cmake --build build-sanitize --target xp_pilot_tests --parallel
@echo ""
@echo "=== Running unit tests under ASan + UBSan ==="
@ASAN_OPTIONS=detect_leaks=0:abort_on_error=1:print_stacktrace=1 \
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
./build-sanitize/xp_pilot_tests
@echo ""
@echo "Sanitizer run clean."
# ── Build (Windows CI) ────────────────────────────────────────────────────────
build-windows: $(SDK_SENTINEL) $(IMGUI_SENTINEL) $(JSON_SENTINEL) $(CATCH2_SENTINEL)
cmake -B build -A x64
cmake --build build --config Release
# ── SkunkCrafts update tree ───────────────────────────────────────────────────
# Stages a publishable tree from the installed plugin and writes the SkunkCrafts
# control files into it. Local installs only carry the mac_x64 binary — the full
# three-platform tree is produced by the release workflow. The live install at
# $(PLUGIN_DIR) is left untouched.
skunkcrafts:
@if [ ! -d "$(PLUGIN_DIR)" ]; then \
echo "Plugin not installed at '$(PLUGIN_DIR)'. Run 'make install' first."; exit 1; \
fi
@VER="$(VERSION)"; \
if [ -z "$$VER" ] && [ -f VERSION.txt ]; then VER="$$(cat VERSION.txt)"; fi; \
if [ -z "$$VER" ]; then echo "No version. Set VERSION=x.y.z or VERSION.txt."; exit 1; fi; \
echo "=== Staging SkunkCrafts release tree ($$VER) ==="; \
rm -rf "$(SKUNK_DIR)"; mkdir -p "$(SKUNK_DIR)"; \
rsync -a \
--exclude '.DS_Store' \
--exclude 'skunkcrafts_updater*' \
"$(PLUGIN_DIR)/" "$(SKUNK_DIR)/"; \
cp packaging/README.md packaging/THIRD_PARTY_LICENSES.md RELEASE.md LICENSE "$(SKUNK_DIR)/"; \
python3 tools/skunkcrafts/generate.py --tree "$(SKUNK_DIR)" --version "$$VER"; \
echo "Staged release tree at $(SKUNK_DIR)/ (version $$VER)."
# ── Release ───────────────────────────────────────────────────────────────────
release:
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make release VERSION=1.2.1"; exit 1; \
fi
@if ! git diff --quiet || ! git diff --cached --quiet; then \
echo "Uncommitted changes present. Commit or stash first."; exit 1; \
fi
@if [ -n "$$(git ls-files --others --exclude-standard)" ]; then \
echo "Untracked files present. Commit or clean up first."; exit 1; \
fi
@echo "$(VERSION)" > VERSION.txt
@git add VERSION.txt
@git commit -m "release $(VERSION)"
@git push origin main
@git tag -a "v$(VERSION)" -m "Release $(VERSION)"
@git push origin "v$(VERSION)"
@echo "Released v$(VERSION) and pushed tag to origin."
release-build: $(SDK_SENTINEL) $(IMGUI_SENTINEL) $(JSON_SENTINEL) $(CATCH2_SENTINEL)
@echo "=== Building xp_pilot (release) ==="
cmake -B build -DCMAKE_BUILD_TYPE=Release -DRELEASE=ON -Wno-dev
cmake --build build --parallel
@echo ""
@file build/xp_pilot.xpl
@echo "Done. Release build with version from VERSION.txt."
# ── Cleanup Tags ──────────────────────────────────────────────────────────────
cleanup-tags:
git fetch --prune --prune-tags origin
@echo "Local tags synced with remote."
# ── Cleanup GitHub Actions runs ───────────────────────────────────────────────
cleanup-runs:
@command -v gh >/dev/null 2>&1 || { \
echo "gh not found. Install with: brew install gh"; exit 1; }
@echo "Deleting GitHub Actions runs (keeping newest per workflow)..."
@for wf in $$(gh workflow list --json id -q '.[].id'); do \
gh run list --workflow=$$wf --limit 1000 --json databaseId -q '.[1:] | .[].databaseId' \
| xargs -I {} gh run delete {}; \
done
@echo "Cleanup complete."
# ── Clean ─────────────────────────────────────────────────────────────────────
clean:
rm -rf build build-lint build-sanitize
# ── Distclean ─────────────────────────────────────────────────────────────────
# Remove everything 'make setup' downloaded so a full re-bootstrap is forced.
distclean: clean
rm -rf sdk/ vendor/
@echo "Removed sdk/ and vendor/. Run 'make setup' to re-download dependencies."