1#! /bin/sh
2
3IAM=`hostname || uname -n`
4MYNAME=`IFS=. ; set $IAM ; echo $1`
5
6case "$1" in
7 '--one'|'-1')
8     shift
9     FB_FIRSTONLY=1
10     LIST=$MYNAME
11     ;;
12 *)
13     FB_FIRSTONLY=0
14esac
15
16BUILD_ARGS="$@"
17PARSE="--enable-parse-clocks"
18#PARSE=
19STD="--enable-simulator"
20
21case "$SIMUL::$FB_FIRSTONLY" in
22 ::*)
23    PARALLEL_BUILDS=1
24    ;;
25 *::0)
26    PARALLEL_BUILDS=$SIMUL
27    ;;
28 *)
29    PARALLEL_BUILDS=1
30esac
31
32case "$PARALLEL_BUILDS" in
33 1)  ;;
34 *)  echo Launching $PARALLEL_BUILDS parallel builds on each machine
35esac
36
37# Campus:
38# * baldwin	   sparc-sun-solaris2.10
39# * bridgeport	   sparc-sun-solaris2.10
40# * pogo	   sparc-sun-solaris2.10
41# * rackety	   sparc-sun-solaris2.10
42
43if [ ! -r sntp/libevent/build-aux/config.guess ] ; then
44	echo "Error: bootstrap required." 1>&2 && exit 1
45fi
46
47# HMS: we need $PWD because solaris produces /deacon/backroom when
48# we are in /backroom and in general there is no /deacon/backroom.
49c_d=${PWD:-`pwd`}
50
51SIG=`perl -e 'print rand'`
52
53case "$LIST" in
54 '') LIST="pogo" ;;
55esac
56
57for i in $LIST
58do
59    SKIPTHIS=0
60    [ -f .buildkey-$i ] && SKIPTHIS=1
61    case "$SKIPTHIS" in
62     1)
63	echo flock-build running on $i? check LIST, skipping
64	;;
65     0)
66	echo $i
67	echo $SIG > .buildkey-$i
68	case "1" in
69	 0)
70	    ssh $i "cd $c_d ; ./build $SIG $PARSE $STD $BUILD_ARGS" &
71	    ssh $i "cd $c_d ; ./build $SIG $PARSE $STD --disable-debugging --disable-saveconfig $BUILD_ARGS" &
72	    ssh $i "cd $c_d ; ./build $SIG $PARSE $STD --without-crypto --enable-c99-snprintf --enable-leap-smear $BUILD_ARGS" &
73	    ssh $i "cd $c_d ; ./build $SIG        $STD --disable-all-clocks --disable-autokey --without-sntp --disable-thread-support $BUILD_ARGS" &
74	    ;;
75	 1)
76	    cat > .flockbuild-$i-$SIG <<-ENDQUOT
77		#!/bin/sh
78
79		# script uses job control and expects to be invoked
80		# in a ssh session started with the -tt option, 
81		# which forces a pseudo-tty to be used.
82		
83		cd $c_d
84		COUNT=0
85
86		./build $SIG $PARSE $STD $BUILD_ARGS &
87
88		COUNT=\`expr \$COUNT + 1\`
89		echo \`date -u '+%H:%M:%S'\` $i started build \$COUNT of 4
90		[ 0 -lt \`expr \$COUNT % $PARALLEL_BUILDS\` ] || wait
91
92		case $FB_FIRSTONLY in
93		 '0')
94			./build $SIG $PARSE $STD --disable-debugging --disable-saveconfig $BUILD_ARGS &
95
96			COUNT=\`expr \$COUNT + 1\`
97			echo \`date -u '+%H:%M:%S'\` $i started build \$COUNT of 4
98			[ 0 -lt \`expr \$COUNT % $PARALLEL_BUILDS\` ] || wait
99
100			./build $SIG $PARSE $STD --without-crypto --enable-c99-snprintf --enable-leap-smear $BUILD_ARGS &
101
102			COUNT=\`expr \$COUNT + 1\`
103			echo \`date -u '+%H:%M:%S'\` $i started build \$COUNT of 4
104			[ 0 -lt \`expr \$COUNT % $PARALLEL_BUILDS\` ] || wait
105
106			./build $SIG        $STD --disable-all-clocks --disable-autokey --without-sntp --disable-thread-support $BUILD_ARGS &
107
108			COUNT=\`expr \$COUNT + 1\`
109			echo \`date -u '+%H:%M:%S'\` $i started build \$COUNT of 4
110			wait
111		esac
112		echo \`date -u '+%H:%M:%S'\` $i flock-build $c_d done.
113		rm .buildkey-$i
114ENDQUOT
115	    chmod +x .flockbuild-$i-$SIG
116	    ssh -tt $i "$c_d/.flockbuild-$i-$SIG ; \
117		rm $c_d/.flockbuild-$i-$SIG" 2>/dev/null &
118	esac
119    esac
120done
121echo `date -u '+%H:%M:%S'` flock-build launched
122