# $Id: Portfile 50750 2009-05-08 19:38:12Z and.damore@macports.org $

PortSystem 1.0

name         xpdf
version      3.02
revision     5
description  Xpdf is a viewer for PDF files.
long_description \
    Xpdf is a viewer for Portable Document Format \
    (PDF) files.  These are also sometimes also called \
    Acrobat files, from the name of Adobes PDF software.

maintainers    ricci openmaintainer
categories   graphics print
platforms    darwin
homepage     http://www.foolabs.com/xpdf/

master_sites \
    ftp://ftp.funet.fi/pub/TeX/CTAN/support/xpdf/ \
    ftp://ctan.unsw.edu.au/tex-archive/support/xpdf/ \
    ftp://ftp.tex.ac.uk/tex-archive/support/xpdf/ \
    ftp://ftp.kddlabs.co.jp/CTAN/support/xpdf/ \
    ftp://ftp.meiji.ac.jp/pub/TeX/CTAN/support/xpdf/ \
    ftp://ctan.tug.org/tex-archive/support/xpdf/ \
    ftp://ftp.dante.de/tex-archive/support/xpdf/ \
    ftp://gd.tuwien.ac.at/publishing/tex/CTAN/support/xpdf/ \
    ftp://ftp.ntnu.no/pub/tex/CTAN/support/xpdf/ \
    ftp://www.dnsbalance.ring.gr.jp/pub/text/CTAN/support/xpdf/ \
    http://www.t.ring.gr.jp/archives/text/CTAN/support/xpdf/ \
    ftp://ftp.chg.ru/pub/TeX/CTAN/support/xpdf/ \
    ftp://ftp.foolabs.com/pub/xpdf/

## checksums    md5 599dc4cc65a07ee868cf92a667a913d2

set xpdfmain ${distname}${extract.suffix}
distfiles    ${xpdfmain}	\
             xpdf-${version}pl1.patch	\
             xpdf-${version}pl2.patch	\
             xpdf-${version}pl3.patch

checksums           xpdf-${version}.tar.gz \
                    md5     599dc4cc65a07ee868cf92a667a913d2 \
                    sha1    f9940698840c8a8045677e8be68ab8580903e20a \
                    rmd160  e900cb8670b8c430beaa45895fb474411cb1958d \
                    xpdf-${version}pl1.patch \
                    md5     877118786dfe27d1b7aa5a6759cc6e45 \
                    sha1    cd3c8ed6e1fd3606098b85d5cc8a7d1aa305266d \
                    rmd160  5c310f96760f72e9c1062b00c57c2ed035ac6757 \
                    xpdf-${version}pl2.patch \
                    md5     3a5cb165ae66781e0b21e6219ae06795 \
                    sha1    d082ebe0d36cad0c04603950216f5c52de1c2593 \
                    rmd160  0024e3d203d69e073a458570cec5679e260ad204 \
                    xpdf-${version}pl3.patch \
                    md5     581963ede0fb5715e1a69f01b5b8ce63 \
                    sha1    23f496804802a3da530f1d0bab894bae3e938fc2 \
                    rmd160  859ec3131d3c4526a6075ee639c5eb704194211b

extract.only ${xpdfmain}

depends_lib \
	port:xorg-libXp port:xpm port:xorg-libXt port:freetype \
	port:libpaper lib:libXm:openmotif port:t1lib

depends_run  path:share/ghostscript/fonts:ghostscript

patchfiles   xpdf-${version}-salvage-your-eye.patch \
             patch-xpdf-NameToUnicodeTable.h.diff \
             patch-xpdf-UnicodeMapTables.h.diff


pre-patch {
			system "cd ${workpath} && patch -p0 < ${distpath}/xpdf-${version}pl1.patch"
			system "cd ${workpath} && patch -p0 < ${distpath}/xpdf-${version}pl2.patch"
			system "cd ${workpath} && patch -p0 < ${distpath}/xpdf-${version}pl3.patch"
}

post-patch {
    reinplace "s|/usr/local|${prefix}|g" \
        ${worksrcpath}/doc/sample-xpdfrc ${worksrcpath}/xpdf/GlobalParams.cc
}

configure.args	\
    --with-x \
    --mandir=${prefix}/share/man \
    --with-appdef-dir=${prefix}/etc/X11/app-defaults \
    --with-Xp-library=${prefix}/lib \
    --with-Xp-includes=${prefix}/include \
    --with-Xt-library=${prefix}/lib \
    --with-Xt-includes=${prefix}/include \
    --with-Xm-library=${prefix}/lib \
    --with-Xm-includes=${prefix}/include \
    --with-t1-library=${prefix}/lib \
    --with-t1-includes=${prefix}/include \
    --with-libpaper-library=${prefix}/lib \
    --with-libpaper-includes=${prefix}/include \
    --with-freetype2-library=${prefix}/lib \
    --with-freetype2-includes=${prefix}/include/freetype2 \
    --enable-wordlist \
    --enable-opi
configure.cxxflags-append "-I${prefix}/include/freetype2 -I${prefix}/include"
configure.ldflags-append "-lz"

variant a4 description {Use A4 as the default paper size instead of Letter} {
    configure.args-append --enable-a4-paper
}

variant with_poppler description {Add Poppler support} {
	depends_run-append port:poppler
	post-destroot {
		foreach i { pdffonts pdfimages pdfinfo pdftoppm pdftops pdftotext } {
			delete ${destroot}${prefix}/bin/${i}
			delete ${destroot}${prefix}/share/man/man1/${i}.1
		}
	}
}

platform puredarwin {
    depends_lib-delete lib:libXm:openmotif
    depends_lib-append port:lesstif
    configure.args-delete \
        --with-Xp-library=${prefix}/lib \
        --with-Xp-includes=${prefix}/include \
        --with-Xt-library=${prefix}/lib \
        --with-Xt-includes=${prefix}/include \
        --with-Xm-library=${prefix}/lib \
        --with-Xm-includes=${prefix}/include
}

variant drm description {Obey access restrictions in PDF files} {
    patchfiles-delete xpdf-${version}-salvage-your-eye.patch
}

post-install {
    ui_msg " \
        Xpdf language support packages are also available at \
        http://www.foolabs.com/xpdf/download.html"
}

