Makefile RawHistoryFolder
1# Makefile for dumber
2
3.PHONY: build build-frontend test lint clean install-tools dev generate help check init build-static build-no-gui
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=.
14DIST_DIR=dist
15
16# Detect number of CPU cores for parallel compilation
17NPROCS?=$(shell nproc 2>/dev/null || echo 1)
18
19# Local caches to avoid $HOME permission issues (override via .env.local)
20GOMODCACHE?=$(CURDIR)/tmp/go-mod
21GOCACHE?=$(CURDIR)/tmp/go-cache
22GOTMPDIR?=$(CURDIR)/tmp
23GOENV=GOMODCACHE=$(GOMODCACHE) GOCACHE=$(GOCACHE) GOTMPDIR=$(GOTMPDIR)
24
25# Version information from git
26VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev")
27COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
28BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
29
30# Linker flags
31LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE)"
32
33# Default target
34help: ## Show this help message
35 @echo "Available targets:"
36 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
37
38# Build targets
39build: build-frontend ## Build the application with GUI (frontend assets, then Go binary with WebKitGTK)
40 @echo "Building $(BINARY_NAME) $(VERSION) with GUI using $(NPROCS) cores..."
41 @mkdir -p $(DIST_DIR) tmp tmp/go-cache tmp/go-mod
42 $(GOENV) CGO_ENABLED=1 go build -p $(NPROCS) $(LDFLAGS) -tags=webkit_cgo -o $(DIST_DIR)/$(BINARY_NAME) $(MAIN_PATH)
43 @echo "✅ Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)"
44
45build-frontend: ## Build Svelte GUI with Tailwind CSS
46 @echo "Building Svelte GUI with Tailwind CSS..."
47 @cd gui && npm install --silent && npm run build
48 @echo "GUI build complete"
49
50build-no-gui: build-frontend ## Build binary without GUI (CGO disabled, CLI-only functionality)
51 @echo "Building $(BINARY_NAME) $(VERSION) (CLI-only, no GUI) using $(NPROCS) cores..."
52 @mkdir -p $(DIST_DIR) tmp tmp/go-cache tmp/go-mod
53 $(GOENV) CGO_ENABLED=0 go build -p $(NPROCS) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-no-gui $(MAIN_PATH)
54 @echo "✅ Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)-no-gui"
55
56build-static: build-no-gui ## Alias for build-no-gui (backward compatibility)
57 @echo "Note: build-static is deprecated, use build-no-gui instead"
58
59# GUI build with WebKitGTK 6.0 (GTK4)
60.PHONY: build-gui run-gui
61build-gui: build ## Alias for default build (backward compatibility)
62 @echo "Note: build-gui is now the default 'build' target"
63
64run-gui: ## Run the GUI with native WebKitGTK 6.0 (requires GTK4/WebKitGTK 6 dev packages)
65 @echo "Running GUI (webkit_cgo) using $(NPROCS) cores…"
66 @mkdir -p tmp tmp/go-cache tmp/go-mod
67 $(GOENV) CGO_ENABLED=1 go run -p $(NPROCS) -tags=webkit_cgo $(MAIN_PATH)
68
69.PHONY: check-webkit
70check-webkit: ## Check system has GTK4/WebKitGTK 6.0/JavaScriptCore 6.0
71 @echo "Checking pkg-config versions..."
72 @which pkg-config >/dev/null 2>&1 || (echo "pkg-config not found" && exit 1)
73 @echo "gtk4: $$(pkg-config --modversion gtk4 2>/dev/null || echo not found)"
74 @echo "webkitgtk-6.0: $$(pkg-config --modversion webkitgtk-6.0 2>/dev/null || echo not found)"
75 @echo "javascriptcoregtk-6.0: $$(pkg-config --modversion javascriptcoregtk-6.0 2>/dev/null || echo not found)"
76
77# Development targets
78dev: ## Run in development mode
79 @echo "Running in development mode..."
80 go run $(MAIN_PATH)
81
82generate: ## Generate code (SQLC)
83 @echo "Generating code with SQLC..."
84 sqlc generate
85 @echo "Code generation complete"
86
87# Testing
88test: ## Run tests
89 @echo "Running tests..."
90 @mkdir -p tmp tmp/go-cache tmp/go-mod
91 $(GOENV) CGO_ENABLED=0 go test -v ./...
92
93test-race: ## Run tests with race detection
94 @echo "Running tests with race detection..."
95 @mkdir -p tmp tmp/go-cache tmp/go-mod
96 $(GOENV) CGO_ENABLED=1 go test -race -v ./...
97
98# Linting
99lint: ## Run golangci-lint
100 @echo "Running golangci-lint..."
101 golangci-lint run
102
103lint-fix: ## Run golangci-lint with --fix
104 @echo "Running golangci-lint with --fix..."
105 golangci-lint run --fix
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) # Remove any old binaries in root
119 rm -rf gui/dist gui/node_modules
120 go clean -cache
121 go clean -testcache
122
123# Project initialization
124init: install-tools ## Initialize project dependencies and tools
125 @echo "Project dependencies and tools installed!"
126 @echo "Ready for development. 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 @$(GOENV) go version
133 @echo "\nSQLC version:"
134 @$(GOENV) sqlc version
135 @echo "\nGolangci-lint version:"
136 @$(GOENV) golangci-lint version
137 @echo "\nBuilding project..."
138 @$(MAKE) build
139 @echo "\nTesting built binary..."
140 @$(DIST_DIR)/$(BINARY_NAME) version
141 @echo "\nRunning tests..."
142 @$(MAKE) test
143 @echo "\n✅ All checks passed! Project is ready for development."