##
##  perforce.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.
##

#   package information
Name:         perforce
Summary:      The Perforce SCM System
URL:          http://www.perforce.com/
Vendor:       Perforce Software
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        SCM
License:      Commercial
Version:      2002.2
Release:      20030108

#   list of sources
Source0:      perforce-%{version}.tar.bz2
Source1:      ftp://ftp.perforce.com/perforce/utils/c4/c4.tar.gz
Source2:      http://www.perforce.com/perforce/doc.021/man/p4.1
Source3:      http://www.perforce.com/perforce/doc.021/man/p4d.1
Source4:      http://www.perforce.com/perforce/doc.021/manuals/p4guide/p4guide.pdf
Source5:      http://www.perforce.com/perforce/doc.021/manuals/p4sag/p4sag.pdf
Source6:      http://www.perforce.com/perforce/doc.021/manuals/cmdref/cmdref.pdf
Source7:      http://www.perforce.com/perforce/doc.021/manuals/p4ftp/p4ftp.pdf
Source8:      rc.perforce
%NoSource     0

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

%description
    Perforce (P4) is a commercial (but freely available and useable
    for Open Source projects) Software Configuration Management (SCM)
    system. It is superior to Concurrent Versions System (CVS) and
    even (with the help of an existing CVS to P4 repository conversion
    tool) can operate on the RCS files of CVS. This is the unlicensed
    demo version. It has full time-unlimited functionality, but is
    restricted to 2 users. For a real license one has to contact
    <opensource@perforce.com>.

%prep
    %integrity
    %setup0 -q -c
    %setup1 -q -T -D -a 1

%build
    ( cd c4-1.6
      %{l_make} %{l_mflags} \
          CC="%{l_cc}" CFLAGS="%{l_cflags -O}"
    )

%install
    rm -rf $RPM_BUILD_ROOT
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/perforce \
        $RPM_BUILD_ROOT%{l_prefix}/share/perforce \
        $RPM_BUILD_ROOT%{l_prefix}/var/perforce/p4d.depot
    subdir="perforce-%{version}/bin"
    case "%{l_target}" in
        *-freebsd* ) subdir="$subdir.freebsd4"   ;;
        *-linux*   ) subdir="$subdir.linux22x86" ;;
        *-solaris* ) subdir="$subdir.solaris26"  ;;
        * ) echo "platform %{l_target} not supported" 1>&2; exit 1 ;;
    esac
    ( cd $subdir
      %{l_shtool} install -c -m 755 \
          p4 $RPM_BUILD_ROOT%{l_prefix}/bin/
      %{l_shtool} install -c -m 755 \
          p4d p4web p4ftpd p4p $RPM_BUILD_ROOT%{l_prefix}/sbin/
      %{l_shtool} install -c -m 644 \
          %{SOURCE p4.1} %{SOURCE p4d.1} $RPM_BUILD_ROOT%{l_prefix}/man/man1/
      %{l_shtool} install -c -m 644 \
          %{SOURCE p4guide.pdf} %{SOURCE p4sag.pdf} \
          %{SOURCE cmdref.pdf} %{SOURCE p4ftp.pdf} \
          $RPM_BUILD_ROOT%{l_prefix}/share/perforce/
    )
    ( cd c4-1.6
      %{l_shtool} install -c -m 755 \
          c4 $RPM_BUILD_ROOT%{l_prefix}/bin/
      %{l_shtool} install -c -m 644 \
          c4.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    )
    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e 's;@l_rusr@;%{l_rusr};g' \
        -e 's;@l_rgrp@;%{l_rgrp};g' \
        %{SOURCE rc.perforce} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%dir %attr(700,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/perforce' \
        '%dir %attr(700,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/perforce/p4d.depot'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    if [ ".$1" = .1 ]; then
        $RPM_INSTALL_PREFIX/etc/rc perforce start
        sleep 1
        P4PORT=`$RPM_INSTALL_PREFIX/etc/rc -q perforce_port`
        export P4PORT
        ( echo "Protections:"
          echo "    read  user *         *  //..."
          echo "    write user *         *  //..."
          echo "    super user %{l_rusr} *  //..."
        ) | su %{l_rusr} -c "$RPM_INSTALL_PREFIX/bin/p4 protect -i" >/dev/null 2>&1
        $RPM_INSTALL_PREFIX/etc/rc perforce stop
    fi

