Makefile RawHistoryFolder
1# Makefile for dumber (Clean Architecture - puregotk)
2
3.PHONY: build build-frontend test lint clean install-tools dev generate help init check-docs man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego
4
5# Load local overrides from .env.local if present (Makefile syntax)
6ifneq (,$(wildcard .env.local))
7include .env.local
8export
9endif
10
11# Variables
12BINARY_NAME=dumber
13MAIN_PATH=./cmd/dumber
14DIST_DIR=dist
15
16# Detect number of CPU cores for parallel compilation
17NPROCS?=$(shell nproc 2>/dev/null || echo 1)
18
19# Version information from git
20VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev")
21COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
22BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
23
24# Linker flags
25LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)"
26
27# Default target
28help: ## Show this help message
29 @echo "Available targets:"
30 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
31
32# Build targets
33build: build-frontend ## Build the application (pure Go, no CGO)
34 @echo "Building $(BINARY_NAME) $(VERSION) using $(NPROCS) cores..."
35 @mkdir -p $(DIST_DIR)
36 CGO_ENABLED=0 go build -p $(NPROCS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
37 @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
38
39build-frontend: ## Build homepage and error pages
40 @echo "Building webui pages (homepage + error)..."
41 @cd webui && npm install --silent && npm run build
42 @echo "Frontend build complete"
43
44build-quick: ## Build without frontend (faster for backend development)
45 @echo "Building $(BINARY_NAME) $(VERSION) (quick, no frontend)..."
46 @mkdir -p $(DIST_DIR)
47 CGO_ENABLED=0 go build -p $(NPROCS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
48 @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
49
50# Development targets
51dev: ## Run in development mode
52 @echo "Running in development mode..."
53 go run $(MAIN_PATH)
54
55run: build-quick ## Build and run
56 @echo "Running $(BINARY_NAME)..."
57 $(DIST_DIR)/$(BINARY_NAME)
58
59generate: ## Generate code (SQLC)
60 @echo "Generating code with SQLC..."
61 sqlc generate
62 @echo "Code generation complete"
63
64mocks: ## Generate mock implementations with mockery
65 @echo "Generating mocks with mockery..."
66 mockery
67 @echo "Mock generation complete"
68
69# Testing
70test: ## Run tests
71 @echo "Running tests..."
72 go test -v ./...
73
74check-docs: ## Verify README/docs match code
75 @go run ./dev/check-docs.go --fail-on-error
76
77test-race: ## Run tests with race detection
78 @echo "Running tests with race detection..."
79 go test -race -v ./...
80
81test-cover: ## Run tests with coverage
82 @echo "Running tests with coverage..."
83 go test -coverprofile=coverage.out ./...
84 go tool cover -html=coverage.out -o coverage.html
85 @echo "Coverage report: coverage.html"
86
87stress-omnibox-callbacks: ## Run placeholder omnibox callback stress harness
88 GOFLAGS=-mod=mod CGO_ENABLED=0 go run ./scripts/stress_omnibox_callbacks.go
89
90verify-purego: ## Ensure callback path stays cgo/export free
91 bash ./scripts/verify_purego_only.sh
92
93# Linting
94lint: ## Run golangci-lint
95 @echo "Running golangci-lint..."
96 golangci-lint run
97
98lint-fix: ## Run golangci-lint with --fix
99 @echo "Running golangci-lint with --fix..."
100 golangci-lint run --fix
101
102# Format code
103fmt: ## Format Go code with gofmt
104 @echo "Formatting Go code..."
105 go fmt ./...
106
107# Tools installation
108install-tools: ## Install development tools
109 @echo "Installing development tools..."
110 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
111 go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
112 @echo "Tools installed successfully"
113
114# Cleanup
115clean: ## Clean build artifacts
116 @echo "Cleaning build artifacts..."
117 rm -rf $(DIST_DIR)
118 rm -f $(BINARY_NAME)
119 rm -rf webui/dist webui/node_modules
120 rm -f assets/webui/homepage.min.js assets/webui/error.min.js assets/webui/config.min.js assets/webui/index.html assets/webui/error.html assets/webui/config.html assets/webui/style.css
121 rm -f coverage.out coverage.html
122 go clean -cache
123 go clean -testcache
124
125# Project initialization
126init: install-tools ## Initialize project dependencies and tools
127 @echo "Initializing project..."
128 go mod tidy
129 @echo "Project initialized! Run 'make help' for available commands."
130
131# Check setup
132check: ## Check that all tools and dependencies are working
133 @echo "Checking project setup..."
134 @echo "Go version:"
135 @go version
136 @echo "\nSQLC version:"
137 @sqlc version
138 @echo "\nGolangci-lint version:"
139 @golangci-lint version
140 @echo "\nBuilding project..."
141 @$(MAKE) build-quick
142 @echo "\nRunning tests..."
143 @$(MAKE) test
144 @echo "\nVerifying purego-only constraints..."
145 @$(MAKE) verify-purego
146 @echo "\nAll checks passed!"
147
148# Documentation
149man: build-quick ## Install man pages to ~/.local/share/man/man1/
150 @echo "Installing man pages..."
151 $(DIST_DIR)/$(BINARY_NAME) gen-docs
152
153# Native release targets
154.PHONY: release-snapshot release
155
156release-snapshot: build-frontend ## Build snapshot using goreleaser
157 @echo "Building snapshot with goreleaser..."
158 goreleaser release --snapshot --clean
159
160release: ## Create full release using goreleaser
161 @echo "Building release with goreleaser..."
162 GITHUB_TOKEN=$$(gh auth token) goreleaser release --clean
163
164# Flatpak targets
165flatpak-deps: ## Install Flatpak build dependencies (Arch)
166 @echo "Installing Flatpak build dependencies..."
167 sudo pacman -S --needed flatpak flatpak-builder
168 flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
169 flatpak install --user -y flathub org.gnome.Platform//48 org.gnome.Sdk//48
170 flatpak install --user -y flathub org.freedesktop.Sdk.Extension.golang//24.08
171 flatpak install --user -y flathub org.freedesktop.Sdk.Extension.node20//24.08
172 @echo "Flatpak dependencies installed!"
173
174flatpak-build: ## Build Flatpak bundle locally
175 @echo "Building Flatpak bundle..."
176 flatpak-builder --force-clean --user --repo=flatpak-repo flatpak-build dev.bnema.Dumber.yml
177 flatpak build-bundle flatpak-repo dumber.flatpak dev.bnema.Dumber
178 @echo "Flatpak bundle created: dumber.flatpak"
179
180flatpak-install: ## Install Flatpak locally for testing
181 @echo "Installing Flatpak locally..."
182 flatpak-builder --force-clean --user --install flatpak-build dev.bnema.Dumber.yml
183 @echo "Flatpak installed! Run with: make flatpak-run"
184
185flatpak-run: ## Run the installed Flatpak
186 flatpak run dev.bnema.Dumber
187
188flatpak-clean: ## Clean Flatpak build artifacts
189 @echo "Cleaning Flatpak build artifacts..."
190 rm -rf flatpak-build flatpak-repo .flatpak-builder dumber.flatpak
191 @echo "Flatpak artifacts cleaned!"