lib/Tools/install
author wenzelm
Tue, 25 Oct 2016 17:22:05 +0200
changeset 64398 5076725247fa
parent 63995 2e4d80723fb0
child 79059 ae682b2aab03
permissions -rwxr-xr-x
more robust printing of names in the context of outer syntax;

#!/usr/bin/env bash
#
# Author: Markus Wenzel, TU Muenchen
#
# DESCRIPTION: install standalone Isabelle executables


PRG=$(basename "$0")

function usage()
{
  echo
  echo "Usage: isabelle $PRG [OPTIONS] BINDIR"
  echo
  echo "  Options are:"
  echo "    -d DISTDIR   refer to DISTDIR as Isabelle distribution"
  echo "                 (default ISABELLE_HOME)"
  echo
  echo "  Install Isabelle executables with absolute references to the"
  echo "  distribution directory."
  echo
  exit 1
}

function fail()
{
  echo "$1" >&2
  exit 2
}


## process command line

# options

DISTDIR="$ISABELLE_HOME"
BINDIR=""

while getopts "d:" OPT
do
  case "$OPT" in
    d)
      DISTDIR="$OPTARG"
      ;;
    \?)
      usage
      ;;
  esac
done

shift $(($OPTIND - 1))


# args

[ "$#" -ge 1 ] && { BINDIR="$1"; shift; }
[ "$#" -ne 0 -o -z "$BINDIR" ] && usage


## main

echo "referring to distribution at \"$DISTDIR\""

mkdir -p "$BINDIR" || fail "Bad directory: \"$BINDIR\""

for NAME in isabelle isabelle_java isabelle_scala_script
do
  BIN="$BINDIR/$NAME"
  DIST="$DISTDIR/bin/$NAME"
  echo "installing $BIN"
  rm -f "$BIN"
  echo "#!/usr/bin/env bash" > "$BIN" || fail "Cannot write file: $BIN"
  echo >> "$BIN"
  echo "exec \"$DIST\" \"\$@\"" >> "$BIN"
  chmod +x "$BIN"
done