#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../ibm-jre-142/java-ibm-conf.in
# Copyright (C) 2006 - 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2005 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

# Remember the type of package (jre or jdk)
java_pkg_type=$1

# Prevent executing normal make and install build steps.
# This package has custom make and install.
makeopt=
makeinstopt=

# Make prefix same a java_home. This way artifacts like the bin, lib
# and doc directory are created at the proper level.
. $base/package/*/*/java-jdk-conf.in $java_pkg_type

# The archive to be installed/patched depends on the
# current architecture.
case $arch in
	x86)		srctar="`match_source_file x86.t`" ;
			if [ -z "$srctar" ]; then
				srctar="`match_source_file 386.t`";
			fi ;;
	x86-64)		srctar="`match_source_file x86_64`" ;;
	powerpc64)	srctar="`match_source_file ppc64`" ;;
	powerpc)	srctar="`match_source_file ppc`" ;;
esac

# Make sure there is a file to be patched. If not we
# apparently do not support the current architecture.
[ "$srctar" ] || abort "No binary for this architecture ($arch) detected!"


# Custom installation.
java_postmake() {
	if [ $java_pkg_type == jre ]; then
		# Move the contents of the jre directory up one dir.
		for entry in $(ls -A jre); do
			mv jre/$entry .
		done
		rm -rf jre
	fi

	# Copy the extracted archive to the current prefix location.
	# But make sure to preserve any possible links.
	tar -c {.,}[a-zA-Z0-9]* | tar -x -C /$prefix
}

hook_add postmake 5 java_postmake