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

_realname=libshout
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.4
pkgrel=1
pkgdesc="Library for accessing a shoutcast/icecast server (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://www.icecast.org/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-speex")
source=("https://downloads.xiph.org/releases/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-dont-hate-yourself_m4.all.patch
        0001-dont-hate-yourself.all.patch
        0002-msvc-is-impotent-unlike.all.patch
        0004-no-undefined-on.mingw.patch
        0006-winsock.patch
        0007-includes.patch
        01-libshout-tls-compile-with-OpenSSL-1.1.0.patch)
sha256sums=('8ce90c5d05e7ad1da4c12f185837e8a867c22df2d557b0125afaba4b1438e6c3'
            '6f5a4c56567c4be1f4d6e7bb4c8fe2c3129cfee4ca5a6225e4bdc4d5e63e8f99'
            '5e1fcc545cd76b0318fd8f7ae7e4a9e9d11ed5174693a37c72212b7c2cfaa0c9'
            'ba91f165de0207c58a30744666be0c5843ccc501252b799abef6636b04a4e3ef'
            '6966bd722b6d61411427851e44870b4a3600923e165e514dbf5d214dc9c9786d'
            '7dab423ae546c9bafbd02b9ff73c685c9babf0c61b94f1ae25ea7c87af3b8bea'
            'e378517b241e89e4ef9729783125aa55496f9d8edc7b7b80ee6f9bbe1f4000ec'
            '3bcc32465233bc6e40d0ee36eee08298cad6cf14584562897a7088493adeb5ad')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-dont-hate-yourself_m4.all.patch
  patch -p1 -i ${srcdir}/0001-dont-hate-yourself.all.patch
  patch -p1 -i ${srcdir}/0002-msvc-is-impotent-unlike.all.patch
  patch -p1 -i ${srcdir}/0004-no-undefined-on.mingw.patch
  patch -p1 -i ${srcdir}/0006-winsock.patch
  patch -p1 -i ${srcdir}/0007-includes.patch
  # https://salsa.debian.org/multimedia-team/libshout/blob/master/debian/patches/01-libshout-tls-compile-with-OpenSSL-1.1.0.patch
  patch -p1 -i ${srcdir}/01-libshout-tls-compile-with-OpenSSL-1.1.0.patch
  autoreconf -fvi
}

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

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -k check || true
}

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