#!/bin/sh
#
# $Id: run-polyml-5.0,v 1.2 2006/12/08 21:18:35 wenzelm Exp $
# Author: Makarius
#
# Poly/ML startup script (for 5.0)
## diagnostics
fail_out()
{
echo "Unable to create output heap file: \"$OUTFILE\"" >&2
exit 2
}
check_file()
{
if [ ! -f "$1" ]; then
echo "Unable to locate $1" >&2
echo "Please check your ML system settings!" >&2
exit 2
fi
}
## compiler executables and libraries
POLY="$ML_HOME/poly"
check_file "$POLY"
if [ "$(basename "$ML_HOME")" = bin ]; then
POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
else
POLYLIB="$ML_HOME"
fi
export LD_LIBRARY_PATH="$POLYLIB:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="$POLYLIB:$DYLD_LIBRARY_PATH"
## prepare databases
if [ -z "$INFILE" ]; then
EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
else
check_file "$INFILE"
POLY="$INFILE"
EXIT=""
fi
ROOT_FUNCTION="fn () => (Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.rootFunction ())"
if [ -z "$OUTFILE" ]; then
COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
else
if [ -z "$COMPRESS" ]; then
COMMIT="fun commit () = (TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", $ROOT_FUNCTION); true);"
else
COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", $ROOT_FUNCTION); true);"
fi
[ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
rm -f "${OUTFILE}.o" || fail_out
fi
## run it!
MLTEXT="PolyML.Compiler.printInAlphabeticalOrder := false; $EXIT $COMMIT $MLTEXT"
MLEXIT="commit();"
if [ -z "$TERMINATE" ]; then
FEEDER_OPTS=""
else
FEEDER_OPTS="-q"
fi
SAVE_INFILE="$INFILE"
SAVE_OUTFILE="$OUTFILE"
SAVE_MLTEXT="$MLTEXT"
SAVE_NOWRITE="$NOWRITE"
unset INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
INFILE="$SAVE_INFILE"
OUTFILE="$SAVE_OUTFILE"
MLTEXT="$SAVE_MLTEXT"
NOWRITE="$SAVE_NOWRITE"
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
{ read FPID; "$POLY" $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
RC="$?"
if [ -n "$OUTFILE" ]; then
if [ -e "${OUTFILE}.o" ]; then
cc -o "$OUTFILE" "${OUTFILE}.o" -L"$POLYLIB" -lpolymain -lpolyml -lstdc++ || fail_out
rm -f "${OUTFILE}.o"
[ -e "${OUTFILE}.exe" ] && mv "${OUTFILE}.exe" "$OUTFILE"
fi
[ -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
fi
exit "$RC"
syntax highlighted by Code2HTML, v. 0.9.1