##
##  xerces-c.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 version
%define       V_opkg             2.1.0
%define       V_dist             2_1_0

#   package information
Name:         xerces-c
Summary:      Validating XML parser
URL:          http://xml.apache.org/xerces-c/
Vendor:       Apache Software Foundation
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Web
License:      Apache Software License 1.1
Version:      %{V_opkg}
Release:      20030103

#   package options
%option       with_pth           no
%option       with_threads       no

#   package option dependencies
%if "%{with_pth}" == "yes"
%undefine     with_threads
%define       with_threads       yes
%endif

#   list of sources
Source0:      http://xml.apache.org/dist/xerces-c/stable/xerces-c-src%{V_dist}.tar.gz
Patch0:       xerces-c.patch
Patch1:       xerces-c-pth.patch

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103, gcc, make, autoconf, libtool
PreReq:       OpenPKG, openpkg >= 20030103
%if "%{with_pth}" == "yes"
BuildPreReq:  pth
PreReq:       pth
%endif
AutoReq:      no
AutoReqProv:  no

%description
    Xerces-C++ is a validating XML parser written in a portable subset of C++.

%prep
    %setup -q -n xerces-c-src%{V_dist}
    %patch0 -p0
%if "%{with_pth}" == "yes"
    %patch1 -p0
%endif

%build
    rm -rf $RPM_BUILD_ROOT
    ( XERCESCROOT=`pwd`
      export XERCESCROOT
      %{l_shtool} subst \
          -e 's;@l_ar@;%{l_libtool} --mode=link c++ -static -o;' \
          obj/Makefile.in
      cd $XERCESCROOT/src/xercesc
      %{l_prefix}/bin/autoconf
%if "%{with_threads}" == "yes"
      os="freebsd"
      pt="pthread"
      case "%{l_target}" in
%if "%{with_pth}" == "yes"
          *-freebsd*)    os=freebsd; pt=pth     ;;
%else
          *-freebsd*)    os=freebsd; pt=pthread ;;
%endif
          *-linux*)      os=linux;   pt=pthread ;;
          *-solaris*)    os=solaris; pt=pthread ;;
          *-irix*)       os=irix;    pt=sproc   ;;
          *-hpux-10.*)   os=hp-10;   pt=none    ;;
          *-hpux-11.*)   os=hp-11;   pt=none    ;;
          *-aix*)        os=aix;     pt=pthread ;;
      esac
%else
      os="freebsd"
      pt="none"
      case "%{l_target}" in
          *-freebsd*)    os=freebsd ;;
          *-linux*)      os=linux   ;;
          *-solaris*)    os=solaris ;;
          *-irix*)       os=irix    ;;
          *-hpux-10.*)   os=hp-10   ;;
          *-hpux-11.*)   os=hp-11   ;;
          *-aix*)        os=aix     ;;
      esac ;
%endif
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      LDFLAGS="%{l_ldflags}" \
      ./runConfigure \
          -P%{l_prefix} \
          -p$os \
          -cgcc \
          -xc++ \
          -minmem \
          -nsocket \
          -tnative \
          -r$pt
      %{l_make} %{l_mflags}

      cd $XERCESCROOT/samples
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      LDFLAGS="%{l_ldflags}" \
      ./runConfigure \
          -p$os \
          -cgcc \
          -xc++
      %{l_make} %{l_mflags}

      cd $XERCESCROOT/tests
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      LDFLAGS="%{l_ldflags}" \
      ./runConfigure \
          -p$os \
          -cgcc \
          -xc++
      %{l_make} %{l_mflags}
    )

%install
    ( XERCESCROOT=`pwd`
      export XERCESCROOT
      cd $XERCESCROOT/src/xercesc
      %{l_make} %{l_mflags} install "PREFIX=$RPM_BUILD_ROOT%{l_prefix}"
      cd $XERCESCROOT/bin
      %{l_shtool} mkdir -f -p -m 755 \
          $i $RPM_BUILD_ROOT%{l_prefix}/libexec/xerces-c
      for i in *; do
          if [ -f $i ]; then
              %{l_shtool} install -s -c -m 755 \
                  $i $RPM_BUILD_ROOT%{l_prefix}/libexec/xerces-c
          fi
      done
    )
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

