# Maintainer: Wolfgang Stöggl <c72578@yahoo.de>

_realname=sox
_base_ver=14.4.2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
# https://sourceforge.net/p/sox/code/ci/07de8a77a862e6800b95a8d3a61c6b4e41362755/
pkgver=14.4.2.r3203.07de8a77
pkgrel=4
pkgdesc="SoX is the Swiss Army Knife of sound processing utilities (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://sourceforge.net/projects/sox/"
license=("GPL")
makedepends=(autoconf-archive git
             ${MINGW_PACKAGE_PREFIX}-flac
             ${MINGW_PACKAGE_PREFIX}-gcc
             ${MINGW_PACKAGE_PREFIX}-gsm
             ${MINGW_PACKAGE_PREFIX}-id3lib
             ${MINGW_PACKAGE_PREFIX}-lame
             ${MINGW_PACKAGE_PREFIX}-libao
             ${MINGW_PACKAGE_PREFIX}-libid3tag
             ${MINGW_PACKAGE_PREFIX}-libmad
             ${MINGW_PACKAGE_PREFIX}-libpng
             ${MINGW_PACKAGE_PREFIX}-libsndfile
             ${MINGW_PACKAGE_PREFIX}-libtool
             ${MINGW_PACKAGE_PREFIX}-libvorbis
             ${MINGW_PACKAGE_PREFIX}-opencore-amr
             ${MINGW_PACKAGE_PREFIX}-opusfile
             ${MINGW_PACKAGE_PREFIX}-pkg-config
             ${MINGW_PACKAGE_PREFIX}-twolame
             ${MINGW_PACKAGE_PREFIX}-vo-amrwbenc
             ${MINGW_PACKAGE_PREFIX}-wavpack)
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs
             ${MINGW_PACKAGE_PREFIX}-flac
             ${MINGW_PACKAGE_PREFIX}-gsm
             ${MINGW_PACKAGE_PREFIX}-id3lib
             ${MINGW_PACKAGE_PREFIX}-lame
             ${MINGW_PACKAGE_PREFIX}-libao
             ${MINGW_PACKAGE_PREFIX}-libid3tag
             ${MINGW_PACKAGE_PREFIX}-libmad
             ${MINGW_PACKAGE_PREFIX}-libpng
             ${MINGW_PACKAGE_PREFIX}-libsndfile
             ${MINGW_PACKAGE_PREFIX}-libtool
             ${MINGW_PACKAGE_PREFIX}-libvorbis
             ${MINGW_PACKAGE_PREFIX}-opencore-amr
             ${MINGW_PACKAGE_PREFIX}-opusfile
             ${MINGW_PACKAGE_PREFIX}-twolame
             ${MINGW_PACKAGE_PREFIX}-vo-amrwbenc
             ${MINGW_PACKAGE_PREFIX}-wavpack)
options=('staticlibs' 'strip')
source=("${_realname}"::"git+https://git.code.sf.net/p/sox/code#commit=07de8a77a862e6800b95a8d3a61c6b4e41362755"
        "0001-ucrt-no-rewind-pipe.patch")
sha256sums=('SKIP'
            '693e7dcd737ea6c5137f2827518ff08549841d480cde00c4f3f505b2657c71f0')

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

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

  patch -Np1 -i "${srcdir}/0001-ucrt-no-rewind-pipe.patch"

  autoreconf -i
}

build() {
  mkdir -p "$srcdir/build-${MINGW_CHOST}" && cd "$srcdir/build-${MINGW_CHOST}"
  # Silence format warnings originating from usage of PRIu64 and PRIuPTR within lsx_warn, lsx_debug and lsx_fail
  export CFLAGS="$CFLAGS -Wno-format"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-distro='MSYS2 MINGW-packages'

  make
}

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