# -*- 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 106554 2013-05-30 23:03:55Z cal@macports.org $

PortSystem              1.0
PortGroup               active_variants 1.1

name                    couchdb-devel
conflicts               couchdb
version                 1.4.0a-20130330
revision                1

categories              databases
platforms               darwin

description             CouchDB is a document database server
maintainers             jsnider.net:jeff \
                        openmaintainer
long_description        ${description} with a restful HTTP API, capable of \
                        storing arbitrary JSON documents, building powerful data views, \
                        defined in JavaScript, and processed in parallel using Map/Reduce. \
                        It leaves out SQL and transactions for simplicity's sake, to \
                        improve scalability and to relax users' lives.
homepage                http://couchdb.apache.org/
license                 Apache-2

fetch.type              git
git.url                 https://git-wip-us.apache.org/repos/asf/couchdb.git
git.branch              97505126c90469e7588272d0eec451b93159cd9a

depends_build           port:automake \
                        port:autoconf \
                        port:libtool \
                        port:help2man \
                        port:pkgconfig \
                        port:autoconf-archive

depends_lib             port:icu \
                        port:spidermonkey \
                        port:erlang \
                        port:curl

# erlang is not universal
universal_variant       no

patchfiles              patch-automake-1.13.diff \
                        patch-etc-launchd-org.apache.couchdb.plist.tpl.in.diff \
                        patch-src-couchdb-priv-Makefile.am.diff \
                        patch-parameterized-modules-r16b-bug.38395.patch

require_active_variants erlang ssl

pre-configure {
    system "cd ${worksrcpath}; ./bootstrap"
}

configure.args          --with-js-include=${prefix}/include/js \
                        --with-erlang=${prefix}/lib/erlang/usr/include \
                        --enable-js-trunk

set dbgroup             couchdb
set dbuser              couchdb
set logdir              ${prefix}/var/log/couchdb
set dbdir               ${prefix}/var/lib/couchdb
set confdir             ${prefix}/etc/couchdb
set rundir              ${prefix}/var/run/couchdb
set plistdir            /Library/LaunchDaemons
startupitem.uniquename  org.apache.couchdb
set plist               ${startupitem.uniquename}.plist

add_users               ${dbuser} group=${dbgroup}

post-destroot {
    move ${destroot}${confdir}/local.ini ${destroot}${confdir}/local.ini.sample
    xinstall -m 755 -o ${dbuser} -g ${dbgroup} -d \
        ${destroot}${dbdir} \
        ${destroot}${logdir} \
        ${destroot}${plistdir} \
        ${destroot}${rundir}
    destroot.keepdirs-append \
        ${destroot}${dbdir} \
        ${destroot}${logdir} \
        ${destroot}${rundir}
    system "cd ${destroot}${plistdir} && ln -sf ${prefix}${plistdir}/${plist}"
}

post-activate {
    if {![file exists ${confdir}/local.ini]} {
        xinstall -m 640 -o ${dbuser} -g ${dbgroup} ${confdir}/local.ini.sample ${confdir}/local.ini
    }
}


notes "
Run the following command to load the CouchDB launchd plist\
in order to start the service now and at system startup:

sudo port load couchdb
"

livecheck.type          regex
livecheck.url           "https://git-wip-us.apache.org/repos/asf?p=couchdb.git;a=commit;h=refs/heads/master"
livecheck.version       ${git.branch}
livecheck.regex         <tr><td>commit</td><td class="sha1">(\[a-f0-9\]{40})</td></tr>


