lib/scripts/getsettings
author wenzelm
Tue Apr 17 23:24:46 2012 +0200 (2012-04-17)
changeset 47525 9c8a1b9c0630
parent 47490 f4348634595b
child 47661 012a887997f3
permissions -rw-r--r--
retain ISABELLE_HOME_WINDOWS which is useful for jEdit to fold file names symbolically, but without DOS expansion that causes problems with Cygwin/Posix roundtrip (cf. 5a7903ba2dac);
     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 -w "$(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   if [ -z "$ISABELLE_JDK_HOME" ]; then
    99     echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
   100     return 127
   101   else
   102     local PRG="$1"; shift
   103     "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
   104   fi
   105 }
   106 
   107 #robust invocation via SCALA_HOME
   108 function isabelle_scala () {
   109   if [ -z "$ISABELLE_JDK_HOME" ]; then
   110     echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
   111     return 127
   112   elif [ -z "$SCALA_HOME" ]; then
   113     echo "Unknown SCALA_HOME -- Scala unavailable" >&2
   114     return 127
   115   else
   116     local PRG="$1"; shift
   117     "$SCALA_HOME/bin/$PRG" "$@"
   118   fi
   119 }
   120 
   121 #CLASSPATH convenience
   122 function classpath () {
   123   for X in "$@"
   124   do
   125     if [ -z "$CLASSPATH" ]; then
   126       CLASSPATH="$X"
   127     else
   128       CLASSPATH="$X:$CLASSPATH"
   129     fi
   130   done
   131   export CLASSPATH
   132 }
   133 
   134 #arrays
   135 function splitarray ()
   136 {
   137   SPLITARRAY=()
   138   local IFS="$1"; shift
   139   for X in $*
   140   do
   141     SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
   142   done
   143 }
   144 
   145 #nested components
   146 ISABELLE_COMPONENTS=""
   147 function init_component ()
   148 {
   149   local COMPONENT="$1"
   150   case "$COMPONENT" in
   151     /*) ;;
   152     *)
   153       echo >&2 "Absolute component path required: \"$COMPONENT\""
   154       exit 2
   155       ;;
   156   esac
   157 
   158   if [ ! -d "$COMPONENT" ]; then
   159     echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
   160     exit 2
   161   elif [ -z "$ISABELLE_COMPONENTS" ]; then
   162     ISABELLE_COMPONENTS="$COMPONENT"
   163   else
   164     ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
   165   fi
   166   if [ -f "$COMPONENT/etc/settings" ]; then
   167     source "$COMPONENT/etc/settings"
   168     local RC="$?"
   169     if [ "$RC" -ne 0 ]; then
   170       echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
   171       exit 2
   172     fi
   173   fi
   174   if [ -f "$COMPONENT/etc/components" ]; then
   175     {
   176       while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
   177       do
   178         case "$REPLY" in
   179           \#* | "") ;;
   180           /*) init_component "$REPLY" ;;
   181           *) init_component "$COMPONENT/$REPLY" ;;
   182         esac
   183       done
   184     } < "$COMPONENT/etc/components"
   185   fi
   186 }
   187 
   188 #main components
   189 init_component "$ISABELLE_HOME"
   190 [ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
   191 
   192 #ML system identifier
   193 if [ -z "$ML_PLATFORM" ]; then
   194   ML_IDENTIFIER="$ML_SYSTEM"
   195 else
   196   ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
   197 fi
   198 
   199 ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
   200 
   201 set +o allexport
   202 
   203 fi