lib/scripts/getsettings
author wenzelm
Sat Sep 28 13:50:38 2013 +0200 (2013-09-28)
changeset 53967 bfaae48b0ce0
parent 53913 5ff12177a067
child 53970 eee1863c565a
permissions -rwxr-xr-x
simplified ISABELLE_HOME on Windows (see also 9c8a1b9c0630, 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@53913
    14
#GNU tar (notably on Mac OS X)
wenzelm@53913
    15
if [ -x /usr/bin/gnutar ]; then
wenzelm@53913
    16
  function tar() { /usr/bin/gnutar "$@"; }
wenzelm@53913
    17
fi
wenzelm@53913
    18
wenzelm@48838
    19
#Cygwin vs. POSIX
wenzelm@47461
    20
if [ "$OSTYPE" = cygwin ]
wenzelm@47461
    21
then
wenzelm@47661
    22
  if [ -z "$USER_HOME" ]; then
wenzelm@47661
    23
    USER_HOME="$(cygpath -u "$HOMEDRIVE\\$HOMEPATH")"
wenzelm@47661
    24
  fi
wenzelm@47661
    25
wenzelm@47461
    26
  function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
wenzelm@47996
    27
  CYGWIN_ROOT="$(jvmpath "/")"
wenzelm@53576
    28
wenzelm@53576
    29
  ISABELLE_CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
wenzelm@53576
    30
  unset CLASSPATH
wenzelm@47461
    31
else
wenzelm@47661
    32
  if [ -z "$USER_HOME" ]; then
wenzelm@47661
    33
    USER_HOME="$HOME"
wenzelm@47661
    34
  fi
wenzelm@47661
    35
wenzelm@47461
    36
  function jvmpath() { echo "$@"; }
wenzelm@53576
    37
wenzelm@53576
    38
  ISABELLE_CLASSPATH="$CLASSPATH"
wenzelm@53576
    39
  unset CLASSPATH
wenzelm@47461
    40
fi
wenzelm@47461
    41
wenzelm@15972
    42
export ISABELLE_HOME
wenzelm@2736
    43
wenzelm@11553
    44
#key executables
wenzelm@28499
    45
ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle-process"
wenzelm@28504
    46
ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
wenzelm@2299
    47
wenzelm@34254
    48
function isabelle ()
wenzelm@34254
    49
{
wenzelm@34254
    50
  "$ISABELLE_TOOL" "$@"
wenzelm@34254
    51
}
wenzelm@34254
    52
wenzelm@36196
    53
#platform
wenzelm@41758
    54
source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
wenzelm@48455
    55
if [ -z "$ISABELLE_PLATFORM" ]; then
wenzelm@48455
    56
  echo 1>&2 "Failed to determine hardware and operating system type!"
wenzelm@48455
    57
  exit 2
wenzelm@48455
    58
fi
wenzelm@36196
    59
wenzelm@25434
    60
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    61
ISABELLE_ID=""
wenzelm@48837
    62
[ -z "$ISABELLE_IDENTIFIER" ] && ISABELLE_IDENTIFIER=""
wenzelm@21490
    63
wenzelm@41511
    64
#sometimes users put strange things in here ...
wenzelm@2621
    65
unset ENV
wenzelm@2621
    66
unset BASH_ENV
wenzelm@2621
    67
wenzelm@41614
    68
#shared library convenience
wenzelm@52443
    69
function librarypath ()
wenzelm@52443
    70
{
wenzelm@41614
    71
  for X in "$@"
wenzelm@41614
    72
  do
wenzelm@41614
    73
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    74
      *-darwin)
wenzelm@41614
    75
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
    76
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
    77
        else
wenzelm@41614
    78
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
    79
        fi
wenzelm@41614
    80
        export DYLD_LIBRARY_PATH
wenzelm@41614
    81
        ;;
wenzelm@41614
    82
      *)
wenzelm@41614
    83
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
    84
          LD_LIBRARY_PATH="$X"
wenzelm@41614
    85
        else
wenzelm@41614
    86
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
    87
        fi
wenzelm@41614
    88
        export LD_LIBRARY_PATH
wenzelm@41614
    89
        ;;
wenzelm@41614
    90
    esac
wenzelm@41614
    91
  done
wenzelm@41614
    92
}
wenzelm@41614
    93
wenzelm@47115
    94
#robust invocation via ISABELLE_JDK_HOME
wenzelm@52443
    95
function isabelle_jdk ()
wenzelm@52443
    96
{
wenzelm@47465
    97
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
    98
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
    99
    return 127
wenzelm@47465
   100
  else
wenzelm@47465
   101
    local PRG="$1"; shift
wenzelm@47465
   102
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
   103
  fi
wenzelm@47115
   104
}
wenzelm@47115
   105
wenzelm@47115
   106
#robust invocation via SCALA_HOME
wenzelm@52443
   107
function isabelle_scala ()
wenzelm@52443
   108
{
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@52443
   121
#administrative build
wenzelm@52443
   122
if [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@52443
   123
  function isabelle_admin_build ()
wenzelm@52443
   124
  {
wenzelm@52443
   125
    "$ISABELLE_HOME/Admin/build" "$@"
wenzelm@52443
   126
  }
wenzelm@52443
   127
else
wenzelm@52443
   128
  function isabelle_admin_build () { return 0; }
wenzelm@52443
   129
fi
wenzelm@52443
   130
wenzelm@53576
   131
#classpath
wenzelm@52443
   132
function classpath ()
wenzelm@52443
   133
{
wenzelm@27908
   134
  for X in "$@"
wenzelm@27908
   135
  do
wenzelm@53576
   136
    if [ -z "$ISABELLE_CLASSPATH" ]; then
wenzelm@53576
   137
      ISABELLE_CLASSPATH="$X"
wenzelm@27908
   138
    else
wenzelm@53580
   139
      ISABELLE_CLASSPATH="$ISABELLE_CLASSPATH:$X"
wenzelm@27908
   140
    fi
wenzelm@27908
   141
  done
wenzelm@53576
   142
  export ISABELLE_CLASSPATH
wenzelm@27908
   143
}
wenzelm@27908
   144
wenzelm@32390
   145
#arrays
wenzelm@32390
   146
function splitarray ()
wenzelm@32390
   147
{
wenzelm@32390
   148
  SPLITARRAY=()
wenzelm@32390
   149
  local IFS="$1"; shift
wenzelm@32390
   150
  for X in $*
wenzelm@32390
   151
  do
wenzelm@32390
   152
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   153
  done
wenzelm@32390
   154
}
wenzelm@32390
   155
wenzelm@48838
   156
wenzelm@48838
   157
# components
wenzelm@48838
   158
wenzelm@32305
   159
ISABELLE_COMPONENTS=""
wenzelm@48838
   160
ISABELLE_COMPONENTS_MISSING=""
wenzelm@48838
   161
wenzelm@48838
   162
#init component tree
wenzelm@32305
   163
function init_component ()
wenzelm@32305
   164
{
wenzelm@32305
   165
  local COMPONENT="$1"
wenzelm@40570
   166
  case "$COMPONENT" in
wenzelm@40570
   167
    /*) ;;
wenzelm@40570
   168
    *)
wenzelm@40570
   169
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   170
      exit 2
wenzelm@40570
   171
      ;;
wenzelm@40570
   172
  esac
wenzelm@32305
   173
wenzelm@48838
   174
  if [ -d "$COMPONENT" ]; then
wenzelm@48838
   175
    if [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@48838
   176
      ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@48838
   177
    else
wenzelm@48838
   178
      ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@48838
   179
    fi
wenzelm@48838
   180
  else
wenzelm@48448
   181
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@48838
   182
    if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
wenzelm@48838
   183
      ISABELLE_COMPONENTS_MISSING="$COMPONENT"
wenzelm@48838
   184
    else
wenzelm@48838
   185
      ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
wenzelm@48838
   186
    fi
wenzelm@32305
   187
  fi
wenzelm@48838
   188
wenzelm@32305
   189
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   190
    source "$COMPONENT/etc/settings"
wenzelm@41760
   191
    local RC="$?"
wenzelm@41760
   192
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   193
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   194
      exit 2
wenzelm@41760
   195
    fi
wenzelm@32305
   196
  fi
wenzelm@32305
   197
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@48838
   198
    init_components "$COMPONENT" "$COMPONENT/etc/components"
wenzelm@48838
   199
  fi
wenzelm@48838
   200
}
wenzelm@48838
   201
wenzelm@48838
   202
#init component forest
wenzelm@48838
   203
function init_components ()
wenzelm@48838
   204
{
wenzelm@48838
   205
  local BASE="$1"
wenzelm@48838
   206
  local CATALOG="$2"
wenzelm@48838
   207
wenzelm@48838
   208
  if [ ! -f "$CATALOG" ]; then
wenzelm@48838
   209
    echo >&2 "Bad component catalog file: \"$CATALOG\""
wenzelm@48838
   210
    exit 2
wenzelm@48838
   211
  fi
wenzelm@48838
   212
  {
wenzelm@48838
   213
    while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@48838
   214
    do
wenzelm@48838
   215
      case "$REPLY" in
wenzelm@48838
   216
        \#* | "") ;;
wenzelm@48838
   217
        /*) init_component "$REPLY" ;;
wenzelm@48838
   218
        *) init_component "$BASE/$REPLY" ;;
wenzelm@48838
   219
      esac
wenzelm@48838
   220
    done
wenzelm@48838
   221
  } < "$CATALOG"
wenzelm@32305
   222
}
wenzelm@32305
   223
wenzelm@32305
   224
#main components
wenzelm@32305
   225
init_component "$ISABELLE_HOME"
wenzelm@48725
   226
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
wenzelm@32321
   227
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   228
wenzelm@48838
   229
wenzelm@21490
   230
#ML system identifier
wenzelm@6413
   231
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   232
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   233
else
wenzelm@6413
   234
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   235
fi
wenzelm@21468
   236
wenzelm@48838
   237
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@48838
   238
wenzelm@47748
   239
#enforce JAVA_HOME
wenzelm@47748
   240
export JAVA_HOME="$ISABELLE_JDK_HOME"
wenzelm@47748
   241
wenzelm@48495
   242
#build condition etc.
wenzelm@48495
   243
case "$ML_SYSTEM" in
wenzelm@48495
   244
  polyml*)
wenzelm@48495
   245
    ISABELLE_POLYML="true"
wenzelm@48495
   246
    ;;
wenzelm@48495
   247
  *)
wenzelm@48495
   248
    ISABELLE_POLYML=""
wenzelm@48495
   249
    ;;
wenzelm@48495
   250
esac
wenzelm@48495
   251
wenzelm@2299
   252
set +o allexport
wenzelm@7770
   253
wenzelm@7770
   254
fi