# $Id: Portfile 79059 2011-05-31 15:58:45Z ricci@macports.org $

PortSystem 1.0

name         xpdf
set base_version    3.02
version      ${base_version}pl5
revision     1
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/

distname     ${name}-${base_version}

checksums           ${distfiles} \
                    md5     599dc4cc65a07ee868cf92a667a913d2 \
                    sha1    f9940698840c8a8045677e8be68ab8580903e20a \
                    rmd160  e900cb8670b8c430beaa45895fb474411cb1958d \
                    ${distname}pl1.patch \
                    md5     877118786dfe27d1b7aa5a6759cc6e45 \
                    sha1    cd3c8ed6e1fd3606098b85d5cc8a7d1aa305266d \
                    rmd160  5c310f96760f72e9c1062b00c57c2ed035ac6757 \
                    ${distname}pl2.patch \
                    md5     3a5cb165ae66781e0b21e6219ae06795 \
                    sha1    d082ebe0d36cad0c04603950216f5c52de1c2593 \
                    rmd160  0024e3d203d69e073a458570cec5679e260ad204 \
                    ${distname}pl3.patch \
                    md5     581963ede0fb5715e1a69f01b5b8ce63 \
                    sha1    23f496804802a3da530f1d0bab894bae3e938fc2 \
                    rmd160  859ec3131d3c4526a6075ee639c5eb704194211b \
                    ${distname}pl4.patch \
                    md5     70b752716798dd341a4bf890df5f6fdc \
                    sha1    1aa3087a1c7882884ae7d3a502240a55acca65fd \
                    rmd160  428065e8c9639b6799705b216be603f52efb8a22 \
                    ${distname}pl5.patch \
                    md5     504902ca5e9d66c67eed03636ec6b163 \
                    sha1    0acd49e73bba47fa1ec7b479eb8f1398a33eabbc \
                    rmd160  f502a7c5311e935f3e4a5fd5b770b44e68c09a7a

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

depends_run  path:share/ghostscript/fonts:ghostscript

patch.post_args     -p1
patchfiles   ${distname}pl1.patch \
             ${distname}pl2.patch \
             ${distname}pl3.patch \
             ${distname}pl4.patch \
             ${distname}pl5.patch \
             ${distname}-salvage-your-eye.patch \
             patch-xpdf-NameToUnicodeTable.h.diff \
             patch-xpdf-UnicodeMapTables.h.diff

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-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
}

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
}

variant no_mangle_names description {do not mangle the CLI tool names, conflicts with poppler} {
	conflicts-append port:poppler
}

## make t1lib support a variant, see https://trac.macports.org/ticket/29629)
variant t1lib description {Include t1lib support (moved to variant due to security issue)} {
    depends_lib-append		port:t1lib
    configure.args-append	--with-t1-library=${prefix}/lib \
							--with-t1-includes=${prefix}/include \
}

post-destroot {
	if {! [variant_isset no_mangle_names]} {
		## rename the CLI tools to xpdf-${TOOL_NAME} to avoid conflicts with poppler
		foreach binFile { pdffonts pdfimages pdfinfo pdftoppm pdftops pdftotext } {
			move ${destroot}${prefix}/bin/${binFile}  ${destroot}${prefix}/bin/${name}-${binFile}
			move ${destroot}${prefix}/share/man/man1/${binFile}.1 ${destroot}${prefix}/share/man/man1/${name}-${binFile}.1
		}
	}
}

notes "
xpdf 3.02pl5 revision 1 (aka 'xpdf @3.02pl5_1') without +t1lib is xpdf 3.02pl6.
Xpdf language support packages are also available at 
	http://www.foolabs.com/xpdf/download.html
and are available in MacPorts as xpdf-LANG_NAME.
"
