1{ stdenv, fetchurl, pkgconfig, zlib, expat, openssl
2, libjpeg, libpng, libtiff, freetype, fontconfig, lcms2, libpaper, jbig2dec
3, libiconv
4, x11Support ? false, xlibsWrapper ? null
5, cupsSupport ? false, cups ? null
6}:
7
8assert x11Support -> xlibsWrapper != null;
9assert cupsSupport -> cups != null;
10let
11 version = "9.15";
12 sha256 = "0p1isp6ssfay141klirn7n9s8b546vcz6paksfmksbwy0ljsypg6";
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 buildInputs =
49 [ pkgconfig zlib expat openssl
50 libjpeg libpng libtiff freetype fontconfig lcms2 libpaper jbig2dec
51 libiconv
52 ]
53 ++ stdenv.lib.optional x11Support xlibsWrapper
54 ++ stdenv.lib.optional cupsSupport cups
55 # [] # maybe sometimes jpeg2000 support
56 ;
57
58 patches = [
59 ./urw-font-files.patch
60 # fetched from debian's ghostscript 9.15_dfsg-1 (called 020150707~0c0b085.patch there)
61 ./CVE-2015-3228.patch
62 ];
63
64 makeFlags = [ "cups_serverroot=$(out)" "cups_serverbin=$(out)/lib/cups" ];
65
66 preConfigure = ''
67 rm -rf jpeg libpng zlib jasper expat tiff lcms{,2} jbig2dec openjpeg freetype cups/libs
68
69 sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
70 '';
71
72 configureFlags =
73 [ "--with-system-libtiff"
74 "--enable-dynamic"
75 (if x11Support then "--with-x" else "--without-x")
76 (if cupsSupport then "--enable-cups" else "--disable-cups")
77 ];
78
79 doCheck = true;
80 preCheck = "mkdir ./obj";
81 # parallel check sometimes gave: Fatal error: can't create ./obj/whitelst.o
82
83 # don't build/install statically linked bin/gs
84 buildFlags = "so";
85 installTargets="soinstall";
86
87 postInstall = ''
88 ln -s gsc "$out"/bin/gs
89
90 mkdir -p "$doc/share/ghostscript/${version}"
91 mv "$out/share/ghostscript/${version}"/{doc,examples} "$doc/share/ghostscript/${version}/"
92
93 ln -s "${fonts}" "$out/share/ghostscript/fonts"
94 '';
95
96 meta = {
97 homepage = "http://www.ghostscript.com/";
98 description = "PostScript interpreter (mainline version)";
99
100 longDescription = ''
101 Ghostscript is the name of a set of tools that provides (i) an
102 interpreter for the PostScript language and the PDF file format,
103 (ii) a set of C procedures (the Ghostscript library) that
104 implement the graphics capabilities that appear as primitive
105 operations in the PostScript language, and (iii) a wide variety
106 of output drivers for various file formats and printers.
107 '';
108
109 license = stdenv.lib.licenses.gpl3Plus;
110
111 platforms = stdenv.lib.platforms.all;
112 maintainers = [ stdenv.lib.maintainers.viric ];
113 };
114}