##
##  java-gcj.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  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:         java-gcj
Summary:      GCJ/GIJ based Java Tool Chain
URL:          http://www.openpkg.org/
Vendor:       OpenPKG Project
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Language
License:      GPL
Version:      1.4.2
Release:      20080101

#   list of sources
Source0:      java-gcj.txt

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
PreReq:       java
BuildPreReq:  gcc >= 4.2, gcc::with_java = yes, ecj, fastjar, gjdoc
PreReq:       gcc >= 4.2, gcc::with_java = yes, ecj, fastjar, gjdoc

%description
    This is a glue package to provide a minimum Sun Java JDK/JRE like
    command interface to the GCJ/GIJ based Java tool chain and their
    companion tools. It is *NOT* a complete JDK/JRE, but at least
    provides the most important tools for compiling and running non-GUI
    Java 1.4 applications.

%track

%prep
    %setup -q -T -c

%build

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/bin \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/include \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/lib \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/jre/bin \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/jre/lib

    #   provide JDK replacements
    for spec in \
        appletviewer:gappletviewer \
        jar:fastjar \
        jarsigner:gjarsigner \
        java:gij \
        javac:ecj \
        javadoc:gjdoc \
        javah:gcjh \
        keytool:gkeytool \
        rmic:grmic \
        rmiregistry:grmiregistry \
    ; do
        eval `echo "$spec" | sed -e 's/^\(.*\):\(.*\)$/dst=\1; src=\2/'`
        %{l_shtool} mkln -s \
            $RPM_BUILD_ROOT%{l_prefix}/bin/$src \
            $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/bin/$dst
    done

    #   provide JRE replacements
    for spec in \
        java:gij \
        keytool:gkeytool \
        rmic:grmic \
        rmiregistry:grmiregistry \
    ; do
        eval `echo "$spec" | sed -e 's/^\(.*\):\(.*\)$/dst=\1; src=\2/'`
        %{l_shtool} mkln -s \
            $RPM_BUILD_ROOT%{l_prefix}/bin/$src \
            $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/jre/bin/$dst
    done

    #   provide JDK C headers
    gcj_includedir=`gcj -print-libgcc-file-name | sed -e 's;/[^/]*$;/include;'`
    for header in \
        jawt.h \
        jawt_md.h \
        jni.h \
        jni_md.h \
        jvmpi.h \
    ; do
        %{l_shtool} mkln -s \
            $RPM_BUILD_ROOT$gcj_includedir/$header \
            $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/include/$header
    done

    #   remember particular toolkit platform identification
    version=`(%{l_prefix}/bin/gij -version; echo "") 2>/dev/null | sed -e '1q' | \
        sed -e 's;^;X;' -e 's;^X.*"\([0-9][0-9.]*\)".*$;\1;' -e 's;^X.*;0.0.0;'`
    echo "gnu-gcj-$version" >$RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/PLATFORM

    #   install a simple README document
    %{l_shtool} install -c -m 644 \
        %{SOURCE java-gcj.txt} $RPM_BUILD_ROOT%{l_prefix}/libexec/java-gcj/README

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

%files -f files

%clean

%post
    #   unconditionally (re)register
    platform=`cat $RPM_INSTALL_ROOT/libexec/java-gcj/PLATFORM 2>/dev/null`
    if [ ".$platform" != . ]; then
        $RPM_INSTALL_PREFIX/bin/java-toolkit --register="$platform:$RPM_INSTALL_PREFIX/libexec/java-gcj"
    fi

    #   optionally activate if we are the only toolkit
    if [ ".`$RPM_INSTALL_PREFIX/bin/java-toolkit --list | wc -l | awk '{ print $1; }'`" = .1 ]; then
        $RPM_INSTALL_PREFIX/bin/java-toolkit --activate="$platform"
    fi

%preun
    #   unconditionally unregister
    platform=`cat $RPM_INSTALL_ROOT/libexec/java-gcj/PLATFORM 2>/dev/null`
    if [ ".$platform" != . ]; then
        $RPM_INSTALL_PREFIX/bin/java-toolkit --unregister="$platform"
    fi

