#!/bin/sh
##########################################################
# Script : openjdk.build
# Purpose: Build OpenJDK/OpenJRE et al for Slackware ARM
#          from Eric Hameleers' unmodified sources.
# Author : Stuart Winter <mozes@slackware.com>
# Version: 1.01
# Date...: 14-Nov-2012
##########################################################

source /usr/share/slackdev/buildkit.sh

CWD=$PWD

# Build & install the deps first:
( cd bootstrap-deps
  ( cd apache-ant && ./apache-ant.SlackBuild && upgradepkg --install-new /tmp/apache-ant-*.t?z )
  ( cd xalan
    sed -i '/slack-required/d' xalan.SlackBuild
    ./xalan.SlackBuild && upgradepkg --install-new /tmp/xalan-*.t?z )
  ( cd xerces
    sed -i '/slack-required/d' xerces.SlackBuild
   ./xerces.SlackBuild && upgradepkg --install-new /tmp/xerces-*.t?z )
)

# Build the run-time dependencies:
( cd rhino
  # Slackware proper does not have 'install/slack-required' files:
  find . -iname '*.slackbuild' -type f -print0 | xargs -0 sed -i 's?cat.*slack-required.*??g'
  ./rhino.SlackBuild && upgradepkg --install-new /tmp/rhino-*.t?z ) 2>&1 | tee $CWD/rhino.build.log

# Source the Apache ANT settings:
. /etc/profile.d/apache-ant.sh

# Build OpenJDK:
( cd openjdk
  # I may have already patched it, in which case ignore the rejected hunk
  patch -r- -p1 < $CWD/slackarm-localpatches/openjdk.SlackBuild.SlackARM.diff 
  BOOTSTRAP=YES ./openjdk.SlackBuild && upgradepkg --install-new /tmp/openjdk-*.t?z ) 2>&1 | tee $CWD/openjdk.build.log

# Set the package type to be txz:
# The OpenJDK/JRE packages are bordering on 100MB, so I'd like to keep them
# using LZMA compression rather than gzipped tar, and since they're in /extra,
# I'm making an exception.  If they go in the main tree, they'll probably switch
# to .tgz:
export PKGTYPE=txz

# Build Iced-Tea web plugin:
# seamonkey (not normally present on the Slackware ARM build servers)
# is needed to build the Iced Tea plugin
upgradepkg --install-new ~/tgzstash/xap/seamonkey-*t?z
( cd icedtea-web
  ./icedtea-web.SlackBuild ) 2>&1 | tee $CWD/icedtea-web.build.log

# Rename the run-time packages to official.  We will abandon the build-time-only
# dependencies; if users want them they can download and build them from alienBOB's
# source repo @ ftp://ftp.slackware.org.uk/people/alien/slackbuilds/
#cd /tmp
#for i in icedtea-*.t?z openjdk-*.t?z openjre-*.t?z rhino-*.t?z ; do
#   mv -fv $i $( echo $i |sed 's?alien??g' )
#done

# Remove the unneeded build-time deps.
# Only Rhino is required for OpenJDK/OpenJRE to run.
removepkg apache-ant xalan xerces

# Manually move these ones since they're not the standard Slackware ARM
# build scripts and I don't have the stomach to modify them at the moment ;-)
echo "******************************************************************"
echo "**** The completed packages are in /tmp ready for migration into *"
echo "**** the source tree                                             *"
cd /tmp
ls -1 icedtea-*.t?z openjdk-*.t?z openjre-*.t?z rhino-*.t?z
echo "******************************************************************"
#EOF
