lib/scripts/getsettings
author wenzelm
Sat Apr 14 12:36:11 2012 +0200 (2012-04-14)
changeset 47461 5a7903ba2dac
parent 47254 de2fb19683f4
child 47465 71d5f37ee2bf
permissions -rw-r--r--
more robust treatment of ISABELLE_HOME on windows: eliminate spaces and funny unicode characters in directory name via DOS~1 notation;
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@47461
    14
#JVM path wrapper
wenzelm@47461
    15
if [ "$OSTYPE" = cygwin ]
wenzelm@47461
    16
then
wenzelm@47461
    17
  ISABELLE_HOME_WINDOWS="$(cygpath -d "$(dirname "$ISABELLE_HOME")")\\$(basename "$ISABELLE_HOME")"
wenzelm@47461
    18
  ISABELLE_HOME="$(cygpath -u "$ISABELLE_HOME_WINDOWS")"
wenzelm@47461
    19
wenzelm@47461
    20
  CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
wenzelm@47461
    21
  function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
wenzelm@47461
    22
  THIS_CYGWIN="$(jvmpath "/")"
wenzelm@47461
    23
else
wenzelm@47461
    24
  function jvmpath() { echo "$@"; }
wenzelm@47461
    25
  CLASSPATH="$CLASSPATH"
wenzelm@47461
    26
fi
wenzelm@47461
    27
HOME_JVM="$HOME"
wenzelm@47461
    28
wenzelm@15972
    29
export ISABELLE_HOME
wenzelm@12598
    30
if { echo -n "$ISABELLE_HOME" | fgrep " " >/dev/null; }
wenzelm@12598
    31
then
wenzelm@45094
    32
  echo 1>&2 "### White space in ISABELLE_HOME may cause strange problems!"
wenzelm@12598
    33
  echo 1>&2 "### ISABELLE_HOME=\"$ISABELLE_HOME\""
wenzelm@12598
    34
fi
wenzelm@2736
    35
wenzelm@11553
    36
#key executables
wenzelm@28499
    37
ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
wenzelm@28504
    38
ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
wenzelm@2299
    39
wenzelm@34254
    40
function isabelle ()
wenzelm@34254
    41
{
wenzelm@34254
    42
  "$ISABELLE_TOOL" "$@"
wenzelm@34254
    43
}
wenzelm@34254
    44
wenzelm@36196
    45
#platform
wenzelm@41758
    46
source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
wenzelm@36196
    47
wenzelm@25434
    48
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    49
ISABELLE_ID=""
wenzelm@25434
    50
ISABELLE_IDENTIFIER=""
wenzelm@21490
    51
wenzelm@41511
    52
#sometimes users put strange things in here ...
wenzelm@2621
    53
unset ENV
wenzelm@2621
    54
unset BASH_ENV
wenzelm@2621
    55
wenzelm@9680
    56
#support easy settings
wenzelm@9680
    57
function choosefrom ()
wenzelm@9680
    58
{
wenzelm@9680
    59
  local RESULT=""
wenzelm@9680
    60
  local FILE=""
wenzelm@9680
    61
wenzelm@9680
    62
  for FILE in "$@"
wenzelm@9680
    63
  do
wenzelm@9680
    64
    [ -z "$RESULT" -a -e "$FILE" ] && RESULT="$FILE"
wenzelm@9680
    65
  done
wenzelm@9680
    66
wenzelm@9680
    67
  [ -z "$RESULT" ] && RESULT="$FILE"
wenzelm@9680
    68
  echo "$RESULT"
wenzelm@9680
    69
}
wenzelm@9680
    70
wenzelm@41614
    71
#shared library convenience
wenzelm@41614
    72
function librarypath () {
wenzelm@41614
    73
  for X in "$@"
wenzelm@41614
    74
  do
wenzelm@41614
    75
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    76
      *-darwin)
wenzelm@41614
    77
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    78
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    79
        else
wenzelm@41614
    80
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    81
        fi
wenzelm@41614
    82
        export DYLD_LIBRARY_PATH
wenzelm@41614
    83
        ;;
wenzelm@41614
    84
      *)
wenzelm@41614
    85
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    86
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    87
        else
wenzelm@41614
    88
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
    89
        fi
wenzelm@41614
    90
        export LD_LIBRARY_PATH
wenzelm@41614
    91
        ;;
wenzelm@41614
    92
    esac
wenzelm@41614
    93
  done
wenzelm@41614
    94
}
wenzelm@41614
    95
wenzelm@47115
    96
#robust invocation via ISABELLE_JDK_HOME
wenzelm@47115
    97
function isabelle_jdk () {
wenzelm@47115
    98
  [ -z "$ISABELLE_JDK_HOME" ] && \
wenzelm@47254
    99
    { echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2; return 2; }
wenzelm@47115
   100
  local PRG="$1"; shift
wenzelm@47115
   101
  "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47115
   102
}
wenzelm@47115
   103
wenzelm@47115
   104
#robust invocation via SCALA_HOME
wenzelm@47115
   105
function isabelle_scala () {
wenzelm@47115
   106
  [ -z "$SCALA_HOME" ] && \
wenzelm@47254
   107
    { echo "Unknown SCALA_HOME -- Scala unavailable" >&2; return 2; }
wenzelm@47115
   108
  local PRG="$1"; shift
wenzelm@47115
   109
  "$SCALA_HOME/bin/$PRG" "$@"
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@32305
   136
#nested components
wenzelm@32305
   137
ISABELLE_COMPONENTS=""
wenzelm@32305
   138
function init_component ()
wenzelm@32305
   139
{
wenzelm@32305
   140
  local COMPONENT="$1"
wenzelm@40570
   141
  case "$COMPONENT" in
wenzelm@40570
   142
    /*) ;;
wenzelm@40570
   143
    *)
wenzelm@40570
   144
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   145
      exit 2
wenzelm@40570
   146
      ;;
wenzelm@40570
   147
  esac
wenzelm@32305
   148
wenzelm@32305
   149
  if [ ! -d "$COMPONENT" ]; then
wenzelm@41758
   150
    echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
wenzelm@32305
   151
    exit 2
wenzelm@32305
   152
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   153
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   154
  else
wenzelm@32305
   155
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   156
  fi
wenzelm@32305
   157
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   158
    source "$COMPONENT/etc/settings"
wenzelm@41760
   159
    local RC="$?"
wenzelm@41760
   160
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   161
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   162
      exit 2
wenzelm@41760
   163
    fi
wenzelm@32305
   164
  fi
wenzelm@32305
   165
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   166
    {
wenzelm@33512
   167
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   168
      do
wenzelm@32305
   169
        case "$REPLY" in
wenzelm@32305
   170
          \#* | "") ;;
wenzelm@32305
   171
          /*) init_component "$REPLY" ;;
wenzelm@32305
   172
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   173
        esac
wenzelm@32305
   174
      done
wenzelm@33295
   175
    } < "$COMPONENT/etc/components"
wenzelm@32305
   176
  fi
wenzelm@32305
   177
}
wenzelm@32305
   178
wenzelm@32305
   179
#main components
wenzelm@32305
   180
init_component "$ISABELLE_HOME"
wenzelm@32321
   181
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   182
wenzelm@21490
   183
#ML system identifier
wenzelm@6413
   184
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   185
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   186
else
wenzelm@6413
   187
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   188
fi
wenzelm@21468
   189
wenzelm@6413
   190
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@3118
   191
wenzelm@2299
   192
set +o allexport
wenzelm@7770
   193
wenzelm@7770
   194
fi