# -*- 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 71090 2010-09-01 06:47:44Z ryandesign@macports.org $

PortSystem              1.0

name                    webdot
version                 2.26
categories              www graphics
maintainers             ryandesign
homepage                http://www.graphviz.org/
master_sites            ${homepage}pub/graphviz/stable/SOURCES/
platforms               darwin
use_parallel_build      yes
universal_variant       no

description             Graphviz web service

long_description        WebDot is a CGI program that converts a graph \
                        description from a Graphviz .dot or .gv file into \
                        an image that can be included on a web page

checksums               md5     62fe6a26adb3090a6b2ebd61b0684873 \
                        sha1    5139044040db383e362a13d6552100d90f9942fc \
                        rmd160  9d9669a420812dfcda8d9701eee474b1c88269ce

depends_build           port:pkgconfig

depends_lib             path:bin/dot:graphviz

depends_run             port:ghostscript

pre-configure {
    if {![file exists ${prefix}/lib/graphviz/tcl/libtcldot.dylib]} {
        set graphviz_port graphviz
        if {[expr [lindex [split [exec ${prefix}/bin/pkg-config --modversion libgvc] .] 1] % 2]} {
            set graphviz_port graphviz-devel
        }
        ui_msg "${name} requires that ${graphviz_port} first be installed with the +tcl variant."
        ui_msg "Rebuild ${graphviz_port} using:"
        ui_msg "    sudo port upgrade --enforce-variants ${graphviz_port} +tcl"
        return -code error "${graphviz_port} missing +tcl variant"
    }
}

post-configure {
    reinplace "/^CGI-BIN_DIR=/s|=.*$|=${cgi_bin}|" ${worksrcpath}/Makefile
    reinplace "/^HTML_DIR=/s|=.*$|=${html_dir}/|" ${worksrcpath}/Makefile
    reinplace "/^CACHE_DIR=/s|=.*$|=${prefix}/var/cache|" ${worksrcpath}/Makefile
    reinplace "/^TCLSH_EXECUTABLE=/s|=.*$|=${prefix}/bin/tclsh|" ${worksrcpath}/Makefile
    reinplace "/^LIBTCLDOT=/s|=.*$|=${prefix}/lib/graphviz/tcl/libtcldot.dylib|" ${worksrcpath}/Makefile
    reinplace "/^GS=/s|=.*$|=${prefix}/bin/gs|" ${worksrcpath}/Makefile
    reinplace "/^PS2EPSI=/s|=.*$|=${prefix}/bin/ps2epsi|" ${worksrcpath}/Makefile
}

platform darwin {
    post-configure {
        set www_user www
        if {${os.major} >= 9} {
            set www_user _www
        }
        reinplace "/^HTTPD-USER-GROUP=/s|=.*$|=${www_user}:${www_user}|" ${worksrcpath}/Makefile
    }
}

set www                 ${prefix}/www
set html_dir            ${www}/htdocs
set cgi_bin             ${www}/cgi-bin

variant apache_apple description {Install file in Apple's web server directories instead} {
    set www             /Library/WebServer
    set html_dir        ${www}/Documents
    set cgi_bin         ${www}/CGI-Executables
}

livecheck.type          regex
livecheck.url           ${homepage}Download_source.php
livecheck.regex         ${name}-(\[0-9\]+\\.\[0-9\]*\[02468\](\\.\[0-9\]+)*)\\.tar
