gotidb/Makefile

117 lines
2.6 KiB
Makefile

.PHONY: all build test clean fmt lint build-all
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
GOLINT=golangci-lint
# Binary name
BINARY_NAME=gotidb
BINARY_UNIX=$(BINARY_NAME)_unix
BINARY_WIN=$(BINARY_NAME).exe
BINARY_MAC=$(BINARY_NAME)_mac
# Build directory
BUILD_DIR=build
# Main package path
MAIN_PACKAGE=./cmd/server
# Get the current git commit hash
COMMIT=$(shell git rev-parse --short HEAD)
BUILD_TIME=$(shell date +%FT%T%z)
# Build flags
LDFLAGS=-ldflags "-X main.commit=${COMMIT} -X main.buildTime=${BUILD_TIME}"
# Default target
all: test build
# Build the project
build:
mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
# Build for all platforms
build-all: build-linux build-windows build-mac
build-linux:
mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_UNIX) $(MAIN_PACKAGE)
build-windows:
mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_WIN) $(MAIN_PACKAGE)
build-mac:
mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_MAC) $(MAIN_PACKAGE)
# Run tests
test:
$(GOTEST) -v ./...
# Run tests with coverage
test-coverage:
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
# Clean build artifacts
clean:
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
# Format code
fmt:
$(GOFMT) ./...
# Run linter
lint:
$(GOLINT) run
# Download dependencies
deps:
$(GOMOD) download
# Verify dependencies
verify:
$(GOMOD) verify
# Update dependencies
update-deps:
$(GOMOD) tidy
# Install development tools
install-tools:
$(GOGET) -u github.com/golangci/golangci-lint/cmd/golangci-lint
# Run the application
run:
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
./$(BUILD_DIR)/$(BINARY_NAME)
# Help target
help:
@echo "Available targets:"
@echo " all : Run tests and build"
@echo " build : Build for current platform"
@echo " build-all : Build for all platforms"
@echo " test : Run tests"
@echo " test-coverage: Run tests with coverage"
@echo " clean : Clean build artifacts"
@echo " fmt : Format code"
@echo " lint : Run linter"
@echo " deps : Download dependencies"
@echo " verify : Verify dependencies"
@echo " update-deps : Update dependencies"
@echo " install-tools: Install development tools"
@echo " run : Run the application"
# Default to help if no target is specified
.DEFAULT_GOAL := help