lib/scripts/run-polyml-5.0
author wenzelm
Fri, 08 Dec 2006 23:25:52 +0100
changeset 21713 85722dc0fc81
parent 21711 dfac729d3066
child 21736 ccb2346ee416
permissions -rwxr-xr-x
more careful evaluation of ML text, prevents spurious output;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     1
#!/usr/bin/env bash
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     2
#
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     3
# $Id$
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     4
# Author: Makarius
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     5
#
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     6
# Poly/ML startup script (for 5.0)
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     7
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     8
export -n INFILE OUTFILE COPYDB COMPRESS MLTEXT TERMINATE NOWRITE
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
     9
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    10
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    11
## diagnostics
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    12
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    13
function fail_out()
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    14
{
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    15
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    16
  exit 2
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    17
}
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    18
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    19
function check_file()
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    20
{
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    21
  if [ ! -f "$1" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    22
    echo "Unable to locate $1" >&2
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    23
    echo "Please check your ML system settings!" >&2
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    24
    exit 2
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    25
  fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    26
}
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    27
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    28
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    29
## compiler executables and libraries
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    30
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    31
POLY="$ML_HOME/poly"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    32
check_file "$POLY"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    33
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    34
if [ "$(basename "$ML_HOME")" = bin ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    35
  POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    36
else
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    37
  POLYLIB="$ML_HOME"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    38
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    39
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    40
export LD_LIBRARY_PATH="$POLYLIB:$LD_LIBRARY_PATH"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    41
export DYLD_LIBRARY_PATH="$POLYLIB:$DYLD_LIBRARY_PATH"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    42
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    43
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    44
## prepare databases
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    45
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    46
if [ -z "$INFILE" ]; then
21713
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    47
  PRG="$POLY"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    48
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    49
else
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    50
  check_file "$INFILE"
21713
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    51
  PRG="$INFILE"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    52
  EXIT=""
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    53
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    54
21711
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    55
ROOT_FUNCTION="fn () => (Signal.signal (2, Signal.SIG_HANDLE (fn _ => Process.interruptConsoleProcesses ())); PolyML.rootFunction ())"
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    56
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    57
if [ -z "$OUTFILE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    58
  COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    59
else
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    60
  if [ -z "$COMPRESS" ]; then
21711
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    61
    COMMIT="fun commit () = (TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", $ROOT_FUNCTION); true);"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    62
  else
21711
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    63
    COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", $ROOT_FUNCTION); true);"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    64
  fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    65
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    66
  rm -f "${OUTFILE}.o" || fail_out
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    67
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    68
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    69
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    70
## run it!
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    71
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    72
MLTEXT="PolyML.Compiler.printInAlphabeticalOrder := false; $EXIT $COMMIT $MLTEXT"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    73
MLEXIT="commit();"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    74
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    75
if [ -z "$TERMINATE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    76
  FEEDER_OPTS=""
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    77
else
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    78
  FEEDER_OPTS="-q"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    79
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    80
21713
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    81
if [ "$PRG" = "$POLY" ]; then
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    82
  "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    83
    { read FPID; "$PRG" $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    84
else
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    85
  "$ISABELLE_HOME/lib/scripts/feeder" -p -t "$MLEXIT" $FEEDER_OPTS | \
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    86
    { read FPID; "$PRG" $ML_OPTIONS "$MLTEXT"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    87
fi
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    88
RC="$?"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    89
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    90
if [ -n "$OUTFILE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    91
  if [ -e "${OUTFILE}.o" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    92
    cc -o "$OUTFILE" "${OUTFILE}.o" -L"$POLYLIB" -lpolymain -lpolyml -lstdc++ || fail_out
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    93
    rm -f "${OUTFILE}.o"
21711
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    94
    [ -e "${OUTFILE}.exe" ] && mv "${OUTFILE}.exe" "$OUTFILE"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    95
  fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    96
  [ -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    97
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    98
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    99
exit "$RC"