lib/scripts/getsettings
author wenzelm
Sun Apr 01 22:02:14 2012 +0200 (2012-04-01)
changeset 47254 de2fb19683f4
parent 47115 1a05adae1cc9
child 47461 5a7903ba2dac
permissions -rw-r--r--
less brutal return from function, to allow caller to report error;
     1 # -*- shell-script -*- :mode=shellscript:
     2 #
     3 # Author: Markus Wenzel, TU Muenchen
     4 #
     5 # getsettings - bash source script to augment current env.
     6 
     7 if [ -z "$ISABELLE_SETTINGS_PRESENT" ]
     8 then
     9 
    10 set -o allexport
    11 
    12 ISABELLE_SETTINGS_PRESENT=true
    13 
    14 export ISABELLE_HOME
    15 if { echo -n "$ISABELLE_HOME" | fgrep " " >/dev/null; }
    16 then
    17   echo 1>&2 "### White space in ISABELLE_HOME may cause strange problems!"
    18   echo 1>&2 "### ISABELLE_HOME=\"$ISABELLE_HOME\""
    19 fi
    20 
    21 #key executables
    22 ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
    23 ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
    24 
    25 function isabelle ()
    26 {
    27   "$ISABELLE_TOOL" "$@"
    28 }
    29 
    30 #platform
    31 source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
    32 
    33 #Isabelle distribution identifier -- filled in automatically!
    34 ISABELLE_ID=""
    35 ISABELLE_IDENTIFIER=""
    36 
    37 #sometimes users put strange things in here ...
    38 unset ENV
    39 unset BASH_ENV
    40 
    41 #support easy settings
    42 function choosefrom ()
    43 {
    44   local RESULT=""
    45   local FILE=""
    46 
    47   for FILE in "$@"
    48   do
    49     [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
    50   done
    51 
    52   [ -z "$RESULT" ] && RESULT="$FILE"
    53   echo "$RESULT"
    54 }
    55 
    56 #JVM path wrapper
    57 if [ "$OSTYPE" = cygwin ]; then
    58   CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
    59   function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
    60   THIS_CYGWIN="$(jvmpath "/")"
    61 else
    62   function jvmpath() { echo "$@"; }
    63   CLASSPATH="$CLASSPATH"
    64 fi
    65 HOME_JVM="$HOME"
    66 
    67 #shared library convenience
    68 function librarypath () {
    69   for X in "$@"
    70   do
    71     case "$ISABELLE_PLATFORM" in
    72       *-darwin)
    73         if [ -z "$DYLD_LIBRARY_PATH" ]; then
    74           DYLD_LIBRARY_PATH="$X"
    75         else
    76           DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
    77         fi
    78         export DYLD_LIBRARY_PATH
    79         ;;
    80       *)
    81         if [ -z "$LD_LIBRARY_PATH" ]; then
    82           LD_LIBRARY_PATH="$X"
    83         else
    84           LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
    85         fi
    86         export LD_LIBRARY_PATH
    87         ;;
    88     esac
    89   done
    90 }
    91 
    92 #robust invocation via ISABELLE_JDK_HOME
    93 function isabelle_jdk () {
    94   [ -z "$ISABELLE_JDK_HOME" ] && \
    95     { echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2; return 2; }
    96   local PRG="$1"; shift
    97   "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
    98 }
    99 
   100 #robust invocation via SCALA_HOME
   101 function isabelle_scala () {
   102   [ -z "$SCALA_HOME" ] && \
   103     { echo "Unknown SCALA_HOME -- Scala unavailable" >&2; return 2; }
   104   local PRG="$1"; shift
   105   "$SCALA_HOME/bin/$PRG" "$@"
   106 }
   107 
   108 #CLASSPATH convenience
   109 function classpath () {
   110   for X in "$@"
   111   do
   112     if [ -z "$CLASSPATH" ]; then
   113       CLASSPATH="$X"
   114     else
   115       CLASSPATH="$X:$CLASSPATH"
   116     fi
   117   done
   118   export CLASSPATH
   119 }
   120 
   121 #arrays
   122 function splitarray ()
   123 {
   124   SPLITARRAY=()
   125   local IFS="$1"; shift
   126   for X in $*
   127   do
   128     SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
   129   done
   130 }
   131 
   132 #nested components
   133 ISABELLE_COMPONENTS=""
   134 function init_component ()
   135 {
   136   local COMPONENT="$1"
   137   case "$COMPONENT" in
   138     /*) ;;
   139     *)
   140       echo >&2 "Absolute component path required: \"$COMPONENT\""
   141       exit 2
   142       ;;
   143   esac
   144 
   145   if [ ! -d "$COMPONENT" ]; then
   146     echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
   147     exit 2
   148   elif [ -z "$ISABELLE_COMPONENTS" ]; then
   149     ISABELLE_COMPONENTS="$COMPONENT"
   150   else
   151     ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
   152   fi
   153   if [ -f "$COMPONENT/etc/settings" ]; then
   154     source "$COMPONENT/etc/settings"
   155     local RC="$?"
   156     if [ "$RC" -ne 0 ]; then
   157       echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
   158       exit 2
   159     fi
   160   fi
   161   if [ -f "$COMPONENT/etc/components" ]; then
   162     {
   163       while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
   164       do
   165         case "$REPLY" in
   166           \#* | "") ;;
   167           /*) init_component "$REPLY" ;;
   168           *) init_component "$COMPONENT/$REPLY" ;;
   169         esac
   170       done
   171     } < "$COMPONENT/etc/components"
   172   fi
   173 }
   174 
   175 #main components
   176 init_component "$ISABELLE_HOME"
   177 [ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
   178 
   179 #ML system identifier
   180 if [ -z "$ML_PLATFORM" ]; then
   181   ML_IDENTIFIER="$ML_SYSTEM"
   182 else
   183   ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
   184 fi
   185 
   186 ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
   187 
   188 set +o allexport
   189 
   190 fi