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

_realname=a52dec
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.7.4
pkgrel=4
pkgdesc="A free library for decoding ATSC A/52 streams (mingw-w64)"
url="https://liba52.sourceforge.io/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://liba52.sourceforge.io/files/${_realname}-${pkgver}.tar.gz"
        '0001-a52dec-0.7.4-build.patch'
        '0002-do-not-AC_C_ALWAYS_INLINE-it-redefines-inline-breaking-mingw-w64-GCC-5.1.0-C99.patch')
sha256sums=('a21d724ab3b3933330194353687df82c475b5dfb997513eef4c25de6c865ec33'
            '00a094d6178cd21bfc2303ff2ac91ce656810e6fef50e77ab30e18d0f4d4a650'
            'a642b0a98caca1299fb75b7260bf9a60cdbd995623a00ec2e766bad2da836076')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-a52dec-0.7.4-build.patch"
  patch -Np1 -i "${srcdir}/0002-do-not-AC_C_ALWAYS_INLINE-it-redefines-inline-breaking-mingw-w64-GCC-5.1.0-C99.patch"
  sed -i 's/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/' configure.in
  mv configure.in configure.ac
  ./bootstrap
}

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

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -m644 ${srcdir}/${_realname}-${pkgver}/liba52/a52_internal.h "${pkgdir}${MINGW_PREFIX}/include/a52dec/"
}
