2024-06-30 08:16:52 +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 ,
2024-05-02 00:46:19 +00:00
# for passthru.tests
# , graphicsmagick
# , imagemagick
# , libspectre
# , lilypond
# , pstoedit
# , python3
} :
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 {
pname = " g h o s t s c r i p t ${ lib . optionalString x11Support " - w i t h - X " } " ;
version = " 1 0 . 0 2 . 1 " ;
src = fetchurl {
2024-06-30 08:16:52 +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
} /ghostscript- $ { version } . tar . xz " ;
2024-05-02 00:46:19 +00:00
hash = " s h a 5 1 2 - 7 g 9 1 T B v Y o Y Q o r R T q o + r Y D / i 5 Y n W v U B L n q D h P H x B J D a B W 7 s m u P M e R p 6 E 6 J O F u V N 9 b z N 0 Q n H 1 T o U U 0 u 9 c 2 C j A L E Q = " ;
} ;
patches = [
./urw-font-files.patch
./doc-no-ref.diff
] ;
2024-06-30 08:16:52 +00:00
outputs = [
" o u t "
" m a n "
" d o c "
] ;
2024-05-02 00:46:19 +00:00
enableParallelBuilding = true ;
2024-06-30 08:16:52 +00:00
depsBuildBuild = [ buildPackages . stdenv . cc ] ;
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
nativeBuildInputs = [
pkg-config
autoconf
zlib
] ++ lib . optional cupsSupport cups ;
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
]
2024-05-02 00:46:19 +00:00
++ lib . optional cupsSupport cups ;
preConfigure = ''
# 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 " '' }
rm - rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs openjpeg
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
'' ;
2024-06-30 08:16:52 +00:00
configureFlags =
[
" - - w i t h - s y s t e m - l i b t i f f "
" - - w i t h o u t - t e s s e r a c t "
]
++ 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 "
]
++ lib . optionals x11Support [ " - - w i t h - x " ]
++ lib . optionals cupsSupport [ " - - e n a b l e - c u p s " ] ;
2024-05-02 00:46:19 +00:00
# make check does nothing useful
doCheck = false ;
# don't build/install statically linked bin/gs
2024-06-30 08:16:52 +00:00
buildFlags =
[ " s o " ]
2024-05-02 00:46:19 +00:00
# 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 " ;
installTargets = [ " s o i n s t a l l " ] ;
2024-06-30 08:16:52 +00:00
postInstall =
''
ln - s gsc " $ o u t " /bin/gs
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
cp - r Resource " $ o u t / s h a r e / g h o s t s c r i p t / ${ version } "
2024-05-02 00:46:19 +00:00
2024-06-30 08:16:52 +00:00
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 "
''
+ lib . optionalString stdenv . isDarwin ''
for file in $ out/lib /* . d y l i b * ; d o
install_name_tool - id " $ f i l e " $ file
done
'' ;
2024-05-02 00:46:19 +00:00
# dynamic library name only contains maj.min, eg. '9.53'
dylib_version = lib . versions . majorMinor version ;
preFixup = lib . optionalString stdenv . isDarwin ''
install_name_tool - change libgs . dylib . $ dylib_version $ out/lib/libgs.dylib. $ dylib_version $ out/bin/gs
install_name_tool - change libgs . dylib . $ dylib_version $ out/lib/libgs.dylib. $ dylib_version $ out/bin/gsx
'' ;
# 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 " 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
runHook postInstallCheck
'' ;
# passthru.tests = {
# test-corpus-render = callPackage ./test-corpus-render.nix {};
# inherit graphicsmagick imagemagick libspectre lilypond pstoedit;
# inherit (python3.pkgs) matplotlib;
# };
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 .
'' ;
license = lib . licenses . agpl3Plus ;
platforms = lib . platforms . all ;
maintainers = [ lib . maintainers . viric ] ;
mainProgram = " g s " ;
} ;
}