# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# include patches from Archlinux AUR mingw-w64 stuff

_realname=popt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.16
pkgrel=1
pkgdesc="C library for parsing command line parameters (mingw-w64)"
arch=('any')
url="http://www.rpm5.org/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
options=('staticlibs' 'strip')
source=(#"http://rpm5.org/files/popt/popt-${pkgver}.tar.gz"
        ftp://anduin.linuxfromscratch.org/BLFS/popt/popt-${pkgver}.tar.gz
        "0001-nl_langinfo.mingw32.patch"
        "197416.all.patch"
        "217602.all.patch"
        "278402-manpage.all.patch"
        "318833.all.patch"
        "356669.all.patch"
        "367153-manpage.all.patch"
        "get-w32-console-maxcols.mingw32.patch"
        "no-uid-stuff-on.mingw32.patch"
        )
sha256sums=('e728ed296fe9f069a0e005003c3d6b2dde3d9cad453422a10d6558616d304cc8'
            '9d0d7a257f72cf6fa70c34417ed0e7c0949c3abaa2906cca07ad37c48af306a6'
            '38ea3b1e9b49129c666bdb58afeaa7648336148eaaec96fb52850edb5b351d7e'
            '6554fae42ea6117747df66879872e59746ff8f44130f678c9b99fa23580107c7'
            '99b9b5547edfac75eddb90083e3d19c0076d25f1d3e1ad165b49af81ecad8ce9'
            '6a2d7d78a391041e8fecd8b8c952ac4a4d5368ff006ec37b21551ee23dd99362'
            '3acd9334d967ea84ef75da2fdcb8b9efc4301b9755e1773fd6a4488c7b77ef61'
            'eb885494ee5b9e8e904c1235b38bac28f248d236728cb28f22f99aee93c46989'
            '28d1613f177c5c62c4d79453dec86265cce5823a2464820efa705468a1aed6b7'
            'acf7c9d3a57a6fc72ed4881cb407722ae034a40933818459782e274e71e84f1c')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  rm -rf po/ca.po || true
  patch -p1 -i $srcdir/0001-nl_langinfo.mingw32.patch
  patch -p1 -i $srcdir/197416.all.patch
  patch -p1 -i $srcdir/217602.all.patch
  patch -p1 -i $srcdir/278402-manpage.all.patch
  patch -p1 -i $srcdir/318833.all.patch
  patch -p1 -i $srcdir/356669.all.patch
  patch -p1 -i $srcdir/367153-manpage.all.patch
  patch -p1 -i $srcdir/get-w32-console-maxcols.mingw32.patch
  patch -p1 -i $srcdir/no-uid-stuff-on.mingw32.patch
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cp -r ${srcdir}/${_realname}-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -D -m644 "${srcdir}/${_realname}-${pkgver}/COPYING" "$pkgdir${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
