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

_realname=libconfig
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.2
pkgrel=1
pkgdesc="C/C++ Configuration File Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/hyperrealm/libconfig"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
options=('!emptydirs')
source=("https://github.com/hyperrealm/libconfig/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-mingw-fixes.patch")
sha256sums=('8e71983761b08c65b15b769b3ec1d980036c461fdfd415c7183378a4b3eac8f4'
            '62b569bcbdf31fb87a2a70f7ec0396563225b2be107762818098c59e9a2a0b21')

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

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

  autoreconf -fiv
}

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

  CFLAGS+=" -Wno-implicit-function-declaration" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --disable-examples \
    --enable-shared \
    --enable-static

  make lib
}

package() {
  cd "${srcdir}/build-${MSYSTEM}/lib"

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
