-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
292 lines (244 loc) · 10.5 KB
/
Makefile
File metadata and controls
292 lines (244 loc) · 10.5 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
# trex - tmux session manager
# ISC License
BINARY := trex
VERSION := $(shell grep '^version' Cargo.toml | head -1 | cut -d'"' -f2)
PREFIX ?= $(HOME)/.cargo
BINDIR := $(PREFIX)/bin
CARGO := cargo
INSTALL := install
RM := rm -f
# Targets
TARGET_NATIVE := $(shell rustc -vV | grep host | cut -d' ' -f2)
TARGET_MUSL_X86 := x86_64-unknown-linux-musl
TARGET_MUSL_ARM := aarch64-unknown-linux-musl
# Output paths
RELEASE_DIR := target/release
STATIC_X86_DIR := target/$(TARGET_MUSL_X86)/release
STATIC_ARM_DIR := target/$(TARGET_MUSL_ARM)/release
DIST_DIR := dist
.PHONY: all build build-ascii release release-ascii rebuild \
static static-x86 static-arm \
install install-static install-user install-static-user \
install-ascii install-ascii-user \
uninstall uninstall-user \
run run-ascii doc \
test fmt fmt-check lint check pre-release pre-commit \
version bump-patch bump-minor bump-major bump-dry \
dist dist-all clean help
# Default target: show help
all: help
# ─── Build ────────────────────────────────────────────────────────────
# Development build
build:
$(CARGO) build
# Development build with ascii-art feature
build-ascii:
$(CARGO) build --features ascii-art
# Optimized release build
release:
$(CARGO) build --release
# Optimized release build with ascii-art feature
release-ascii:
$(CARGO) build --release --features ascii-art
# Full rebuild from scratch (clears all cargo cache)
rebuild:
$(CARGO) clean
$(RM) -r $(HOME)/.cargo/registry/cache
$(RM) -r $(HOME)/.cargo/git/checkouts
$(CARGO) build --release
# Static Linux binary (x86_64)
static: static-x86
static-x86:
@echo "Building static x86_64 binary..."
@rustup target add $(TARGET_MUSL_X86) 2>/dev/null || true
$(CARGO) build --release --target $(TARGET_MUSL_X86)
@echo "Binary: $(STATIC_X86_DIR)/$(BINARY)"
# Static Linux binary (aarch64) - requires cross or appropriate linker
static-arm:
@echo "Building static aarch64 binary..."
@rustup target add $(TARGET_MUSL_ARM) 2>/dev/null || true
@command -v cross >/dev/null 2>&1 && \
cross build --release --target $(TARGET_MUSL_ARM) || \
$(CARGO) build --release --target $(TARGET_MUSL_ARM)
@echo "Binary: $(STATIC_ARM_DIR)/$(BINARY)"
# ─── Install ──────────────────────────────────────────────────────────
# Install to system (default: ~/.cargo/bin)
install: release
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 $(RELEASE_DIR)/$(BINARY) $(DESTDIR)$(BINDIR)/$(BINARY)
@echo "Installed $(BINARY) to $(DESTDIR)$(BINDIR)"
# Install with ascii-art feature to system
install-ascii: release-ascii
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 $(RELEASE_DIR)/$(BINARY) $(DESTDIR)$(BINDIR)/$(BINARY)
@echo "Installed $(BINARY) (ascii-art) to $(DESTDIR)$(BINDIR)"
# Install static binary
install-static: static-x86
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 $(STATIC_X86_DIR)/$(BINARY) $(DESTDIR)$(BINDIR)/$(BINARY)
@echo "Installed static $(BINARY) to $(DESTDIR)$(BINDIR)"
# Install to ~/.cargo/bin (user install)
install-user:
$(CARGO) install --path .
@echo "Installed $(BINARY) to ~/.cargo/bin"
# Install with ascii-art feature to ~/.cargo/bin
install-ascii-user:
$(CARGO) install --path . --features ascii-art
@echo "Installed $(BINARY) (ascii-art) to ~/.cargo/bin"
# Install static binary to ~/.cargo/bin
install-static-user: static-x86
$(INSTALL) -d $(HOME)/.cargo/bin
$(INSTALL) -m 755 $(STATIC_X86_DIR)/$(BINARY) $(HOME)/.cargo/bin/$(BINARY)
@echo "Installed static $(BINARY) to ~/.cargo/bin"
# Uninstall from system
uninstall:
$(RM) $(DESTDIR)$(BINDIR)/$(BINARY)
@echo "Removed $(BINARY) from $(DESTDIR)$(BINDIR)"
# Uninstall from ~/.cargo/bin
uninstall-user:
$(CARGO) uninstall $(BINARY) 2>/dev/null || true
@echo "Removed $(BINARY) from ~/.cargo/bin"
# ─── Run ──────────────────────────────────────────────────────────────
# Run debug build
run:
$(CARGO) run
# Run with ascii-art feature
run-ascii:
$(CARGO) run --features ascii-art
# ─── Distribution ─────────────────────────────────────────────────────
# Create distribution archives
dist: static-x86
@mkdir -p $(DIST_DIR)
@cp $(STATIC_X86_DIR)/$(BINARY) $(DIST_DIR)/$(BINARY)-$(VERSION)-linux-x86_64
@cd $(DIST_DIR) && tar -czvf $(BINARY)-$(VERSION)-linux-x86_64.tar.gz $(BINARY)-$(VERSION)-linux-x86_64
@echo "Created $(DIST_DIR)/$(BINARY)-$(VERSION)-linux-x86_64.tar.gz"
# Create distribution for both architectures
dist-all: static-x86 static-arm
@mkdir -p $(DIST_DIR)
@cp $(STATIC_X86_DIR)/$(BINARY) $(DIST_DIR)/$(BINARY)-$(VERSION)-linux-x86_64
@cp $(STATIC_ARM_DIR)/$(BINARY) $(DIST_DIR)/$(BINARY)-$(VERSION)-linux-aarch64
@cd $(DIST_DIR) && tar -czvf $(BINARY)-$(VERSION)-linux-x86_64.tar.gz $(BINARY)-$(VERSION)-linux-x86_64
@cd $(DIST_DIR) && tar -czvf $(BINARY)-$(VERSION)-linux-aarch64.tar.gz $(BINARY)-$(VERSION)-linux-aarch64
@echo "Created archives in $(DIST_DIR)/"
# ─── Development ──────────────────────────────────────────────────────
# Run tests
test:
$(CARGO) test
# Format code
fmt:
$(CARGO) fmt
# Check formatting without modifying
fmt-check:
$(CARGO) fmt --check
# Lint code
lint:
$(CARGO) clippy -- -D warnings
# Check without building
check:
$(CARGO) check
# Generate and open documentation
doc:
$(CARGO) doc --open
# Run pre-commit on all files
pre-commit:
python3 -m pre_commit run --all-files
# ─── Version Management ────────────────────────────────────────────
# Show current version
version:
@echo "$(BINARY) $(VERSION)"
# Bump patch version (0.4.x) - updates Cargo.toml, CHANGELOG.md, commits, tags
bump-patch: pre-release
npx commit-and-tag-version --release-as patch --no-verify
@echo "Run 'git push --follow-tags' to publish"
# Bump minor version (0.x.0)
bump-minor: pre-release
npx commit-and-tag-version --release-as minor --no-verify
@echo "Run 'git push --follow-tags' to publish"
# Bump major version (x.0.0)
bump-major: pre-release
npx commit-and-tag-version --release-as major --no-verify
@echo "Run 'git push --follow-tags' to publish"
# Preview version bump without making changes
bump-dry:
npx commit-and-tag-version --dry-run
# Full pre-release validation
pre-release:
@echo "══════════════════════════════════════════════"
@echo " Pre-release check: $(BINARY) $(VERSION)"
@echo "══════════════════════════════════════════════"
@echo ""
@echo "── Formatting ──"
$(CARGO) fmt --check
@echo ""
@echo "── Linting ──"
$(CARGO) clippy -- -D warnings
@echo ""
@echo "── Tests ──"
$(CARGO) test
@echo ""
@echo "── Build (default) ──"
$(CARGO) build --release
@echo ""
@echo "── Build (ascii-art) ──"
$(CARGO) build --release --features ascii-art
@echo ""
@echo "══════════════════════════════════════════════"
@echo " Pre-release check passed"
@echo "══════════════════════════════════════════════"
# Clean build artifacts
clean:
$(CARGO) clean
$(RM) -r $(DIST_DIR)
# ─── Help ─────────────────────────────────────────────────────────────
help:
@echo "trex $(VERSION) - tmux session manager"
@echo ""
@echo "Build:"
@echo " make build Debug build"
@echo " make build-ascii Debug build with ascii-art feature"
@echo " make release Optimized release build"
@echo " make release-ascii Optimized release build with ascii-art feature"
@echo " make rebuild Clean all cache and rebuild from scratch"
@echo " make static Static x86_64 Linux binary (musl)"
@echo " make static-x86 Static x86_64 Linux binary (musl)"
@echo " make static-arm Static aarch64 Linux binary (musl)"
@echo ""
@echo "Install:"
@echo " make install Install to $(BINDIR)"
@echo " make install-ascii Install with ascii-art to $(BINDIR)"
@echo " make install-static Install static binary to $(BINDIR)"
@echo " make install-user Install to ~/.cargo/bin"
@echo " make install-ascii-user Install with ascii-art to ~/.cargo/bin"
@echo " make install-static-user Install static binary to ~/.cargo/bin"
@echo " make uninstall Remove from $(BINDIR)"
@echo " make uninstall-user Remove from ~/.cargo/bin"
@echo ""
@echo "Run:"
@echo " make run Run debug build"
@echo " make run-ascii Run with ascii-art feature"
@echo ""
@echo "Distribution:"
@echo " make dist Create x86_64 release archive"
@echo " make dist-all Create x86_64 and aarch64 release archives"
@echo ""
@echo "Development:"
@echo " make test Run tests"
@echo " make fmt Format code"
@echo " make fmt-check Check formatting (no changes)"
@echo " make lint Run clippy lints"
@echo " make check Type-check without building"
@echo " make doc Generate and open documentation"
@echo " make pre-commit Run pre-commit hooks on all files"
@echo " make pre-release Full pre-release validation"
@echo " make clean Remove build artifacts"
@echo ""
@echo "Version Management:"
@echo " make version Show current version"
@echo " make bump-patch Bump patch version (0.4.x)"
@echo " make bump-minor Bump minor version (0.x.0)"
@echo " make bump-major Bump major version (x.0.0)"
@echo " make bump-dry Preview version bump (dry run)"
@echo ""
@echo "Variables:"
@echo " PREFIX=$(PREFIX) Installation prefix"
@echo " DESTDIR= Staging directory for packagers"