-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (122 loc) · 4.25 KB
/
Makefile
File metadata and controls
141 lines (122 loc) · 4.25 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
# ripcut - fast Go cut replacement
# Build and installation makefile
# Binary name and version
BINARY_NAME=ripcut
VERSION=1.0.0
BUILD_DIR=build
INSTALL_PREFIX=/usr/local
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Build flags
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION)"
.PHONY: all build clean test install uninstall help
# Default target
all: build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
# Build optimized release binary
release:
@echo "Building optimized release binary..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -a -installsuffix cgo -o $(BUILD_DIR)/$(BINARY_NAME) .
# Install binary and man page to system
install: build
@echo "Installing $(BINARY_NAME) to $(INSTALL_PREFIX)/bin..."
@sudo install -d $(INSTALL_PREFIX)/bin
@sudo install $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_PREFIX)/bin/$(BINARY_NAME)
@echo "Installing man page to $(INSTALL_PREFIX)/share/man/man1..."
@sudo install -d $(INSTALL_PREFIX)/share/man/man1
@sudo install -m 644 $(BINARY_NAME).1 $(INSTALL_PREFIX)/share/man/man1/$(BINARY_NAME).1
@echo "$(BINARY_NAME) installed successfully!"
# Uninstall binary and man page from system
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@sudo rm -f $(INSTALL_PREFIX)/bin/$(BINARY_NAME)
@sudo rm -f $(INSTALL_PREFIX)/share/man/man1/$(BINARY_NAME).1
@echo "$(BINARY_NAME) uninstalled successfully!"
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@rm -f $(BINARY_NAME)
# Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Format code
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
# 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: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Run Go benchmarks
bench:
@echo "Running Go benchmarks..."
$(GOTEST) -bench=. -benchmem
# Run performance comparison vs standard cut
benchmark: build
@echo "Running performance comparison vs standard cut..."
@./benchmark.sh
# Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
@echo "Building for Linux amd64..."
@GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
@echo "Building for Linux arm64..."
@GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
@echo "Building for macOS amd64..."
@GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
@echo "Building for macOS arm64..."
@GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
@echo "Building for Windows amd64..."
@GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe .
# Create release archives
package: build-all
@echo "Creating release packages..."
@cd $(BUILD_DIR) && for binary in $(BINARY_NAME)-*; do \
if [ -f "$$binary" ]; then \
echo "Packaging $$binary..."; \
tar -czf "$$binary.tar.gz" "$$binary" ../README.md; \
fi; \
done
# Show help
help:
@echo "Available targets:"
@echo " build Build the binary"
@echo " release Build optimized release binary"
@echo " install Install binary to $(INSTALL_PREFIX)/bin"
@echo " uninstall Remove binary from $(INSTALL_PREFIX)/bin"
@echo " test Run tests"
@echo " clean Clean build artifacts"
@echo " deps Download and tidy dependencies"
@echo " fmt Format code"
@echo " lint Run linter (requires golangci-lint)"
@echo " bench Run Go benchmarks"
@echo " benchmark Run performance comparison vs standard cut"
@echo " build-all Build for multiple platforms"
@echo " package Create release packages"
@echo " help Show this help message"
@echo ""
@echo "Installation installs both the binary and man page."
@echo "Use 'man ripcut' after installation to view the manual."