lib/scripts/getsettings
author wenzelm
Thu Mar 01 14:42:05 2012 +0100 (2012-03-01)
changeset 46741 a29006291f2b
parent 45094 a43694a0b726
child 47115 1a05adae1cc9
permissions -rw-r--r--
more tolerant cygpath invocation, allow empty CLASSPATH;
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@27908
    92
#CLASSPATH convenience
wenzelm@27908
    93
function classpath () {
wenzelm@27908
    94
  for X in "$@"
wenzelm@27908
    95
  do
wenzelm@27908
    96
    if [ -z "$CLASSPATH" ]; then
wenzelm@27908
    97
      CLASSPATH="$X"
wenzelm@27908
    98
    else
wenzelm@41615
    99
      CLASSPATH="$X:$CLASSPATH"
wenzelm@27908
   100
    fi
wenzelm@27908
   101
  done
wenzelm@40568
   102
  export CLASSPATH
wenzelm@27908
   103
}
wenzelm@27908
   104
wenzelm@32390
   105
#arrays
wenzelm@32390
   106
function splitarray ()
wenzelm@32390
   107
{
wenzelm@32390
   108
  SPLITARRAY=()
wenzelm@32390
   109
  local IFS="$1"; shift
wenzelm@32390
   110
  for X in $*
wenzelm@32390
   111
  do
wenzelm@32390
   112
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   113
  done
wenzelm@32390
   114
}
wenzelm@32390
   115
wenzelm@32305
   116
#nested components
wenzelm@32305
   117
ISABELLE_COMPONENTS=""
wenzelm@32305
   118
function init_component ()
wenzelm@32305
   119
{
wenzelm@32305
   120
  local COMPONENT="$1"
wenzelm@40570
   121
  case "$COMPONENT" in
wenzelm@40570
   122
    /*) ;;
wenzelm@40570
   123
    *)
wenzelm@40570
   124
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   125
      exit 2
wenzelm@40570
   126
      ;;
wenzelm@40570
   127
  esac
wenzelm@32305
   128
wenzelm@32305
   129
  if [ ! -d "$COMPONENT" ]; then
wenzelm@41758
   130
    echo >&2 "Missing Isabelle component directory: \"$COMPONENT\""
wenzelm@32305
   131
    exit 2
wenzelm@32305
   132
  elif [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@32305
   133
    ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@32305
   134
  else
wenzelm@32305
   135
    ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@32305
   136
  fi
wenzelm@32305
   137
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   138
    source "$COMPONENT/etc/settings"
wenzelm@41760
   139
    local RC="$?"
wenzelm@41760
   140
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   141
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   142
      exit 2
wenzelm@41760
   143
    fi
wenzelm@32305
   144
  fi
wenzelm@32305
   145
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@32305
   146
    {
wenzelm@33512
   147
      while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@33512
   148
      do
wenzelm@32305
   149
        case "$REPLY" in
wenzelm@32305
   150
          \#* | "") ;;
wenzelm@32305
   151
          /*) init_component "$REPLY" ;;
wenzelm@32305
   152
          *) init_component "$COMPONENT/$REPLY" ;;
wenzelm@32305
   153
        esac
wenzelm@32305
   154
      done
wenzelm@33295
   155
    } < "$COMPONENT/etc/components"
wenzelm@32305
   156
  fi
wenzelm@32305
   157
}
wenzelm@32305
   158
wenzelm@32305
   159
#main components
wenzelm@32305
   160
init_component "$ISABELLE_HOME"
wenzelm@32321
   161
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   162
wenzelm@21490
   163
#ML system identifier
wenzelm@6413
   164
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   165
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   166
else
wenzelm@6413
   167
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   168
fi
wenzelm@21468
   169
wenzelm@6413
   170
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@3118
   171
wenzelm@2299
   172
set +o allexport
wenzelm@7770
   173
wenzelm@7770
   174
fi