1 | #!/bin/sh |
---|
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 | exit 1; |
---|
18 | } |
---|
19 | |
---|
20 | usage () { |
---|
21 | echo "Usage: $0 [-n] [-o OUTPUT-TGZ] VERSION SOURCE-TARBALL" |
---|
22 | exit 2; |
---|
23 | } |
---|
24 | |
---|
25 | exittrap() { :; } |
---|
26 | for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done |
---|
27 | trap 'exittrap' EXIT |
---|
28 | |
---|
29 | SRC_TGZ= |
---|
30 | OUT_TGZ= |
---|
31 | DRYRUN= |
---|
32 | |
---|
33 | set -- `getopt no: "$@"` |
---|
34 | [ $? -eq 0 ] || usage |
---|
35 | |
---|
36 | for opt |
---|
37 | do |
---|
38 | case "$opt" in |
---|
39 | -n) |
---|
40 | DRYRUN=1; shift ;; |
---|
41 | -o) |
---|
42 | OUT_TGZ="$2"; shift 2;; |
---|
43 | --) |
---|
44 | shift; break ;; |
---|
45 | esac |
---|
46 | done |
---|
47 | |
---|
48 | NAME="$1" |
---|
49 | SRC_TGZ="$2" |
---|
50 | |
---|
51 | test -z "$NAME" && usage |
---|
52 | test -z "$SRC_TGZ" && usage |
---|
53 | |
---|
54 | |
---|
55 | ATHENA_SYS="${ATHENA_SYS:-$(machtype -S)}" |
---|
56 | |
---|
57 | if [ "$(uname)" = "SunOS" ]; then |
---|
58 | MAKE=gmake |
---|
59 | TAR=gtar |
---|
60 | else |
---|
61 | MAKE=make |
---|
62 | TAR=tar |
---|
63 | fi |
---|
64 | |
---|
65 | attach barnowl |
---|
66 | aklog |
---|
67 | |
---|
68 | TMPDIR=$(mktemp -d /tmp/barnowl-build-XXXXXX) || die "Unable to mktemp" |
---|
69 | |
---|
70 | exittrap() { rm -rf "$TMPDIR"; } |
---|
71 | |
---|
72 | $TAR -C "$TMPDIR" -xzvf "$SRC_TGZ" || die "Unable to untar" |
---|
73 | |
---|
74 | ( |
---|
75 | cd "$TMPDIR"/* || die "Unable to cd to $TMPDIR" |
---|
76 | |
---|
77 | BARNOWL="/afs/sipb.mit.edu/project/barnowl/arch/$ATHENA_SYS" |
---|
78 | export PKG_CONFIG_PATH="$BARNOWL/lib/pkgconfig" |
---|
79 | |
---|
80 | CFLAGS="-I$BARNOWL/include" \ |
---|
81 | LDFLAGS="-L$BARNOWL/lib -Wl,-R$BARNOWL/lib" \ |
---|
82 | ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \ |
---|
83 | --prefix="/mit/barnowl/builds/$NAME" --mandir=/mit/barnowl/man \ |
---|
84 | PROTECT_CFLAGS=-fno-stack-protector \ |
---|
85 | || die "configure failed" |
---|
86 | |
---|
87 | $MAKE clean || die "make clean failed" |
---|
88 | |
---|
89 | CPUS=$(athinfo localhost cpuspeed | grep -c MHz) |
---|
90 | if [ "$CPUS" = 0 ]; then |
---|
91 | CPUS=1 |
---|
92 | fi |
---|
93 | |
---|
94 | $MAKE -j$CPUS EXE=$NAME all || die "make failed" |
---|
95 | |
---|
96 | if [ -n "$DRYRUN" ]; then |
---|
97 | echo "Build completed; Dropping to a shell..." |
---|
98 | $SHELL |
---|
99 | else |
---|
100 | if [ -n "$OUT_TGZ" ]; then |
---|
101 | mkdir tgz |
---|
102 | $MAKE EXE=$NAME DESTDIR=tgz install || die "Install failed" |
---|
103 | else |
---|
104 | $MAKE EXE=$NAME install || die "Install failed" |
---|
105 | fi |
---|
106 | fi |
---|
107 | ) |
---|
108 | |
---|
109 | if [ -n "$OUT_TGZ" ]; then |
---|
110 | $TAR -C "$TMPDIR/"*/tgz -czvf "$OUT_TGZ" . || die "Make tarball failed" |
---|
111 | fi |
---|
112 | |
---|
113 | rm -rf "$TMPDIR" |
---|
114 | exittrap() { :; } |
---|