-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (205 loc) · 9.11 KB
/
Makefile
File metadata and controls
251 lines (205 loc) · 9.11 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# FlashORM CLI Makefile
# Variables
BINARY_NAME=flash
BINARY_UNIX=$(BINARY_NAME)_unix
BINARY_WINDOWS=$(BINARY_NAME).exe
BUILD_DIR=build
LDFLAGS=-s -w -extldflags "-static"
# ============================================
# Development & Production Builds
# ============================================
# Development build - all features included, no plugins needed
.PHONY: dev
dev:
@echo "🔧 Building DEVELOPMENT version (all features included)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build -tags="dev" -o $(BUILD_DIR)/flash-dev .
@echo "✅ Development build complete: $(BUILD_DIR)/flash-dev"
@echo " Usage: ./$(BUILD_DIR)/flash-dev <command>"
@echo " All commands available without plugins"
# Production build - minimal core only
.PHONY: prod
prod:
@echo "📦 Building PRODUCTION version (core only)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash .
@echo "✅ Production build complete: $(BUILD_DIR)/flash"
@echo " Usage: ./$(BUILD_DIR)/flash add-plugin core"
@echo " Requires plugins for full functionality"
# Install dev version locally
.PHONY: install-dev
install-dev: dev
@echo "Installing development version to $(GOPATH)/bin..."
cp $(BUILD_DIR)/flash-dev $(GOPATH)/bin/flash
@echo "✅ Installed: flash (dev mode)"
# Install prod version locally
.PHONY: install-prod
install-prod: prod
@echo "Installing production version to $(GOPATH)/bin..."
cp $(BUILD_DIR)/flash $(GOPATH)/bin/flash
@echo "✅ Installed: flash (prod mode)"
# ============================================
# Cross-Platform Builds
# ============================================
# Default target now builds for all platforms
.PHONY: all
all: clean build-all
# Build for multiple platforms
.PHONY: build-all
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
# Linux AMD64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-linux-amd64 .
# Linux ARM64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-linux-arm64 .
# Windows AMD64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-windows-amd64.exe .
# macOS AMD64
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-darwin-amd64 .
# macOS ARM64
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-darwin-arm64 .
@echo "Cross-platform build complete in $(BUILD_DIR)/"
# Build core CLI only (lightweight version)
.PHONY: build-core
build-core:
@echo "Building core CLI for multiple platforms..."
@mkdir -p $(BUILD_DIR)
# Linux AMD64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-core-linux-amd64 .
# Linux ARM64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-core-linux-arm64 .
# Windows AMD64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-core-windows-amd64.exe .
# macOS AMD64
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-core-darwin-amd64 .
# macOS ARM64
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -trimpath -o $(BUILD_DIR)/flash-core-darwin-arm64 .
@echo "Core CLI build complete in $(BUILD_DIR)/"
# Build all plugins
.PHONY: build-plugins
build-plugins: build-plugin-core build-plugin-studio
@echo "All plugins built successfully!"
# Build 'core' plugin (ORM features without studio)
.PHONY: build-plugin-core
build-plugin-core:
@echo "Building 'core' plugin..."
@mkdir -p $(BUILD_DIR)
# Linux AMD64
cd plugins/core && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags=plugin_core -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-core-linux-amd64 .
# Linux ARM64
cd plugins/core && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags=plugin_core -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-core-linux-arm64 .
# Windows AMD64
cd plugins/core && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags=plugin_core -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-core-windows-amd64.exe .
# macOS AMD64
cd plugins/core && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags=plugin_core -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-core-darwin-amd64 .
# macOS ARM64
cd plugins/core && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags=plugin_core -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-core-darwin-arm64 .
# Build studio plugin
.PHONY: build-plugin-studio
build-plugin-studio:
@echo "Building studio plugin..."
@mkdir -p $(BUILD_DIR)
# Linux AMD64
cd plugins/studio && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags=plugin_studio -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-studio-linux-amd64 .
# Linux ARM64
cd plugins/studio && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags=plugin_studio -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-studio-linux-arm64 .
# Windows AMD64
cd plugins/studio && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags=plugin_studio -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-studio-windows-amd64.exe .
# macOS AMD64
cd plugins/studio && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags=plugin_studio -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-studio-darwin-amd64 .
# macOS ARM64
cd plugins/studio && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags=plugin_studio -ldflags="$(LDFLAGS)" -trimpath -o ../../$(BUILD_DIR)/flash-plugin-studio-darwin-arm64 .
# Compress binaries with UPX (optional - requires UPX installed)
.PHONY: compress
compress: build-all
@echo "Compressing binaries with UPX..."
@if command -v upx &> /dev/null; then \
upx --best --lzma $(BUILD_DIR)/flash-linux-amd64; \
upx --best --lzma $(BUILD_DIR)/flash-linux-arm64; \
upx --best --lzma $(BUILD_DIR)/flash-windows-amd64.exe; \
upx --best --lzma $(BUILD_DIR)/flash-darwin-amd64; \
upx --best --lzma $(BUILD_DIR)/flash-darwin-arm64; \
echo "Compression complete!"; \
else \
echo "UPX not found. Install from https://upx.github.io/"; \
echo "Skipping compression..."; \
fi
# Install the binary to GOPATH/bin (Linux build used by default)
.PHONY: install
install: build-all
@echo "Installing $(BINARY_NAME) (Linux version) to $(GOPATH)/bin..."
cp $(BUILD_DIR)/$(BINARY_UNIX) $(GOPATH)/bin/$(BINARY_NAME)
@echo "Installation complete"
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BINARY_NAME) $(BINARY_UNIX) $(BINARY_WINDOWS) $(BUILD_DIR) release
@echo "Clean complete"
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v ./...
# Download dependencies
.PHONY: deps
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
# Lint code
.PHONY: lint
lint:
@echo "Linting code..."
golangci-lint run
# Run the CLI with help (Linux binary used by default)
.PHONY: run
run: build-all
./$(BUILD_DIR)/$(BINARY_UNIX) --help
# Development setup
.PHONY: dev-setup
dev-setup: deps
@echo "Setting up development environment..."
@if ! command -v golangci-lint &> /dev/null; then \
echo "Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@echo "Development setup complete"
# Create a release
.PHONY: release
release: clean build-all
@echo "Creating release..."
@mkdir -p release
@cp $(BUILD_DIR)/* release/
@echo "Release created in release/"
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean and build for all platforms"
@echo " build-all - Build flash CLI for multiple platforms"
@echo " build-plugins - Build core + studio plugins for all platforms"
@echo " build-plugin-core - Build only the core plugin"
@echo " build-plugin-studio - Build only the studio plugin"
@echo " compress - Compress binaries with UPX (requires UPX)"
@echo " install - Install Linux binary to GOPATH/bin"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " deps - Download dependencies"
@echo " fmt - Format code"
@echo " lint - Lint code"
@echo " run - Build and run Linux binary with --help"
@echo " dev-setup - Setup development environment"
@echo " release - Create release build"
@echo " help - Show this help"
@echo ""
@echo "Plugin note: only 'core' and 'studio' plugins exist."
@echo " core is auto-installed on first ORM command use."
@echo " studio must be installed with: flash add-plug studio"
@echo " Both can be updated at once with: flash update"