-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (77 loc) · 3.21 KB
/
Copy pathMakefile
File metadata and controls
93 lines (77 loc) · 3.21 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
# gorch Makefile
#
# Targets:
# make one — local build (APP + all COMMANDS)
# make build — cross-compile for darwin/linux/windows (arm64/amd64)
# make all — clean → one → build (full pipeline)
# make front — build frontend only
# make run — build frontend + go run
# make dev — hot-reload dev server (air + vite dev)
# make clean — remove build artifacts
# make test — run Go tests
# make lint — run golangci-lint
# make tidy — run go mod tidy
#
# Test:
# ./test_makefile.sh
# ── Project config ────────────────────────────────────────
# main binary name (built from ./)
APP = gorch
# frontend directory
ADMIN_DIR = webui
# auto-discover cmd/ subdirs
COMMANDS := $(notdir $(patsubst %/.,%,$(wildcard cmd/*/.)))
# ── Build flags ───────────────────────────────────────────
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
RELEASE = -ldflags "-s -w -X main.version=$(VERSION)"
GOBUILD = go build $(RELEASE)
# ── Targets ───────────────────────────────────────────────
.PHONY: one all front build run dev clean test lint tidy
## one: local single-platform build (CGO disabled, current OS/ARCH)
one: front
@echo "Build $(APP) (local) ..."
mkdir -p bin
CGO_ENABLED=0 $(GOBUILD) -o bin/$(APP) ./
@for cmd in $(COMMANDS); do \
CGO_ENABLED=0 $(GOBUILD) -o bin/$$cmd ./cmd/$$cmd; \
done
## all: full pipeline — clean, then local build, then cross-compile
all: clean one build
## build: cross-compile APP + all COMMANDS for 5 platforms
build: front
@echo "Cross-compiling ..."
mkdir -p bin
@for target in $(APP) $(COMMANDS); do \
if [ "$$target" = "$(APP)" ]; then src=.; else src=./cmd/$$target; fi; \
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GOBUILD) -o bin/$$target-$(VERSION).darwin-arm64 $$src && \
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o bin/$$target-$(VERSION).darwin-amd64 $$src && \
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GOBUILD) -o bin/$$target-$(VERSION).linux-arm64 $$src && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o bin/$$target-$(VERSION).linux-amd64 $$src; \
done
@echo "✅ Build success."
## front: build frontend assets (tsc type-check + vite build)
front:
@echo "Build frontend ..."
cd $(ADMIN_DIR) && npm run build
## run: build frontend then run main with go run
run: front
go run ./
## dev: start hot-reload backend (air) + frontend dev server (vite)
dev:
@which air > /dev/null 2>&1 || go install github.com/air-verse/air@latest
@if [ ! -d "$(ADMIN_DIR)/node_modules" ]; then cd $(ADMIN_DIR) && npm install; fi
(cd $(ADMIN_DIR) && npm run dev &)
air
## clean: remove build artifacts and frontend dist
clean:
rm -rf bin/* tmp/* $(ADMIN_DIR)/dist
@echo "✅ Clean complete."
## test: run Go tests with verbose output (52 tests across 5 packages)
test:
go test ./... -v
## lint: run golangci-lint on entire project
lint:
golangci-lint run ./...
## tidy: clean up go.mod dependencies
tidy:
go mod tidy