-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
248 lines (221 loc) · 13.1 KB
/
Copy pathMakefile
File metadata and controls
248 lines (221 loc) · 13.1 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
SHELL := /bin/bash
XPLANE_ROOT := /Users/robertw/X-Plane 12
PLUGIN_DIR := $(XPLANE_ROOT)/Resources/available plugins/xp_sherlock_dataref
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.7.1
SKUNK_DIR := build/skunkcrafts
.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_sherlock_dataref — DataRef Detective for X-Plane 12 (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_sherlock_dataref.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 ""
@echo "Release:"
@echo " skunkcrafts Stage a SkunkCrafts update tree from the install (verify only)"
@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.91.9..."
@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.91.9.zip" -o "$$TMP/imgui.zip"; \
unzip -q "$$TMP/imgui.zip" -d "$$TMP/"; \
SRC="$$TMP/imgui-1.91.9"; \
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.11.3..."
@mkdir -p vendor
@curl -fsSL "https://github.com/nlohmann/json/releases/download/v3.11.3/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_sherlock_dataref ==="
cmake -B build -DCMAKE_BUILD_TYPE=Release -Wno-dev
cmake --build build --parallel
@echo ""
@file build/xp_sherlock_dataref.xpl
@echo "Done. Run 'make install' to deploy."
# ── Test ──────────────────────────────────────────────────────────────────────
test: build
@echo "=== Running xp_sherlock_dataref tests ==="
@./build/xp_sherlock_dataref_tests
# ── Install ───────────────────────────────────────────────────────────────────
install:
@if [ ! -f "build/xp_sherlock_dataref.xpl" ]; then \
echo "Plugin not built yet. Run 'make build' first."; exit 1; \
fi
@echo "=== Installing xp_sherlock_dataref ==="
@mkdir -p "$(PLUGIN_DIR)/mac_x64"
@cp build/xp_sherlock_dataref.xpl "$(PLUGIN_DIR)/mac_x64/"
@xattr -dr com.apple.quarantine "$(PLUGIN_DIR)/mac_x64/xp_sherlock_dataref.xpl" 2>/dev/null || true
@codesign --force --deep --sign - "$(PLUGIN_DIR)/mac_x64/xp_sherlock_dataref.xpl"
@echo "Signed: $(PLUGIN_DIR)/mac_x64/xp_sherlock_dataref.xpl"
@echo "Installed: $(PLUGIN_DIR)/mac_x64/xp_sherlock_dataref.xpl"
@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_SHERLOCK_SANITIZE=ON -DCMAKE_OSX_ARCHITECTURES=arm64 -Wno-dev
@echo "=== Building xp_sherlock_dataref_tests with ASan + UBSan ==="
cmake --build build-sanitize --target xp_sherlock_dataref_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_sherlock_dataref_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 SkunkCrafts tree from the installed plugin and writes the
# updater control files into it. NOTE: 'make install' only deploys mac_x64, so
# locally this produces a mac-only tree — it exists to verify control-file
# generation. The real multi-platform tree is staged in CI from the release job.
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)/"; \
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_sherlock_dataref (release) ==="
cmake -B build -DCMAKE_BUILD_TYPE=Release -DRELEASE=ON -Wno-dev
cmake --build build --parallel
@echo ""
@file build/xp_sherlock_dataref.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."