[de9edab] | 1 | #!/bin/bash |
---|
[56e4869] | 2 | |
---|
| 3 | ######################################################### |
---|
| 4 | # Build script to build BarnOwl for the locker. |
---|
| 5 | |
---|
[3043064] | 6 | # Usage: locker-build [-n] [-o OUTPUT-TGZ] SOURCE-TARBALL |
---|
[56e4869] | 7 | # -n is a dry-run, and drops to a shell in the build directory |
---|
| 8 | # -o does the install into a temporary directory and tars it into the |
---|
| 9 | # specified tarball instead. |
---|
| 10 | # SOURCE-TARBALL is a source tarball, created by do-release |
---|
[5c81472] | 11 | |
---|
| 12 | die() { |
---|
[67dd774] | 13 | echo "$@" 2>&1; |
---|
| 14 | if [ -n "$TMPDIR" ]; then |
---|
| 15 | if [ -n "$DRYRUN" ]; then |
---|
| 16 | echo "Dropping to a shell to investigate..."; |
---|
| 17 | $SHELL |
---|
| 18 | fi |
---|
| 19 | fi |
---|
| 20 | exit 1; |
---|
[56e4869] | 21 | } |
---|
| 22 | |
---|
| 23 | usage () { |
---|
[3043064] | 24 | echo "Usage: $0 [-n] [-o OUTPUT-TGZ] SOURCE-TARBALL" |
---|
[56e4869] | 25 | exit 2; |
---|
[5c81472] | 26 | } |
---|
| 27 | |
---|
[56e4869] | 28 | exittrap() { :; } |
---|
| 29 | for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done |
---|
| 30 | trap 'exittrap' EXIT |
---|
| 31 | |
---|
| 32 | SRC_TGZ= |
---|
| 33 | OUT_TGZ= |
---|
[5c81472] | 34 | DRYRUN= |
---|
[56e4869] | 35 | |
---|
| 36 | set -- `getopt no: "$@"` |
---|
| 37 | [ $? -eq 0 ] || usage |
---|
| 38 | |
---|
| 39 | for opt |
---|
| 40 | do |
---|
| 41 | case "$opt" in |
---|
| 42 | -n) |
---|
| 43 | DRYRUN=1; shift ;; |
---|
| 44 | -o) |
---|
| 45 | OUT_TGZ="$2"; shift 2;; |
---|
| 46 | --) |
---|
| 47 | shift; break ;; |
---|
| 48 | esac |
---|
| 49 | done |
---|
[5c81472] | 50 | |
---|
[3043064] | 51 | SRC_TGZ="$1" |
---|
[56e4869] | 52 | |
---|
| 53 | test -z "$SRC_TGZ" && usage |
---|
| 54 | |
---|
[5c81472] | 55 | |
---|
| 56 | ATHENA_SYS="${ATHENA_SYS:-$(machtype -S)}" |
---|
| 57 | |
---|
| 58 | if [ "$(uname)" = "SunOS" ]; then |
---|
| 59 | MAKE=gmake |
---|
| 60 | TAR=gtar |
---|
| 61 | else |
---|
| 62 | MAKE=make |
---|
| 63 | TAR=tar |
---|
| 64 | fi |
---|
| 65 | |
---|
| 66 | attach barnowl |
---|
| 67 | aklog |
---|
| 68 | |
---|
[56e4869] | 69 | TMPDIR=$(mktemp -d /tmp/barnowl-build-XXXXXX) || die "Unable to mktemp" |
---|
[5c81472] | 70 | |
---|
[56e4869] | 71 | exittrap() { rm -rf "$TMPDIR"; } |
---|
[5c81472] | 72 | |
---|
[67dd774] | 73 | $TAR -C "$TMPDIR" -xzf "$SRC_TGZ" || die "Unable to untar" |
---|
[5c81472] | 74 | |
---|
[56e4869] | 75 | ( |
---|
| 76 | cd "$TMPDIR"/* || die "Unable to cd to $TMPDIR" |
---|
[db98968] | 77 | VERS=$(perl -ne 'print $1 if m{^AC_INIT\(\[[^\]]+\],\s*\[([^\]]+)\]}' configure.ac) |
---|
[3043064] | 78 | test -z "$VERS" && die "Unable to detect barnowl version." |
---|
| 79 | |
---|
| 80 | echo "Building BarnOwl version $VERS" |
---|
[5c81472] | 81 | |
---|
[56e4869] | 82 | BARNOWL="/afs/sipb.mit.edu/project/barnowl/arch/$ATHENA_SYS" |
---|
| 83 | export PKG_CONFIG_PATH="$BARNOWL/lib/pkgconfig" |
---|
[5c81472] | 84 | |
---|
[56e4869] | 85 | CFLAGS="-I$BARNOWL/include" \ |
---|
| 86 | LDFLAGS="-L$BARNOWL/lib -Wl,-R$BARNOWL/lib" \ |
---|
| 87 | ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \ |
---|
[3043064] | 88 | --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \ |
---|
| 89 | --program-suffix="-$VERS" \ |
---|
[56e4869] | 90 | PROTECT_CFLAGS=-fno-stack-protector \ |
---|
| 91 | || die "configure failed" |
---|
[5c81472] | 92 | |
---|
[56e4869] | 93 | $MAKE clean || die "make clean failed" |
---|
[5c81472] | 94 | |
---|
[56e4869] | 95 | CPUS=$(athinfo localhost cpuspeed | grep -c MHz) |
---|
| 96 | if [ "$CPUS" = 0 ]; then |
---|
| 97 | CPUS=1 |
---|
| 98 | fi |
---|
[5c81472] | 99 | |
---|
[3043064] | 100 | $MAKE -j$CPUS all || die "make failed" |
---|
[5c81472] | 101 | |
---|
[56e4869] | 102 | if [ -n "$DRYRUN" ]; then |
---|
| 103 | echo "Build completed; Dropping to a shell..." |
---|
| 104 | $SHELL |
---|
[5c81472] | 105 | else |
---|
[56e4869] | 106 | if [ -n "$OUT_TGZ" ]; then |
---|
| 107 | mkdir tgz |
---|
[3043064] | 108 | $MAKE DESTDIR=tgz install || die "Install failed" |
---|
[56e4869] | 109 | else |
---|
[3043064] | 110 | $MAKE install || die "Install failed" |
---|
[56e4869] | 111 | fi |
---|
[5c81472] | 112 | fi |
---|
[56e4869] | 113 | ) |
---|
| 114 | |
---|
[67dd774] | 115 | if [ "$?" -ne 0 ]; then |
---|
| 116 | exit "$?" |
---|
| 117 | fi |
---|
| 118 | |
---|
[56e4869] | 119 | if [ -n "$OUT_TGZ" ]; then |
---|
| 120 | $TAR -C "$TMPDIR/"*/tgz -czvf "$OUT_TGZ" . || die "Make tarball failed" |
---|
[5c81472] | 121 | fi |
---|
| 122 | |
---|
| 123 | rm -rf "$TMPDIR" |
---|
[56e4869] | 124 | exittrap() { :; } |
---|