-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (67 loc) · 3.07 KB
/
Makefile
File metadata and controls
77 lines (67 loc) · 3.07 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
BINARY := openbee
OUTDIR := dist
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
PLATFORMS := \
linux/amd64 \
linux/arm64 \
darwin/amd64 \
darwin/arm64 \
windows/amd64 \
windows/arm64
.PHONY: help web build build-linux-amd64 release clean npm-prepare npm-publish
help: ## Show available targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'
web: ## Build frontend assets
cd web && pnpm install --frozen-lockfile && pnpm build
build: ## Build binary for the current platform
@mkdir -p $(OUTDIR)
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(OUTDIR)/$(BINARY) ./cmd/openbee/
build-linux-amd64: ## Build binary for linux/amd64
@mkdir -p $(OUTDIR)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(OUTDIR)/$(BINARY)-linux-amd64 ./cmd/openbee/
release: web ## Build binaries for all platforms
@mkdir -p $(OUTDIR)
@for platform in $(PLATFORMS); do \
os=$$(echo $$platform | cut -d/ -f1); \
arch=$$(echo $$platform | cut -d/ -f2); \
out=$(OUTDIR)/$(BINARY)-$$os-$$arch; \
if [ "$$os" = "windows" ]; then out=$$out.exe; fi; \
echo " Building $$out..."; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -ldflags "$(LDFLAGS)" -o $$out ./cmd/openbee/ || exit 1; \
done
@echo "Done. Artifacts in $(OUTDIR)/"
clean: ## Remove build artifacts
rm -rf $(OUTDIR)
npm-prepare: ## Copy extracted dist/ binaries into npm package dirs and set version
@VERSION=$(shell git describe --tags --always --dirty | sed 's/^v//'); \
mkdir -p \
npm/packages/cli-linux-x64/bin \
npm/packages/cli-linux-arm64/bin \
npm/packages/cli-darwin-x64/bin \
npm/packages/cli-darwin-arm64/bin \
npm/packages/cli-win32-x64/bin \
npm/packages/cli-win32-arm64/bin; \
cp $$(find dist -path '*/openbee*linux*amd64*' -name 'openbee') \
npm/packages/cli-linux-x64/bin/openbee; \
cp $$(find dist -path '*/openbee*linux*arm64*' -name 'openbee') \
npm/packages/cli-linux-arm64/bin/openbee; \
cp $$(find dist -path '*/openbee*darwin*amd64*' -name 'openbee') \
npm/packages/cli-darwin-x64/bin/openbee; \
cp $$(find dist -path '*/openbee*darwin*arm64*' -name 'openbee') \
npm/packages/cli-darwin-arm64/bin/openbee; \
cp $$(find dist -path '*/openbee*windows*amd64*' -name 'openbee.exe') \
npm/packages/cli-win32-x64/bin/openbee.exe; \
cp $$(find dist -path '*/openbee*windows*arm64*' -name 'openbee.exe') \
npm/packages/cli-win32-arm64/bin/openbee.exe; \
chmod +x \
npm/packages/cli-linux-x64/bin/openbee \
npm/packages/cli-linux-arm64/bin/openbee \
npm/packages/cli-darwin-x64/bin/openbee \
npm/packages/cli-darwin-arm64/bin/openbee; \
node npm/scripts/set-version.js $$VERSION; \
cp README.md npm/packages/cli/README.md
npm-publish: npm-prepare ## Publish all npm packages to registry
bash npm/scripts/publish.sh