Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (70 loc) · 2.42 KB
/
Copy pathMakefile
File metadata and controls
90 lines (70 loc) · 2.42 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
SHELL := /usr/bin/env bash
APP := loadout
BIN := bin/$(APP)
PKG := github.com/AxeForging/loadout
DIST := dist
# Version — can be overridden from environment
ifeq ($(origin VERSION), environment)
else
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
endif
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILT_BY := $(shell whoami)
LDFLAGS := -s -w \
-X $(PKG)/internal/build.Version=$(VERSION) \
-X $(PKG)/internal/build.Commit=$(GIT_COMMIT) \
-X $(PKG)/internal/build.Date=$(BUILD_TIME) \
-X $(PKG)/internal/build.BuiltBy=$(BUILT_BY)
GOOS_ARCH := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
.PHONY: all build build-all build-web run test test-integration lint fmt format tidy clean ci version tag
all: build
build:
@mkdir -p bin
CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN) ./cmd/$(APP)
@echo "Built $(BIN) ($(VERSION))"
build-all:
@mkdir -p $(DIST)
@echo "Building for all platforms..."
@for t in $(GOOS_ARCH); do \
os=$${t%/*}; arch=$${t#*/}; \
bin_path=$(DIST)/$(APP)-$${os}-$${arch}; \
echo " $$os/$$arch → $$bin_path"; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -trimpath -ldflags "$(LDFLAGS)" -o $$bin_path ./cmd/$(APP); \
done
@echo "Done. Binaries in $(DIST)/"
# Rebuild the SPA into internal/web/dist. The dist output is COMMITTED so
# plain `go build` / `go install` ship the real UI — run this (and commit)
# whenever web/ changes.
build-web:
cd web && pnpm install && pnpm build
run: build
@$(BIN) $(ARGS)
test:
go test -race -count=1 ./...
test-integration:
cd integration && go test -v -tags integration -count=1 ./... -timeout 120s
lint:
golangci-lint run --timeout=5m
fmt:
go fmt ./...
format: fmt
@command -v gofumpt >/dev/null 2>&1 && gofumpt -w . || echo "gofumpt not installed, skipping"
@command -v goimports >/dev/null 2>&1 && goimports -w . || echo "goimports not installed, skipping"
tidy:
go mod tidy
clean:
rm -rf bin $(DIST)
ci: tidy lint test build
version:
@echo "Version: $(VERSION)"
@echo "Commit: $(GIT_COMMIT)"
@echo "Build time: $(BUILD_TIME)"
@echo "Built by: $(BUILT_BY)"
tag:
@if [ "$(VERSION)" = "dev" ]; then \
echo "Error: Set VERSION env var (e.g., VERSION=v0.1.0 make tag)"; \
exit 1; \
fi
git tag -a $(VERSION) -m "Release $(VERSION)"
@echo "Tag created. Push with: git push origin $(VERSION)"