# -*- 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

PortSystem          1.0

name                abiword
version             2.4.5
revision            1

categories          editors textproc aqua
license             GPL-3
maintainers         nomaintainer

description         A word processor with gnome support.
long_description    {*}${description}
homepage            http://www.abisource.com/

master_sites        http://www.abisource.org/downloads/abiword/${version}/source \
                    http://www.nl.abisource.org/downloads/abiword/${version}/source
use_bzip2           yes

checksums           rmd160  f0de27f97135f8fff9b4400b05d74a27eee348cd \
                    sha256  b8e5f61697c6d796e8f9f0812886666487fd0125bc777ca093c096b4b3e31264 \
                    size    24930028

if {![variant_isset use_source] && ${os.platform} eq "darwin" && ${os.major} <= 10} {
    default_variants +use_binary
} elseif {![variant_isset use_binary]} {
    default_variants +use_source
}

if {! [variant_isset use_binary] && ! [variant_isset use_source]} {
    error "Please select either +use_binary or +use_source"
}

variant use_binary conflicts use_source description {Use binary distribution} {
    supported_archs ppc
    distname        AbiWord-${version}-10.2
    extract.suffix  .dmg.gz
    use_bzip2       no
    master_sites    http://www.abisource.org/downloads/abiword/${version}/MacOSX \
                    http://www.nl.abisource.org/downloads/abiword/${version}/MacOSX \
                    http://os.cqu.edu.au/macosx/office/abiword

    checksums       rmd160  d39ea145eea4e08a908013d3d00da9c224e018d3 \
                    sha256  4d12c7b4b18008e8c6d913ae915a8b042dcd24aee13fdec6b55bf20c03a6f9ed \
                    size    9405828

    extract.post_args > ${workpath}/${distname}.dmg
    post-extract {
        file mkdir /tmp/${name}-${version}
        system "hdiutil attach ${workpath}/${distname}.dmg -private -nobrowse -mountpoint /tmp/${name}-${version}"
    }
    patchfiles
    use_configure    no
    build {}
    destroot {
        file mkdir ${destroot}${applications_dir}
        file copy /tmp/${name}-${version}/AbiWord.app ${destroot}${applications_dir}
    }
    post-destroot {
        system "hdiutil detach /tmp/${name}-${version}"
        file delete -force /tmp/${name}-${version}
    }
}

variant use_source description {Build from source} {
    known_fail  yes
    pre-fetch {
        ui_error "The ${name} port currently fails to build."
        ui_error "See: https://trac.macports.org/ticket/41534"
        error "Broken port"
    }

    #depends_build    \
    #    port:pkgconfig

    #depends_lib    \
    #    port:zlib \
    #    port:popt \
    #    port:libpng \
    #    port:fribidi \
    #    port:fontconfig \
    #    port:ImageMagick

    patchfiles    \
        configure.patch \
        abi-detect-platform.m4.patch \
        patch-wv-magick-png.c.diff

    configure.dir   ${worksrcpath}/abi

    build.dir       ${configure.dir}
    build.target

    configure.cppflags -I. -I${prefix}/include

    configure.args \
        --enable-Cocoa \
        --mandir=${prefix}/share/man \
        --with-zlib=${prefix} \
        --with-libpng=${prefix} \
        --with-popt=${prefix} \
        --without-epath \
        --disable-gnome
}
