# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=libwebp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=2
pkgdesc="the WebP library. Includes conversion tools (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://developers.google.com/speed/webp/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-giflib"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libtiff")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-SDL")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/webmproject/libwebp/archive/v${pkgver}.tar.gz)
sha256sums=('d60608c45682fa1e5d41c3c26c199be5d0184084cd8a971a6fc54035f76487d3')
validpgpkeys=('6B0E6B70976DE303EDF2F601F9C3D6BDB8232B5D')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  ./autogen.sh
}

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 \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-swap-16bit-csp \
    --enable-libwebpmux \
    --enable-libwebpdemux \
    --enable-libwebpdecoder \
    --enable-libwebpextras \
    --enable-sdl

  make
}

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