lib/scripts/getsettings
author wenzelm
Thu Mar 01 14:42:05 2012 +0100 (2012-03-01)
changeset 46741 a29006291f2b
parent 45094 a43694a0b726
child 47115 1a05adae1cc9
permissions -rw-r--r--
more tolerant cygpath invocation, allow empty CLASSPATH;
     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 #CLASSPATH convenience
    93 function classpath () {
    94   for X in "$@"
    95   do
    96     if [ -z "$CLASSPATH" ]; then
    97       CLASSPATH="$X"
    98     else
    99       CLASSPATH="$X:$CLASSPATH"
   100     fi
   101   done
   102   export CLASSPATH
   103 }
   104 
   105 #arrays
   106 function splitarray ()
   107 {
   108   SPLITARRAY=()
   109   local IFS="$1"; shift
   110   for X in $*
   111   do
   112     SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
   113   done
   114 }
   115 
   116 #nested components
   117 ISABELLE_COMPONENTS=""
   118 function init_component ()
   119 {
   120   local COMPONENT="$1"
   121   case "$COMPONENT" in
   122     /*) ;;
   123     *)
   124       echo >&2 "Absolute component path required: \"$COMPONENT\""
   125       exit 2
   126       ;;
   127   esac
   128 
   129   if [ ! -d "$COMPONENT" ]; then
   130     echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
   131     exit 2
   132   elif [ -z "$ISABELLE_COMPONENTS" ]; then
   133     ISABELLE_COMPONENTS="$COMPONENT"
   134   else
   135     ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
   136   fi
   137   if [ -f "$COMPONENT/etc/settings" ]; then
   138     source "$COMPONENT/etc/settings"
   139     local RC="$?"
   140     if [ "$RC" -ne 0 ]; then
   141       echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
   142       exit 2
   143     fi
   144   fi
   145   if [ -f "$COMPONENT/etc/components" ]; then
   146     {
   147       while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
   148       do
   149         case "$REPLY" in
   150           \#* | "") ;;
   151           /*) init_component "$REPLY" ;;
   152           *) init_component "$COMPONENT/$REPLY" ;;
   153         esac
   154       done
   155     } < "$COMPONENT/etc/components"
   156   fi
   157 }
   158 
   159 #main components
   160 init_component "$ISABELLE_HOME"
   161 [ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
   162 
   163 #ML system identifier
   164 if [ -z "$ML_PLATFORM" ]; then
   165   ML_IDENTIFIER="$ML_SYSTEM"
   166 else
   167   ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
   168 fi
   169 
   170 ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
   171 
   172 set +o allexport
   173 
   174 fi