1{ stdenv, lib, fetchurl, fetchpatch, pkgconfig, zlib, expat, openssl, autoconf 2, libjpeg, libpng, libtiff, freetype, fontconfig, lcms2, libpaper, jbig2dec 3, libiconv, ijs 4, x11Support ? false, xlibsWrapper ? null 5, cupsSupport ? false, cups ? null 6}: 7 8assert x11Support -> xlibsWrapper != null; 9assert cupsSupport -> cups != null; 10let 11 version = "9.18"; 12 sha256 = "18ad90za28dxybajqwf3y3dld87cgkx1ljllmcnc7ysspfxzbnl3"; 13 14 fonts = stdenv.mkDerivation { 15 name = "ghostscript-fonts"; 16 17 srcs = [ 18 (fetchurl { 19 url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz"; 20 sha256 = "00f4l10xd826kak51wsmaz69szzm2wp8a41jasr4jblz25bg7dhf"; 21 }) 22 (fetchurl { 23 url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz"; 24 sha256 = "1cxaah3r52qq152bbkiyj2f7dx1rf38vsihlhjmrvzlr8v6cqil1"; 25 }) 26 # ... add other fonts here 27 ]; 28 29 installPhase = '' 30 mkdir "$out" 31 mv -v * "$out/" 32 ''; 33 }; 34 35in 36stdenv.mkDerivation rec { 37 name = "ghostscript-${version}"; 38 39 src = fetchurl { 40 url = "http://downloads.ghostscript.com/public/${name}.tar.bz2"; 41 inherit sha256; 42 }; 43 44 outputs = [ "out" "doc" ]; 45 46 enableParallelBuilding = true; 47 48 nativeBuildInputs = [ pkgconfig autoconf ]; 49 buildInputs = 50 [ zlib expat openssl 51 libjpeg libpng libtiff freetype fontconfig lcms2 libpaper jbig2dec 52 libiconv ijs 53 ] 54 ++ lib.optional x11Support xlibsWrapper 55 ++ lib.optional cupsSupport cups 56 ; 57 58 patches = [ 59 ./urw-font-files.patch 60 # http://bugs.ghostscript.com/show_bug.cgi?id=696281 61 (fetchpatch { 62 name = "fix-check-for-using-shared-freetype-lib.patch"; 63 url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=8f5d285"; 64 sha256 = "1f0k043rng7f0rfl9hhb89qzvvksqmkrikmm38p61yfx51l325xr"; 65 }) 66 # http://bugs.ghostscript.com/show_bug.cgi?id=696301 67 (fetchpatch { 68 name = "add-gserrors.h-to-the-installed-files.patch"; 69 url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=feafe5e5"; 70 sha256 = "0s4ayzakjv809dkn7vilxwvs4dw35p3pw942ml91bk9z4kkaxyz7"; 71 }) 72 # http://bugs.ghostscript.com/show_bug.cgi?id=696246 73 (fetchpatch { 74 name = "guard-against-NULL-base-for-non-clist-devices.patch"; 75 url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=007bd77d08d800e6b07274d62e3c91be7c4a3f47"; 76 sha256 = "1la53273agl92lpy7qd0qhgzynx8b90hrk8g9jsj3055ssn6rqwh"; 77 }) 78 (fetchpatch { 79 name = "ensure-plib-devices-always-use-the-clist.patch"; 80 url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=1bdbe4f87dc57648821e613ebcc591b84e8b35b3"; 81 sha256 = "1cq83fgyvrycapxm69v4r9f9qhzsr40ygrc3bkp8pk15wsmvq0k7"; 82 }) 83 (fetchpatch { 84 name = "prevent-rinkj-device-crash-when-misconfigured.patch"; 85 url = "http://git.ghostscript.com/?p=ghostpdl.git;a=patch;h=5571ddfa377c5d7d98f55af40e693814ac287ae4"; 86 sha256 = "08iqdlrngi6k0ml2b71dj5q136fyp1s9g0rr87ayyshn0k0lxwkv"; 87 }) 88 ]; 89 90 preConfigure = '' 91 # requires in-tree (heavily patched) openjpeg 92 rm -rf jpeg libpng zlib jasper expat tiff lcms{,2} jbig2dec freetype cups/libs ijs 93 94 sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak 95 sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib}/include@" -i configure.ac 96 97 autoconf 98 '' + lib.optionalString cupsSupport '' 99 configureFlags="$configureFlags --with-cups-serverbin=$out/lib/cups --with-cups-serverroot=$out/etc/cups --with-cups-datadir=$out/share/cups" 100 ''; 101 102 configureFlags = 103 [ "--with-system-libtiff" 104 "--enable-dynamic" 105 ] ++ lib.optional x11Support "--with-x" 106 ++ lib.optional cupsSupport "--enable-cups"; 107 108 doCheck = true; 109 110 # don't build/install statically linked bin/gs 111 buildFlags = [ "so" ]; 112 installTargets = [ "soinstall" ]; 113 114 postInstall = '' 115 ln -s gsc "$out"/bin/gs 116 117 cp -r Resource "$out/share/ghostscript/${version}" 118 119 mkdir -p "$doc/share/ghostscript/${version}" 120 mv "$out/share/ghostscript/${version}"/{doc,examples} "$doc/share/ghostscript/${version}/" 121 122 ln -s "${fonts}" "$out/share/ghostscript/fonts" 123 ''; 124 125 preFixup = lib.optionalString stdenv.isDarwin '' 126 install_name_tool -change libgs.dylib.${version} $out/lib/libgs.dylib.${version} $out/bin/gs 127 ''; 128 129 meta = { 130 homepage = "http://www.ghostscript.com/"; 131 description = "PostScript interpreter (mainline version)"; 132 133 longDescription = '' 134 Ghostscript is the name of a set of tools that provides (i) an 135 interpreter for the PostScript language and the PDF file format, 136 (ii) a set of C procedures (the Ghostscript library) that 137 implement the graphics capabilities that appear as primitive 138 operations in the PostScript language, and (iii) a wide variety 139 of output drivers for various file formats and printers. 140 ''; 141 142 license = stdenv.lib.licenses.gpl3Plus; 143 144 platforms = stdenv.lib.platforms.all; 145 maintainers = [ stdenv.lib.maintainers.viric ]; 146 }; 147}