lib/scripts/run-polyml-5.0
author wenzelm
Sat, 20 Oct 2007 20:32:23 +0200
changeset 25124 a7dd8d3bf969
parent 24480 97c0ef49fa8f
child 26213 3a190cb91c6c
permissions -rwxr-xr-x
maintain PolyML.Compiler.printInAlphabeticalOrder in polyml.ML;
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
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    55
if [ -z "$OUTFILE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    56
  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
    57
else
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    58
  if [ -z "$COMPRESS" ]; then
24296
3479a9fe73e0 removed signal setup from root function to on-entry hook;
wenzelm
parents: 22253
diff changeset
    59
    COMMIT="fun commit () = (TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", PolyML.rootFunction); true);"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    60
  else
24296
3479a9fe73e0 removed signal setup from root function to on-entry hook;
wenzelm
parents: 22253
diff changeset
    61
    COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", PolyML.rootFunction); true);"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    62
  fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    63
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    64
  rm -f "${OUTFILE}.o" || fail_out
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    65
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    66
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    67
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    68
## run it!
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    69
25124
a7dd8d3bf969 maintain PolyML.Compiler.printInAlphabeticalOrder in polyml.ML;
wenzelm
parents: 24480
diff changeset
    70
MLTEXT="$EXIT $COMMIT $MLTEXT"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    71
MLEXIT="commit();"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    72
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    73
if [ -z "$TERMINATE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    74
  FEEDER_OPTS=""
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    75
else
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    76
  FEEDER_OPTS="-q"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    77
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    78
21713
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    79
if [ "$PRG" = "$POLY" ]; then
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    80
  "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
21736
ccb2346ee416 hardwired option -q;
wenzelm
parents: 21713
diff changeset
    81
    { read FPID; "$PRG" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
21713
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    82
else
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    83
  "$ISABELLE_HOME/lib/scripts/feeder" -p -t "$MLEXIT" $FEEDER_OPTS | \
21736
ccb2346ee416 hardwired option -q;
wenzelm
parents: 21713
diff changeset
    84
    { read FPID; "$PRG" -q $ML_OPTIONS "$MLTEXT"; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
21713
85722dc0fc81 more careful evaluation of ML text, prevents spurious output;
wenzelm
parents: 21711
diff changeset
    85
fi
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    86
RC="$?"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    87
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    88
if [ -n "$OUTFILE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    89
  if [ -e "${OUTFILE}.o" ]; then
24480
97c0ef49fa8f renamed POLYML_LINK_OPTIONS to POLY_LINK_OPTIONS;
wenzelm
parents: 24479
diff changeset
    90
    cc -o "$OUTFILE" "${OUTFILE}.o" -L"$POLYLIB" -lpolymain -lpolyml $POLY_LINK_OPTIONS || fail_out
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    91
    rm -f "${OUTFILE}.o"
21711
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    92
    [ -e "${OUTFILE}.exe" ] && mv "${OUTFILE}.exe" "$OUTFILE"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    93
  fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    94
  [ -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    95
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    96
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    97
exit "$RC"