|
| 1 | +# Makefile for SecureLog - Dual MAC Secure Logging System |
| 2 | +# https://github.com/karasz/securelog |
| 3 | + |
| 4 | +.PHONY: all build test lint fmt vet revive clean install help spell |
| 5 | + |
| 6 | +# Go parameters |
| 7 | +GOCMD=go |
| 8 | +GOBUILD=$(GOCMD) build |
| 9 | +GOTEST=$(GOCMD) test |
| 10 | +GOGET=$(GOCMD) get |
| 11 | +GOFMT=$(GOCMD) fmt |
| 12 | +GOVET=$(GOCMD) vet |
| 13 | +GOMOD=$(GOCMD) mod |
| 14 | + |
| 15 | +# Binary name |
| 16 | +BINARY_NAME=securelog |
| 17 | + |
| 18 | +# Build flags |
| 19 | +LDFLAGS=-ldflags "-s -w" |
| 20 | + |
| 21 | +# Default target |
| 22 | +all: fmt vet lint test build |
| 23 | + |
| 24 | +## help: Show this help message |
| 25 | +help: |
| 26 | + @echo 'Usage:' |
| 27 | + @echo ' make [target]' |
| 28 | + @echo '' |
| 29 | + @echo 'Targets:' |
| 30 | + @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' |
| 31 | + |
| 32 | +## build: Build the project |
| 33 | +build: |
| 34 | + @echo "Building..." |
| 35 | + $(GOBUILD) $(LDFLAGS) -v ./... |
| 36 | + |
| 37 | +## test: Run tests |
| 38 | +test: |
| 39 | + @echo "Running tests..." |
| 40 | + $(GOTEST) -v -race -coverprofile=coverage.out ./... |
| 41 | + @echo "" |
| 42 | + @echo "Coverage summary:" |
| 43 | + @$(GOCMD) tool cover -func=coverage.out | tail -1 |
| 44 | + |
| 45 | +## test-short: Run tests without race detector (faster) |
| 46 | +test-short: |
| 47 | + @echo "Running tests (short)..." |
| 48 | + $(GOTEST) -v ./... |
| 49 | + |
| 50 | +## coverage: Run tests and show coverage report in browser |
| 51 | +coverage: test |
| 52 | + @echo "Opening coverage report in browser..." |
| 53 | + $(GOCMD) tool cover -html=coverage.out |
| 54 | + |
| 55 | +## bench: Run benchmarks |
| 56 | +bench: |
| 57 | + @echo "Running benchmarks..." |
| 58 | + $(GOTEST) -bench=. -benchmem ./... |
| 59 | + |
| 60 | +## fmt: Format Go code |
| 61 | +fmt: |
| 62 | + @echo "Formatting code..." |
| 63 | + @$(GOFMT) ./... |
| 64 | + @echo "Code formatted successfully" |
| 65 | + |
| 66 | +## vet: Run go vet |
| 67 | +vet: |
| 68 | + @echo "Running go vet..." |
| 69 | + @$(GOVET) ./... |
| 70 | + @echo "go vet passed" |
| 71 | + |
| 72 | +## lint: Run linters (revive + staticcheck) |
| 73 | +lint: revive staticcheck |
| 74 | + |
| 75 | +## revive: Run revive linter |
| 76 | +revive: |
| 77 | + @echo "Running revive..." |
| 78 | + @if ! command -v revive > /dev/null 2>&1; then \ |
| 79 | + if [ -f $(HOME)/go/bin/revive ]; then \ |
| 80 | + $(HOME)/go/bin/revive -config revive.toml -formatter friendly -exclude proto/... ./...; \ |
| 81 | + else \ |
| 82 | + echo "Installing revive..." && $(GOGET) github.com/mgechev/revive@latest && $(HOME)/go/bin/revive -config revive.toml -formatter friendly -exclude proto/... ./...; \ |
| 83 | + fi \ |
| 84 | + else \ |
| 85 | + revive -config revive.toml -formatter friendly -exclude proto/... ./...; \ |
| 86 | + fi |
| 87 | + |
| 88 | +## staticcheck: Run staticcheck |
| 89 | +staticcheck: |
| 90 | + @echo "Running staticcheck..." |
| 91 | + @if ! command -v staticcheck > /dev/null 2>&1; then \ |
| 92 | + if [ -f $(HOME)/go/bin/staticcheck ]; then \ |
| 93 | + $(HOME)/go/bin/staticcheck ./...; \ |
| 94 | + else \ |
| 95 | + echo "Installing staticcheck..." && $(GOGET) honnef.co/go/tools/cmd/staticcheck@latest && $(HOME)/go/bin/staticcheck ./...; \ |
| 96 | + fi \ |
| 97 | + else \ |
| 98 | + staticcheck ./...; \ |
| 99 | + fi |
| 100 | + |
| 101 | +## spell: Run spell checker (cspell) |
| 102 | +spell: |
| 103 | + @echo "Running spell checker..." |
| 104 | + @if ! command -v cspell > /dev/null 2>&1; then \ |
| 105 | + echo "cspell not found. Install with: npm install -g cspell"; \ |
| 106 | + echo "Or use: npx cspell"; \ |
| 107 | + exit 1; \ |
| 108 | + fi |
| 109 | + @cspell --no-progress "**/*.{go,md,txt,toml,yml,yaml}" --exclude "vendor/**" --exclude "*.log" |
| 110 | + |
| 111 | +## check: Run all checks (fmt, vet, lint, spell, test) |
| 112 | +check: fmt vet lint spell test |
| 113 | + @echo "" |
| 114 | + @echo "✓ All checks passed!" |
| 115 | + |
| 116 | +## clean: Remove build artifacts and test files |
| 117 | +clean: |
| 118 | + @echo "Cleaning..." |
| 119 | + @rm -f $(BINARY_NAME) |
| 120 | + @rm -f coverage.out |
| 121 | + @rm -rf testdata/tmp* |
| 122 | + @$(GOCMD) clean -testcache |
| 123 | + @echo "Cleaned successfully" |
| 124 | + |
| 125 | +## deps: Download dependencies |
| 126 | +deps: |
| 127 | + @echo "Downloading dependencies..." |
| 128 | + @$(GOMOD) download |
| 129 | + @$(GOMOD) tidy |
| 130 | + |
| 131 | +## deps-update: Update dependencies |
| 132 | +deps-update: |
| 133 | + @echo "Updating dependencies..." |
| 134 | + @$(GOGET) -u ./... |
| 135 | + @$(GOMOD) tidy |
| 136 | + |
| 137 | +## install-tools: Install development tools |
| 138 | +install-tools: |
| 139 | + @echo "Installing development tools..." |
| 140 | + @$(GOGET) github.com/mgechev/revive@latest |
| 141 | + @$(GOGET) honnef.co/go/tools/cmd/staticcheck@latest |
| 142 | + @$(GOGET) github.com/securego/gosec/v2/cmd/gosec@latest |
| 143 | + @echo "" |
| 144 | + @echo "Go tools installed successfully" |
| 145 | + @echo "" |
| 146 | + @echo "To install cspell (spell checker), run:" |
| 147 | + @echo " npm install -g cspell" |
| 148 | + @echo "Or use npx: npx cspell" |
| 149 | + |
| 150 | +## verify: Verify dependencies and check for issues |
| 151 | +verify: |
| 152 | + @echo "Verifying dependencies..." |
| 153 | + @$(GOMOD) verify |
| 154 | + @echo "Dependencies verified" |
| 155 | + |
| 156 | +## security: Run security checks with gosec |
| 157 | +security: |
| 158 | + @echo "Running security checks..." |
| 159 | + @if ! command -v gosec > /dev/null 2>&1; then \ |
| 160 | + if [ -f $(HOME)/go/bin/gosec ]; then \ |
| 161 | + $(HOME)/go/bin/gosec -quiet ./...; \ |
| 162 | + else \ |
| 163 | + echo "Installing gosec..." && $(GOGET) github.com/securego/gosec/v2/cmd/gosec@latest && $(HOME)/go/bin/gosec -quiet ./...; \ |
| 164 | + fi \ |
| 165 | + else \ |
| 166 | + gosec -quiet ./...; \ |
| 167 | + fi |
| 168 | + |
| 169 | +## ci: Run CI pipeline (fmt, vet, lint, spell, test) |
| 170 | +ci: deps verify fmt vet lint spell test |
| 171 | + @echo "" |
| 172 | + @echo "✓ CI pipeline completed successfully!" |
| 173 | + |
| 174 | +## doc: Generate and serve documentation |
| 175 | +doc: |
| 176 | + @echo "Starting documentation server at http://localhost:6060" |
| 177 | + @which godoc > /dev/null || (echo "Installing godoc..." && $(GOGET) golang.org/x/tools/cmd/godoc@latest) |
| 178 | + @godoc -http=:6060 |
| 179 | + |
| 180 | +.DEFAULT_GOAL := help |
0 commit comments