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