lib/scripts/getsettings
author wenzelm
Tue Apr 17 23:24:46 2012 +0200 (2012-04-17)
changeset 47525 9c8a1b9c0630
parent 47490 f4348634595b
child 47661 012a887997f3
permissions -rw-r--r--
retain ISABELLE_HOME_WINDOWS which is useful for jEdit to fold file names symbolically, but without DOS expansion that causes problems with Cygwin/Posix roundtrip (cf. 5a7903ba2dac);
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@47525
    17
  ISABELLE_HOME_WINDOWS="$(cygpath -w "$(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@47465
    98
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
    99
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   100
    return 127
wenzelm@47465
   101
  else
wenzelm@47465
   102
    local PRG="$1"; shift
wenzelm@47465
   103
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
   104
  fi
wenzelm@47115
   105
}
wenzelm@47115
   106
wenzelm@47115
   107
#robust invocation via SCALA_HOME
wenzelm@47115
   108
function isabelle_scala () {
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
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   113
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   114
    return 127
wenzelm@47465
   115
  else
wenzelm@47465
   116
    local PRG="$1"; shift
wenzelm@47465
   117
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   118
  fi
wenzelm@47115
   119
}
wenzelm@47115
   120
wenzelm@27908
   121
#CLASSPATH convenience
wenzelm@27908
   122
function classpath () {
wenzelm@27908
   123
  for X in "$@"
wenzelm@27908
   124
  do
wenzelm@27908
   125
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
   126
      CLASSPATH="$X"
wenzelm@27908
   127
    else
wenzelm@41615
   128
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
   129
    fi
wenzelm@27908
   130
  done
wenzelm@40568
   131
  export CLASSPATH
wenzelm@27908
   132
}
wenzelm@27908
   133
wenzelm@32390
   134
#arrays
wenzelm@32390
   135
function splitarray ()
wenzelm@32390
   136
{
wenzelm@32390
   137
  SPLITARRAY=()
wenzelm@32390
   138
  local IFS="$1"; shift
wenzelm@32390
   139
  for X in $*
wenzelm@32390
   140
  do
wenzelm@32390
   141
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   142
  done
wenzelm@32390
   143
}
wenzelm@32390
   144
wenzelm@32305
   145
#nested components
wenzelm@32305
   146
ISABELLE_COMPONENTS=""
wenzelm@32305
   147
function init_component ()
wenzelm@32305
   148
{
wenzelm@32305
   149
  local COMPONENT="$1"
wenzelm@40570
   150
  case "$COMPONENT" in
wenzelm@40570
   151
    /*) ;;
wenzelm@40570
   152
    *)
wenzelm@40570
   153
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   154
      exit 2
wenzelm@40570
   155
      ;;
wenzelm@40570
   156
  esac
wenzelm@32305
   157
wenzelm@32305
   158
  if [ ! -d "$COMPONENT" ]; then
wenzelm@41758
   159
    echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
wenzelm@32305
   160
    exit 2
wenzelm@32305
   161
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   162
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   163
  else
wenzelm@32305
   164
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   165
  fi
wenzelm@32305
   166
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   167
    source "$COMPONENT/etc/settings"
wenzelm@41760
   168
    local RC="$?"
wenzelm@41760
   169
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   170
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   171
      exit 2
wenzelm@41760
   172
    fi
wenzelm@32305
   173
  fi
wenzelm@32305
   174
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   175
    {
wenzelm@33512
   176
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   177
      do
wenzelm@32305
   178
        case "$REPLY" in
wenzelm@32305
   179
          \#* | "") ;;
wenzelm@32305
   180
          /*) init_component "$REPLY" ;;
wenzelm@32305
   181
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   182
        esac
wenzelm@32305
   183
      done
wenzelm@33295
   184
    } < "$COMPONENT/etc/components"
wenzelm@32305
   185
  fi
wenzelm@32305
   186
}
wenzelm@32305
   187
wenzelm@32305
   188
#main components
wenzelm@32305
   189
init_component "$ISABELLE_HOME"
wenzelm@32321
   190
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   191
wenzelm@21490
   192
#ML system identifier
wenzelm@6413
   193
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   194
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   195
else
wenzelm@6413
   196
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   197
fi
wenzelm@21468
   198
wenzelm@6413
   199
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@3118
   200
wenzelm@2299
   201
set +o allexport
wenzelm@7770
   202
wenzelm@7770
   203
fi