##
##  j2se.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 versions
%define       V_openpkg    1.3.1
%define       V_sol_dist   1_3_1_06
%define       V_sol_fsys   1.3.1_06
%define       V_lnx_dist   1_3_1_06
%define       V_lnx_fsys   1.3.1_06
%define       V_bsd_dist   1.3.1p7_1
%define       V_bsd_fsys   1.3.1

#   package options
%ifndef       with_native
%define       with_native  yes
%endif

#   package information
Name:         j2se
Summary:      Java 2 Platform, Standard Edition (J2SE) 1.3
URL:          http://java.sun.com/j2se/
Vendor:       Sun Microsystems, Inc.
Packager:     The OpenPKG Project
Distribution: OpenPKG [PRIV]
Group:        Language
License:      Commercial
Version:      %{V_openpkg}
Release:      20021110

#   list of sources
Source0:      j2sdk-%{V_sol_dist}-solaris-sparc.sh
Source1:      j2sdk-%{V_lnx_dist}-linux-i586.bin
Source2:      j2sdk-%{V_bsd_dist}-freebsd-ix86.tar.bz2
Source3:      rc.%{name}
Source4:      %{name}.patch

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

%description
    This is the Sun Java 2 Platform, Standard Edition (J2SE) 1.3.
    It contains the Java Development Kit (JDK) and the Java Runtime
    Environment (JRE). The premier solution for rapidly developing
    and deploying mission-critical, enterprise applications, J2SE
    provides the essential compiler, tools, runtimes, and APIs for
    writing, deploying, and running applets and applications in the
    Java programming language.

%prep
    %setup -q -c %{name} -T

%build
    #   no-op

%install
    rm -rf $RPM_BUILD_ROOT

    #   create installation tree
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/libexec \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1

    #   unpack source distribution
    ( umask 022
      cd $RPM_BUILD_ROOT%{l_prefix}/libexec
      case "%{l_target}" in
          ix86-freebsd4* )
%if "%{with_native}" == "yes"
              %{l_bzip2} -d -c %{SOURCE j2sdk-%{V_bsd_dist}-freebsd-ix86.tar.bz2} |\
                  %{l_tar} xf -
              mv j2sdk-%{V_bsd_fsys} %{name}
%else
              echo "yes" | sh %{SOURCE j2sdk-%{V_lnx_dist}-linux-i586.bin} >/dev/null
              mv jdk%{V_lnx_fsys} %{name}
              find %{name}/bin -type f -print | xargs chmod u+w
              ( cd %{name}; %{l_patch} -p0 <%{SOURCE %{name}.patch} )
              brandelf -t Linux \
                  `find %{name}/bin/ -type f -print` \
                  >/dev/null 2>&1 || true
%endif
              ;;
          ix86-linux2.[2-6]* )
              echo "yes" | sh $RPM_SOURCE_DIR/j2sdk-%{V_lnx_dist}-linux-i586.bin >/dev/null
              mv jdk%{V_lnx_fsys} %{name}
              ;;
          sparc64-solaris2.[6-9]* )
              echo "yes" | sh $RPM_SOURCE_DIR/j2sdk-%{V_sol_dist}-solaris-sparc.sh >/dev/null
              mv j2sdk%{V_sol_fsys} %{name}
              ;;
          * )
              echo "Sorry, unsupported architecture '%{l_target}'" 1>&2
              exit 1
              ;;
      esac
    )

    #   post-adjustments to installation area
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/%{name}/demo 2>/dev/null || true
    cp $RPM_BUILD_ROOT%{l_prefix}/libexec/%{name}/man/man1/* \
       $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/%{name}/man 2>/dev/null || true

    #   activate binaries
    ( cd $RPM_BUILD_ROOT%{l_prefix}/bin
      for bin in appletviewer awt_robot extcheck idlj jar jarsigner java \
          javac javadoc javah javap jdb keytool native2ascii \
          oldjava oldjavac oldjdb policytool rmic rmid rmiregistry \
          serialver tnameserv; do
          ln -s ../libexec/%{name}/bin/$bin .
      done
      ( echo "#!/bin/sh"
        echo "exec %{l_prefix}/libexec/%{name}/bin/realpath \${1+\"\$@\"}"
      ) >realpath
      chmod 755 realpath
    )

    #   install run-command script
    %{l_shtool} install -c -m 755 -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE rc.%{name}} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

