#!/usr/bin/env bash
#
# Author: Makarius
#
# build-jars - build Isabelle/Scala
#
# Requires proper Isabelle settings environment.
## sources
declare -a SOURCES=(
Concurrent/future.scala
Concurrent/simple_thread.scala
Concurrent/volatile.scala
General/exn.scala
General/timing.scala
General/linear_set.scala
General/markup.scala
General/path.scala
General/position.scala
General/pretty.scala
General/scan.scala
General/sha1.scala
General/symbol.scala
General/xml.scala
General/xml_data.scala
General/yxml.scala
Isar/keyword.scala
Isar/outer_syntax.scala
Isar/parse.scala
Isar/token.scala
PIDE/command.scala
PIDE/document.scala
PIDE/isar_document.scala
PIDE/markup_tree.scala
PIDE/text.scala
System/cygwin.scala
System/download.scala
System/event_bus.scala
System/gui_setup.scala
System/isabelle_charset.scala
System/isabelle_process.scala
System/isabelle_syntax.scala
System/isabelle_system.scala
System/platform.scala
System/session.scala
System/session_manager.scala
System/standard_system.scala
System/swing_thread.scala
Thy/completion.scala
Thy/html.scala
Thy/thy_header.scala
Thy/thy_info.scala
Thy/thy_load.scala
Thy/thy_syntax.scala
library.scala
package.scala
)
## diagnostics
PRG="$(basename "$0")"
function usage()
{
echo
echo "Usage: isabelle $PRG [OPTIONS]"
echo
echo " Options are:"
echo " -f fresh build"
echo
exit 1
}
function fail()
{
echo "$1" >&2
exit 2
}
[ -z "$ISABELLE_HOME" ] && fail "Missing Isabelle settings environment"
[ -z "$SCALA_HOME" ] && fail "Unknown SCALA_HOME -- Scala unavailable"
## process command line
# options
FRESH=""
while getopts "f" OPT
do
case "$OPT" in
f)
FRESH=true
;;
\?)
usage
;;
esac
done
shift $(($OPTIND - 1))
# args
[ "$#" -ne 0 ] && usage
# build
TARGET_DIR="$ISABELLE_HOME/lib/classes"
TARGET="$TARGET_DIR/ext/Pure.jar"
declare -a UPDATED=()
if [ -n "$FRESH" ]; then
OUTDATED=true
else
OUTDATED=false
if [ ! -e "$TARGET" ]; then
OUTDATED=true
else
for DEP in "${SOURCES[@]}"
do
[ ! -e "$DEP" ] && fail "Missing file: $DEP"
[ "$DEP" -nt "$TARGET" ] && {
OUTDATED=true
UPDATED["${#UPDATED[@]}"]="$DEP"
}
done
fi
fi
if [ "$OUTDATED" = true ]
then
echo "###"
echo "### Building Isabelle/Scala layer ..."
echo "###"
[ "${#UPDATED[@]}" -gt 0 ] && {
echo "Changed files:"
for FILE in "${UPDATED[@]}"
do
echo " $FILE"
done
}
rm -rf classes && mkdir classes
"$SCALA_HOME/bin/scalac" -unchecked -deprecation -d classes -target:jvm-1.5 "${SOURCES[@]}" || \
fail "Failed to compile sources"
mkdir -p "$TARGET_DIR/ext" || fail "Failed to create directory $TARGET_DIR/ext"
pushd classes >/dev/null
CHARSET_SERVICE="META-INF/services/java.nio.charset.spi.CharsetProvider"
mkdir -p "$(dirname "$CHARSET_SERVICE")"
echo isabelle.Isabelle_Charset_Provider > "$CHARSET_SERVICE"
jar cfe "$(jvmpath "$TARGET")" isabelle.GUI_Setup META-INF isabelle || \
fail "Failed to produce $TARGET"
cp "$SCALA_HOME/lib/scala-swing.jar" "$SCALA_HOME/lib/scala-library.jar" "$TARGET_DIR/ext"
popd >/dev/null
rm -rf classes
fi