# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=gegl
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.30
pkgrel=1
pkgdesc="Generic Graphics Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://gegl.org/"
license=("GPL3" "LGPL3")
makedepends=("${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-luajit"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-ruby"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-ffmpeg"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-babl"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-exiv2"
         "${MINGW_PACKAGE_PREFIX}-gexiv2"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-jasper"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libraw"
         "${MINGW_PACKAGE_PREFIX}-librsvg"
         "${MINGW_PACKAGE_PREFIX}-libspiro"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-lcms"
         "${MINGW_PACKAGE_PREFIX}-lensfun"
         "${MINGW_PACKAGE_PREFIX}-maxflow"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-suitesparse")
optdepends=("${MINGW_PACKAGE_PREFIX}-ffmpeg: for using the ffmpeg plugin")
#options=('!strip' 'debug')
noextract=("${_realname}-${pkgver}.tar.xz")
source=(https://download.gimp.org/pub/gegl/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        "asciidoc-fix-missing-dll.patch")
sha256sums=('c112782cf4096969e23217ccdfabe42284e35d5435ff0c43d40e4c70faeca8dd'
            '2c2d800d2f4693e21443a2ba745bb05a23f993886e0d00e0b64fe8c3af1f35d5')

prepare() {
  cd "${srcdir}"
  tar -xf "${_realname}-${pkgver}.tar.xz" || true
  cd "${srcdir}/${_realname}-${pkgver}"
  cp bin/lua/gegl_rectangle.lua bin/lua/gegl_crop.lua
  cp bin/lua/gegl_vector-stroke.lua bin/lua/gegl_fill-path.lua

  patch -p1 -i "${srcdir}"/asciidoc-fix-missing-dll.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    --auto-features=enabled \
    -Dlibv4l=disabled \
    -Dlibv4l2=disabled \
    -Dmrg=disabled \
    -Dpygobject=disabled \
    -Dsdl1=disabled \
    -Dintrospection=true \
    -Ddocs=true \
    "../${_realname}-${pkgver}"

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" ninja install


  rm "${pkgdir}${MINGW_PREFIX}"/lib/gegl-*/*.dll.a
}
