[de9edab] | 1 | #!/bin/bash |
---|
[56e4869] | 2 | |
---|
| 3 | ######################################################### |
---|
| 4 | # Build script to build BarnOwl for the locker. |
---|
| 5 | |
---|
| 6 | # Usage: locker-build [-n] [-o OUTPUT-TGZ] VERSION SOURCE-TARBALL |
---|
| 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 |
---|
| 11 | # VERSION should be of the form 'barnowl-VERSION' |
---|
| 12 | # |
---|
| 13 | # TODO: Scrape $VERSION from the tarball |
---|
[5c81472] | 14 | |
---|
| 15 | die() { |
---|
[67dd774] | 16 | echo "$@" 2>&1; |
---|
| 17 | if [ -n "$TMPDIR" ]; then |
---|
| 18 | if [ -n "$DRYRUN" ]; then |
---|
| 19 | echo "Dropping to a shell to investigate..."; |
---|
| 20 | $SHELL |
---|
| 21 | fi |
---|
| 22 | fi |
---|
| 23 | exit 1; |
---|
[56e4869] | 24 | } |
---|
| 25 | |
---|
| 26 | usage () { |
---|
| 27 | echo "Usage: $0 [-n] [-o OUTPUT-TGZ] VERSION SOURCE-TARBALL" |
---|
| 28 | exit 2; |
---|
[5c81472] | 29 | } |
---|
| 30 | |
---|
[56e4869] | 31 | exittrap() { :; } |
---|
| 32 | for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done |
---|
| 33 | trap 'exittrap' EXIT |
---|
| 34 | |
---|
| 35 | SRC_TGZ= |
---|
| 36 | OUT_TGZ= |
---|
[5c81472] | 37 | DRYRUN= |
---|
[56e4869] | 38 | |
---|
| 39 | set -- `getopt no: "$@"` |
---|
| 40 | [ $? -eq 0 ] || usage |
---|
| 41 | |
---|
| 42 | for opt |
---|
| 43 | do |
---|
| 44 | case "$opt" in |
---|
| 45 | -n) |
---|
| 46 | DRYRUN=1; shift ;; |
---|
| 47 | -o) |
---|
| 48 | OUT_TGZ="$2"; shift 2;; |
---|
| 49 | --) |
---|
| 50 | shift; break ;; |
---|
| 51 | esac |
---|
| 52 | done |
---|
[5c81472] | 53 | |
---|
| 54 | NAME="$1" |
---|
[56e4869] | 55 | SRC_TGZ="$2" |
---|
| 56 | |
---|
| 57 | test -z "$NAME" && usage |
---|
| 58 | test -z "$SRC_TGZ" && usage |
---|
| 59 | |
---|
[5c81472] | 60 | |
---|
| 61 | ATHENA_SYS="${ATHENA_SYS:-$(machtype -S)}" |
---|
| 62 | |
---|
| 63 | if [ "$(uname)" = "SunOS" ]; then |
---|
| 64 | MAKE=gmake |
---|
| 65 | TAR=gtar |
---|
| 66 | else |
---|
| 67 | MAKE=make |
---|
| 68 | TAR=tar |
---|
| 69 | fi |
---|
| 70 | |
---|
| 71 | attach barnowl |
---|
| 72 | aklog |
---|
| 73 | |
---|
[56e4869] | 74 | TMPDIR=$(mktemp -d /tmp/barnowl-build-XXXXXX) || die "Unable to mktemp" |
---|
[5c81472] | 75 | |
---|
[56e4869] | 76 | exittrap() { rm -rf "$TMPDIR"; } |
---|
[5c81472] | 77 | |
---|
[67dd774] | 78 | $TAR -C "$TMPDIR" -xzf "$SRC_TGZ" || die "Unable to untar" |
---|
[5c81472] | 79 | |
---|
[56e4869] | 80 | ( |
---|
| 81 | cd "$TMPDIR"/* || die "Unable to cd to $TMPDIR" |
---|
[5c81472] | 82 | |
---|
[56e4869] | 83 | BARNOWL="/afs/sipb.mit.edu/project/barnowl/arch/$ATHENA_SYS" |
---|
| 84 | export PKG_CONFIG_PATH="$BARNOWL/lib/pkgconfig" |
---|
[5c81472] | 85 | |
---|
[56e4869] | 86 | CFLAGS="-I$BARNOWL/include" \ |
---|
| 87 | LDFLAGS="-L$BARNOWL/lib -Wl,-R$BARNOWL/lib" \ |
---|
| 88 | ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \ |
---|
| 89 | --prefix="/mit/barnowl/builds/$NAME" --mandir=/mit/barnowl/man \ |
---|
| 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 | |
---|
[56e4869] | 100 | $MAKE -j$CPUS EXE=$NAME 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 |
---|
| 108 | $MAKE EXE=$NAME DESTDIR=tgz install || die "Install failed" |
---|
| 109 | else |
---|
| 110 | $MAKE EXE=$NAME install || die "Install failed" |
---|
| 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() { :; } |
---|