Makefile (2430B)
1 .PHONY: build clean fmt test vendor dist 2 .ONESHELL: 3 4 BINARY := bin/marky 5 SRC := cmd/marky.go 6 7 # Tag-derived version (strip leading v) 8 VER := $(shell git describe --tags --exact-match 2>/dev/null || git tag --points-at HEAD | head -n1) 9 V := $(patsubst v%,%,$(VER)) 10 OUTDIR := dist 11 12 # All Go sources in repo (used to decide when to rebuild the binary) 13 GO_SOURCES := $(shell find . -type f -name '*.go') 14 # Embedded assets (served via go:embed) 15 WEB_ASSETS := $(shell [ -d internal/web ] && find internal/web -type f -print || echo) 16 MIGRATIONS := $(shell [ -d internal/migrations ] && find internal/migrations -type f -name '*.sql' -print || echo) 17 18 build: $(BINARY) 19 20 $(BINARY): $(GO_SOURCES) $(WEB_ASSETS) $(MIGRATIONS) 21 mkdir -p $(dir $(BINARY)) 22 go build -o $(BINARY) $(SRC) 23 24 clean: 25 rm -f $(BINARY) 26 27 fmt: 28 gofmt -s -w . 29 30 test: 31 GOFLAGS=-count=1 go test -cover -coverprofile=coverage.out ./... 32 @echo "" 33 @go tool cover -func=coverage.out | tail -n 1 34 35 .PHONY: vendor 36 vendor: 37 @mkdir -p internal/web/vendor 38 @echo "Fetching Vue..." 39 @curl -fsSL https://unpkg.com/vue@3/dist/vue.global.prod.js -o internal/web/vendor/vue.global.prod.js 40 @echo "Fetching marked..." 41 @curl -fsSL https://cdn.jsdelivr.net/npm/marked/marked.min.js -o internal/web/vendor/marked.min.js 42 @echo "Fetching DOMPurify..." 43 @curl -fsSL https://cdn.jsdelivr.net/npm/[email protected]/dist/purify.min.js -o internal/web/vendor/purify.min.js 44 @echo "Vendored frontend libraries updated." 45 46 # Build release binaries for the current tag (if any) 47 dist: 48 @if [ -z "$(VER)" ]; then echo "No tag found."; exit 1; fi 49 @echo "Building marky $(V) artifacts..." 50 @mkdir -p $(OUTDIR) 51 # linux/amd64 52 @rm -rf $(OUTDIR)/.stage_linux_amd64 && mkdir -p $(OUTDIR)/.stage_linux_amd64 53 @CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o "$(OUTDIR)/.stage_linux_amd64/marky" $(SRC) 54 @tar -C "$(OUTDIR)/.stage_linux_amd64" -czf "$(OUTDIR)/marky_$(V)_linux_amd64.tar.gz" marky 55 @rm -rf "$(OUTDIR)/.stage_linux_amd64" 56 # darwin/arm64 57 @rm -rf $(OUTDIR)/.stage_darwin_arm64 && mkdir -p $(OUTDIR)/.stage_darwin_arm64 58 @GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o "$(OUTDIR)/.stage_darwin_arm64/marky" $(SRC) 59 @tar -C "$(OUTDIR)/.stage_darwin_arm64" -czf "$(OUTDIR)/marky_$(V)_darwin_arm64.tar.gz" marky 60 @rm -rf "$(OUTDIR)/.stage_darwin_arm64" 61 @echo "Artifacts written to $(OUTDIR): marky_$(V)_linux_amd64.tar.gz, marky_$(V)_darwin_arm64.tar.gz"