Admin/makebundle
author wenzelm
Sat, 17 Sep 2011 16:53:01 +0200
changeset 44951 3aa3aeb4980f
parent 44807 44db3e309060
child 44964 23dbab7f8cf4
permissions -rwxr-xr-x
specific bundle for x86_64-linux, which is especially important for JRE due to its extra library dependencies;

#!/usr/bin/env bash
#
# makebundle -- re-package with add-on components

## diagnostics

PRG=$(basename "$0")

function usage()
{
  echo
  echo "Usage: $PRG ARCHIVE PLATFORM"
  echo
  echo "  Re-package Isabelle source distribution with add-on components"
  echo "  and heap images"
  echo
  exit 1
}

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


## implicit and explicit arguments

TMP="/var/tmp/isabelle-makebundle$$"
mkdir "$TMP" || fail "Cannot create directory $TMP"

[ "$#" -ne 2 ] && usage

ARCHIVE="$1"; shift
PLATFORM="$1"; shift

[ -f "$ARCHIVE" ] || fail "Bad source archive: $ARCHIVE"


## main

ARCHIVE_DIR="$(cd $(dirname "$ARCHIVE"); echo "$PWD")"
ISABELLE_NAME="$(basename "$ARCHIVE" .tar.gz)"
ISABELLE_HOME="$TMP/$ISABELLE_NAME"

tar -C "$TMP" -x -z -f "$ARCHIVE"


echo "#bundled components" >> "$ISABELLE_HOME/etc/components"

for CONTRIB in "$ARCHIVE_DIR/contrib/"*.tar.gz "$ARCHIVE_DIR/contrib/$PLATFORM"/*.tar.gz
do
  if [ -f "$CONTRIB" ]; then
    tar -C "$ISABELLE_HOME/contrib" -x -z -f "$CONTRIB"
    NAME="$(basename "$CONTRIB" .tar.gz)"
    [ -d "$ISABELLE_HOME/contrib/$NAME" ] || fail "Bad archive content $CONTRIB"

    if [ -e "$ISABELLE_HOME/contrib/$NAME/etc/settings" ]; then
      echo "component $NAME"
      echo "contrib/$NAME" >> "$ISABELLE_HOME/etc/components"
    else
      echo "package $NAME"
    fi
  fi
done


HEAPS_ARCHIVE="$ARCHIVE_DIR/${ISABELLE_NAME}_heaps_${PLATFORM}.tar.gz"
[ -f "$HEAPS_ARCHIVE" ] || fail "Bad heaps archive: $HEAPS_ARCHIVE"
echo "heaps"
tar -C "$TMP" -x -z -f "$HEAPS_ARCHIVE"


(
  cd "$TMP/$ISABELLE_NAME/contrib/ProofGeneral"
  find . -name "*.elc" -exec rm {} ";"
)

case "$PLATFORM" in
  x86_64-linux)
    perl -pi -e 's,^ML_PLATFORM=.*$,ML_PLATFORM="\$ISABELLE_PLATFORM64",g;' "$TMP/$ISABELLE_NAME/etc/settings"
    perl -pi -e "s,^ML_OPTIONS=.*$,ML_OPTIONS=\"-H 400\",g;" "$TMP/$ISABELLE_NAME/etc/settings"
    ;;
  *-darwin)
    perl -pi -e "s,lookAndFeel=.*,lookAndFeel=com.apple.laf.AquaLookAndFeel,g;" \
      "$TMP/$ISABELLE_NAME/src/Tools/jEdit/dist/properties/jEdit.props"
    ;;
  *-cygwin)
    perl -pi -e "s,lookAndFeel=.*,lookAndFeel=com.sun.java.swing.plaf.windows.WindowsLookAndFeel,g;" \
      "$TMP/$ISABELLE_NAME/src/Tools/jEdit/dist/properties/jEdit.props"
    rm "$TMP/$ISABELLE_NAME/contrib/ProofGeneral"
    ln -s ProofGeneral-3.7.1.1 "$TMP/$ISABELLE_NAME/contrib/ProofGeneral"
    ;;
  *)
    ;;
esac

BUNDLE_ARCHIVE="${ARCHIVE_DIR}/${ISABELLE_NAME}_bundle_${PLATFORM}.tar.gz"

echo "$(basename "$BUNDLE_ARCHIVE")"
tar -C "$TMP" -c -z -f "$BUNDLE_ARCHIVE" "$ISABELLE_NAME"


# clean up
cd /tmp
rm -rf "$TMP"