1{ config, stdenv, lib, fetchurl, pkg-config, zlib, expat, openssl, autoconf
2, libjpeg, libpng, libtiff, freetype, fontconfig, libpaper, jbig2dec
3, libiconv, ijs, lcms2, fetchpatch
4, cupsSupport ? config.ghostscript.cups or (!stdenv.isDarwin), cups ? null
5, x11Support ? cupsSupport, xlibsWrapper ? null # with CUPS, X11 only adds very little
6}:
7
8assert x11Support -> xlibsWrapper != null;
9assert cupsSupport -> cups != null;
10
11let
12 fonts = stdenv.mkDerivation {
13 name = "ghostscript-fonts";
14
15 srcs = [
16 (fetchurl {
17 url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz";
18 sha256 = "00f4l10xd826kak51wsmaz69szzm2wp8a41jasr4jblz25bg7dhf";
19 })
20 (fetchurl {
21 url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz";
22 sha256 = "1cxaah3r52qq152bbkiyj2f7dx1rf38vsihlhjmrvzlr8v6cqil1";
23 })
24 # ... add other fonts here
25 ];
26
27 installPhase = ''
28 mkdir "$out"
29 mv -v * "$out/"
30 '';
31 };
32
33in
34stdenv.mkDerivation rec {
35 pname = "ghostscript";
36 version = "9.53.3";
37
38 src = fetchurl {
39 url = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs9${lib.versions.minor version}${lib.versions.patch version}/${pname}-${version}.tar.xz";
40 sha512 = "2vif3vgxa5wma16yxvhhkymk4p309y5204yykarq94r5rk890556d2lj5w7acnaa2ymkym6y0zd4vq9sy9ca2346igg2c6dxqkjr0zb";
41 };
42
43 patches = [
44 (fetchpatch {
45 url = "https://github.com/ArtifexSoftware/ghostpdl/commit/41ef9a0bc36b9db7115fbe9623f989bfb47bbade.patch";
46 sha256 = "1qpc6q1fpxshqc0mqgg36kng47kgljk50bmr8p7wn21jgfkh7m8w";
47 })
48 ./urw-font-files.patch
49 ./doc-no-ref.diff
50 ];
51
52 outputs = [ "out" "man" "doc" ];
53
54 enableParallelBuilding = true;
55
56 nativeBuildInputs = [ pkg-config autoconf ];
57 buildInputs =
58 [ zlib expat openssl
59 libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
60 libiconv ijs lcms2
61 ]
62 ++ lib.optional x11Support xlibsWrapper
63 ++ lib.optional cupsSupport cups
64 ;
65
66 preConfigure = ''
67 # requires in-tree (heavily patched) openjpeg
68 rm -rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs
69
70 sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
71 sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib.dev}/include@" -i configure.ac
72
73 autoconf
74 '';
75
76 configureFlags = [
77 "--with-system-libtiff"
78 "--enable-dynamic"
79 ]
80 ++ lib.optional x11Support "--with-x"
81 ++ lib.optionals cupsSupport [
82 "--enable-cups"
83 "--with-cups-serverbin=$(out)/lib/cups"
84 "--with-cups-serverroot=$(out)/etc/cups"
85 "--with-cups-datadir=$(out)/share/cups"
86 ];
87
88 doCheck = true;
89
90 # don't build/install statically linked bin/gs
91 buildFlags = [ "so" ];
92 installTargets = [ "soinstall" ];
93
94 postInstall = ''
95 ln -s gsc "$out"/bin/gs
96
97 cp -r Resource "$out/share/ghostscript/${version}"
98
99 ln -s "${fonts}" "$out/share/ghostscript/fonts"
100 '' + lib.optionalString stdenv.isDarwin ''
101 for file in $out/lib/*.dylib* ; do
102 install_name_tool -id "$file" $file
103 done
104 '';
105
106 # dynamic library name only contains maj.min, eg. '9.53'
107 dylib_version = lib.versions.majorMinor version;
108 preFixup = lib.optionalString stdenv.isDarwin ''
109 install_name_tool -change libgs.dylib.$dylib_version $out/lib/libgs.dylib.$dylib_version $out/bin/gs
110 '';
111
112 # validate dynamic linkage
113 doInstallCheck = true;
114 installCheckPhase = ''
115 runHook preInstallCheck
116
117 $out/bin/gs --version
118
119 runHook postInstallCheck
120 '';
121
122 meta = {
123 homepage = "https://www.ghostscript.com/";
124 description = "PostScript interpreter (mainline version)";
125
126 longDescription = ''
127 Ghostscript is the name of a set of tools that provides (i) an
128 interpreter for the PostScript language and the PDF file format,
129 (ii) a set of C procedures (the Ghostscript library) that
130 implement the graphics capabilities that appear as primitive
131 operations in the PostScript language, and (iii) a wide variety
132 of output drivers for various file formats and printers.
133 '';
134
135 license = lib.licenses.agpl3;
136
137 platforms = lib.platforms.all;
138 maintainers = [ lib.maintainers.viric ];
139 };
140}