Files
BareCode/barecode/bauen.sh

134 lines
4.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ---------------------------------------------------------------------------
# BareCode Build-Skript
# Verwendung: ./bauen.sh [release|debug|clean|install]
# ---------------------------------------------------------------------------
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
BUILD_TYPE="${1:-release}"
BUILD_DIR="build"
# Farben
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}==>${NC} $1"; }
success() { echo -e "${GREEN}==>${NC} $1"; }
warn() { echo -e "${YELLOW}==>${NC} $1"; }
error() { echo -e "${RED}==>${NC} $1"; exit 1; }
# ---------------------------------------------------------------------------
# clean
# ---------------------------------------------------------------------------
if [ "$BUILD_TYPE" = "clean" ]; then
info "Build-Verzeichnis wird gelöscht…"
rm -rf "$BUILD_DIR"
success "Fertig."
exit 0
fi
# ---------------------------------------------------------------------------
# Abhängigkeiten prüfen
# ---------------------------------------------------------------------------
info "Prüfe Abhängigkeiten…"
command -v cmake &>/dev/null || error "cmake nicht gefunden. Installation: sudo pacman -S cmake"
command -v ninja &>/dev/null || error "ninja nicht gefunden. Installation: sudo pacman -S ninja"
command -v lrelease &>/dev/null || \
command -v lrelease-qt6 &>/dev/null || \
error "lrelease nicht gefunden. Installation: sudo pacman -S qt6-tools"
# Qt6 prüfen
if ! pkg-config --exists Qt6Core 2>/dev/null; then
if ! cmake --find-package -DNAME=Qt6 -DCOMPILER_ID=GNU \
-DLANGUAGE=CXX -DMODE=EXIST &>/dev/null 2>&1; then
warn "Qt6 konnte nicht automatisch geprüft werden — cmake wird es versuchen."
fi
fi
success "Abhängigkeiten OK."
# ---------------------------------------------------------------------------
# CMake-Build-Typ
# ---------------------------------------------------------------------------
case "$BUILD_TYPE" in
release|Release)
CMAKE_BUILD_TYPE="Release"
;;
debug|Debug)
CMAKE_BUILD_TYPE="Debug"
;;
install)
CMAKE_BUILD_TYPE="Release"
;;
*)
error "Unbekannter Build-Typ: '$BUILD_TYPE'. Erlaubt: release, debug, clean, install"
;;
esac
# ---------------------------------------------------------------------------
# Konfigurieren
# ---------------------------------------------------------------------------
info "Konfiguriere mit CMake (${CMAKE_BUILD_TYPE})…"
cmake -B "$BUILD_DIR" \
-G Ninja \
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
2>&1 || error "CMake-Konfiguration fehlgeschlagen."
success "Konfiguration OK."
# ---------------------------------------------------------------------------
# Bauen
# ---------------------------------------------------------------------------
JOBS=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || echo 4)
info "Baue mit $JOBS parallelen Jobs…"
cmake --build "$BUILD_DIR" -j"$JOBS" 2>&1 || error "Build fehlgeschlagen."
success "Build erfolgreich!"
# ---------------------------------------------------------------------------
# Installieren (optional)
# ---------------------------------------------------------------------------
if [ "$BUILD_TYPE" = "install" ]; then
info "Installiere nach /usr (sudo erforderlich)…"
sudo cmake --install "$BUILD_DIR" || error "Installation fehlgeschlagen."
success "BareCode wurde installiert."
echo ""
echo " Starten: BareCode"
exit 0
fi
# ---------------------------------------------------------------------------
# Fertig
# ---------------------------------------------------------------------------
BINARY="$BUILD_DIR/BareCode"
if [ -f "$BINARY" ]; then
# .qm-Dateien neben die Binary kopieren damit sie gefunden werden
mkdir -p "$BUILD_DIR/translations"
if compgen -G "$BUILD_DIR/translations/barecode_*.qm" > /dev/null 2>&1; then
success "Übersetzungen bereits vorhanden."
else
# Aus dem cmake-Zwischenverzeichnis holen
find "$BUILD_DIR" -name "barecode_*.qm" -not -path "$BUILD_DIR/translations/*" \
-exec cp {} "$BUILD_DIR/translations/" \; 2>/dev/null || true
fi
echo ""
success "BareCode ist bereit:"
echo " Starten: ./$BINARY"
echo " Installieren: ./bauen.sh install"
echo " Debug-Build: ./bauen.sh debug"
echo " Aufräumen: ./bauen.sh clean"
fi