-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (104 loc) · 3.6 KB
/
Makefile
File metadata and controls
117 lines (104 loc) · 3.6 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
NAME := mwget
VERSION := $(shell grep '^version = ' Cargo.toml | cut -d '"' -f 2)
TARGET := x86_64-unknown-linux-gnu
RELEASE_DIR := target/$(TARGET)/release
DIST_DIR := dist
BINARY := $(RELEASE_DIR)/$(NAME)
ARCHIVE_NAME := $(NAME)-$(TARGET)_$(VERSION).tar.gz
all: build
# Install the Rust target if not installed
setup:
@echo "Setting up target $(TARGET)..."
@if rustup target list --installed | grep -q "$(TARGET)"; then \
echo "✓ Target $(TARGET) already installed"; \
else \
echo "Installing target $(TARGET)..."; \
rustup target add $(TARGET); \
echo "✓ Target $(TARGET) installed"; \
fi
# Compile the project for the specified target
build: setup
@echo "Building $(NAME) v$(VERSION) for target $(TARGET)..."
@cargo build --release --target $(TARGET)
@echo "✓ Build completed: $(BINARY)"
# Create distribution package
package: build
@echo "Creating distribution package..."
@mkdir -p $(DIST_DIR)/$(NAME)-$(TARGET)_$(VERSION)
@cp $(BINARY) $(DIST_DIR)/$(NAME)-$(TARGET)_$(VERSION)/
@cd $(DIST_DIR) && tar -czf $(ARCHIVE_NAME) $(NAME)-$(TARGET)_$(VERSION)/
@echo "✓ Package created: $(DIST_DIR)/$(ARCHIVE_NAME)"
# Install locally
install: build
@echo "Installing $(NAME) to /usr/local/bin..."
@cp $(BINARY) /usr/local/bin/$(NAME)
@echo "✓ Installation completed"
# Uninstall locally
uninstall:
@echo "Removing $(NAME) from /usr/local/bin..."
@rm -f /usr/local/bin/$(NAME)
@echo "✓ Uninstallation completed"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@cargo clean
@rm -rf $(DIST_DIR)
@echo "✓ Clean completed"
# Show build info
info:
@echo "=== $(NAME) Build Information ==="
@echo "Name: $(NAME)"
@echo "Version: $(VERSION)"
@echo "Target: $(TARGET)"
@echo "Binary: $(BINARY)"
@echo "Archive: $(ARCHIVE_NAME)"
@echo "Rust version: $(shell rustc --version)"
@echo "Available targets:"
@rustup target list | grep "$(TARGET)"
# Run tests
test:
@echo "Running code formatting check..."
@cargo fmt --check
@echo "Running clippy lints..."
@cargo clippy -- -D warnings
@echo "Running tests..."
@cargo test
# Build and run binary (for quick testing)
run: build
@echo "Running $(BINARY) with --help..."
@$(BINARY) --help
# Release preparation (build + package + verify)
release: clean package
@echo "=== Release Summary ==="
@echo "Version: $(VERSION)"
@echo "Package: $(DIST_DIR)/$(ARCHIVE_NAME)"
@if [ -f "$(DIST_DIR)/$(ARCHIVE_NAME)" ]; then \
echo "Size: $$(du -h $(DIST_DIR)/$(ARCHIVE_NAME) | cut -f1)"; \
echo "SHA256: $$(sha256sum $(DIST_DIR)/$(ARCHIVE_NAME) | cut -d' ' -f1)"; \
else \
echo "❌ Package not found!"; \
exit 1; \
fi
@echo "✓ Release ready for distribution"
# Help
help:
@echo "=== $(NAME) Makefile ==="
@echo ""
@echo "Available targets:"
@echo " setup - Install target"
@echo " build - Build binary"
@echo " package - Create distribution tar.gz package"
@echo " install - Install binary to /usr/local/bin"
@echo " uninstall - Remove binary from /usr/local/bin"
@echo " clean - Clean build artifacts"
@echo " test - Run fmt check, clippy, and cargo tests"
@echo " run - Build and run with --help"
@echo " release - Full release preparation"
@echo " info - Show build information"
@echo " help - Show this help message"
@echo ""
@echo "Examples:"
@echo " make package # Build and create package"
@echo " make release # Full release preparation"
@echo " make build TARGET=x86_64-unknown-linux-musl # Build for musl"
.PHONY: all setup build package info clean uninstall install help release run test