2023-04-29 16:46:19 +00:00
{ config
, stdenv
, lib
, fetchurl
, pkg-config
, zlib
, expat
, openssl
, autoconf
, libjpeg
, libpng
, libtiff
, freetype
, fontconfig
, libpaper
, jbig2dec
, libiconv
, ijs
, lcms2
, callPackage
, bash
, buildPackages
, openjpeg
, cupsSupport ? config . ghostscript . cups or ( ! stdenv . isDarwin )
, cups
, x11Support ? cupsSupport
, xorg # with CUPS, X11 only adds very little
, dynamicDrivers ? true
# for passthru.tests
, graphicsmagick
, imagemagick
, libspectre
, lilypond
, pstoedit
, python3
2020-04-24 23:36:52 +00:00
} :
let
fonts = stdenv . mkDerivation {
name = " g h o s t s c r i p t - f o n t s " ;
srcs = [
( fetchurl {
url = " m i r r o r : / / s o u r c e f o r g e / g s - f o n t s / g h o s t s c r i p t - f o n t s - s t d - 8 . 1 1 . t a r . g z " ;
sha256 = " 0 0 f 4 l 1 0 x d 8 2 6 k a k 5 1 w s m a z 6 9 s z z m 2 w p 8 a 4 1 j a s r 4 j b l z 2 5 b g 7 d h f " ;
} )
( fetchurl {
url = " m i r r o r : / / g n u / g h o s t s c r i p t / g n u - g s - f o n t s - o t h e r - 6 . 0 . t a r . g z " ;
sha256 = " 1 c x a a h 3 r 5 2 q q 1 5 2 b b k i y j 2 f 7 d x 1 r f 3 8 v s i h l h j m r v z l r 8 v 6 c q i l 1 " ;
} )
# ... add other fonts here
] ;
installPhase = ''
mkdir " $ o u t "
mv - v * " $ o u t / "
'' ;
} ;
in
stdenv . mkDerivation rec {
2023-07-15 17:15:38 +00:00
pname = " g h o s t s c r i p t ${ lib . optionalString x11Support " - w i t h - X " } " ;
2023-11-16 04:20:00 +00:00
version = " 1 0 . 0 2 . 0 " ;
2020-04-24 23:36:52 +00:00
src = fetchurl {
2023-04-29 16:46:19 +00:00
url = " h t t p s : / / g i t h u b . c o m / A r t i f e x S o f t w a r e / g h o s t p d l - d o w n l o a d s / r e l e a s e s / d o w n l o a d / g s ${ lib . replaceStrings [ " . " ] [ " " ] version } / g h o s t s c r i p t - ${ version } . t a r . x z " ;
2023-11-16 04:20:00 +00:00
hash = " s h a 5 1 2 - x J N E F R B j 6 R W t 1 V o K h C w q Z F 2 D Y q X L y m Y 7 0 H Y 4 9 L 0 2 m a C M r e N 6 n v 6 Q W t W k H g F D U + X h s S a L e S X k M S i t M N W w M T l r c Q = = " ;
2020-04-24 23:36:52 +00:00
} ;
patches = [
./urw-font-files.patch
./doc-no-ref.diff
] ;
outputs = [ " o u t " " m a n " " d o c " ] ;
enableParallelBuilding = true ;
2021-12-06 16:07:01 +00:00
depsBuildBuild = [
buildPackages . stdenv . cc
] ;
nativeBuildInputs = [ pkg-config autoconf zlib ]
++ lib . optional cupsSupport cups ;
buildInputs = [
zlib expat openssl
libjpeg libpng libtiff freetype fontconfig libpaper jbig2dec
2022-05-18 14:49:53 +00:00
libiconv ijs lcms2 bash openjpeg
2021-12-06 16:07:01 +00:00
]
2022-10-30 15:09:59 +00:00
++ lib . optionals x11Support [ xorg . libICE xorg . libX11 xorg . libXext xorg . libXt ]
2021-12-06 16:07:01 +00:00
++ lib . optional cupsSupport cups
;
2020-04-24 23:36:52 +00:00
preConfigure = ''
2021-12-06 16:07:01 +00:00
# https://ghostscript.com/doc/current/Make.htm
export CCAUX = $ CC_FOR_BUILD
$ { lib . optionalString cupsSupport '' e x p o r t C U P S C O N F I G = " ${ cups . dev } / b i n / c u p s - c o n f i g " '' }
2022-05-18 14:49:53 +00:00
rm - rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs openjpeg
2020-04-24 23:36:52 +00:00
sed " s @ i f ( t e s t - f \$ ( I N C L U D E ) [ ^ ] * ) @ i f ( t r u e ) @ ; s @ I N C L U D E = / u s r / i n c l u d e @ I N C L U D E = / n o - s u c h - p a t h @ " - i base/unix-aux.mak
sed " s @ ^ Z L I B D I R = . * @ Z L I B D I R = ${ zlib . dev } / i n c l u d e @ " - i configure . ac
autoconf
'' ;
configureFlags = [
" - - w i t h - s y s t e m - l i b t i f f "
2022-01-26 04:04:25 +00:00
" - - w i t h o u t - t e s s e r a c t "
2023-04-29 16:46:19 +00:00
] ++ lib . optionals dynamicDrivers [
" - - e n a b l e - d y n a m i c "
" - - d i s a b l e - h i d d e n - v i s i b i l i t y "
2023-07-15 17:15:38 +00:00
] ++ lib . optionals x11Support [
2023-04-29 16:46:19 +00:00
" - - w i t h - x "
] ++ lib . optionals cupsSupport [
2020-04-24 23:36:52 +00:00
" - - e n a b l e - c u p s "
] ;
2021-09-26 12:46:18 +00:00
# make check does nothing useful
doCheck = false ;
2020-04-24 23:36:52 +00:00
# don't build/install statically linked bin/gs
2023-11-16 04:20:00 +00:00
buildFlags = [ " s o " ]
# 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 . isDarwin ) " L D F L A G S = - h e a d e r p a d _ m a x _ i n s t a l l _ n a m e s " ;
2020-04-24 23:36:52 +00:00
installTargets = [ " s o i n s t a l l " ] ;
postInstall = ''
ln - s gsc " $ o u t " /bin/gs
cp - r Resource " $ o u t / s h a r e / g h o s t s c r i p t / ${ version } "
ln - s " ${ fonts } " " $ o u t / s h a r e / g h o s t s c r i p t / f o n t s "
2021-01-17 00:15:33 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . i s D a r w i n ''
2020-04-24 23:36:52 +00:00
for file in $ out/lib /* . d y l i b * ; d o
install_name_tool - id " $ f i l e " $ file
done
'' ;
2020-11-30 08:33:03 +00:00
# dynamic library name only contains maj.min, eg. '9.53'
dylib_version = lib . versions . majorMinor version ;
2020-04-24 23:36:52 +00:00
preFixup = lib . optionalString stdenv . isDarwin ''
2020-11-30 08:33:03 +00:00
install_name_tool - change libgs . dylib . $ dylib_version $ out/lib/libgs.dylib. $ dylib_version $ out/bin/gs
2023-07-15 17:15:38 +00:00
install_name_tool - change libgs . dylib . $ dylib_version $ out/lib/libgs.dylib. $ dylib_version $ out/bin/gsx
2020-11-30 08:33:03 +00:00
'' ;
# validate dynamic linkage
doInstallCheck = true ;
installCheckPhase = ''
runHook preInstallCheck
$ out/bin/gs - - version
2023-07-15 17:15:38 +00:00
$ out/bin/gsx - - version
2021-09-26 12:46:18 +00:00
pushd examples
for f in * . { ps , eps , pdf } ; do
echo " R e n d e r i n g $ f "
$ out/bin/gs \
- dNOPAUSE \
- dBATCH \
- sDEVICE = bitcmyk \
- sOutputFile = /dev/null \
- r600 \
- dBufferSpace = 100000 \
$ f
done
popd # examples
2020-11-30 08:33:03 +00:00
runHook postInstallCheck
2020-04-24 23:36:52 +00:00
'' ;
2023-04-29 16:46:19 +00:00
passthru . tests = {
test-corpus-render = callPackage ./test-corpus-render.nix { } ;
inherit graphicsmagick imagemagick libspectre lilypond pstoedit ;
inherit ( python3 . pkgs ) matplotlib ;
} ;
2021-09-26 12:46:18 +00:00
2020-04-24 23:36:52 +00:00
meta = {
homepage = " h t t p s : / / w w w . g h o s t s c r i p t . c o m / " ;
description = " P o s t S c r i p t i n t e r p r e t e r ( m a i n l i n e v e r s i o n ) " ;
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-17 00:15:33 +00:00
license = lib . licenses . agpl3 ;
platforms = lib . platforms . all ;
maintainers = [ lib . maintainers . viric ] ;
2021-10-14 00:43:12 +00:00
mainProgram = " g s " ;
2020-04-24 23:36:52 +00:00
} ;
}