-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
112 lines (94 loc) · 3.12 KB
/
Makefile
File metadata and controls
112 lines (94 loc) · 3.12 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
.PHONY: build build-cli build-all build-all-prefixes clean test test-cli run fmt lint install-cli help
# Prefix variable - controls binary names and appName ldflags
# Default: cola (produces cola-registry, cola-regctl)
# Override: make build-all PREFIX=cdt (produces cdt-registry, cdt-regctl)
PREFIX ?= cola
# Build variables - derived from PREFIX
BINARY_NAME=$(PREFIX)-registry
CLI_BINARY_NAME=$(PREFIX)-regctl
BUILD_DIR=bin
DIST_DIR=dist
CMD_DIR=cmd/cola-registry
CLI_CMD_DIR=cmd/cola-regctl
# Version variables - can be overridden via environment or command line
VERSION ?= dev
BUILD_NUM ?= $(shell date +%Y%m%d-%H%M%S)
APP_NAME_SERVER = $(PREFIX)-registry
APP_NAME_CLI = $(PREFIX)-regctl
# Build flags
LDFLAGS_BASE = -s -w
LDFLAGS_SERVER = $(LDFLAGS_BASE) \
-X 'main.version=$(VERSION)' \
-X 'main.buildNum=$(BUILD_NUM)' \
-X 'main.appName=$(APP_NAME_SERVER)'
LDFLAGS_CLI = $(LDFLAGS_BASE) \
-X 'main.version=$(VERSION)' \
-X 'main.buildNum=$(BUILD_NUM)' \
-X 'main.appName=$(APP_NAME_CLI)'
# Default target
all: build
## build: Build the server binary
build:
@echo "Building $(BINARY_NAME) version=$(VERSION) build=$(BUILD_NUM)..."
@CGO_ENABLED=0 go build -ldflags="$(LDFLAGS_SERVER)" -o $(BUILD_DIR)/$(BINARY_NAME) ./$(CMD_DIR)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
## build-cli: Build the CLI client binary
build-cli:
@echo "Building $(CLI_BINARY_NAME) version=$(VERSION) build=$(BUILD_NUM)..."
@CGO_ENABLED=0 go build -ldflags="$(LDFLAGS_CLI)" -o $(BUILD_DIR)/$(CLI_BINARY_NAME) ./$(CLI_CMD_DIR)
@echo "Build complete: $(BUILD_DIR)/$(CLI_BINARY_NAME)"
## build-all: Build both server and CLI binaries
build-all: build build-cli
## build-all-prefixes: Build both cola- and cdt- prefixed binaries
build-all-prefixes:
@$(MAKE) build-all PREFIX=cola
@$(MAKE) build-all PREFIX=cdt
## clean: Remove build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@echo "Clean complete"
## test: Run all tests
test:
@echo "Running tests..."
@go test -v -race -coverprofile=coverage.txt ./...
@echo "Tests complete"
## test-cli: Run CLI client tests only
test-cli:
@echo "Running CLI tests..."
@go test -v -race ./internal/client/...
@echo "CLI tests complete"
## run: Build and run the server
run: build
@echo "Starting server..."
@$(BUILD_DIR)/$(BINARY_NAME) server
## fmt: Format code
fmt:
@echo "Formatting code..."
@go fmt ./...
@echo "Format complete"
## fmt-check: Check if code is formatted (for CI)
fmt-check:
@echo "Checking code formatting..."
@if [ -n "$$(gofmt -l .)" ]; then \
echo "Code is not formatted. Run 'make fmt'"; \
gofmt -l .; \
exit 1; \
fi
@echo "Format check passed"
## lint: Run linter (go vet)
lint:
@echo "Running linter..."
@go vet ./...
@echo "Lint complete"
## install-cli: Install the CLI client to $GOPATH/bin
install-cli: build-cli
@echo "Installing $(CLI_BINARY_NAME) to $$GOPATH/bin..."
@cp $(BUILD_DIR)/$(CLI_BINARY_NAME) $$GOPATH/bin/
@echo "Install complete"
## help: Show this help message
help:
@echo "Usage: make [target] [PREFIX=cola|cdt]"
@echo ""
@echo "Targets:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'