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
2024-10-11 05:15:48 +00:00
, fixDarwinDylibNames
2024-09-26 11:04:55 +00:00
, cupsSupport ? config . ghostscript . cups or ( ! stdenv . hostPlatform . isDarwin )
2023-04-29 16:46:19 +00:00
, 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 " ;
2024-06-20 14:57:18 +00:00
hash = " s h a 2 5 6 - D r b z V h G f L k m y V j I Q h S 4 X 9 X + d z F d V 8 1 C m m k a g 1 k G g x A E = " ;
2020-04-24 23:36:52 +00:00
} )
( 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 " ;
2024-06-20 14:57:18 +00:00
hash = " s h a 2 5 6 - g U b M z E a Z / p 2 r h B R G v d F w O f R 2 n J A + z r V E C R i L k g d U q r M = " ;
2020-04-24 23:36:52 +00:00
} )
# ... 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 " } " ;
2024-10-11 05:15:48 +00:00
version = " 1 0 . 0 4 . 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 " ;
2024-10-11 05:15:48 +00:00
hash = " s h a 2 5 6 - U n 7 v C 2 z Q T s 8 c j X o R e W x p p S 0 0 / + N q / K h q Q A c p o v w B y I c = " ;
2020-04-24 23:36:52 +00:00
} ;
patches = [
./urw-font-files.patch
./doc-no-ref.diff
] ;
2024-07-27 06:49:29 +00:00
outputs = [ " o u t " " m a n " " d o c " " f o n t s " ] ;
2020-04-24 23:36:52 +00:00
enableParallelBuilding = true ;
2021-12-06 16:07:01 +00:00
depsBuildBuild = [
buildPackages . stdenv . cc
] ;
nativeBuildInputs = [ pkg-config autoconf zlib ]
2024-10-11 05:15:48 +00:00
++ lib . optional cupsSupport cups
++ lib . optional stdenv . hostPlatform . isDarwin fixDarwinDylibNames ;
2021-12-06 16:07:01 +00:00
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)
2024-09-26 11:04:55 +00:00
++ lib . optional ( x11Support && stdenv . hostPlatform . 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 } "
2024-07-27 06:49:29 +00:00
mkdir - p $ fonts/share/fonts
cp - rv $ { fonts } /* " $ f o n t s / s h a r e / f o n t s / "
ln - s " $ f o n t s / s h a r e / f o n t s " " $ o u t / s h a r e / g h o s t s c r i p t / f o n t s "
2020-04-24 23:36:52 +00:00
'' ;
2024-10-11 05:15:48 +00:00
# dynamic library name only contains major version number, eg. '10'
dylib_version = lib . versions . major version ;
2024-09-26 11:04:55 +00:00
preFixup = lib . optionalString stdenv . hostPlatform . isDarwin ''
2024-10-11 05:15:48 +00:00
for file in $ out/bin / { gs , gsc , gsx } ; do
install_name_tool - change libgs . $ dylib_version . dylib $ out/lib/libgs. $ dylib_version . dylib $ file
done
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 .
'' ;
2024-04-21 15:54:59 +00:00
license = lib . licenses . agpl3Plus ;
2021-01-17 00:15:33 +00:00
platforms = lib . platforms . all ;
2024-09-19 14:19:46 +00:00
maintainers = [ lib . maintainers . tobim ] ;
2021-10-14 00:43:12 +00:00
mainProgram = " g s " ;
2020-04-24 23:36:52 +00:00
} ;
}