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

pkgbase=libtirpc
pkgname=('libtirpc' 'libtirpc-devel')
pkgver=1.3.6
pkgrel=1
pkgdesc="A port of Sun's Transport-Independent RPC library"
arch=('i686' 'x86_64')
license=('BSD')
url="https://git.linux-nfs.org/?p=steved/libtirpc.git;a=summary"
msys2_references=(
  "cpe: cpe:/a:libtirpc_project:libtirpc"
  "cpe: cpe:/a:redhat:libtirpc"
)
makedepends=('gcc' 'patch' 'heimdal-devel' 'autotools')
source=(https://downloads.sourceforge.net/libtirpc/libtirpc-${pkgver}.tar.bz2
        0.2.4-cygwin-ipv6.patch
        0.2.4-cygwin-poll.patch
        0.2.4-cygwin-rpc-types.patch
        0.3.2-no-undefined.patch
        1.3.2-cygwin-types.patch
        1.3.4-no-errqueue.patch
        1.3.6-Makefile-am.patch
        1.3.6-cygwin-bindresvport.patch
        1.3.6-cygwin-pthread.patch
        1.3.6-cygwin-rpcent.patch)
sha256sums=('bbd26a8f0df5690a62a47f6aa30f797f3ef8d02560d1bc449a83066b5a1d3508'
            '24d8f179812434e3be91800eb4387fec38d9050f3d1902ee1e66246c776fac11'
            '90cedf3f930bf44dbbed2e520305df1a53daddac464d1d68edf501466578ac0c'
            'c247c94a431c0548610c6e97b620a3f81767a31f894b14027737b8afbade95f8'
            '19f6c539781476c5ac7fd58f080ca587c4c70c69dd82d57e30d69d39b9c7ac9f'
            '6a93776a8a1a40c67455b35ebec9452d36da6752ab9defbc84e147e3edb33150'
            '56b25ddbfbee6eaa204151c77ce15d897ed4e9fb938e91048998127cb3deb373'
            'cef6d53e47504d23a69a77c82088ebba5a7094e3f208e93e6ccabbc2b59d6c8c'
            '71d266bb7d22c0293ef8bf8f78960b130bf26bd94eea57d72469595fa1ab9068'
            '630254c38fe8598d9c6e59a96bcd4ec2b548240057c868a1f54d0bc6f206ab18'
            '9c9b7d00518b614f7695805396a8f1703c523513b4ef9a54f381a5bec4cd4456')

prepare() {
  cd libtirpc-${pkgver}

  # from cygwin: https://cygwin.com/cgit/cygwin-packages/libtirpc
  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.2.4-cygwin-rpc-types.patch
  patch -p2 -i ${srcdir}/0.3.2-no-undefined.patch
  patch -p2 -i ${srcdir}/1.3.2-cygwin-types.patch
  patch -p2 -i ${srcdir}/1.3.4-no-errqueue.patch
  patch -p2 -i ${srcdir}/1.3.6-Makefile-am.patch
  patch -p2 -i ${srcdir}/1.3.6-cygwin-bindresvport.patch
  patch -p2 -i ${srcdir}/1.3.6-cygwin-pthread.patch
  patch -p2 -i ${srcdir}/1.3.6-cygwin-rpcent.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/
}
