-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
226 lines (204 loc) · 8.26 KB
/
Copy pathMakefile
File metadata and controls
226 lines (204 loc) · 8.26 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
# RequestBite rbite Makefile
# Cross-platform build automation for macOS, Linux, and Windows
ENV_FILE ?= .env.dev
-include $(ENV_FILE)
export
# Extract version from git tag (strip 'v' prefix), fallback to "dev"
# If on exact tag like v1.2.3, VERSION = 1.2.3
# If ahead of tag, VERSION = 1.2.3-abc1234 (tag-commit)
# If no tags, VERSION = dev
# Use environment variable VERSION if already set (e.g., from CI/CD)
VERSION ?= $(shell if git describe --tags --exact-match 2>/dev/null >/dev/null; then \
git describe --tags --exact-match | sed 's/^v//'; \
else \
git describe --tags 2>/dev/null | sed 's/^v//' | sed 's/-[0-9]\+-g/-/' || echo "dev"; \
fi)
# Binary name
BINARY_NAME := rbite
# Build metadata
BUILD_TIME := $(shell date -u '+%Y-%m-%d %H:%M:%S UTC')
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Build flags
LDFLAGS := -s -w \
-X 'main.Version=$(VERSION)' \
-X 'main.BuildTime=$(BUILD_TIME)' \
-X 'main.GitCommit=$(GIT_COMMIT)' \
-X 'main.DefaultAPIHostname=$(API_HOSTNAME)' \
-X 'main.DefaultAPIURL=$(REQUESTBITE_API_URL)' \
-X 'main.DefaultHQURL=$(HQ_URL)' \
-X 'main.DefaultOAuthClientID=$(OAUTH_CLIENT_ID)' \
-X 'main.DefaultOAuthScopes=$(OAUTH_SCOPES)' \
-X 'main.DefaultOAuthCallbackURL=$(OAUTH_CALLBACK_URL)'
BUILD_FLAGS := -ldflags="$(LDFLAGS)" -trimpath
# Target platforms
PLATFORMS := \
darwin/amd64 \
darwin/arm64 \
linux/amd64 \
windows/amd64
# Output directories
BUILD_DIR := build
DIST_DIR := dist
# Colors for output
COLOR_RESET := \033[0m
COLOR_BOLD := \033[1m
COLOR_GREEN := \033[32m
COLOR_BLUE := \033[34m
COLOR_YELLOW := \033[33m
.PHONY: all build build-all release clean install dev dev-web build-web help
# Default target
all: build
# Build the file-browser web assets (requires Node.js + npm)
build-web:
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Building file browser web assets...$(COLOR_RESET)"
@cd web && npm install --silent && node build.js
@echo "$(COLOR_GREEN)✓ Web assets built: cmd/rbite/web/index.html$(COLOR_RESET)"
# Build for current platform (development)
build:
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Building $(BINARY_NAME) v$(VERSION) for current platform...$(COLOR_RESET)"
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/rbite
@echo "$(COLOR_GREEN)✓ Build complete: $(BUILD_DIR)/$(BINARY_NAME)$(COLOR_RESET)"
# Build for all platforms
build-all: clean
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Building $(BINARY_NAME) v$(VERSION) for all platforms...$(COLOR_RESET)"
@mkdir -p $(BUILD_DIR)
@$(foreach platform,$(PLATFORMS),\
$(call build_platform,$(platform)))
@echo "$(COLOR_GREEN)✓ All builds complete$(COLOR_RESET)"
@echo ""
@echo "Built binaries:"
@ls -lh $(BUILD_DIR)/$(BINARY_NAME)-*
# Build for a specific platform (internal function)
define build_platform
$(eval OS := $(word 1,$(subst /, ,$(1))))
$(eval ARCH := $(word 2,$(subst /, ,$(1))))
$(eval OUTPUT := $(BUILD_DIR)/$(BINARY_NAME)-$(VERSION)-$(OS)-$(ARCH)$(if $(filter windows,$(OS)),.exe,))
@echo " Building for $(OS)/$(ARCH)..."
@CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build $(BUILD_FLAGS) -o $(OUTPUT) ./cmd/rbite
endef
# Create release archives and checksums
release: build-all
@echo ""
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Creating release archives...$(COLOR_RESET)"
@mkdir -p $(DIST_DIR)
@cd $(BUILD_DIR) && \
for binary in $(BINARY_NAME)-$(VERSION)-*; do \
if [ -f "$$binary" ]; then \
base=$$(basename "$$binary"); \
os_arch=$$(echo "$$base" | sed 's/$(BINARY_NAME)-$(VERSION)-//'); \
\
if echo "$$os_arch" | grep -q "windows"; then \
archive="$(BINARY_NAME)-$(VERSION)-$${os_arch%.exe}.zip"; \
echo " Creating $$archive..."; \
cp ../LICENSE . 2>/dev/null || true; \
cp ../README.md . 2>/dev/null || true; \
zip -q "../$(DIST_DIR)/$$archive" "$$binary" LICENSE README.md 2>/dev/null || zip -q "../$(DIST_DIR)/$$archive" "$$binary"; \
rm -f LICENSE README.md; \
else \
archive="$(BINARY_NAME)-$(VERSION)-$$os_arch.tar.gz"; \
echo " Creating $$archive..."; \
temp_dir="$(BINARY_NAME)"; \
mkdir -p "$$temp_dir"; \
cp "$$binary" "$$temp_dir/$(BINARY_NAME)"; \
cp ../LICENSE "$$temp_dir/" 2>/dev/null || true; \
cp ../README.md "$$temp_dir/" 2>/dev/null || true; \
cp -r ../completions "$$temp_dir/" 2>/dev/null || true; \
cp -r ../man "$$temp_dir/" 2>/dev/null || true; \
tar -czf "../$(DIST_DIR)/$$archive" "$$temp_dir"; \
rm -rf "$$temp_dir"; \
fi; \
fi; \
done
@echo ""
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Generating checksums...$(COLOR_RESET)"
@cd $(DIST_DIR) && \
if command -v shasum >/dev/null 2>&1; then \
shasum -a 256 *.tar.gz *.zip 2>/dev/null > SHA256SUMS; \
else \
sha256sum *.tar.gz *.zip 2>/dev/null > SHA256SUMS; \
fi
@echo "$(COLOR_GREEN)✓ Release archives created$(COLOR_RESET)"
@echo ""
@echo "Release artifacts:"
@ls -lh $(DIST_DIR)/*.tar.gz $(DIST_DIR)/*.zip 2>/dev/null || true
@echo ""
@echo "Checksums (SHA256SUMS):"
@cat $(DIST_DIR)/SHA256SUMS
# Clean build artifacts
clean:
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Cleaning build artifacts...$(COLOR_RESET)"
@rm -rf $(BUILD_DIR)
@rm -rf $(DIST_DIR)
@rm -rf tmp/
@rm -f build-errors.log
@echo "$(COLOR_GREEN)✓ Clean complete$(COLOR_RESET)"
# Install locally for testing (to ~/.local/bin)
install: build
@echo "$(COLOR_BOLD)$(COLOR_BLUE)Installing $(BINARY_NAME) to ~/.local/bin...$(COLOR_RESET)"
@mkdir -p ~/.local/bin
@cp $(BUILD_DIR)/$(BINARY_NAME) ~/.local/bin/
@chmod +x ~/.local/bin/$(BINARY_NAME)
@echo "$(COLOR_GREEN)✓ Installed to ~/.local/bin/$(BINARY_NAME)$(COLOR_RESET)"
@echo ""
@if echo "$$PATH" | grep -q "$$HOME/.local/bin"; then \
echo "Ready to use: $(BINARY_NAME) --version"; \
else \
echo "$(COLOR_YELLOW)Warning:$(COLOR_RESET) ~/.local/bin is not in your PATH"; \
echo "Add to PATH: export PATH=\"$$HOME/.local/bin:$$PATH\";"; \
fi
# Run with hot reload for both Go and web frontend (requires air + Node.js)
# Usage: make dev-web ARGS="-f ."
dev-web:
@if ! command -v air >/dev/null; then \
echo "Air is not installed. Install it with: go install github.com/air-verse/air@latest"; \
exit 1; \
fi
@node web/watch.js & air -- $(ARGS); kill %1 2>/dev/null; wait
# Run with hot reload (requires air)
# Usage: make dev ARGS="-e 3000"
dev:
@# For --help or --version, run directly without Air
@if echo "$(ARGS)" | grep -qE "(-h|--help|-v|--version)"; then \
echo "$(COLOR_BLUE)Running without hot reload (--help or --version detected)$(COLOR_RESET)"; \
$(MAKE) build > /dev/null 2>&1; \
./$(BUILD_DIR)/$(BINARY_NAME) $(ARGS); \
elif command -v air >/dev/null; then \
air -- $(ARGS); \
else \
echo "Air is not installed. Install it with: go install github.com/air-verse/air@latest"; \
echo "Or run without hot reload using: make build && ./build/$(BINARY_NAME) $(ARGS)"; \
exit 1; \
fi
# Show version
version:
@echo "$(BINARY_NAME) v$(VERSION)"
@echo "Build time: $(BUILD_TIME)"
@echo "Git commit: $(GIT_COMMIT)"
# Show help
help:
@echo "$(COLOR_BOLD)RequestBite rbite - Build System$(COLOR_RESET)"
@echo ""
@echo "$(COLOR_BOLD)Usage:$(COLOR_RESET)"
@echo " make [target]"
@echo ""
@echo "$(COLOR_BOLD)Targets:$(COLOR_RESET)"
@echo " build-web - Build file browser web assets (requires Node.js)"
@echo " build - Build for current platform (default)"
@echo " dev - Run with hot reload using Air (for development)"
@echo " build-all - Build for all platforms (darwin/amd64, darwin/arm64, linux/amd64, windows/amd64)"
@echo " release - Build all platforms and create release archives with checksums"
@echo " clean - Remove all build artifacts"
@echo " install - Install locally to ~/.local/bin (for testing)"
@echo " version - Show version information"
@echo " help - Show this help message"
@echo ""
@echo "$(COLOR_BOLD)Examples:$(COLOR_RESET)"
@echo " make build # Quick build for development"
@echo " make dev # Run with hot reload"
@echo " make dev ARGS="-e 3000" # Run with CLI arguments"
@echo " make build-all # Build for all platforms"
@echo " make release # Create release archives"
@echo " make install # Install locally"
@echo ""
@echo "$(COLOR_BOLD)Current version:$(COLOR_RESET) $(VERSION)"