-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
136 lines (120 loc) · 4.11 KB
/
Makefile
File metadata and controls
136 lines (120 loc) · 4.11 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
# klip - A tiny cross-platform clipboard manager
# Makefile for building, testing, and managing the project
# Variables
BINARY_NAME=klip
MAIN_PACKAGE=./cmd/klip
BUILD_DIR=build
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS=-ldflags "-X main.version=$(VERSION)"
# Default target
.PHONY: all
all: build
# Build the binary
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
# 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 $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PACKAGE)
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PACKAGE)
.PHONY: build-darwin
build-darwin:
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PACKAGE)
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PACKAGE)
.PHONY: build-windows
build-windows:
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PACKAGE)
# Install the binary to GOPATH/bin
.PHONY: install
install:
@echo "Installing $(BINARY_NAME)..."
go install $(LDFLAGS) $(MAIN_PACKAGE)
@echo "Installed to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run linting
.PHONY: lint
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found, running go vet instead..."; \
go vet ./...; \
fi
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
# Run a quick test of the built binary
.PHONY: test-binary
test-binary: build
@echo "Testing the built binary..."
@$(BUILD_DIR)/$(BINARY_NAME) --help 2>/dev/null || echo "Binary built successfully (no --help flag available)"
@echo "Testing basic functionality..."
@$(BUILD_DIR)/$(BINARY_NAME) set --no-clip test-makefile "Hello from Makefile"
@$(BUILD_DIR)/$(BINARY_NAME) get test-makefile --no-clip --raw
@$(BUILD_DIR)/$(BINARY_NAME) rm test-makefile
@echo "Basic functionality test passed!"
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
@echo "Clean complete"
# Clean everything including Go cache
.PHONY: clean-all
clean-all: clean
@echo "Cleaning Go cache..."
go clean -cache -modcache -testcache
@echo "Full clean complete"
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the binary (default)"
@echo " build-all - Build for all platforms (Linux, macOS, Windows)"
@echo " build-linux - Build for Linux (amd64, arm64)"
@echo " build-darwin - Build for macOS (amd64, arm64)"
@echo " build-windows - Build for Windows (amd64)"
@echo " install - Install binary to GOPATH/bin"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " test-binary - Test the built binary functionality"
@echo " lint - Run linter (golangci-lint or go vet)"
@echo " fmt - Format code"
@echo " clean - Remove build artifacts"
@echo " clean-all - Remove build artifacts and Go cache"
@echo " help - Show this help message"
@echo ""
@echo "Variables:"
@echo " VERSION - Set version string (default: git describe or 'dev')"
@echo ""
@echo "Examples:"
@echo " make build VERSION=v1.0.0"
@echo " make test-coverage"
@echo " make build-all"