-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (139 loc) · 5.04 KB
/
Makefile
File metadata and controls
165 lines (139 loc) · 5.04 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
# SQL Parser Go Makefile
# Variables
BINARY_NAME=sqlparser
MAIN_PATH=./cmd/sqlparser
BUILD_DIR=./bin
PACKAGES=./...
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOLINT=golint
.PHONY: all build clean test deps fmt lint run help install
# Default target
all: deps fmt lint test build
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
# Install dependencies
deps:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v $(PACKAGES)
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
# Lint code
lint:
@echo "Linting code..."
@command -v golint >/dev/null 2>&1 || { echo "golint not installed. Installing..."; $(GOGET) -u golang.org/x/lint/golint; }
golint $(PACKAGES)
# Run the application
run:
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
./$(BUILD_DIR)/$(BINARY_NAME)
# Install the binary to GOPATH/bin
install:
@echo "Installing $(BINARY_NAME)..."
$(GOBUILD) -o $(GOPATH)/bin/$(BINARY_NAME) $(MAIN_PATH)
# Development commands
dev-query:
@echo "Running development query analysis..."
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
./$(BUILD_DIR)/$(BINARY_NAME) -query ./examples/queries/complex_query.sql -output table -verbose
dev-simple:
@echo "Running simple query analysis..."
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
./$(BUILD_DIR)/$(BINARY_NAME) -query ./examples/queries/simple_query.sql -output json
dev-log:
@echo "Running log analysis..."
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
./$(BUILD_DIR)/$(BINARY_NAME) -log ./examples/logs/sample_profiler.log -output table
# Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
# Generate documentation
docs:
@echo "Generating documentation..."
$(GOCMD) doc -all $(PACKAGES)
# Check for security vulnerabilities
security:
@echo "Checking for security vulnerabilities..."
@command -v gosec >/dev/null 2>&1 || { echo "gosec not installed. Installing..."; $(GOGET) github.com/securecodewarrior/gosec/v2/cmd/gosec@latest; }
gosec $(PACKAGES)
# Run benchmarks
bench:
@echo "Running performance benchmarks..."
$(GOTEST) -run=none -bench=. -benchmem $(PACKAGES)
# Run benchmarks with CPU profiling
bench-cpu:
@echo "Running benchmarks with CPU profiling..."
$(GOTEST) -run=none -bench=. -benchmem -cpuprofile=cpu.prof $(PACKAGES)
# Run benchmarks with memory profiling
bench-mem:
@echo "Running benchmarks with memory profiling..."
$(GOTEST) -run=none -bench=. -benchmem -memprofile=mem.prof $(PACKAGES)
# Performance comparison
perf-compare:
@echo "Running performance comparison..."
$(GOTEST) -run=none -bench=BenchmarkParser -count=5 -benchmem $(PACKAGES)
# Build optimized release version
build-release:
@echo "Building optimized release version..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) -ldflags="-s -w" -gcflags="-m" -o $(BUILD_DIR)/$(BINARY_NAME)-optimized $(MAIN_PATH)
# Build with performance profiling enabled
build-profile:
@echo "Building with profiling enabled..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -tags profile -o $(BUILD_DIR)/$(BINARY_NAME)-profile $(MAIN_PATH)
# Optimize build
build-optimized:
@echo "Building optimized $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -ldflags="-s -w" -gcflags="-N -l" -o $(BUILD_DIR)/$(BINARY_NAME)-optimized $(MAIN_PATH)
# Show help
help:
@echo "Available targets:"
@echo " all - Run deps, fmt, lint, test, and build"
@echo " build - Build the application"
@echo " build-optimized - Build with optimization flags"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " test - Run tests"
@echo " bench - Run benchmarks with memory stats"
@echo " perf - Run performance tests"
@echo " profile - Run with CPU profiling"
@echo " memcheck - Check memory usage (requires valgrind)"
@echo " fmt - Format code"
@echo " lint - Lint code"
@echo " run - Build and run the application"
@echo " install - Install binary to GOPATH/bin"
@echo " dev-query - Run development query analysis"
@echo " dev-simple - Run simple query analysis"
@echo " dev-log - Run log analysis"
@echo " build-all - Build for multiple platforms"
@echo " docs - Generate documentation"
@echo " security - Check for security vulnerabilities"
@echo " help - Show this help"