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

_realname=libnfs
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.0.0
pkgrel=2
pkgdesc="Client library for accessing NFS shares over a network (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/sahlberg/libnfs/"
license=('BSD' 'GPL3' 'LGPL2.1')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("https://github.com/sahlberg/libnfs/archive/${_realname}-${pkgver}.tar.gz"
        2.0.0-win32.patch
        2.0.0-no-unefined.patch)
sha256sums=('6ee77e9fe220e2d3e3b1f53cfea04fb319828cc7dbb97dd9df09e46e901d797d'
            '57375b4a8743c74613b77193035e77adb86386d5a84937f6f4b8e761f172f4a8'
            '2ff5c413351e822d862d9c467b19f097e3d93a23de1a1511abfbb51268f21c25')

prepare() {
  cd ${_realname}-${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/2.0.0-win32.patch
  patch -p1 -i ${srcdir}/2.0.0-no-unefined.patch
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENCE-BSD.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENCE-BSD.txt
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENCE-GPL-3.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENCE-GPL-3.txt
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENCE-LGPL-2.1.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENCE-LGPL-2.1.txt
}
