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