127 lines
4.1 KiB
Makefile
127 lines
4.1 KiB
Makefile
# FastestMirror Makefile
|
|
# Because automation is better than repetitive typing
|
|
|
|
# Variables
|
|
BINARY_NAME=fastestmirror
|
|
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
|
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
BUILD_TIME=$(shell date +%Y-%m-%dT%H:%M:%S%z)
|
|
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildTime=$(BUILD_TIME)"
|
|
|
|
# Build targets
|
|
.PHONY: all build clean test fmt lint install uninstall package help
|
|
|
|
all: test build ## Run tests and build binary
|
|
|
|
build: ## Build the binary for current platform
|
|
@echo "🔨 Building $(BINARY_NAME) v$(VERSION)..."
|
|
go build $(LDFLAGS) -o $(BINARY_NAME) .
|
|
@echo "Build complete: ./$(BINARY_NAME)"
|
|
|
|
build-all: ## Build binaries for all platforms
|
|
@echo "🏗️ Building for all platforms..."
|
|
@mkdir -p dist
|
|
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-amd64 .
|
|
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-arm64 .
|
|
GOOS=linux GOARCH=386 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-386 .
|
|
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-amd64 .
|
|
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-arm64 .
|
|
@echo "Multi-platform build complete in ./dist/"
|
|
|
|
test: ## Run tests
|
|
@echo "🧪 Running tests..."
|
|
go test -v ./...
|
|
@echo "Tests complete"
|
|
|
|
test-coverage: ## Run tests with coverage
|
|
@echo "🧪 Running tests with coverage..."
|
|
go test -coverprofile=coverage.out ./...
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
@echo "Coverage report generated: coverage.html"
|
|
|
|
fmt: ## Format code
|
|
@echo "Formatting code..."
|
|
go fmt ./...
|
|
@echo "Code formatted"
|
|
|
|
lint: ## Run linters
|
|
@echo "Running linters..."
|
|
@if command -v golangci-lint >/dev/null 2>&1; then \
|
|
golangci-lint run; \
|
|
else \
|
|
echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
|
|
go vet ./...; \
|
|
fi
|
|
@echo "Linting complete"
|
|
|
|
clean: ## Clean build artifacts
|
|
@echo "Cleaning up..."
|
|
rm -f $(BINARY_NAME)
|
|
rm -rf dist/
|
|
rm -f coverage.out coverage.html
|
|
@echo "Clean complete"
|
|
|
|
install: build ## Install binary to /usr/local/bin
|
|
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
|
|
sudo cp $(BINARY_NAME) /usr/local/bin/
|
|
@echo "Installation complete"
|
|
|
|
uninstall: ## Remove binary from /usr/local/bin
|
|
@echo "Uninstalling $(BINARY_NAME)..."
|
|
sudo rm -f /usr/local/bin/$(BINARY_NAME)
|
|
@echo "Uninstallation complete"
|
|
|
|
package: build-all ## Create distribution packages
|
|
@echo "Creating packages..."
|
|
@mkdir -p dist/packages
|
|
|
|
# Create tar.gz archives
|
|
@for binary in dist/$(BINARY_NAME)-*; do \
|
|
if [ -f "$$binary" ]; then \
|
|
platform=$$(basename "$$binary" | sed 's/$(BINARY_NAME)-//'); \
|
|
echo "Creating tar.gz for $$platform..."; \
|
|
tar -czf "dist/packages/$(BINARY_NAME)-$(VERSION)-$$platform.tar.gz" -C dist "$$(basename $$binary)"; \
|
|
fi \
|
|
done
|
|
|
|
@echo "Packages created in dist/packages/"
|
|
|
|
release: clean test package ## Prepare a release
|
|
@echo "🚀 Release $(VERSION) ready!"
|
|
@echo "📁 Files in dist/packages/:"
|
|
@ls -la dist/packages/
|
|
|
|
deps: ## Download dependencies
|
|
@echo "📥 Downloading dependencies..."
|
|
go mod download
|
|
go mod tidy
|
|
@echo "Dependencies updated"
|
|
|
|
dev-deps: ## Install development dependencies
|
|
@echo "🛠️ Installing development dependencies..."
|
|
@if ! command -v golangci-lint >/dev/null 2>&1; then \
|
|
echo "Installing golangci-lint..."; \
|
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
|
|
fi
|
|
@echo "Development dependencies installed"
|
|
|
|
run: build ## Build and run the application
|
|
@echo "🏃 Running $(BINARY_NAME)..."
|
|
./$(BINARY_NAME)
|
|
|
|
demo: build ## Run a demo of the find command
|
|
@echo "🎬 Running demo..."
|
|
./$(BINARY_NAME) find --top 3
|
|
|
|
check: fmt lint test ## Run all checks (format, lint, test)
|
|
@echo "All checks passed!"
|
|
|
|
help: ## Show this help message
|
|
@echo "FastestMirror Build System"
|
|
@echo "Usage: make [target]"
|
|
@echo ""
|
|
@echo "Targets:"
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
|
|
|
|
# Default target
|
|
.DEFAULT_GOAL := help
|