lib/scripts/run-polyml
author wenzelm
Mon, 16 Feb 2009 21:23:33 +0100
changeset 29758 7a3b5bbed313
parent 29145 b1c6f4563df7
child 31315 3c7b40548a84
permissions -rwxr-xr-x
removed rudiments of glossary;

#!/usr/bin/env bash
#
# Author: Makarius
#
# Poly/ML 5.1/5.2 startup script.

export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE


## diagnostics

function fail_out()
{
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
  exit 2
}

function 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
  INIT=""
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
else
  check_file "$INFILE"
  INIT="(Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.SaveState.loadState \"$INFILE\" handle Fail msg => (TextIO.output (TextIO.stdErr, msg ^ \"\\n\"); OS.Process.exit OS.Process.failure));"
  EXIT=""
fi

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.SaveState.saveState \"$OUTFILE\"; true);"
  else
    COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
  fi
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
fi


## run it!

MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
MLEXIT="commit();"

if [ -z "$TERMINATE" ]; then
  FEEDER_OPTS=""
else
  FEEDER_OPTS="-q"
fi

"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
  { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
RC="$?"

[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"

exit "$RC"