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

%define       V_real         2-0-15
%define       V_here         2.0.15
%define       V_log_dispatch 2.01

#   package information
Name:         rt
Summary:      Request Tracker
URL:          http://www.fsck.com/projects/rt/
Vendor:       Fsck
Packager:     The OpenPKG Project
Distribution: OpenPKG [JUNK]
Group:        Database
License:      GPL
Version:      %{V_here}
Release:      20030113

#   list of sources
Source0:      http://www.cpan.org/modules/by-module/Log/Log-Dispatch-%{V_log_dispatch}.tar.gz
Source1:      http://www.fsck.com/pub/rt/release/rt-%{V_real}.tar.gz

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, perl-sys, perl-util, perl-ds, perl-text, perl-dbix
PreReq:       OpenPKG, openpkg >= 20020206, perl, mysql, apache, perl-sys, perl-util, perl-ds, perl-text, perl-dbix
AutoReq:      no
AutoReqProv:  no

%description
    RT is an industrial-grade ticketing system. It lets a group of
    people intelligently and efficiently manage requests submitted by a
    community of users. RT is used by systems administrators, customer
    support staffs, NOCs, developers and even marketing departments at
    over a thousand sites around the world.

%prep
    %setup -q -c
    %setup -q -T -D -a 1

%build
    rm -rf $RPM_BUILD_ROOT
    ( cd Log-Dispatch-%{V_log_dispatch}
    
      #   perform common prolog operations
      rt=%{l_prefix}/share/rt
      %{l_prefix}/bin/perl-openpkg prolog
      %{l_shtool} mkdir -f -p -m 755 ${RPM_BUILD_ROOT}$rt
      perl="${RPM_BUILD_DIR}/perl"
      echo "exec ${l_prefix}/bin/perl \\" >>$perl
      echo " \"\$@\"" >>$perl
      chmod a+x $perl

      #   build and install individual modules
      perl_args="INSTALLSITELIB=${RPM_BUILD_ROOT}$rt"
      make=`%{l_prefix}/bin/rpm --eval '%{l_make} %{l_mflags}'`
      make_args="PERL=${perl} FULLPERL=${perl}"
      chmod -R u+rw Makefile.PL
      cp Makefile.PL Makefile.PL.orig
      sed -e "s:\$^X:'$perl':g" <Makefile.PL.orig >Makefile.PL
      $perl Makefile.PL ${1+"$@"} $perl_args </dev/null
      $make $make_args pure_all
      $make $make_args pure_install

      #   perform common epilog operations
      %{l_prefix}/bin/perl-openpkg epilog
    )

    ( cd rt-%{V_real}
      %{l_shtool} subst \
          -e 's;^\(PERL[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/bin/perl;g' \
          -e 's;^\(BIN_OWNER[[:blank:]]*=[[:blank:]]*\).*;\1%{l_musr};g' \
          -e 's;^\(RTGROUP[[:blank:]]*=[[:blank:]]*\).*;\1%{l_mgrp};g' \
          -e 's;^\(LIBS_OWNER[[:blank:]]*=[[:blank:]]*\).*;\1%{l_musr};g' \
          -e 's;^\(LIBS_GROUP[[:blank:]]*=[[:blank:]]*\).*;\1%{l_mgrp};g' \
          -e 's;^\(RT_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/share/rt;g' \
          -e 's;^\(RT_LIB_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/share/rt;g' \
          -e 's;^\(RT_ETC_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/etc/rt;g' \
          -e 's;^\(RT_BIN_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/bin;g' \
          -e 's;^\(RT_MAN_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/man;g' \
          -e 's;^\(MASON_LOCAL_HTML_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/share/rt/mason;g' \
          -e 's;^\(MASON_DATA_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/var/rt/mason-data;g' \
          -e 's;^\(MASON_SESSION_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/var/rt/mason-session;g' \
          -e 's;^\(RT_LOG_PATH[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/var/rt/log;g' \
          -e 's;^\(RT_MODPERL_HANDLER[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/cgi/rt/webmux.pl;g' \
          -e 's;^\(RT_FASTCGI_HANDLER[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/cgi/rt/mason_handler.fcgi;g' \
          -e 's;^\(RT_SPEEDYCGI_HANDLER[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix}/cgi/rt/mason_handler.scgi;g' \
          -e 's;^\(DB_TYPE[[:blank:]]*=[[:blank:]]*\).*;\1mysql;g' \
          -e 's;^\(DB_HOST[[:blank:]]*=[[:blank:]]*\).*;\1localhost;g' \
          -e 's;^\(DB_PORT[[:blank:]]*=[[:blank:]]*\).*;\1;g' \
          -e 's;^\(DB_HOME[[:blank:]]*=[[:blank:]]*\).*;\1%{l_prefix};g' \
          -e 's;^\(DB_DBA[[:blank:]]*=[[:blank:]]*\).*;\1root;g' \
          -e 's;^\(DB_DBA_PASSWORD[[:blank:]]*=[[:blank:]]*\).*;\1XXX;g' \
          -e 's;^\(DB_RT_HOST[[:blank:]]*=[[:blank:]]*\).*;\1localhost;g' \
          -e 's;^\(DB_DATABASE[[:blank:]]*=[[:blank:]]*\).*;\1RT;g' \
          -e 's;^\(DB_RT_USER[[:blank:]]*=[[:blank:]]*\).*;\1RT;g' \
          -e 's;^\(DB_RT_PASS[[:blank:]]*=[[:blank:]]*\).*;\1XXX;g' \
          -e 's;^\(WEB_USER[[:blank:]]*=[[:blank:]]*\).*;\1%{l_nusr};g' \
          -e 's;^\(WEB_GROUP[[:blank:]]*=[[:blank:]]*\).*;\1%{l_ngrp};g' \
          -e 's;\([[:blank:]]INSTALLSITELIB=\);\1\$(DESTDIR);g' \
          -e 's;\([[:blank:]]INSTALLSITEMAN1DIR=\);\1\$(DESTDIR);g' \
          -e 's;\([[:blank:]]INSTALLSITEMAN3DIR=\);\1\$(DESTDIR);g' \
          -e 's;chown;true;g' \
          -e 's;chgrp;true;g' \
          -e 's;mkdir -p;%{l_shtool} mkdir -p;g' \
          Makefile
      %{l_make} %{l_mflags}
    )

%install
    mkdir -p $RPM_BUILD_ROOT%{l_prefix}/cgi/rt
    ( cd rt-%{V_real}
      CC=%{l_cc} \
      LDFLAGS=%{l_ldflags} \
      LDDFLAGS=%{l_lddflags} \
      PERL5LIB=${RPM_BUILD_ROOT}%{l_prefix}/share/rt \
      %{l_make} %{l_mflags} dirs upgrade instruct \
        DESTDIR=$RPM_BUILD_ROOT
    )
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%{l_prefix}/share/rt'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

