# $Id: Portfile 79564 2011-06-18 09:52:00Z jwa@macports.org $

PortSystem 1.0

name		couchdb
version		1.1.0

categories	databases
platforms	darwin

description	CouchDB is a document database server
maintainers	jwa
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/
master_sites	apache
master_sites.mirror_subdir	${name}/${version}/
distname	apache-${name}-${version}

checksums           md5     907b763d3a14b6649bf0371ffa75a36b \
                    sha1    7cb6a12f3becaae4eeb8ee75b15fbe6395fa7a98 \
                    rmd160  4dcb5c520b0402366e82a1c195fc4404bc7bd37d

depends_lib	port:automake \
    port:autoconf \
    port:libtool \
    port:help2man \
    port:icu \
    port:spidermonkey \
    port:curl \
    port:erlang

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

# erlang is not universal
universal_variant   no

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

post-destroot {
    addgroup ${dbgroup}
    adduser ${dbuser} gid=[existsgroup ${dbgroup}]
    xinstall -m 755 -o ${dbuser} -g ${dbgroup} -d \
	${destroot}${dbdir} \
	${destroot}${logdir} \
	${destroot}${plistdir}
    destroot.keepdirs-append \
        ${destroot}${dbdir} \
        ${destroot}${logdir}
    system "cd ${destroot}${plistdir} && ln -sf ${prefix}${plistdir}/${plist}"
# the following patches can be removed after next version
    reinplace "s;`${prefix}/bin/icu-config --invoke`;;" ${destroot}${prefix}/bin/couchdb
    reinplace "s;^.*DYLD_LIBRARY_PATH.*$;;g" ${destroot}${prefix}${plistdir}/${plist}
}

post-activate {
    ui_msg "########################################################################"
    ui_msg "# Run the following command to install the CouchDB launchd"
    ui_msg "# startup item in order to start and re-start service automatically:"
    ui_msg "#"
    ui_msg "# sudo launchctl load -w ${plistdir}/${plist}"
    ui_msg "########################################################################"
}

notes "couchdb requires erlang to be installed with ssl support (+ssl)"

livecheck.type	regex
livecheck.url	http://couchdb.apache.org/downloads.html
livecheck.regex	apache-${name}-(\[0-9.\]+\[0-9\]+)
