-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (109 loc) · 4.05 KB
/
Makefile
File metadata and controls
130 lines (109 loc) · 4.05 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
.PHONY: build clean test install uninstall deps fmt vet lint templ
# Build variables
BINARY_NAME=ergs
BUILD_DIR=bin
VERSION?=$(shell grep 'const Version' pkg/version/version.go | cut -d'"' -f2)
LDFLAGS=-ldflags "-X main.version=$(VERSION)"
BUILD_TAGS=fts5
# CGO Configuration
# Set to 0 for CGO-free builds (default) using ncruces/go-sqlite3
# Set to 1 to enable CGO if needed: make build CGO_ENABLED=1
CGO_ENABLED?=0
# Default target
all: build
# Generate templ templates
templ:
@echo "Generating templ templates..."
go install github.com/a-h/templ/cmd/templ@latest
templ generate
# Build the binary
build: templ
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=$(CGO_ENABLED) go build -tags $(BUILD_TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
# Build for multiple platforms
build-all: templ
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 go build -tags $(BUILD_TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 go build -tags $(BUILD_TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=arm64 go build -tags $(BUILD_TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 go build -tags $(BUILD_TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe .
# Install dependencies
deps:
go mod download
go mod tidy
# Format code
fmt:
go fmt ./...
# Vet code
vet:
go vet ./...
test:
CGO_ENABLED=$(CGO_ENABLED) go test -tags $(BUILD_TAGS) ./...
test-verbose:
CGO_ENABLED=$(CGO_ENABLED) go test -tags $(BUILD_TAGS) -v ./...
# Run tests with coverage
test-coverage:
CGO_ENABLED=$(CGO_ENABLED) go test -tags $(BUILD_TAGS) -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Install binary to ~/.local/bin
install: build
@mkdir -p ~/.local/bin
cp $(BUILD_DIR)/$(BINARY_NAME) ~/.local/bin/$(BINARY_NAME).new
mv ~/.local/bin/$(BINARY_NAME).new ~/.local/bin/$(BINARY_NAME)
@echo "✓ Installed $(BINARY_NAME) to ~/.local/bin"
@echo " Make sure ~/.local/bin is in your PATH"
# Uninstall binary from ~/.local/bin
uninstall:
@if [ -f ~/.local/bin/$(BINARY_NAME) ]; then \
rm ~/.local/bin/$(BINARY_NAME); \
echo "✓ Removed $(BINARY_NAME) from ~/.local/bin"; \
else \
echo "$(BINARY_NAME) not found in ~/.local/bin"; \
fi
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
rm -f ergs.db
@echo "Cleaning generated templ files..."
find . -name "*_templ.go" -type f -delete
# Development setup
dev-setup: deps
@echo "Installing development tools..."
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/a-h/templ/cmd/templ@latest
# Lint code
lint:
golangci-lint run
# Run development environment
dev-run:
CGO_ENABLED=$(CGO_ENABLED) go run -tags $(BUILD_TAGS) . $(ARGS)
# Example commands for testing
example-fetch:
./$(BUILD_DIR)/$(BINARY_NAME) fetch --github-token $(GITHUB_TOKEN)
example-search:
./$(BUILD_DIR)/$(BINARY_NAME) search --query golang
# Help
help:
@echo "Available targets:"
@echo " build - Build the binary (CGO-free by default)"
@echo " build-all - Build for multiple platforms (CGO-free)"
@echo " templ - Generate templ templates"
@echo " deps - Install dependencies"
@echo " fmt - Format code"
@echo " vet - Vet code"
@echo " test - Run tests"
@echo " test-verbose - Run tests"
@echo " test-coverage- Run tests with coverage"
@echo " install - Install binary to ~/.local/bin"
@echo " uninstall - Remove binary from ~/.local/bin"
@echo " clean - Clean build artifacts"
@echo " dev-setup - Setup development environment"
@echo " lint - Lint code"
@echo " dev-run - Run in development mode"
@echo " help - Show this help"
@echo ""
@echo "CGO Configuration:"
@echo " Default: CGO_ENABLED=0 (CGO-free builds using ncruces/go-sqlite3)"
@echo " To enable CGO: make build CGO_ENABLED=1"