lib/scripts/getsettings
author wenzelm
Tue Aug 14 10:44:03 2012 +0200 (2012-08-14)
changeset 48790 6e739225dd8a
parent 48725 e852f4d6af80
child 48837 d1d806a42c91
permissions -rwxr-xr-x
always retain doc-src (as regular component);
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@48455
    54
if [ -z "$ISABELLE_PLATFORM" ]; then
wenzelm@48455
    55
  echo 1>&2 "Failed to determine hardware and operating system type!"
wenzelm@48455
    56
  exit 2
wenzelm@48455
    57
fi
wenzelm@36196
    58
wenzelm@25434
    59
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    60
ISABELLE_ID=""
wenzelm@25434
    61
ISABELLE_IDENTIFIER=""
wenzelm@21490
    62
wenzelm@41511
    63
#sometimes users put strange things in here ...
wenzelm@2621
    64
unset ENV
wenzelm@2621
    65
unset BASH_ENV
wenzelm@2621
    66
wenzelm@9680
    67
#support easy settings
wenzelm@9680
    68
function choosefrom ()
wenzelm@9680
    69
{
wenzelm@9680
    70
  local RESULT=""
wenzelm@9680
    71
  local FILE=""
wenzelm@9680
    72
wenzelm@9680
    73
  for FILE in "$@"
wenzelm@9680
    74
  do
wenzelm@9680
    75
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
wenzelm@9680
    76
  done
wenzelm@9680
    77
wenzelm@9680
    78
  [ -z "$RESULT" ] && RESULT="$FILE"
wenzelm@9680
    79
  echo "$RESULT"
wenzelm@9680
    80
}
wenzelm@9680
    81
wenzelm@41614
    82
#shared library convenience
wenzelm@41614
    83
function librarypath () {
wenzelm@41614
    84
  for X in "$@"
wenzelm@41614
    85
  do
wenzelm@41614
    86
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    87
      *-darwin)
wenzelm@41614
    88
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    89
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    90
        else
wenzelm@41614
    91
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    92
        fi
wenzelm@41614
    93
        export DYLD_LIBRARY_PATH
wenzelm@41614
    94
        ;;
wenzelm@41614
    95
      *)
wenzelm@41614
    96
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    97
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    98
        else
wenzelm@41614
    99
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
   100
        fi
wenzelm@41614
   101
        export LD_LIBRARY_PATH
wenzelm@41614
   102
        ;;
wenzelm@41614
   103
    esac
wenzelm@41614
   104
  done
wenzelm@41614
   105
}
wenzelm@41614
   106
wenzelm@47115
   107
#robust invocation via ISABELLE_JDK_HOME
wenzelm@47115
   108
function isabelle_jdk () {
wenzelm@47465
   109
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   110
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   111
    return 127
wenzelm@47465
   112
  else
wenzelm@47465
   113
    local PRG="$1"; shift
wenzelm@47465
   114
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
   115
  fi
wenzelm@47115
   116
}
wenzelm@47115
   117
wenzelm@47115
   118
#robust invocation via SCALA_HOME
wenzelm@47115
   119
function isabelle_scala () {
wenzelm@47465
   120
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   121
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   122
    return 127
wenzelm@47465
   123
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   124
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   125
    return 127
wenzelm@47465
   126
  else
wenzelm@47465
   127
    local PRG="$1"; shift
wenzelm@47465
   128
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   129
  fi
wenzelm@47115
   130
}
wenzelm@47115
   131
wenzelm@27908
   132
#CLASSPATH convenience
wenzelm@27908
   133
function classpath () {
wenzelm@27908
   134
  for X in "$@"
wenzelm@27908
   135
  do
wenzelm@27908
   136
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
   137
      CLASSPATH="$X"
wenzelm@27908
   138
    else
wenzelm@41615
   139
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
   140
    fi
wenzelm@27908
   141
  done
wenzelm@40568
   142
  export CLASSPATH
wenzelm@27908
   143
}
wenzelm@27908
   144
wenzelm@32390
   145
#arrays
wenzelm@32390
   146
function splitarray ()
wenzelm@32390
   147
{
wenzelm@32390
   148
  SPLITARRAY=()
wenzelm@32390
   149
  local IFS="$1"; shift
wenzelm@32390
   150
  for X in $*
wenzelm@32390
   151
  do
wenzelm@32390
   152
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   153
  done
wenzelm@32390
   154
}
wenzelm@32390
   155
wenzelm@32305
   156
#nested components
wenzelm@32305
   157
ISABELLE_COMPONENTS=""
wenzelm@32305
   158
function init_component ()
wenzelm@32305
   159
{
wenzelm@32305
   160
  local COMPONENT="$1"
wenzelm@40570
   161
  case "$COMPONENT" in
wenzelm@40570
   162
    /*) ;;
wenzelm@40570
   163
    *)
wenzelm@40570
   164
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   165
      exit 2
wenzelm@40570
   166
      ;;
wenzelm@40570
   167
  esac
wenzelm@32305
   168
wenzelm@32305
   169
  if [ ! -d "$COMPONENT" ]; then
wenzelm@48448
   170
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@32305
   171
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   172
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   173
  else
wenzelm@32305
   174
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   175
  fi
wenzelm@32305
   176
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   177
    source "$COMPONENT/etc/settings"
wenzelm@41760
   178
    local RC="$?"
wenzelm@41760
   179
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   180
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   181
      exit 2
wenzelm@41760
   182
    fi
wenzelm@32305
   183
  fi
wenzelm@32305
   184
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   185
    {
wenzelm@33512
   186
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   187
      do
wenzelm@32305
   188
        case "$REPLY" in
wenzelm@32305
   189
          \#* | "") ;;
wenzelm@32305
   190
          /*) init_component "$REPLY" ;;
wenzelm@32305
   191
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   192
        esac
wenzelm@32305
   193
      done
wenzelm@33295
   194
    } < "$COMPONENT/etc/components"
wenzelm@32305
   195
  fi
wenzelm@32305
   196
}
wenzelm@32305
   197
wenzelm@32305
   198
#main components
wenzelm@32305
   199
init_component "$ISABELLE_HOME"
wenzelm@48725
   200
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
wenzelm@32321
   201
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   202
wenzelm@21490
   203
#ML system identifier
wenzelm@6413
   204
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   205
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   206
else
wenzelm@6413
   207
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   208
fi
wenzelm@21468
   209
wenzelm@47748
   210
#enforce JAVA_HOME
wenzelm@47748
   211
export JAVA_HOME="$ISABELLE_JDK_HOME"
wenzelm@47748
   212
wenzelm@6413
   213
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@3118
   214
wenzelm@48495
   215
#build condition etc.
wenzelm@48495
   216
case "$ML_SYSTEM" in
wenzelm@48495
   217
  polyml*)
wenzelm@48495
   218
    ISABELLE_POLYML="true"
wenzelm@48495
   219
    ;;
wenzelm@48495
   220
  *)
wenzelm@48495
   221
    ISABELLE_POLYML=""
wenzelm@48495
   222
    ;;
wenzelm@48495
   223
esac
wenzelm@48495
   224
wenzelm@2299
   225
set +o allexport
wenzelm@7770
   226
wenzelm@7770
   227
fi