# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=libconfig
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.2
pkgrel=2
pkgdesc="C/C++ Configuration File Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/hyperrealm/libconfig"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('!libtool' '!emptydirs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/hyperrealm/libconfig/archive/v${pkgver}.tar.gz"
        "001-mingw-fixes.patch")
sha256sums=('f67ac44099916ae260a6c9e290a90809e7d782d96cdd462cac656ebc5b685726'
            '5490e62dbf460b47032138732423da000658da832812c162b7f175b38d2ffbc3')

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

  patch -Np1 -i "${srcdir}/001-mingw-fixes.patch"

  autoreconf -fiv
}

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

  make lib
}

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