# $Id: Portfile 75159 2011-01-17 02:00:53Z rmstonecipher@macports.org $

PortSystem          1.0

name                espgs
version             7.07.1
revision            4
categories          print textproc
platforms           darwin
maintainers         nomaintainer
description         Interpreter for PostScript and PDF
long_description    Easy Software Products now produces maintenance updates \
                    of GNU Ghostscript under the name ESP Ghostscript. These \
                    updates incorporate bug fixes to the current GNU version \
                    of Ghostscript as well as the latest CUPS, GIMP-print, \
                    and other add-ons to Ghostscript.

homepage            http://www.cups.org/ghostscript.php
master_sites        sourceforge \
                    http://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/fonts/:fonts \
                    http://www.ijg.org/files/:jpeg \
                    sourceforge:libpng:libpng
distname            ${name}-${version}-source
set std_fonts       ghostscript-fonts-std-8.11
set other_fonts     ghostscript-fonts-other-6.0
set png_src         libpng-1.2.8
distfiles           ${distname}${extract.suffix} \
                    ${std_fonts}${extract.suffix}:fonts \
                    ${other_fonts}${extract.suffix}:fonts \
                    ${png_src}${extract.suffix}:libpng
checksums           ${name}-${version}-source${extract.suffix} md5 20dfdc45c3aeb9893b75d41087f828d9 \
                    ${std_fonts}${extract.suffix} md5 6865682b095f8c4500c54b285ff05ef6 \
                    ${other_fonts}${extract.suffix} md5 1a643ae62ef166562e4d422b1a601272 \
                    ${png_src}${extract.suffix} md5 cac1512878fb98f2456df6dc50bc9bc7
worksrcdir          ${name}-${version}

depends_lib         port:jpeg \
                    port:libpng \
                    port:zlib

# Should be depends_extract, but that isn't implemented
# To understand why doing this, please check official document:
# http://www.ghostscript.com/doc/AFPL/8.00/Make.htm#Third-party_libraries
post-extract {
    system "cd ${workpath}; mv ${png_src} ${worksrcdir}/libpng"
}

configure.args      --without-gimp-print \
                    --disable-cups \
                    --mandir=${prefix}/share/man \
                    --with-fontpath="${prefix}/share/ghostscript/fonts:/usr/share/ghostscript/fonts"

pre-build {
    # Ensure the macports include/ directory is added. Don't know why
    # configure doesn't do this already.
    set search {CFLAGS=-O2 $(GCFLAGS) $(XCFLAGS) $(ACDEFS)}
    reinplace "s|${search}|${search} -I${prefix}/include|g" \
        ${worksrcpath}/Makefile
}

build.target
destroot.destdir    prefix=${destroot}${prefix} datadir=${destroot}${prefix}/share

post-destroot {
    system "mkdir -p ${destroot}${prefix}/share/ghostscript/"
    system "cd ${workpath} && \
            tar -cf - fonts | \
            tar -xf - -C ${destroot}${prefix}/share/ghostscript/"
}

variant x11 {
    depends_lib-append      port:xorg-libXext port:xorg-libXt
    configure.args-append   --with-x
}

# Their Makefile.in is busted
configure.cflags-append ${configure.cppflags}

