the_goth_cardgame_collection/build_scripts/build.sh

134 lines
4.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# =============================================================================
# The Goth Cardgame Collection - One-File Build Script (Linux / ChromeOS / macOS)
# Output: dist/<os>/TheGothCardgameCollection
# Usage: ./build_scripts/build.sh [--current | --all | --clean]
# =============================================================================
set -euo pipefail
2026-11-14 22:33:43 +00:00
# Immer ins Projekt-Hauptverzeichnis wechseln
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
cd "${PROJECT_ROOT}"
APP_NAME="TheGothCardgameCollection"
MODE="${1:---current}"
if [[ "${MODE}" == "--clean" ]]; then
echo "[CLEAN] Entferne temporäre Build-Ordner..."
rm -rf build .venv_build_linux .venv_build_macos
echo "[OK] Aufgeräumt (dist/ blieb erhalten)."
exit 0
fi
# Ziel-OS automatisch erkennen
UNAME_OUT="$(uname -s)"
case "${UNAME_OUT}" in
Linux*) OS_NAME="linux" ;;
Darwin*) OS_NAME="macos" ;;
*) echo "[ERROR] Unbekanntes Unix-System: ${UNAME_OUT}"; exit 1 ;;
esac
echo "============================================================"
echo " Building ${APP_NAME} (Single-File) -> dist/${OS_NAME}/"
echo "============================================================"
if ! command -v python3 >/dev/null 2>&1; then
echo "[ERROR] python3 nicht gefunden."
exit 1
fi
if ! python3 -c "import tkinter" >/dev/null 2>&1; then
echo "[ERROR] Das Python-Modul 'tkinter' fehlt auf diesem Build-System."
echo " Debian/Ubuntu/ChromeOS: sudo apt update && sudo apt install -y python3-tk"
echo " Fedora: sudo dnf install -y python3-tkinter"
echo " Arch: sudo pacman -S tk"
echo " macOS (Homebrew): brew install python-tk"
exit 1
fi
# Isolierte Build-Venv anlegen & Dependencies automatisch installieren
VENV_DIR="${PROJECT_ROOT}/.venv_build_${OS_NAME}"
if [[ ! -d "${VENV_DIR}" ]]; then
echo "[1/3] Erstelle isolierte Build-Umgebung (${VENV_DIR})..."
python3 -m venv "${VENV_DIR}"
fi
# shellcheck disable=SC1091
source "${VENV_DIR}/bin/activate"
echo "[2/3] Prüfe & aktualisiere Build-Abhängigkeiten (PyInstaller, Pillow, Pygame)..."
python -m pip install --upgrade --quiet pip
python -m pip install --quiet pyinstaller pillow pygame
# Ziel- & Arbeitsverzeichnisse vorbereiten
DIST_DIR="${PROJECT_ROOT}/dist/${OS_NAME}"
WORK_DIR="${PROJECT_ROOT}/build/${OS_NAME}"
mkdir -p "${DIST_DIR}" "${WORK_DIR}"
ICON_ARGS=()
2026-11-14 22:33:43 +00:00
if [[ -f "${PROJECT_ROOT}/resources/images/game_icon.ico" ]]; then
ICON_ARGS=(--icon "${PROJECT_ROOT}/resources/images/game_icon.ico")
fi
STRIP_ARGS=()
if command -v strip >/dev/null 2>&1; then
STRIP_ARGS=(--strip)
fi
2026-11-14 22:33:43 +00:00
echo "[3/3] Kompiliere kompakte Einzeldatei mit absoluten Pfaden..."
python -m PyInstaller \
--noconfirm \
--clean \
--onefile \
--windowed \
"${STRIP_ARGS[@]}" \
--name "${APP_NAME}" \
--distpath "${DIST_DIR}" \
--workpath "${WORK_DIR}" \
--specpath "${WORK_DIR}" \
"${ICON_ARGS[@]}" \
2026-11-14 22:33:43 +00:00
--add-data "${PROJECT_ROOT}/resources:resources" \
--add-data "${PROJECT_ROOT}/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 \
2026-11-14 22:33:43 +00:00
"${PROJECT_ROOT}/main.py"
deactivate
chmod +x "${DIST_DIR}/${APP_NAME}" 2>/dev/null || true
rm -rf "${WORK_DIR}"
echo ""
echo "[DONE] Fertige ausführbare Datei liegt bereit unter:"
echo " dist/${OS_NAME}/${APP_NAME}"
# Optionaler Cross-Build via Wine (falls --all übergeben wurde und Wine + Python installiert ist)
if [[ "${MODE}" == "--all" && "${OS_NAME}" == "linux" ]]; then
echo ""
echo "------------------------------------------------------------"
echo " Prüfe optionalen Windows-Cross-Build via Wine..."
echo "------------------------------------------------------------"
if command -v wine >/dev/null 2>&1 && wine python --version >/dev/null 2>&1; then
echo "[WINE] Starte Windows-Build -> dist/windows/${APP_NAME}.exe ..."
wine cmd /c "build_scripts\\build.bat --current"
else
echo "[SKIP] Wine mit Windows-Python nicht gefunden – überspringe Windows-Cross-Build."
fi
2026-11-14 22:33:43 +00:00
fi