lib/scripts/getsettings
author wenzelm
Mon Jul 23 16:13:26 2012 +0200 (2012-07-23)
changeset 48448 94c11abc5a52
parent 47996 25b9f59ab1b9
child 48455 a509f19d4cc6
permissions -rwxr-xr-x
clarified init_component: always liberal;
reduced divergence of clone from lib/scripts/getsettings;
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@47661
    14
#Cygwin vs Posix
wenzelm@47461
    15
if [ "$OSTYPE" = cygwin ]
wenzelm@47461
    16
then
wenzelm@47661
    17
  if [ -z "$USER_HOME" ]; then
wenzelm@47661
    18
    USER_HOME="$(cygpath -u "$HOMEDRIVE\\$HOMEPATH")"
wenzelm@47661
    19
  fi
wenzelm@47661
    20
wenzelm@47525
    21
  ISABELLE_HOME_WINDOWS="$(cygpath -w "$(dirname "$ISABELLE_HOME")")\\$(basename "$ISABELLE_HOME")"
wenzelm@47461
    22
  ISABELLE_HOME="$(cygpath -u "$ISABELLE_HOME_WINDOWS")"
wenzelm@47461
    23
wenzelm@47461
    24
  CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
wenzelm@47461
    25
  function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
wenzelm@47996
    26
  CYGWIN_ROOT="$(jvmpath "/")"
wenzelm@47461
    27
else
wenzelm@47661
    28
  if [ -z "$USER_HOME" ]; then
wenzelm@47661
    29
    USER_HOME="$HOME"
wenzelm@47661
    30
  fi
wenzelm@47661
    31
wenzelm@47461
    32
  function jvmpath() { echo "$@"; }
wenzelm@47461
    33
  CLASSPATH="$CLASSPATH"
wenzelm@47461
    34
fi
wenzelm@47461
    35
wenzelm@15972
    36
export ISABELLE_HOME
wenzelm@12598
    37
if { echo -n "$ISABELLE_HOME" | fgrep " " >/dev/null; }
wenzelm@12598
    38
then
wenzelm@45094
    39
  echo 1>&2 "### White space in ISABELLE_HOME may cause strange problems!"
wenzelm@12598
    40
  echo 1>&2 "### ISABELLE_HOME=\"$ISABELLE_HOME\""
wenzelm@12598
    41
fi
wenzelm@2736
    42
wenzelm@11553
    43
#key executables
wenzelm@28499
    44
ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
wenzelm@28504
    45
ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
wenzelm@2299
    46
wenzelm@34254
    47
function isabelle ()
wenzelm@34254
    48
{
wenzelm@34254
    49
  "$ISABELLE_TOOL" "$@"
wenzelm@34254
    50
}
wenzelm@34254
    51
wenzelm@36196
    52
#platform
wenzelm@41758
    53
source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
wenzelm@36196
    54
wenzelm@25434
    55
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    56
ISABELLE_ID=""
wenzelm@25434
    57
ISABELLE_IDENTIFIER=""
wenzelm@21490
    58
wenzelm@41511
    59
#sometimes users put strange things in here ...
wenzelm@2621
    60
unset ENV
wenzelm@2621
    61
unset BASH_ENV
wenzelm@2621
    62
wenzelm@9680
    63
#support easy settings
wenzelm@9680
    64
function choosefrom ()
wenzelm@9680
    65
{
wenzelm@9680
    66
  local RESULT=""
wenzelm@9680
    67
  local FILE=""
wenzelm@9680
    68
wenzelm@9680
    69
  for FILE in "$@"
wenzelm@9680
    70
  do
wenzelm@9680
    71
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
wenzelm@9680
    72
  done
wenzelm@9680
    73
wenzelm@9680
    74
  [ -z "$RESULT" ] && RESULT="$FILE"
wenzelm@9680
    75
  echo "$RESULT"
wenzelm@9680
    76
}
wenzelm@9680
    77
wenzelm@41614
    78
#shared library convenience
wenzelm@41614
    79
function librarypath () {
wenzelm@41614
    80
  for X in "$@"
wenzelm@41614
    81
  do
wenzelm@41614
    82
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    83
      *-darwin)
wenzelm@41614
    84
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    85
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    86
        else
wenzelm@41614
    87
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    88
        fi
wenzelm@41614
    89
        export DYLD_LIBRARY_PATH
wenzelm@41614
    90
        ;;
wenzelm@41614
    91
      *)
wenzelm@41614
    92
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    93
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    94
        else
wenzelm@41614
    95
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
    96
        fi
wenzelm@41614
    97
        export LD_LIBRARY_PATH
wenzelm@41614
    98
        ;;
wenzelm@41614
    99
    esac
wenzelm@41614
   100
  done
wenzelm@41614
   101
}
wenzelm@41614
   102
wenzelm@47115
   103
#robust invocation via ISABELLE_JDK_HOME
wenzelm@47115
   104
function isabelle_jdk () {
wenzelm@47465
   105
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   106
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   107
    return 127
wenzelm@47465
   108
  else
wenzelm@47465
   109
    local PRG="$1"; shift
wenzelm@47465
   110
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
   111
  fi
wenzelm@47115
   112
}
wenzelm@47115
   113
wenzelm@47115
   114
#robust invocation via SCALA_HOME
wenzelm@47115
   115
function isabelle_scala () {
wenzelm@47465
   116
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   117
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   118
    return 127
wenzelm@47465
   119
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   120
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   121
    return 127
wenzelm@47465
   122
  else
wenzelm@47465
   123
    local PRG="$1"; shift
wenzelm@47465
   124
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   125
  fi
wenzelm@47115
   126
}
wenzelm@47115
   127
wenzelm@27908
   128
#CLASSPATH convenience
wenzelm@27908
   129
function classpath () {
wenzelm@27908
   130
  for X in "$@"
wenzelm@27908
   131
  do
wenzelm@27908
   132
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
   133
      CLASSPATH="$X"
wenzelm@27908
   134
    else
wenzelm@41615
   135
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
   136
    fi
wenzelm@27908
   137
  done
wenzelm@40568
   138
  export CLASSPATH
wenzelm@27908
   139
}
wenzelm@27908
   140
wenzelm@32390
   141
#arrays
wenzelm@32390
   142
function splitarray ()
wenzelm@32390
   143
{
wenzelm@32390
   144
  SPLITARRAY=()
wenzelm@32390
   145
  local IFS="$1"; shift
wenzelm@32390
   146
  for X in $*
wenzelm@32390
   147
  do
wenzelm@32390
   148
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   149
  done
wenzelm@32390
   150
}
wenzelm@32390
   151
wenzelm@32305
   152
#nested components
wenzelm@32305
   153
ISABELLE_COMPONENTS=""
wenzelm@32305
   154
function init_component ()
wenzelm@32305
   155
{
wenzelm@32305
   156
  local COMPONENT="$1"
wenzelm@40570
   157
  case "$COMPONENT" in
wenzelm@40570
   158
    /*) ;;
wenzelm@40570
   159
    *)
wenzelm@40570
   160
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   161
      exit 2
wenzelm@40570
   162
      ;;
wenzelm@40570
   163
  esac
wenzelm@32305
   164
wenzelm@32305
   165
  if [ ! -d "$COMPONENT" ]; then
wenzelm@48448
   166
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@32305
   167
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   168
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   169
  else
wenzelm@32305
   170
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   171
  fi
wenzelm@32305
   172
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   173
    source "$COMPONENT/etc/settings"
wenzelm@41760
   174
    local RC="$?"
wenzelm@41760
   175
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   176
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   177
      exit 2
wenzelm@41760
   178
    fi
wenzelm@32305
   179
  fi
wenzelm@32305
   180
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   181
    {
wenzelm@33512
   182
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   183
      do
wenzelm@32305
   184
        case "$REPLY" in
wenzelm@32305
   185
          \#* | "") ;;
wenzelm@32305
   186
          /*) init_component "$REPLY" ;;
wenzelm@32305
   187
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   188
        esac
wenzelm@32305
   189
      done
wenzelm@33295
   190
    } < "$COMPONENT/etc/components"
wenzelm@32305
   191
  fi
wenzelm@32305
   192
}
wenzelm@32305
   193
wenzelm@32305
   194
#main components
wenzelm@32305
   195
init_component "$ISABELLE_HOME"
wenzelm@32321
   196
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   197
wenzelm@21490
   198
#ML system identifier
wenzelm@6413
   199
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   200
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   201
else
wenzelm@6413
   202
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   203
fi
wenzelm@21468
   204
wenzelm@47748
   205
#enforce JAVA_HOME
wenzelm@47748
   206
export JAVA_HOME="$ISABELLE_JDK_HOME"
wenzelm@47748
   207
wenzelm@6413
   208
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@3118
   209
wenzelm@2299
   210
set +o allexport
wenzelm@7770
   211
wenzelm@7770
   212
fi