|
| 1 | +.PHONY: help build run test fmt docs clean vet lint coverage install-tools |
| 2 | + |
| 3 | +# Variables |
| 4 | +BINARY_NAME=lime-go |
| 5 | +GO=go |
| 6 | +GOFLAGS=-v |
| 7 | +GOTEST=$(GO) test |
| 8 | +GOVET=$(GO) vet |
| 9 | +GOFMT=gofmt |
| 10 | +GODOC=$(GO) doc |
| 11 | +MODULE=github.com/takenet/lime-go |
| 12 | +TEST_PACKAGES=$(shell $(GO) list ./... | grep -v '/examples/') |
| 13 | + |
| 14 | +# Default target |
| 15 | +help: ## Display this help message |
| 16 | + @echo "Available targets:" |
| 17 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' |
| 18 | + |
| 19 | +build: ## Build the project |
| 20 | + @echo "Building..." |
| 21 | + $(GO) build $(GOFLAGS) ./... |
| 22 | + |
| 23 | +run: ## Run the example client |
| 24 | + @echo "Running example client..." |
| 25 | + $(GO) run examples/client/main.go |
| 26 | + |
| 27 | +run-server: ## Run the example server |
| 28 | + @echo "Running example server..." |
| 29 | + $(GO) run examples/server/main.go examples/server/certificate.go examples/server/credentials.go |
| 30 | + |
| 31 | +run-ws-chat: ## Run the websocket chat server |
| 32 | + @echo "Running websocket chat server..." |
| 33 | + $(GO) run examples/ws-chat/server/main.go |
| 34 | + |
| 35 | +test: ## Run all tests with race detector |
| 36 | + @echo "Running tests with race detector..." |
| 37 | + $(GOTEST) $(GOFLAGS) -race -coverprofile=coverage.txt -covermode=atomic $(TEST_PACKAGES) |
| 38 | + |
| 39 | +test-no-race: ## Run all tests without race detector |
| 40 | + @echo "Running tests without race detector..." |
| 41 | + $(GOTEST) $(GOFLAGS) -coverprofile=coverage.txt -covermode=atomic $(TEST_PACKAGES) |
| 42 | + |
| 43 | +test-short: ## Run tests in short mode |
| 44 | + @echo "Running short tests..." |
| 45 | + $(GOTEST) $(GOFLAGS) -short $(TEST_PACKAGES) |
| 46 | + |
| 47 | +test-verbose: ## Run tests with verbose output |
| 48 | + @echo "Running tests with verbose output..." |
| 49 | + $(GOTEST) -v -race -coverprofile=coverage.txt -covermode=atomic $(TEST_PACKAGES) |
| 50 | + |
| 51 | +coverage: test ## Run tests and show coverage |
| 52 | + @echo "Generating coverage report..." |
| 53 | + $(GO) tool cover -html=coverage.txt -o coverage.html |
| 54 | + @echo "Coverage report generated: coverage.html" |
| 55 | + |
| 56 | +fmt: ## Format code with gofmt |
| 57 | + @echo "Formatting code..." |
| 58 | + $(GOFMT) -s -w . |
| 59 | + @echo "Code formatted successfully" |
| 60 | + |
| 61 | +fmt-check: ## Check if code is formatted |
| 62 | + @echo "Checking code format..." |
| 63 | + @test -z "$$($(GOFMT) -l .)" || (echo "Code is not formatted. Run 'make fmt'" && exit 1) |
| 64 | + |
| 65 | +vet: ## Run go vet |
| 66 | + @echo "Running go vet..." |
| 67 | + $(GOVET) ./... |
| 68 | + |
| 69 | +lint: ## Run golangci-lint (requires golangci-lint installed) |
| 70 | + @echo "Running linter..." |
| 71 | + @which golangci-lint > /dev/null || (echo "golangci-lint not installed. Run 'make install-tools'" && exit 1) |
| 72 | + golangci-lint run ./... |
| 73 | + |
| 74 | +docs: ## Generate and display documentation |
| 75 | + @echo "Generating documentation..." |
| 76 | + @echo "Main package:" |
| 77 | + $(GODOC) $(MODULE) |
| 78 | + @echo "\nFor full documentation, run: godoc -http=:6060" |
| 79 | + @echo "Then visit: http://localhost:6060/pkg/$(MODULE)/" |
| 80 | + |
| 81 | +docs-serve: ## Serve documentation on http://localhost:6060 |
| 82 | + @echo "Starting documentation server..." |
| 83 | + @which godoc > /dev/null || (echo "godoc not installed. Run 'make install-tools'" && exit 1) |
| 84 | + godoc -http=:6060 |
| 85 | + |
| 86 | +clean: ## Clean build artifacts and test cache |
| 87 | + @echo "Cleaning..." |
| 88 | + $(GO) clean |
| 89 | + rm -f coverage.txt coverage.html |
| 90 | + @echo "Clean complete" |
| 91 | + |
| 92 | +clean-cache: ## Clean Go build and module cache (fixes version mismatch issues) |
| 93 | + @echo "Cleaning Go cache..." |
| 94 | + $(GO) clean -cache -modcache -i -r |
| 95 | + @echo "Cache cleaned. Run 'make deps' to re-download dependencies." |
| 96 | + |
| 97 | +tidy: ## Tidy and verify module dependencies |
| 98 | + @echo "Tidying module dependencies..." |
| 99 | + $(GO) mod tidy |
| 100 | + $(GO) mod verify |
| 101 | + |
| 102 | +install-tools: ## Install development tools |
| 103 | + @echo "Installing development tools..." |
| 104 | + $(GO) install golang.org/x/tools/cmd/godoc@latest |
| 105 | + $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
| 106 | + @echo "Tools installed successfully" |
| 107 | + |
| 108 | +deps: ## Download dependencies |
| 109 | + @echo "Downloading dependencies..." |
| 110 | + $(GO) mod download |
| 111 | + |
| 112 | +check: fmt-check vet test ## Run all checks (format, vet, test) |
| 113 | + |
| 114 | +ci: check lint ## Run all CI checks |
| 115 | + |
| 116 | +all: clean deps build test ## Clean, download deps, build and test |
| 117 | + |
| 118 | +.DEFAULT_GOAL := help |
0 commit comments