lib/scripts/getsettings
author wenzelm
Sun Sep 21 20:22:12 2014 +0200 (2014-09-21)
changeset 58413 22dd971f6938
parent 57411 9444489766a1
child 58640 37f852399a32
permissions -rwxr-xr-x
renamed ISABELLE_POLYML to ML_SYSTEM_POLYML, to avoid overlap with ISABELLE_POLYML_PATH;
     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 #GNU tar (notably on Mac OS X)
    15 if [ -x /usr/bin/gnutar ]; then
    16   function tar() { /usr/bin/gnutar "$@"; }
    17 fi
    18 
    19 #sane environment defaults (notably on Mac OS X)
    20 if [ "$ISABELLE_APP" = true -a -x /usr/libexec/path_helper ]; then
    21   eval $(/usr/libexec/path_helper -s)
    22 fi
    23 
    24 #Cygwin vs. POSIX
    25 if [ "$OSTYPE" = cygwin ]
    26 then
    27   unset INI_DIR
    28 
    29   if [ -z "$USER_HOME" ]; then
    30     USER_HOME="$(cygpath -u "$HOMEDRIVE\\$HOMEPATH")"
    31   fi
    32 
    33   function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
    34   CYGWIN_ROOT="$(jvmpath "/")"
    35 
    36   ISABELLE_CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
    37   unset CLASSPATH
    38 else
    39   if [ -z "$USER_HOME" ]; then
    40     USER_HOME="$HOME"
    41   fi
    42 
    43   function jvmpath() { echo "$@"; }
    44 
    45   ISABELLE_CLASSPATH="$CLASSPATH"
    46   unset CLASSPATH
    47 fi
    48 
    49 export ISABELLE_HOME
    50 
    51 #key executables
    52 ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
    53 ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle_process"
    54 ISABELLE_SCALA_SCRIPT="$ISABELLE_HOME/bin/isabelle_scala_script"
    55 
    56 function isabelle ()
    57 {
    58   "$ISABELLE_TOOL" "$@"
    59 }
    60 
    61 function isabelle_process ()
    62 {
    63   "$ISABELLE_PROCESS" "$@"
    64 }
    65 
    66 function isabelle_scala_script ()
    67 {
    68   "$ISABELLE_SCALA_SCRIPT" "$@"
    69 }
    70 
    71 #platform
    72 source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
    73 if [ -z "$ISABELLE_PLATFORM" ]; then
    74   echo 1>&2 "Failed to determine hardware and operating system type!"
    75   exit 2
    76 fi
    77 
    78 #Isabelle distribution identifier -- filled in automatically!
    79 ISABELLE_ID=""
    80 [ -z "$ISABELLE_IDENTIFIER" ] && ISABELLE_IDENTIFIER=""
    81 
    82 #sometimes users put strange things in here ...
    83 unset ENV
    84 unset BASH_ENV
    85 
    86 #shared library convenience
    87 function librarypath ()
    88 {
    89   for X in "$@"
    90   do
    91     case "$ISABELLE_PLATFORM" in
    92       *-darwin)
    93         if [ -z "$DYLD_LIBRARY_PATH" ]; then
    94           DYLD_LIBRARY_PATH="$X"
    95         else
    96           DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
    97         fi
    98         export DYLD_LIBRARY_PATH
    99         ;;
   100       *)
   101         if [ -z "$LD_LIBRARY_PATH" ]; then
   102           LD_LIBRARY_PATH="$X"
   103         else
   104           LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
   105         fi
   106         export LD_LIBRARY_PATH
   107         ;;
   108     esac
   109   done
   110 }
   111 
   112 #robust invocation via ISABELLE_JDK_HOME
   113 function isabelle_jdk ()
   114 {
   115   if [ -z "$ISABELLE_JDK_HOME" ]; then
   116     echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
   117     return 127
   118   else
   119     local PRG="$1"; shift
   120     "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
   121   fi
   122 }
   123 
   124 #robust invocation via SCALA_HOME
   125 function isabelle_scala ()
   126 {
   127   if [ -z "$ISABELLE_JDK_HOME" ]; then
   128     echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
   129     return 127
   130   elif [ -z "$SCALA_HOME" ]; then
   131     echo "Unknown SCALA_HOME -- Scala unavailable" >&2
   132     return 127
   133   else
   134     local PRG="$1"; shift
   135     "$SCALA_HOME/bin/$PRG" "$@"
   136   fi
   137 }
   138 
   139 #administrative build
   140 if [ -e "$ISABELLE_HOME/Admin/build" ]; then
   141   function isabelle_admin_build ()
   142   {
   143     "$ISABELLE_HOME/Admin/build" "$@"
   144   }
   145 else
   146   function isabelle_admin_build () { return 0; }
   147 fi
   148 
   149 #classpath
   150 function classpath ()
   151 {
   152   for X in "$@"
   153   do
   154     if [ -z "$ISABELLE_CLASSPATH" ]; then
   155       ISABELLE_CLASSPATH="$X"
   156     else
   157       ISABELLE_CLASSPATH="$ISABELLE_CLASSPATH:$X"
   158     fi
   159   done
   160   export ISABELLE_CLASSPATH
   161 }
   162 
   163 #arrays
   164 function splitarray ()
   165 {
   166   SPLITARRAY=()
   167   local IFS="$1"; shift
   168   for X in $*
   169   do
   170     SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
   171   done
   172 }
   173 
   174 
   175 # components
   176 
   177 ISABELLE_COMPONENTS=""
   178 ISABELLE_COMPONENTS_MISSING=""
   179 
   180 #init component tree
   181 function init_component ()
   182 {
   183   local COMPONENT="$1"
   184   case "$COMPONENT" in
   185     /*) ;;
   186     *)
   187       echo >&2 "Absolute component path required: \"$COMPONENT\""
   188       exit 2
   189       ;;
   190   esac
   191 
   192   if [ -d "$COMPONENT" ]; then
   193     if [ -z "$ISABELLE_COMPONENTS" ]; then
   194       ISABELLE_COMPONENTS="$COMPONENT"
   195     else
   196       ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
   197     fi
   198   else
   199     echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
   200     if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
   201       ISABELLE_COMPONENTS_MISSING="$COMPONENT"
   202     else
   203       ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
   204     fi
   205   fi
   206 
   207   if [ -f "$COMPONENT/etc/settings" ]; then
   208     source "$COMPONENT/etc/settings"
   209     local RC="$?"
   210     if [ "$RC" -ne 0 ]; then
   211       echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
   212       exit 2
   213     fi
   214   fi
   215   if [ -f "$COMPONENT/etc/components" ]; then
   216     init_components "$COMPONENT" "$COMPONENT/etc/components"
   217   fi
   218 }
   219 
   220 #init component forest
   221 function init_components ()
   222 {
   223   local BASE="$1"
   224   local CATALOG="$2"
   225 
   226   if [ ! -f "$CATALOG" ]; then
   227     echo >&2 "Bad component catalog file: \"$CATALOG\""
   228     exit 2
   229   fi
   230   {
   231     while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
   232     do
   233       case "$REPLY" in
   234         \#* | "") ;;
   235         /*) init_component "$REPLY" ;;
   236         *) init_component "$BASE/$REPLY" ;;
   237       esac
   238     done
   239   } < "$CATALOG"
   240 }
   241 
   242 #main components
   243 init_component "$ISABELLE_HOME"
   244 [ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
   245 [ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
   246 
   247 
   248 #ML system identifier
   249 if [ -z "$ML_PLATFORM" ]; then
   250   ML_IDENTIFIER="$ML_SYSTEM"
   251 else
   252   ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
   253 fi
   254 
   255 ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
   256 
   257 #enforce JAVA_HOME
   258 export JAVA_HOME="$ISABELLE_JDK_HOME"
   259 
   260 #build condition etc.
   261 case "$ML_SYSTEM" in
   262   polyml*)
   263     ML_SYSTEM_POLYML="true"
   264     ;;
   265   *)
   266     ML_SYSTEM_POLYML=""
   267     ;;
   268 esac
   269 
   270 set +o allexport
   271 
   272 fi