# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=nspr
pkgver=4.36
pkgrel=1
pkgdesc="Netscape Portable Runtime"
url="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR"
arch=(x86_64)
license=(MPL-2.0)
depends=(
  glibc
  sh
)
makedepends=(
  mercurial
  zip
)
source=(
  "hg+https://hg.mozilla.org/projects/nspr#tag=NSPR_${pkgver//./_}_RTM"
  0001-linux-prefer-GCC-provided-atomics-to-asssembly-imple.patch
  0002-configure.in-Remove-assembly-files-from-build.patch
)
b2sums=('6ea7e245860fbdbb8bd550cad9c5ee4c9681c3c94ff36b106622cf0aec9aa1e7932de7801a8e49b309d395ccee4d29199e6142f5f292f65c5ea08f344855248d'
        'fe81bbb23478958438e385ec5563842cdaf7400021def0d2f2184c0c38389e75f28ed7a4f3b52cada4d76c6318c104dda661f1d4efaa224bc832a989729ef852'
        '36417d30e22a8f56c1a2fb70ec35bfd489d93d0514afdaaef3f84b121861998444999d66a44e59f8816705853524666efc38e8a6bc86f6a1d10c7c4740f0cf1b')

prepare() {
  cd nspr

  # https://bugzilla.mozilla.org/show_bug.cgi?id=1496426
  # https://gitlab.archlinux.org/archlinux/packaging/packages/nspr/-/merge_requests/1
  patch -Np1 -i ../0001-linux-prefer-GCC-provided-atomics-to-asssembly-imple.patch
  patch -Np1 -i ../0002-configure.in-Remove-assembly-files-from-build.patch

  autoreconf -fvi
}

build() {
  local configure_options=(
      --prefix=/usr
      --libdir=/usr/lib
      --includedir=/usr/include/nspr
      --enable-optimize
      --disable-debug
      --enable-64bit
  )

  cd nspr
  ./configure "${configure_options[@]}"
  make ${SOURCE_DATE_EPOCH:+
    SH_NOW="${SOURCE_DATE_EPOCH}000000"
    SH_DATE="$(date --utc --date="@$SOURCE_DATE_EPOCH" '+%Y-%m-%d %T')"
  }
}

package() {
  cd nspr
  make DESTDIR="$pkgdir" install
  ln -s nspr.pc "$pkgdir/usr/lib/pkgconfig/mozilla-nspr.pc"

  rm -r "$pkgdir"/usr/include/nspr/md
  rm "$pkgdir"/usr/bin/{compile-et.pl,prerr.properties}
}

# vim:set sw=2 sts=-1 et:
