@echo off
REM waveform_trace 打包脚本 (Windows)
REM 用法: build.bat

echo ========================================
echo   waveform_trace 打包脚本
echo ========================================

cd /d "%~dp0src"

echo.
echo [1/3] 安装依赖...
pip install -r requirements.txt
if %errorlevel% neq 0 (
    echo 错误: 依赖安装失败
    exit /b 1
)

echo.
echo [2/3] 清理旧文件...
if exist build rmdir /s /q build
if exist dist rmdir /s /q dist
if exist waveform_trace.spec del waveform_trace.spec

echo.
echo [3/3] PyInstaller 打包...
pyinstaller --onefile --name waveform_trace --collect-all pyverilog waveform_trace_cli.py
if %errorlevel% neq 0 (
    echo 错误: 打包失败
    exit /b 1
)

echo.
echo [4/4] 复制到 bin 目录...
if not exist "..\bin" mkdir "..\bin"
copy /y "dist\waveform_trace.exe" "..\bin\"

echo.
echo ========================================
echo   打包完成!
echo   输出: tools/waveform_trace/bin/waveform_trace.exe
echo ========================================
