Admin/makebin
author haftmann
Wed Jan 30 10:57:47 2008 +0100 (2008-01-30)
changeset 26015 ad2756de580e
parent 25183 261d6791952c
child 26209 79c8d7277f33
permissions -rwxr-xr-x
idempotent semigroups
     1 #!/usr/bin/env bash
     2 #
     3 # $Id$
     4 #
     5 # makebin -- make Isabelle logic images for current platform.
     6 
     7 
     8 ## global settings
     9 
    10 TMP="/var/tmp/isabelle-makebin$$"
    11 
    12 TAR=tar
    13 type -path gtar >/dev/null && TAR=gtar
    14 
    15 export THIS_IS_ISABELLE_BUILD=true
    16 export THIS_IS_ISABELLE_MAKEBIN=true
    17 
    18 
    19 ## diagnostics
    20 
    21 PRG=$(basename "$0")
    22 
    23 function usage()
    24 {
    25   echo
    26   echo "Usage: $PRG [OPTIONS] ARCHIVE"
    27   echo
    28   echo "  Options are:"
    29   echo "    -l           produce library"
    30   echo "    -n           dry run"
    31   echo
    32   echo "  Precompile Isabelle for the current platform."
    33   echo
    34   exit 1
    35 }
    36 
    37 function fail()
    38 {
    39   echo "$1" >&2
    40   exit 2
    41 }
    42 
    43 
    44 ## process command line
    45 
    46 # options
    47 
    48 DO_LIBRARY=""
    49 DRY_RUN=""
    50 
    51 while getopts "ln" OPT
    52 do
    53   case "$OPT" in
    54     l)
    55       DO_LIBRARY=true
    56       ;;
    57     n)
    58       DRY_RUN=true
    59       ;;
    60     \?)
    61       usage
    62       ;;
    63   esac
    64 done
    65 
    66 shift $(($OPTIND - 1))
    67 
    68 
    69 # args
    70 
    71 [ "$#" -gt 1 ] && usage
    72 
    73 ARCHIVE="$1"; shift
    74 
    75 
    76 ## main
    77 
    78 [ ! -f "$ARCHIVE" ] && fail "Bad archive file $ARCHIVE"
    79 ARCHIVE_BASE=$(basename "$ARCHIVE")
    80 ARCHIVE_DIR=$(cd $(dirname "$ARCHIVE"); echo "$PWD")
    81 ARCHIVE_FULL="$ARCHIVE_DIR/$ARCHIVE_BASE"
    82 
    83 ISABELLE_NAME=$(basename "$ARCHIVE_BASE" .tar.gz)
    84 ISABELLE_HOME="$TMP/$ISABELLE_NAME"
    85 
    86 
    87 # build logics
    88 
    89 mkdir "$TMP" || fail "Cannot create directory $TMP"
    90 
    91 cd "$TMP"
    92 "$TAR" xzf "$ARCHIVE_FULL"
    93 cd "$ISABELLE_NAME"
    94 
    95 perl -pi \
    96   -e 's:^ISABELLE_USEDIR_OPTIONS=.*$:ISABELLE_USEDIR_OPTIONS="-p 1":;' \
    97   -e 's:^HOL_USEDIR_OPTIONS=.*$:HOL_USEDIR_OPTIONS="-p 2":;' \
    98   etc/settings
    99 
   100 if [ -n "$DO_LIBRARY" ]; then
   101   perl -pi -e 's:^ISABELLE_USEDIR_OPTIONS=.*$:ISABELLE_USEDIR_OPTIONS="-p 1 -i true -d pdf -V outline=/proof,/ML":;' \
   102     etc/settings
   103 fi
   104 
   105 ISABELLE_HOME_USER=$(./bin/isatool getenv -b ISABELLE_HOME_USER)
   106 [ -f "$ISABELLE_HOME_USER/etc/settings" ] && \
   107   echo "### WARNING!  Personal Isabelle settings present. " >&2
   108 
   109 COMPILER=$(./bin/isatool getenv -b ML_IDENTIFIER)
   110 PLATFORM=$(./bin/isatool getenv -b ML_PLATFORM)
   111 
   112 if [ -n "$DRY_RUN" ]; then
   113   mkdir -p "heaps/$COMPILER/log"
   114   touch "heaps/$COMPILER/HOL"
   115   touch "heaps/$COMPILER/log/HOL.gz"
   116   touch "heaps/$COMPILER/HOL-Complex"
   117   touch "heaps/$COMPILER/log/HOL-Complex.gz"
   118   touch "heaps/$COMPILER/ZF"
   119   touch "heaps/$COMPILER/log/ZF.gz"
   120   mkdir browser_info
   121 elif [ -n "$DO_LIBRARY" ]; then
   122   ./build -bait
   123 else
   124   ./build -b -m HOL-Complex HOL
   125   ./build -b ZF
   126   rm -f "heaps/$COMPILER/Pure" "heaps/$COMPILER/FOL"
   127 fi
   128 
   129 
   130 # prepare result
   131 
   132 cd "$TMP"
   133 
   134 chmod -R g=o "$TMP"
   135 chgrp -R isabelle "$TMP"
   136 
   137 if [ -n "$DO_LIBRARY" ]; then
   138   "$TAR" cf "${ISABELLE_NAME}_library.tar" $ISABELLE_NAME/browser_info && \
   139     gzip -f "${ISABELLE_NAME}_library.tar"
   140     cp -f "${ISABELLE_NAME}_library.tar.gz" "$ARCHIVE_DIR"
   141 else
   142   for IMG in HOL HOL-Complex ZF
   143   do
   144     "$TAR" cf "${IMG}_$PLATFORM.tar" \
   145       "$ISABELLE_NAME/heaps/$COMPILER/$IMG" \
   146       "$ISABELLE_NAME/heaps/$COMPILER/log/$IMG.gz"
   147     gzip -f "${IMG}_$PLATFORM.tar"
   148     cp -f "${IMG}_$PLATFORM.tar.gz" "$ARCHIVE_DIR"
   149   done
   150 fi
   151 
   152 
   153 # clean up
   154 cd /tmp
   155 rm -rf "$TMP"