lib/scripts/getsettings
author wenzelm
Fri Aug 17 11:42:05 2012 +0200 (2012-08-17)
changeset 48837 d1d806a42c91
parent 48790 6e739225dd8a
child 48838 623ba165d059
permissions -rwxr-xr-x
allow to provide external ISABELLE_IDENTIFIER for repository clone -- potentially relevant for isatest and mira;
clarified spaces in file names -- ISABELLE_HOME is non-critical after abolishment of "make";
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@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@32305
   151
#nested components
wenzelm@32305
   152
ISABELLE_COMPONENTS=""
wenzelm@32305
   153
function init_component ()
wenzelm@32305
   154
{
wenzelm@32305
   155
  local COMPONENT="$1"
wenzelm@40570
   156
  case "$COMPONENT" in
wenzelm@40570
   157
    /*) ;;
wenzelm@40570
   158
    *)
wenzelm@40570
   159
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   160
      exit 2
wenzelm@40570
   161
      ;;
wenzelm@40570
   162
  esac
wenzelm@32305
   163
wenzelm@32305
   164
  if [ ! -d "$COMPONENT" ]; then
wenzelm@48448
   165
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@32305
   166
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   167
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   168
  else
wenzelm@32305
   169
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   170
  fi
wenzelm@32305
   171
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   172
    source "$COMPONENT/etc/settings"
wenzelm@41760
   173
    local RC="$?"
wenzelm@41760
   174
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   175
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   176
      exit 2
wenzelm@41760
   177
    fi
wenzelm@32305
   178
  fi
wenzelm@32305
   179
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   180
    {
wenzelm@33512
   181
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   182
      do
wenzelm@32305
   183
        case "$REPLY" in
wenzelm@32305
   184
          \#* | "") ;;
wenzelm@32305
   185
          /*) init_component "$REPLY" ;;
wenzelm@32305
   186
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   187
        esac
wenzelm@32305
   188
      done
wenzelm@33295
   189
    } < "$COMPONENT/etc/components"
wenzelm@32305
   190
  fi
wenzelm@32305
   191
}
wenzelm@32305
   192
wenzelm@32305
   193
#main components
wenzelm@32305
   194
init_component "$ISABELLE_HOME"
wenzelm@48725
   195
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
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@48495
   210
#build condition etc.
wenzelm@48495
   211
case "$ML_SYSTEM" in
wenzelm@48495
   212
  polyml*)
wenzelm@48495
   213
    ISABELLE_POLYML="true"
wenzelm@48495
   214
    ;;
wenzelm@48495
   215
  *)
wenzelm@48495
   216
    ISABELLE_POLYML=""
wenzelm@48495
   217
    ;;
wenzelm@48495
   218
esac
wenzelm@48495
   219
wenzelm@2299
   220
set +o allexport
wenzelm@7770
   221
wenzelm@7770
   222
fi