lib/scripts/getsettings
author wenzelm
Thu Sep 13 16:09:35 2012 +0200 (2012-09-13)
changeset 49347 d4768cb77a69
parent 49000 0cebcbeac4c7
child 52443 725916b7dee5
permissions -rwxr-xr-x
more liberal init_components: base dir may get created later when resolving missing components;
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@41614
    62
#shared library convenience
wenzelm@41614
    63
function librarypath () {
wenzelm@41614
    64
  for X in "$@"
wenzelm@41614
    65
  do
wenzelm@41614
    66
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    67
      *-darwin)
wenzelm@41614
    68
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    69
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    70
        else
wenzelm@41614
    71
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    72
        fi
wenzelm@41614
    73
        export DYLD_LIBRARY_PATH
wenzelm@41614
    74
        ;;
wenzelm@41614
    75
      *)
wenzelm@41614
    76
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    77
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    78
        else
wenzelm@41614
    79
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
    80
        fi
wenzelm@41614
    81
        export LD_LIBRARY_PATH
wenzelm@41614
    82
        ;;
wenzelm@41614
    83
    esac
wenzelm@41614
    84
  done
wenzelm@41614
    85
}
wenzelm@41614
    86
wenzelm@47115
    87
#robust invocation via ISABELLE_JDK_HOME
wenzelm@47115
    88
function isabelle_jdk () {
wenzelm@47465
    89
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
    90
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
    91
    return 127
wenzelm@47465
    92
  else
wenzelm@47465
    93
    local PRG="$1"; shift
wenzelm@47465
    94
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
    95
  fi
wenzelm@47115
    96
}
wenzelm@47115
    97
wenzelm@47115
    98
#robust invocation via SCALA_HOME
wenzelm@47115
    99
function isabelle_scala () {
wenzelm@47465
   100
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   101
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   102
    return 127
wenzelm@47465
   103
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   104
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   105
    return 127
wenzelm@47465
   106
  else
wenzelm@47465
   107
    local PRG="$1"; shift
wenzelm@47465
   108
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   109
  fi
wenzelm@47115
   110
}
wenzelm@47115
   111
wenzelm@27908
   112
#CLASSPATH convenience
wenzelm@27908
   113
function classpath () {
wenzelm@27908
   114
  for X in "$@"
wenzelm@27908
   115
  do
wenzelm@27908
   116
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
   117
      CLASSPATH="$X"
wenzelm@27908
   118
    else
wenzelm@41615
   119
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
   120
    fi
wenzelm@27908
   121
  done
wenzelm@40568
   122
  export CLASSPATH
wenzelm@27908
   123
}
wenzelm@27908
   124
wenzelm@32390
   125
#arrays
wenzelm@32390
   126
function splitarray ()
wenzelm@32390
   127
{
wenzelm@32390
   128
  SPLITARRAY=()
wenzelm@32390
   129
  local IFS="$1"; shift
wenzelm@32390
   130
  for X in $*
wenzelm@32390
   131
  do
wenzelm@32390
   132
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   133
  done
wenzelm@32390
   134
}
wenzelm@32390
   135
wenzelm@48838
   136
wenzelm@48838
   137
# components
wenzelm@48838
   138
wenzelm@32305
   139
ISABELLE_COMPONENTS=""
wenzelm@48838
   140
ISABELLE_COMPONENTS_MISSING=""
wenzelm@48838
   141
wenzelm@48838
   142
#init component tree
wenzelm@32305
   143
function init_component ()
wenzelm@32305
   144
{
wenzelm@32305
   145
  local COMPONENT="$1"
wenzelm@40570
   146
  case "$COMPONENT" in
wenzelm@40570
   147
    /*) ;;
wenzelm@40570
   148
    *)
wenzelm@40570
   149
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   150
      exit 2
wenzelm@40570
   151
      ;;
wenzelm@40570
   152
  esac
wenzelm@32305
   153
wenzelm@48838
   154
  if [ -d "$COMPONENT" ]; then
wenzelm@48838
   155
    if [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@48838
   156
      ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@48838
   157
    else
wenzelm@48838
   158
      ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@48838
   159
    fi
wenzelm@48838
   160
  else
wenzelm@48448
   161
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@48838
   162
    if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
wenzelm@48838
   163
      ISABELLE_COMPONENTS_MISSING="$COMPONENT"
wenzelm@48838
   164
    else
wenzelm@48838
   165
      ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
wenzelm@48838
   166
    fi
wenzelm@32305
   167
  fi
wenzelm@48838
   168
wenzelm@32305
   169
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   170
    source "$COMPONENT/etc/settings"
wenzelm@41760
   171
    local RC="$?"
wenzelm@41760
   172
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   173
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   174
      exit 2
wenzelm@41760
   175
    fi
wenzelm@32305
   176
  fi
wenzelm@32305
   177
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@48838
   178
    init_components "$COMPONENT" "$COMPONENT/etc/components"
wenzelm@48838
   179
  fi
wenzelm@48838
   180
}
wenzelm@48838
   181
wenzelm@48838
   182
#init component forest
wenzelm@48838
   183
function init_components ()
wenzelm@48838
   184
{
wenzelm@48838
   185
  local BASE="$1"
wenzelm@48838
   186
  local CATALOG="$2"
wenzelm@48838
   187
wenzelm@48838
   188
  if [ ! -f "$CATALOG" ]; then
wenzelm@48838
   189
    echo >&2 "Bad component catalog file: \"$CATALOG\""
wenzelm@48838
   190
    exit 2
wenzelm@48838
   191
  fi
wenzelm@48838
   192
  {
wenzelm@48838
   193
    while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@48838
   194
    do
wenzelm@48838
   195
      case "$REPLY" in
wenzelm@48838
   196
        \#* | "") ;;
wenzelm@48838
   197
        /*) init_component "$REPLY" ;;
wenzelm@48838
   198
        *) init_component "$BASE/$REPLY" ;;
wenzelm@48838
   199
      esac
wenzelm@48838
   200
    done
wenzelm@48838
   201
  } < "$CATALOG"
wenzelm@32305
   202
}
wenzelm@32305
   203
wenzelm@32305
   204
#main components
wenzelm@32305
   205
init_component "$ISABELLE_HOME"
wenzelm@48725
   206
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
wenzelm@32321
   207
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   208
wenzelm@48838
   209
wenzelm@21490
   210
#ML system identifier
wenzelm@6413
   211
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   212
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   213
else
wenzelm@6413
   214
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   215
fi
wenzelm@21468
   216
wenzelm@48838
   217
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@48838
   218
wenzelm@47748
   219
#enforce JAVA_HOME
wenzelm@47748
   220
export JAVA_HOME="$ISABELLE_JDK_HOME"
wenzelm@47748
   221
wenzelm@48495
   222
#build condition etc.
wenzelm@48495
   223
case "$ML_SYSTEM" in
wenzelm@48495
   224
  polyml*)
wenzelm@48495
   225
    ISABELLE_POLYML="true"
wenzelm@48495
   226
    ;;
wenzelm@48495
   227
  *)
wenzelm@48495
   228
    ISABELLE_POLYML=""
wenzelm@48495
   229
    ;;
wenzelm@48495
   230
esac
wenzelm@48495
   231
wenzelm@2299
   232
set +o allexport
wenzelm@7770
   233
wenzelm@7770
   234
fi