lib/scripts/run-polyml-5.0
author wenzelm
Thu May 20 20:20:52 2010 +0200 (2010-05-20)
changeset 37012 106c56e916f8
parent 31317 1f5740424c69
permissions -rwxr-xr-x
enable shell script editor mode;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Makarius
     4 #
     5 # Poly/ML 5.0 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   PRG="$POLY"
    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   PRG="$INFILE"
    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   COMMIT="fun commit () = (PolyML.shareCommonData PolyML.rootFunction; TextIO.output (TextIO.stdOut, \"Exporting $OUTFILE\n\"); PolyML.export (\"$OUTFILE\", PolyML.rootFunction); true);"
    58   [ -f "$OUTFILE" ] && { chmod +w "$OUTFILE" || fail_out; }
    59   rm -f "${OUTFILE}.o" || fail_out
    60 fi
    61 
    62 
    63 ## run it!
    64 
    65 MLTEXT="$EXIT $COMMIT $MLTEXT"
    66 MLEXIT="commit();"
    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; "$PRG" -q $ML_OPTIONS; RC="$?"; kill -HUP "$FPID"; exit "$RC"; }
    76 RC="$?"
    77 
    78 if [ -n "$OUTFILE" ]; then
    79   if [ -e "${OUTFILE}.o" ]; then
    80     cc -o "$OUTFILE" "${OUTFILE}.o" -L"$POLYLIB" -lpolymain -lpolyml $POLY_LINK_OPTIONS || fail_out
    81     rm -f "${OUTFILE}.o"
    82     [ -e "${OUTFILE}.exe" ] && mv "${OUTFILE}.exe" "$OUTFILE"
    83   fi
    84   [ -f "$OUTFILE" -a -n "$NOWRITE" ] && chmod -w "$OUTFILE"
    85 fi
    86 
    87 exit "$RC"