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