| Josh Bleecher Snyder | 1c18ec9 | 2025-07-08 10:55:54 -0700 | [diff] [blame] | 1 | # Makefile for building sketch with embedded assets |
| 2 | # |
| 3 | # Two-layer architecture: |
| 4 | # 1. Linux binary ("innie") - runs in container, embeds webui assets |
| 5 | # 2. Native binary ("outie") - runs on user's machine, embeds innie |
| 6 | |
| 7 | BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 8 | COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown") |
| 9 | VERSION := $(shell git describe --tags --dirty --always 2>/dev/null || echo "dev") |
| 10 | LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(BUILD_TIME) -X main.makefile=true |
| 11 | |
| Josh Bleecher Snyder | 973413b | 2025-07-08 19:35:05 +0000 | [diff] [blame^] | 12 | # Support for cross-compilation, used by GoReleaser |
| 13 | GOOS ?= $(shell go env GOOS) |
| 14 | GOARCH ?= $(shell go env GOARCH) |
| 15 | |
| Josh Bleecher Snyder | 1c18ec9 | 2025-07-08 10:55:54 -0700 | [diff] [blame] | 16 | .PHONY: all clean help |
| 17 | .PHONY: outie innie |
| 18 | .PHONY: webui-assets |
| 19 | |
| 20 | all: outie |
| 21 | |
| 22 | outie: innie |
| Josh Bleecher Snyder | 973413b | 2025-07-08 19:35:05 +0000 | [diff] [blame^] | 23 | # Note: This incantation is duplicated in .goreleaser.yml; please keep them in sync. |
| 24 | GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="$(LDFLAGS)" -tags=outie -o sketch ./cmd/sketch |
| Josh Bleecher Snyder | 1c18ec9 | 2025-07-08 10:55:54 -0700 | [diff] [blame] | 25 | |
| 26 | innie: webui-assets |
| Josh Bleecher Snyder | 5ae245b | 2025-07-08 22:00:24 +0000 | [diff] [blame] | 27 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -tags=innie -o embedded/sketch-linux/sketch-linux-amd64 ./cmd/sketch |
| 28 | CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -tags=innie -o embedded/sketch-linux/sketch-linux-arm64 ./cmd/sketch |
| Josh Bleecher Snyder | 1c18ec9 | 2025-07-08 10:55:54 -0700 | [diff] [blame] | 29 | |
| 30 | webui-assets: |
| 31 | rm -rf embedded/webui-dist |
| Josh Bleecher Snyder | 973413b | 2025-07-08 19:35:05 +0000 | [diff] [blame^] | 32 | unset GOOS GOARCH && go run ./cmd/genwebui -- embedded/webui-dist |
| Josh Bleecher Snyder | 1c18ec9 | 2025-07-08 10:55:54 -0700 | [diff] [blame] | 33 | |
| 34 | clean: |
| 35 | @echo "Cleaning build artifacts..." |
| 36 | rm -f sketch |
| 37 | rm -rf embedded/sketch-linux embedded/webui-dist |
| 38 | cd webui && rm -rf node_modules dist |