[buildout]
extends =
  ../fontconfig/buildout.cfg
  ../freetype/buildout.cfg
  ../libidn/buildout.cfg
  ../libjpeg/buildout.cfg
  ../libtiff/buildout.cfg
  ../libxml2/buildout.cfg
  ../patch/buildout.cfg
  ../pkgconfig/buildout.cfg
  ../tesseract/buildout.cfg
  ../xz-utils/buildout.cfg

parts = ghostscript

[ghostscript]
recipe = slapos.recipe.cmmi
shared = true
url = https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10021/ghostscript-10.02.1.tar.xz
md5sum = 26c0cbfa2e09da97f1fc78728048ada8
pkg_config_depends = ${libidn:location}/lib/pkgconfig:${libtiff:location}/lib/pkgconfig:${libjpeg:location}/lib/pkgconfig:${fontconfig:location}/lib/pkgconfig:${fontconfig:pkg_config_depends}
# XXX --with-tessdata work arounds a slaprunner bug of having softwares installed in a path containing //
configure-options =
  --disable-cups
  --with-system-libtiff
  --without-so
  --without-x
  --with-drivers=FILES
  --with-tessdata=$(python -c 'print("""${:tessdata-location}""".replace("//", "/"))')
environment =
  PATH=${patch:location}/bin:${pkgconfig:location}/bin:${xz-utils:location}/bin:%(PATH)s
  PKG_CONFIG_PATH=${:pkg_config_depends}
  CFLAGS=-I${libjpeg:location}/include
  LDFLAGS=-Wl,-rpath=${libidn:location}/lib -Wl,-rpath=${fontconfig:location}/lib -Wl,-rpath=${freetype:location}/lib -Wl,-rpath=${libtiff:location}/lib -L${libjpeg:location}/lib -Wl,-rpath=${libjpeg:location}/lib
  LD_LIBRARY_PATH=${libidn:location}/lib:${fontconfig:location}/lib:${freetype:location}/lib:${libtiff:location}/lib:${libxml2:location}/lib
patches =
  https://github.com/ArtifexSoftware/ghostpdl/commit/f8a4030a319705b9402b386a0ada8dd00b8181d3.patch#7b6dcda1cf19e639994921713fb41277
patch-options = -p1
# configure gives priority to local jpeg library and refuse mixing local libjpeg with "system" libtiff.
# We remove this local jpeg library source folder so that configure picks up the slapos versions of these libraries.
pre-configure = rm -r jpeg

post-make-hook = ${tesseract-download-traineddata:post-make-hook}
tessdata-location = @@LOCATION@@/share/tessdata/
tessdata-urls = ${tesseract-download-traineddata:urls}
