-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
107 lines (89 loc) · 2.87 KB
/
Makefile
File metadata and controls
107 lines (89 loc) · 2.87 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
# Makefile for dgop
# Project settings
BINARY_NAME=dgop
SOURCE_DIR=cmd/dgop
BUILD_DIR=bin
INSTALL_DIR=/usr/local/bin
# Go settings
GO=go
GOFLAGS=-ldflags="-s -w"
# Version and build info
VERSION=$(shell git describe --tags --always 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Build flags with version info
BUILD_LDFLAGS=-ldflags="-s -w -X main.Version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.commit=$(COMMIT)"
.PHONY: all build clean install uninstall test fmt vet deps help
# Default target
all: build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GO) build $(BUILD_LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(SOURCE_DIR)/*.go
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Install the binary to system path
install: build
@echo "Installing $(BINARY_NAME) to $(INSTALL_DIR)..."
@cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/$(BINARY_NAME)
@chmod +x $(INSTALL_DIR)/$(BINARY_NAME)
@echo "Installation complete"
# Uninstall the binary from system path
uninstall:
@echo "Uninstalling $(BINARY_NAME) from $(INSTALL_DIR)..."
@rm -f $(INSTALL_DIR)/$(BINARY_NAME)
@echo "Uninstall complete"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@echo "Clean complete"
# Run tests
test:
@echo "Running tests..."
$(GO) test -v ./...
# Format Go code
fmt:
@echo "Formatting Go code..."
$(GO) fmt ./...
# Run Go vet
vet:
@echo "Running go vet..."
$(GO) vet ./...
# Update dependencies
deps:
@echo "Updating dependencies..."
$(GO) mod tidy
$(GO) mod download
# Development build (with debug info)
dev:
@echo "Building $(BINARY_NAME) for development..."
@mkdir -p $(BUILD_DIR)
$(GO) build -o $(BUILD_DIR)/$(BINARY_NAME) $(SOURCE_DIR)/*.go
@echo "Development build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Check Go version compatibility
check-go:
@echo "Checking Go version..."
@go version | grep -E "go1\.(2[2-9]|[3-9][0-9])" > /dev/null || (echo "ERROR: Go 1.22 or higher required" && exit 1)
@echo "Go version OK"
# Build with version info
version: check-go
@echo "Version: $(VERSION)"
@echo "Build Time: $(BUILD_TIME)"
@echo "Commit: $(COMMIT)"
# Help target
help:
@echo "Available targets:"
@echo " all - Build the binary (default)"
@echo " build - Build the binary"
@echo " install - Install binary to $(INSTALL_DIR)"
@echo " uninstall - Remove binary from $(INSTALL_DIR)"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " fmt - Format Go code"
@echo " vet - Run go vet"
@echo " deps - Update dependencies"
@echo " dev - Build with debug info"
@echo " check-go - Check Go version compatibility"
@echo " version - Show version information"
@echo " help - Show this help message"