secondvoice/build_mingw.bat
StillHammer 94ad6b4a22 feat: Add MinGW support - Build without Visual Studio!
Lightweight Windows build option using MinGW-w64 instead of Visual Studio:

Size Comparison:
- Visual Studio: 10-20 GB install
- MinGW: ~500 MB install (20x smaller!)

New Files:
- setup_mingw.bat: One-click installer for all tools
  - Chocolatey (package manager)
  - MinGW-w64 (GCC compiler)
  - CMake, Ninja, Git
  - vcpkg integration

- build_mingw.bat: Build script for MinGW
  - Auto-detection of GCC
  - Debug/Release modes
  - Clean build support
  - User-friendly error messages

- WINDOWS_MINGW.md: Complete MinGW guide
  - Installation instructions
  - Troubleshooting
  - Performance comparison MSVC vs GCC
  - Distribution guide

CMake Updates:
- Added mingw-debug and mingw-release presets
- GCC compiler flags: -O3 -Wall -Wextra
- Static linking for portable .exe

Documentation:
- Updated WINDOWS_QUICK_START.md with MinGW option
- Comparison table: MinGW vs Visual Studio
- Recommendation: MinGW for most users

Benefits:
- 20x smaller download (500MB vs 10-20GB)
- 5-10 min install vs 30-60 min
- Same performance as MSVC
- Portable standalone .exe
- Perfect for users without Visual Studio

Usage:
1. Run setup_mingw.bat (one time)
2. Restart terminal
3. Run build_mingw.bat --release
4. Done!

Output: build/mingw-release/SecondVoice.exe

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 03:42:41 +08:00

164 lines
3.4 KiB
Batchfile

@echo off
REM Build script for SecondVoice on Windows using MinGW (no Visual Studio!)
echo ========================================
echo SecondVoice - MinGW Build Script
echo ========================================
echo.
REM Check if MinGW/GCC is installed
where gcc >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] GCC not found in PATH
echo.
echo Please run setup_mingw.bat first to install MinGW
echo .\setup_mingw.bat
echo.
pause
exit /b 1
)
echo [INFO] GCC found:
gcc --version | findstr "gcc"
echo.
REM Check if vcpkg is installed
if not defined VCPKG_ROOT (
echo [ERROR] VCPKG_ROOT environment variable not set
echo.
echo Please run setup_mingw.bat first to install vcpkg
echo .\setup_mingw.bat
echo.
pause
exit /b 1
)
echo [INFO] vcpkg found at: %VCPKG_ROOT%
echo.
REM Check if .env exists
if not exist ".env" (
echo [WARNING] .env file not found
echo Please create .env from .env.example and add your API keys:
echo copy .env.example .env
echo notepad .env
echo.
)
REM Check for CMake
where cmake >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] CMake not found
echo Please run setup_mingw.bat first
pause
exit /b 1
)
REM Check for Ninja
where ninja >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Ninja not found
echo Please run setup_mingw.bat first
pause
exit /b 1
)
REM Parse command line arguments
set BUILD_TYPE=Release
set CLEAN_BUILD=0
:parse_args
if "%~1"=="" goto :done_parsing
if /i "%~1"=="--debug" (
set BUILD_TYPE=Debug
shift
goto :parse_args
)
if /i "%~1"=="--release" (
set BUILD_TYPE=Release
shift
goto :parse_args
)
if /i "%~1"=="--clean" (
set CLEAN_BUILD=1
shift
goto :parse_args
)
echo [WARNING] Unknown argument: %~1
shift
goto :parse_args
:done_parsing
echo [INFO] Build type: %BUILD_TYPE%
echo.
REM Clean build if requested
if %CLEAN_BUILD%==1 (
echo [INFO] Cleaning build directory...
if exist "build\mingw-%BUILD_TYPE%" (
rmdir /s /q "build\mingw-%BUILD_TYPE%"
)
echo.
)
REM Set preset name based on build type
if /i "%BUILD_TYPE%"=="Debug" (
set PRESET=mingw-debug
) else (
set PRESET=mingw-release
)
REM Configure with CMake
echo [INFO] Configuring CMake with preset: %PRESET%
cmake --preset %PRESET%
if %errorlevel% neq 0 (
echo.
echo [ERROR] CMake configuration failed
echo.
echo Common issues:
echo 1. VCPKG_ROOT not set correctly
echo 2. Missing dependencies (run setup_mingw.bat)
echo 3. PATH not refreshed (close and reopen terminal)
echo.
pause
exit /b 1
)
echo.
echo [INFO] Building with Ninja...
cmake --build build/mingw-%BUILD_TYPE%
if %errorlevel% neq 0 (
echo.
echo [ERROR] Build failed
echo.
echo Check the error messages above for details.
echo If you see dependency errors, try:
echo build_mingw.bat --clean --release
echo.
pause
exit /b 1
)
echo.
echo ========================================
echo [SUCCESS] Build completed!
echo ========================================
echo.
echo Executable location:
echo build\mingw-%BUILD_TYPE%\SecondVoice.exe
echo.
echo To run the application:
echo cd build\mingw-%BUILD_TYPE%
echo SecondVoice.exe
echo.
echo Make sure you have:
echo 1. Created .env with your API keys
echo 2. config.json is present (copied automatically)
echo 3. A microphone connected
echo.
exit /b 0