# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

pkgname=rpcsvc-proto
pkgver=1.4.4
pkgrel=1
pkgdesc="rpcsvc protocol definitions from glibc."
arch=('i686' 'x86_64')
url="https://github.com/thkukuk/rpcsvc-proto"
msys2_references=(
  "anitya: 155452"
)
license=('BSD')
depends=('libintl' 'libiconv')
makedepends=('autotools' 'gcc' 'gettext-devel' 'libiconv-devel')
source=("${pkgname}-${pkgver}.tar.gz"::"${url}/archive/v${pkgver}.tar.gz")
sha512sums=('8477709678a5af6338011e730a20ba5fc5e97f6f360738a956fd96ad26da309135ff042c65b3590bc35fee907e2eea7203aa782963efd30d066aa1306c2c5326')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # Replace stat64 with stat, cygwin/msys2 does not export it.
  sed -s "s|stat64|stat|g" -i "rpcgen/rpc_main.c"

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM_CHOST}" ]] && rm -rf "${srcdir}/build-${MSYSTEM_CHOST}"
  mkdir -p "${srcdir}/build-${MSYSTEM_CHOST}" && cd "${srcdir}/build-${MSYSTEM_CHOST}"

  ../${pkgname}-${pkgver}/configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --target=${CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${pkgname}-${pkgver}/COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
