2023-04-11 21:53:17 +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
2023-04-11 22:53:49 +00:00
# for passthru.tests
, graphicsmagick
, imagemagick
, libspectre
, lilypond
, pstoedit
, python3
2005-08-30 13:50:14 +00:00
} :
2015-07-26 13:50:59 +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 / "
'' ;
} ;
2005-04-29 13:23:15 +00:00
2015-07-26 13:50:59 +00:00
in
2014-11-05 02:26:53 +00:00
stdenv . mkDerivation rec {
2023-05-29 23:41:39 +00:00
pname = " g h o s t s c r i p t ${ lib . optionalString x11Support " - w i t h - X " } " ;
2023-11-20 22:33:51 +00:00
version = " 1 0 . 0 2 . 1 " ;
2011-05-24 15:35:38 +00:00
2014-11-05 02:26:53 +00:00
src = fetchurl {
2023-04-11 21:53:17 +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-20 22:33:51 +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 = " ;
2011-05-24 15:35:38 +00:00
} ;
2018-09-04 16:50:15 +00:00
patches = [
./urw-font-files.patch
./doc-no-ref.diff
] ;
2017-07-11 08:53:41 +00:00
outputs = [ " o u t " " m a n " " d o c " ] ;
2005-04-29 13:23:15 +00:00
2013-09-26 15:00:12 +00:00
enableParallelBuilding = true ;
2021-11-04 12:48:57 +00:00
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
2022-04-21 11:54:14 +00:00
libiconv ijs lcms2 bash openjpeg
2021-11-04 22:11:37 +00:00
]
2022-10-04 18:58:14 +00:00
++ lib . optionals x11Support [ xorg . libICE xorg . libX11 xorg . libXext xorg . libXt ]
2021-11-04 22:11:37 +00:00
++ lib . optional cupsSupport cups
;
2012-01-03 17:50:10 +00:00
2015-07-26 13:50:59 +00:00
preConfigure = ''
2021-11-04 12:48:57 +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-04-21 11:54:14 +00:00
rm - rf jpeg libpng zlib jasper expat tiff lcms2mt jbig2dec freetype cups/libs ijs openjpeg
2015-07-26 13:50:59 +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
2016-04-16 17:50:01 +00:00
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
2016-01-13 16:47:07 +00:00
autoconf
2015-07-26 13:50:59 +00:00
'' ;
2019-11-20 08:21:30 +00:00
configureFlags = [
" - - w i t h - s y s t e m - l i b t i f f "
2022-01-09 01:01:38 +00:00
" - - w i t h o u t - t e s s e r a c t "
2023-04-11 21:53:17 +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-05-29 23:41:39 +00:00
] ++ lib . optionals x11Support [
2023-04-11 21:53:17 +00:00
" - - w i t h - x "
] ++ lib . optionals cupsSupport [
2019-11-20 08:21:30 +00:00
" - - e n a b l e - c u p s "
] ;
2008-07-17 19:37:18 +00:00
2021-09-11 18:07:58 +00:00
# make check does nothing useful
doCheck = false ;
2012-01-03 17:50:10 +00:00
2015-07-26 13:50:59 +00:00
# don't build/install statically linked bin/gs
2023-11-05 19:46:28 +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 " ;
2016-02-02 13:52:03 +00:00
installTargets = [ " s o i n s t a l l " ] ;
2014-11-05 02:26:53 +00:00
2012-01-03 17:50:10 +00:00
postInstall = ''
2015-07-26 13:50:59 +00:00
ln - s gsc " $ o u t " /bin/gs
2016-02-02 13:52:03 +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 } "
2015-07-26 13:50:59 +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 "
2021-01-15 13:21:58 +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 ''
2017-02-16 18:32:39 +00:00
for file in $ out/lib /* . d y l i b * ; d o
install_name_tool - id " $ f i l e " $ file
done
2012-01-03 17:50:10 +00:00
'' ;
2014-11-05 02:26:53 +00:00
2020-11-24 09:46:19 +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 ''
2020-11-24 09:46:19 +00:00
install_name_tool - change libgs . dylib . $ dylib_version $ out/lib/libgs.dylib. $ dylib_version $ out/bin/gs
2023-06-25 20:14:56 +00:00
install_name_tool - change libgs . dylib . $ dylib_version $ out/lib/libgs.dylib. $ dylib_version $ out/bin/gsx
2020-11-24 09:46:19 +00:00
'' ;
# validate dynamic linkage
doInstallCheck = true ;
installCheckPhase = ''
runHook preInstallCheck
$ out/bin/gs - - version
2023-06-25 20:14:56 +00:00
$ out/bin/gsx - - version
2021-09-11 18:07:58 +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-24 09:46:19 +00:00
runHook postInstallCheck
2016-01-05 15:04:33 +00:00
'' ;
2023-04-11 22:53:49 +00:00
passthru . tests = {
test-corpus-render = callPackage ./test-corpus-render.nix { } ;
inherit graphicsmagick imagemagick libspectre lilypond pstoedit ;
inherit ( python3 . pkgs ) matplotlib ;
} ;
2021-09-12 12:13:19 +00:00
2014-11-05 02:26:53 +00:00
meta = {
2020-04-01 01:11:51 +00:00
homepage = " h t t p s : / / w w w . g h o s t s c r i p t . c o m / " ;
2014-11-05 02:26:53 +00:00
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-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 = " g s " ;
2014-11-05 02:26:53 +00:00
} ;
2005-04-29 13:23:15 +00:00
}