-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
304 lines (254 loc) · 11.1 KB
/
Makefile
File metadata and controls
304 lines (254 loc) · 11.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# Claude Usage - Makefile
# Cross-platform build targets for Linux, Windows, and macOS
BINARY_NAME=claude-usage
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
# Optimized build flags (stripped, no debug info) - default for production
BUILD_FLAGS=-ldflags "-s -w -X main.Version=$(VERSION)" -trimpath
# Debug build flags (with symbols, for development)
BUILD_FLAGS_DEBUG=-ldflags "-X main.Version=$(VERSION)"
# Output directories
DIST_DIR=dist
INSTALL_DIR=$(HOME)/.local/bin
# Linux paths
DESKTOP_FILE=$(HOME)/.config/autostart/claude-usage.desktop
APPLICATIONS_DIR=$(HOME)/.local/share/applications
ICONS_DIR=$(HOME)/.local/share/icons/hicolor
.PHONY: all build build-fast build-debug clean install uninstall run test lint \
check-upx build-linux build-windows build-macos build-all \
autostart autostart-remove desktop-install desktop-remove \
install-linux install-macos generate-icons \
build-macos-app help
# Default target
all: build
# Check if UPX is installed
check-upx:
@command -v upx >/dev/null 2>&1 || \
(echo "ERROR: UPX not found. Install with: sudo apt install upx-ucl (Linux), brew install upx (macOS), or choco install upx (Windows)" && exit 1)
# Build for current platform (optimized + UPX compressed, ~5MB)
build: check-upx
go build $(BUILD_FLAGS) -o $(BINARY_NAME) ./cmd/claude-usage
upx --best --lzma $(BINARY_NAME)
@echo "Built optimized binary: $(BINARY_NAME) (stripped + UPX compressed)"
# Build stripped but without UPX (faster for quick iteration, ~7.5MB)
build-fast:
go build $(BUILD_FLAGS) -o $(BINARY_NAME) ./cmd/claude-usage
@echo "Built stripped binary: $(BINARY_NAME) (no UPX compression)"
# Build with debug symbols (for development/debugging, ~12MB)
build-debug:
go build $(BUILD_FLAGS_DEBUG) -o $(BINARY_NAME)-debug ./cmd/claude-usage
@echo "Built debug binary: $(BINARY_NAME)-debug (with symbols, no compression)"
# Run the application
run: build
./$(BINARY_NAME)
# Install to ~/.local/bin
install: build
@mkdir -p $(INSTALL_DIR)
cp $(BINARY_NAME) $(INSTALL_DIR)/
@echo "Installed to $(INSTALL_DIR)/$(BINARY_NAME)"
@echo "Make sure $(INSTALL_DIR) is in your PATH"
# Uninstall
uninstall: autostart-remove desktop-remove
rm -f $(INSTALL_DIR)/$(BINARY_NAME)
@echo "Removed $(INSTALL_DIR)/$(BINARY_NAME)"
# Clean build artifacts
clean:
rm -f $(BINARY_NAME)
rm -rf $(DIST_DIR)
# Run tests
test:
go test -v ./...
# Run linter
lint:
golangci-lint run
# ============================================
# Icon Generation
# ============================================
# Generate all icon assets
generate-icons:
go run scripts/generate-icons/main.go
# ============================================
# Cross-platform builds
# ============================================
# Create dist directory
$(DIST_DIR):
mkdir -p $(DIST_DIR)
# Build for Linux (amd64) - optimized + UPX
build-linux-amd64: $(DIST_DIR) check-upx
GOOS=linux GOARCH=amd64 go build $(BUILD_FLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/claude-usage
upx --best --lzma $(DIST_DIR)/$(BINARY_NAME)-linux-amd64
# Build for Linux (arm64) - optimized + UPX
build-linux-arm64: $(DIST_DIR) check-upx
GOOS=linux GOARCH=arm64 go build $(BUILD_FLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/claude-usage
upx --best --lzma $(DIST_DIR)/$(BINARY_NAME)-linux-arm64
# Build for Linux (all architectures)
build-linux: build-linux-amd64 build-linux-arm64
# Build for Windows (amd64) - optimized + UPX
build-windows-amd64: $(DIST_DIR) check-upx
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -ldflags "-s -w -X main.Version=$(VERSION) -H=windowsgui" -trimpath -o $(DIST_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/claude-usage
upx --best --lzma $(DIST_DIR)/$(BINARY_NAME)-windows-amd64.exe
# Build for Windows
build-windows: build-windows-amd64
# Build for macOS (Intel) - stripped only, no UPX (Gatekeeper compatibility)
build-macos-amd64: $(DIST_DIR)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build $(BUILD_FLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/claude-usage
# Build for macOS (Apple Silicon) - stripped only, no UPX (Gatekeeper compatibility)
build-macos-arm64: $(DIST_DIR)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build $(BUILD_FLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/claude-usage
# Build for macOS (all architectures)
build-macos: build-macos-amd64 build-macos-arm64
# Build macOS .app bundle (run on macOS only)
build-macos-app: build-macos
./scripts/build-macos-app.sh $(VERSION)
# Build for all platforms
build-all: build-linux build-windows build-macos
@echo "Built binaries for all platforms in $(DIST_DIR)/"
@ls -la $(DIST_DIR)/
# ============================================
# Linux Desktop Integration
# ============================================
# Install desktop entry (applications menu)
desktop-install: install generate-icons
@mkdir -p $(APPLICATIONS_DIR)
@mkdir -p $(ICONS_DIR)/16x16/apps
@mkdir -p $(ICONS_DIR)/24x24/apps
@mkdir -p $(ICONS_DIR)/32x32/apps
@mkdir -p $(ICONS_DIR)/48x48/apps
@mkdir -p $(ICONS_DIR)/64x64/apps
@mkdir -p $(ICONS_DIR)/128x128/apps
@mkdir -p $(ICONS_DIR)/256x256/apps
@cp assets/linux/claude-usage-16.png $(ICONS_DIR)/16x16/apps/claude-usage.png
@cp assets/linux/claude-usage-24.png $(ICONS_DIR)/24x24/apps/claude-usage.png
@cp assets/linux/claude-usage-32.png $(ICONS_DIR)/32x32/apps/claude-usage.png
@cp assets/linux/claude-usage-48.png $(ICONS_DIR)/48x48/apps/claude-usage.png
@cp assets/linux/claude-usage-64.png $(ICONS_DIR)/64x64/apps/claude-usage.png
@cp assets/linux/claude-usage-128.png $(ICONS_DIR)/128x128/apps/claude-usage.png
@cp assets/linux/claude-usage-256.png $(ICONS_DIR)/256x256/apps/claude-usage.png
@sed "s|Exec=claude-usage|Exec=$(INSTALL_DIR)/$(BINARY_NAME)|" assets/linux/claude-usage.desktop > $(APPLICATIONS_DIR)/claude-usage.desktop
@gtk-update-icon-cache $(ICONS_DIR) 2>/dev/null || true
@update-desktop-database $(APPLICATIONS_DIR) 2>/dev/null || true
@echo "Desktop entry installed to $(APPLICATIONS_DIR)/claude-usage.desktop"
@echo "Icons installed to $(ICONS_DIR)/*/apps/claude-usage.png"
# Remove desktop entry
desktop-remove:
@rm -f $(APPLICATIONS_DIR)/claude-usage.desktop
@rm -f $(ICONS_DIR)/16x16/apps/claude-usage.png
@rm -f $(ICONS_DIR)/24x24/apps/claude-usage.png
@rm -f $(ICONS_DIR)/32x32/apps/claude-usage.png
@rm -f $(ICONS_DIR)/48x48/apps/claude-usage.png
@rm -f $(ICONS_DIR)/64x64/apps/claude-usage.png
@rm -f $(ICONS_DIR)/128x128/apps/claude-usage.png
@rm -f $(ICONS_DIR)/256x256/apps/claude-usage.png
@gtk-update-icon-cache $(ICONS_DIR) 2>/dev/null || true
@update-desktop-database $(APPLICATIONS_DIR) 2>/dev/null || true
@echo "Desktop entry removed"
# Install autostart entry (Linux)
autostart: install generate-icons
@mkdir -p $(HOME)/.config/autostart
@sed "s|Exec=claude-usage|Exec=$(INSTALL_DIR)/$(BINARY_NAME)|" assets/linux/claude-usage.desktop > $(DESKTOP_FILE)
@echo "X-GNOME-Autostart-enabled=true" >> $(DESKTOP_FILE)
@echo "Autostart entry created at $(DESKTOP_FILE)"
# Remove autostart entry
autostart-remove:
@rm -f $(DESKTOP_FILE)
@echo "Removed autostart entry"
# Full Linux install (binary + desktop entry + autostart)
install-linux: desktop-install autostart
@echo ""
@echo "Linux installation complete!"
@echo " - Binary: $(INSTALL_DIR)/$(BINARY_NAME)"
@echo " - Desktop entry: $(APPLICATIONS_DIR)/claude-usage.desktop"
@echo " - Autostart: $(DESKTOP_FILE)"
@echo ""
@echo "You can now find 'Claude Usage' in your applications menu."
# ============================================
# macOS Installation (run on macOS only)
# ============================================
LAUNCHAGENT_DIR=$(HOME)/Library/LaunchAgents
LAUNCHAGENT_PLIST=com.github.utajum.claude-usage.plist
# Install macOS app bundle and launchagent
install-macos: build-macos-app
@echo "Installing Claude Usage.app to /Applications..."
@rm -rf "/Applications/Claude Usage.app"
@cp -r "$(DIST_DIR)/Claude Usage.app" /Applications/
@mkdir -p $(LAUNCHAGENT_DIR)
@cp assets/macos/$(LAUNCHAGENT_PLIST) $(LAUNCHAGENT_DIR)/
@launchctl unload $(LAUNCHAGENT_DIR)/$(LAUNCHAGENT_PLIST) 2>/dev/null || true
@launchctl load $(LAUNCHAGENT_DIR)/$(LAUNCHAGENT_PLIST)
@echo ""
@echo "macOS installation complete!"
@echo " - App: /Applications/Claude Usage.app"
@echo " - Autostart: $(LAUNCHAGENT_DIR)/$(LAUNCHAGENT_PLIST)"
@echo ""
@echo "Claude Usage will start automatically on login."
# Uninstall macOS app
uninstall-macos:
@launchctl unload $(LAUNCHAGENT_DIR)/$(LAUNCHAGENT_PLIST) 2>/dev/null || true
@rm -f $(LAUNCHAGENT_DIR)/$(LAUNCHAGENT_PLIST)
@rm -rf "/Applications/Claude Usage.app"
@echo "macOS uninstallation complete"
# ============================================
# Claude CLI Config Sync
# ============================================
# Extract and update Claude CLI configuration from installed binary
sync-config:
@./scripts/extract-claude-config.sh --verbose
# Check if Claude CLI config is up to date (for CI/pre-commit)
check-config:
@./scripts/extract-claude-config.sh --check
# Show current Claude CLI config values as JSON
show-config:
@./scripts/extract-claude-config.sh --json
# ============================================
# Development helpers
# ============================================
# Show version
version:
@echo $(VERSION)
# Format code
fmt:
go fmt ./...
# Update dependencies
deps:
go mod tidy
go mod download
# Show help
help:
@echo "Claude Usage - Build Targets"
@echo ""
@echo "Development:"
@echo " make build - Build optimized (stripped + UPX, ~5MB)"
@echo " make build-fast - Build stripped only, no UPX (~7.5MB)"
@echo " make build-debug - Build with debug symbols (~12MB)"
@echo " make run - Build and run"
@echo " make test - Run tests"
@echo " make lint - Run linter"
@echo " make fmt - Format code"
@echo " make clean - Remove build artifacts"
@echo " make generate-icons - Generate icon assets"
@echo ""
@echo "Claude CLI Config:"
@echo " make sync-config - Update config from Claude CLI binary"
@echo " make check-config - Check if config is up to date"
@echo " make show-config - Show current config as JSON"
@echo ""
@echo "Installation (Linux):"
@echo " make install - Install binary to ~/.local/bin"
@echo " make install-linux - Full install (binary + desktop + autostart)"
@echo " make desktop-install- Install desktop entry (app menu)"
@echo " make autostart - Enable autostart on login"
@echo " make uninstall - Remove everything"
@echo ""
@echo "Installation (macOS):"
@echo " make install-macos - Install .app bundle + autostart"
@echo " make uninstall-macos- Remove app and autostart"
@echo ""
@echo "Installation (Windows):"
@echo " Run: powershell -File scripts/install-windows.ps1"
@echo " Uninstall: powershell -File scripts/install-windows.ps1 -Uninstall"
@echo ""
@echo "Cross-compilation:"
@echo " make build-linux - Build for Linux (amd64, arm64)"
@echo " make build-windows - Build for Windows (amd64)"
@echo " make build-macos - Build for macOS (Intel, Apple Silicon)"
@echo " make build-macos-app- Build macOS .app bundle"
@echo " make build-all - Build for all platforms"