lib/scripts/getsettings
author wenzelm
Mon Oct 27 16:11:24 2014 +0100 (2014-10-27)
changeset 58791 00916b0dd596
parent 58640 37f852399a32
child 60531 9cc91b8a6489
permissions -rwxr-xr-x
clarified ISABELLE_JDK_HOME vs. JAVA_HOME;
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@57411
    19
#sane environment defaults (notably on Mac OS X)
wenzelm@57411
    20
if [ "$ISABELLE_APP" = true -a -x /usr/libexec/path_helper ]; then
wenzelm@57411
    21
  eval $(/usr/libexec/path_helper -s)
wenzelm@57411
    22
fi
wenzelm@57411
    23
wenzelm@48838
    24
#Cygwin vs. POSIX
wenzelm@47461
    25
if [ "$OSTYPE" = cygwin ]
wenzelm@47461
    26
then
wenzelm@53970
    27
  unset INI_DIR
wenzelm@53970
    28
wenzelm@58640
    29
  if [ -n "$TEMP_WINDOWS" ]; then
wenzelm@58640
    30
    TMPDIR="$(cygpath -u "$TEMP_WINDOWS")"
wenzelm@58640
    31
    TMP="$TMPDIR"
wenzelm@58640
    32
    TEMP="$TMPDIR"
wenzelm@58640
    33
  fi
wenzelm@58640
    34
wenzelm@47661
    35
  if [ -z "$USER_HOME" ]; then
wenzelm@47661
    36
    USER_HOME="$(cygpath -u "$HOMEDRIVE\\$HOMEPATH")"
wenzelm@47661
    37
  fi
wenzelm@47661
    38
wenzelm@47461
    39
  function jvmpath() { cygpath -i -C UTF8 -w -p "$@"; }
wenzelm@47996
    40
  CYGWIN_ROOT="$(jvmpath "/")"
wenzelm@53576
    41
wenzelm@53576
    42
  ISABELLE_CLASSPATH="$(cygpath -i -u -p "$CLASSPATH")"
wenzelm@53576
    43
  unset CLASSPATH
wenzelm@47461
    44
else
wenzelm@47661
    45
  if [ -z "$USER_HOME" ]; then
wenzelm@47661
    46
    USER_HOME="$HOME"
wenzelm@47661
    47
  fi
wenzelm@47661
    48
wenzelm@47461
    49
  function jvmpath() { echo "$@"; }
wenzelm@53576
    50
wenzelm@53576
    51
  ISABELLE_CLASSPATH="$CLASSPATH"
wenzelm@53576
    52
  unset CLASSPATH
wenzelm@47461
    53
fi
wenzelm@47461
    54
wenzelm@15972
    55
export ISABELLE_HOME
wenzelm@2736
    56
wenzelm@11553
    57
#key executables
wenzelm@56440
    58
ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
wenzelm@56439
    59
ISABELLE_PROCESS="$ISABELLE_HOME/bin/isabelle_process"
wenzelm@56448
    60
ISABELLE_SCALA_SCRIPT="$ISABELLE_HOME/bin/isabelle_scala_script"
wenzelm@56440
    61
wenzelm@56440
    62
function isabelle ()
wenzelm@56440
    63
{
wenzelm@56440
    64
  "$ISABELLE_TOOL" "$@"
wenzelm@56440
    65
}
wenzelm@2299
    66
wenzelm@56439
    67
function isabelle_process ()
wenzelm@56439
    68
{
wenzelm@56439
    69
  "$ISABELLE_PROCESS" "$@"
wenzelm@56439
    70
}
wenzelm@56439
    71
wenzelm@56440
    72
function isabelle_scala_script ()
wenzelm@34254
    73
{
wenzelm@56448
    74
  "$ISABELLE_SCALA_SCRIPT" "$@"
wenzelm@34254
    75
}
wenzelm@34254
    76
wenzelm@36196
    77
#platform
wenzelm@41758
    78
source "$ISABELLE_HOME/lib/scripts/isabelle-platform"
wenzelm@48455
    79
if [ -z "$ISABELLE_PLATFORM" ]; then
wenzelm@48455
    80
  echo 1>&2 "Failed to determine hardware and operating system type!"
wenzelm@48455
    81
  exit 2
wenzelm@48455
    82
fi
wenzelm@36196
    83
wenzelm@25434
    84
#Isabelle distribution identifier -- filled in automatically!
wenzelm@41511
    85
ISABELLE_ID=""
wenzelm@48837
    86
[ -z "$ISABELLE_IDENTIFIER" ] && ISABELLE_IDENTIFIER=""
wenzelm@21490
    87
wenzelm@41511
    88
#sometimes users put strange things in here ...
wenzelm@2621
    89
unset ENV
wenzelm@2621
    90
unset BASH_ENV
wenzelm@2621
    91
wenzelm@41614
    92
#shared library convenience
wenzelm@52443
    93
function librarypath ()
wenzelm@52443
    94
{
wenzelm@41614
    95
  for X in "$@"
wenzelm@41614
    96
  do
wenzelm@41614
    97
    case "$ISABELLE_PLATFORM" in
wenzelm@41614
    98
      *-darwin)
wenzelm@41614
    99
        if [ -z "$DYLD_LIBRARY_PATH" ]; then
wenzelm@41614
   100
          DYLD_LIBRARY_PATH="$X"
wenzelm@41614
   101
        else
wenzelm@41614
   102
          DYLD_LIBRARY_PATH="$X:$DYLD_LIBRARY_PATH"
wenzelm@41614
   103
        fi
wenzelm@41614
   104
        export DYLD_LIBRARY_PATH
wenzelm@41614
   105
        ;;
wenzelm@41614
   106
      *)
wenzelm@41614
   107
        if [ -z "$LD_LIBRARY_PATH" ]; then
wenzelm@41614
   108
          LD_LIBRARY_PATH="$X"
wenzelm@41614
   109
        else
wenzelm@41614
   110
          LD_LIBRARY_PATH="$X:$LD_LIBRARY_PATH"
wenzelm@41614
   111
        fi
wenzelm@41614
   112
        export LD_LIBRARY_PATH
wenzelm@41614
   113
        ;;
wenzelm@41614
   114
    esac
wenzelm@41614
   115
  done
wenzelm@41614
   116
}
wenzelm@41614
   117
wenzelm@47115
   118
#robust invocation via ISABELLE_JDK_HOME
wenzelm@52443
   119
function isabelle_jdk ()
wenzelm@52443
   120
{
wenzelm@47465
   121
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@58791
   122
    echo "Unknown ISABELLE_JDK_HOME -- Java development tools unavailable" >&2
wenzelm@47490
   123
    return 127
wenzelm@47465
   124
  else
wenzelm@47465
   125
    local PRG="$1"; shift
wenzelm@47465
   126
    "$ISABELLE_JDK_HOME/bin/$PRG" "$@"
wenzelm@47465
   127
  fi
wenzelm@47115
   128
}
wenzelm@47115
   129
wenzelm@58791
   130
#robust invocation via JAVA_HOME
wenzelm@58791
   131
function isabelle_java ()
wenzelm@58791
   132
{
wenzelm@58791
   133
  if [ -z "$JAVA_HOME" ]; then
wenzelm@58791
   134
    echo "Unknown JAVA_HOME -- Java unavailable" >&2
wenzelm@58791
   135
    return 127
wenzelm@58791
   136
  else
wenzelm@58791
   137
    local PRG="$1"; shift
wenzelm@58791
   138
    "$JAVA_HOME/bin/$PRG" "$@"
wenzelm@58791
   139
  fi
wenzelm@58791
   140
}
wenzelm@58791
   141
wenzelm@47115
   142
#robust invocation via SCALA_HOME
wenzelm@52443
   143
function isabelle_scala ()
wenzelm@52443
   144
{
wenzelm@58791
   145
  if [ -z "$JAVA_HOME" ]; then
wenzelm@58791
   146
    echo "Unknown JAVA_HOME -- Java unavailable" >&2
wenzelm@47490
   147
    return 127
wenzelm@47465
   148
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   149
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   150
    return 127
wenzelm@47465
   151
  else
wenzelm@47465
   152
    local PRG="$1"; shift
wenzelm@47465
   153
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   154
  fi
wenzelm@47115
   155
}
wenzelm@47115
   156
wenzelm@52443
   157
#administrative build
wenzelm@52443
   158
if [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@52443
   159
  function isabelle_admin_build ()
wenzelm@52443
   160
  {
wenzelm@52443
   161
    "$ISABELLE_HOME/Admin/build" "$@"
wenzelm@52443
   162
  }
wenzelm@52443
   163
else
wenzelm@52443
   164
  function isabelle_admin_build () { return 0; }
wenzelm@52443
   165
fi
wenzelm@52443
   166
wenzelm@53576
   167
#classpath
wenzelm@52443
   168
function classpath ()
wenzelm@52443
   169
{
wenzelm@27908
   170
  for X in "$@"
wenzelm@27908
   171
  do
wenzelm@53576
   172
    if [ -z "$ISABELLE_CLASSPATH" ]; then
wenzelm@53576
   173
      ISABELLE_CLASSPATH="$X"
wenzelm@27908
   174
    else
wenzelm@53580
   175
      ISABELLE_CLASSPATH="$ISABELLE_CLASSPATH:$X"
wenzelm@27908
   176
    fi
wenzelm@27908
   177
  done
wenzelm@53576
   178
  export ISABELLE_CLASSPATH
wenzelm@27908
   179
}
wenzelm@27908
   180
wenzelm@32390
   181
#arrays
wenzelm@32390
   182
function splitarray ()
wenzelm@32390
   183
{
wenzelm@32390
   184
  SPLITARRAY=()
wenzelm@32390
   185
  local IFS="$1"; shift
wenzelm@32390
   186
  for X in $*
wenzelm@32390
   187
  do
wenzelm@32390
   188
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   189
  done
wenzelm@32390
   190
}
wenzelm@32390
   191
wenzelm@48838
   192
wenzelm@48838
   193
# components
wenzelm@48838
   194
wenzelm@32305
   195
ISABELLE_COMPONENTS=""
wenzelm@48838
   196
ISABELLE_COMPONENTS_MISSING=""
wenzelm@48838
   197
wenzelm@48838
   198
#init component tree
wenzelm@32305
   199
function init_component ()
wenzelm@32305
   200
{
wenzelm@32305
   201
  local COMPONENT="$1"
wenzelm@40570
   202
  case "$COMPONENT" in
wenzelm@40570
   203
    /*) ;;
wenzelm@40570
   204
    *)
wenzelm@40570
   205
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   206
      exit 2
wenzelm@40570
   207
      ;;
wenzelm@40570
   208
  esac
wenzelm@32305
   209
wenzelm@48838
   210
  if [ -d "$COMPONENT" ]; then
wenzelm@48838
   211
    if [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@48838
   212
      ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@48838
   213
    else
wenzelm@48838
   214
      ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@48838
   215
    fi
wenzelm@48838
   216
  else
wenzelm@48448
   217
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@48838
   218
    if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
wenzelm@48838
   219
      ISABELLE_COMPONENTS_MISSING="$COMPONENT"
wenzelm@48838
   220
    else
wenzelm@48838
   221
      ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
wenzelm@48838
   222
    fi
wenzelm@32305
   223
  fi
wenzelm@48838
   224
wenzelm@32305
   225
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   226
    source "$COMPONENT/etc/settings"
wenzelm@41760
   227
    local RC="$?"
wenzelm@41760
   228
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   229
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   230
      exit 2
wenzelm@41760
   231
    fi
wenzelm@32305
   232
  fi
wenzelm@32305
   233
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@48838
   234
    init_components "$COMPONENT" "$COMPONENT/etc/components"
wenzelm@48838
   235
  fi
wenzelm@48838
   236
}
wenzelm@48838
   237
wenzelm@48838
   238
#init component forest
wenzelm@48838
   239
function init_components ()
wenzelm@48838
   240
{
wenzelm@48838
   241
  local BASE="$1"
wenzelm@48838
   242
  local CATALOG="$2"
wenzelm@48838
   243
wenzelm@48838
   244
  if [ ! -f "$CATALOG" ]; then
wenzelm@48838
   245
    echo >&2 "Bad component catalog file: \"$CATALOG\""
wenzelm@48838
   246
    exit 2
wenzelm@48838
   247
  fi
wenzelm@48838
   248
  {
wenzelm@48838
   249
    while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@48838
   250
    do
wenzelm@48838
   251
      case "$REPLY" in
wenzelm@48838
   252
        \#* | "") ;;
wenzelm@48838
   253
        /*) init_component "$REPLY" ;;
wenzelm@48838
   254
        *) init_component "$BASE/$REPLY" ;;
wenzelm@48838
   255
      esac
wenzelm@48838
   256
    done
wenzelm@48838
   257
  } < "$CATALOG"
wenzelm@32305
   258
}
wenzelm@32305
   259
wenzelm@32305
   260
#main components
wenzelm@32305
   261
init_component "$ISABELLE_HOME"
wenzelm@48725
   262
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
wenzelm@32321
   263
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   264
wenzelm@48838
   265
wenzelm@21490
   266
#ML system identifier
wenzelm@6413
   267
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   268
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   269
else
wenzelm@6413
   270
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   271
fi
wenzelm@21468
   272
wenzelm@48838
   273
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@48838
   274
wenzelm@47748
   275
#enforce JAVA_HOME
wenzelm@58791
   276
export JAVA_HOME="$ISABELLE_JDK_HOME/jre"
wenzelm@47748
   277
wenzelm@48495
   278
#build condition etc.
wenzelm@48495
   279
case "$ML_SYSTEM" in
wenzelm@48495
   280
  polyml*)
wenzelm@58413
   281
    ML_SYSTEM_POLYML="true"
wenzelm@48495
   282
    ;;
wenzelm@48495
   283
  *)
wenzelm@58413
   284
    ML_SYSTEM_POLYML=""
wenzelm@48495
   285
    ;;
wenzelm@48495
   286
esac
wenzelm@48495
   287
wenzelm@2299
   288
set +o allexport
wenzelm@7770
   289
wenzelm@7770
   290
fi