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

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

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

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  #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-${MINGW_CHOST}
  make SLIB_CMD="" DESTDIR=${pkgdir} install

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