# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libilbc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.4
pkgrel=2
pkgdesc="A friendly copy of the iLBC codec from the WebRTC project (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('BSD')
url="https://github.com/TimothyGu/libilbc/"
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/TimothyGu/libilbc/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.zst{,.asc})
validpgpkeys=('9456AFC0814A8139E99483517FE6B095B582B0D4') # Timothy Gu <timothygu99@gmail.com>
sha256sums=('70a37660e59f999dbde8fd10fb0fb375baf8dd02093ab4b32f94bc4abaac4358'
            'SKIP')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${extra_config[@]}" \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-${pkgver}

  make
}

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

  install -D -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -D -m644 "${srcdir}"/${_realname}-${pkgver}/PATENTS -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
