# $Id: Portfile 66285 2010-04-08 08:09:09Z jmr@macports.org $

PortSystem              1.0

name                    pdftk
version                 1.41
revision                1
categories              textproc graphics pdf
maintainers             ryandesign
platforms               darwin
homepage                http://www.pdfhacks.com/pdftk/
master_sites            ${homepage}
use_bzip2               yes
worksrcdir              ${distname}/${name}
use_configure           no
universal_variant       no
use_parallel_build      no

description \
    pdftk - PDF Toolkit, for various operations on PDF files

long_description \
    pdftk is a simple tool for doing everyday things with PDF documents: \
    Merge PDF Documents \
    Split PDF Pages into a New Document \
    Decrypt Input as Necessary (Password Required) \
    Encrypt Output as Desired \
    Fill PDF Forms with FDF Data and/or Flatten Forms \
    Apply a Background Watermark \
    Report on PDF Metrics such as Metadata, Bookmarks, and Page Labels \
    Update PDF Metadata \
    Attach Files to PDF Pages or the PDF Document \
    Unpack PDF Attachments \
    Burst a PDF Document into Single Pages \
    Uncompress and Re-Compress Page Streams \
    Repair Corrupted PDF (Where Possible)

checksums \
    md5 7214230b937dc996d209c05b7b7b3518 \
    sha1 e5eb83dd96dbda68072efe8f2637aad59f50dffc

depends_lib \
    port:libiconv

set toolpath ${prefix}/bin/
set versuff ""

pre-fetch {
    if {![file exists ${toolpath}gcj${versuff}]} {
        return -code error "

Cannot build ${name} because ${toolpath}gcj${versuff}
is missing, possibly because of this gcc bug:

http://trac.macports.org/projects/macports/ticket/13553
"
    }
}

pre-build {
    reinplace "s|^\\(CPPFLAGS=\\)|\\1 ${configure.cppflags}|" ${worksrcpath}/Makefile.MacOSX
    reinplace "s|^\\(CXXFLAGS=\\)|\\1 ${configure.cxxflags} ${configure.ldflags}|" ${worksrcpath}/Makefile.MacOSX
    build.args-append   TOOLPATH=${toolpath} VERSUFF=${versuff}
}

build.args \
    -f Makefile.MacOSX

destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 755 -W ${worksrcpath} pdftk ${destroot}${prefix}/bin
    xinstall -m 644 -W ${worksrcpath}/.. pdftk.1.html pdftk.1.txt \
        ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath}/../debian pdftk.1 \
        ${destroot}${prefix}/share/man/man1
}

if {${os.arch} == "powerpc"} {
variant with_gcc41 conflicts with_gcc42 description {Build using gcc41 (PowerPC only)} {
    depends_lib-append  port:gcc41
    set versuff         -mp-4.1
}
}

variant with_gcc42 conflicts with_gcc41 description {Build using gcc42} {
    depends_lib-append  port:gcc42
    set versuff         -mp-4.2
}

if { (![variant_exists with_gcc41] || ![variant_isset with_gcc41]) && ![variant_isset with_gcc42] } {
    default_variants    +with_gcc42
}
