1 | #!/bin/bash |
---|
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 |
---|
14 | |
---|
15 | die() { |
---|
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; |
---|
24 | } |
---|
25 | |
---|
26 | usage () { |
---|
27 | echo "Usage: $0 [-n] [-o OUTPUT-TGZ] VERSION SOURCE-TARBALL" |
---|
28 | exit 2; |
---|
29 | } |
---|
30 | |
---|
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= |
---|
37 | DRYRUN= |
---|
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 |
---|
53 | |
---|
54 | NAME="$1" |
---|
55 | SRC_TGZ="$2" |
---|
56 | |
---|
57 | test -z "$NAME" && usage |
---|
58 | test -z "$SRC_TGZ" && usage |
---|
59 | |
---|
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 | |
---|
74 | TMPDIR=$(mktemp -d /tmp/barnowl-build-XXXXXX) || die "Unable to mktemp" |
---|
75 | |
---|
76 | exittrap() { rm -rf "$TMPDIR"; } |
---|
77 | |
---|
78 | $TAR -C "$TMPDIR" -xzf "$SRC_TGZ" || die "Unable to untar" |
---|
79 | |
---|
80 | ( |
---|
81 | cd "$TMPDIR"/* || die "Unable to cd to $TMPDIR" |
---|
82 | |
---|
83 | BARNOWL="/afs/sipb.mit.edu/project/barnowl/arch/$ATHENA_SYS" |
---|
84 | export PKG_CONFIG_PATH="$BARNOWL/lib/pkgconfig" |
---|
85 | |
---|
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" |
---|
92 | |
---|
93 | $MAKE clean || die "make clean failed" |
---|
94 | |
---|
95 | CPUS=$(athinfo localhost cpuspeed | grep -c MHz) |
---|
96 | if [ "$CPUS" = 0 ]; then |
---|
97 | CPUS=1 |
---|
98 | fi |
---|
99 | |
---|
100 | $MAKE -j$CPUS EXE=$NAME all || die "make failed" |
---|
101 | |
---|
102 | if [ -n "$DRYRUN" ]; then |
---|
103 | echo "Build completed; Dropping to a shell..." |
---|
104 | $SHELL |
---|
105 | else |
---|
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 |
---|
112 | fi |
---|
113 | ) |
---|
114 | |
---|
115 | if [ "$?" -ne 0 ]; then |
---|
116 | exit "$?" |
---|
117 | fi |
---|
118 | |
---|
119 | if [ -n "$OUT_TGZ" ]; then |
---|
120 | $TAR -C "$TMPDIR/"*/tgz -czvf "$OUT_TGZ" . || die "Make tarball failed" |
---|
121 | fi |
---|
122 | |
---|
123 | rm -rf "$TMPDIR" |
---|
124 | exittrap() { :; } |
---|