-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
218 lines (186 loc) · 7.49 KB
/
Makefile
File metadata and controls
218 lines (186 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Makefile for MindPalace project
# Variables
GO := go
GOFLAGS := -v
CGO_ENABLED := 1
BINARY_NAME := mindpalace
PLUGIN_DIR := plugins
BUILD_DIR := build
MAIN_SRC := cmd/mindpalace/main.go
PLUGIN_NAMES := calendar plugingenerator taskmanager
PLUGIN_OUTPUTS := $(foreach name, $(PLUGIN_NAMES), $(PLUGIN_DIR)/$(name)/$(name).so)
MODELS_DIR := models
WHISPER_MODEL := $(MODELS_DIR)/ggml-base.en.bin
# Derived paths
ROOT_DIR := $(shell pwd)
WHISPER_LIB_DIR := $(ROOT_DIR)/whisper-cpp/build/lib
PKG_CONFIG_PATH := $(WHISPER_LIB_DIR)/pkgconfig:$(PKG_CONFIG_PATH)
# Allow passing arguments to run
RUN_ARGS ?=
# Default target
.PHONY: all
all: whisper build plugins
# Build the main binary
.PHONY: build
build: setup world
@echo "Building MindPalace binary..."
@mkdir -p $(BUILD_DIR)
PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) CGO_LDFLAGS="-Wl,-rpath,$(WHISPER_LIB_DIR)" $(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_SRC)
# Build all plugins
.PHONY: plugins
plugins: setup $(PLUGIN_OUTPUTS)
# Build plugins
$(PLUGIN_DIR)/calendar/calendar.so: $(PLUGIN_DIR)/calendar/plugin.go
@echo "Building plugin: $@"
cd $(dir $<) && $(GO) build $(GOFLAGS) -buildmode=plugin -o calendar.so ./*.go
$(PLUGIN_DIR)/plugingenerator/plugingenerator.so: $(PLUGIN_DIR)/plugingenerator/plugin.go
@echo "Building plugin: $@"
cd $(dir $<) && $(GO) build $(GOFLAGS) -buildmode=plugin -o plugingenerator.so ./*.go
$(PLUGIN_DIR)/taskmanager/taskmanager.so: $(PLUGIN_DIR)/taskmanager/plugin.go
@echo "Building plugin: $@"
cd $(dir $<) && $(GO) build $(GOFLAGS) -buildmode=plugin -o taskmanager.so ./*.go
# Run the application with optional arguments
.PHONY: run
run: build plugins
@echo "Running MindPalace with args: $(RUN_ARGS)"
@echo "LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) $(RUN_ARGS)"
LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) $(RUN_ARGS)
# Run with verbose logging
.PHONY: run-verbose
run-verbose: build plugins
@echo "Running MindPalace in verbose mode..."
@echo "LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -trace"
LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -trace
# Run with debug logging
.PHONY: run-debug
run-debug: build plugins
@echo "Running MindPalace in debug mode..."
@echo "LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -debug"
LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -debug
# Run in headless mode
.PHONY: run-headless
run-headless: build plugins
@echo "Running MindPalace in headless mode..."
@echo "LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -headless"
LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -headless
# Run for testing with log capture and auto-kill after 10s
.PHONY: run-test
run-test: build plugins
@echo "Running MindPalace for testing (10s timeout)..."
@echo "Starting application..."
@timeout 10s bash -c 'LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH ./$(BUILD_DIR)/$(BINARY_NAME) -debug 2>&1 | tee test_run.log' || true
@echo "Application stopped after 10 seconds. Logs saved to test_run.log"
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning up..."
rm -rf $(BUILD_DIR)
find $(PLUGIN_DIR) -name "*.so" -type f -delete
# Clean everything including dependencies
.PHONY: clean-all
clean-all: clean
@echo "Cleaning all dependencies..."
rm -rf whisper-cpp
# Check dependencies and install
.PHONY: setup
setup:
@echo "Checking dependencies..."
@if ! command -v go > /dev/null 2>&1; then echo "Error: Go is not installed. Please install Go 1.23.5 or later."; exit 1; fi
@if ! command -v godot > /dev/null 2>&1; then echo "Warning: Godot not found. You may need to install it for the UI components."; fi
@if ! command -v cmake > /dev/null 2>&1; then echo "Error: CMake is not installed. Please install CMake."; exit 1; fi
@echo "Installing Go dependencies..."
$(GO) mod tidy
$(GO) mod download
$(MAKE) whisper
$(MAKE) download-model
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
$(GO) fmt ./...
# Run tests
.PHONY: test
test:
@echo "Running tests..."
PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) CGO_LDFLAGS="-Wl,-rpath,$(WHISPER_LIB_DIR)" LD_LIBRARY_PATH=$(WHISPER_LIB_DIR):$$LD_LIBRARY_PATH $(GO) test ./... -v
# Generate documentation
.PHONY: doc
doc:
@echo "Generating documentation..."
$(GO) doc -all ./... > doc.txt
# Check code quality
.PHONY: lint
lint:
@echo "Running linter..."
CGO_ENABLED=1 PKG_CONFIG_PATH=$(shell pwd)/whisper-cpp/build/lib/pkgconfig:$(PKG_CONFIG_PATH) CGO_LDFLAGS="-Wl,-rpath,$(shell pwd)/whisper-cpp/build/lib" golangci-lint run ./...
# Build everything and create a release package
.PHONY: release
release: clean build plugins
@echo "Creating release package..."
@mkdir -p release
tar -czf release/mindpalace.tar.gz $(BUILD_DIR)/$(BINARY_NAME) $(PLUGIN_OUTPUTS) events.json
# Development targets
.PHONY: dev
dev:
@echo "Starting development with air..."
air
.PHONY: dev-verbose
dev-verbose:
@echo "Starting development with air in verbose mode..."
air -c .air.toml -- -v
# Download Whisper model
.PHONY: download-model
download-model: $(WHISPER_MODEL)
$(WHISPER_MODEL):
@echo "Downloading Whisper model..."
@mkdir -p $(MODELS_DIR)
curl -L https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin -o $(WHISPER_MODEL)
# Clone Whisper repository
whisper-cpp:
@echo "Cloning Whisper repository..."
git clone https://github.com/ggerganov/whisper.cpp.git whisper-cpp
# Build the Whisper library
.PHONY: whisper
whisper: whisper-cpp
@echo "Building Whisper library..."
cd whisper-cpp && cmake -B build -DCMAKE_INSTALL_PREFIX=$(shell pwd)/whisper-cpp/build
cd whisper-cpp && cmake --build build --config Release
@echo "Installing Whisper library (ignoring bin install errors)..."
-cd whisper-cpp && cmake --install build || echo "Install completed with warnings (bins may not be installed)"
@echo "Setting up pkgconfig files..."
cd whisper-cpp/build/lib/pkgconfig && cp whisper.pc libwhisper.pc && cp whisper.pc libwhisper-linux.pc
# Build the Godot world binary
.PHONY: world
world:
@echo "Building Godot world binary..."
cd world && godot --headless --export-release Linux ./world.x86_64
@echo "Moving Godot world binary to pkg/world..."
@mkdir -p pkg/world
@cp world/world.x86_64 pkg/world/world
# Help target
.PHONY: help
help:
@echo "Available targets:"
@echo " all : Build everything (default)"
@echo " build : Build the main binary"
@echo ""
@echo " plugins : Build all plugins"
@echo " run : Build and run (use RUN_ARGS='flags' for arguments)"
@echo " run-verbose : Run with verbose logging"
@echo " run-debug : Run with debug logging"
@echo " run-headless: Run in headless mode"
@echo " clean : Remove build artifacts"
@echo " clean-all : Remove all build artifacts and dependencies"
@echo " setup : Check dependencies and install"
@echo " fmt : Format code"
@echo " test : Run tests"
@echo " doc : Generate documentation"
@echo " lint : Run linter"
@echo " release : Create a release package"
@echo " dev : Start development mode with air"
@echo " dev-verbose : Start development mode in verbose"
@echo " world : Build the Godot world binary and move to pkg/world"
@echo " whisper : Clone and build the Whisper library"
@echo " help : Show this help message"
@echo ""
@echo "Example: make run RUN_ARGS='-v --events custom_events.json'"