lib/scripts/getsettings
author wenzelm
Thu Oct 09 13:56:27 2014 +0200 (2014-10-09)
changeset 58640 37f852399a32
parent 58413 22dd971f6938
child 58791 00916b0dd596
permissions -rwxr-xr-x
prefer original TEMP from Windows, e.g. relevant for Isabelle distribution within read-only directory (due to its bundled Cygwin and /tmp inside of it);
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@47465
   122
    echo "Unknown ISABELLE_JDK_HOME -- Java 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@47115
   130
#robust invocation via SCALA_HOME
wenzelm@52443
   131
function isabelle_scala ()
wenzelm@52443
   132
{
wenzelm@47465
   133
  if [ -z "$ISABELLE_JDK_HOME" ]; then
wenzelm@47465
   134
    echo "Unknown ISABELLE_JDK_HOME -- Java tools unavailable" >&2
wenzelm@47490
   135
    return 127
wenzelm@47465
   136
  elif [ -z "$SCALA_HOME" ]; then
wenzelm@47465
   137
    echo "Unknown SCALA_HOME -- Scala unavailable" >&2
wenzelm@47490
   138
    return 127
wenzelm@47465
   139
  else
wenzelm@47465
   140
    local PRG="$1"; shift
wenzelm@47465
   141
    "$SCALA_HOME/bin/$PRG" "$@"
wenzelm@47465
   142
  fi
wenzelm@47115
   143
}
wenzelm@47115
   144
wenzelm@52443
   145
#administrative build
wenzelm@52443
   146
if [ -e "$ISABELLE_HOME/Admin/build" ]; then
wenzelm@52443
   147
  function isabelle_admin_build ()
wenzelm@52443
   148
  {
wenzelm@52443
   149
    "$ISABELLE_HOME/Admin/build" "$@"
wenzelm@52443
   150
  }
wenzelm@52443
   151
else
wenzelm@52443
   152
  function isabelle_admin_build () { return 0; }
wenzelm@52443
   153
fi
wenzelm@52443
   154
wenzelm@53576
   155
#classpath
wenzelm@52443
   156
function classpath ()
wenzelm@52443
   157
{
wenzelm@27908
   158
  for X in "$@"
wenzelm@27908
   159
  do
wenzelm@53576
   160
    if [ -z "$ISABELLE_CLASSPATH" ]; then
wenzelm@53576
   161
      ISABELLE_CLASSPATH="$X"
wenzelm@27908
   162
    else
wenzelm@53580
   163
      ISABELLE_CLASSPATH="$ISABELLE_CLASSPATH:$X"
wenzelm@27908
   164
    fi
wenzelm@27908
   165
  done
wenzelm@53576
   166
  export ISABELLE_CLASSPATH
wenzelm@27908
   167
}
wenzelm@27908
   168
wenzelm@32390
   169
#arrays
wenzelm@32390
   170
function splitarray ()
wenzelm@32390
   171
{
wenzelm@32390
   172
  SPLITARRAY=()
wenzelm@32390
   173
  local IFS="$1"; shift
wenzelm@32390
   174
  for X in $*
wenzelm@32390
   175
  do
wenzelm@32390
   176
    SPLITARRAY["${#SPLITARRAY[@]}"]="$X"
wenzelm@32390
   177
  done
wenzelm@32390
   178
}
wenzelm@32390
   179
wenzelm@48838
   180
wenzelm@48838
   181
# components
wenzelm@48838
   182
wenzelm@32305
   183
ISABELLE_COMPONENTS=""
wenzelm@48838
   184
ISABELLE_COMPONENTS_MISSING=""
wenzelm@48838
   185
wenzelm@48838
   186
#init component tree
wenzelm@32305
   187
function init_component ()
wenzelm@32305
   188
{
wenzelm@32305
   189
  local COMPONENT="$1"
wenzelm@40570
   190
  case "$COMPONENT" in
wenzelm@40570
   191
    /*) ;;
wenzelm@40570
   192
    *)
wenzelm@40570
   193
      echo >&2 "Absolute component path required: \"$COMPONENT\""
wenzelm@40570
   194
      exit 2
wenzelm@40570
   195
      ;;
wenzelm@40570
   196
  esac
wenzelm@32305
   197
wenzelm@48838
   198
  if [ -d "$COMPONENT" ]; then
wenzelm@48838
   199
    if [ -z "$ISABELLE_COMPONENTS" ]; then
wenzelm@48838
   200
      ISABELLE_COMPONENTS="$COMPONENT"
wenzelm@48838
   201
    else
wenzelm@48838
   202
      ISABELLE_COMPONENTS="$ISABELLE_COMPONENTS:$COMPONENT"
wenzelm@48838
   203
    fi
wenzelm@48838
   204
  else
wenzelm@48448
   205
    echo >&2 "### Missing Isabelle component: \"$COMPONENT\""
wenzelm@48838
   206
    if [ -z "$ISABELLE_COMPONENTS_MISSING" ]; then
wenzelm@48838
   207
      ISABELLE_COMPONENTS_MISSING="$COMPONENT"
wenzelm@48838
   208
    else
wenzelm@48838
   209
      ISABELLE_COMPONENTS_MISSING="$ISABELLE_COMPONENTS_MISSING:$COMPONENT"
wenzelm@48838
   210
    fi
wenzelm@32305
   211
  fi
wenzelm@48838
   212
wenzelm@32305
   213
  if [ -f "$COMPONENT/etc/settings" ]; then
wenzelm@41760
   214
    source "$COMPONENT/etc/settings"
wenzelm@41760
   215
    local RC="$?"
wenzelm@41760
   216
    if [ "$RC" -ne 0 ]; then
wenzelm@41760
   217
      echo >&2 "Return code $RC from bash script: \"$COMPONENT/etc/settings\""
wenzelm@41760
   218
      exit 2
wenzelm@41760
   219
    fi
wenzelm@32305
   220
  fi
wenzelm@32305
   221
  if [ -f "$COMPONENT/etc/components" ]; then
wenzelm@48838
   222
    init_components "$COMPONENT" "$COMPONENT/etc/components"
wenzelm@48838
   223
  fi
wenzelm@48838
   224
}
wenzelm@48838
   225
wenzelm@48838
   226
#init component forest
wenzelm@48838
   227
function init_components ()
wenzelm@48838
   228
{
wenzelm@48838
   229
  local BASE="$1"
wenzelm@48838
   230
  local CATALOG="$2"
wenzelm@48838
   231
wenzelm@48838
   232
  if [ ! -f "$CATALOG" ]; then
wenzelm@48838
   233
    echo >&2 "Bad component catalog file: \"$CATALOG\""
wenzelm@48838
   234
    exit 2
wenzelm@48838
   235
  fi
wenzelm@48838
   236
  {
wenzelm@48838
   237
    while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
wenzelm@48838
   238
    do
wenzelm@48838
   239
      case "$REPLY" in
wenzelm@48838
   240
        \#* | "") ;;
wenzelm@48838
   241
        /*) init_component "$REPLY" ;;
wenzelm@48838
   242
        *) init_component "$BASE/$REPLY" ;;
wenzelm@48838
   243
      esac
wenzelm@48838
   244
    done
wenzelm@48838
   245
  } < "$CATALOG"
wenzelm@32305
   246
}
wenzelm@32305
   247
wenzelm@32305
   248
#main components
wenzelm@32305
   249
init_component "$ISABELLE_HOME"
wenzelm@48725
   250
[ -d "$ISABELLE_HOME/Admin" ] && init_component "$ISABELLE_HOME/Admin"
wenzelm@32321
   251
[ -d "$ISABELLE_HOME_USER" ] && init_component "$ISABELLE_HOME_USER"
wenzelm@2299
   252
wenzelm@48838
   253
wenzelm@21490
   254
#ML system identifier
wenzelm@6413
   255
if [ -z "$ML_PLATFORM" ]; then
wenzelm@6413
   256
  ML_IDENTIFIER="$ML_SYSTEM"
wenzelm@6413
   257
else
wenzelm@6413
   258
  ML_IDENTIFIER="${ML_SYSTEM}_${ML_PLATFORM}"
wenzelm@6413
   259
fi
wenzelm@21468
   260
wenzelm@48838
   261
ISABELLE_OUTPUT="$ISABELLE_OUTPUT/$ML_IDENTIFIER"
wenzelm@48838
   262
wenzelm@47748
   263
#enforce JAVA_HOME
wenzelm@47748
   264
export JAVA_HOME="$ISABELLE_JDK_HOME"
wenzelm@47748
   265
wenzelm@48495
   266
#build condition etc.
wenzelm@48495
   267
case "$ML_SYSTEM" in
wenzelm@48495
   268
  polyml*)
wenzelm@58413
   269
    ML_SYSTEM_POLYML="true"
wenzelm@48495
   270
    ;;
wenzelm@48495
   271
  *)
wenzelm@58413
   272
    ML_SYSTEM_POLYML=""
wenzelm@48495
   273
    ;;
wenzelm@48495
   274
esac
wenzelm@48495
   275
wenzelm@2299
   276
set +o allexport
wenzelm@7770
   277
wenzelm@7770
   278
fi