lib/scripts/getsettings
author wenzelm
Wed Oct 28 20:49:09 2009 +0100 (2009-10-28)
changeset 33286 1807921b6268
parent 32390 468eff174a77
child 33294 e2a11715aab1
permissions -rw-r--r--
slightly more robust error message;
     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 later on!"
    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 #legacy settings
    25 ISABELLE="$ISABELLE_PROCESS"
    26 ISATOOL="$ISABELLE_TOOL"
    27 
    28 #Isabelle distribution identifier -- filled in automatically!
    29 ISABELLE_IDENTIFIER=""
    30 
    31 #users tend to put strange things in here ...
    32 unset ENV
    33 unset BASH_ENV
    34 
    35 #support easy settings
    36 function choosefrom ()
    37 {
    38   local RESULT=""
    39   local FILE=""
    40 
    41   for FILE in "$@"
    42   do
    43     [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
    44   done
    45 
    46   [ -z "$RESULT" ] && RESULT="$FILE"
    47   echo "$RESULT"
    48 }
    49 
    50 #JVM path wrapper
    51 if [ "$OSTYPE" = cygwin ]; then
    52   CLASSPATH="$(cygpath -u -p "$CLASSPATH")"
    53   function jvmpath() { cygpath -w -p "$@"; }
    54 else
    55   function jvmpath() { echo "$@"; }
    56 fi
    57 HOME_JVM="$HOME"
    58 
    59 #CLASSPATH convenience
    60 function classpath () {
    61   for X in "$@"
    62   do
    63     if [ -z "$CLASSPATH" ]; then
    64       CLASSPATH="$X"
    65     else
    66       CLASSPATH="$CLASSPATH:$X"
    67     fi
    68   done
    69 }
    70 
    71 #arrays
    72 function splitarray ()
    73 {
    74   SPLITARRAY=()
    75   local IFS="$1"; shift
    76   for X in $*
    77   do
    78     SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
    79   done
    80 }
    81 
    82 #nested components
    83 ISABELLE_COMPONENTS=""
    84 function init_component ()
    85 {
    86   local COMPONENT="$1"
    87 
    88   if [ ! -d "$COMPONENT" ]; then
    89     echo >&2 "Bad Isabelle component: \"$COMPONENT"\"
    90     exit 2
    91   elif [ -z "$ISABELLE_COMPONENTS" ]; then
    92     ISABELLE_COMPONENTS="$COMPONENT"
    93   else
    94     ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
    95   fi
    96   if [ -f "$COMPONENT/etc/settings" ]; then
    97     source "$COMPONENT/etc/settings" || exit 2
    98   fi
    99   if [ -f "$COMPONENT/etc/components" ]; then
   100     {
   101       while read; do
   102         case "$REPLY" in
   103           \#* | "") ;;
   104           /*) init_component "$REPLY" ;;
   105           *) init_component "$COMPONENT/$REPLY" ;;
   106         esac
   107       done
   108     } < "$COMPONENT/etc/components"
   109   fi
   110 }
   111 
   112 #main components
   113 init_component "$ISABELLE_HOME"
   114 
   115 [ "$ISABELLE_HOME" -ef "$ISABELLE_HOME_USER" ] && \
   116   { echo >&2 "### ISABELLE_HOME and ISABELLE_HOME_USER must not be the same directory!"; }
   117 [ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
   118 
   119 #ML system identifier
   120 if [ -z "$ML_PLATFORM" ]; then
   121   ML_IDENTIFIER="$ML_SYSTEM"
   122 else
   123   ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
   124 fi
   125 
   126 ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
   127 
   128 set +o allexport
   129 
   130 fi