# $Id: Portfile 92284 2012-04-23 23:50:24Z jeremyhu@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            ghostscript
version         9.05
revision        2
categories      print
license         GPL-3+
maintainers     takanori openmaintainer
description     GPL Ghostscript, An interpreter for PostScript and PDF
long_description \
                Ghostscript is the well-known PostScript interpreter which \
                is available for all common and most esoteric platforms and \
                supports many different printers and some displays.
platforms       darwin
homepage        http://www.cs.wisc.edu/~ghost/
master_sites    http://downloads.ghostscript.com/public/:source \
                sourceforge:gs-fonts:fonts \
                sourceforge:mapping-for-pdf.adobe:misc
set mrversion   20091116
distfiles       ${distname}.tar.gz:source \
                ghostscript-fonts-other-6.0.tar.gz:fonts \
                mappingresources4pdf_2unicode_${mrversion}.tar.Z:misc \
                mappingresources4pdf_other_${mrversion}.tar.Z:misc
patchfiles      patch-base_unix-dll.mak.diff \
                patch-base_stdpre.h.diff \
                patch-base_unixinst.mak.diff
#               patch-base_gsgcache.c.diff \
#               patch-base_gsgdata.c.diff \
#               patch-base_gsgdata.h.diff
#               patch-configure.ac.diff

checksums           ${distname}.tar.gz \
                    md5     f7c6f0431ca8d44ee132a55d583212c1 \
                    sha1    af93787ba966360abbe085b213ec563b5db5a8cc \
                    rmd160  8635300e684513f4b8d1f708869efeae27393514 \
                    ghostscript-fonts-other-6.0.tar.gz \
                    md5     1a643ae62ef166562e4d422b1a601272 \
                    sha1    da62dfcb9c10d96743c7e30c1eebe7166489798c \
                    rmd160  ab60dbf71e7d91283a106c3df381cadfe173082f \
                    mappingresources4pdf_2unicode_${mrversion}.tar.Z \
                    md5     59267a7d0b818267c8ce85d1dbc4479a \
                    sha1    aaf44cb1e5dd2043c932e641b0e41432aee2ca0d \
                    rmd160  bc1b86e6a5f0e022f88070195eb3e01e167114a7 \
                    mappingresources4pdf_other_${mrversion}.tar.Z \
                    md5     202fa0a291fc1f5b50cfa239106c1b92 \
                    sha1    fc4eabff932c1623f7ee0a34085e79a44d51d0e5 \
                    rmd160  1e2ea9af6be8b60c9a54963e542fa06ceb2daccd

depends_lib     port:expat \
                port:fontconfig \
                port:freetype \
                port:jbig2dec \
                port:jpeg \
                port:lcms2 \
                port:libiconv \
                port:libidn \
                port:libpaper \
                port:libpng \
                port:perl5 \
                port:tiff \
                port:xorg-libXext \
                port:xorg-libXt \
                port:zlib
#               port:ijs

depends_build   port:pkgconfig

post-extract {
    foreach d {jbig2dec jpeg lcms2 libpng tiff zlib} {
        move "${worksrcpath}/${d}" "${worksrcpath}/${d}_local"
    }

    move ${workpath}/MappingOther/Adobe-CNS1-ETen-B5 ${workpath}/MappingOther/Adobe-CNS1-ETenms-B5
    eval copy -force [glob ${workpath}/ToUnicode/*]    ${worksrcpath}/Resource/CMap
    eval copy -force [glob ${workpath}/MappingOther/*] ${worksrcpath}/Resource/CMap
}

post-patch {
    reinplace "s|__PREFIX__|${prefix}|" ${worksrcpath}/base/unix-dll.mak

    # Ensure that MacPorts perl is used
    fs-traverse f ${worksrcpath} {
        if [string match "*.pl" ${f}] {
            reinplace "s|#!/usr/bin/perl|#!${prefix}/bin/perl|" ${f}
        }
    }
}

use_autoreconf yes
autoreconf.args -fv

# Make included OpenJPEG uses its own headers rather than the system ones
configure.cppflags-delete       "-I${prefix}/include"
configure.cppflags-append       "-isystem${prefix}/include"

configure.args  --disable-compile-inits \
                --disable-cups \
                --disable-gtk \
                --without-luratech \
                --with-system-libtiff

build.target        so
use_parallel_build  yes

destroot.target     soinstall
post-destroot {
    system "strip ${destroot}${prefix}/bin/gsc ${destroot}${prefix}/bin/gsx"
    ln -s gsc ${destroot}${prefix}/bin/gs

    xinstall -m 755 -d ${destroot}${prefix}/share/${name}/fonts
    foreach f {*.afm *.gsf *.pfa *.pfm} {
        eval xinstall -m 644 [glob ${workpath}/fonts/${f}] ${destroot}${prefix}/share/${name}/fonts
    }

    xinstall -m 755 -d ${destroot}${prefix}/share/doc
    ln -s ../${name}/${version}/doc ${destroot}${prefix}/share/doc/${name}
}

configure.universal_args-delete --disable-dependency-tracking

variant no_x11 {
    depends_lib-delete port:xorg-libXext
    depends_lib-delete port:xorg-libXt
    configure.args-append --without-x
}

variant cups description {Enable CUPS driver} {
    configure.args-delete --disable-cups
    configure.args-append --enable-cups
}

livecheck.type  regex
livecheck.url   http://downloads.ghostscript.com/public/
livecheck.regex ${name}-(\\d+(?:\\.\\d+)*)
