-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
388 lines (333 loc) · 15.2 KB
/
Makefile
File metadata and controls
388 lines (333 loc) · 15.2 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# OmaSign Project Makefile
SHELL := /bin/bash
PROJECT_DIR := $(shell pwd)
# Detect Python version
PYTHON := $(shell command -v python3.13 || command -v python3.10 || command -v python3)
PYTHON_VERSION := $(shell $(PYTHON) -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
# Global UV install
UV := uv
# Translate Directory Resolution
TRANSLATE_DIR := $(shell if [ -d "$(PROJECT_DIR)/../translate" ]; then echo "$(PROJECT_DIR)/../translate"; elif [ -d "$(PROJECT_DIR)/../sign-translate" ]; then echo "$(PROJECT_DIR)/../sign-translate"; else echo ""; fi)
# Binaries from uv-managed environment
VENV_DIR := $(PROJECT_DIR)/.venv
PYTHON_BIN := $(VENV_DIR)/bin/python
PYTEST := $(VENV_DIR)/bin/pytest
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[1;33m
NC := \033[0m # No Color
# -- Phony Targets --
.PHONY: all setup check-tools check-uv venv install-pywhispercpp \
inject-configs build-rust run run-daemon run-control run-renderer \
start-servers start-ui test test-scripts clean clean-cache clean-all help run-frontend \
install-desktop uninstall-desktop fix-permissions
# -- Default Targets --
all: setup
help:
@printf "$(GREEN)OmaSign Build System$(NC)\n"
@printf "\n"
@printf "$(YELLOW)Setup Commands:$(NC)\n"
@printf " make setup - Complete initial setup\n"
@printf " make check-tools - Verify system dependencies\n"
@printf " make venv - Setup Python environment with uv\n"
@printf " make build-rust - Build Rust components (Tauri + Ratatui)\n"
@printf "\n"
@printf "$(YELLOW)Run Commands:$(NC)\n"
@printf " make run - Launch all services (daemon, control, renderer)\n"
@printf " make run-daemon - Run Python daemon only\n"
@printf " make run-control - Run Ratatui control hub only\n"
@printf " make run-renderer - Run Tauri signer window only\n"
@printf "\n"
@printf "$(YELLOW)Development:$(NC)\n"
@printf " make test - Run Python unit tests\n"
@printf " make test-scripts - Run shell script tests\n"
@printf " make test-all - Run all tests\n"
@printf " make clean - Remove build artifacts\n"
@printf " make clean-all - Remove everything (including venv)\n"
# -- Setup (Master Target) --
setup: fix-permissions check-tools check-uv venv install-pywhispercpp inject-configs build-rust install-desktop
@printf "$(GREEN)✓ Setup complete!$(NC)\n"
@printf "\n"
@printf "$(YELLOW)Next steps:$(NC)\n"
@printf " 1. Add to ~/.config/hypr/hyprland.conf:\n"
@printf " source = ~/.config/hypr/omasign.conf\n"
@printf " 2. Add to ~/.config/hypr/hyprlock.conf:\n"
@printf " source = ~/.config/hypr/hyprlock-omasign.conf\n"
@printf " 3. Log out and back in to apply autostart changes.\n"
@printf " 4. Launch 'OmaSign Control Hub' from your app menu or run: make run\n"
# -- Dependency Checks --
check-tools:
@bash $(PROJECT_DIR)/scripts/check_dependencies.sh
check-uv:
@printf "$(YELLOW)--- Checking uv Installation ---$(NC)\n"
@command -v uv >/dev/null 2>&1 || { \
printf "$(RED)✗ uv not found. Installing...$(NC)\n"; \
curl -LsSf https://astral.sh/uv/install.sh | sh; \
}
@printf "$(GREEN)✓ uv found: $$(uv --version)$(NC)\n"
# -- Fix Permissions --
fix-permissions:
@printf "$(YELLOW)--- Fixing script permissions ---$(NC)\n"
@chmod +x $(PROJECT_DIR)/scripts/*.sh
@chmod +x $(PROJECT_DIR)/tests/*.sh 2>/dev/null || true
@printf "$(GREEN)✓ Scripts made executable$(NC)\n"
# -- Python Environment Setup --
.venv/pyvenv.cfg:
@printf "$(YELLOW)--- Checking Python virtual environment ---$(NC)\n"
@if [ -f ".venv/pyvenv.cfg" ]; then \
read -p "A virtual environment already exists at .venv. Replace it? [y/N]: " yn; \
case $$yn in \
[Yy]*) \
printf "$(YELLOW)Recreating virtual environment...$(NC)\n"; \
rm -rf .venv; \
$(UV) venv --python $(PYTHON_VERSION); \
;; \
*) \
printf "$(GREEN)✓ Keeping existing virtual environment$(NC)\n"; \
;; \
esac; \
else \
printf "$(YELLOW)Creating Python virtual environment (Python $(PYTHON_VERSION))...$(NC)\n"; \
$(UV) venv --python $(PYTHON_VERSION); \
fi
@touch .venv/pyvenv.cfg
venv: .venv/pyvenv.cfg
@printf "$(YELLOW)--- Syncing Python dependencies with uv ---$(NC)\n"
@if [ -f "uv.lock" ]; then \
$(UV) sync; \
else \
$(UV) sync; \
fi
@printf "$(GREEN)✓ Python environment synced$(NC)\n"
# Special handling for pywhispercpp with hardware acceleration
install-pywhispercpp: venv
@printf "$(YELLOW)--- Installing pywhispercpp with HW Acceleration Support ---$(NC)\n"
@if [ -n "$$(lspci | grep -i nvidia)" ] && command -v nvcc &> /dev/null; then \
printf "$(GREEN)✓ NVIDIA GPU detected. Installing with CUDA support...$(NC)\n"; \
GGML_CUDA=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
elif command -v vulkaninfo &> /dev/null; then \
VULKAN_SUMMARY=$$(vulkaninfo --summary 2>/dev/null); \
if echo "$$VULKAN_SUMMARY" | grep -q "PHYSICAL_DEVICE_TYPE_DISCRETE_GPU"; then \
printf "$(GREEN)✓ Discrete Vulkan GPU detected. Installing with Vulkan support...$(NC)\n"; \
GGML_VULKAN=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
elif echo "$$VULKAN_SUMMARY" | grep -q "PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU" && \
echo "$$VULKAN_SUMMARY" | grep -iE "Arc|Radeon|Iris|Apple"; then \
printf "$(GREEN)✓ High-performance Integrated GPU detected (Arc/Radeon/Iris). Installing with Vulkan support...$(NC)\n"; \
GGML_VULKAN=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
else \
printf "$(YELLOW)⚠ Vulkan detected but appears to be a weak integrated GPU or software rasterizer.$(NC)\n"; \
printf "$(YELLOW)Falling back to CPU OpenBLAS for stability/performance.$(NC)\n"; \
GGML_BLAS=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
fi; \
elif [ -n "$$(uname -s | grep Darwin)" ]; then \
printf "$(GREEN)✓ macOS detected. Installing with CoreML support...$(NC)\n"; \
WHISPER_COREML=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
elif [ -n "$$(lspci | grep -iE 'Arc|Radeon|NVIDIA')" ]; then \
printf "$(YELLOW)⚠ High-end GPU name detected in lspci but 'vulkaninfo'/'nvcc' missing.$(NC)\n"; \
printf "$(YELLOW)Attempting Vulkan build anyway...$(NC)\n"; \
GGML_VULKAN=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
else \
printf "$(YELLOW)⚠ No dedicated accelerator detected.$(NC)\n"; \
printf "$(YELLOW)Installing with OpenBLAS support for CPU optimization...$(NC)\n"; \
GGML_BLAS=1 $(UV) pip install git+https://github.com/absadiki/pywhispercpp --force-reinstall --no-cache; \
fi
# -- Configuration Symlinking --
inject-configs:
@bash $(PROJECT_DIR)/scripts/setup_configs.sh
# -- Rust Build --
build-rust:
@printf "$(YELLOW)--- Building Rust components ---$(NC)\n"
@# Build Tauri renderer
@if [ -d "$(PROJECT_DIR)/renderer/signer-window/src-tauri" ]; then \
printf "$(YELLOW)Building Tauri signer window...$(NC)\n"; \
(cd $(PROJECT_DIR)/renderer/signer-window && npm install && npm run tauri build); \
printf "$(GREEN)✓ Tauri renderer built$(NC)\n"; \
else \
printf "$(YELLOW)⚠ renderer/signer-window not found. Please create it first.$(NC)\n"; \
fi
@# Build Ratatui control hub
@if [ -d "$(PROJECT_DIR)/control/sign_control" ]; then \
printf "$(YELLOW)Building Ratatui control hub...$(NC)\n"; \
(cd $(PROJECT_DIR)/control/sign_control && cargo build --release); \
printf "$(GREEN)✓ Control hub built$(NC)\n"; \
else \
printf "$(YELLOW)⚠ control/sign_control not found, Please create it first.$(NC)\n"; \
fi
# Install desktop entry
install-desktop: build-rust
@printf "$(YELLOW)--- Installing Desktop Entry ---$(NC)\n"
@bash $(PROJECT_DIR)/scripts/install_desktop.sh
@printf "$(GREEN)✓ Desktop entry installed$(NC)\n"
@printf "$(YELLOW)Launch from your application menu or run: make run-control$(NC)\n"
# Uninstall desktop entry
uninstall-desktop:
@printf "$(YELLOW)--- Removing Desktop Entry ---$(NC)\n"
@rm -f $(HOME)/.local/share/applications/omasign-control.desktop
@if command -v update-desktop-database &> /dev/null; then \
update-desktop-database $(HOME)/.local/share/applications; \
fi
@printf "$(GREEN)✓ Desktop entry removed$(NC)\n"
# -- Running Services --
.PHONY: restart
restart: stop run
# run: check-running
# @printf "$(GREEN)--- Launching OmaSign Services ---$(NC)\n"
# @printf "$(YELLOW)Starting daemon...$(NC)\n"
#
#
# @printf "$(YELLOW)Starting Control Hub and Renderer...$(NC)\n"
# @if [ -f "$(PROJECT_DIR)/control/sign_control/target/release/sign_control" ]; then \
# kitty --title "OmaSign Control" -e sh -c '$(PROJECT_DIR)/control/sign_control/target/release/sign_control; read -p "Control Hub stopped. Press Enter to close..."' & \
# fi
# @if [ -f "$(PROJECT_DIR)/renderer/signer-window/src-tauri/target/release/app" ]; then \
# $(PROJECT_DIR)/renderer/signer-window/src-tauri/target/release/app & \
# fi
# @sleep 1
# @printf "$(GREEN)✓ All services launched. Use 'make stop' to terminate.$(NC)\n"
#
run: fix-permissions stop start-servers start-ui
run-quiet: fix-permissions stop start-servers-quiet start-ui
start-servers: check-servers
@if [ -z "$(TRANSLATE_DIR)" ]; then \
printf "$(RED)✗ sign.mt frontend not found in ../translate or ../sign-translate$(NC)\n"; \
exit 1; \
fi
@printf "$(GREEN)--- Launching Background Services ---$(NC)\n"
@printf "$(YELLOW)Starting sign.mt frontend server...$(NC)\n"
@kitty --title "sign.mt Frontend" -e sh -c 'cd $(TRANSLATE_DIR) && npm start' &
@printf "$(YELLOW)Starting OmaSign daemon...$(NC)\n"
@kitty --title "OmaSign Daemon" -e sh -c '$(PYTHON_BIN) $(PROJECT_DIR)/daemon/app.py; read -p "Daemon stopped. Press Enter to close..."' &
@$(MAKE) wait-for-services
start-servers-quiet: check-servers
@if [ -z "$(TRANSLATE_DIR)" ]; then \
printf "$(RED)✗ sign.mt frontend not found in ../translate or ../sign-translate$(NC)\n"; \
exit 1; \
fi
@mkdir -p $(PROJECT_DIR)/cache
@printf "$(GREEN)--- Launching Background Services (Quiet) ---$(NC)\n"
@printf "$(YELLOW)Starting sign.mt frontend server (background)...$(NC)\n"
@nohup bash -c "cd $(TRANSLATE_DIR) && npm start" > $(PROJECT_DIR)/cache/frontend.log 2>&1 &
@printf "$(YELLOW)Starting OmaSign daemon (background)...$(NC)\n"
@nohup $(PYTHON_BIN) $(PROJECT_DIR)/daemon/app.py > $(PROJECT_DIR)/cache/daemon.log 2>&1 &
@$(MAKE) wait-for-services
wait-for-services:
@printf "$(YELLOW)Waiting for services to be ready...$(NC)\n"
@printf "$(YELLOW)Waiting for Daemon (port 8765)...$(NC)\n"
@COUNT=0; \
while ! ss -tln | grep -q ":8765"; do \
sleep 1; \
COUNT=`expr $$COUNT + 1`; \
printf "\rWaiting... (%ss) " "$$COUNT"; \
if [ $$COUNT -ge 30 ]; then \
printf "\n$(RED)✗ Daemon failed to start after 30 seconds. Check logs/terminals.$(NC)\n"; \
make stop; \
exit 1; \
fi; \
done
@printf "$(GREEN)✓ Daemon is ready.$(NC)\n"
@printf "$(YELLOW)Waiting for sign.mt frontend (port 4200)...$(NC)\n"
@timeout 120 bash -c 'until ss -tln | grep -q ":4200"; do sleep 1; printf "."; done'
@printf "\n$(GREEN)✓ sign.mt is ready.$(NC)\n"
@printf "$(GREEN)✓ Background services are running.$(NC)\n"
start-ui:
@printf "$(GREEN)--- Launching UI Components ---$(NC)\n"
@if [ -f "$(PROJECT_DIR)/control/sign_control/target/release/sign_control" ]; then \
kitty --title "OmaSign Control" $(PROJECT_DIR)/control/sign_control/target/release/sign_control & \
fi
@sleep 2 # Wait for sign.mt to be ready
chromium --app=http://localhost:4200/renderer \
--window-size=420,480 \
--window-position=1400,800 \
--new-window \
--disable-session-crashed-bubble \
--disable-infobars &
@# Wait for window to appear then position it correctly for this monitor
@sleep 3 && $(PROJECT_DIR)/scripts/position_signer.sh &
@printf "$(GREEN)✓ UI components launched.$(NC)\n"
# @if [ -f "$(PROJECT_DIR)/renderer/signer-window/src-tauri/target/release/app" ]; then \
# $(PROJECT_DIR)/renderer/signer-window/src-tauri/target/release/app & \
# fi
# @printf "$(GREEN)✓ UI components launched.$(NC)\n"
check-servers:
@if pgrep -f "[v]ite|[d]aemon/app.py|[s]ign.mt" > /dev/null; then \
printf "$(RED)⚠ Services appear to be already running. Use 'make stop' first.$(NC)\n"; \
exit 1; \
fi
check-running:
@if pgrep -f "[d]aemon/app.py" > /dev/null; then \
printf "$(YELLOW)⚠ Daemon already running. Stop with: make stop$(NC)\n"; \
exit 1; \
fi
run-daemon:
@printf "$(GREEN)--- Starting OmaSign Daemon ---$(NC)\n"
@unset GOOGLE_API_KEY; $(PYTHON_BIN) $(PROJECT_DIR)/daemon/app.py
run-control:
@printf "$(GREEN)--- Starting Control Hub ---$(NC)\n"
@$(PROJECT_DIR)/control/sign_control/target/release/sign_control
run-renderer:
@printf "$(GREEN)--- Starting Signer Renderer ---$(NC)\n"
@$(PROJECT_DIR)/renderer/signer-window/src-tauri/target/release/app
run-frontend:
@if [ -z "$(TRANSLATE_DIR)" ]; then \
printf "$(RED)✗ sign.mt frontend not found in ../translate or ../sign-translate$(NC)\n"; \
exit 1; \
fi
@printf "$(YELLOW)--- Starting sign.mt Frontend (Vite Dev Server) ---$(NC)\n"
@cd $(TRANSLATE_DIR) && npm start
stop:
@printf "$(YELLOW)--- Stopping OmaSign Services ---$(NC)\n"
@# Kill by port (Robust cleanup for servers)
@if command -v fuser >/dev/null; then \
fuser -k 4200/tcp >/dev/null 2>&1 || true; \
fuser -k 8765/tcp >/dev/null 2>&1 || true; \
fi
@# Kill by name (Cleanup for UI and scripts)
@pkill -f "[v]ite|[s]ign.mt" || true
@pkill -f "[d]aemon/app.py" || true
@pkill -f "[s]ign_control" || true
@pkill -f "[s]igner-window/src-tauri/target/release/app" || true
@pkill -f "[h]ttp://localhost:4200/renderer" || true
@rm -f /tmp/omasign_caption.txt
@sleep 0.5
@printf "$(GREEN)✓ Services stopped$(NC)\n"
# -- Testing --
test: venv
@printf "$(YELLOW)--- Running Python Tests ---$(NC)\n"
@if [ -f "$(PYTEST)" ]; then \
$(PYTEST) $(PROJECT_DIR)/daemon/tests/ -v; \
else \
printf "$(RED)✗ pytest not found. Run: uv add --dev pytest pytest-asyncio$(NC)\n"; \
exit 1; \
fi
test-scripts: fix-permissions
@printf "$(YELLOW)--- Running Script Tests ---$(NC)\n"
@bash $(PROJECT_DIR)/tests/test_scripts.sh
test-all: test-scripts test
@printf "$(GREEN)✓ All tests completed$(NC)\n"
# -- Cleanup --
clean:
@printf "$(YELLOW)--- Cleaning build artifacts ---$(NC)\n"
@rm -rf $(PROJECT_DIR)/renderer/signer-window/src-tauri/target
@rm -rf $(PROJECT_DIR)/control/sign_control/target
@find $(PROJECT_DIR) -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@find $(PROJECT_DIR) -type f -name "*.pyc" -delete 2>/dev/null || true
@printf "$(GREEN)✓ Build artifacts cleaned$(NC)\n"
clean-cache:
@printf "$(YELLOW)--- Cleaning cache directory ---$(NC)\n"
@rm -rf $(PROJECT_DIR)/cache/*
@printf "$(GREEN)✓ Cache cleaned$(NC)\n"
clean-all: clean clean-cache
@printf "$(YELLOW)--- Removing virtual environment ---$(NC)\n"
@rm -rf $(PROJECT_DIR)/.venv
@rm -f uv.lock
@printf "$(GREEN)✓ Complete cleanup done$(NC)\n"
# -- Utility Targets --
update-deps:
@printf "$(YELLOW)--- Updating dependencies ---$(NC)\n"
@$(UV) lock
@printf "$(GREEN)✓ Dependencies locked in uv.lock$(NC)\n"
dev-shell:
@printf "$(GREEN)--- Activating development shell ---$(NC)\n"
@printf "Run: source .venv/bin/activate\n"
@$(SHELL)
.PHONY: check-running stop update-deps dev-shell