1{ stdenv, lib, fetchurl, 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.${ver_min}";
12 ver_min = "22";
13 sha256 = "1fyi4yvdj39bjgs10klr31cda1fbx1ar7a7b7yz7v68gykk65y61";
14
15 fonts = stdenv.mkDerivation {
16 name = "ghostscript-fonts";
17
18 srcs = [
19 (fetchurl {
20 url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz";
21 sha256 = "00f4l10xd826kak51wsmaz69szzm2wp8a41jasr4jblz25bg7dhf";
22 })
23 (fetchurl {
24 url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz";
25 sha256 = "1cxaah3r52qq152bbkiyj2f7dx1rf38vsihlhjmrvzlr8v6cqil1";
26 })
27 # ... add other fonts here
28 ];
29
30 installPhase = ''
31 mkdir "$out"
32 mv -v * "$out/"
33 '';
34 };
35
36in
37stdenv.mkDerivation rec {
38 name = "ghostscript-${version}";
39
40 src = fetchurl {
41 url = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs9${ver_min}/${name}.tar.xz";
42 inherit sha256;
43 };
44
45 outputs = [ "out" "man" "doc" ];
46
47 enableParallelBuilding = true;
48
49 nativeBuildInputs = [ pkgconfig autoconf ];
50 buildInputs =
51 [ zlib expat openssl
52 libjpeg libpng libtiff freetype fontconfig lcms2 libpaper jbig2dec
53 libiconv ijs
54 ]
55 ++ lib.optional x11Support xlibsWrapper
56 ++ lib.optional cupsSupport cups
57 ;
58
59 patches = [
60 ./urw-font-files.patch
61 ];
62
63 preConfigure = ''
64 # requires in-tree (heavily patched) openjpeg
65 rm -rf jpeg libpng zlib jasper expat tiff lcms{,2} jbig2dec freetype cups/libs ijs
66
67 sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
68 sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib.dev}/include@" -i configure.ac
69
70 autoconf
71 '' + lib.optionalString cupsSupport ''
72 configureFlags="$configureFlags --with-cups-serverbin=$out/lib/cups --with-cups-serverroot=$out/etc/cups --with-cups-datadir=$out/share/cups"
73 '';
74
75 configureFlags =
76 [ "--with-system-libtiff"
77 "--enable-dynamic"
78 ] ++ lib.optional x11Support "--with-x"
79 ++ lib.optional cupsSupport "--enable-cups";
80
81 doCheck = true;
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 cp -r Resource "$out/share/ghostscript/${version}"
91
92 mkdir -p "$doc/share/ghostscript/${version}"
93 mv "$out/share/ghostscript/${version}"/{doc,examples} "$doc/share/ghostscript/${version}/"
94
95 ln -s "${fonts}" "$out/share/ghostscript/fonts"
96 '' + stdenv.lib.optionalString stdenv.isDarwin ''
97 for file in $out/lib/*.dylib* ; do
98 install_name_tool -id "$file" $file
99 done
100 '';
101
102 preFixup = lib.optionalString stdenv.isDarwin ''
103 install_name_tool -change libgs.dylib.${version} $out/lib/libgs.dylib.${version} $out/bin/gs
104 '';
105
106 passthru = { inherit version; };
107
108 meta = {
109 homepage = https://www.ghostscript.com/;
110 description = "PostScript interpreter (mainline version)";
111
112 longDescription = ''
113 Ghostscript is the name of a set of tools that provides (i) an
114 interpreter for the PostScript language and the PDF file format,
115 (ii) a set of C procedures (the Ghostscript library) that
116 implement the graphics capabilities that appear as primitive
117 operations in the PostScript language, and (iii) a wide variety
118 of output drivers for various file formats and printers.
119 '';
120
121 license = stdenv.lib.licenses.agpl3;
122
123 platforms = stdenv.lib.platforms.all;
124 maintainers = [ stdenv.lib.maintainers.viric ];
125 };
126}