-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
278 lines (231 loc) · 9 KB
/
Makefile
File metadata and controls
278 lines (231 loc) · 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
# git-adr Makefile
# Build, test, and install git-adr (Rust implementation)
.PHONY: all clean test test-unit lint format check build build-release \
install install-bin uninstall help ci dev docs docs-check \
version bump-patch bump-minor bump-major tag \
release-patch release-minor release-major \
clippy audit deny completions
# ============================================================
# Configuration
# ============================================================
DESTDIR ?=
prefix ?= /usr/local
bindir ?= $(prefix)/bin
mandir ?= $(prefix)/share/man
datadir ?= $(prefix)/share
# Completion directories
BASH_COMPLETION_DIR ?= $(datadir)/bash-completion/completions
ZSH_COMPLETION_DIR ?= $(datadir)/zsh/site-functions
FISH_COMPLETION_DIR ?= $(datadir)/fish/vendor_completions.d
# Project paths
TARGET_DIR := target
SHARE_DIR := share
COMPLETION_DIR := $(SHARE_DIR)/completions
# Binary name
BINARY := git-adr
# Version from Cargo.toml
VERSION := $(shell grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
# Features
FEATURES ?= all
# ============================================================
# Default target
# ============================================================
all: build
# ============================================================
# Help
# ============================================================
help:
@echo "git-adr Makefile (v$(VERSION))"
@echo ""
@echo "Build:"
@echo " make build Build debug binary"
@echo " make build-release Build optimized release binary"
@echo " make completions Generate shell completion scripts"
@echo ""
@echo "Install (may require sudo):"
@echo " make install Install binary to $(bindir)"
@echo " make install-completions Install shell completions"
@echo " make uninstall Remove installed files"
@echo ""
@echo "Development:"
@echo " make test Run all tests"
@echo " make test-unit Run unit tests only"
@echo " make lint Run clippy lints"
@echo " make format Format code with rustfmt"
@echo " make check Run format check + clippy"
@echo " make audit Run cargo audit (security)"
@echo " make deny Run cargo deny (licenses/advisories)"
@echo " make ci Full CI checks (mirrors GitHub Actions)"
@echo " make docs Generate and open documentation"
@echo " make docs-check Check documentation builds without warnings"
@echo ""
@echo "Version:"
@echo " make version Show current version"
@echo " make bump-patch Bump patch version (0.2.3 -> 0.2.4)"
@echo " make bump-minor Bump minor version (0.2.3 -> 0.3.0)"
@echo " make bump-major Bump major version (0.2.3 -> 1.0.0)"
@echo " make tag Create git tag for current version"
@echo ""
@echo "Release:"
@echo " make release-patch Bump patch, tag, ready to push"
@echo " make release-minor Bump minor, tag, ready to push"
@echo " make release-major Bump major, tag, ready to push"
@echo " make clean Clean build artifacts"
@echo ""
@echo "Configuration:"
@echo " prefix=$(prefix)"
@echo " DESTDIR=$(DESTDIR)"
@echo " FEATURES=$(FEATURES)"
# ============================================================
# Build targets
# ============================================================
build:
cargo build --features $(FEATURES)
build-release:
cargo build --release --features $(FEATURES)
# Generate shell completion scripts
completions: build
@echo "Generating shell completions..."
@mkdir -p $(COMPLETION_DIR)
@$(TARGET_DIR)/debug/$(BINARY) completion bash > $(COMPLETION_DIR)/git-adr.bash 2>/dev/null || \
echo " (bash completion generation not yet implemented)"
@$(TARGET_DIR)/debug/$(BINARY) completion zsh > $(COMPLETION_DIR)/_git-adr 2>/dev/null || \
echo " (zsh completion generation not yet implemented)"
@$(TARGET_DIR)/debug/$(BINARY) completion fish > $(COMPLETION_DIR)/git-adr.fish 2>/dev/null || \
echo " (fish completion generation not yet implemented)"
# ============================================================
# Installation targets
# ============================================================
install: install-bin
@echo ""
@echo "git-adr $(VERSION) installed successfully!"
@echo ""
@echo "Quick start:"
@echo " git adr init # Initialize in a repository"
@echo " git adr new 'Title' # Create an ADR"
@echo " git adr list # List all ADRs"
install-bin: build-release
@echo "Installing git-adr binary..."
install -d $(DESTDIR)$(bindir)
install -m 755 $(TARGET_DIR)/release/$(BINARY) $(DESTDIR)$(bindir)/$(BINARY)
@echo "Installed to $(DESTDIR)$(bindir)/$(BINARY)"
install-completions: completions
@echo "Installing shell completions..."
@if [ -f "$(COMPLETION_DIR)/git-adr.bash" ]; then \
install -d $(DESTDIR)$(BASH_COMPLETION_DIR); \
install -m 644 $(COMPLETION_DIR)/git-adr.bash $(DESTDIR)$(BASH_COMPLETION_DIR)/git-adr; \
echo " bash: $(DESTDIR)$(BASH_COMPLETION_DIR)/git-adr"; \
fi
@if [ -f "$(COMPLETION_DIR)/_git-adr" ]; then \
install -d $(DESTDIR)$(ZSH_COMPLETION_DIR); \
install -m 644 $(COMPLETION_DIR)/_git-adr $(DESTDIR)$(ZSH_COMPLETION_DIR)/_git-adr; \
echo " zsh: $(DESTDIR)$(ZSH_COMPLETION_DIR)/_git-adr"; \
fi
@if [ -f "$(COMPLETION_DIR)/git-adr.fish" ]; then \
install -d $(DESTDIR)$(FISH_COMPLETION_DIR); \
install -m 644 $(COMPLETION_DIR)/git-adr.fish $(DESTDIR)$(FISH_COMPLETION_DIR)/git-adr.fish; \
echo " fish: $(DESTDIR)$(FISH_COMPLETION_DIR)/git-adr.fish"; \
fi
uninstall:
@echo "Uninstalling git-adr..."
rm -f $(DESTDIR)$(bindir)/$(BINARY)
rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/git-adr
rm -f $(DESTDIR)$(ZSH_COMPLETION_DIR)/_git-adr
rm -f $(DESTDIR)$(FISH_COMPLETION_DIR)/git-adr.fish
@echo "Uninstall complete."
# ============================================================
# Testing targets
# ============================================================
test:
cargo test --all-features
test-unit:
cargo test --all-features --lib
# ============================================================
# Code quality targets
# ============================================================
lint: clippy
clippy:
cargo clippy --all-targets --all-features -- -D warnings
format:
cargo fmt
format-check:
cargo fmt -- --check
check: format-check clippy
@echo "All quality checks passed!"
audit:
@if command -v cargo-audit >/dev/null 2>&1; then \
cargo audit; \
else \
echo "cargo-audit not installed. Install with: cargo install cargo-audit"; \
fi
deny:
@if command -v cargo-deny >/dev/null 2>&1; then \
cargo deny check; \
else \
echo "cargo-deny not installed. Install with: cargo install cargo-deny"; \
fi
# Full CI check (mirrors GitHub Actions)
ci: check deny test docs-check
@echo "CI checks passed!"
# Documentation check (mirrors CI docs job)
docs-check:
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
# ============================================================
# Documentation
# ============================================================
docs:
cargo doc --all-features --open
# ============================================================
# Version management
# ============================================================
version:
@echo "$(VERSION)"
# Bump patch version (0.2.3 -> 0.2.4)
bump-patch:
@current=$(VERSION) && \
major=$$(echo $$current | cut -d. -f1) && \
minor=$$(echo $$current | cut -d. -f2) && \
patch=$$(echo $$current | cut -d. -f3) && \
new_patch=$$((patch + 1)) && \
new_version="$$major.$$minor.$$new_patch" && \
sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" Cargo.toml && \
rm -f Cargo.toml.bak && \
echo "Bumped version: $$current -> $$new_version"
# Bump minor version (0.2.3 -> 0.3.0)
bump-minor:
@current=$(VERSION) && \
major=$$(echo $$current | cut -d. -f1) && \
minor=$$(echo $$current | cut -d. -f2) && \
new_minor=$$((minor + 1)) && \
new_version="$$major.$$new_minor.0" && \
sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" Cargo.toml && \
rm -f Cargo.toml.bak && \
echo "Bumped version: $$current -> $$new_version"
# Bump major version (0.2.3 -> 1.0.0)
bump-major:
@current=$(VERSION) && \
major=$$(echo $$current | cut -d. -f1) && \
new_major=$$((major + 1)) && \
new_version="$$new_major.0.0" && \
sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" Cargo.toml && \
rm -f Cargo.toml.bak && \
echo "Bumped version: $$current -> $$new_version"
# Create git tag for current version
tag:
git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
@echo "Created tag: v$(VERSION)"
# Bump and tag shortcuts
release-patch: bump-patch tag
@echo "Release ready. Run 'git push --follow-tags' to publish."
release-minor: bump-minor tag
@echo "Release ready. Run 'git push --follow-tags' to publish."
release-major: bump-major tag
@echo "Release ready. Run 'git push --follow-tags' to publish."
# ============================================================
# Clean target
# ============================================================
clean:
@echo "Cleaning build artifacts..."
cargo clean
rm -rf $(SHARE_DIR)
@echo "Clean complete."