lib/scripts/getsettings
author wenzelm
Thu Sep 12 14:32:02 2013 +0200 (2013-09-12)
changeset 53580 ffc926553ec5
parent 53576 793a429c63e7
child 53913 5ff12177a067
permissions -rwxr-xr-x
reverse orientation of ISABELLE_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 #Cygwin vs. POSIX
    15 if [ "$OSTYPE" = cygwin ]
    16 then
    17   if [ -z "$USER_HOME" ]; then
    18     USER_HOME="$(cygpath -u "$HOMEDRIVE\\$HOMEPATH")"
    19   fi
    20 
    21   ISABELLE_HOME_WINDOWS="$(cygpath -w "$(dirname "$ISABELLE_HOME")")\\$(basename "$ISABELLE_HOME")"
    22   ISABELLE_HOME="$(cygpath -u "$ISABELLE_HOME_WINDOWS")"
    23 
    24   function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
    25   CYGWIN_ROOT="$(jvmpath "/")"
    26 
    27   ISABELLE_CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
    28   unset CLASSPATH
    29 else
    30   if [ -z "$USER_HOME" ]; then
    31     USER_HOME="$HOME"
    32   fi
    33 
    34   function jvmpath() { echo "$@"; }
    35 
    36   ISABELLE_CLASSPATH="$CLASSPATH"
    37   unset CLASSPATH
    38 fi
    39 
    40 export ISABELLE_HOME
    41 
    42 #key executables
    43 ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
    44 ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
    45 
    46 function isabelle ()
    47 {
    48   "$ISABELLE_TOOL" "$@"
    49 }
    50 
    51 #platform
    52 source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
    53 if [ -z "$ISABELLE_PLATFORM" ]; then
    54   echo 1>&2 "Failed to determine hardware and operating system type!"
    55   exit 2
    56 fi
    57 
    58 #Isabelle distribution identifier -- filled in automatically!
    59 ISABELLE_ID=""
    60 [ -z "$ISABELLE_IDENTIFIER" ] && ISABELLE_IDENTIFIER=""
    61 
    62 #sometimes users put strange things in here ...
    63 unset ENV
    64 unset BASH_ENV
    65 
    66 #shared library convenience
    67 function librarypath ()
    68 {
    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 {
    95   if [ -z "$ISABELLE_JDK_HOME" ]; then
    96     echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
    97     return 127
    98   else
    99     local PRG="$1"; shift
   100     "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
   101   fi
   102 }
   103 
   104 #robust invocation via SCALA_HOME
   105 function isabelle_scala ()
   106 {
   107   if [ -z "$ISABELLE_JDK_HOME" ]; then
   108     echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
   109     return 127
   110   elif [ -z "$SCALA_HOME" ]; then
   111     echo "Unknown SCALA_HOME -- Scala unavailable" >&2
   112     return 127
   113   else
   114     local PRG="$1"; shift
   115     "$SCALA_HOME/bin/$PRG" "$@"
   116   fi
   117 }
   118 
   119 #administrative build
   120 if [ -e "$ISABELLE_HOME/Admin/build" ]; then
   121   function isabelle_admin_build ()
   122   {
   123     "$ISABELLE_HOME/Admin/build" "$@"
   124   }
   125 else
   126   function isabelle_admin_build () { return 0; }
   127 fi
   128 
   129 #classpath
   130 function classpath ()
   131 {
   132   for X in "$@"
   133   do
   134     if [ -z "$ISABELLE_CLASSPATH" ]; then
   135       ISABELLE_CLASSPATH="$X"
   136     else
   137       ISABELLE_CLASSPATH="$ISABELLE_CLASSPATH:$X"
   138     fi
   139   done
   140   export ISABELLE_CLASSPATH
   141 }
   142 
   143 #arrays
   144 function splitarray ()
   145 {
   146   SPLITARRAY=()
   147   local IFS="$1"; shift
   148   for X in $*
   149   do
   150     SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
   151   done
   152 }
   153 
   154 
   155 # components
   156 
   157 ISABELLE_COMPONENTS=""
   158 ISABELLE_COMPONENTS_MISSING=""
   159 
   160 #init component tree
   161 function init_component ()
   162 {
   163   local COMPONENT="$1"
   164   case "$COMPONENT" in
   165     /*) ;;
   166     *)
   167       echo >&2 "Absolute component path required: \"$COMPONENT\""
   168       exit 2
   169       ;;
   170   esac
   171 
   172   if [ -d "$COMPONENT" ]; then
   173     if [ -z "$ISABELLE_COMPONENTS" ]; then
   174       ISABELLE_COMPONENTS="$COMPONENT"
   175     else
   176       ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
   177     fi
   178   else
   179     echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
   180     if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
   181       ISABELLE_COMPONENTS_MISSING="$COMPONENT"
   182     else
   183       ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
   184     fi
   185   fi
   186 
   187   if [ -f "$COMPONENT/etc/settings" ]; then
   188     source "$COMPONENT/etc/settings"
   189     local RC="$?"
   190     if [ "$RC" -ne 0 ]; then
   191       echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
   192       exit 2
   193     fi
   194   fi
   195   if [ -f "$COMPONENT/etc/components" ]; then
   196     init_components "$COMPONENT" "$COMPONENT/etc/components"
   197   fi
   198 }
   199 
   200 #init component forest
   201 function init_components ()
   202 {
   203   local BASE="$1"
   204   local CATALOG="$2"
   205 
   206   if [ ! -f "$CATALOG" ]; then
   207     echo >&2 "Bad component catalog file: \"$CATALOG\""
   208     exit 2
   209   fi
   210   {
   211     while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
   212     do
   213       case "$REPLY" in
   214         \#* | "") ;;
   215         /*) init_component "$REPLY" ;;
   216         *) init_component "$BASE/$REPLY" ;;
   217       esac
   218     done
   219   } < "$CATALOG"
   220 }
   221 
   222 #main components
   223 init_component "$ISABELLE_HOME"
   224 [ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
   225 [ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
   226 
   227 
   228 #ML system identifier
   229 if [ -z "$ML_PLATFORM" ]; then
   230   ML_IDENTIFIER="$ML_SYSTEM"
   231 else
   232   ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
   233 fi
   234 
   235 ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
   236 
   237 #enforce JAVA_HOME
   238 export JAVA_HOME="$ISABELLE_JDK_HOME"
   239 
   240 #build condition etc.
   241 case "$ML_SYSTEM" in
   242   polyml*)
   243     ISABELLE_POLYML="true"
   244     ;;
   245   *)
   246     ISABELLE_POLYML=""
   247     ;;
   248 esac
   249 
   250 set +o allexport
   251 
   252 fi