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

pkgbase='libtirpc'
pkgname=('libtirpc' 'libtirpc-devel')
pkgver=1.3.8
pkgrel=1
pkgdesc="A port of Sun's Transport-Independent RPC library"
arch=('i686' 'x86_64')
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'
)
license=('spdx:BSD-3-Clause AND SISSL')
makedepends=(
  'autotools'
  'gcc'
  'heimdal-devel'
  'patch'
)
source=(
  "https://downloads.sourceforge.net/libtirpc/${pkgbase}-${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-pthread.patch'
  '1.3.6-cygwin-rpcent.patch'
  '1.3.7-cygwin-bindresvport.patch'
)
sha256sums=('8839959bfcc7a0f4c609d8e4f53f1c67ae33de23775ec35beb39ff15adf11920'
            '24d8f179812434e3be91800eb4387fec38d9050f3d1902ee1e66246c776fac11'
            '90cedf3f930bf44dbbed2e520305df1a53daddac464d1d68edf501466578ac0c'
            'c247c94a431c0548610c6e97b620a3f81767a31f894b14027737b8afbade95f8'
            '19f6c539781476c5ac7fd58f080ca587c4c70c69dd82d57e30d69d39b9c7ac9f'
            '6a93776a8a1a40c67455b35ebec9452d36da6752ab9defbc84e147e3edb33150'
            '56b25ddbfbee6eaa204151c77ce15d897ed4e9fb938e91048998127cb3deb373'
            'cef6d53e47504d23a69a77c82088ebba5a7094e3f208e93e6ccabbc2b59d6c8c'
            '630254c38fe8598d9c6e59a96bcd4ec2b548240057c868a1f54d0bc6f206ab18'
            '9c9b7d00518b614f7695805396a8f1703c523513b4ef9a54f381a5bec4cd4456'
            '41bdf48abce469bc12e092b7d89921db50ac51870fbf35e5bedd69b744b49eda')

prepare() {
  cd "${pkgbase}-${pkgver}"

  # from cygwin: https://cygwin.com/cgit/cygwin-packages/libtirpc
  patch -Np2 -i "${srcdir}/0.2.4-cygwin-ipv6.patch"
  patch -Np2 -i "${srcdir}/0.2.4-cygwin-poll.patch"
  patch -Np2 -i "${srcdir}/0.2.4-cygwin-rpc-types.patch"
  patch -Np2 -i "${srcdir}/0.3.2-no-undefined.patch"
  patch -Np2 -i "${srcdir}/1.3.2-cygwin-types.patch"
  patch -Np2 -i "${srcdir}/1.3.4-no-errqueue.patch"
  patch -Np2 -i "${srcdir}/1.3.6-Makefile-am.patch"
  patch -Np2 -i "${srcdir}/1.3.6-cygwin-pthread.patch"
  patch -Np2 -i "${srcdir}/1.3.6-cygwin-rpcent.patch"
  patch -Np2 -i "${srcdir}/1.3.7-cygwin-bindresvport.patch"

  autoreconf -fiv
}

build() {
  cd "${pkgbase}-${pkgver}"

  export lt_cv_deplibs_check_method='pass_all'

  ./configure \
    --build="${CHOST}" \
    --prefix=/usr \
    --sysconfdir=/etc \
    --enable-gssapi

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

check() {
  cd "${pkgbase}-${pkgver}"

  make check
}

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

  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/"
}
