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;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Makarius
     4 #
     5 # Poly/ML 5.1/5.2 startup script.
     6 
     7 export -n INFILE OUTFILE MLTEXT TERMINATE NOWRITE
     8 
     9 
    10 ## diagnostics
    11 
    12 function fail_out()
    13 {
    14   echo "Unable to create output heap file: \"$OUTFILE\"" >&2
    15   exit 2
    16 }
    17 
    18 function check_file()
    19 {
    20   if [ ! -f "$1" ]; then
    21     echo "Unable to locate $1" >&2
    22     echo "Please check your ML system settings!" >&2
    23     exit 2
    24   fi
    25 }
    26 
    27 
    28 ## compiler executables and libraries
    29 
    30 POLY="$ML_HOME/poly"
    31 check_file "$POLY"
    32 
    33 if [ "$(basename "$ML_HOME")" = bin ]; then
    34   POLYLIB="$(cd "$ML_HOME"; cd "$(pwd -P)"; cd ../lib; pwd)"
    35 else
    36   POLYLIB="$ML_HOME"
    37 fi
    38 
    39 export LD_LIBRARY_PATH="$POLYLIB:$LD_LIBRARY_PATH"
    40 export DYLD_LIBRARY_PATH="$POLYLIB:$DYLD_LIBRARY_PATH"
    41 
    42 
    43 ## prepare databases
    44 
    45 if [ -z "$INFILE" ]; then
    46   INIT=""
    47   EXIT="fun exit 0 = (OS.Process.exit OS.Process.success): unit | exit _ = OS.Process.exit OS.Process.failure;"
    48 else
    49   check_file "$INFILE"
    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));"
    51   EXIT=""
    52 fi
    53 
    54 if [ -z "$OUTFILE" ]; then
    55   COMMIT='fun commit () = false;'
    56   MLEXIT=""
    57 else
    58   COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
    59   [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    60   MLEXIT="commit();"
    61 fi
    62 
    63 
    64 ## run it!
    65 
    66 MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
    67 
    68 if [ -z "$TERMINATE" ]; then
    69   FEEDER_OPTS=""
    70 else
    71   FEEDER_OPTS="-q"
    72 fi
    73 
    74 "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
    75   { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
    76 RC="$?"
    77 
    78 [ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
    79 
    80 exit "$RC"
    81 
    82 #:wrap=soft:maxLineLen=100: