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

_realname=lcms
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.19
pkgrel=6
pkgdesc="Lightweight color management development library/engine (mingw-w64)"
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://www.littlecms.com"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libtiff")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/sourceforge/lcms/lcms-${pkgver}.tar.gz"
        "cve-2013-4276.patch"
        "lcms-1.17-windows.patch"
        "lcms-1.19-rhbz1003950.patch"
        "lcms-1.19-rhbz675186.patch"
        0002-need-jconfig-before-jmoreconfig.mingw.patch)
sha256sums=('80ae32cb9f568af4dc7ee4d3c05a4c31fc513fc3e31730fed0ce7378237273a9'
            'cd10cc5ce791ae782b1257e6181a71cbdb685b705779c9ef2ceffc7fb2021bd0'
            'fd058c3a14a6ae58f7a33384cde2764a2b8307acd0388c0995e8ed574a663a39'
            'd1e6e400b9a9f95fee8bf1e32c01d88088766b8e3c6b0602d81afb52a186b988'
            '07709d9187e0794a298fc6c1af6a775892733894402ce76aa8e4e8160adb4c33'
            '3e85375a6b38de36e19fa7b4415b8c86aff492c0ef625932bec073d45e944339')

prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/cve-2013-4276.patch"
  patch -Np1 -i "${srcdir}/lcms-1.19-rhbz1003950.patch"
  patch -Np1 -i "${srcdir}/lcms-1.19-rhbz675186.patch"
  #patch -Np1 -i "${srcdir}/lcms-1.17-windows.patch"
  patch -Np1 -i "${srcdir}/0002-need-jconfig-before-jmoreconfig.mingw.patch"

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf ${srcdir}/${_realname}-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

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

  make
}

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