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

_realname=lensfun
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.2
pkgrel=7
pkgdesc="Database of photographic lenses and a library that allows advanced access to the database (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://lensfun.github.io/"
license=("LGPL3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/lensfun/lensfun/archive/v${pkgver}.tar.gz
        lensfun-update-data.patch
        cmake-mingw.patch)
sha256sums=('ae8bcad46614ca47f5bda65b00af4a257a9564a61725df9c74cb260da544d331'
            'bba9bfca4469febaa8576f9245e98260fdfecadf10c3a2419013a8fa8e3af84d'
            '279ac435096d3eb9577eb0b9a2a460a4bbab7487e71a6f793a02b0b947acd502')

prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/cmake-mingw.patch"
  patch -p1 -i "${srcdir}/lensfun-update-data.patch"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  [[ $CARCH == x86_64 ]] && ENABLESSE2="-DBUILD_FOR_SSE2=ON"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DSETUP_PY_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DSETUP_PY_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_STATIC=OFF \
    -DBUILD_AUXFUN=ON \
    -DBUILD_LENSTOOL=ON \
    -DBUILD_TESTS=OFF \
    -DBUILD_FOR_SSE=ON \
    -DBUILD_DOC=OFF \
    $ENABLESSE2 \
    ../${_realname}-${pkgver}

  make #VERBOSE=1
}

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