# Maintainer: Ilya Rakhlin <i.rakhlin@gmail.com>

_realname=pkgconf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
epoch=1
pkgver=2.5.1
pkgrel=1
pkgdesc='pkg-config compatible utility which does not depend on glib'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/pkgconf/pkgconf'
msys2_references=(
  "archlinux: pkgconf"
  "cpe: cpe:/a:pkgconf:pkgconf"
)
license=('spdx:ISC')
provides=("${MINGW_PACKAGE_PREFIX}-pkg-config")
conflicts=("${MINGW_PACKAGE_PREFIX}-pkg-config")
replaces=("${MINGW_PACKAGE_PREFIX}-pkg-config")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson" "${MINGW_PACKAGE_PREFIX}-cc")
groups=("${MINGW_PACKAGE_PREFIX}-toolchain")
source=("https://github.com/pkgconf/pkgconf/archive/pkgconf-$pkgver/$_realname-$pkgver.tar.gz")
sha256sums=('79721badcad1987dead9c3609eb4877ab9b58821c06bdacb824f2c8897c11f2a')

prepare() {
  mv "${_realname}-${_realname}-${pkgver}" "${_realname}-${pkgver}"
}

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

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--buildtype=release")
  else
    _extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson setup \
    --prefix="${MINGW_PREFIX}" \
    "${_extra_config[@]}" \
    -Dtests=disabled \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  cp "${pkgdir}${MINGW_PREFIX}"/bin/pkgconf "${pkgdir}${MINGW_PREFIX}"/bin/pkg-config
  cp "${pkgdir}${MINGW_PREFIX}"/bin/pkgconf "${pkgdir}${MINGW_PREFIX}"/bin/${MINGW_CHOST}-pkgconf
  cp "${pkgdir}${MINGW_PREFIX}"/bin/pkg-config "${pkgdir}${MINGW_PREFIX}"/bin/${MINGW_CHOST}-pkg-config
}
