#!/usr/bin/env bash
## diagnostics
PRG="$(basename "$0")"
THIS="$(cd $(dirname "$0"); pwd)"
function usage()
{
cat <<EOF
Usage: $PRG [VERSION]
Build hybrid Isabelle component for JDK on x86-linux/x86_64-linux.
VERSION is 7u4 for 1.7.0_04 etc.
EOF
exit 1
}
function fail()
{
echo "$1" >&2
exit 2
}
## process command line
# args
VERSION=""
[ "$#" -gt 0 ] && { VERSION="$1"; shift; }
[ "$#" -gt 0 ] && usage
case "$VERSION" in
*u?)
MAJOR="$(echo "$VERSION" | cut -du -f1)"
MINOR="0$(echo "$VERSION" | cut -du -f2)"
;;
*u??)
MAJOR="$(echo "$VERSION" | cut -du -f1)"
MINOR="$(echo "$VERSION" | cut -du -f2)"
;;
*)
fail "Bad version identifier: \"$VERSION\""
;;
esac
FULL_VERSION="1.${MAJOR}.0_${MINOR}"
## main
DIR="jdk${FULL_VERSION}_x86-linux"
mkdir "$DIR" || fail "Cannot create fresh directory: \"$DIR\""
# README
cat >> "$DIR/README" << EOF
This is JDK $FULL_VERSION for x86-linux and x86_64-linux
See http://www.oracle.com/technetwork/java/javase/downloads/index.html
for the original downloads, which are covered by the Oracle Binary
Code License Agreement for Java SE.
EOF
# settings
mkdir "$DIR/etc"
cat >> "$DIR/etc/settings" << EOF
# -*- shell-script -*- :mode=shellscript:
ISABELLE_JDK_HOME="\$COMPONENT/\${ISABELLE_PLATFORM64:-\$ISABELLE_PLATFORM}"
EOF
# content
tar -C "$DIR" -x -f "jdk-$VERSION-linux-i586.tar.gz" || \
fail "Bad archive: \"jdk-$VERSION-linux-i586.tar.gz\""
mv "$DIR/jdk$FULL_VERSION" "$DIR/x86-linux"
tar -C "$DIR" -x -f "jdk-$VERSION-linux-x64.tar.gz" || \
fail "Bad archive: \"jdk-$VERSION-linux-x64.tar.gz\""
mv "$DIR/jdk$FULL_VERSION" "$DIR/x86_64-linux"
(
cd "$DIR/x86-linux"
for FILE in $(find . -type f)
do
if cmp -s "$FILE" "../x86_64-linux/$FILE"
then
ln -f "$FILE" "../x86_64-linux/$FILE"
fi
done
)
# create archive
tar -cz -f "${DIR}.tar.gz" "$DIR" && rm -rf "$DIR"