# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=libtirpc
pkgname=('libtirpc' 'libtirpc-devel')
pkgver=1.3.1
pkgrel=1
pkgdesc="A port of Sun's Transport-Independent RPC library"
arch=('i686' 'x86_64')
license=('BSD')
url="https://libtirpc.sourceforge.io/"
makedepends=('gcc' 'make' 'patch' 'heimdal-devel')
source=(https://downloads.sourceforge.net/libtirpc/libtirpc-${pkgver}.tar.bz2
        0.3.2-no-undefined.patch
        0.2.4-cygwin-rpc-types.patch
        0.2.4-cygwin-pthread.patch
        1.0.2-cygwin-bindresvport.patch
        0.2.4-cygwin-ipv6.patch
        0.2.4-cygwin-poll.patch
        0.3.2-cygwin-rpcent.patch
        1.0.2-includedir.patch
        msys2-autotools.patch)
sha256sums=('245895caf066bec5e3d4375942c8cb4366adad184c29c618d97f724ea309ee17'
            '19f6c539781476c5ac7fd58f080ca587c4c70c69dd82d57e30d69d39b9c7ac9f'
            'c247c94a431c0548610c6e97b620a3f81767a31f894b14027737b8afbade95f8'
            'd45ae803c401ca5a37e5084da822ff7f448241be38d457ef981692322e7fd057'
            'dfcd2fc7ec85b98cb6616e9b7f3168be169ed7a10b15c986917bc4cc3fc0f9da'
            '24d8f179812434e3be91800eb4387fec38d9050f3d1902ee1e66246c776fac11'
            '90cedf3f930bf44dbbed2e520305df1a53daddac464d1d68edf501466578ac0c'
            'fe6af160a7fa983fa772f6fa0d84d930c94250424289665625ebad7dd33c191c'
            'e22f57de0fc49d4c1a173c21d829a4f234f66e060254a7977cacc16b311bf10f'
            '92940578daafd46f24326b802702405f60f6bcf0a6753f3552ce059dfca86111')

prepare() {
  cd libtirpc-${pkgver}
  patch -p2 -i ${srcdir}/0.3.2-no-undefined.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-rpc-types.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-pthread.patch
  patch -p2 -i ${srcdir}/1.0.2-cygwin-bindresvport.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-ipv6.patch
  patch -p2 -i ${srcdir}/0.2.4-cygwin-poll.patch
  patch -p2 -i ${srcdir}/0.3.2-cygwin-rpcent.patch
  patch -p2 -i ${srcdir}/1.0.2-includedir.patch
  patch -p1 -i ${srcdir}/msys2-autotools.patch

  autoreconf -fiv
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cd libtirpc-${pkgver}
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --enable-gssapi

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package_libtirpc() {
  depends=('gcc-libs')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/etc ${pkgdir}/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libtirpc-devel() {
  pkgdesc="Libtirpc headers and libraries"
  groups=('development')
  depends=("libtirpc=${pkgver}")

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
