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