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