1BINARY := arche
2SERVER := arche-server
3CMD := ./cmd/arche
4CMD_SRV := ./cmd/arche-server
5BUILD_DIR := ./bin
6COVER_DIR := ./coverage
7
8CGO_ENABLED := 1
9GOFLAGS :=
10LDFLAGS := -ldflags="-s -w"
11
12TEST_FLAGS := -race -count=1
13COVER_FLAGS := -coverprofile=$(COVER_DIR)/cover.out -covermode=atomic
14
15.DEFAULT_GOAL := help
16
17.PHONY: build
18build:
19 @mkdir -p $(BUILD_DIR)
20 CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY) $(CMD)
21 @echo "✓ Built $(BUILD_DIR)/$(BINARY)"
22 CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(SERVER) $(CMD_SRV)
23 @echo "✓ Built $(BUILD_DIR)/$(SERVER)"
24
25.PHONY: build-debug
26build-debug:
27 @mkdir -p $(BUILD_DIR)
28 CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -gcflags="all=-N -l" -o $(BUILD_DIR)/$(BINARY)-debug $(CMD)
29 @echo "✓ Built $(BUILD_DIR)/$(BINARY)-debug"
30 CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -gcflags="all=-N -l" -o $(BUILD_DIR)/$(SERVER)-debug $(CMD_SRV)
31 @echo "✓ Built $(BUILD_DIR)/$(SERVER)-debug"
32
33.PHONY: build-server
34build-server:
35 @mkdir -p $(BUILD_DIR)
36 CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(SERVER) $(CMD_SRV)
37 @echo "✓ Built $(BUILD_DIR)/$(SERVER)"
38
39.PHONY: build-client
40build-client:
41 @mkdir -p $(BUILD_DIR)
42 CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY) $(CMD)
43 @echo "✓ Built $(BUILD_DIR)/$(BINARY)"
44
45.PHONY: install
46install:
47 CGO_ENABLED=$(CGO_ENABLED) go install $(GOFLAGS) $(LDFLAGS) $(CMD)
48 @echo "✓ Installed arche"
49
50.PHONY: run
51run: build
52 $(BUILD_DIR)/$(BINARY) $(ARGS)
53
54.PHONY: test
55test:
56 CGO_ENABLED=$(CGO_ENABLED) go test $(TEST_FLAGS) ./...
57
58.PHONY: test-short
59test-short:
60 CGO_ENABLED=$(CGO_ENABLED) go test $(TEST_FLAGS) -short ./...
61
62.PHONY: test-pkg
63test-pkg:
64 CGO_ENABLED=$(CGO_ENABLED) go test $(TEST_FLAGS) $(PKG)
65
66.PHONY: cover
67cover:
68 @mkdir -p $(COVER_DIR)
69 CGO_ENABLED=$(CGO_ENABLED) go test $(TEST_FLAGS) $(COVER_FLAGS) ./...
70 go tool cover -html=$(COVER_DIR)/cover.out -o $(COVER_DIR)/cover.html
71 @echo "✓ Coverage report: $(COVER_DIR)/cover.html"
72
73.PHONY: cover-func
74cover-func:
75 @mkdir -p $(COVER_DIR)
76 CGO_ENABLED=$(CGO_ENABLED) go test $(TEST_FLAGS) $(COVER_FLAGS) ./...
77 go tool cover -func=$(COVER_DIR)/cover.out
78
79.PHONY: lint
80lint:
81 golangci-lint run ./...
82
83.PHONY: lint-fix
84lint-fix:
85 golangci-lint run --fix ./...
86
87.PHONY: fmt
88fmt:
89 gofumpt -w .
90 goimports -w .
91 djlint --profile go --reformat .
92 @echo "✓ Formatted all files"
93
94.PHONY: fmt-check
95fmt-check:
96 @out=$$(gofumpt -l .); \
97 if [ -n "$$out" ]; then \
98 echo "Unformatted files:"; echo "$$out"; exit 1; \
99 fi
100 djlint --profile go --check .
101 @echo "✓ All files formatted"
102
103.PHONY: vet
104vet:
105 CGO_ENABLED=$(CGO_ENABLED) go vet ./...
106
107.PHONY: generate
108generate:
109 CGO_ENABLED=$(CGO_ENABLED) go generate ./...
110
111.PHONY: tidy
112tidy:
113 go mod tidy
114 go mod verify
115
116.PHONY: deps
117deps:
118 go list -m -json all | jq -r 'select(.Indirect | not) | .Path + " " + .Version'
119
120.PHONY: db-inspect
121db-inspect:
122 sqlite3 $(or $(REPO),.)/arche/store.db
123
124.PHONY: db-schema
125db-schema:
126 sqlite3 $(or $(REPO),.)/arche/store.db ".schema"
127
128.PHONY: clean
129clean:
130 rm -rf $(BUILD_DIR) $(COVER_DIR)
131 @echo "✓ Cleaned"
132
133.PHONY: clean-all
134clean-all: clean
135 go clean -cache -testcache
136 @echo "✓ Cleaned build cache"
137
138.PHONY: ci
139ci: fmt-check vet lint test
140 @echo "✓ CI passed"