# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 83993 2011-09-14 17:54:18Z mww@macports.org $

PortSystem              1.0

name                    pdftk
version                 1.44
categories              textproc graphics pdf
maintainers             ryandesign
platforms               darwin
homepage                http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
master_sites            ${homepage}
use_zip                 yes
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               sha1    7cb137dcba885caff32ff96b7e11c9dc4ce2cba7 \
                        rmd160  cacd286759005f002f5a46c0af28d3a1aaad73eb

distname                ${name}-${version}-src
worksrcdir              ${name}-${version}-dist

depends_lib \
    port:libiconv

build.dir               ${worksrcpath}/${name}

patchfiles              patch-Makefile.OSX-10.6.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${build.dir}/Makefile.OSX-10.6
}

set versuff ""

pre-configure {
    if {![file exists ${prefix}/bin/gcj${versuff}]} {
        return -code error "

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

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

pre-build {
    build.args-append   VERSUFF=${versuff}
}

build.args-append       -f Makefile.OSX-10.6

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

variant with_gcc42 requires gcc42 description {Deprecated synonym for gcc42} {}
variant gcc42 conflicts gcc45 description {Build using gcc42} {
    patchfiles-append   patch-gcj-4.2-and-older.diff
    configure.compiler  macports-gcc-4.2
    depends_build-append port:fastjar
    depends_lib-append  port:gcc42
    set versuff         -mp-4.2
}

variant gcc45 conflicts gcc42 description {Build using gcc45} {
    configure.compiler  macports-gcc-4.5
    depends_lib-append  port:gcc45
    set versuff         -mp-4.5
}

if {![variant_isset gcc42] && ![variant_isset gcc45]} {
    if {${os.platform} == "darwin" && ${os.major} < 10} {
        default_variants    +gcc42
    } else {
        default_variants    +gcc45
    }
}
