##
##  cvs.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   the involved versions
%define       V_cvs       1.11.4
%define       V_cvslock   0.2

#   package information
Name:         cvs
Summary:      Concurrent Versions Systems (CVS)
URL:          http://www.cvshome.org/
Vendor:       B. Berliner, D.D. Zuhn, J. Polk
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        SCM
License:      GPL
Version:      %{V_cvs}
Release:      20030103

#   optional support for applying the RSE patches
%option       with_rse_patches              no
%option       with_rse_patch_cvsuser_caller cvs

#   list of sources
Source0:      http://www.cvshome.org/files/19/10/cvs-%{V_cvs}.tar.gz
Source1:      ftp://riemann.iam.uni-bonn.de/pub/users/roessler/cvslock/cvslock-%{V_cvslock}.tar.gz
Source2:      cvs.patches.rse
Source3:      cvs.patches.msvb
Source4:      rc.cvs

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103, perl, patch
PreReq:       OpenPKG, openpkg >= 20030103, perl, patch
AutoReq:      no
AutoReqProv:  no

%description
    CVS is a version control system, which allows you to keep old
    versions of files (usually source code), keep a log of who,
    when, and why changes occurred, etc., like RCS or SCCS. Unlike
    the simpler systems, CVS does not just operate on one file at a
    time or one directory at a time, but operates on hierarchical
    collections of directories consisting of version controlled files.
    CVS helps to manage releases and to control the concurrent editing
    of source files among multiple authors. CVS allows triggers to
    enable/log/control various operations and works well over a wide
    area network. CVS keeps a single copy of the master sources. This
    copy is called the source repository.

    Additionally the following popular CVS tools are included: cvs2cl
    (a tool for assembling a GNU ChangeLog file from "cvs log" output)
    and cvslock (an administration tool for manually locking a CVS
    repository area).

%if "%{with_rse_patches}" == "yes"
    This version of CVS has the large set of patches applied from
    Ralf S. Engelschall <rse@engelschall.com> (-DRSE_PATCHES). This
    means that (still undocumented) extra functionality is available.
%endif

%prep
    %setup0 -q -c
    %setup1 -q -T -D -a 1
%if "%{with_rse_patches}" == "yes"
    ( cd cvs-%{V_cvs}
      cat %{SOURCE cvs.patches.rse} |\
      sed -e 's;\(#define RSE_PATCH_CVSUSER_CALLER "\)cvs\("\);\1%{with_rse_patch_cvsuser_caller}\2;' |\
      %{l_patch} -p0
      #   patch the patches to run on Solaris
      case "%{l_target}" in
          *-solaris* )
          %{l_patch} -p0 < %{SOURCE cvs.patches.msvb}
          ;;
      esac
    )
%endif

%build
    ( cd cvs-%{V_cvs}
      CC="%{l_cc}" \
%if "%{with_rse_patches}" == "yes"
      CFLAGS="%{l_cflags -O} -DRSE_PATCHES" \
%else
      CFLAGS="%{l_cflags -O}" \
%endif
      ./configure \
          --prefix=%{l_prefix} \
          --with-patch=%{l_prefix}/bin/patch \
          --without-krb4 \
          --without-gssapi \
          --enable-encryption \
          --enable-server
      %{l_make} %{l_mflags -O}
    )
    ( cd cvslock-%{V_cvslock}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix}
      %{l_make} %{l_mflags -O}
    )

%install
    rm -rf $RPM_BUILD_ROOT
    ( cd cvs-%{V_cvs}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
      rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/rcs2log
      rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
      mv $RPM_BUILD_ROOT%{l_prefix}/share/cvs/contrib/* \
         $RPM_BUILD_ROOT%{l_prefix}/share/cvs/
      rmdir $RPM_BUILD_ROOT%{l_prefix}/share/cvs/contrib
    )
    ( cd cvslock-%{V_cvslock}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    )
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
%if "%{with_rse_patches}" == "yes"
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/var/cvs
    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e 's;@l_musr@;%{l_musr};g' \
        -e 's;@l_mgrp@;%{l_mgrp};g' \
        %{SOURCE rc.cvs} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
%endif
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

