-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathMakefile
More file actions
227 lines (203 loc) · 7.21 KB
/
Makefile
File metadata and controls
227 lines (203 loc) · 7.21 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Flint Makefile
.PHONY: all install build web-build deps check-go check-bun test test-verbose test-cover lint fmt vet clean dev-setup run dev build-musl-amd64 build-musl-arm64 help
# Default target
all: build
# Install all dependencies, build everything, and install to system
install: deps web-build build
@echo "📦 Installing flint to /usr/local/bin..."
sudo cp flint /usr/local/bin/
sudo chmod +x /usr/local/bin/flint
@echo "✅ Flint installed successfully!"
@echo "🚀 Run 'flint serve' to get started"
# Install Go dependencies and check for bun
deps: check-go
@echo "📥 Installing Go dependencies..."
go mod download
go mod tidy
@$(MAKE) check-bun
# Check if Go is installed, install if not
check-go:
@echo "🔍 Checking for Go..."
@if ! command -v go >/dev/null 2>&1; then \
echo "📦 Installing Go 1.25.1..."; \
$(MAKE) install-go; \
echo "✅ Go installed successfully"; \
echo "⚠️ Please restart your shell or run: source ~/.profile"; \
else \
echo "✅ Go is already installed ($$(go version))"; \
fi
# Install Go based on OS and architecture
install-go:
@echo "🔍 Detecting OS and architecture..."
@OS=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
ARCH=$$(uname -m); \
case $$ARCH in \
x86_64) ARCH="amd64" ;; \
aarch64|arm64) ARCH="arm64" ;; \
*) echo "❌ Unsupported architecture: $$ARCH"; exit 1 ;; \
esac; \
case $$OS in \
linux) \
echo "🐧 Installing Go for Linux ($$ARCH)..."; \
wget -q https://go.dev/dl/go1.25.1.linux-$$ARCH.tar.gz -O /tmp/go1.25.1.tar.gz; \
sudo rm -rf /usr/local/go; \
sudo tar -C /usr/local -xzf /tmp/go1.25.1.tar.gz; \
rm /tmp/go1.25.1.tar.gz; \
echo "export PATH=\$$PATH:/usr/local/go/bin" >> ~/.profile; \
export PATH=$$PATH:/usr/local/go/bin; \
echo "🔄 Added Go to PATH in ~/.profile"; \
;; \
darwin) \
echo "🍎 Installing Go for macOS ($$ARCH)..."; \
curl -L https://go.dev/dl/go1.25.1.darwin-$$ARCH.tar.gz -o /tmp/go1.25.1.tar.gz; \
sudo rm -rf /usr/local/go; \
sudo tar -C /usr/local -xzf /tmp/go1.25.1.tar.gz; \
rm /tmp/go1.25.1.tar.gz; \
echo "export PATH=\$$PATH:/usr/local/go/bin" >> ~/.profile; \
export PATH=$$PATH:/usr/local/go/bin; \
echo "🔄 Added Go to PATH in ~/.profile"; \
;; \
*) \
echo "❌ Unsupported OS: $$OS"; \
echo "Please install Go manually from https://golang.org/dl/"; \
exit 1; \
;; \
esac
# Check if bun is installed, install if not
check-bun:
@echo "🔍 Checking for bun..."
@if ! command -v bun >/dev/null 2>&1; then \
echo "📦 Installing bun..."; \
curl -fsSL https://bun.sh/install | bash; \
echo "✅ Bun installed successfully"; \
echo "⚠️ Please restart your shell or run: source ~/.bashrc"; \
echo "🔄 Attempting to use bun from ~/.bun/bin/bun"; \
export PATH="$$HOME/.bun/bin:$$PATH"; \
else \
echo "✅ Bun is already installed"; \
fi
@echo "📥 Installing web dependencies..."
@if command -v bun >/dev/null 2>&1; then \
cd web && bun install; \
else \
echo "🔄 Using bun from ~/.bun/bin/bun"; \
cd web && ~/.bun/bin/bun install; \
fi
# Build web assets (required before Go build)
web-build:
@echo "🌐 Building web assets..."
@if command -v bun >/dev/null 2>&1; then \
cd web && bun run build; \
else \
echo "🔄 Using bun from ~/.bun/bin/bun"; \
cd web && ~/.bun/bin/bun run build; \
fi
@echo "✅ Web assets built successfully"
# Build the Go binary (requires web assets to be built first)
build: web-build
@echo "🔨 Building flint binary..."
go build -ldflags="-s -w" -o flint .
@echo "✅ Flint binary built successfully"
# Development build (faster, no web rebuild)
dev:
@echo "🔨 Building flint binary (development mode)..."
go build -ldflags="-s -w" -o flint .
@echo "✅ Development build complete"
# Clean build artifacts
clean:
@echo "🧹 Cleaning build artifacts..."
go clean
rm -f flint
rm -rf web/out
rm -rf web/.next
@echo "✅ Clean complete"
# Test targets
test:
go test ./...
test-verbose:
go test -v ./...
test-cover:
go test -cover ./...
# Code quality targets
lint:
golangci-lint run
fmt:
go fmt ./...
vet:
go vet ./...
check: fmt vet lint test
# Development helpers
dev-setup:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
run:
go run main.go serve
# Alias for backwards compatibility
install-deps: deps
# Build musl binary for Alpine Linux (amd64)
build-musl-amd64: web-build
@echo "🐧 Building musl binary for Alpine Linux (amd64)..."
@echo "🐳 Using Alpine Docker container for musl compilation..."
docker run --rm --platform linux/amd64 \
-v "$(PWD)":/src \
-w /src \
alpine:3.19 \
sh -c ' \
set -e && \
echo "📦 Installing build dependencies..." && \
apk add --no-cache go libvirt-dev pkgconfig gcc musl-dev && \
echo "🔨 Building flint with musl..." && \
CGO_ENABLED=1 go build -ldflags="-s -w" -o flint-musl-amd64 . && \
echo "✅ musl binary built: flint-musl-amd64" \
'
@echo "✅ Alpine Linux (amd64) musl binary built successfully"
# Build musl binary for Alpine Linux (arm64)
build-musl-arm64: web-build
@echo "🐧 Building musl binary for Alpine Linux (arm64)..."
@echo "🐳 Using Alpine Docker container for musl compilation..."
docker run --rm --platform linux/arm64 \
-v "$(PWD)":/src \
-w /src \
alpine:3.19 \
sh -c ' \
set -e && \
echo "📦 Installing build dependencies..." && \
apk add --no-cache go libvirt-dev pkgconfig gcc musl-dev && \
echo "🔨 Building flint with musl..." && \
CGO_ENABLED=1 go build -ldflags="-s -w" -o flint-musl-arm64 . && \
echo "✅ musl binary built: flint-musl-arm64" \
'
@echo "✅ Alpine Linux (arm64) musl binary built successfully"
# Help target
help:
@echo "🌀 Flint Build System"
@echo ""
@echo "🚀 One-command install: make install"
@echo ""
@echo "Available targets:"
@echo " install - Install Go (if needed), bun (if needed), dependencies, build everything, and install to /usr/local/bin"
@echo " build - Build web assets and Go binary"
@echo " web-build - Build only web assets"
@echo " dev - Quick build (Go binary only, assumes web assets exist)"
@echo " build-musl-amd64 - Build musl binary for Alpine Linux (amd64) via Docker"
@echo " build-musl-arm64 - Build musl binary for Alpine Linux (arm64) via Docker"
@echo " deps - Install Go, bun, and all dependencies"
@echo " check-go - Check for Go installation, install if missing"
@echo " check-bun - Check for bun installation, install if missing"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " test-verbose - Run tests with verbose output"
@echo " test-cover - Run tests with coverage"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " check - Run fmt, vet, lint, and test"
@echo " dev-setup - Install development tools"
@echo " run - Run flint serve"
@echo " help - Show this help"
@echo ""
@echo "📋 Automatic installations:"
@echo " • Go 1.25.1 (Linux amd64/arm64, macOS amd64/arm64)"
@echo " • Bun (JavaScript runtime)"
@echo " • All Go and web dependencies"
@echo ""
@echo "🚀 Quick start: make install"