# -*- 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 107539 2013-07-02 17:37:01Z larryv@macports.org $

PortSystem              1.0
PortGroup               active_variants 1.1

name                    couchdb
conflicts               couchdb-devel
version                 1.3.1
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

master_sites            apache
master_sites.mirror_subdir ${name}/source/${version}/
distname                apache-${name}-${version}

checksums               rmd160  d79e08aa756365a0adfee1dd1922ed5d4c8006c7 \
                        sha256  e3051cb0be560513e0cb2d4fcb03a4cad4eda5bf381a115375d1067875ec8a6a

depends_build           port:help2man

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

# erlang is not universal
universal_variant       no

patchfiles              patch-etc-launchd-org.apache.couchdb.plist.tpl.in.diff \
                        patch-src-couchdb-priv-Makefile.in.diff \
                        patch-parameterized-modules-r16b-bug.38395.patch \
                        patch-r16b01-compatability.39607.patch

require_active_variants erlang ssl

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           http://couchdb.apache.org/downloads.html
livecheck.regex         apache-${name}-(\[0-9.\]+\[0-9\]+)
