-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
156 lines (132 loc) · 4.24 KB
/
Makefile
File metadata and controls
156 lines (132 loc) · 4.24 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Binary name and paths
BINARY_NAME=godaml
BINARY_DIR=bin
CMD_DIR=cmd
MAIN_PATH=./$(CMD_DIR)/main.go
# Build flags
LDFLAGS=-ldflags "-s -w"
BUILD_FLAGS=-trimpath
# Default target
.PHONY: all
all: clean build
# Build the CLI tool
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BINARY_DIR)
$(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Build complete: $(BINARY_DIR)/$(BINARY_NAME)"
# Build for multiple platforms
.PHONY: build-all
build-all: clean
@echo "Building for multiple platforms..."
@mkdir -p $(BINARY_DIR)
@echo "Building for Linux amd64..."
GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
@echo "Building for Linux arm64..."
GOOS=linux GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
@echo "Building for macOS amd64..."
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
@echo "Building for macOS arm64..."
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
@echo "Building for Windows amd64..."
GOOS=windows GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
@echo "Multi-platform build complete"
# Install the CLI tool to GOPATH/bin
.PHONY: install
install:
@echo "Installing $(BINARY_NAME)..."
$(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY_NAME) $(MAIN_PATH)
@echo "Installed $(BINARY_NAME) to $(GOPATH)/bin/"
# Run tests
.PHONY: test
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BINARY_DIR)
@rm -f coverage.out coverage.html
@echo "Clean complete"
# Download dependencies
.PHONY: deps
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Generate proto files (if needed)
.PHONY: proto
proto:
@echo "Generating proto files..."
@if [ -d "proto" ]; then \
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/*.proto; \
fi
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
# Lint code
.PHONY: lint
lint:
@echo "Linting code..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Vet code
.PHONY: vet
vet:
@echo "Vetting code..."
$(GOCMD) vet ./...
# Run the CLI tool with example parameters
.PHONY: run
run: build
@echo "Running $(BINARY_NAME) with example parameters..."
./$(BINARY_DIR)/$(BINARY_NAME) --help
# Development workflow: format, vet, test, build
.PHONY: dev
dev: fmt vet test build
# Release workflow: clean, deps, test, build-all
.PHONY: release
release: clean deps test build-all
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean and build"
@echo " build - Build the CLI tool for current platform"
@echo " build-all - Build for multiple platforms"
@echo " install - Install CLI tool to GOPATH/bin"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " clean - Clean build artifacts"
@echo " deps - Download and tidy dependencies"
@echo " proto - Generate proto files"
@echo " fmt - Format code"
@echo " lint - Lint code (requires golangci-lint)"
@echo " vet - Vet code"
@echo " run - Build and run with help"
@echo " dev - Development workflow (fmt, vet, test, build)"
@echo " release - Release workflow (clean, deps, test, build-all)"
@echo " help - Show this help"