# Maintainer: Jeremy Drake <github@jdrake.com>

pkgname=('popt' 'popt-devel')
pkgver=1.19
pkgrel=1
pkgdesc="A command-line option parser library"
arch=('i686' 'x86_64')
url="http://rpm.org/"
license=('custom')
makedepends=('gcc'
             'gettext-devel'
             'libiconv-devel'
             'autotools')
source=(http://ftp.rpm.org/popt/releases/popt-1.x/${pkgname}-${pkgver}.tar.gz)
sha256sums=('c25a4838fc8e4c1c8aacb8bd620edb3084a3d63bf8987fdad3ca2758c63240f9')

prepare() {
  cd ${pkgname}-${pkgver}

  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${CHOST}"
  cd "${srcdir}/build-${CHOST}"

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

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

check() {
  cd "${srcdir}/build-${CHOST}"
  make check
}

package_popt() {
  depends=('libiconv' 'libintl')

  mkdir -p "${pkgdir}/usr/share"
  cp -rf "${srcdir}/dest/usr/bin" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/share/locale" "${pkgdir}/usr/share/"
  cd "${srcdir}/${pkgname}-${pkgver}"
  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_popt-devel() {
  options=('staticlibs')
  depends=("popt=${pkgver}-${pkgrel}")
  pkgdesc="popt headers and libraries"

  mkdir -p "${pkgdir}/usr/share"
  cp -rf "${srcdir}/dest/usr/include" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/lib" "${pkgdir}/usr/"
  cp -rf "${srcdir}/dest/usr/share/man" "${pkgdir}/usr/share/"
}
