-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (133 loc) · 4.76 KB
/
Makefile
File metadata and controls
154 lines (133 loc) · 4.76 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
142
143
144
145
146
147
148
149
150
151
152
153
154
# Go parameters
BINARY_NAME=mcp-obsidian
GO_CMD=go
GO_BUILD=$(GO_CMD) build
GO_CLEAN=$(GO_CMD) clean
GO_TEST=$(GO_CMD) test
GO_GET=$(GO_CMD) get
GO_MOD=$(GO_CMD) mod
GO_VET=$(GO_CMD) vet
GO_FMT=$(GO_CMD) fmt
# Build parameters
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)"
# Directories
BUILD_DIR=build
COVERAGE_DIR=coverage
.PHONY: all build clean test lint fmt vet deps help install run check coverage tidy verify
# Default target
all: check build
## help: Display this help message
help:
@echo "Available targets:"
@echo " make build - Build the binary"
@echo " make clean - Remove build artifacts"
@echo " make test - Run tests"
@echo " make coverage - Run tests with coverage report"
@echo " make lint - Run linters (golangci-lint)"
@echo " make fmt - Format code"
@echo " make vet - Run go vet"
@echo " make check - Run all checks (fmt, vet, lint, test)"
@echo " make deps - Download dependencies"
@echo " make tidy - Tidy and verify dependencies"
@echo " make verify - Verify dependencies"
@echo " make install - Install the binary"
@echo " make run - Run the application (requires VAULT=/path/to/vault)"
@echo " make all - Run checks and build"
## build: Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "Built: $(BUILD_DIR)/$(BINARY_NAME)"
## clean: Remove build artifacts and test cache
clean:
@echo "Cleaning..."
@$(GO_CLEAN)
@rm -rf $(BUILD_DIR)
@rm -rf $(COVERAGE_DIR)
@rm -f $(BINARY_NAME)
@echo "Clean complete"
## test: Run tests
test:
@echo "Running tests..."
@$(GO_TEST) -v -race -timeout 30s ./...
## coverage: Run tests with coverage
coverage:
@echo "Running tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
@$(GO_TEST) -v -race -coverprofile=$(COVERAGE_DIR)/coverage.out -covermode=atomic ./...
@$(GO_CMD) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@echo "Coverage report: $(COVERAGE_DIR)/coverage.html"
@$(GO_CMD) tool cover -func=$(COVERAGE_DIR)/coverage.out
## fmt: Format code
fmt:
@echo "Formatting code..."
@$(GO_FMT) ./...
@echo "Code formatted"
## vet: Run go vet
vet:
@echo "Running go vet..."
@$(GO_VET) ./...
@echo "go vet passed"
## lint: Run golangci-lint
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Install it from https://golangci-lint.run/usage/install/"; \
echo "Running basic checks instead..."; \
$(MAKE) fmt vet; \
fi
## check: Run all checks (fmt, vet, lint, test)
check: fmt vet lint test
@echo "All checks passed!"
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
@$(GO_GET) -v -t -d ./...
@echo "Dependencies downloaded"
## tidy: Tidy and verify dependencies
tidy:
@echo "Tidying dependencies..."
@$(GO_MOD) tidy
@$(GO_MOD) verify
@echo "Dependencies tidied and verified"
## verify: Verify dependencies
verify:
@echo "Verifying dependencies..."
@$(GO_MOD) verify
@echo "Dependencies verified"
## install: Install the binary to $GOPATH/bin
install:
@echo "Installing $(BINARY_NAME)..."
@$(GO_CMD) install $(LDFLAGS)
@echo "Installed to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
## run: Run the application (requires VAULT parameter)
run: build
@if [ -z "$(VAULT)" ]; then \
echo "Error: VAULT parameter is required"; \
echo "Usage: make run VAULT=/path/to/vault"; \
exit 1; \
fi
@echo "Running $(BINARY_NAME) with vault: $(VAULT)"
@$(BUILD_DIR)/$(BINARY_NAME) $(VAULT)
# Advanced targets
## build-all: Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe .
@echo "Multi-platform builds complete"
## release: Build optimized release binaries
release:
@echo "Building release binaries..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GO_BUILD) $(LDFLAGS) -a -installsuffix cgo -trimpath -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "Release build complete: $(BUILD_DIR)/$(BINARY_NAME)"