# -*- 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 116547 2014-01-28 11:11:04Z ciserlohn@macports.org $

PortSystem          1.0

name                fossil
version             1.28
epoch               20110901182519
categories          devel
platforms           darwin
license             BSD
maintainers         ciserlohn

description         Simple, high-reliability, distributed software configuration management

long_description    Fossil is a distributed software configuration management which supports \
                    distributed version control, distributed bug tracking, distributed wiki, \
                    and a distributed blog mechanism all in single integrated package. It provides \
                    an easy-to-use web interface to access and administrate projects over the \
                    built-in webserver or CGI.

homepage            http://www.fossil-scm.org/

master_sites        ${homepage}download/
distname            ${name}-src-20140127173344

checksums           rmd160  1997925a7b596cca864de571648363855a4bb08b \
                    sha256  aca7c5a7c39ae2880712020e089c9c12543ba656c71d8cf8ac50e3c8871baa80

test.run            yes

depends_lib         port:tcl \
                    port:zlib \
                    port:openssl \
                    port:libiconv

configure.args-append       --disable-lineedit \
                            --with-tcl=${prefix}/lib

configure.env-append CC_FOR_BUILD="${configure.cc} [get_canonical_archflags]"

configure.ldflags-append    -liconv

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        COPYRIGHT-BSD2.txt \
        ${docdir}
}

post-activate {
    
    if [file exists $::env(HOME)/.fossil] {
        ui_msg "* Trying to rebuild known repositories:" 

        set exec_cmd exec
        set fossil_list {fossil all list}
        set fossil_rebuild {fossil rebuild}

        if [catch {eval $exec_cmd $fossil_list} repositories] {
            ui_error "failed to execute $fossil_list"
        }

        if [llength $repositories] {
            foreach repo $repositories {
                if {![catch {eval $exec_cmd $fossil_rebuild $repo} result]} {
                    ui_msg "* successfully rebuild $repo"
                } else {
                    ui_msg "* failed to rebuild $repo"
                }
            }
        } else {
            ui_msg "* No repositories found"
        }

        ui_msg "* Finished rebuilding repositories"
    }
}

variant readline description {Enable readline support for the embedded sqlite shell in the 'fossil sqlite3' command} {
    depends_lib-append      port:readline
    configure.args-delete   --disable-lineedit
}

notes "
It is recommended to rebuild repositories created with earlier versions of\
fossil. To rebuild a repository run:

fossil rebuild /<path>/<to>/<repository>

Rebuilding a repository is a safe operation\; executing it more then once will\
not harm the integrity of a repository.
"

livecheck.type      regex
livecheck.url       ${homepage}/download.html
livecheck.regex     {Version ([\d.]*)}
