anchor.diff:        libjpeg libpng libtiff freetype fontconfig lcms2 libpaper jbig2dec
         libiconv ijs
       ]
  -    ++ stdenv.lib.optional x11Support xlibsWrapper
  -    ++ stdenv.lib.optional cupsSupport cups
  +    ++ lib.optional x11Support xlibsWrapper
  +    ++ lib.optional cupsSupport cups
       ;
   
     patches = [
  
positive.code: { stdenv, fetchurl, fetchpatch, pkgconfig, zlib, expat, openssl, autoconf
  , libjpeg, libpng, libtiff, freetype, fontconfig, lcms2, libpaper, jbig2dec
  , libiconv, ijs
  , x11Support ? false, xlibsWrapper ? null
  
negative.code:     sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib}/include@" -i configure.ac
  
      autoconf
    '' + lib.optionalString cupsSupport ''
      configureFlags="$configureFlags --with-cups-serverbin=$out/lib/cups --with-cups-serverroot=$out/etc/cups --with-cups-datadir=$out/share/cups"
    '';
  
    configureFlags =
      [ "--with-system-libtiff"
        "--enable-dynamic"
      ] ++ lib.optional x11Support "--with-x"
        ++ lib.optional cupsSupport "--enable-cups";
  
    doCheck = true;
  
    # don't build/install statically linked bin/gs
    buildFlags = [ "so" ];
    installTargets = [ "soinstall" ];
  
    postInstall = ''
      ln -s gsc "$out"/bin/gs
  
      cp -r Resource "$out/share/ghostscript/${version}"
  
      mkdir -p "$doc/share/ghostscript/${version}"
      mv "$out/share/ghostscript/${version}"/{doc,examples} "$doc/share/ghostscript/${version}/"
  