# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=libmpeg2
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r1108.946bf4b
pkgrel=1
pkgdesc="Library for decoding MPEG-1 and MPEG-2 video streams (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://libmpeg2.sourceforge.io/"
license=("GPL2")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-svn")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "git")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("${_realname}"::"git+https://code.videolan.org/videolan/libmpeg2.git"
        0001-fix-bootstrap.mingw.patch
        0002-libmpeg2-fix-deprecated.patch
        0003-do-not-AC_C_ALWAYS_INLINE-it-redefines-inline-breaking-mingw-w64-GCC-5.1.0-C99.patch)
sha256sums=('SKIP'
            '0ba11aa8ee1aa185dec49790d6c12ed364345fe2ea78616caafa96f1cbd91766'
            '4dca32a82a5845f4fcbc26d79ae4fdc5d9ab27cca5c2ae5ea5fa9078a0077eb6'
            '8beb78faac22b9a6c37b4ff23663cd83ce894443c02337e427729acd8bd6cce0')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/0001-fix-bootstrap.mingw.patch
  patch -p1 -i ${srcdir}/0002-libmpeg2-fix-deprecated.patch
  patch -p1 -i ${srcdir}/0003-do-not-AC_C_ALWAYS_INLINE-it-redefines-inline-breaking-mingw-w64-GCC-5.1.0-C99.patch

  ./bootstrap
}

build() {
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH} && cd build-${CARCH}
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-sdl

  make
}

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