# Contributor: Teemu Nätkinniemi ("teepean") <tnatkinn@gmail.com>

_realname=isa-l
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.31.1
pkgrel=1
pkgdesc="Intelligent Storage Acceleration Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.intel.com/content/www/us/en/developer/tools/isa-l/overview.html"
msys2_repository_url="https://github.com/intel/isa-l"
msys2_references=(
  'aur: isa-l'
)
license=('spdx:BSD-3-Clear')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-nasm")
source=("https://github.com/intel/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-fix-building-shared-library.patch
        002-do-not-require-yasm.patch
        003-aarch64.patch)
sha256sums=('e1d5573a4019738243b568ab1e1422e6ab7557c5cae33cc8686944d327ad6bb4'
            '92a43ca667f1f40b2b78ae38434a6dad4c359e5ee7fdd73bd8d09d40bff03aed'
            'c6ee2f69d92bc94a554c4bbbb790eca30c9c7696e2af8cba72baabe7238eb6a3'
            '7047bb8fdc872327a0d5f25bb2e870b1fa09db53c2f4b63f0c1c1d2d84966378')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

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

  apply_patch_with_msg \
    001-fix-building-shared-library.patch \
    002-do-not-require-yasm.patch \
    003-aarch64.patch

  ./autogen.sh
}

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

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared

  make || make -j1
}

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

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
