lib/scripts/run-polyml
author wenzelm
Thu Nov 11 18:55:17 2010 +0100 (2010-11-11)
changeset 40480 d695d258dfbc
parent 39619 34952c2423c6
child 40544 34e56a6668ba
permissions -rwxr-xr-x
tuned error message;
wenzelm@10555
     1
#!/usr/bin/env bash
wenzelm@2301
     2
#
wenzelm@26215
     3
# Author: Makarius
wenzelm@2314
     4
#
wenzelm@26215
     5
# Poly/ML 5.1/5.2 startup script.
wenzelm@9977
     6
wenzelm@31317
     7
export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
wenzelm@2301
     8
wenzelm@2301
     9
wenzelm@2301
    10
## diagnostics
wenzelm@2301
    11
wenzelm@2349
    12
function fail_out()
wenzelm@2301
    13
{
wenzelm@2349
    14
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
wenzelm@2301
    15
  exit 2
wenzelm@2301
    16
}
wenzelm@2301
    17
wenzelm@10206
    18
function check_file()
wenzelm@5063
    19
{
wenzelm@5063
    20
  if [ ! -f "$1" ]; then
wenzelm@5063
    21
    echo "Unable to locate $1" >&2
wenzelm@10206
    22
    echo "Please check your ML system settings!" >&2
wenzelm@5063
    23
    exit 2
wenzelm@5063
    24
  fi
wenzelm@5063
    25
}
wenzelm@5063
    26
wenzelm@2301
    27
wenzelm@26215
    28
## compiler executables and libraries
wenzelm@16374
    29
wenzelm@21356
    30
POLY="$ML_HOME/poly"
wenzelm@10206
    31
check_file "$POLY"
wenzelm@2301
    32
wenzelm@26215
    33
if [ "$(basename "$ML_HOME")" = bin ]; then
wenzelm@26215
    34
  POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
wenzelm@16392
    35
else
wenzelm@26215
    36
  POLYLIB="$ML_HOME"
wenzelm@16392
    37
fi
wenzelm@10206
    38
wenzelm@26215
    39
export LD_LIBRARY_PATH="$POLYLIB:$LD_LIBRARY_PATH"
wenzelm@26215
    40
export DYLD_LIBRARY_PATH="$POLYLIB:$DYLD_LIBRARY_PATH"
wenzelm@9765
    41
wenzelm@9765
    42
wenzelm@2301
    43
## prepare databases
wenzelm@2301
    44
wenzelm@2301
    45
if [ -z "$INFILE" ]; then
wenzelm@26215
    46
  INIT=""
wenzelm@26215
    47
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
wenzelm@10105
    48
else
wenzelm@26215
    49
  check_file "$INFILE"
wenzelm@40480
    50
  INIT="(Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.SaveState.loadState \"$INFILE\" handle Fail msg => (TextIO.output (TextIO.stdErr, msg ^ \": $INFILE\\n\"); OS.Process.exit OS.Process.failure));"
wenzelm@26215
    51
  EXIT=""
wenzelm@2301
    52
fi
wenzelm@2301
    53
wenzelm@2301
    54
if [ -z "$OUTFILE" ]; then
wenzelm@39619
    55
  COMMIT='fun commit () = false;'
wenzelm@39619
    56
  MLEXIT=""
wenzelm@2301
    57
else
wenzelm@31317
    58
  COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
wenzelm@26215
    59
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
wenzelm@39619
    60
  MLEXIT="commit();"
wenzelm@2301
    61
fi
wenzelm@2301
    62
wenzelm@2301
    63
wenzelm@2301
    64
## run it!
wenzelm@2301
    65
wenzelm@26215
    66
MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
wenzelm@26215
    67
wenzelm@16254
    68
if [ -z "$TERMINATE" ]; then
wenzelm@16254
    69
  FEEDER_OPTS=""
wenzelm@16254
    70
else
wenzelm@16254
    71
  FEEDER_OPTS="-q"
wenzelm@16254
    72
fi
wenzelm@16254
    73
wenzelm@26215
    74
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
wenzelm@26215
    75
  { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
wenzelm@9789
    76
RC="$?"
wenzelm@2301
    77
wenzelm@4505
    78
[ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
wenzelm@2301
    79
wenzelm@9789
    80
exit "$RC"
wenzelm@40480
    81
wenzelm@40480
    82
#:wrap=soft:maxLineLen=100: