#!/usr/bin/env bash
set -euo pipefail
APP_NAME="Govibe Nexus Video Player"
BASE_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
TOPDIR="$BASE_DIR/rpmbuild"
if ! command -v rpmbuild >/dev/null 2>&1; then
  echo "rpmbuild not found. Install it first: sudo dnf install -y rpm-build" >&2
  exit 1
fi
rm -rf "$TOPDIR"
mkdir -p "$TOPDIR"/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
cp "$BASE_DIR"/rpm/SOURCES/* "$TOPDIR/SOURCES/"
cp "$BASE_DIR"/rpm/SPECS/* "$TOPDIR/SPECS/"
rpmbuild --define "_topdir $TOPDIR" -ba "$TOPDIR/SPECS/govibe-nexus-video-player.spec"
mkdir -p "$BASE_DIR/built-rpms"
find "$TOPDIR/RPMS" -type f -name '*.rpm' -exec cp -f {} "$BASE_DIR/built-rpms/" \;
echo "Built RPM for $APP_NAME:"
find "$BASE_DIR/built-rpms" -type f -name '*.rpm' -print
