-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (88 loc) · 2.95 KB
/
Copy pathMakefile
File metadata and controls
110 lines (88 loc) · 2.95 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
# Makefile for cc-switcher
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
BINARY_NAME=cs
BINARY_WINDOWS=$(BINARY_NAME).exe
# Build parameters
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0")
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
# Targets
.PHONY: all build clean test deps help run build-all release
# Default target
all: clean deps test build
# Build for current platform
build:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) -v
# Build for Windows
build-windows:
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_WINDOWS) -v
# Build for Linux
build-linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux -v
# Build for Linux ARM64
build-linux-arm64:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 -v
# Build for macOS Intel
build-macos-intel:
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-macos-intel -v
# Build for macOS ARM64
build-macos-arm64:
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-macos-arm64 -v
# Build for all platforms
build-all: build-windows build-linux build-linux-arm64 build-macos-intel build-macos-arm64
# Clean build artifacts
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)*
rm -f coverage.out
# Run tests
test:
$(GOTEST) -v -race -coverprofile=coverage.out ./...
# Download dependencies
deps:
$(GOMOD) download
$(GOMOD) verify
# Format code
fmt:
$(GOCMD) fmt ./...
# Run linter
lint:
golangci-lint run
# Run the binary
run: build
./$(BINARY_NAME)
# Install locally
install: build
cp $(BINARY_NAME) $(GOPATH)/bin/
# Create release artifacts
release: clean deps test build-all
# Development setup
dev-setup:
@echo "Setting up development environment..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Show help
help:
@echo "Available targets:"
@echo " build - Build binary for current platform"
@echo " build-windows - Build binary for Windows"
@echo " build-linux - Build binary for Linux"
@echo " build-linux-arm64- Build binary for Linux ARM64"
@echo " build-macos-intel- Build binary for macOS Intel"
@echo " build-macos-arm64- Build binary for macOS ARM64"
@echo " build-all - Build binaries for all platforms"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " deps - Download dependencies"
@echo " fmt - Format code"
@echo " lint - Run linter"
@echo " run - Build and run binary"
@echo " install - Install binary to GOPATH/bin"
@echo " release - Create release artifacts"
@echo " dev-setup - Setup development environment"
@echo " help - Show this help message"