-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
75 lines (64 loc) · 1.65 KB
/
Makefile
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
# Makefile for Go Project
# Project variables
PROJECT_NAME := gorag
BINARY_NAME := $(PROJECT_NAME)
BUILD_DIR := build
GO_FILES := $(shell find . -name '*.go' -not -path "./vendor/*")
# Tools
GOFMT := gofmt
GOLINT := golint
GOTEST := go test
GOBUILD := go build
GOCLEAN := go clean
# Default target
all: format lint test build
# Format code using gofmt
.PHONY: format
format:
@echo "==> Formatting code..."
@$(GOFMT) -s -w $(GO_FILES)
# Lint code using golint
.PHONY: lint
lint:
@echo "==> Linting code..."
@if ! [ -x "$$(command -v $(GOLINT))" ]; then \
echo "Installing golint..."; \
go install golang.org/x/lint/golint@latest; \
fi
@$(GOLINT) ./...
# Run tests
.PHONY: test
test:
@echo "==> Running tests..."
@$(GOTEST) -v ./...
# Build the project
.PHONY: build
build:
@echo "==> Building binary..."
@mkdir -p $(BUILD_DIR)
@$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME)
# Clean build files
.PHONY: clean
clean:
@echo "==> Cleaning build files..."
@$(GOCLEAN)
@rm -rf $(BUILD_DIR)
# Install project dependencies (if necessary)
.PHONY: deps
deps:
@echo "==> Installing dependencies..."
@go mod tidy
# Run all targets (default behavior)
.PHONY: all
all: format lint test build
# Help message
.PHONY: help
help:
@echo "Available make commands:"
@echo " make format - Format all Go source files"
@echo " make lint - Run linters on the source code"
@echo " make test - Run unit tests"
@echo " make build - Build the project binary"
@echo " make clean - Remove build files and clean the project"
@echo " make deps - Install project dependencies"
@echo " make all - Format, lint, test, and build the project"