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