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