-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
450 lines (354 loc) · 14.9 KB
/
Makefile
File metadata and controls
450 lines (354 loc) · 14.9 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# MultiGit Makefile
# Production-ready multi-remote Git synchronization tool
# https://github.com/TIVerse/multigit
.PHONY: help all build release install uninstall clean test check fmt lint doc examples coverage bench run dev
# Variables
BINARY_NAME := multigit
BINARY_ALIAS := mg
CARGO := cargo
TARGET_DIR := target
BUILD_TYPE := release
RUST_LOG ?= info
# Detect OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS := linux
INSTALL_PATH := /usr/local/bin
EXT :=
endif
ifeq ($(UNAME_S),Darwin)
OS := macos
INSTALL_PATH := /usr/local/bin
EXT :=
endif
ifeq ($(OS),Windows_NT)
OS := windows
INSTALL_PATH := $(USERPROFILE)\.cargo\bin
EXT := .exe
else
ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
OS := windows
INSTALL_PATH := $(HOME)/.cargo/bin
EXT := .exe
endif
endif
# Default target
.DEFAULT_GOAL := help
##@ General
help: ## Display this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
all: clean fmt lint test build ## Run all checks and build
##@ Building
build: ## Build debug binary
@echo "🔨 Building debug binary..."
@$(CARGO) build --verbose
release: ## Build optimized release binary
@echo "🚀 Building optimized release binary..."
@$(CARGO) build --release --verbose --bin $(BINARY_NAME)
@$(CARGO) build --release --verbose --bin $(BINARY_ALIAS)
@echo "✅ Binaries built:"
@echo " $(TARGET_DIR)/release/$(BINARY_NAME)$(EXT)"
@echo " $(TARGET_DIR)/release/$(BINARY_ALIAS)$(EXT)"
build-all-targets: ## Build for all platforms (requires cross-compilation tools)
@echo "🌍 Building for all platforms..."
@echo "⚠️ Note: Cross-compilation requires additional tools and linkers"
@echo ""
@echo "Building Linux x86_64 (GNU)..."
@$(CARGO) build --release --target x86_64-unknown-linux-gnu || true
@echo ""
@echo "Building Linux x86_64 (MUSL - static)..."
@echo "Note: Requires musl-tools: sudo apt install musl-tools"
@$(CARGO) build --release --target x86_64-unknown-linux-musl || echo "⚠️ MUSL build failed (install musl-tools or skip)"
@echo ""
@echo "Building macOS x86_64..."
@echo "Note: Requires macOS SDK and linker (osxcross on Linux)"
@$(CARGO) build --release --target x86_64-apple-darwin || echo "⚠️ macOS x86_64 build skipped (requires macOS or osxcross)"
@echo ""
@echo "Building macOS ARM64 (Apple Silicon)..."
@$(CARGO) build --release --target aarch64-apple-darwin || echo "⚠️ macOS ARM64 build skipped (requires macOS or osxcross)"
@echo ""
@echo "Building Windows x86_64..."
@echo "Note: Requires MinGW-w64 toolchain"
@$(CARGO) build --release --target x86_64-pc-windows-msvc || echo "⚠️ Windows build skipped (requires MinGW or Wine)"
@echo ""
@echo "✅ Multi-platform build completed (some targets may have been skipped)"
build-current: ## Build for current platform only
@echo "🔨 Building for current platform..."
@$(CARGO) build --release
build-linux: ## Build Linux targets (GNU and MUSL)
@echo "🐧 Building Linux targets..."
@echo "Building Linux x86_64 (GNU)..."
@$(CARGO) build --release --target x86_64-unknown-linux-gnu
@echo "Building Linux x86_64 (MUSL - requires musl-tools)..."
@$(CARGO) build --release --target x86_64-unknown-linux-musl || echo "⚠️ Install musl-tools: sudo apt install musl-tools"
build-linux-musl: ## Build static Linux binary with MUSL
@echo "🐧 Building static Linux binary (MUSL)..."
@echo "Checking for musl-tools..."
@which musl-gcc > /dev/null 2>&1 || (echo "❌ musl-tools not found. Install with: sudo apt install musl-tools" && exit 1)
@$(CARGO) build --release --target x86_64-unknown-linux-musl
@echo "✅ Static binary: target/x86_64-unknown-linux-musl/release/$(BINARY_NAME)"
dist: ## Create distribution packages for all platforms
@echo "📦 Creating distribution packages..."
@bash scripts/build-release.sh
check: ## Check code without building
@echo "🔍 Checking code..."
@$(CARGO) check --all-targets --all-features
##@ Testing
test: ## Run all tests
@echo "🧪 Running all tests..."
@$(CARGO) test --verbose
test-unit: ## Run unit tests only
@echo "🧪 Running unit tests..."
@$(CARGO) test --lib --verbose
test-integration: ## Run integration tests only
@echo "🧪 Running integration tests..."
@$(CARGO) test --test test_runner --verbose
test-doc: ## Run documentation tests
@echo "📚 Running doc tests..."
@$(CARGO) test --doc --verbose
test-nocapture: ## Run tests with output
@echo "🧪 Running tests with output..."
@$(CARGO) test --verbose -- --nocapture
test-watch: ## Run tests in watch mode (requires cargo-watch)
@echo "👀 Watching tests..."
@$(CARGO) watch -x test
##@ Code Quality
fmt: ## Format code with rustfmt
@echo "🎨 Formatting code..."
@$(CARGO) fmt --all
fmt-check: ## Check code formatting
@echo "🔍 Checking code formatting..."
@$(CARGO) fmt --all -- --check
lint: ## Run clippy linter
@echo "🔎 Running clippy..."
@$(CARGO) clippy --all-targets --all-features -- -D warnings
lint-fix: ## Fix clippy warnings automatically
@echo "🔧 Fixing clippy warnings..."
@$(CARGO) clippy --fix --allow-dirty --allow-staged
audit: ## Check for security vulnerabilities
@echo "🔒 Auditing dependencies..."
@$(CARGO) audit
outdated: ## Check for outdated dependencies
@echo "📦 Checking outdated dependencies..."
@$(CARGO) outdated
##@ Documentation
doc: ## Generate documentation
@echo "📖 Generating documentation..."
@$(CARGO) doc --no-deps --all-features
doc-open: ## Generate and open documentation
@echo "📖 Generating and opening documentation..."
@$(CARGO) doc --no-deps --all-features --open
doc-private: ## Generate documentation including private items
@echo "📖 Generating full documentation..."
@$(CARGO) doc --no-deps --all-features --document-private-items
##@ Examples
examples: ## Run all examples
@echo "🎯 Running examples..."
@$(CARGO) run --example basic_usage
@$(CARGO) run --example scheduler_example
@$(CARGO) run --example ui_formatting
example-basic: ## Run basic usage example
@echo "🎯 Running basic usage example..."
@$(CARGO) run --example basic_usage
example-scheduler: ## Run scheduler example
@echo "🎯 Running scheduler example..."
@$(CARGO) run --example scheduler_example
example-ui: ## Run UI formatting example
@echo "🎯 Running UI formatting example..."
@$(CARGO) run --example ui_formatting
##@ Coverage
coverage: ## Generate code coverage report
@echo "📊 Generating coverage report..."
@$(CARGO) tarpaulin --out Html --output-dir coverage --verbose
coverage-xml: ## Generate XML coverage report
@echo "📊 Generating XML coverage report..."
@$(CARGO) tarpaulin --out Xml --output-dir coverage --verbose
coverage-lcov: ## Generate LCOV coverage report
@echo "📊 Generating LCOV coverage report..."
@$(CARGO) tarpaulin --out Lcov --output-dir coverage --verbose
coverage-open: ## Generate and open coverage report
@echo "📊 Generating and opening coverage report..."
@$(CARGO) tarpaulin --out Html --output-dir coverage --verbose
@open coverage/index.html || xdg-open coverage/index.html 2>/dev/null
##@ Installation
install: release ## Install binaries to system (Linux/macOS: /usr/local/bin, Windows: cargo bin)
@echo "📦 Installing $(BINARY_NAME) and $(BINARY_ALIAS) for $(OS)..."
ifeq ($(OS),windows)
@echo "Installing to $(INSTALL_PATH)..."
@copy /Y $(TARGET_DIR)\release\$(BINARY_NAME).exe $(INSTALL_PATH)\$(BINARY_NAME).exe
@copy /Y $(TARGET_DIR)\release\$(BINARY_ALIAS).exe $(INSTALL_PATH)\$(BINARY_ALIAS).exe
@echo "✅ Installed both binaries to $(INSTALL_PATH)"
else
@echo "Installing to $(INSTALL_PATH)..."
@sudo install -Dm755 $(TARGET_DIR)/release/$(BINARY_NAME) $(INSTALL_PATH)/$(BINARY_NAME)
@sudo install -Dm755 $(TARGET_DIR)/release/$(BINARY_ALIAS) $(INSTALL_PATH)/$(BINARY_ALIAS)
@echo "✅ Installed both binaries to $(INSTALL_PATH)"
endif
@echo "💡 Run '$(BINARY_NAME) --version' or '$(BINARY_ALIAS) --version' to verify"
install-user: release ## Install binaries to user directory (no sudo required)
@echo "📦 Installing $(BINARY_NAME) and $(BINARY_ALIAS) to user directory..."
ifeq ($(OS),windows)
@echo "Installing to $(INSTALL_PATH)..."
@copy /Y $(TARGET_DIR)\release\$(BINARY_NAME).exe $(INSTALL_PATH)\$(BINARY_NAME).exe
@copy /Y $(TARGET_DIR)\release\$(BINARY_ALIAS).exe $(INSTALL_PATH)\$(BINARY_ALIAS).exe
else
@mkdir -p ~/.local/bin
@install -m755 $(TARGET_DIR)/release/$(BINARY_NAME) ~/.local/bin/$(BINARY_NAME)
@install -m755 $(TARGET_DIR)/release/$(BINARY_ALIAS) ~/.local/bin/$(BINARY_ALIAS)
@echo "✅ Installed both binaries to ~/.local/bin"
endif
@echo "💡 Make sure your user bin directory is in PATH"
install-macos: release ## Install binaries on macOS with proper permissions
@echo "🍎 Installing for macOS..."
@sudo install -m755 $(TARGET_DIR)/release/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@sudo install -m755 $(TARGET_DIR)/release/$(BINARY_ALIAS) /usr/local/bin/$(BINARY_ALIAS)
@echo "✅ Installed to /usr/local/bin"
@which $(BINARY_NAME)
@which $(BINARY_ALIAS)
install-linux: release ## Install binaries on Linux with proper permissions
@echo "🐧 Installing for Linux..."
@sudo install -Dm755 $(TARGET_DIR)/release/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@sudo install -Dm755 $(TARGET_DIR)/release/$(BINARY_ALIAS) /usr/local/bin/$(BINARY_ALIAS)
@echo "✅ Installed to /usr/local/bin"
@which $(BINARY_NAME)
@which $(BINARY_ALIAS)
install-windows: release ## Install binaries on Windows
@echo "🪟 Installing for Windows..."
@bash scripts/install-windows.sh
uninstall: ## Uninstall binaries from system
@echo "🗑️ Uninstalling $(BINARY_NAME) and $(BINARY_ALIAS)..."
ifeq ($(OS),windows)
@del /F $(INSTALL_PATH)\$(BINARY_NAME).exe
@del /F $(INSTALL_PATH)\$(BINARY_ALIAS).exe
else
@sudo rm -f $(INSTALL_PATH)/$(BINARY_NAME)
@sudo rm -f $(INSTALL_PATH)/$(BINARY_ALIAS)
endif
@echo "✅ Uninstalled both binaries"
uninstall-user: ## Uninstall binaries from user directory
@echo "🗑️ Uninstalling from user directory..."
ifeq ($(OS),windows)
@del /F $(INSTALL_PATH)\$(BINARY_NAME).exe
@del /F $(INSTALL_PATH)\$(BINARY_ALIAS).exe
else
@rm -f ~/.local/bin/$(BINARY_NAME)
@rm -f ~/.local/bin/$(BINARY_ALIAS)
endif
@echo "✅ Uninstalled both binaries"
##@ Development
dev: ## Run development binary with debug logging
@echo "🚧 Running development build..."
@RUST_LOG=debug $(CARGO) run -- --help
run: ## Run release binary
@echo "▶️ Running $(BINARY_NAME)..."
@$(CARGO) run --release
run-help: ## Show help message
@$(CARGO) run --release -- --help
run-version: ## Show version
@$(CARGO) run --release -- --version
watch: ## Watch for changes and rebuild
@echo "👀 Watching for changes..."
@$(CARGO) watch -x "build --all-features"
##@ Benchmarking
bench: ## Run benchmarks
@echo "⚡ Running benchmarks..."
@$(CARGO) bench
bench-save: ## Run benchmarks and save baseline
@echo "⚡ Running benchmarks and saving baseline..."
@$(CARGO) bench -- --save-baseline
##@ Release
pre-release: clean fmt lint test doc ## Run all pre-release checks
@echo "✅ Pre-release checks completed successfully!"
@echo "📦 Ready to create release build"
release-build: pre-release release ## Build release with all checks
@echo "🎉 Release build completed!"
release-tag: ## Create and push a new version tag
@echo "🏷️ Creating release tag..."
@read -p "Enter version (e.g., v1.0.0): " version; \
git tag -a $$version -m "Release $$version"; \
git push origin $$version
publish-dry: ## Dry run cargo publish (not used - multigit name taken on crates.io)
@echo "⚠️ Note: 'multigit' name is already taken on crates.io"
@echo "🚀 Performing dry run publish (for testing only)..."
@$(CARGO) publish --dry-run --allow-dirty
# Note: multigit name is taken on crates.io, so we don't publish there
# Releases are distributed via GitHub Releases instead
# publish: ## Publish to crates.io
# @echo "🚀 Publishing to crates.io..."
# @$(CARGO) publish
##@ Cleaning
clean: ## Remove build artifacts
@echo "🧹 Cleaning build artifacts..."
@$(CARGO) clean
@rm -rf coverage/
clean-all: clean ## Remove all generated files including locks
@echo "🧹 Deep cleaning..."
@rm -f Cargo.lock
clean-doc: ## Remove generated documentation
@echo "🧹 Cleaning documentation..."
@rm -rf $(TARGET_DIR)/doc
##@ Docker (Optional)
docker-build: ## Build Docker image
@echo "🐳 Building Docker image..."
@docker build -t $(BINARY_NAME):latest .
docker-run: ## Run in Docker container
@echo "🐳 Running in Docker..."
@docker run -it --rm $(BINARY_NAME):latest
##@ Maintenance
update: ## Update dependencies
@echo "📦 Updating dependencies..."
@$(CARGO) update
tree: ## Show dependency tree
@echo "🌳 Showing dependency tree..."
@$(CARGO) tree
bloat: ## Analyze binary size
@echo "📏 Analyzing binary size..."
@$(CARGO) bloat --release
verify: ## Verify project integrity
@echo "✅ Verifying project..."
@$(CARGO) verify-project
fix: ## Auto-fix code issues
@echo "🔧 Auto-fixing code issues..."
@$(CARGO) fix --allow-dirty --allow-staged
##@ CI/CD Simulation
ci-test: ## Simulate CI test workflow
@echo "🤖 Simulating CI test workflow..."
@$(MAKE) fmt-check
@$(MAKE) lint
@$(MAKE) build
@$(MAKE) test
@$(MAKE) test-doc
@echo "✅ CI test simulation passed!"
ci-full: clean ci-test release ## Full CI workflow simulation
@echo "✅ Full CI simulation completed!"
##@ Information
info: ## Show project information
@echo "📦 Project Information"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@echo "Name: $(BINARY_NAME)"
@echo "Version: $$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2)"
@echo "Rust: $$(rustc --version)"
@echo "Cargo: $$(cargo --version)"
@echo "Target Dir: $(TARGET_DIR)"
@echo "Install Dir: $(INSTALL_PATH)"
@echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
deps: ## Show direct dependencies
@echo "📦 Direct Dependencies:"
@$(CARGO) metadata --format-version 1 --no-deps | jq -r '.packages[0].dependencies[] | " - \(.name) \(.req)"'
lines: ## Count lines of code
@echo "📊 Lines of Code:"
@find src -name "*.rs" | xargs wc -l | tail -1 | awk '{print " Source: " $$1 " lines"}'
@find tests -name "*.rs" | xargs wc -l | tail -1 | awk '{print " Tests: " $$1 " lines"}'
features: ## List available features
@echo "🎯 Available Features:"
@grep '\[features\]' Cargo.toml -A 20 | grep -E '^\w+\s*=' | sed 's/=.*//' | sed 's/^/ - /'
##@ Quick Commands
q: fmt lint test ## Quick check: format, lint, and test
@echo "✅ Quick checks passed!"
qq: fmt-check lint test ## Quicker check: verify format, lint, and test
@echo "✅ Quicker checks passed!"
b: build ## Quick alias for build
r: run ## Quick alias for run
t: test ## Quick alias for test
c: clean ## Quick alias for clean
i: install ## Quick alias for install