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

_realname=libshout
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.6
pkgrel=5
pkgdesc="Library for accessing a shoutcast/icecast server (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.icecast.org/"
msys2_repository_url="https://gitlab.xiph.org/xiph/icecast-libshout"
msys2_references=(
  "cpe: cpe:/a:libshout:libshout"
)
license=('spdx:LGPL-2.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-speex"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
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=('39cbd4f0efdfddc9755d88217e47f8f2d7108fa767f9d58a2ba26a16d8f7c910'
            '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

  # https://lists.xiph.org/pipermail/icecast-dev/2022-May/002750.html
  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() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  export ac_cv_func_gettimeofday=no

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

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

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