-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
118 lines (91 loc) · 3.87 KB
/
Copy pathMakefile
File metadata and controls
118 lines (91 loc) · 3.87 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
.PHONY: help build install install-user go-install clean test format all test-integration test-coverage lint vet deps
# Default target
.DEFAULT_GOAL := help
# Build variables
BINARY_NAME := monodev
BUILD_DIR := bin
GO_FILES := $(shell find . -name '*.go' -not -path './vendor/*')
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
# Installation variables (can be overridden)
DESTDIR ?=
PREFIX ?= /usr/local
INSTALL_DIR := $(DESTDIR)$(PREFIX)/bin
# Go build flags
LDFLAGS := -ldflags "-X main.version=$(VERSION)"
##@ General
help: ## Display this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
all: clean build ## Clean and build the binary
build: ## Build the Go binary
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) cmd/monodev/main.go
@echo "✓ Built $(BUILD_DIR)/$(BINARY_NAME)"
install: build ## Build and install to $(PREFIX)/bin (default: /usr/local/bin). Override with: make install PREFIX=/custom/path
@echo "Installing $(BINARY_NAME) to $(INSTALL_DIR)..."
@mkdir -p $(INSTALL_DIR)
@if [ -w $(INSTALL_DIR) ]; then \
cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/$(BINARY_NAME); \
else \
sudo cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_DIR)/$(BINARY_NAME); \
fi
@echo "✓ Installed to $(INSTALL_DIR)/$(BINARY_NAME)"
install-user: build ## Build and install to user's local bin directory (~/bin or ~/.local/bin)
@echo "Installing $(BINARY_NAME) to user bin directory..."
@if [ -d $$HOME/bin ]; then \
INSTALL_PATH=$$HOME/bin; \
elif [ -d $$HOME/.local/bin ]; then \
INSTALL_PATH=$$HOME/.local/bin; \
else \
INSTALL_PATH=$$HOME/bin; \
mkdir -p $$INSTALL_PATH; \
fi; \
cp $(BUILD_DIR)/$(BINARY_NAME) $$INSTALL_PATH/$(BINARY_NAME); \
echo "✓ Installed to $$INSTALL_PATH/$(BINARY_NAME)"; \
echo " Make sure $$INSTALL_PATH is in your PATH"
go-install: ## Install using 'go install' (recommended for development)
@echo "Installing $(BINARY_NAME) using 'go install'..."
@go install $(LDFLAGS) ./cmd/monodev
@echo "✓ Installed using go install (to $$(go env GOPATH)/bin or $$(go env GOBIN))"
clean: ## Remove build artifacts and test coverage files
@echo "Cleaning build artifacts and test files..."
rm -rf $(BUILD_DIR) coverage.out coverage.html
@echo "✓ Cleaned"
##@ Testing
test: ## Run unit tests (fast, no system dependencies)
@echo "Running unit tests..."
go test -v ./internal/...
test-quick: ## Run tests without verbose output (faster)
@go test ./internal/...
test-coverage: ## Run unit tests with coverage report
@echo "Running unit tests with coverage..."
go test -v -coverprofile=coverage.out ./internal/...
go tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report generated: coverage.html"
@go tool cover -func=coverage.out | grep total | awk '{print "✓ Total coverage: " $$3}'
test-integration: ## Run integration tests
@echo "Running integration tests..."
go test -v -tags=integration ./test/integration/...
##@ Development
format: ## Format Go code
@echo "Formatting Go code..."
gofmt -w $(GO_FILES)
@echo "✓ Formatted"
lint: ## Run golangci-lint (requires golangci-lint)
@command -v golangci-lint >/dev/null 2>&1 || { echo "ERROR: golangci-lint not found. Install it: brew install golangci-lint" >&2; exit 1; }
golangci-lint run ./...
vet: ## Run go vet
@echo "Running go vet..."
go vet ./...
@echo "✓ Vet passed"
deps: ## Download dependencies
@echo "Downloading dependencies..."
go mod download
go mod tidy
@echo "✓ Dependencies updated"
##@ Information
version: ## Show version information
@echo "Version: $(VERSION)"
size: build ## Show binary size
@ls -lh $(BUILD_DIR)/$(BINARY_NAME) | awk '{print "Binary size:", $$5}'