-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (128 loc) · 3.78 KB
/
Makefile
File metadata and controls
147 lines (128 loc) · 3.78 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
# Makefile for Lux CLI
# Variables
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(GOPATH)/bin
PROJECT_NAME = lux
BINARY_NAME = lux
VERSION ?= $(shell git describe --tags --always --dirty)
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS = -X 'github.com/luxfi/cli/cmd.Version=$(VERSION)'
# Default target
.PHONY: all
all: build
# Build the CLI binary
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p bin
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME) main.go
@echo "Build complete: ./bin/$(BINARY_NAME)"
# Install the binary to GOBIN
.PHONY: install
install:
@echo "Installing $(BINARY_NAME) to $(GOBIN)..."
go install -ldflags "$(LDFLAGS)" .
@echo "Installed to: $(GOBIN)/$(BINARY_NAME)"
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Lint the code
.PHONY: lint
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
# Run go mod tidy
.PHONY: tidy
tidy:
@echo "Running go mod tidy..."
go mod tidy
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf bin/
rm -f coverage.out coverage.html
go clean -cache
@echo "Clean complete"
# Build for multiple platforms
.PHONY: build-all
build-all: build-linux build-darwin build-windows
.PHONY: build-linux
build-linux:
@echo "Building for Linux..."
@mkdir -p bin
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME)-linux-amd64 main.go
GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME)-linux-arm64 main.go
.PHONY: build-darwin
build-darwin:
@echo "Building for macOS..."
@mkdir -p bin
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME)-darwin-amd64 main.go
GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME)-darwin-arm64 main.go
.PHONY: build-windows
build-windows:
@echo "Building for Windows..."
@mkdir -p bin
GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME)-windows-amd64.exe main.go
# Development build (with race detector)
.PHONY: dev
dev:
@echo "Building with race detector..."
@mkdir -p bin
go build -race -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME) main.go
# Check for vulnerabilities
.PHONY: vuln-check
vuln-check:
@echo "Checking for vulnerabilities..."
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
# Generate documentation
.PHONY: docs
docs:
@echo "Generating documentation..."
go doc -all > docs.txt
# Show help
.PHONY: help
help:
@echo "Lux CLI Makefile"
@echo ""
@echo "Usage:"
@echo " make [target]"
@echo ""
@echo "Targets:"
@echo " all - Build the binary (default)"
@echo " build - Build the binary"
@echo " install - Install the binary to GOBIN"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " lint - Run linters"
@echo " fmt - Format code"
@echo " tidy - Run go mod tidy"
@echo " clean - Clean build artifacts"
@echo " build-all - Build for all platforms"
@echo " dev - Build with race detector"
@echo " vuln-check - Check for vulnerabilities"
@echo " docs - Generate documentation"
@echo " help - Show this help message"
# Ensure dependencies are downloaded
.PHONY: deps
deps:
@echo "Downloading dependencies..."
go mod download