-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (116 loc) Β· 4.18 KB
/
Copy pathMakefile
File metadata and controls
140 lines (116 loc) Β· 4.18 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Makefile for tcsh - WebSocket Shell
# Cross-platform build targets for Linux, macOS, and Windows
# Binary name
BINARY_NAME=tcsh
MODULE_NAME=github.com/fabricates/tcsh
# Version (can be overridden: make VERSION=1.0.0)
VERSION?=dev
COMMIT?=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME?=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
# Build flags
LDFLAGS=-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildTime=$(BUILD_TIME)
# Output directory
OUT_DIR=bin
.PHONY: all clean build linux darwin windows \
linux-amd64 linux-arm64 \
darwin-amd64 darwin-arm64 \
windows-amd64 windows-arm64 \
install test help
# Default target
all: clean build
# Build for current platform
build:
@echo "Building for current platform..."
@mkdir -p $(OUT_DIR)
go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME) .
@echo "Build complete: $(OUT_DIR)/$(BINARY_NAME)"
# Install to GOPATH/bin
install:
@echo "Installing $(BINARY_NAME)..."
go install -ldflags "$(LDFLAGS)" .
@echo "Installed to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
# Build for all platforms
cross-compile: linux darwin windows
@echo "Cross-compilation complete!"
# Linux builds
linux: linux-amd64 linux-arm64
linux-amd64:
@echo "Building for Linux amd64..."
@mkdir -p $(OUT_DIR)
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME)-linux-amd64 .
linux-arm64:
@echo "Building for Linux arm64..."
@mkdir -p $(OUT_DIR)
GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME)-linux-arm64 .
# macOS builds
darwin: darwin-amd64 darwin-arm64
darwin-amd64:
@echo "Building for macOS amd64..."
@mkdir -p $(OUT_DIR)
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME)-darwin-amd64 .
darwin-arm64:
@echo "Building for macOS arm64 (Apple Silicon)..."
@mkdir -p $(OUT_DIR)
GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME)-darwin-arm64 .
# Windows builds
windows: windows-amd64 windows-arm64
windows-amd64:
@echo "Building for Windows amd64..."
@mkdir -p $(OUT_DIR)
GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME)-windows-amd64.exe .
windows-arm64:
@echo "Building for Windows arm64..."
@mkdir -p $(OUT_DIR)
GOOS=windows GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(OUT_DIR)/$(BINARY_NAME)-windows-arm64.exe .
# Run tests
test:
@echo "Running tests..."
go test -v ./...
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(OUT_DIR)
@rm -f $(BINARY_NAME)
@echo "Clean complete"
# Tidy dependencies
tidy:
@echo "Tidying go modules..."
go mod tidy
# Format code
fmt:
@echo "Formatting code..."
go fmt ./...
# Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found. Install: https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run
# Show help
help:
@echo "Available targets:"
@echo " make build - Build for current platform"
@echo " make install - Install to GOPATH/bin"
@echo " make cross-compile - Build for all platforms"
@echo " make linux - Build for Linux (amd64, arm64)"
@echo " make darwin - Build for macOS (amd64, arm64)"
@echo " make windows - Build for Windows (amd64, arm64)"
@echo " make linux-amd64 - Build for Linux amd64"
@echo " make linux-arm64 - Build for Linux arm64"
@echo " make darwin-amd64 - Build for macOS amd64"
@echo " make darwin-arm64 - Build for macOS arm64 (Apple Silicon)"
@echo " make windows-amd64 - Build for Windows amd64"
@echo " make windows-arm64 - Build for Windows arm64"
@echo " make test - Run tests"
@echo " make clean - Remove build artifacts"
@echo " make tidy - Tidy go modules"
@echo " make fmt - Format code"
@echo " make lint - Run linter (requires golangci-lint)"
@echo " make help - Show this help message"
@echo ""
@echo "Variables:"
@echo " VERSION=x.y.z - Set version (default: dev)"
@echo ""
@echo "Examples:"
@echo " make build"
@echo " make cross-compile"
@echo " make VERSION=1.0.0 linux-amd64"