# Maintainer: Yuta Nakai <nak5124@live.jp>

_realname=l-smash
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.14.5
pkgrel=3
pkgdesc="Loyal to Spec of Mpeg4 and Ad-hoc Simple Hackwork. Yet another opensource mp4 handler (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://l-smash.github.io/l-smash/"
license=('spdx:ISC')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/l-smash/l-smash/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-remove-version-script.patch"
        "0002-use-cc-instead-of-gcc.patch")
sha256sums=('e6f7c31de684f4b89ee27e5cd6262bf96f2a5b117ba938d2d606cf6220f05935'
            '7f5267757e8eee42faecbaa64e2002b65f6bd356e637cb8297ae96cf3ef72d68'
            'b366a6accdd2bf5f5d8bd7abb3559553b61701722c629f75e3c98c9d9f1f3b31')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    patch -p1 -i "${srcdir}"/0001-remove-version-script.patch
    patch -p1 -i "${srcdir}"/0002-use-cc-instead-of-gcc.patch
  fi
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  #On clang this isn't properly detected
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --target-os=mingw \
    --enable-shared

  make SLIB_CMD="" ${MAKEFLAGS}
}

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

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
