lib/scripts/run-polyml
author wenzelm
Sat Dec 20 11:55:34 2008 +0100 (2008-12-20)
changeset 29145 b1c6f4563df7
parent 26215 94d32a7cd0fb
child 31315 3c7b40548a84
permissions -rwxr-xr-x
removed Ids;
     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 COPYDB COMPRESS 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 ^ \"\\n\"); OS.Process.exit OS.Process.failure));"
    51   EXIT=""
    52 fi
    53 
    54 if [ -z "$OUTFILE" ]; then
    55   COMMIT='fun commit () = (TextIO.output (TextIO.stdErr, "Error - Database is not opened for writing.\n"); false);'
    56 else
    57   if [ -z "$COMPRESS" ]; then
    58     COMMIT="fun commit () = (TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
    59   else
    60     COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.SaveState.saveState \"$OUTFILE\"; true);"
    61   fi
    62   [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    63 fi
    64 
    65 
    66 ## run it!
    67 
    68 MLTEXT="$INIT $EXIT $COMMIT $MLTEXT"
    69 MLEXIT="commit();"
    70 
    71 if [ -z "$TERMINATE" ]; then
    72   FEEDER_OPTS=""
    73 else
    74   FEEDER_OPTS="-q"
    75 fi
    76 
    77 "$ISABELLE_HOME/lib/scripts/feeder" -p -h "$MLTEXT" -t "$MLEXIT" $FEEDER_OPTS | \
    78   { read FPID; "$POLY" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
    79 RC="$?"
    80 
    81 [ -n "$OUTFILE" -a -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
    82 
    83 exit "$RC"