-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (138 loc) · 4.57 KB
/
Copy pathMakefile
File metadata and controls
165 lines (138 loc) · 4.57 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
BINARY := tinycode
MODULE := github.com/bobbyjohnstx/tinycode
MAIN := ./cmd/tinycode
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
PLUGIN_DIRS := $(wildcard cmd/plugin-*)
PLUGIN_NAMES := $(notdir $(PLUGIN_DIRS))
.PHONY: build build-all build-plugins build-full clean test vet lint fmt check build-webapp embed-webapp package image image-full
## build: Build tinycode for the current platform
build:
go build -ldflags "$(LDFLAGS)" -o dist/$(BINARY) $(MAIN)
## build-plugins: Build all plugins for the current platform
build-plugins:
@for dir in $(PLUGIN_DIRS); do \
name=$$(basename $$dir); \
echo "Building plugin $$name ..."; \
go build -ldflags "-s -w" -o dist/plugins/$$name ./$$dir; \
done
## build-full: Build tinycode and all plugins for the current platform
build-full: build build-plugins
## build-all: Cross-compile tinycode for all supported platforms
build-all:
@for platform in $(PLATFORMS); do \
os=$${platform%/*}; \
arch=$${platform#*/}; \
ext=""; \
if [ "$$os" = "windows" ]; then ext=".exe"; fi; \
output="dist/$(BINARY)-$${os}-$${arch}$${ext}"; \
echo "Building $$output ..."; \
GOOS=$$os GOARCH=$$arch go build -ldflags "$(LDFLAGS)" -o $$output $(MAIN); \
done
## build-all-plugins: Cross-compile all plugins for all supported platforms
build-all-plugins:
@for platform in $(PLATFORMS); do \
os=$${platform%/*}; \
arch=$${platform#*/}; \
ext=""; \
if [ "$$os" = "windows" ]; then ext=".exe"; fi; \
for dir in $(PLUGIN_DIRS); do \
name=$$(basename $$dir); \
output="dist/plugins/$${name}-$${os}-$${arch}$${ext}"; \
echo "Building plugin $$output ..."; \
GOOS=$$os GOARCH=$$arch go build -ldflags "-s -w" -o $$output ./$$dir; \
done; \
done
## build-all-full: Cross-compile tinycode and all plugins for all platforms
build-all-full: build-all build-all-plugins
## package: Create release archives with tinycode + all plugins for all platforms
package: build-all-full
@mkdir -p dist/release
@for platform in $(PLATFORMS); do \
os=$${platform%/*}; \
arch=$${platform#*/}; \
ext=""; \
if [ "$$os" = "windows" ]; then ext=".exe"; fi; \
archiveName="$(BINARY)-$${os}-$${arch}"; \
stageDir="dist/release/$$archiveName"; \
mkdir -p "$$stageDir/plugins"; \
cp "dist/$(BINARY)-$${os}-$${arch}$${ext}" "$$stageDir/$(BINARY)$${ext}"; \
for dir in $(PLUGIN_DIRS); do \
name=$$(basename $$dir); \
pluginBin="dist/plugins/$${name}-$${os}-$${arch}$${ext}"; \
if [ -f "$$pluginBin" ]; then \
cp "$$pluginBin" "$$stageDir/plugins/$${name}$${ext}"; \
fi; \
done; \
if [ "$$os" = "windows" ]; then \
(cd dist/release && zip -qr "$$archiveName.zip" "$$archiveName"); \
else \
tar -czf "dist/release/$$archiveName.tar.gz" -C dist/release "$$archiveName"; \
fi; \
rm -rf "$$stageDir"; \
done
## test: Run all tests
test:
go test ./... -count=1
## test-race: Run all tests with the race detector
test-race:
go test ./... -count=1 -race -timeout 300s
## test-verbose: Run all tests with verbose output
test-verbose:
go test ./... -v -count=1
## vet: Run go vet
vet:
go vet ./...
## staticcheck: Run staticcheck v0.8.1 (2026.2.1)
staticcheck:
go run honnef.co/go/tools/cmd/staticcheck@v0.8.1 ./...
## fmt: Format Go source code
fmt:
gofmt -w .
## lint: Run go vet and staticcheck
lint: vet staticcheck
## check: Run vet, staticcheck, and tests
check: lint test
## build-webapp: Build SolidJS web app with esbuild (output in packages/app/dist/)
build-webapp:
node script/build-webapp.mjs
## embed-webapp: Build SolidJS web app and embed into Go binary
embed-webapp:
./script/embed-webapp.sh
IMAGE_NAME ?= tinycode
IMAGE_TAG ?= $(VERSION)
## image: Build container image (tinycode only)
image:
podman build \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
-t $(IMAGE_NAME):$(IMAGE_TAG) \
-t $(IMAGE_NAME):latest \
-f Containerfile .
## image-full: Build container image with all plugins
image-full:
podman build \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--build-arg BUILD_PLUGINS=1 \
-t $(IMAGE_NAME):$(IMAGE_TAG)-full \
-t $(IMAGE_NAME):latest-full \
-f Containerfile .
## clean: Remove build artifacts
clean:
rm -rf dist/
go clean
## help: Show this help
help:
@grep -E '^## ' Makefile | sed 's/## //' | column -t -s ':'