-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (59 loc) · 1.85 KB
/
Makefile
File metadata and controls
76 lines (59 loc) · 1.85 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
.PHONY: build test clean install lint fmt
# Build variables
BINARY_NAME=agent
BUILD_DIR=bin
MAIN_PATH=./cmd/agent
# Go variables
GOFLAGS=-trimpath
LDFLAGS=-s -w
# Default target
all: build
# Build the binary
build:
@mkdir -p $(BUILD_DIR)
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Built $(BUILD_DIR)/$(BINARY_NAME)"
# Build for all platforms
build-all: build-linux build-darwin build-windows
build-linux:
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=linux GOARCH=arm64 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
build-darwin:
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
build-windows:
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
# Run tests
test:
go test -v ./...
# Run tests with coverage
test-coverage:
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
# Install to GOPATH/bin
install:
go install $(GOFLAGS) -ldflags "$(LDFLAGS)" $(MAIN_PATH)
# Run linter
lint:
golangci-lint run ./...
# Format code
fmt:
go fmt ./...
# Tidy dependencies
tidy:
go mod tidy
# Development build (no optimizations)
dev:
@mkdir -p $(BUILD_DIR)
go build -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
# Run the binary
run: build
./$(BUILD_DIR)/$(BINARY_NAME)