easyblock = 'ConfigureMake'

name = 'Ghostscript'
version = '9.53.3'

homepage = 'https://ghostscript.com'
description = """Ghostscript is a versatile processor for PostScript data with the ability to render PostScript to
 different targets. It used to be part of the cups printing stack, but is no longer used for that."""

toolchain = {'name': 'GCCcore', 'version': '10.2.0'}
toolchainopts = {'pic': True}

source_urls = [
    'https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs%s/' % version.replace('.', ''),
]
sources = [SOURCELOWER_TAR_GZ]
patches = ['Ghostscript-9.53.3_fix-freetype-callback.patch']
checksums = [
    '6eaf422f26a81854a230b80fd18aaef7e8d94d661485bd2e97e695b9dce7bf7f',  # ghostscript-9.53.3.tar.gz
    # Ghostscript-9.53.3_fix-freetype-callback.patch
    'c539e6c9e1ddaeee132e12265a6918eb6c4c71aec20e8c0e7b703159c13dc12f',
]

dependencies = [
    ('zlib', '1.2.11'),
    ('libpng', '1.6.37'),
    ('freetype', '2.10.3'),
    ('libjpeg-turbo', '2.0.5'),
    ('expat', '2.2.9'),
    ('GLib', '2.66.1'),
    ('cairo', '1.16.0'),
    ('LibTIFF', '4.1.0'),
]

builddependencies = [
    # use same binutils version that was used when building GCCcore toolchain
    ('binutils', '2.35'),
    ('pkg-config', '0.29.2'),
]

# Do not use local copies of zlib, jpeg, freetype, and png
preconfigopts = "mv zlib zlib.no && mv jpeg jpeg.no && mv freetype freetype.no && mv libpng libpng.no && "
preconfigopts += 'export LIBS="$LIBS -L$EBROOTZLIB/lib -lz" && '

configopts = "--with-system-libtiff --enable-dynamic"

postinstallcmds = [
    # build and install shared libs
    "make so && make soinstall",
    # install header files
    "mkdir -p %(installdir)s/include/ghostscript",
    "install -v -m644 base/*.h %(installdir)s/include/ghostscript",
    "install -v -m644 psi/*.h %(installdir)s/include/ghostscript",
]

sanity_check_paths = {
    'files': ['bin/gs', 'lib/libgs.%s' % SHLIB_EXT],
    'dirs': ['lib/ghostscript', 'include/ghostscript', 'share/man'],
}

moduleclass = 'tools'
