NAME="librewolf"
DESC="LibreWolf is a custom and independent version of Firefox, with the primary goals of privacy, security and user freedom"
VERSION="120.0-1"

FILES=(
  "https://gitlab.com/api/v4/projects/32320088/packages/generic/librewolf-source/${VERSION}/librewolf-${VERSION}.source.tar.gz"
  "with-icu-74-fix.patch"
  "librewolf.desktop"
  "mozconfig"
)
HASHES=(
  "9654cf9ee9083193b5e4311c136735c23a834cba740fc65dd7da72c790119283"
  "be296d7c5ad66144ebbca4656b548728eb4917a91c5f1e2d8dbc665b60cebd07"
  "d1d4fb76689405df792bdb1130be471f3ed6090c4fed634dfc1365c1495fb637"
  "80b09c546c037994d6b022e0a9075c3c165d6790a0ee35fdb67ac6dc8fc2bc84"
)

DEPENDS=(
  "dbus" "dbus-glib" "gtk3" "ffmpeg" "pulseaudio"
  "nss" "libevent" "libvpx" "libwebp" "icu"
  "liboauth" "pciutils" "wireless-tools"
  "startup-notification" "libnotify"
)
BUILD=(
  "pypi-six" "zip" "yasm"
  "unzip" "rustc" "python3"
  "nasm" "mesa" "llvm"
  "inetutils" "diffutils" "cbindgen"
)

PACKAGE() {
  tar xf "${NAME}-${VERSION}.source.tar.gz"
  cd "${NAME}-${VERSION}"

  patch -Np1 -i "../with-icu-74-fix.patch"
  cp "${ROOTDIR}/mozconfig" .

  export CFLAGS+=" -g0"
  export CXXFLAGS+=" -g0"

  export RUSTFLAGS="-Cdebuginfo=0"
  export MOZ_DEBUG_FLAGS=" "

  export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=none
  export MOZBUILD_STATE_PATH="${PWD}/mozbuild"

  ulimit -n 4096

  python3 ./mach configure
  python3 ./mach build --verbose
  DESTDIR="${ROOTDIR}" python3 ./mach install

  unset MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE MOZBUILD_STATE_PATH

  mkdir -pv "${ROOTDIR}/usr/share/applications"
  mkdir -pv "${ROOTDIR}/usr/share/pixmaps"

  cp "${ROOTDIR}/librewolf.desktop" "${ROOTDIR}/usr/share/applications/librewolf.desktop"
  ln -sfv /usr/lib/librewolf/browser/chrome/icons/default/default128.png \
          "${ROOTDIR}/usr/share/pixmaps/librewolf.png"

  cd .. && rm -r "${NAME}-${VERSION}"
}
