-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (84 loc) · 2.99 KB
/
Makefile
File metadata and controls
102 lines (84 loc) · 2.99 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
.PHONY: build install uninstall clean test bench run
# Build tags for gnet optimizations:
# poll_opt - Optimized epoll/kqueue pollers (lower latency)
# gc_opt - Optimized connection matrix (less GC pressure)
TAGS := poll_opt,gc_opt
# Output binary
BINARY := telego
# Version info
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
# Directory of this Makefile
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Install paths
PREFIX := /usr/local
BINDIR := $(PREFIX)/bin
SYSCONFDIR := /etc/telego
CONFIG := $(SYSCONFDIR)/config.toml
# Creating an RPM distribution
ifneq ("$(wildcard $(MAKEFILE_DIR)/dist/rpmbuild.mk)","")
include $(MAKEFILE_DIR)/dist/rpmbuild.mk
endif
# Default target: build with all optimizations
build:
CGO_ENABLED=0 go build -trimpath -tags="$(TAGS)" -ldflags="$(LDFLAGS)" -o $(BINARY) ./cmd/telego
# Install as systemd service
install: build
@echo "Installing $(BINARY) to $(BINDIR)..."
install -d $(BINDIR)
install -m 755 $(BINARY) $(BINDIR)/$(BINARY)
@echo "Installing systemd service..."
sed 's|CONFIG_PATH|$(CONFIG)|g' $(MAKEFILE_DIR)dist/telego.service > /etc/systemd/system/telego.service
systemctl daemon-reload
@echo "Creating config directory..."
install -d $(SYSCONFDIR)
@if [ ! -f $(CONFIG) ]; then \
echo "Installing example config to $(CONFIG)..."; \
install -m 600 $(MAKEFILE_DIR)config.example.toml $(CONFIG); \
echo "IMPORTANT: Edit $(CONFIG) and add your secrets"; \
else \
echo "Config already exists at $(CONFIG), skipping"; \
fi
@echo ""
@echo "Installation complete. Next steps:"
@echo " 1. Edit $(CONFIG)"
@echo " 2. systemctl enable telego"
@echo " 3. systemctl start telego"
# Uninstall
uninstall:
systemctl stop telego 2>/dev/null || true
systemctl disable telego 2>/dev/null || true
rm -f /etc/systemd/system/telego.service
rm -f $(BINDIR)/$(BINARY)
systemctl daemon-reload
@echo "Uninstalled. Config remains at $(SYSCONFDIR)"
# Run tests with optimizations
test:
go test -tags="$(TAGS)" -race ./...
# Run benchmarks
bench:
go test -tags="$(TAGS)" -bench=. -benchmem ./pkg/transport/...
# Run the proxy (development)
run: build
./$(BINARY) run -c config.toml
# Build without optimizations (for debugging/profiling)
build-debug:
go build -gcflags="all=-N -l" -o $(BINARY) ./cmd/telego
# Build for multiple platforms
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -tags="$(TAGS)" -ldflags="$(LDFLAGS)" -o $(BINARY)-linux-amd64 ./cmd/telego
build-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -tags="$(TAGS)" -ldflags="$(LDFLAGS)" -o $(BINARY)-linux-arm64 ./cmd/telego
# Clean build artifacts
clean:
rm -f $(BINARY) $(BINARY)-linux-*
# Format and lint
fmt:
go fmt ./...
go vet ./...
# Update dependencies
deps:
go mod tidy
go mod download