#
# spec file for package subversion
#
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2009-2010 Pascal Bleser <pascal.bleser@opensuse.org>
#
# 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/
#


# Subversion as of 1.7.4 does not work with ruby 1.9 in Factory 
%define with_ruby          0%{?suse_version} > 1110 && 0%{?suse_version} < 1220
%define with_intree_swig 0%{?suse_version} != 1110
%if 0%{?always_use_intree_sqlite:1}
%define with_intree_sqlite 1
%define with_python_ctypes 0%{?suse_version} > 1110
%else
%define with_intree_sqlite 0%{?suse_version} < 1110
%define with_python_ctypes 0
%endif
%if %suse_version >= 1220
%define with_python_ctypes 0
%endif
%define with_kde4_kwallet  0%{?suse_version} > 1100
%define with_gnome_keyring 0%{?suse_version} > 1100

%bcond_without	neon
%bcond_without	serf

# run build --with=regression_tests to run test suite
%bcond_with	regression_tests

%if 0%{?sles_version} > 10 && 0%{?sles_version} < 12
%define with_bashcomp 0
%else
%define with_bashcomp 1
%endif

Name:           subversion
Version:        1.7.9
Release:        0
# in-tree SWIG version to use for the build:
%define swig_version   1.3.36
%define sqlite_version 3.7.6.3
%define sqlite_pkg_version 3070603
BuildRequires:  apache2-devel
BuildRequires:  db-devel
BuildRequires:  file-devel
BuildRequires:  gcc-c++
BuildRequires:  libstdc++-devel
BuildRequires:  libtool
BuildRequires:  pkgconfig
BuildRequires:  python-devel
BuildRequires:  python-xml
BuildRequires:  update-alternatives
BuildRequires:  zlib-devel
%if %with_bashcomp
BuildRequires:  bash-completion
%endif #with_bashcomp
%if %with_python_ctypes
BuildRequires:  ctypesgen
%endif
%if %with_ruby
BuildRequires:  ruby-devel
%endif # with_ruby
BuildRequires:  apache2-prefork
BuildRequires:  cyrus-sasl-devel
%if %with_gnome_keyring
BuildRequires:  dbus-1-devel
BuildRequires:  glib2-devel
%if 0%{?suse_version} >= 1130
BuildRequires:  libgnome-keyring-devel
%else
BuildRequires:  gnome-keyring-devel
%endif
%endif # with_gnome_keyring
%if %{with serf}
BuildRequires:  libserf-devel
%endif
%if %with_kde4_kwallet
BuildRequires:  dbus-1-devel
BuildRequires:  kdelibs4-core
BuildRequires:  libkde4-devel
BuildRequires:  libqt4-devel
%endif # with_kde4_kwallet
%if 0%{?suse_version} >= 1130
%define with_java 1
BuildRequires:  java-devel >= 1.6.0
BuildRequires:  junit
%else
%define with_java 0
%endif
%if %{with neon}
%if 0%{?suse_version} > 1030
BuildRequires:  libneon-devel
%else
BuildRequires:  neon-devel
BuildRequires:  openldap2-devel
%endif # suse_version > 1030
%endif # with neon
%if %{with regression_tests}
# for check section, to find a free port:
BuildRequires:  iproute2
%endif # with regression_tests
#
%define _fwdefdir /etc/sysconfig/SuSEfirewall2.d/services
#
%define	apxs                /usr/sbin/apxs2
%define	apache_libexecdir	%(%{apxs} -q LIBEXECDIR)
%define	apache_sysconfdir	%(%{apxs} -q SYSCONFDIR)
%define apache_mmn          %(MMN="$(%{apxs} -q LIBEXECDIR)_MMN"; test -x "$MMN" && "$MMN")
%if %{!?site_python:1}0
%define site_python	%(%__python -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib()")
%endif
#
PreReq:         %insserv_prereq %fillup_prereq
#
Summary:        Subversion version control system
License:        Apache-2.0
Group:          Development/Tools/Version Control
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Url:            http://subversion.apache.org
Source0:        http://www.apache.org/dist/subversion/subversion-%{version}.tar.bz2
Source1:        subversion.conf
Source2:        subversion.README.SuSE
Source3:        svnmerge.py
Source4:        contrib-1187941.tar.bz2
Source9:        subversion.rcsvnserve
Source10:       subversion.sysconfig.svnserve
Source12:       subversion.sysconfig.svnserve.remoteaccess
Source13:       subversion.xinetd.svnserve
Source42:       subversion.svngrep.sh
Source43:       subversion.svndiff.sh
# https://people.apache.org/keys/group/subversion.asc
Source50:       subversion.keyring
Source51:       https://www.apache.org/dist/subversion/%{name}-%{version}.tar.bz2.asc
%if 0%{?suse_version} >= 1230
BuildRequires:  gpg-offline
%endif
%if %with_intree_swig
# http://ovh.dl.sourceforge.net/project/swig/swig/swig-%{swig_version}/swig-%{swig_version}.tar.gz
Source90:       swig-%{swig_version}.tar.bz2
%else
BuildRequires:  swig
%endif
%if %with_intree_sqlite
# http://www.sqlite.org/sqlite-amalgamation-%{sqlite_version}.tar.gz
Source91:       sqlite-autoconf-%{sqlite_pkg_version}.tar.bz2
%else
BuildRequires:  sqlite3-devel >= %{sqlite_version}
%requires_ge    libsqlite3-0
%endif # with_intree_sqlite
Source92:       %{name}.rpmlintrc
Source93:       subversion-tests-httpd.conf.tmpl
Source94:       subversion-tests-httpd-users
#
Patch11:        subversion.libtool-verbose.patch
# build fixes
Patch20:        subversion-swig-perl-install_vendor.patch
Patch23:        subversion.libtool-pie-flags.patch
Patch31:        subversion.perl.LD_RUN_PATH.patch
Patch37:        subversion-no-build-date.patch
# PATCH-FEATURE-UPSTREAM subversion-neon-systemproxy.patch dimstar@opensuse.org -- Use system proxy offered by neon, if no specific config is used (Thus, actually using libproxy in the background to use 'the right proxy' as configured in the system).
Patch38:        subversion-neon-systemproxy.patch
Patch39:        subversion-1.7.4-ruby-1.9-RbConfig.patch
Patch40:        subversion-1.7.8-TestHarness_run_py_test_exit_code.patch
#
%if %with_ruby
%if %{!?rb_arch:1}0
%define rb_arch %(echo "%{_host_cpu}-%{_os}" | sed -e "s/i686/i586/" -e "s/armv5tel/armv4l/" -e "s/hppa2.0/hppa/")
%endif
%if %{!?rb_major_ver:1}0
%define rb_major_ver %(/usr/bin/ruby -e 'puts VERSION'|cut -f1,2 -d.)
%endif
%if %{!?site_ruby:1}0
%define site_ruby %{_usr}/%{_lib}/ruby/site_ruby/%{rb_major_ver}
%endif
%endif # with_ruby
%if %with_java
Provides:       subversion-javahl = %{version}-%{release}
%endif # with_java

%description
Subversion exists to be universally recognized and adopted as an open-source,
centralized version control system characterized by its reliability as a safe
haven for valuable data; the simplicity of its model and usage; and its ability
to support the needs of a wide variety of users and projects, from individuals
to large-scale enterprise operations.


%package devel
Summary:        Development package for Subversion developers
Group:          Development/Libraries/C and C++
Requires:       subversion = %{version}
# this pulls in libapr1-devel and libexpat-devel
Requires:       libapr-util1-devel

%description devel
The subversion-devel package includes the static libraries and include
files for developers interacting with the subversion package.



%package tools
Summary:        Tools for Subversion
Group:          Development/Tools/Version Control

%description tools
This package contains some tools for subversion server and
repository admins.

%package perl
Summary:        Allows Perl scripts to directly use Subversion repositories
Group:          Development/Tools/Version Control
Requires:       perl = %{perl_version}
Requires:       perl >= 5.8
Requires:       subversion = %{version}

%description perl
Provides Perl (SWIG) support for Subversion.



%package python
Summary:        Allows Python scripts to directly use Subversion repositories
Group:          Development/Tools/Version Control
Requires:       subversion = %{version}

%description python
Provides Python (SWIG) support for Subversion.



%if %with_python_ctypes

%package python-ctypes

Summary:        High-Level Python Bindings for Subversion
Group:          Development/Tools/Version Control
Requires:       subversion = %{version}

%description python-ctypes
Provides high-level Python support for Subversion, based on ctypes.
%endif # with_python_ctypes
%if %with_ruby

%package ruby
Summary:        Allows Ruby scripts to directly use Subversion repositories
Group:          Development/Tools/Version Control
Requires:       subversion = %{version}

%description ruby
Provides Ruby (SWIG) support for Subversion.



%endif # with_ruby

%package server
Summary:        Apache server module for Subversion server
Group:          Development/Tools/Version Control
Requires:       %{apache_mmn}
Requires:       apache2
Requires:       subversion = %{version}

%description server
The subversion-server package adds the Subversion server Apache module
to the Apache directories and configuration.

http://subversion.apache.org



%if %with_kde4_kwallet

%package -n libsvn_auth_kwallet-1-0 
Summary:        A Concurrent Versioning system similar to but better than CVS
Group:          Development/Tools/Version Control

%description -n libsvn_auth_kwallet-1-0
Provides KWallet integration for Subversion.


%endif # with_kde4_kwallet
%if %with_gnome_keyring

%package -n libsvn_auth_gnome_keyring-1-0
Summary:        A Concurrent Versioning system similar to but better than CVS
Group:          Development/Tools/Version Control

%description -n libsvn_auth_gnome_keyring-1-0
Subversion does the same thing cvs (CVS (Concurrent Versioning System))
but has major enhancements compared to CVS. The name of the cmdline
client is svn.



%endif # with_gnome_keyring

%if %with_bashcomp

%package bash-completion
Summary:        Bash Completion for %{name}
Group:          Development/Tools/Version Control
Requires:       %{name} = %{version}
Requires:       bash-completion
%if %{?suse_version} >= 1130
BuildArch:      noarch
%endif

%description bash-completion
Bash command line completion support for %{name} - completion of subcommands,
parameters and keywords for the svn command and other tools.

%endif # with_bashcomp

%prep
%{?gpg_verify: %gpg_verify %{S:51}}
%if %with_intree_swig
%setup -q -n subversion-%{version} -a 4 -b 90
%else
%setup -q -n subversion-%{version} -a 4
%endif
#
%if %with_intree_sqlite
%__install -d ./sqlite-amalgamation
pushd ./sqlite-amalgamation
%__bzip2 -d -c "%{SOURCE91}" | %__tar xf - "sqlite-autoconf-%{sqlite_pkg_version}/sqlite3.c"
%__mv "sqlite-autoconf-%{sqlite_pkg_version}/sqlite3.c" .
%__rm -rf "sqlite-autoconf-%{sqlite_pkg_version}"
popd #./sqlite-amalgamation
%endif # with_intree_sqlite
#
%patch11 -p0
%patch20
%patch23 -p0
%patch31
%patch37 -p1
%patch38
%patch39 -p1
%patch40 -p1

SQLITE_RECOMMENDED_VER=$(grep -E '^SQLITE_RECOMMENDED_VER=' configure.ac|cut -f2 -d=|cut -f2 -d\")
#"
[ "$SQLITE_RECOMMENDED_VER" = "%{sqlite_version}" ] || {
    echo "ERROR: recommended sqlite version is $SQLITE_RECOMMENDED_VER, but we're using %{sqlite_version}" >&2;
    exit 1;
}

%build
# Re-boot strap, needed for patch37
./autogen.sh
# This package failed when testing with -Wl,-as-needed being default.
# So we disable it here, if you want to retest, just delete this comment and the line below.
export SUSE_ASNEEDED=0
%if 0%{?sles_version} == 9
mkdir BUILDPATH
%__ln_s "%{_usr}/bin/python2.5" "BUILDPATH/python"
export PATH="$PWD/BUILDPATH:$PATH"
export PYTHON="%{_usr}/bin/python2.5"
%endif
%if %with_intree_swig
SWIG_ROOT=`cd ..; pwd`/intree-swig
pushd "../swig-%{swig_version}"
%ifarch aarch64
cp ../subversion-%{version}/build/config.* Tools/config/
%endif
CFLAGS="%{optflags}" \
CXXFLAGS="%{optflags}" \
./configure \
	    --prefix="$SWIG_ROOT" \
	    --libdir="$SWIG_ROOT/%{_lib}" \
	    --without-tcl \
	    --without-java \
	    --without-gcj \
	    --without-guile \
	    --without-mzscheme \
	    --without-ocaml \
	    --without-pike \
	    --without-chicken \
	    --without-csharp \
	    --without-lua \
	    --without-allegrocl \
	    --without-clisp \
	    --without-r \
	    --with-swiglibdir="$SWIG_ROOT/share/swig"
%__make %{?jobs:-j%{jobs}}
%__make install
popd #swig
%endif

with_jdk=none
%if %with_java
for i in \
/usr/%{_lib}/jvm/java-openjdk \
/usr/%{_lib}/jvm/java \
/usr/%{_lib}/jvm/java-1.5.0-ibm \
/usr/%{_lib}/jvm/java-1.4.2-gcj \
/usr/%{_lib}/BEAJava2-1.4.2 \
/usr/%{_lib}/SunJava2-1.4.2 \
/usr/%{_lib}/jvm/java-1.4.2-sun \
/usr/lib/jvm/java-1.4.2-sun \
/usr/%{_lib}/jvm/java-1.5.0-ibm \
/usr/%{_lib}/jvm/java-1.5.0-sun \
/usr/lib/jvm/java-1.5.0-sun \
/usr/%{_lib}/jvm/java-1.4.2-ibm \
/usr/%{_lib}/jvm/IBMJava2-1.4.2 \
/usr/lib/BEAJava2-1.4.2 \
/usr/lib/SunJava2-1.4.2 \
/usr/lib/jvm/java-1.4.2-sun \
/usr/lib/IBMJava2-1.4 \
; do
if [ -d "$i" ] ; then
with_jdk="$i"
break
fi
done
%endif # with_java
if [ "$with_jdk" != "none" ] ; then
with_jdk="--with-jdk=$with_jdk --enable-javahl"
echo with_jdk > with_jdk
cat > with_jdk.files <<EOF-JAVA
%{_libdir}/libsvnjavahl*.so.*
%{_libdir}/libsvnjavahl*.so
%dir %{_libdir}/svn-javahl
%{_libdir}/svn-javahl/svn-javahl.jar
%{_datadir}/java/svn-javahl.jar
EOF-JAVA
else
with_jdk=""
rm -f with_jdk
echo -n '' > with_jdk.files
fi
%if !%with_java
with_jdk=""
rm -f with_jdk
echo -n '' > with_jdk.files
%endif # !with_java
cat with_jdk.files
# ### these possibly need further discussion
# swig_pydir = @libdir@/svn-python/libsvn
# swig_pydir_extra = @libdir@/svn-python/svn
sed --in-place=~ "
s@^swig_pydir = .*@swig_pydir = %{site_python}/libsvn@
s@^swig_pydir_extra = .*@swig_pydir_extra = %{site_python}/svn@
" Makefile.in
diff -u Makefile.in~ Makefile.in || true
sh -x autogen.sh
for i in subversion/bindings/javahl/native/*.cpp
do
	d=$(sed -n '/^#include "..\/include/{s@^[^/]\+\([^"]\+\).*@subversion/bindings/javahl\1@;H};${x;s@\n@ @gp}' $i)
	echo
	echo "# $i"
	if ! test -z "$d"
	then
		echo ${i%.cpp}.lo: $d
	fi
	echo
done >> build-outputs.mK
export CFLAGS="$(%{apxs} -q CFLAGS) %{optflags} -fpie -fstack-protector"
export CXXFLAGS="$CFLAGS"
export LDFLAGS=-pie
export PATH="${SWIG_ROOT}/bin:${PATH}"
%configure \
	--with-editor="vim -c 'set tw=72 et' " \
%if %{with neon}
	--with-neon=%{_prefix} \
%endif
%if %{with serf} 
	--with-serf=%{_prefix} \
%endif
	--with-apr=%{_prefix} \
	--with-apr-util=%{_prefix} \
	--with-apxs=%{apxs} \
	--with-zlib=%{_prefix} \
	--with-berkeley-db=db.h:db.h:%{_prefix}:db \
	$with_jdk \
%if %with_java
    --with-junit="%{_usr}/share/java/junit.jar" \
%endif
	--with-jikes=no \
%if %with_intree_swig
	--with-swig="$SWIG_ROOT" \
%endif
%if %with_intree_sqlite
	--with-sqlite="./sqlite-amalgamation/sqlite3.c" \
%else
	--with-sqlite="%{_usr}" \
%endif
%if %with_gnome_keyring
    --with-gnome-keyring \
%endif
%if %with_kde4_kwallet
    --with-kwallet \
%endif
	--disable-mod-activation \
	--with-libmagic \
	--disable-static
%__make %{?jobs:-j%jobs} SWIG_LDFLAGS=
#
if [ "$with_jdk" != "" ] ; then
with_jdk=javahl
fi
%if %with_ruby
ruby_target=swig-rb
%else
ruby_target=
%endif # with_ruby
%if %with_python_ctypes
python_ctypes_target=ctypes-python
%else
python_ctypes_target=
%endif # with_python_ctypes
%__make extraclean-swig
%__make swig-py $python_ctypes_target swig-pl $ruby_target SWIG_LDFLAGS= $with_jdk

%install
if [ -f with_jdk ] ; then
with_jdk=install-javahl
else
with_jdk=
fi
%if %with_ruby
ruby_target=install-swig-rb
%else
ruby_target=
%endif # with_ruby
%if %with_python_ctypes
python_ctypes_target=install-ctypes-python
%else
python_ctypes_target=
%endif # with_python_ctypes
%__make DESTDIR="$RPM_BUILD_ROOT" install install-swig-pl install-swig-py $python_ctypes_target $ruby_target $with_jdk
%if %with_python_ctypes
# remove csvn .pyc files and recompile them because they contain the $RPM_BUILD_ROOT path:
find "%{buildroot}%{py_prefix}/lib/python%{py_ver}/site-packages/csvn/" -name "*.pyc" | xargs %__rm -f
%__python "%{py_libdir}/compileall.py" -f -d "%{py_prefix}/lib/python%{py_ver}/site-packages/csvn" "%{buildroot}/%{py_prefix}/lib/python%{py_ver}/csvn"
%endif # with_python_ctypes

%perl_process_packlist
%find_lang %name
#
cp -Lav %{S:42} $RPM_BUILD_ROOT%{_bindir}/svngrep
cp -Lav %{S:43} $RPM_BUILD_ROOT%{_bindir}/svndiff
#
mkdir -p $RPM_BUILD_ROOT/usr/share/emacs/site-lisp/
cp -avL contrib/client-side/emacs/*.el $RPM_BUILD_ROOT/usr/share/emacs/site-lisp/
rm -f $RPM_BUILD_ROOT/usr/share/emacs/site-lisp/vc-svn.el
#
install -m 755 contrib/client-side/svnmerge/svnmerge.py $RPM_BUILD_ROOT/usr/bin/svnmerge.py
cp -avL contrib/client-side/svn_apply_autoprops.py $RPM_BUILD_ROOT/usr/bin
#
mkdir -p $RPM_BUILD_ROOT/%{apache_sysconfdir}/conf.d
cp -av %{S:1} $RPM_BUILD_ROOT/%{apache_sysconfdir}/conf.d/subversion.conf
#
cp -avL %{S:2} README.SuSE
cp -avL subversion/mod_authz_svn/INSTALL README.mod_authz_svn
cat %name.lang > files.subversion
cat with_jdk.files >> files.subversion
#
# tools
%__make DESTDIR="$RPM_BUILD_ROOT" install-tools
%__mv $RPM_BUILD_ROOT%{_bindir}/svn-tools/{svn-populate-node-origins-index,svn-rep-sharing-stats,svnauthz-validate,svnmucc} $RPM_BUILD_ROOT%{_bindir}
# discard all other tools
%__rm -rf $RPM_BUILD_ROOT%{_bindir}/svn-tools
#
#
#
mkdir -p $RPM_BUILD_ROOT/usr/sbin
mkdir -p $RPM_BUILD_ROOT/var/adm/fillup-templates
install -m 644 -D %{S:13} $RPM_BUILD_ROOT/etc/xinetd.d/svnserve
install -m 755 -D %{S:9} $RPM_BUILD_ROOT/etc/init.d/svnserve
ln -sv /etc/init.d/svnserve $RPM_BUILD_ROOT/usr/sbin/rcsvnserve
install -m 644 -D %{S:10} $RPM_BUILD_ROOT/var/adm/fillup-templates/sysconfig.svnserve
install -m 644 -D %{S:12} $RPM_BUILD_ROOT/%{_fwdefdir}/svnserve
#useless libtool stuff
rm -f %{buildroot}%{_libdir}/*.la
if [ "$with_jdk" != "" ] ; then
    install -d -m 0755 $RPM_BUILD_ROOT/%{_datadir}/java
    ln -sv %{_libdir}/svn-javahl/svn-javahl.jar $RPM_BUILD_ROOT/%{_datadir}/java/svn-javahl.jar
fi
rm -f %{buildroot}/var/adm/perl-modules/subversion

%if %with_bashcomp
%__install -D -m0644 tools/client-side/bash_completion "%{buildroot}/etc/bash_completion.d/%{name}"
%endif #with_bashcomp

# clean tools for doc
%__rm -rf tools/*/*.in

%check

#
# double check that the essential repository access schemes have been compiled in
# requires at least one http library: neon or serf
#
schemes=$(LD_LIBRARY_PATH="${RPM_BUILD_ROOT}%{_libdir}" "${RPM_BUILD_ROOT}%{_bindir}/svn" --version | %__grep "'" | cut -d\' -f2 | sort -u)
# reset vim syntax: '
test "$schemes" = "file
http
https
svn"
#
%if %{with neon}
#
# double check that when building with neon support, ra_neon is actually available and handles http and https schemes
#
serf_schemes=$(LD_LIBRARY_PATH="${RPM_BUILD_ROOT}%{_libdir}" "${RPM_BUILD_ROOT}%{_bindir}/svn" --version | %__grep -A2 "ra_neon" | %__grep "'" | cut -d\' -f2 )
# reset vim syntax: '
test "$serf_schemes" = "http
https"
#
%endif # with neon
#
%if %{with serf}
#
# double check that when building with serf support, ra_serf is actually available and handles http and https schemes
#
serf_schemes=$(LD_LIBRARY_PATH="${RPM_BUILD_ROOT}%{_libdir}" "${RPM_BUILD_ROOT}%{_bindir}/svn" --version | %__grep -A2 "ra_serf" | %__grep "'" | cut -d\' -f2 )
# reset vim syntax: '
test "$serf_schemes" = "http
https"
#
%endif # with serf
#

%if %{with regression_tests}

ulimit -a
# During "make check", auth-test loads DSOs at runtime and can't find
# them if we don't set up LD_LIBRARY_PATH as below.
export LD_LIBRARY_PATH="$PWD/subversion/libsvn_auth_kwallet/.libs:$PWD/subversion/libsvn_auth_gnome_keyring/.libs:$LD_LIBRARY_PATH"
CHECK_FS_TYPE=fsfs

# run tests over ra_local (file://)
%__make check CLEANUP=true FS_TYPE="$CHECK_FS_TYPE"

SVNSERVE_PIDFILE="$PWD/svnserve.pid"
HTTPD_PIDFILE="$PWD/httpd.pid"
# hook up cleanup routine
function on_exit {
    if [ -e "$SVNSERVE_PIDFILE" ]; then
        pid=`cat "$SVNSERVE_PIDFILE" 2>/dev/null || :`
        test -n "$pid" && kill -9 "$pid" || :
    fi
    if [ -e "$HTTPD_PIDFILE" ]; then
        pid=`cat "$HTTPD_PIDFILE" 2>/dev/null || :`
        test -n "$pid" && kill -9 "$pid" || :
    fi
}
trap on_exit EXIT

# find next free port
function find_next_free_port {
    if [ -z "$free_port" ]; then                # on first invocation
        local start_port=1025                   # start with user port range
    else                                        # on subsequent invocations
        local start_port=$free_port;            # look for ports above the last
        let start_port++;                       # as the daemon might still use it
    fi
    free_port=""
    # in the OBS build VMs, the call to ss actually fails, resulting in all port to be returned as unused,
    # subsequent calls to the function will use a sequence from 1025, which are always available in VM.
    # For local builds this takes into account locally used ports. Either way works to get a usable port.
    for p in `/usr/sbin/ss -nat|tail +2|awk '{ split($4, a, ":"); if (a[2] > 1024) { print a[2]; }}'`; do used_port[$p]="$p"; done
    for p in `seq $start_port 65535`; do
        if [ -z "${used_port[$p]}" ]; then
            free_port="$p"
            break
        fi
    done
    if [ -z "$free_port" ]; then
        echo "ERROR: failed to find a free port" >&2
        echo "Used TCP ports: ${used_port[*]}" >&2
        exit 1
    fi
}
find_next_free_port

# run tests over ra_svn (svn://)
"$PWD/subversion/svnserve/svnserve" --listen-host 127.0.0.1 --listen-port "$free_port" --pid-file "$SVNSERVE_PIDFILE" -d -r "$PWD/subversion/tests/cmdline"
%__make check CLEANUP=true FS_TYPE="$CHECK_FS_TYPE" BASE_URL="svn://127.0.0.1:$free_port"
kill -9 `cat "$SVNSERVE_PIDFILE" 2>/dev/null`
%__rm "$SVNSERVE_PIDFILE"

# run tests over ra_neon (http://)
%if %{with neon}
find_next_free_port
# create apache configuration
%__cp "%{SOURCE94}" users
APACHE_LIBEXECDIR="%{apache_libexecdir}"
< "%{SOURCE93}" \
	sed "s/REPLACE_PORT/$free_port/g" | \
	sed "s/REPLACE_BUILDROOT/${RPM_BUILD_ROOT//\//\\/}/g" | \
	sed "s/REPLACE_BUILDDIR/${PWD//\//\\/}/g" | \
	sed "s/REPLACE_APACHE_LIBEXECDIR/${APACHE_LIBEXECDIR//\//\\/}/g" > httpd.conf
LD_LIBRARY_PATH="%{buildroot}%{_libdir}:$LD_LIBRARY_PATH" /usr/sbin/httpd2 -d "$PWD" -f httpd.conf
%__make check CLEANUP=true FS_TYPE="$CHECK_FS_TYPE" BASE_URL=http://127.0.0.1:$free_port HTTP_LIBRARY=neon
kill -9 `cat "$HTTPD_PIDFILE" 2>/dev/null`
%__rm "$HTTPD_PIDFILE"
%endif # neon

# run tests over ra_serf (http://)
%if %{with serf}
find_next_free_port
# create apache configuration
%__cp "%{SOURCE94}" users
APACHE_LIBEXECDIR="%{apache_libexecdir}"
< "%{SOURCE93}" \
	sed "s/REPLACE_PORT/$free_port/g" | \
	sed "s/REPLACE_BUILDROOT/${RPM_BUILD_ROOT//\//\\/}/g" | \
	sed "s/REPLACE_BUILDDIR/${PWD//\//\\/}/g" | \
	sed "s/REPLACE_APACHE_LIBEXECDIR/${APACHE_LIBEXECDIR//\//\\/}/g" > httpd.conf
LD_LIBRARY_PATH="%{buildroot}%{_libdir}:$LD_LIBRARY_PATH" /usr/sbin/httpd2 -d "$PWD" -f httpd.conf
%__make check CLEANUP=true FS_TYPE="$CHECK_FS_TYPE" BASE_URL=http://127.0.0.1:$free_port HTTP_LIBRARY=serf
kill -9 `cat "$HTTPD_PIDFILE" 2>/dev/null`
%__rm "$HTTPD_PIDFILE"
%endif # serf

%if %with_java
%__make check-javahl
%endif # with_java
%__make check-swig-pl
%if 0%{?suse_version} > 1140
# python bindings fail testsuite on 11.4
%__make check-swig-py
%endif
%if %with_ruby
%__make check-swig-rb
%endif # with_ruby

%endif # with regression_tests

%clean
%__rm -rf "%{buildroot}"

%preun
%stop_on_removal svnserve

%post
%{fillup_and_insserv -n svnserve svnserve}
/sbin/ldconfig

%postun
%restart_on_update svnserve
%{insserv_cleanup}
/sbin/ldconfig

%post -n subversion-python -p /sbin/ldconfig

%postun -n subversion-python -p /sbin/ldconfig

%post -n subversion-perl -p /sbin/ldconfig

%postun -n subversion-perl -p /sbin/ldconfig
%if %with_ruby

%post -n subversion-ruby -p /sbin/ldconfig

%postun -n subversion-ruby -p /sbin/ldconfig
%endif # with_ruby
%if %with_gnome_keyring

%post -n libsvn_auth_gnome_keyring-1-0 -p /sbin/ldconfig

%postun -n libsvn_auth_gnome_keyring-1-0 -p /sbin/ldconfig
%endif # with_gnome_keyring
%if %with_kde4_kwallet

%post -n libsvn_auth_kwallet-1-0 -p /sbin/ldconfig

%postun -n libsvn_auth_kwallet-1-0 -p /sbin/ldconfig
%endif # with_kde4_kwallet

%files -f files.subversion
%defattr(-,root,root)
%doc README.SuSE BUGS CHANGES LICENSE README.mod_authz_svn
%doc tools/hook-scripts tools/backup tools/bdb tools/examples tools/xslt
#
%config(noreplace) /etc/xinetd.d/svnserve
%attr(754,root,root) /etc/init.d/svnserve
%attr(754,root,root) /usr/sbin/rcsvnserve
/var/adm/fillup-templates/sysconfig.svnserve
%config %{_fwdefdir}/*
#
%attr(755,root,root) /usr/bin/svn
%attr(755,root,root) /usr/bin/svnadmin
%attr(755,root,root) /usr/bin/svndumpfilter
%attr(755,root,root) /usr/bin/svnlook
%attr(755,root,root) /usr/bin/svnserve
%attr(755,root,root) /usr/bin/svnversion
%attr(755,root,root) /usr/bin/svndiff
%attr(755,root,root) /usr/bin/svngrep
%attr(755,root,root) /usr/bin/svnsync
%attr(755,root,root) /usr/bin/svnrdump
%{_libdir}/libsvn_client*.so.*
%{_libdir}/libsvn_delta*.so.*
%{_libdir}/libsvn_diff*.so.*
%{_libdir}/libsvn_fs*.so.*
%{_libdir}/libsvn_ra*.so.*
%{_libdir}/libsvn_repos*.so.*
%{_libdir}/libsvn_subr*.so.*
%{_libdir}/libsvn_wc*.so.*
%{_mandir}/man?/svn*
#
/usr/share/emacs

%files perl
%defattr(-,root,root)
%doc %{_mandir}/man?/SVN::*
%{_libdir}/libsvn_swig_perl-1.so.*
%perl_vendorarch/SVN
%perl_vendorarch/auto/SVN

%files python
%defattr(-,root,root)
%dir %{site_python}
%dir %{site_python}/svn
%dir %{site_python}/libsvn
%{_libdir}/libsvn_swig_py-1.so.*
%{site_python}/libsvn/*
%{site_python}/svn/*
%if %with_python_ctypes

%files python-ctypes
%defattr(-,root,root)
%doc subversion/bindings/ctypes-python/examples
%dir %{site_python}
%{site_python}/csvn
%if %suse_version >= 1020
%{site_python}/svn_ctypes_python_bindings-*-py%{py_ver}.egg-info
%endif # suse_version >= 1020
%endif # with_python_ctypes
%if %with_ruby

%files ruby
%defattr(-,root,root)
%dir %{site_ruby}
%{site_ruby}/svn
%{site_ruby}/%{rb_arch}/svn
%{_libdir}/libsvn_swig_ruby-1.so.*
%endif # with_ruby

%files devel
%defattr(-,root,root)
%dir %{_includedir}/subversion-1
%{_libdir}/libsvn_*.so
%{_includedir}/subversion-1/*

%files tools
%defattr(-,root,root)
%attr(755,root,root) %{_bindir}/svnmerge.py
%attr(755,root,root) %{_bindir}/svn_apply_autoprops.py
%{_bindir}/svn-populate-node-origins-index
%{_bindir}/svnauthz-validate
%{_bindir}/svn-rep-sharing-stats
%{_bindir}/svnmucc

%files server
%defattr(-,root,root)
%dir %{apache_sysconfdir}/conf.d
%config (noreplace) %{apache_sysconfdir}/conf.d/subversion.conf
%dir %{apache_libexecdir}
%{apache_libexecdir}/mod_dav_svn.*
%{apache_libexecdir}/mod_authz_svn.*
%{apache_libexecdir}/mod_dontdothat.*
%if %with_gnome_keyring

%files -n libsvn_auth_gnome_keyring-1-0
%defattr(-,root,root)
%{_libdir}/libsvn_auth_gnome_keyring-1.so.0
%{_libdir}/libsvn_auth_gnome_keyring-1.so.0.*
%endif # with_gnome_keyring
%if %with_kde4_kwallet

%files -n libsvn_auth_kwallet-1-0
%defattr(-,root,root)
%{_libdir}/libsvn_auth_kwallet-1.so.0
%{_libdir}/libsvn_auth_kwallet-1.so.0.*
%endif # with_kde4_kwallet

%if %with_bashcomp

%files bash-completion
%defattr(-,root,root)
%config %{_sysconfdir}/bash_completion.d/%{name}
%endif #with_bashcomp

%changelog
