-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
99 lines (78 loc) · 2.43 KB
/
Makefile
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
# Stop execution when a command fails
.ONESHELL:
.SHELLFLAGS = -ec
# Automatically determine the module path using go list
MODULE_PATH := $(shell go list -m -f {{.Path}})
COMMON_PACKAGE := $(MODULE_PATH)/common
# Define the output directory for binaries
BIN_DIR := bin
# Define the output binary names
DAEMON_BINARY := $(BIN_DIR)/pinner
CLI_BINARY := $(BIN_DIR)/pinner-cli
LC_BINARY := $(BIN_DIR)/light-client
# Define the source files
DAEMON_SOURCE := cmd/pinner/main.go
CLI_SOURCE := cmd/pinner-cli/main.go
LC_SOURCE := cmd/light-client/main.go
# Define the directories containing Go files
GO_DIRS := api cmd/pinner cmd/pinner-cli common internal
# Retrieve version and git commit hash
VERSION := $(shell git describe --tags --always --dirty)
GIT_COMMIT := $(shell git rev-parse HEAD)
# Default target to build all binaries
.PHONY: all
all: fmt vet staticcheck test build
# Create the bin directory if it doesn't exist
$(BIN_DIR):
mkdir -p $(BIN_DIR)
# Build both the daemon and CLI tool
.PHONY: build
build: $(BIN_DIR) build-pinner build-cli build-light
# Build the daemon binary with a custom name
.PHONY: build-pinner
build-pinner: $(BIN_DIR)
go build $(EXTRA_TAGS) -ldflags "-s -w -X $(COMMON_PACKAGE).BinaryName=pinner -X $(COMMON_PACKAGE).Version=$(VERSION) -X $(COMMON_PACKAGE).GitCommit=$(GIT_COMMIT)" -o $(DAEMON_BINARY) $(DAEMON_SOURCE)
# Build the CLI tool binary with a custom name
.PHONY: build-cli
build-cli: $(BIN_DIR)
go build -ldflags "-s -w -X $(COMMON_PACKAGE).BinaryName=pinner-cli -X $(COMMON_PACKAGE).Version=$(VERSION) -X $(COMMON_PACKAGE).GitCommit=$(GIT_COMMIT)" -o $(CLI_BINARY) $(CLI_SOURCE)
# Build Light client
.PHONY: build-light
build-light: $(BIN_DIR)
go build -ldflags "-s -w -X $(COMMON_PACKAGE).BinaryName=light-client -X $(COMMON_PACKAGE).Version=$(VERSION) -X $(COMMON_PACKAGE).GitCommit=$(GIT_COMMIT)" -o $(LC_BINARY) $(LC_SOURCE)
# Run tests
.PHONY: test
test:
go test ./...
# Run tests with coverage report
.PHONY: test-cover
test-cover:
go test -cover ./...
# Format the code
.PHONY: fmt
fmt:
go fmt ./...
# Run static analysis (vet)
.PHONY: vet
vet:
go vet ./...
# Tidy up module dependencies
.PHONY: tidy
tidy:
go mod tidy
# Clean up binaries and other generated files
.PHONY: clean
clean:
rm -rf $(BIN_DIR)
rm -f coverage.out
# Generate code (if applicable)
.PHONY: generate
generate:
go generate ./...
# Install dependencies
.PHONY: deps
deps:
go mod download
.PHONY: staticcheck
staticcheck:
staticcheck ./...