lib/scripts/run-polyml-5.0
author wenzelm
Wed, 14 May 2008 11:05:10 +0200
changeset 26882 9e824d8f4512
parent 26375 234f10289d97
child 29145 b1c6f4563df7
permissions -rwxr-xr-x
renamed Position.path to Path.position; added line_file, ignore empty name;
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
#
26213
3a190cb91c6c tuned comment;
wenzelm
parents: 25124
diff changeset
     6
# Poly/ML 5.0 startup script.
21653
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
26375
234f10289d97 back to feeder -- Isabelle ML setup no longer evaluates command line;
wenzelm
parents: 26213
diff changeset
    79
"$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
234f10289d97 back to feeder -- Isabelle ML setup no longer evaluates command line;
wenzelm
parents: 26213
diff changeset
    80
  { read FPID; "$PRG" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    81
RC="$?"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    82
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    83
if [ -n "$OUTFILE" ]; then
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    84
  if [ -e "${OUTFILE}.o" ]; then
24480
97c0ef49fa8f renamed POLYML_LINK_OPTIONS to POLY_LINK_OPTIONS;
wenzelm
parents: 24479
diff changeset
    85
    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
    86
    rm -f "${OUTFILE}.o"
21711
dfac729d3066 root function: restore default interrupt handler;
wenzelm
parents: 21653
diff changeset
    87
    [ -e "${OUTFILE}.exe" ] && mv "${OUTFILE}.exe" "$OUTFILE"
21653
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    88
  fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    89
  [ -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    90
fi
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    91
219924615db6 setup for polyml-5.0;
wenzelm
parents:
diff changeset
    92
exit "$RC"