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