lib/scripts/run-polyml
author wenzelm
Thu Mar 06 19:21:26 2008 +0100 (2008-03-06)
changeset 26215 94d32a7cd0fb
parent 25123 8831ca91f43f
child 29145 b1c6f4563df7
permissions -rwxr-xr-x
rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm@10555
     1
#!/usr/bin/env bash
wenzelm@2301
     2
#
wenzelm@2314
     3
# $Id$
wenzelm@26215
     4
# Author: Makarius
wenzelm@2314
     5
#
wenzelm@26215
     6
# Poly/ML 5.1/5.2 startup script.
wenzelm@9977
     7
wenzelm@10105
     8
export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
wenzelm@2301
     9
wenzelm@2301
    10
wenzelm@2301
    11
## diagnostics
wenzelm@2301
    12
wenzelm@2349
    13
function fail_out()
wenzelm@2301
    14
{
wenzelm@2349
    15
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
wenzelm@2301
    16
  exit 2
wenzelm@2301
    17
}
wenzelm@2301
    18
wenzelm@10206
    19
function check_file()
wenzelm@5063
    20
{
wenzelm@5063
    21
  if [ ! -f "$1" ]; then
wenzelm@5063
    22
    echo "Unable to locate $1" >&2
wenzelm@10206
    23
    echo "Please check your ML system settings!" >&2
wenzelm@5063
    24
    exit 2
wenzelm@5063
    25
  fi
wenzelm@5063
    26
}
wenzelm@5063
    27
wenzelm@2301
    28
wenzelm@26215
    29
## compiler executables and libraries
wenzelm@16374
    30
wenzelm@21356
    31
POLY="$ML_HOME/poly"
wenzelm@10206
    32
check_file "$POLY"
wenzelm@2301
    33
wenzelm@26215
    34
if [ "$(basename "$ML_HOME")" = bin ]; then
wenzelm@26215
    35
  POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
wenzelm@16392
    36
else
wenzelm@26215
    37
  POLYLIB="$ML_HOME"
wenzelm@16392
    38
fi
wenzelm@10206
    39
wenzelm@26215
    40
export LD_LIBRARY_PATH="$POLYLIB:$LD_LIBRARY_PATH"
wenzelm@26215
    41
export DYLD_LIBRARY_PATH="$POLYLIB:$DYLD_LIBRARY_PATH"
wenzelm@9765
    42
wenzelm@9765
    43
wenzelm@2301
    44
## prepare databases
wenzelm@2301
    45
wenzelm@2301
    46
if [ -z "$INFILE" ]; then
wenzelm@26215
    47
  INIT=""
wenzelm@26215
    48
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
wenzelm@10105
    49
else
wenzelm@26215
    50
  check_file "$INFILE"
wenzelm@26215
    51
  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));"
wenzelm@26215
    52
  EXIT=""
wenzelm@2301
    53
fi
wenzelm@2301
    54
wenzelm@2301
    55
if [ -z "$OUTFILE" ]; then
wenzelm@26215
    56
  COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
wenzelm@2301
    57
else
wenzelm@26215
    58
  if [ -z "$COMPRESS" ]; then
wenzelm@26215
    59
    COMMIT="fun commit () = (TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
wenzelm@26215
    60
  else
wenzelm@26215
    61
    COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
wenzelm@26215
    62
  fi
wenzelm@26215
    63
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
wenzelm@2301
    64
fi
wenzelm@2301
    65
wenzelm@2301
    66
wenzelm@2301
    67
## run it!
wenzelm@2301
    68
wenzelm@26215
    69
MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
wenzelm@26215
    70
MLEXIT="commit();"
wenzelm@26215
    71
wenzelm@16254
    72
if [ -z "$TERMINATE" ]; then
wenzelm@16254
    73
  FEEDER_OPTS=""
wenzelm@16254
    74
else
wenzelm@16254
    75
  FEEDER_OPTS="-q"
wenzelm@16254
    76
fi
wenzelm@16254
    77
wenzelm@26215
    78
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
wenzelm@26215
    79
  { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
wenzelm@9789
    80
RC="$?"
wenzelm@2301
    81
wenzelm@4505
    82
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
wenzelm@2301
    83
wenzelm@9789
    84
exit "$RC"