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