-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (126 loc) · 4.08 KB
/
Copy pathMakefile
File metadata and controls
149 lines (126 loc) · 4.08 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
# Pathfinding Labs CLI Makefile
BINARY_NAME=plabs
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X github.com/DataDog/pathfinding-labs/internal/cmd.version=$(VERSION) -X github.com/DataDog/pathfinding-labs/internal/cmd.commit=$(COMMIT)"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
# Build directories
BUILD_DIR=build
DIST_DIR=dist
.PHONY: all build clean test fmt lint deps install uninstall release help
## Default target
all: build
## Build the binary for the current platform
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/plabs
## Build for all platforms
build-all: build-linux build-darwin build-windows
## Build for Linux (amd64 and arm64)
build-linux:
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/plabs
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/plabs
## Build for macOS (amd64 and arm64)
build-darwin:
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/plabs
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/plabs
## Build for Windows (amd64)
build-windows:
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/plabs
## Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
## Run tests with 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: coverage.html"
## Format code
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
## Run linter
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Install with: brew install golangci-lint"; \
fi
## Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
## Install the binary to /usr/local/bin
install: build
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
@cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@echo "Installed! Run 'plabs --help' to get started."
## Uninstall the binary
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@rm -f /usr/local/bin/$(BINARY_NAME)
@echo "Uninstalled."
## Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR)
@rm -rf $(DIST_DIR)
@rm -f coverage.out coverage.html
## Create release artifacts (requires goreleaser)
release:
@echo "Creating release..."
@if command -v goreleaser >/dev/null 2>&1; then \
goreleaser release --clean; \
else \
echo "goreleaser not installed. Install with: brew install goreleaser"; \
exit 1; \
fi
## Create a snapshot release (for testing)
snapshot:
@echo "Creating snapshot release..."
@if command -v goreleaser >/dev/null 2>&1; then \
goreleaser release --snapshot --clean; \
else \
echo "goreleaser not installed. Install with: brew install goreleaser"; \
exit 1; \
fi
## Run the CLI (for development)
run: build
./$(BUILD_DIR)/$(BINARY_NAME) $(ARGS)
## Show version info
version:
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Build Time: $(BUILD_TIME)"
## Show help
help:
@echo "Pathfinding Labs CLI Build System"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'
@echo ""
@echo "Examples:"
@echo " make build # Build for current platform"
@echo " make install # Build and install to /usr/local/bin"
@echo " make test # Run tests"
@echo " make build-all # Build for all platforms"