lib/scripts/getsettings
author wenzelm
Sun Feb 13 17:45:21 2011 +0100 (2011-02-13)
changeset 41760 bf49b7a85936
parent 41759 6aa5804aaf90
child 43519 024bd7f5ee0f
permissions -rw-r--r--
more explicit exit due to failed etc/settings -- normally return code 0=true and 1=false could be tolerated, but bash syntax errors also return 1;
wenzelm@25434
     1
# -*- shell-script -*- :mode=shellscript:
wenzelm@29145
     2
#
wenzelm@9789
     3
# Author: Markus Wenzel, TU Muenchen
wenzelm@2299
     4
#
wenzelm@2348
     5
# getsettings - bash source script to augment current env.
wenzelm@2299
     6
wenzelm@7770
     7
if [ -z "$ISABELLE_SETTINGS_PRESENT" ]
wenzelm@7770
     8
then
wenzelm@7770
     9
wenzelm@3185
    10
set -o allexport
wenzelm@3185
    11
wenzelm@7770
    12
ISABELLE_SETTINGS_PRESENT=true
wenzelm@7770
    13
wenzelm@15972
    14
export ISABELLE_HOME
wenzelm@12598
    15
if { echo -n "$ISABELLE_HOME" | fgrep " " >/dev/null; }
wenzelm@12598
    16
then
wenzelm@12598
    17
  echo 1>&2 "### White space in ISABELLE_HOME may cause strange problems later on!"
wenzelm@12598
    18
  echo 1>&2 "### ISABELLE_HOME=\"$ISABELLE_HOME\""
wenzelm@12598
    19
fi
wenzelm@2736
    20
wenzelm@11553
    21
#key executables
wenzelm@28499
    22
ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
wenzelm@28504
    23
ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
wenzelm@2299
    24
wenzelm@34254
    25
function isabelle ()
wenzelm@34254
    26
{
wenzelm@34254
    27
  "$ISABELLE_TOOL" "$@"
wenzelm@34254
    28
}
wenzelm@34254
    29
wenzelm@36196
    30
#platform
wenzelm@41758
    31
source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
wenzelm@36196
    32
wenzelm@25434
    33
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    34
ISABELLE_ID=""
wenzelm@25434
    35
ISABELLE_IDENTIFIER=""
wenzelm@21490
    36
wenzelm@41511
    37
#sometimes users put strange things in here ...
wenzelm@2621
    38
unset ENV
wenzelm@2621
    39
unset BASH_ENV
wenzelm@2621
    40
wenzelm@9680
    41
#support easy settings
wenzelm@9680
    42
function choosefrom ()
wenzelm@9680
    43
{
wenzelm@9680
    44
  local RESULT=""
wenzelm@9680
    45
  local FILE=""
wenzelm@9680
    46
wenzelm@9680
    47
  for FILE in "$@"
wenzelm@9680
    48
  do
wenzelm@9680
    49
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
wenzelm@9680
    50
  done
wenzelm@9680
    51
wenzelm@9680
    52
  [ -z "$RESULT" ] && RESULT="$FILE"
wenzelm@9680
    53
  echo "$RESULT"
wenzelm@9680
    54
}
wenzelm@9680
    55
wenzelm@27914
    56
#JVM path wrapper
wenzelm@25650
    57
if [ "$OSTYPE" = cygwin ]; then
wenzelm@27908
    58
  CLASSPATH="$(cygpath -u -p "$CLASSPATH")"
wenzelm@41623
    59
  function jvmpath() { cygpath -C UTF8 -w -p "$@"; }
wenzelm@36194
    60
  THIS_CYGWIN="$(jvmpath "/")"
wenzelm@25650
    61
else
wenzelm@27908
    62
  function jvmpath() { echo "$@"; }
wenzelm@25650
    63
fi
wenzelm@28055
    64
HOME_JVM="$HOME"
wenzelm@25650
    65
wenzelm@41614
    66
#shared library convenience
wenzelm@41614
    67
function librarypath () {
wenzelm@41614
    68
  for X in "$@"
wenzelm@41614
    69
  do
wenzelm@41614
    70
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    71
      *-darwin)
wenzelm@41614
    72
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    73
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    74
        else
wenzelm@41614
    75
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    76
        fi
wenzelm@41614
    77
        export DYLD_LIBRARY_PATH
wenzelm@41614
    78
        ;;
wenzelm@41614
    79
      *)
wenzelm@41614
    80
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    81
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    82
        else
wenzelm@41614
    83
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
    84
        fi
wenzelm@41614
    85
        export LD_LIBRARY_PATH
wenzelm@41614
    86
        ;;
wenzelm@41614
    87
    esac
wenzelm@41614
    88
  done
wenzelm@41614
    89
}
wenzelm@41614
    90
wenzelm@27908
    91
#CLASSPATH convenience
wenzelm@27908
    92
function classpath () {
wenzelm@27908
    93
  for X in "$@"
wenzelm@27908
    94
  do
wenzelm@27908
    95
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
    96
      CLASSPATH="$X"
wenzelm@27908
    97
    else
wenzelm@41615
    98
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
    99
    fi
wenzelm@27908
   100
  done
wenzelm@40568
   101
  export CLASSPATH
wenzelm@27908
   102
}
wenzelm@27908
   103
wenzelm@32390
   104
#arrays
wenzelm@32390
   105
function splitarray ()
wenzelm@32390
   106
{
wenzelm@32390
   107
  SPLITARRAY=()
wenzelm@32390
   108
  local IFS="$1"; shift
wenzelm@32390
   109
  for X in $*
wenzelm@32390
   110
  do
wenzelm@32390
   111
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   112
  done
wenzelm@32390
   113
}
wenzelm@32390
   114
wenzelm@32305
   115
#nested components
wenzelm@32305
   116
ISABELLE_COMPONENTS=""
wenzelm@32305
   117
function init_component ()
wenzelm@32305
   118
{
wenzelm@32305
   119
  local COMPONENT="$1"
wenzelm@40570
   120
  case "$COMPONENT" in
wenzelm@40570
   121
    /*) ;;
wenzelm@40570
   122
    *)
wenzelm@40570
   123
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   124
      exit 2
wenzelm@40570
   125
      ;;
wenzelm@40570
   126
  esac
wenzelm@32305
   127
wenzelm@32305
   128
  if [ ! -d "$COMPONENT" ]; then
wenzelm@41758
   129
    echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
wenzelm@32305
   130
    exit 2
wenzelm@32305
   131
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   132
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   133
  else
wenzelm@32305
   134
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   135
  fi
wenzelm@32305
   136
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   137
    source "$COMPONENT/etc/settings"
wenzelm@41760
   138
    local RC="$?"
wenzelm@41760
   139
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   140
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   141
      exit 2
wenzelm@41760
   142
    fi
wenzelm@32305
   143
  fi
wenzelm@32305
   144
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   145
    {
wenzelm@33512
   146
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   147
      do
wenzelm@32305
   148
        case "$REPLY" in
wenzelm@32305
   149
          \#* | "") ;;
wenzelm@32305
   150
          /*) init_component "$REPLY" ;;
wenzelm@32305
   151
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   152
        esac
wenzelm@32305
   153
      done
wenzelm@33295
   154
    } < "$COMPONENT/etc/components"
wenzelm@32305
   155
  fi
wenzelm@32305
   156
}
wenzelm@32305
   157
wenzelm@32305
   158
#main components
wenzelm@32305
   159
init_component "$ISABELLE_HOME"
wenzelm@32321
   160
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   161
wenzelm@21490
   162
#ML system identifier
wenzelm@6413
   163
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   164
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   165
else
wenzelm@6413
   166
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   167
fi
wenzelm@21468
   168
wenzelm@6413
   169
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@3118
   170
wenzelm@2299
   171
set +o allexport
wenzelm@7770
   172
wenzelm@7770
   173
fi