Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (86 loc) · 2.75 KB
/
Copy pathMakefile
File metadata and controls
105 lines (86 loc) · 2.75 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
.PHONY: all build test clean install lint fmt help
# Variables
BINARY_NAME := nettune
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -ldflags "-X github.com/jtsang4/nettune/pkg/version.Version=$(VERSION) \
-X github.com/jtsang4/nettune/pkg/version.GitCommit=$(GIT_COMMIT) \
-X github.com/jtsang4/nettune/pkg/version.BuildDate=$(BUILD_DATE)"
# Output directory
DIST_DIR := dist
# Go settings
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOCLEAN := $(GOCMD) clean
GOGET := $(GOCMD) get
GOMOD := $(GOCMD) mod
all: build
## Build the binary for the current platform
build:
@echo "Building $(BINARY_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) ./cmd/nettune
## Build for all supported platforms
build-all:
@echo "Building for all platforms..."
@mkdir -p $(DIST_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/nettune
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/nettune
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/nettune
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/nettune
@echo "Generating checksums..."
@cd $(DIST_DIR) && sha256sum $(BINARY_NAME)-* > checksums.txt
## Run tests
test:
$(GOTEST) -v -race ./...
## Run tests with coverage
test-coverage:
$(GOTEST) -v -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
## Run short tests (no integration tests)
test-short:
$(GOTEST) -v -short ./...
## Clean build artifacts
clean:
$(GOCLEAN)
rm -rf $(DIST_DIR)
rm -f coverage.out coverage.html
## Install the binary
install:
$(GOBUILD) $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY_NAME) ./cmd/nettune
## Run linter
lint:
golangci-lint run ./...
## Format code
fmt:
gofmt -s -w .
## Tidy dependencies
tidy:
$(GOMOD) tidy
## Download dependencies
deps:
$(GOMOD) download
## Run the server (for development)
run-server:
$(GOCMD) run ./cmd/nettune server --api-key=dev-key
## Run the client (for development)
run-client:
$(GOCMD) run ./cmd/nettune client --api-key=dev-key --server=http://127.0.0.1:9876
## Show version info
version:
@echo "Version: $(VERSION)"
@echo "Git Commit: $(GIT_COMMIT)"
@echo "Build Date: $(BUILD_DATE)"
## Show help
help:
@echo "Nettune Makefile"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^##' Makefile | sed 's/## / /'
@echo ""
@echo "Variables:"
@echo " VERSION=$(VERSION)"
@echo " GIT_COMMIT=$(GIT_COMMIT)"