APP=gimp
VERSION=2.8.22
BUILD=1sml
HOMEPAGE="https://www.gimp.org/"
DOWNLOAD="https://download.gimp.org/mirror/pub/gimp/v2.8/gimp-2.8.22.tar.bz2"
DESC="The GNU Image Manipulation Program"
REQUIRES="libexif alsa-lib curl libgudev babl gtk2 dbus-glib gegl glib-networking hicolor-icon-theme lcms2 libwebp openjpeg"

build() {
  mkandenterbuilddir
  rm -rf $APP-$VERSION

  tar xf $SRCDIR/$APP-$VERSION.tar.?z*
  cd $APP-$VERSION
  fixbuilddirpermissions

  # We might have an issue with pagecurl causing gimp to segfault
  # https://gitlab.gnome.org/GNOME/gimp/-/issues/4392
  # remove /lib/gimp/2.0/plug-ins/pagecurl ?

  # credits: sabotage linux

  patch -p1 < $SRCDIR/gimp-toolbox-wilber.patch
  sed -i 's@^[[:space:]]*-I$(includedir)@@' $(find . -name Makefile.in)
  sed -i 's@^libgimpui = .*$@libgimpui = $(top_builddir)/libgimp/libgimpui-$(GIMP_API_VERSION).la $(top_builddir)/libgimpmodule/libgimpmodule-$(GIMP_API_VERSION).la@' $(find plug-ins/ -name Makefile.in)
  printf '#!/bin/sh\necho -lfreetype -I/usr/include/freetype2\n' > freetype-config
  chmod +x freetype-config
  export PATH="$PWD:$PATH"

  CXXFLAGS="$CFLAGS -D_GNU_SOURCE" \
  ./configure \
    --prefix="/" \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --disable-altivec \
    --disable-python \
    --disable-alsatest \
    --disable-nls \
    --disable-silent-rules \
    --disable-glibtest \
    --without-webkit 

  for i in po po-plug-ins po-python po-libgimp po-script-fu po-tips ; do           
    printf 'all:\n\ttrue\ninstall:\n\ttrue\nclean:\n\ttrue\n' > "$i"/Makefile
  done    

  make
  make install DESTDIR=$PKG

  cp COPYING $PKGDOCS/

  mkfinalpkg
}

SHA512SUMS="
b54b7c2788ce4f55887d7c4dbdd4879754b313cab813e1e5cda28419f41e16ed0eafb112763bc865a989634b290d6317b85bf70108977f9819f475f8f36dbc85  gimp-2.8.22.tar.lz
c1cea444156555bfe0c5d3a20733e04fb15a4ddaf0fd3f6f814d12bef554f3598ef9a27cd171df70e069e57f8d4fe661d8ef1691fef2ff7e44937cbb46e579b7  gimp-toolbox-wilber.patch
"
