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

_realname=smpeg2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.0
pkgrel=5
pkgdesc="SDL2 MPEG Player Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://icculus.org/smpeg/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "subversion")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-SDL2")
options=('staticlibs' 'strip')
source=("${_realname}::svn://svn.icculus.org/smpeg/tags/release_${pkgver//./_}")
sha256sums=('SKIP')

prepare() {
  cd "${srcdir}"/${_realname}
  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}/"

  CFLAGS+=" -Wno-error=narrowing"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --mandir=${MINGW_PREFIX}/share/man \
    --enable-shared \
    --enable-static

  make
}

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

  # hacky way of resolving conflicts
  rm ${pkgdir}${MINGW_PREFIX}/bin/plaympeg
  rm -r ${pkgdir}${MINGW_PREFIX}/share/man
}
