@echo off setlocal EnableDelayedExpansion REM ============================================================================= REM The Goth Cardgame Collection - One-File Build Script (Windows) REM Output: dist\windows\TheGothCardgameCollection.exe REM Usage: build_scripts\build.bat [--current | --all | --clean] REM ============================================================================= REM Immer ins Projekt-Hauptverzeichnis wechseln (auch bei Doppelklick auf build.bat) cd /d "%~dp0.." set "PROJECT_ROOT=%CD%" set "APP_NAME=TheGothCardgameCollection" set "MODE=%~1" if "%MODE%"=="" set "MODE=--current" if /I "%MODE%"=="--clean" ( echo [CLEAN] Entferne temporaere Build-Ordner... if exist "build" rmdir /s /q "build" if exist ".venv_build_win" rmdir /s /q ".venv_build_win" echo [OK] Aufgeraeumt ^(dist\ blieb erhalten^). exit /b 0 ) echo ============================================================ echo Building %APP_NAME%.exe ^(Single-File^) -^> dist\windows\ echo ============================================================ REM Python-Befehl ermitteln (python, py -3 oder python3) set "PY_CMD=" where python >nul 2>nul && ( python -c "import sys; sys.exit(0)" >nul 2>nul && set "PY_CMD=python" ) if "%PY_CMD%"=="" ( where py >nul 2>nul && ( py -3 -c "import sys; sys.exit(0)" >nul 2>nul && set "PY_CMD=py -3" ) ) if "%PY_CMD%"=="" ( where python3 >nul 2>nul && ( python3 -c "import sys; sys.exit(0)" >nul 2>nul && set "PY_CMD=python3" ) ) if "%PY_CMD%"=="" ( echo [ERROR] Keine funktionierende Python-3-Installation im PATH gefunden! pause exit /b 1 ) REM Isolierte Build-Venv anlegen & Dependencies automatisch installieren set "VENV_DIR=%PROJECT_ROOT%\.venv_build_win" if not exist "%VENV_DIR%\Scripts\python.exe" ( echo [1/3] Erstelle isolierte Build-Umgebung ^(.venv_build_win^)... %PY_CMD% -m venv "%VENV_DIR%" if errorlevel 1 ( echo [ERROR] Konnte virtuelle Umgebung nicht erstellen. exit /b 1 ) ) set "VENV_PY=%VENV_DIR%\Scripts\python.exe" echo [2/3] Pruefe ^& aktualisiere Build-Abhaengigkeiten ^(PyInstaller, Pillow, Pygame^)... "%VENV_PY%" -m pip install --upgrade --quiet pip "%VENV_PY%" -m pip install --quiet pyinstaller pillow pygame if errorlevel 1 ( echo [ERROR] Installation der Build-Abhaengigkeiten fehlgeschlagen. exit /b 1 ) set "DIST_DIR=%PROJECT_ROOT%\dist\windows" set "WORK_DIR=%PROJECT_ROOT%\build\windows" if not exist "%DIST_DIR%" mkdir "%DIST_DIR%" if not exist "%WORK_DIR%" mkdir "%WORK_DIR%" set "ICON_ARG=" if exist "resources\images\game_icon.ico" ( set "ICON_ARG=--icon resources\images\game_icon.ico" ) echo [3/3] Kompiliere kompakte Einzeldatei... "%VENV_PY%" -m PyInstaller ^ --noconfirm ^ --clean ^ --onefile ^ --windowed ^ --name "%APP_NAME%" ^ --distpath "%DIST_DIR%" ^ --workpath "%WORK_DIR%" ^ --specpath "%WORK_DIR%" ^ %ICON_ARG% ^ --add-data "resources;resources" ^ --add-data "games;games" ^ --collect-submodules games ^ --collect-submodules controller ^ --collect-submodules models ^ --collect-submodules view ^ --collect-submodules resources ^ --hidden-import tkinter ^ --hidden-import tkinter.ttk ^ --hidden-import tkinter.font ^ --hidden-import sqlite3 ^ --hidden-import PIL._tkinter_finder ^ --exclude-module matplotlib ^ --exclude-module numpy ^ --exclude-module scipy ^ --exclude-module pandas ^ --exclude-module pytest ^ --exclude-module unittest ^ --exclude-module pydoc ^ main.py if errorlevel 1 ( echo [ERROR] PyInstaller-Build fehlgeschlagen! exit /b 1 ) if exist "%WORK_DIR%" rmdir /s /q "%WORK_DIR%" echo. echo [DONE] Fertige ausfuehrbare Datei liegt bereit unter: echo dist\windows\%APP_NAME%.exe REM Optionaler Linux-Build via WSL, falls --all uebergeben wurde if /I "%MODE%"=="--all" ( echo. echo ------------------------------------------------------------ echo Pruefe optionalen Linux-Build via WSL... echo ------------------------------------------------------------ where wsl >nul 2>nul if not errorlevel 1 ( echo [WSL] Starte Linux-Build -^> dist/linux/%APP_NAME% ... wsl bash ./build_scripts/build.sh --current ) else ( echo [SKIP] WSL nicht verfuegbar - ueberspringe Linux-Build. ) ) endlocal exit /b 0