nixpkgs/pkgs/misc/ghostscript/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

155 lines
4.4 KiB
Nix
Raw Normal View History

{ config, stdenv, lib, fetchurl, pkg-config, zlib, expat, openssl, autoconf
, libjpeg, libpng, libtiff, freetype, fontconfig, libpaper, jbig2dec
2022-04-25 21:45:03 +00:00
, libiconv, ijs, lcms2, callPackage, bash, buildPackages, openjpeg
2021-11-04 22:11:37 +00:00
, cupsSupport ? config.ghostscript.cups or (!stdenv.isDarwin), cups
, x11Support ? cupsSupport, xlibsWrapper # with CUPS, X11 only adds very little
}:
let
fonts = stdenv.mkDerivation {
name = "ghostscript-fonts";
srcs = [
(fetchurl {
url = "mirror://sourceforge/gs-fonts/ghostscript-fonts-std-8.11.tar.gz";
sha256 = "00f4l10xd826kak51wsmaz69szzm2wp8a41jasr4jblz25bg7dhf";
})
(fetchurl {
url = "mirror://gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz";
sha256 = "1cxaah3r52qq152bbkiyj2f7dx1rf38vsihlhjmrvzlr8v6cqil1";
})
# ... add other fonts here
];
installPhase = ''
mkdir "$out"
mv -v * "$out/"
'';
};
in
2014-11-05 02:26:53 +00:00
stdenv.mkDerivation rec {
pname = "ghostscript${lib.optionalString (x11Support) "-with-X"}";
2022-04-25 21:45:03 +00:00
version = "9.56.1";
2014-11-05 02:26:53 +00:00
src = fetchurl {
url = "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs9${lib.versions.minor version}${lib.versions.patch version}/ghostscript-${version}.tar.xz";
2022-04-25 21:45:03 +00:00
sha512 = "22ysgdprh960rxmxyk2fy2my47cdrhfhbrwar1955hvad54iw79l916drp92wh3qzbxw6z40i70wk00vz8bn2ryig7qgpc1q01m2npy";
};
patches = [
./urw-font-files.patch
./doc-no-ref.diff
];
2017-07-11 08:53:41 +00:00
outputs = [ "out" "man" "doc" ];
enableParallelBuilding = true;
depsBuildBuild = [
buildPackages.stdenv.cc
];
nativeBuildInputs = [ pkg-config autoconf zlib ]
++ lib.optional cupsSupport cups;
2021-11-04 22:11:37 +00:00
buildInputs = [
zlib expat openssl
libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
ghostscript: use system-wide openjpeg The following error occurs when using `imagemagickBig`: $ ./result/bin/identify sample.jp2 [1] 699089 IOT instruction (core dumped) ./result/bin/identify sample.jp2 When looking at the call-trace it seems as if certain symbols, e.g. `opj_malloc` are mixed up: #8 0x00007f78c79ad2f5 in MagickSignalHandler.cold () from /nix/store/bqy80qiw6czqh7vsmmmivwdswp9zzjgl-imagemagick-7.1.0-29/lib/libMagickCore-7.Q16HDRI.so.10 #9 <signal handler called> #10 0x00007f78c5a6095f in opj_malloc () from /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9 #11 0x00007f78c5a60981 in opj_calloc () from /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9 #12 0x00007f78c4f48e24 in opj_create_decompress () from /nix/store/qwalb0kjz1p9c4j48qkk6ql47ds2lnhh-openjpeg-2.4.0/lib/libopenjp2.so.7 The `opj_create_decompress()` is called from the `openjpeg`-integration of `imagemagick` and thus shouldn't affect `ghostscript` at all. However, `ghostscript` (`libgs.so` to be precise) also exposes e.g. `opj_malloc`: $ objdump -t /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9.55|grep opj_malloc 0000000000205940 g F .text 000000000000002b opj_malloc Because of that, two incompatible symbols are used in the same process and thus the `identify`-call breaks because the wrong one is used. To work around that I decided to use the system-wide openjpeg instead. I'm not sure why `libgs.so` wants to expose these symbols anyways, but with that workaround the problem is solved. Even though it's mentioned that ghostscript's openjpeg is heavily patched, I think that this is somewhat outdated or at least irrelevant considering that both ArchLinux[1] and Fedora[2] use the system-wide `openjpeg` instead. [1] https://github.com/archlinux/svntogit-packages/blob/bafcb5473b59d5386dd110d1cb249372dce9ea6c/trunk/PKGBUILD#L50 [2] https://src.fedoraproject.org/rpms/ghostscript/blob/e4eec13ab6ace2bad64b740d352964bbf61d1aa7/f/ghostscript.spec#_245
2022-04-21 11:54:14 +00:00
libiconv ijs lcms2 bash openjpeg
2021-11-04 22:11:37 +00:00
]
++ lib.optional x11Support xlibsWrapper
++ 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"''}
ghostscript: use system-wide openjpeg The following error occurs when using `imagemagickBig`: $ ./result/bin/identify sample.jp2 [1] 699089 IOT instruction (core dumped) ./result/bin/identify sample.jp2 When looking at the call-trace it seems as if certain symbols, e.g. `opj_malloc` are mixed up: #8 0x00007f78c79ad2f5 in MagickSignalHandler.cold () from /nix/store/bqy80qiw6czqh7vsmmmivwdswp9zzjgl-imagemagick-7.1.0-29/lib/libMagickCore-7.Q16HDRI.so.10 #9 <signal handler called> #10 0x00007f78c5a6095f in opj_malloc () from /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9 #11 0x00007f78c5a60981 in opj_calloc () from /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9 #12 0x00007f78c4f48e24 in opj_create_decompress () from /nix/store/qwalb0kjz1p9c4j48qkk6ql47ds2lnhh-openjpeg-2.4.0/lib/libopenjp2.so.7 The `opj_create_decompress()` is called from the `openjpeg`-integration of `imagemagick` and thus shouldn't affect `ghostscript` at all. However, `ghostscript` (`libgs.so` to be precise) also exposes e.g. `opj_malloc`: $ objdump -t /nix/store/wg6ly83k1k1fjiygiv1jr7li3p6dwsvq-ghostscript-with-X-9.55.0/lib/libgs.so.9.55|grep opj_malloc 0000000000205940 g F .text 000000000000002b opj_malloc Because of that, two incompatible symbols are used in the same process and thus the `identify`-call breaks because the wrong one is used. To work around that I decided to use the system-wide openjpeg instead. I'm not sure why `libgs.so` wants to expose these symbols anyways, but with that workaround the problem is solved. Even though it's mentioned that ghostscript's openjpeg is heavily patched, I think that this is somewhat outdated or at least irrelevant considering that both ArchLinux[1] and Fedora[2] use the system-wide `openjpeg` instead. [1] https://github.com/archlinux/svntogit-packages/blob/bafcb5473b59d5386dd110d1cb249372dce9ea6c/trunk/PKGBUILD#L50 [2] https://src.fedoraproject.org/rpms/ghostscript/blob/e4eec13ab6ace2bad64b740d352964bbf61d1aa7/f/ghostscript.spec#_245
2022-04-21 11:54:14 +00:00
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
2016-01-13 16:47:07 +00:00
autoconf
'';
configureFlags = [
"--with-system-libtiff"
"--enable-dynamic"
"--without-tesseract"
]
++ lib.optional x11Support "--with-x"
++ lib.optionals cupsSupport [
"--enable-cups"
];
# make check does nothing useful
doCheck = false;
# don't build/install statically linked bin/gs
2016-02-02 13:52:03 +00:00
buildFlags = [ "so" ];
installTargets = [ "soinstall" ];
2014-11-05 02:26:53 +00:00
postInstall = ''
ln -s gsc "$out"/bin/gs
2016-02-02 13:52:03 +00:00
cp -r Resource "$out/share/ghostscript/${version}"
ln -s "${fonts}" "$out/share/ghostscript/fonts"
2021-01-15 13:21:58 +00:00
'' + lib.optionalString stdenv.isDarwin ''
for file in $out/lib/*.dylib* ; do
install_name_tool -id "$file" $file
done
'';
2014-11-05 02:26:53 +00:00
# dynamic library name only contains maj.min, eg. '9.53'
dylib_version = lib.versions.majorMinor version;
2016-02-02 13:52:03 +00:00
preFixup = lib.optionalString stdenv.isDarwin ''
install_name_tool -change libgs.dylib.$dylib_version $out/lib/libgs.dylib.$dylib_version $out/bin/gs
'';
# validate dynamic linkage
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
$out/bin/gs --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 {};
2014-11-05 02:26:53 +00:00
meta = {
homepage = "https://www.ghostscript.com/";
2014-11-05 02:26:53 +00:00
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.
'';
2021-01-15 13:21:58 +00:00
license = lib.licenses.agpl3;
platforms = lib.platforms.all;
maintainers = [ lib.maintainers.viric ];
2021-10-11 06:03:44 +00:00
mainProgram = "gs";
2014-11-05 02:26:53 +00:00
};
}