-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
245 lines (214 loc) · 10.3 KB
/
Makefile
File metadata and controls
245 lines (214 loc) · 10.3 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
# HawkOp Makefile
# Build automation for the HawkOp CLI
.PHONY: help build release test lint fmt check-fmt pre-commit clean install run
.PHONY: build-all build-linux-x64 build-linux-arm64 build-macos-intel build-macos-arm build-windows-x64 build-windows-arm64
.PHONY: dist checksums changelog changelog-preview
.PHONY: functional-test functional-test-dry-run
.PHONY: setup-hooks check-test-coverage
# Default target
.DEFAULT_GOAL := help
# Variables
BINARY_NAME := hawkop
VERSION := $(shell grep '^version' Cargo.toml | head -n1 | cut -d'"' -f2)
DIST_DIR := dist
PREFIX ?= /usr/local
# Colors for output
CYAN := \033[0;36m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m
## help: Show this help message
help:
@echo "$(CYAN)HawkOp Build System$(NC)"
@echo ""
@echo "$(GREEN)Available targets:$(NC)"
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'
## build: Build debug binary
build:
@echo "$(CYAN)Building debug binary...$(NC)"
cargo build
## release: Run interactive release wizard
release:
@echo "$(YELLOW)Tip: For better Ctrl+C handling, run directly: ./scripts/release.sh$(NC)"
@./scripts/release.sh
## test: Run all tests
test:
@echo "$(CYAN)Running tests...$(NC)"
cargo test
## lint: Run clippy lints
lint:
@echo "$(CYAN)Running clippy...$(NC)"
cargo clippy -- -D warnings
## fmt: Format code
fmt:
@echo "$(CYAN)Formatting code...$(NC)"
cargo fmt
## check-fmt: Check code formatting without modifying
check-fmt:
@echo "$(CYAN)Checking code formatting...$(NC)"
cargo fmt -- --check
## pre-commit: Run all checks before committing (format, lint, test)
pre-commit:
@echo "$(CYAN)╔════════════════════════════════════════════════════════╗$(NC)"
@echo "$(CYAN)║ Running Pre-Commit Checks ║$(NC)"
@echo "$(CYAN)╚════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo "$(YELLOW)[1/4] Formatting code...$(NC)"
@cargo fmt
@echo "$(GREEN)✓ Code formatted$(NC)"
@echo ""
@echo "$(YELLOW)[2/4] Checking format...$(NC)"
@cargo fmt -- --check && echo "$(GREEN)✓ Format check passed$(NC)" || (echo "$(RED)✗ Format check failed$(NC)" && exit 1)
@echo ""
@echo "$(YELLOW)[3/4] Running clippy...$(NC)"
@cargo clippy -- -D warnings && echo "$(GREEN)✓ Clippy passed$(NC)" || (echo "$(RED)✗ Clippy failed$(NC)" && exit 1)
@echo ""
@echo "$(YELLOW)[4/4] Running tests...$(NC)"
@cargo test && echo "$(GREEN)✓ Tests passed$(NC)" || (echo "$(RED)✗ Tests failed$(NC)" && exit 1)
@echo ""
@echo "$(GREEN)╔════════════════════════════════════════════════════════╗$(NC)"
@echo "$(GREEN)║ All pre-commit checks passed! ✓ ║$(NC)"
@echo "$(GREEN)╚════════════════════════════════════════════════════════╝$(NC)"
## clean: Remove build artifacts
clean:
@echo "$(CYAN)Cleaning build artifacts...$(NC)"
cargo clean
rm -rf $(DIST_DIR)
## install: Install binary to system (use PREFIX to customize location)
install: build-release
@echo "$(CYAN)Installing $(BINARY_NAME) to $(PREFIX)/bin...$(NC)"
install -d $(PREFIX)/bin
install -m 755 target/release/$(BINARY_NAME) $(PREFIX)/bin/
## run: Run the binary (debug mode)
run:
cargo run --
## build-release: Build optimized release binary
build-release:
@echo "$(CYAN)Building release binary...$(NC)"
cargo build --release
## build-all: Build for all supported platforms
build-all: build-linux-x64 build-linux-arm64 build-macos-intel build-macos-arm build-windows-x64 build-windows-arm64
## build-linux-x64: Build for Linux x86_64
build-linux-x64:
@echo "$(CYAN)Building for Linux x86_64...$(NC)"
cargo build --release --target x86_64-unknown-linux-gnu
## build-linux-arm64: Build for Linux ARM64
build-linux-arm64:
@echo "$(CYAN)Building for Linux ARM64...$(NC)"
cargo build --release --target aarch64-unknown-linux-gnu
## build-macos-intel: Build for macOS Intel
build-macos-intel:
@echo "$(CYAN)Building for macOS Intel...$(NC)"
cargo build --release --target x86_64-apple-darwin
## build-macos-arm: Build for macOS Apple Silicon
build-macos-arm:
@echo "$(CYAN)Building for macOS Apple Silicon...$(NC)"
cargo build --release --target aarch64-apple-darwin
## build-windows-x64: Build for Windows x86_64
build-windows-x64:
@echo "$(CYAN)Building for Windows x86_64...$(NC)"
cargo build --release --target x86_64-pc-windows-msvc
## build-windows-arm64: Build for Windows ARM64
build-windows-arm64:
@echo "$(CYAN)Building for Windows ARM64...$(NC)"
cargo build --release --target aarch64-pc-windows-msvc
## dist: Create distribution archives for all platforms
dist: clean build-all
@echo "$(CYAN)Creating distribution archives...$(NC)"
@mkdir -p $(DIST_DIR)
@# Linux x86_64
@tar -czf $(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-x86_64-unknown-linux-gnu.tar.gz \
-C target/x86_64-unknown-linux-gnu/release $(BINARY_NAME) \
-C ../../../ LICENSE README.md
@# Linux ARM64
@tar -czf $(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-aarch64-unknown-linux-gnu.tar.gz \
-C target/aarch64-unknown-linux-gnu/release $(BINARY_NAME) \
-C ../../../ LICENSE README.md
@# macOS Intel
@tar -czf $(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-x86_64-apple-darwin.tar.gz \
-C target/x86_64-apple-darwin/release $(BINARY_NAME) \
-C ../../../ LICENSE README.md
@# macOS Apple Silicon
@tar -czf $(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-aarch64-apple-darwin.tar.gz \
-C target/aarch64-apple-darwin/release $(BINARY_NAME) \
-C ../../../ LICENSE README.md
@# Windows x86_64
@cd target/x86_64-pc-windows-msvc/release && \
zip -q $(CURDIR)/$(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-x86_64-pc-windows-msvc.zip \
$(BINARY_NAME).exe && \
cd $(CURDIR) && \
zip -qj $(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-x86_64-pc-windows-msvc.zip LICENSE README.md
@# Windows ARM64
@cd target/aarch64-pc-windows-msvc/release && \
zip -q $(CURDIR)/$(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-aarch64-pc-windows-msvc.zip \
$(BINARY_NAME).exe && \
cd $(CURDIR) && \
zip -qj $(DIST_DIR)/$(BINARY_NAME)-v$(VERSION)-aarch64-pc-windows-msvc.zip LICENSE README.md
@$(MAKE) checksums
@echo "$(GREEN)Distribution archives created in $(DIST_DIR)/$(NC)"
## checksums: Generate SHA256 checksums for distribution archives
checksums:
@echo "$(CYAN)Generating SHA256 checksums...$(NC)"
@cd $(DIST_DIR) && shasum -a 256 *.tar.gz *.zip > checksums.txt
@echo "$(GREEN)Checksums generated: $(DIST_DIR)/checksums.txt$(NC)"
## changelog: Extract changelog for a version (usage: make changelog or make changelog V=0.2.0)
changelog:
@V=$${V:-$(VERSION)}; \
if [ "$$V" = "Unreleased" ]; then \
awk '/^## \[Unreleased\]/{found=1; next} /^## \[/{if(found) exit} /^\[.*\]:/{next} found{print}' CHANGELOG.md; \
else \
awk -v ver="$$V" '/^## \[/{if(found) exit; if($$0 ~ "\\["ver"\\]") found=1; next} /^\[.*\]:/{next} found{print}' CHANGELOG.md; \
fi
## changelog-preview: Show changelog for current version with header
changelog-preview:
@echo "$(CYAN)╔════════════════════════════════════════════════════════╗$(NC)"
@echo "$(CYAN)║ Changelog for v$(VERSION)$(NC)"
@echo "$(CYAN)╚════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@$(MAKE) -s changelog
@echo ""
## setup-hooks: Install git hooks for pre-commit and pre-push checks
setup-hooks:
@echo "$(CYAN)Installing git hooks...$(NC)"
@git config core.hooksPath .githooks
@chmod +x .githooks/*
@echo "$(GREEN)Git hooks installed.$(NC)"
@echo " pre-commit: format + clippy + test"
@echo " pre-push: pre-commit + functional tests (if HAWKOP_PROFILE set)"
@echo ""
@echo "$(YELLOW)To uninstall: git config --unset core.hooksPath$(NC)"
## check-test-coverage: Check functional test coverage for all CLI commands
check-test-coverage:
@chmod +x scripts/check-test-coverage.sh
@./scripts/check-test-coverage.sh
## functional-test: Run functional tests against real API (uses HAWKOP_PROFILE)
functional-test:
@echo "$(CYAN)╔════════════════════════════════════════════════════════╗$(NC)"
@echo "$(CYAN)║ Running Functional Tests ║$(NC)"
@echo "$(CYAN)╚════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@if [ -z "$$HAWKOP_PROFILE" ]; then \
echo "$(RED)Error: HAWKOP_PROFILE must be set$(NC)"; \
echo "$(YELLOW)Example: HAWKOP_PROFILE=test make functional-test$(NC)"; \
exit 1; \
fi
@echo "$(YELLOW)Using profile: $$HAWKOP_PROFILE$(NC)"
@echo ""
cargo test --features functional-tests --test functional -- --test-threads=1 --nocapture
## functional-test-dry-run: Preview functional tests (list only, no execution)
functional-test-dry-run:
@echo "$(CYAN)╔════════════════════════════════════════════════════════╗$(NC)"
@echo "$(CYAN)║ Functional Tests Preview (List Only) ║$(NC)"
@echo "$(CYAN)╚════════════════════════════════════════════════════════╝$(NC)"
@echo ""
@echo "$(YELLOW)The following tests would run:$(NC)"
@echo ""
@cargo test --features functional-tests --test functional -- --list 2>/dev/null | grep ": test$$" | sed 's/: test$$//' | while read test; do \
echo " $(GREEN)✓$(NC) $$test"; \
done
@echo ""
@echo "$(CYAN)Total:$(NC) $$(cargo test --features functional-tests --test functional -- --list 2>/dev/null | grep -c ': test$$') tests"
@echo ""
@echo "$(YELLOW)To run these tests:$(NC)"
@echo " HAWKOP_PROFILE=test make functional-test"