-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (100 loc) · 3.07 KB
/
Makefile
File metadata and controls
120 lines (100 loc) · 3.07 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
.PHONY: all build run test clean install deps fmt vet lint
# Build variables
BINARY_NAME=gommail
BUILD_DIR=build
CMD_DIR=cmd/gommail
# Go variables
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOVET=$(GOCMD) vet
# Default target: build and test
all: build test
@echo "Build and tests completed successfully!"
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) ./$(CMD_DIR)
# Run the application
run: build
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME)
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage (excluding debug tools)
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out $(shell go list ./... | grep -v /cmd/debug-)
$(GOCMD) tool cover -html=coverage.out -o coverage.html
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
# Install dependencies
deps:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
# Vet code
vet:
@echo "Vetting code..."
$(GOVET) ./...
# Run all checks
check: fmt vet test
# Install the application
install: build
@echo "Installing $(BINARY_NAME)..."
cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/
# Development build with debug info
dev-build:
@echo "Building $(BINARY_NAME) for development..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -gcflags="all=-N -l" -o $(BUILD_DIR)/$(BINARY_NAME) ./$(CMD_DIR)
# Cross-compile for different platforms
build-linux:
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./$(CMD_DIR)
build-windows:
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./$(CMD_DIR)
build-macos:
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./$(CMD_DIR)
build-all: build-linux build-windows build-macos
# Quick development cycle
dev: fmt vet build test
@echo "Development cycle completed successfully!"
# Help
help:
@echo "Available targets:"
@echo " all - Build and test (default)"
@echo " build - Build the application"
@echo " run - Build and run the application"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " fmt - Format code"
@echo " vet - Vet code"
@echo " check - Run fmt, vet, and test"
@echo " dev - Quick development cycle (fmt, vet, build, test)"
@echo " install - Install the application"
@echo " dev-build - Build with debug info"
@echo " build-all - Cross-compile for all platforms"
@echo " help - Show this help"