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

_realname=smpeg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.5
pkgrel=6
pkgdesc="SDL MPEG Player Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://icculus.org/smpeg/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gtk2"
             "subversion")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-SDL")
optdepends=("${MINGW_PACKAGE_PREFIX}-gtk2: for gtv")
source=("${_realname}::svn://svn.icculus.org/smpeg/tags/release_${pkgver//./_}"
        001-no-undefined.patch
        002-clang-libtool-tweak.patch
        003-aarch64.patch)
sha256sums=('SKIP'
            'd9c89f26abb9c5c6341876a613dac805e3c4ded590c99668104fcc453a4f412d'
            '0193f2f287b72372ec066f1057309e3ebf036c45473fecffea7cd7005ed23bc5'
            'c31e876017fb5de4870f0524f115bcfca47b4644e6a24047b96e885c61469a38')

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

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

  apply_patch_with_msg \
    001-no-undefined.patch \
    002-clang-libtool-tweak.patch \
    003-aarch64.patch
  
  ./autogen.sh
}

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

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

  make
}

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

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