Makefile RawHistoryFolder
1# Makefile for dumber (Clean Architecture - puregotk)
2
3.PHONY: build build-frontend test lint clean install-tools dev generate help init man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego check
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
74test-race: ## Run tests with race detection
75 @echo "Running tests with race detection..."
76 go test -race -v ./...
77
78test-cover: ## Run tests with coverage
79 @echo "Running tests with coverage..."
80 go test -coverprofile=coverage.out ./...
81 go tool cover -html=coverage.out -o coverage.html
82 @echo "Coverage report: coverage.html"
83
84stress-omnibox-callbacks: ## Run placeholder omnibox callback stress harness
85 GOFLAGS=-mod=mod CGO_ENABLED=0 go run ./scripts/stress_omnibox_callbacks.go
86
87verify-purego: ## Ensure callback path stays cgo/export free
88 bash ./scripts/verify_purego_only.sh
89
90# Linting
91lint: ## Run golangci-lint
92 @echo "Running golangci-lint..."
93 golangci-lint run
94
95lint-fix: ## Run golangci-lint with --fix
96 @echo "Running golangci-lint with --fix..."
97 golangci-lint run --fix
98
99# Format code
100fmt: ## Format Go code with gofmt
101 @echo "Formatting Go code..."
102 go fmt ./...
103
104# Tools installation
105install-tools: ## Install development tools
106 @echo "Installing development tools..."
107 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
108 go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
109 @echo "Tools installed successfully"
110
111# Cleanup
112clean: ## Clean build artifacts
113 @echo "Cleaning build artifacts..."
114 rm -rf $(DIST_DIR)
115 rm -f $(BINARY_NAME)
116 rm -rf webui/dist webui/node_modules
117 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
118 rm -f coverage.out coverage.html
119 go clean -cache
120 go clean -testcache
121
122# Project initialization
123init: install-tools ## Initialize project dependencies and tools
124 @echo "Initializing project..."
125 go mod tidy
126 @echo "Project initialized! Run 'make help' for available commands."
127
128# Check setup
129check: ## Check that all tools and dependencies are working
130 @echo "Checking project setup..."
131 @echo "Go version:"
132 @go version
133 @echo "\nSQLC version:"
134 @sqlc version
135 @echo "\nGolangci-lint version:"
136 @golangci-lint version
137 @echo "\nBuilding project..."
138 @$(MAKE) build-quick
139 @echo "\nRunning tests..."
140 @$(MAKE) test
141 @echo "\nVerifying purego-only constraints..."
142 @$(MAKE) verify-purego
143 @echo "\nAll checks passed!"
144
145# Documentation
146man: build-quick ## Install man pages to ~/.local/share/man/man1/
147 @echo "Installing man pages..."
148 $(DIST_DIR)/$(BINARY_NAME) gen-docs
149
150# Native release targets
151.PHONY: release-snapshot release
152
153release-snapshot: build-frontend ## Build snapshot using goreleaser
154 @echo "Building snapshot with goreleaser..."
155 goreleaser release --snapshot --clean
156
157release: ## Create full release using goreleaser
158 @echo "Building release with goreleaser..."
159 GITHUB_TOKEN=$$(gh auth token) goreleaser release --clean
160
161# Flatpak targets
162flatpak-deps: ## Install Flatpak build dependencies (Arch)
163 @echo "Installing Flatpak build dependencies..."
164 sudo pacman -S --needed flatpak flatpak-builder
165 flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
166 flatpak install --user -y flathub org.gnome.Platform//48 org.gnome.Sdk//48
167 flatpak install --user -y flathub org.freedesktop.Sdk.Extension.golang//24.08
168 flatpak install --user -y flathub org.freedesktop.Sdk.Extension.node20//24.08
169 @echo "Flatpak dependencies installed!"
170
171flatpak-build: ## Build Flatpak bundle locally
172 @echo "Building Flatpak bundle..."
173 flatpak-builder --force-clean --user --repo=flatpak-repo flatpak-build dev.bnema.Dumber.yml
174 flatpak build-bundle flatpak-repo dumber.flatpak dev.bnema.Dumber
175 @echo "Flatpak bundle created: dumber.flatpak"
176
177flatpak-install: ## Install Flatpak locally for testing
178 @echo "Installing Flatpak locally..."
179 flatpak-builder --force-clean --user --install flatpak-build dev.bnema.Dumber.yml
180 @echo "Flatpak installed! Run with: make flatpak-run"
181
182flatpak-run: ## Run the installed Flatpak
183 flatpak run dev.bnema.Dumber
184
185flatpak-clean: ## Clean Flatpak build artifacts
186 @echo "Cleaning Flatpak build artifacts..."
187 rm -rf flatpak-build flatpak-repo .flatpak-builder dumber.flatpak
188 @echo "Flatpak artifacts cleaned!"