lib/scripts/getsettings
author wenzelm
Fri Aug 17 12:14:58 2012 +0200 (2012-08-17)
changeset 48838 623ba165d059
parent 48837 d1d806a42c91
child 49000 0cebcbeac4c7
permissions -rwxr-xr-x
direct support for component forests via init_components;
explicit ISABELLE_COMPONENTS_MISSING;
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@48838
    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@2736
    37
wenzelm@11553
    38
#key executables
wenzelm@28499
    39
ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
wenzelm@28504
    40
ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
wenzelm@2299
    41
wenzelm@34254
    42
function isabelle ()
wenzelm@34254
    43
{
wenzelm@34254
    44
  "$ISABELLE_TOOL" "$@"
wenzelm@34254
    45
}
wenzelm@34254
    46
wenzelm@36196
    47
#platform
wenzelm@41758
    48
source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
wenzelm@48455
    49
if [ -z "$ISABELLE_PLATFORM" ]; then
wenzelm@48455
    50
  echo 1>&2 "Failed to determine hardware and operating system type!"
wenzelm@48455
    51
  exit 2
wenzelm@48455
    52
fi
wenzelm@36196
    53
wenzelm@25434
    54
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    55
ISABELLE_ID=""
wenzelm@48837
    56
[ -z "$ISABELLE_IDENTIFIER" ] && ISABELLE_IDENTIFIER=""
wenzelm@21490
    57
wenzelm@41511
    58
#sometimes users put strange things in here ...
wenzelm@2621
    59
unset ENV
wenzelm@2621
    60
unset BASH_ENV
wenzelm@2621
    61
wenzelm@9680
    62
#support easy settings
wenzelm@9680
    63
function choosefrom ()
wenzelm@9680
    64
{
wenzelm@9680
    65
  local RESULT=""
wenzelm@9680
    66
  local FILE=""
wenzelm@9680
    67
wenzelm@9680
    68
  for FILE in "$@"
wenzelm@9680
    69
  do
wenzelm@9680
    70
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
wenzelm@9680
    71
  done
wenzelm@9680
    72
wenzelm@9680
    73
  [ -z "$RESULT" ] && RESULT="$FILE"
wenzelm@9680
    74
  echo "$RESULT"
wenzelm@9680
    75
}
wenzelm@9680
    76
wenzelm@41614
    77
#shared library convenience
wenzelm@41614
    78
function librarypath () {
wenzelm@41614
    79
  for X in "$@"
wenzelm@41614
    80
  do
wenzelm@41614
    81
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    82
      *-darwin)
wenzelm@41614
    83
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    84
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    85
        else
wenzelm@41614
    86
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    87
        fi
wenzelm@41614
    88
        export DYLD_LIBRARY_PATH
wenzelm@41614
    89
        ;;
wenzelm@41614
    90
      *)
wenzelm@41614
    91
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    92
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    93
        else
wenzelm@41614
    94
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
    95
        fi
wenzelm@41614
    96
        export LD_LIBRARY_PATH
wenzelm@41614
    97
        ;;
wenzelm@41614
    98
    esac
wenzelm@41614
    99
  done
wenzelm@41614
   100
}
wenzelm@41614
   101
wenzelm@47115
   102
#robust invocation via ISABELLE_JDK_HOME
wenzelm@47115
   103
function isabelle_jdk () {
wenzelm@47465
   104
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   105
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   106
    return 127
wenzelm@47465
   107
  else
wenzelm@47465
   108
    local PRG="$1"; shift
wenzelm@47465
   109
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
   110
  fi
wenzelm@47115
   111
}
wenzelm@47115
   112
wenzelm@47115
   113
#robust invocation via SCALA_HOME
wenzelm@47115
   114
function isabelle_scala () {
wenzelm@47465
   115
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   116
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   117
    return 127
wenzelm@47465
   118
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   119
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   120
    return 127
wenzelm@47465
   121
  else
wenzelm@47465
   122
    local PRG="$1"; shift
wenzelm@47465
   123
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   124
  fi
wenzelm@47115
   125
}
wenzelm@47115
   126
wenzelm@27908
   127
#CLASSPATH convenience
wenzelm@27908
   128
function classpath () {
wenzelm@27908
   129
  for X in "$@"
wenzelm@27908
   130
  do
wenzelm@27908
   131
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
   132
      CLASSPATH="$X"
wenzelm@27908
   133
    else
wenzelm@41615
   134
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
   135
    fi
wenzelm@27908
   136
  done
wenzelm@40568
   137
  export CLASSPATH
wenzelm@27908
   138
}
wenzelm@27908
   139
wenzelm@32390
   140
#arrays
wenzelm@32390
   141
function splitarray ()
wenzelm@32390
   142
{
wenzelm@32390
   143
  SPLITARRAY=()
wenzelm@32390
   144
  local IFS="$1"; shift
wenzelm@32390
   145
  for X in $*
wenzelm@32390
   146
  do
wenzelm@32390
   147
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   148
  done
wenzelm@32390
   149
}
wenzelm@32390
   150
wenzelm@48838
   151
wenzelm@48838
   152
# components
wenzelm@48838
   153
wenzelm@32305
   154
ISABELLE_COMPONENTS=""
wenzelm@48838
   155
ISABELLE_COMPONENTS_MISSING=""
wenzelm@48838
   156
wenzelm@48838
   157
#init component tree
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@48838
   169
  if [ -d "$COMPONENT" ]; then
wenzelm@48838
   170
    if [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@48838
   171
      ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@48838
   172
    else
wenzelm@48838
   173
      ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@48838
   174
    fi
wenzelm@48838
   175
  else
wenzelm@48448
   176
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@48838
   177
    if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
wenzelm@48838
   178
      ISABELLE_COMPONENTS_MISSING="$COMPONENT"
wenzelm@48838
   179
    else
wenzelm@48838
   180
      ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
wenzelm@48838
   181
    fi
wenzelm@32305
   182
  fi
wenzelm@48838
   183
wenzelm@32305
   184
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   185
    source "$COMPONENT/etc/settings"
wenzelm@41760
   186
    local RC="$?"
wenzelm@41760
   187
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   188
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   189
      exit 2
wenzelm@41760
   190
    fi
wenzelm@32305
   191
  fi
wenzelm@32305
   192
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@48838
   193
    init_components "$COMPONENT" "$COMPONENT/etc/components"
wenzelm@48838
   194
  fi
wenzelm@48838
   195
}
wenzelm@48838
   196
wenzelm@48838
   197
#init component forest
wenzelm@48838
   198
function init_components ()
wenzelm@48838
   199
{
wenzelm@48838
   200
  local BASE="$1"
wenzelm@48838
   201
  local CATALOG="$2"
wenzelm@48838
   202
wenzelm@48838
   203
  if [ ! -d "$BASE" ]; then
wenzelm@48838
   204
    echo >&2 "Bad component base directory: \"$BASE\""
wenzelm@48838
   205
    exit 2
wenzelm@32305
   206
  fi
wenzelm@48838
   207
  if [ ! -f "$CATALOG" ]; then
wenzelm@48838
   208
    echo >&2 "Bad component catalog file: \"$CATALOG\""
wenzelm@48838
   209
    exit 2
wenzelm@48838
   210
  fi
wenzelm@48838
   211
  {
wenzelm@48838
   212
    while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@48838
   213
    do
wenzelm@48838
   214
      case "$REPLY" in
wenzelm@48838
   215
        \#* | "") ;;
wenzelm@48838
   216
        /*) init_component "$REPLY" ;;
wenzelm@48838
   217
        *) init_component "$BASE/$REPLY" ;;
wenzelm@48838
   218
      esac
wenzelm@48838
   219
    done
wenzelm@48838
   220
  } < "$CATALOG"
wenzelm@32305
   221
}
wenzelm@32305
   222
wenzelm@32305
   223
#main components
wenzelm@32305
   224
init_component "$ISABELLE_HOME"
wenzelm@48725
   225
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
wenzelm@32321
   226
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   227
wenzelm@48838
   228
wenzelm@21490
   229
#ML system identifier
wenzelm@6413
   230
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   231
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   232
else
wenzelm@6413
   233
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   234
fi
wenzelm@21468
   235
wenzelm@48838
   236
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@48838
   237
wenzelm@47748
   238
#enforce JAVA_HOME
wenzelm@47748
   239
export JAVA_HOME="$ISABELLE_JDK_HOME"
wenzelm@47748
   240
wenzelm@48495
   241
#build condition etc.
wenzelm@48495
   242
case "$ML_SYSTEM" in
wenzelm@48495
   243
  polyml*)
wenzelm@48495
   244
    ISABELLE_POLYML="true"
wenzelm@48495
   245
    ;;
wenzelm@48495
   246
  *)
wenzelm@48495
   247
    ISABELLE_POLYML=""
wenzelm@48495
   248
    ;;
wenzelm@48495
   249
esac
wenzelm@48495
   250
wenzelm@2299
   251
set +o allexport
wenzelm@7770
   252
wenzelm@7770
   253
fi