# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=twolame
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.0
pkgrel=3
pkgdesc="An optimized MPEG Audio Layer 2 (MP2) encoder (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('LGPL')
url="https://www.twolame.org/"
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-libsndfile")
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-mingw32-does-not-need-handholding.all.patch
        0005-silent.mingw.patch
        0002-Add-missing-TL_API.patch)
sha256sums=('cc35424f6019a88c6f52570b63e1baf50f62963a3eac52a03a800bb070d7c87d'
            '89bab27e8fb97eb1ca59e353705f2a22cf4e9c570c22f599b9090d0fd344b035'
            '01b00dfa83ad4af3dad944ddbe1f5b1da03fb9ea2b699d95c9da109391eec911'
            'ad0bf19387e842ce6070a7a812a80237b16591441f6b822909722d3870a01c88')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-mingw32-does-not-need-handholding.all.patch
  patch -p1 -i "${srcdir}"/0005-silent.mingw.patch
  patch -p1 -i "${srcdir}"/0002-Add-missing-TL_API.patch

  WANT_AUTOMAKE=latest autoreconf -fi
}

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

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

  make
}

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