Files
stroke/Makefile
2025-09-12 17:01:54 +03:00

141 lines
3.8 KiB
Makefile

# Makefile for Stroke - Server Stress Testing Tool
# Variables
BINARY_NAME=stroke
MAIN_PATH=./cmd/stroke
BUILD_DIR=./bin
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
VERSION=1.0.0
# Build flags
LDFLAGS=-ldflags "-X main.version=$(VERSION) -s -w"
.PHONY: all build clean test test-coverage deps fmt vet lint install uninstall
# Default target
all: clean fmt vet test build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "✅ Build complete! Binary: $(BUILD_DIR)/$(BINARY_NAME)"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@echo "✅ Clean complete!"
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
@echo "✅ Tests complete!"
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -cover ./...
@echo "✅ Coverage tests complete!"
# Generate detailed coverage report
coverage-html:
@echo "Generating HTML coverage report..."
@mkdir -p coverage
$(GOTEST) -coverprofile=coverage/coverage.out ./...
$(GOCMD) tool cover -html=coverage/coverage.out -o coverage/coverage.html
@echo "✅ Coverage report generated: coverage/coverage.html"
# Install dependencies
deps:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
@echo "✅ Dependencies installed!"
# Format code
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
@echo "✅ Code formatted!"
# Vet code
vet:
@echo "Vetting code..."
$(GOCMD) vet ./...
@echo "✅ Code vetted!"
# Install the binary
install: build
@echo "Installing $(BINARY_NAME)..."
@cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
@echo "$(BINARY_NAME) installed to $(GOPATH)/bin/"
# Uninstall the binary
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@rm -f $(GOPATH)/bin/$(BINARY_NAME)
@echo "$(BINARY_NAME) uninstalled!"
# Run benchmarks
bench:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
@echo "✅ Benchmarks complete!"
# Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
# Linux amd64
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
# Linux arm64
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
# macOS amd64
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
# macOS arm64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
# Windows amd64
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
@echo "✅ Multi-platform builds complete!"
# Quick development build and test
dev: fmt vet test build
# Release build
release: clean deps fmt vet test build-all
@echo "🚀 Release build complete! Binaries in $(BUILD_DIR)/"
# Help
help:
@echo "Available targets:"
@echo " all - Run clean, fmt, vet, test, and build"
@echo " build - Build the binary"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " test-coverage- Run tests with coverage"
@echo " coverage-html- Generate HTML coverage report"
@echo " deps - Install dependencies"
@echo " fmt - Format code"
@echo " vet - Vet code"
@echo " install - Install binary to GOPATH/bin"
@echo " uninstall - Remove binary from GOPATH/bin"
@echo " bench - Run benchmarks"
@echo " build-all - Build for multiple platforms"
@echo " dev - Quick development cycle"
@echo " release - Complete release build"
@echo " help - Show this help"