lib/scripts/run-polyml-5.0
author nipkow
Wed Aug 26 19:54:19 2009 +0200 (2009-08-26)
changeset 32416 4ea7648b6ae2
parent 31317 1f5740424c69
permissions -rwxr-xr-x
merged
wenzelm@21653
     1
#!/usr/bin/env bash
wenzelm@21653
     2
#
wenzelm@21653
     3
# Author: Makarius
wenzelm@21653
     4
#
wenzelm@26213
     5
# Poly/ML 5.0 startup script.
wenzelm@21653
     6
wenzelm@31317
     7
export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
wenzelm@21653
     8
wenzelm@21653
     9
wenzelm@21653
    10
## diagnostics
wenzelm@21653
    11
wenzelm@21653
    12
function fail_out()
wenzelm@21653
    13
{
wenzelm@21653
    14
  echo "Unable to create output heap file: \"$OUTFILE\"" >&2
wenzelm@21653
    15
  exit 2
wenzelm@21653
    16
}
wenzelm@21653
    17
wenzelm@21653
    18
function check_file()
wenzelm@21653
    19
{
wenzelm@21653
    20
  if [ ! -f "$1" ]; then
wenzelm@21653
    21
    echo "Unable to locate $1" >&2
wenzelm@21653
    22
    echo "Please check your ML system settings!" >&2
wenzelm@21653
    23
    exit 2
wenzelm@21653
    24
  fi
wenzelm@21653
    25
}
wenzelm@21653
    26
wenzelm@21653
    27
wenzelm@21653
    28
## compiler executables and libraries
wenzelm@21653
    29
wenzelm@21653
    30
POLY="$ML_HOME/poly"
wenzelm@21653
    31
check_file "$POLY"
wenzelm@21653
    32
wenzelm@21653
    33
if [ "$(basename "$ML_HOME")" = bin ]; then
wenzelm@21653
    34
  POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
wenzelm@21653
    35
else
wenzelm@21653
    36
  POLYLIB="$ML_HOME"
wenzelm@21653
    37
fi
wenzelm@21653
    38
wenzelm@21653
    39
export LD_LIBRARY_PATH="$POLYLIB:$LD_LIBRARY_PATH"
wenzelm@21653
    40
export DYLD_LIBRARY_PATH="$POLYLIB:$DYLD_LIBRARY_PATH"
wenzelm@21653
    41
wenzelm@21653
    42
wenzelm@21653
    43
## prepare databases
wenzelm@21653
    44
wenzelm@21653
    45
if [ -z "$INFILE" ]; then
wenzelm@21713
    46
  PRG="$POLY"
wenzelm@21653
    47
  EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
wenzelm@21653
    48
else
wenzelm@21653
    49
  check_file "$INFILE"
wenzelm@21713
    50
  PRG="$INFILE"
wenzelm@21653
    51
  EXIT=""
wenzelm@21653
    52
fi
wenzelm@21653
    53
wenzelm@21653
    54
if [ -z "$OUTFILE" ]; then
wenzelm@21653
    55
  COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
wenzelm@21653
    56
else
wenzelm@31317
    57
  COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", PolyML.rootFunction); true);"
wenzelm@21653
    58
  [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
wenzelm@21653
    59
  rm -f "${OUTFILE}.o" || fail_out
wenzelm@21653
    60
fi
wenzelm@21653
    61
wenzelm@21653
    62
wenzelm@21653
    63
## run it!
wenzelm@21653
    64
wenzelm@25124
    65
MLTEXT="$EXIT $COMMIT $MLTEXT"
wenzelm@21653
    66
MLEXIT="commit();"
wenzelm@21653
    67
wenzelm@21653
    68
if [ -z "$TERMINATE" ]; then
wenzelm@21653
    69
  FEEDER_OPTS=""
wenzelm@21653
    70
else
wenzelm@21653
    71
  FEEDER_OPTS="-q"
wenzelm@21653
    72
fi
wenzelm@21653
    73
wenzelm@26375
    74
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
wenzelm@26375
    75
  { read FPID; "$PRG" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
wenzelm@21653
    76
RC="$?"
wenzelm@21653
    77
wenzelm@21653
    78
if [ -n "$OUTFILE" ]; then
wenzelm@21653
    79
  if [ -e "${OUTFILE}.o" ]; then
wenzelm@24480
    80
    cc -o "$OUTFILE" "${OUTFILE}.o" -L"$POLYLIB" -lpolymain -lpolyml $POLY_LINK_OPTIONS || fail_out
wenzelm@21653
    81
    rm -f "${OUTFILE}.o"
wenzelm@21711
    82
    [ -e "${OUTFILE}.exe" ] && mv "${OUTFILE}.exe" "$OUTFILE"
wenzelm@21653
    83
  fi
wenzelm@21653
    84
  [ -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
wenzelm@21653
    85
fi
wenzelm@21653
    86
wenzelm@21653
    87
exit "$RC"