# -*- 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                            graphviz-oldgui
conflicts                       graphviz-gui graphviz-gui-devel
version                         16
revision                        0
checksums                       rmd160  35eac7c7013bddc0d1f107fcaf8e9c7d1e078231 \
                                sha256  f21cf94bb9c8248e7926ef645135b33afa18d2d3742bf4af3b76b607604d0947 \
                                size    1253850

categories                      graphics
maintainers                     {ryandesign @ryandesign}
homepage                        http://www.pixelglow.com/graphviz/
master_sites                    http://www.pixelglow.com/downloads/
platforms                       macosx
use_parallel_build              no
dist_subdir                     graphviz
distname                        graphviz-1.13-v${version}
worksrcdir                      Graphviz 1.13 (v${version})
extract.suffix                  .tgz
universal_variant               no
installs_libs                   no
supported_archs                 ppc

description                     Mac OS X Aqua GUI for viewing and exporting \
                                Graphviz graphs

long_description                ${description}.

depends_build                   port:pkgconfig \
                                port:libiconv

depends_lib                     path:bin/dot:graphviz

depends_skip_archcheck          graphviz \
                                libiconv

pre-configure {
    if {${os.major} >= 9} {
        set newport graphviz-gui
        if {[expr [lindex [split [exec ${prefix}/bin/pkg-config --modversion libgvc] .] 1] % 2]} {
            set newport graphviz-gui-devel
        }
        ui_msg "Consider installing ${newport} instead of ${name}."
    }
}

post-extract {
    # The frameworks are v1.13 frameworks that aren't applicable anymore.
    delete ${worksrcpath}/Graphviz.app/Contents/Frameworks
    # Remove the .DS_Store files that we don't really want to install.
    fs-traverse item [list ${worksrcpath}] {
        if {[file tail ${item}] eq ".DS_Store" && [file isfile ${item}]} {
            delete ${item}
        }
    }
    # Convert the strings from UTF-16 to UTF-8 so that we can patch them.
    system -W ${worksrcpath}/Graphviz.app/Contents/Resources/English.lproj "${prefix}/bin/iconv -f utf-16 -t utf-8 InfoPlist.strings > InfoPlist.strings.utf8"
}

patchfiles                      patch-version.diff \
                                patch-gv-extension.diff

post-patch {
    # Convert the strings back to UTF-16 which is what Mac OS X expects.
    system -W ${worksrcpath}/Graphviz.app/Contents/Resources/English.lproj "${prefix}/bin/iconv -f utf-8 -t utf-16 InfoPlist.strings.utf8 > InfoPlist.strings"
    delete ${worksrcpath}/Graphviz.app/Contents/Resources/English.lproj/InfoPlist.strings.utf8
}

use_configure                   no

build {
    # Replace the v1.13 executables with symlinks to a wrapper script that
    # calls the new executables in ${prefix}/bin. The wrapper is necessary
    # to emulate the -Tepdf option which was specific to Pixelglow's fork.
    set dispatcher graphviz-dispatcher.php
    set macospath ${worksrcpath}/Graphviz.app/Contents/MacOS
    xinstall -m 755 ${filespath}/${dispatcher}.in ${macospath}/${dispatcher}
    reinplace "s%@PREFIX@%${prefix}%g" ${macospath}/${dispatcher}
    foreach prog {acyclic bcomps ccomps circo cvtgxl dijkstra dot gc gvcolor gvpack gvpr neato nop sccmap tred twopi unflatten} {
        delete ${macospath}/${prog}
        ln -s ${dispatcher} ${macospath}/${prog}
    }
}

destroot {
    set apppath ${destroot}${applications_dir}
    xinstall -d ${apppath}
    copy ${worksrcpath}/Graphviz.app ${apppath}
}

livecheck.type                  none
