File couchdb.spec of Package couchdb

#
# spec file for package couchdb 
#
# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# norootforbuild 

%define tarname apache-couchdb
%define couchdb_user couchdb
%define couchdb_group couchdb
%define couchdb_home %{_localstatedir}/lib/couchdb

%define xul_version 192
%define xul_pathext /

%if 0%{suse_version} == 1120
%define xul_version 191
%define xul_pathext /unstable
%endif
%if 0%{suse_version} == 1130
%define xul_version 192
%define xul_pathext /
%endif

Name:           couchdb
Version:        1.0.2
Release:        0.1
Summary:        A document database server, accessible via a RESTful JSON API

License:        ASL 2.0
Url:            http://couchdb.apache.org/
Group:          Productivity/File utilities
Source0:        http://www.apache.org/dist/%{name}/%{version}/%{tarname}-%{version}.tar.gz
Source1:        %{name}.init
# PATCH-FIX-UPSTREAM couchdb-mozjs-rpath.patch dimstar@opensuse.org -- couchdb does not honor mozjs' libflags from the .pc file.
Patch0:         couchdb-mozjs-rpath.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

BuildRequires:  erlang
BuildRequires:  help2man
BuildRequires:  libcurl-devel
BuildRequires:  libicu-devel
BuildRequires:  mozilla-xulrunner%{xul_version}-devel
BuildRequires:  pkgconfig

Requires:       erlang
#Requires:       %{_bindir}/icu-config
#Requires:       libicu-devel

# Require the proper mozilla-js (do not rely on the autoprovreq found libmozjs)
%if 0%{suse_version} < 1130
Requires:       mozilla-xulrunner%{xul_version}
%else
Requires:       mozilla-js%{xul_version}
%endif

#Initscripts
Requires(post): aaa_base
Requires(preun): aaa_base
#initscripts

# Users and groups
Requires(pre): pwdutils

%description
Apache CouchDB is a distributed, fault-tolerant and schema-free
document-oriented database accessible via a RESTful HTTP/JSON API.
Among other features, it provides robust, incremental replication
with bi-directional conflict detection and resolution, and is
queryable and indexable using a table-oriented view engine with
JavaScript acting as the default view definition language.

%prep
%setup -q -n %{tarname}-%{version}
%patch0 -p1

%build
autoreconf -fi
# We need to define the use of gnu99 standard. It seems expected in the code, but not passed.
export CFLAGS="%{optflags} -std=gnu99"
%configure \
   --with-js-include=$(pkg-config --variable=includedir mozilla-js)%{xul_pathext} \
   --with-js-lib=$(pkg-config --variable=libdir mozilla-js)
make %{?jobs:-j%jobs}

%install
%makeinstall
## Install couchdb initscript
install -D -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/%{name}
install -d %{buildroot}%{_sbindir}
ln -s %{_initrddir}/couchdb %{buildroot}%{_sbindir}/rccouchdb

# Create /var/log/couchdb
mkdir -p %{buildroot}%{_localstatedir}/log/couchdb

# Create /var/run/couchdb
mkdir -p %{buildroot}%{_localstatedir}/run/couchdb

# Create /var/lib/couchdb
mkdir -p %{buildroot}%{_localstatedir}/lib/couchdb

# Create /etc/couchdb/default.d
mkdir -p %{buildroot}%{_sysconfdir}/couchdb/default.d

# Create /etc/couchdb/local.d
mkdir -p %{buildroot}%{_sysconfdir}/couchdb/local.d

# Remove unecessary files
rm %{buildroot}%{_sysconfdir}/rc.d/couchdb
rm -rf  %{buildroot}%{_datadir}/doc/couchdb

# clean-up .la archives
find %{buildroot} -name '*.la' -delete -print

%clean
rm -rf %{buildroot}

%pre
getent group %{couchdb_group} >/dev/null || groupadd -r %{couchdb_group}
getent passwd %{couchdb_user} >/dev/null || \
useradd -r -g %{couchdb_group} -d %{couchdb_home} -s /bin/bash \
-c "Couchdb Database Server" %{couchdb_user}
exit 0

%post
%{fillup_and_insserv couchdb}

%postun
%restart_on_update couchdb
%insserv_cleanup

%preun
%stop_on_removal couchdb

%files
%defattr(-,root,root,-)
%doc AUTHORS BUGS CHANGES LICENSE NEWS NOTICE README THANKS
%dir %{_sysconfdir}/couchdb
%dir %{_sysconfdir}/couchdb/local.d
%dir %{_sysconfdir}/couchdb/default.d
%config(noreplace) %attr(0644, %{couchdb_user}, root) %{_sysconfdir}/couchdb/default.ini
%config(noreplace) %attr(0644, %{couchdb_user}, root) %{_sysconfdir}/couchdb/local.ini
%config(noreplace) %{_sysconfdir}/default/couchdb
%config(noreplace) %{_sysconfdir}/logrotate.d/couchdb
%{_initrddir}/couchdb
%{_sbindir}/rccouchdb
%{_bindir}/*
%{_libdir}/couchdb
%{_datadir}/couchdb
%{_mandir}/man1/*
%dir %attr(0755, %{couchdb_user}, root) %{_localstatedir}/log/couchdb
%dir %attr(0755, %{couchdb_user}, root) %{_localstatedir}/run/couchdb
%dir %attr(0755, %{couchdb_user}, root) %{_localstatedir}/lib/couchdb

%changelog
openSUSE Build Service is sponsored by