Debian Codegraph @

scripts/locker-build

raw
1 #!/bin/bash
2
3 #########################################################
4 # Build script to build BarnOwl for the locker.
5 die() {
6 echo "$@" 2>&1;
7 if [ -n "$TMPDIR" ]; then
8 if [ -n "$DRYRUN" ]; then
9 echo "Dropping to a shell to investigate...";
10 $SHELL
11 fi
12 fi
13 exit 1;
14 }
15
16 usage () {
17 cat >&2 <<EOF
18 Usage: $0 [-n] [-o OUTPUT-TGZ] SOURCE-TARBALL
19 -n is a dry-run, and drops to a shell in the build directory
20 -o does the install into a temporary directory and tars it into the
21 specified tarball instead.
22
23 SOURCE-TARBALL is a source tarball, created by do-release.
24 EOF
25 exit 2;
26 }
27
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=
34 DRYRUN=
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
50
51 SRC_TGZ="$1"
52
53 test -z "$SRC_TGZ" && usage
54
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
69 TMPDIR=$(mktemp -d /tmp/barnowl-build-XXXXXX) || die "Unable to mktemp"
70
71 exittrap() { rm -rf "$TMPDIR"; }
72
73 $TAR -C "$TMPDIR" -xzf "$SRC_TGZ" || die "Unable to untar"
74
75 (
76 cd "$TMPDIR"/* || die "Unable to cd to $TMPDIR"
77 VERS=$(perl -ne 'print $1 if m{^AC_INIT\(\[[^\]]+\],\s*\[([^\]]+)\]}' configure.ac)
78 test -z "$VERS" && die "Unable to detect barnowl version."
79
80 echo "Building BarnOwl version $VERS"
81
82 opt_rpath="-Wl,-R"
83 [ $(uname) = "SunOS" ] && opt_rpath="-R"
84
85 BARNOWL="/afs/sipb.mit.edu/project/barnowl/arch/$ATHENA_SYS"
86 export PKG_CONFIG_PATH="$BARNOWL/lib/pkgconfig"
87 eval $("$BARNOWL/bin/barnowl-perl-config")
88
89 SUFFIX=
90 case $ATHENA_SYS in
91 *_deb50)
92 # Both Debian Lenny and Ubuntu Karmic use the _deb50
93 # sysname, but they have different zephyr versions (soname
94 # 3 and 4, respectively). So for that sysname, we include
95 # the zephyr soname into the build name, and the wrapper
96 # script picks the right one.
97 if /sbin/ldconfig -p | grep -qF "libzephyr.so.4"; then
98 SUFFIX=.zephyr4
99 else
100 SUFFIX=.zephyr3
101 fi
102 ;;
103 esac
104
105 CPPFLAGS="-I$BARNOWL/include -I/usr/athena/include" \
106 LDFLAGS="-L$BARNOWL/lib -L/usr/athena/lib $opt_rpath$BARNOWL/lib" \
107 ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \
108 --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \
109 --program-suffix="-$VERS$SUFFIX" \
110 --with-zephyr --without-stack-protector \
111 || die "configure failed"
112
113 $MAKE clean || die "make clean failed"
114
115 CPUS=$(athinfo localhost cpuspeed | grep -c MHz)
116 if [ "$CPUS" = 0 ]; then
117 CPUS=1
118 fi
119
120 $MAKE -j$CPUS all || die "make failed"
121
122 $MAKE check || die "Unit tests failed"
123
124 if [ -n "$DRYRUN" ]; then
125 echo "Build completed; Dropping to a shell..."
126 $SHELL
127 else
128 if [ -n "$OUT_TGZ" ]; then
129 mkdir tgz
130 $MAKE DESTDIR=tgz install || die "Install failed"
131 else
132 $MAKE install || die "Install failed"
133 fi
134 fi
135 )
136
137 if [ "$?" -ne 0 ]; then
138 exit "$?"
139 fi
140
141 if [ -n "$OUT_TGZ" ]; then
142 $TAR -C "$TMPDIR/"*/tgz -czvf "$OUT_TGZ" . || die "Make tarball failed"
143 fi
144
145 rm -rf "$TMPDIR"
146 exittrap() { :; }