# $Id$

PortSystem 1.0

name         xpdf
conflicts    pdf2json
version      3.04
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    nomaintainer
categories   graphics print
license      {GPL-2 GPL-3}
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           ${distfiles} \
                    rmd160  fb29aad21054d5d3b349aec4806262feeca1bd8e \
                    sha256  11390c74733abcb262aaca4db68710f13ffffd42bfe2a0861a5dfc912b2977e5

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

variant drm description {Obey access restrictions in PDF files} {}
if {![variant_isset drm]} {
    patchfiles-append ${distname}-salvage-your-eye.patch
}

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

# t1lib support should not be on by default; 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 { pdfdetach 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 language support packages are also available at 
	http://www.foolabs.com/xpdf/download.html
and are available in MacPorts as xpdf-LANG_NAME.
"