-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (150 loc) · 7.25 KB
/
Copy pathMakefile
File metadata and controls
165 lines (150 loc) · 7.25 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
# Makefile for Microverse - Battery Monitor for macOS
.PHONY: all build build-debug clean install install-debug uninstall run app debug-app benchmark
# Configuration
APP_NAME = Microverse
BUNDLE_ID = com.microverse.app
BUILD_DIR = build
APP_PATH = /Applications/$(APP_NAME).app
# Build settings
SWIFT = swift
all: install
# Build using Swift Package Manager (Release)
build:
@echo "🔨 Building $(APP_NAME) (Release)..."
$(SWIFT) build -c release
# Build using Swift Package Manager (Debug)
build-debug:
@echo "🔨 Building $(APP_NAME) (Debug)..."
$(SWIFT) build -c debug
# Clean build artifacts
clean:
@echo "🧹 Cleaning..."
rm -rf $(BUILD_DIR)
rm -rf .build
rm -rf /tmp/$(APP_NAME).app
# Create app bundle and install to /Applications (Release)
install: build app
@echo "📦 Installing $(APP_NAME) to /Applications..."
@if sudo -n true 2>/dev/null; then \
set -e; \
sudo rm -rf "$(APP_PATH)"; \
sudo cp -R /tmp/$(APP_NAME).app "$(APP_PATH)"; \
echo "✅ Installed to $(APP_PATH)"; \
echo "🚀 Launching $(APP_NAME)..."; \
open "$(APP_PATH)" >/dev/null 2>&1 || echo "⚠️ Launch failed. Open $(APP_PATH) manually."; \
elif [ -t 0 ]; then \
set -e; \
echo "🔐 sudo required to install to /Applications..."; \
sudo rm -rf "$(APP_PATH)"; \
sudo cp -R /tmp/$(APP_NAME).app "$(APP_PATH)"; \
echo "✅ Installed to $(APP_PATH)"; \
echo "🚀 Launching $(APP_NAME)..."; \
open "$(APP_PATH)" >/dev/null 2>&1 || echo "⚠️ Launch failed. Open $(APP_PATH) manually."; \
else \
echo "⚠️ sudo not available (no cached credentials / no tty). Skipping /Applications copy."; \
echo " Run 'sudo -v' first, or manually:"; \
echo " sudo rm -rf \"$(APP_PATH)\" && sudo cp -R /tmp/$(APP_NAME).app \"$(APP_PATH)\""; \
echo "🚀 Launching from /tmp/$(APP_NAME).app..."; \
open -n /tmp/$(APP_NAME).app >/dev/null 2>&1 || echo "⚠️ Launch failed. Open /tmp/$(APP_NAME).app manually."; \
fi
# Create app bundle and install to /Applications (Debug)
install-debug: build-debug debug-app
@echo "📦 Installing $(APP_NAME) (Debug) to /Applications..."
@if sudo -n true 2>/dev/null; then \
set -e; \
sudo rm -rf "$(APP_PATH)"; \
sudo cp -R /tmp/$(APP_NAME).app "$(APP_PATH)"; \
echo "✅ Installed to $(APP_PATH)"; \
echo "🚀 Launching $(APP_NAME)..."; \
open "$(APP_PATH)" >/dev/null 2>&1 || echo "⚠️ Launch failed. Open $(APP_PATH) manually."; \
elif [ -t 0 ]; then \
set -e; \
echo "🔐 sudo required to install to /Applications..."; \
sudo rm -rf "$(APP_PATH)"; \
sudo cp -R /tmp/$(APP_NAME).app "$(APP_PATH)"; \
echo "✅ Installed to $(APP_PATH)"; \
echo "🚀 Launching $(APP_NAME)..."; \
open "$(APP_PATH)" >/dev/null 2>&1 || echo "⚠️ Launch failed. Open $(APP_PATH) manually."; \
else \
echo "⚠️ sudo not available (no cached credentials / no tty). Skipping /Applications copy."; \
echo " Run 'sudo -v' first, or manually:"; \
echo " sudo rm -rf \"$(APP_PATH)\" && sudo cp -R /tmp/$(APP_NAME).app \"$(APP_PATH)\""; \
echo "🚀 Launching from /tmp/$(APP_NAME).app..."; \
open -n /tmp/$(APP_NAME).app >/dev/null 2>&1 || echo "⚠️ Launch failed. Open /tmp/$(APP_NAME).app manually."; \
fi
# Create app bundle structure (Release)
app: build
@echo "📦 Creating app bundle..."
$(eval TEMP_DIR := $(shell mktemp -d))
@mkdir -p $(TEMP_DIR)/$(APP_NAME).app/Contents/{MacOS,Resources,Frameworks}
@cp .build/release/$(APP_NAME) $(TEMP_DIR)/$(APP_NAME).app/Contents/MacOS/
@cp Info.plist $(TEMP_DIR)/$(APP_NAME).app/Contents/
@if [ -f Resources/AppIcon.icns ]; then cp Resources/AppIcon.icns $(TEMP_DIR)/$(APP_NAME).app/Contents/Resources/; fi
@if [ -d .build/arm64-apple-macosx/release/Sparkle.framework ]; then \
cp -R .build/arm64-apple-macosx/release/Sparkle.framework $(TEMP_DIR)/$(APP_NAME).app/Contents/Frameworks/; \
install_name_tool -id "@rpath/Sparkle.framework/Versions/B/Sparkle" $(TEMP_DIR)/$(APP_NAME).app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle 2>/dev/null || true; \
fi
@echo 'APPL????' > $(TEMP_DIR)/$(APP_NAME).app/Contents/PkgInfo
@chmod +x $(TEMP_DIR)/$(APP_NAME).app/Contents/MacOS/$(APP_NAME)
@install_name_tool -add_rpath "@loader_path/../Frameworks" $(TEMP_DIR)/$(APP_NAME).app/Contents/MacOS/$(APP_NAME) 2>/dev/null || true
@rm -rf /tmp/$(APP_NAME).app
@mv $(TEMP_DIR)/$(APP_NAME).app /tmp/
@rmdir $(TEMP_DIR)
@echo "🔏 Ad-hoc code signing /tmp/$(APP_NAME).app (binds Info.plist + stable bundle id)..."
@codesign --force --deep --sign - /tmp/$(APP_NAME).app
@echo "✅ App bundle created at /tmp/$(APP_NAME).app"
# Create app bundle structure (Debug)
debug-app: build-debug
@echo "📦 Creating debug app bundle..."
$(eval TEMP_DIR := $(shell mktemp -d))
@mkdir -p $(TEMP_DIR)/$(APP_NAME).app/Contents/{MacOS,Resources,Frameworks}
@cp .build/debug/$(APP_NAME) $(TEMP_DIR)/$(APP_NAME).app/Contents/MacOS/
@cp Info.plist $(TEMP_DIR)/$(APP_NAME).app/Contents/
@if [ -f Resources/AppIcon.icns ]; then cp Resources/AppIcon.icns $(TEMP_DIR)/$(APP_NAME).app/Contents/Resources/; fi
@if [ -d .build/arm64-apple-macosx/debug/Sparkle.framework ]; then \
cp -R .build/arm64-apple-macosx/debug/Sparkle.framework $(TEMP_DIR)/$(APP_NAME).app/Contents/Frameworks/; \
install_name_tool -id "@rpath/Sparkle.framework/Versions/B/Sparkle" $(TEMP_DIR)/$(APP_NAME).app/Contents/Frameworks/Sparkle.framework/Versions/B/Sparkle 2>/dev/null || true; \
fi
@echo 'APPL????' > $(TEMP_DIR)/$(APP_NAME).app/Contents/PkgInfo
@chmod +x $(TEMP_DIR)/$(APP_NAME).app/Contents/MacOS/$(APP_NAME)
@install_name_tool -add_rpath "@loader_path/../Frameworks" $(TEMP_DIR)/$(APP_NAME).app/Contents/MacOS/$(APP_NAME) 2>/dev/null || true
@rm -rf /tmp/$(APP_NAME).app
@mv $(TEMP_DIR)/$(APP_NAME).app /tmp/
@rmdir $(TEMP_DIR)
@echo "🔏 Ad-hoc code signing /tmp/$(APP_NAME).app (binds Info.plist + stable bundle id)..."
@codesign --force --deep --sign - /tmp/$(APP_NAME).app
@echo "✅ Debug app bundle created at /tmp/$(APP_NAME).app"
# Uninstall app
uninstall:
@echo "🗑 Uninstalling $(APP_NAME)..."
@sudo rm -rf "$(APP_PATH)"
rm -rf "$$HOME/Library/Preferences/$(BUNDLE_ID).plist"
rm -rf "$$HOME/Library/Caches/$(BUNDLE_ID)"
@echo "✅ Uninstalled"
# Run the app directly (for development)
run: build
@echo "🚀 Running $(APP_NAME)..."
.build/release/$(APP_NAME)
# Run CLI performance benchmarks.
# Must use -c release to get accurate timings (debug mode disables
# optimizations and adds runtime checks that skew all measurements).
# See Sources/MicroverseBenchmark/main.swift for what's measured and why.
benchmark:
@echo "⏱ Running benchmarks (release)..."
$(SWIFT) run -c release MicroverseBenchmark
# Show help
help:
@echo "Microverse Makefile"
@echo ""
@echo "Usage:"
@echo " make - Build and install to /Applications (default)"
@echo " make install - Build release and install to /Applications"
@echo " make install-debug - Build debug and install to /Applications"
@echo " make build - Build release version only"
@echo " make build-debug - Build debug version only"
@echo " make clean - Clean all build artifacts"
@echo " make uninstall - Remove app and preferences"
@echo " make run - Build and run directly (development)"
@echo " make benchmark - Run release CLI benchmarks"
@echo ""
@echo "Note: Installation requires administrator privileges"