-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (151 loc) · 4.95 KB
/
Makefile
File metadata and controls
177 lines (151 loc) · 4.95 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
.PHONY: all build build-release build-all test test-coverage bench clean install fmt lint check help
# Variables
BINARY_NAME=apple-mail-mcp
VERSION=0.3.0
BUILD_DIR=bin
COVERAGE_FILE=coverage.out
MAIN_PATH=./cmd/apple-mail-mcp
PREFIX?=/usr/local
# Only use sudo when installing to system directories (default /usr/local)
# When PREFIX is customized, assume user owns the directory
ifeq ($(PREFIX),/usr/local)
SUDO=sudo
else
SUDO=
endif
# Build flags
LDFLAGS=-ldflags "-s -w -X main.Version=$(VERSION)"
BUILD_FLAGS=-trimpath
# Go commands
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
# Default target
all: clean build test
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Build optimized release version
build-release:
@echo "Building release version..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Release build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Build for all platforms
build-all: build-darwin-amd64 build-darwin-arm64
build-darwin-amd64:
@echo "Building for macOS (Intel)..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) \
-o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64"
build-darwin-arm64:
@echo "Building for macOS (Apple Silicon)..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) \
-o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64"
# Run all tests
test:
@echo "Running tests..."
$(GOTEST) -v -race ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -race -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "Coverage report generated: $(COVERAGE_FILE)"
@$(GOCMD) tool cover -func=$(COVERAGE_FILE)
# View coverage in browser
coverage-html: test-coverage
@echo "Opening coverage report in browser..."
$(GOCMD) tool cover -html=$(COVERAGE_FILE)
# Run benchmarks
bench:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f $(COVERAGE_FILE)
@echo "Clean complete"
# Install the binary
install: build-release
@echo "Installing $(BINARY_NAME) to $(PREFIX)/bin..."
@$(SUDO) mkdir -p $(PREFIX)/bin
@$(SUDO) cp $(BUILD_DIR)/$(BINARY_NAME) $(PREFIX)/bin/
@echo "Installation complete"
# Uninstall the binary
uninstall:
@echo "Uninstalling $(BINARY_NAME) from $(PREFIX)/bin..."
@$(SUDO) rm -f $(PREFIX)/bin/$(BINARY_NAME)
@echo "Uninstall complete"
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
@echo "Format complete"
# Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Run: brew install golangci-lint" && exit 1)
golangci-lint run ./...
# Run all quality checks
check: fmt lint test
@echo "All checks passed!"
# Update dependencies
deps:
@echo "Downloading dependencies..."
$(GOGET) -v ./...
$(GOMOD) tidy
@echo "Dependencies updated"
# Verify dependencies
verify:
@echo "Verifying dependencies..."
$(GOMOD) verify
@echo "Dependencies verified"
# Run the application (for testing)
run: build
@echo "Running $(BINARY_NAME)..."
$(BUILD_DIR)/$(BINARY_NAME)
# Show help
help:
@echo "Apple Mail MCP Server - Makefile Commands"
@echo ""
@echo "Build Commands:"
@echo " make build - Build the application"
@echo " make build-release - Build optimized release version"
@echo " make build-all - Build for all platforms"
@echo ""
@echo "Test Commands:"
@echo " make test - Run all tests"
@echo " make test-coverage - Run tests with coverage report"
@echo " make coverage-html - View coverage report in browser"
@echo " make bench - Run benchmarks"
@echo ""
@echo "Quality Commands:"
@echo " make fmt - Format code"
@echo " make lint - Run linter"
@echo " make check - Run all quality checks"
@echo ""
@echo "Dependency Commands:"
@echo " make deps - Update dependencies"
@echo " make verify - Verify dependencies"
@echo ""
@echo "Installation Commands:"
@echo " make install - Install binary to /usr/local/bin (uses sudo)"
@echo " make uninstall - Uninstall binary"
@echo " PREFIX=~/.local make install - Install to custom directory (no sudo)"
@echo ""
@echo "Other Commands:"
@echo " make clean - Clean build artifacts"
@echo " make run - Build and run the application"
@echo " make help - Show this help message"