# -*- 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
PortGroup               active_variants 1.1

name                    webdot
version                 2.30
revision                6
categories              www graphics
maintainers             ryandesign
homepage                http://www.graphviz.org/
master_sites            ${homepage}pub/graphviz/stable/SOURCES/
platforms               darwin
use_parallel_build      yes
supported_archs         noarch

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               rmd160  7c3c493b889ed21676bbe72a0955449b0461903e \
                        sha256  f11567ae7a696b82c7d7d9f366827e641b2bc5a50695a3076b53e01b6902113e

depends_build           port:pkgconfig

depends_lib             path:bin/dot:graphviz

depends_run             port:ghostscript

require_active_variants path:bin/dot:graphviz tcl

set www_user www
if {${os.platform} eq "darwin" && ${os.major} >= 9} {
    set www_user _www
}
set www_group ${www_user}

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
}

post-configure {
    reinplace "/^HTTPD-USER-GROUP=/s|=.*$|=${www_user}:${www_group}|" ${worksrcpath}/Makefile
}

destroot.keepdirs ${destroot}${prefix}/var/cache/webdot

post-destroot {
    xinstall -d ${destroot}${prefix}/var/cache/webdot -o ${www_user} -g ${www_group}
}

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
