-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
/
Copy pathdefault.nix
197 lines (169 loc) · 5.3 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{ config
, stdenv
, lib
, fetchurl
, pkg-config
, zlib
, expat
, openssl
, autoconf
, libjpeg
, libpng
, libtiff
, freetype
, fontconfig
, libpaper
, jbig2dec
, libiconv
, ijs
, lcms2
, callPackage
, bash
, buildPackages
, openjpeg
, fixDarwinDylibNames
, cupsSupport ? config.ghostscript.cups or (!stdenv.hostPlatform.isDarwin)
, cups
, x11Support ? cupsSupport
, xorg # with CUPS, X11 only adds very little
, dynamicDrivers ? true
# for passthru.tests
, graphicsmagick
, imagemagick
, libspectre
, lilypond
, pstoedit
, python3
}:
let
fonts = stdenv.mkDerivation {
name = "ghostscript-fonts";
srcs = [
(fetchurl {
url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz";
hash = "sha256-DrbzVhGfLkmyVjIQhS4X9X+dzFdV81Cmmkag1kGgxAE=";
})
(fetchurl {
url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz";
hash = "sha256-gUbMzEaZ/p2rhBRGvdFwOfR2nJA+zrVECRiLkgdUqrM=";
})
# ... add other fonts here
];
installPhase = ''
mkdir "$out"
mv -v * "$out/"
'';
};
in
stdenv.mkDerivation rec {
pname = "ghostscript${lib.optionalString x11Support "-with-X"}";
version = "10.04.0";
src = fetchurl {
url = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs${lib.replaceStrings ["."] [""] version}/ghostscript-${version}.tar.xz";
hash = "sha256-Un7vC2zQTs8cjXoReWxppS00/+Nq/KhqQAcpovwByIc=";
};
patches = [
./urw-font-files.patch
./doc-no-ref.diff
];
outputs = [ "out" "man" "doc" "fonts" ];
enableParallelBuilding = true;
depsBuildBuild = [
buildPackages.stdenv.cc
];
nativeBuildInputs = [ pkg-config autoconf zlib ]
++ lib.optional cupsSupport cups
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = [
zlib expat openssl
libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
libiconv ijs lcms2 bash openjpeg
]
++ lib.optionals x11Support [ xorg.libICE xorg.libX11 xorg.libXext xorg.libXt ]
++ lib.optional cupsSupport cups
;
preConfigure = ''
# https://ghostscript.com/doc/current/Make.htm
export CCAUX=$CC_FOR_BUILD
${lib.optionalString cupsSupport ''export CUPSCONFIG="${cups.dev}/bin/cups-config"''}
rm -rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs openjpeg
sed "s@if ( test -f \$(INCLUDE)[^ ]* )@if ( true )@; s@INCLUDE=/usr/include@INCLUDE=/no-such-path@" -i base/unix-aux.mak
sed "s@^ZLIBDIR=.*@ZLIBDIR=${zlib.dev}/include@" -i configure.ac
autoconf
'';
configureFlags = [
"--with-system-libtiff"
"--without-tesseract"
] ++ lib.optionals dynamicDrivers [
"--enable-dynamic"
"--disable-hidden-visibility"
] ++ lib.optionals x11Support [
"--with-x"
] ++ lib.optionals cupsSupport [
"--enable-cups"
];
# make check does nothing useful
doCheck = false;
# don't build/install statically linked bin/gs
buildFlags = [ "so" ]
# without -headerpad, the following error occurs on Darwin when compiling with X11 support (as of 10.02.0)
# error: install_name_tool: changing install names or rpaths can't be redone for: [...]libgs.dylib.10 (the program must be relinked, and you may need to use -headerpad or -headerpad_max_install_names)
++ lib.optional (x11Support && stdenv.hostPlatform.isDarwin) "LDFLAGS=-headerpad_max_install_names";
installTargets = [ "soinstall" ];
postInstall = ''
ln -s gsc "$out"/bin/gs
cp -r Resource "$out/share/ghostscript/${version}"
mkdir -p $fonts/share/fonts
cp -rv ${fonts}/* "$fonts/share/fonts/"
ln -s "$fonts/share/fonts" "$out/share/ghostscript/fonts"
'';
# dynamic library name only contains major version number, eg. '10'
dylib_version = lib.versions.major version;
preFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
for file in $out/bin/{gs,gsc,gsx}; do
install_name_tool -change libgs.$dylib_version.dylib $out/lib/libgs.$dylib_version.dylib $file
done
'';
# validate dynamic linkage
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
$out/bin/gs --version
$out/bin/gsx --version
pushd examples
for f in *.{ps,eps,pdf}; do
echo "Rendering $f"
$out/bin/gs \
-dNOPAUSE \
-dBATCH \
-sDEVICE=bitcmyk \
-sOutputFile=/dev/null \
-r600 \
-dBufferSpace=100000 \
$f
done
popd # examples
runHook postInstallCheck
'';
passthru.tests = {
test-corpus-render = callPackage ./test-corpus-render.nix {};
inherit graphicsmagick imagemagick libspectre lilypond pstoedit;
inherit (python3.pkgs) matplotlib;
};
meta = {
homepage = "https://www.ghostscript.com/";
description = "PostScript interpreter (mainline version)";
longDescription = ''
Ghostscript is the name of a set of tools that provides (i) an
interpreter for the PostScript language and the PDF file format,
(ii) a set of C procedures (the Ghostscript library) that
implement the graphics capabilities that appear as primitive
operations in the PostScript language, and (iii) a wide variety
of output drivers for various file formats and printers.
'';
license = lib.licenses.agpl3Plus;
platforms = lib.platforms.all;
maintainers = [ lib.maintainers.tobim ];
mainProgram = "gs";
};
}