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