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