154359Sroberto#! /bin/sh
254359Sroberto
354359SrobertoLOGF=make.log
482498SrobertoIAM=`hostname || uname -n`
5200576SrobertoMYNAME=`IFS=. ; set $IAM ; echo $1`
6200576SrobertoSIG=
754359Sroberto
882498Srobertocase "$1" in
982498Sroberto 0.*)
1082498Sroberto    SIG=$1
1182498Sroberto    shift
1282498Sroberto    CONFIG_ARGS="$@"
13200576Sroberto    KEY=`sed -e q < .buildkey-$MYNAME`
1482498Sroberto    case "$SIG" in
1582498Sroberto     $KEY) ;;
1682498Sroberto     *)
1782498Sroberto	echo "Wrong directory for build on host $IAM"
18132451Sroberto	echo "This is <`pwd`>"
19132451Sroberto	echo "SIG is <$SIG>"
20132451Sroberto	echo "KEY is <$KEY>"
21285612Sdelphij	exit 1
22285612Sdelphij	;;
2382498Sroberto    esac
2482498Sroberto    ;;
2582498Sroberto *)
2682498Sroberto    CONFIG_ARGS="$@"
2782498Sroberto    ;;
2882498Srobertoesac
2954359Sroberto
3054359Sroberto#set -e
3154359Sroberto#set -x
3254359Sroberto
33285612Sdelphijif [ ! -r sntp/libevent/build-aux/config.guess ] ; then
34285612Sdelphij	echo "Error: bootstrap required." 1>&2 && exit 1
35285612Sdelphijfi
36285612Sdelphij
37285612Sdelphij# sntp/scripts/cvo.sh invokes config.guess, and we want it to use the copy
38285612Sdelphij# in the build-aux directory if there's not another config.guess earlier
39285612Sdelphij# on the path, so we invoke it using env to append to the PATH.
40285612Sdelphij
41285612SdelphijCVO=`env PATH="$PATH:./sntp/libevent/build-aux" sntp/scripts/cvo.sh @cvo@`
4254359Srobertocase "$CVO" in
43285612Sdelphij *-*-*-*) echo "sntp/scripts/cvo.sh returned <$CVO>, which makes no sense to me."
44285612Sdelphij    exit 1
45285612Sdelphij    ;;
4654359Sroberto *-*-*) ;;
47285612Sdelphij *) echo "sntp/scripts/cvo.sh returned <$CVO>, which makes no sense to me."
4854359Sroberto    exit 1
4954359Sroberto    ;;
5054359Srobertoesac
5154359Sroberto
52285612Sdelphijcase "$NTP_BDIR" in
53285612Sdelphij '')
54285612Sdelphij    case "$IAM" in
55285612Sdelphij     *.ntp.org)
56285612Sdelphij	NTP_BDIR=host
57182007Sroberto	;;
58285612Sdelphij     *.udel.edu)
59285612Sdelphij	NTP_BDIR=host
60285612Sdelphij	# HMS: --enable-local-libopts is the default now...
61285612Sdelphij	#CONFIG_ARGS="$CONFIG_ARGS --enable-local-libopts"
62285612Sdelphij	case "$CVO" in
63285612Sdelphij	 *-*-ultrix*)
64285612Sdelphij	    CONFIG_ARGS="$CONFIG_ARGS --with-libregex=/usr/local"
65285612Sdelphij	    ;;
66285612Sdelphij	esac
67285612Sdelphij	;;
68285612Sdelphij     *)
69285612Sdelphij	NTP_BDIR=cvo
70285612Sdelphij	;;
71285612Sdelphij     esac
72285612Sdelphij     ;;
73285612Sdelphijesac
74285612Sdelphij
75285612Sdelphijcase "$NTP_BDIR" in
76285612Sdelphij host) 
77285612Sdelphij    BASEDIR=A.$MYNAME
7854359Sroberto    ;;
79285612Sdelphij cvo)
80285612Sdelphij    BASEDIR=A.$CVO
81285612Sdelphij    ;;
8254359Sroberto *)
83285612Sdelphij    echo "build: NTP_BDIR must be either 'cvo' or 'host'!" 1>&2
84285612Sdelphij    exit 1
8554359Sroberto    ;;
8654359Srobertoesac
8754359Sroberto
8882498SrobertoKEYSUF=""
8982498Sroberto
9082498Srobertocase "$CONFIG_ARGS" in
9182498Sroberto *--with-crypto=autokey*)
9282498Sroberto    KEYSUF="-autokey"
9382498Sroberto    ;;
9482498Sroberto *--without-crypto*)
95132451Sroberto    KEYSUF="-noopenssl"
9682498Sroberto    ;;
9782498Srobertoesac
9882498Sroberto
99182007Srobertocase "$CONFIG_ARGS" in
100182007Sroberto *--disable-all-clocks*)
101182007Sroberto    KEYSUF="$KEYSUF-no-refclocks"
102182007Sroberto    ;;
103182007Srobertoesac
104182007Sroberto
105182007Srobertocase "$CONFIG_ARGS" in
106182007Sroberto *--disable-debugging*)
107182007Sroberto    KEYSUF="$KEYSUF-nodebug"
108182007Sroberto    ;;
109182007Srobertoesac
110182007Sroberto
11154359Srobertocase "$CC" in
112285612Sdelphij '')
113285612Sdelphij    CCSUF=""
11454359Sroberto    ;;
115285612Sdelphij *)
116285612Sdelphij    CCSUF="-`echo $CC | sed -e 's: :_:g' -e's:/:+:g'`"
117285612Sdelphij    ;;
11854359Srobertoesac
11954359Sroberto
120285612SdelphijBDIR="$BASEDIR$KEYSUF$CCSUF"
12154359Sroberto
12254359Sroberto[ -d "$BDIR" ] || mkdir $BDIR
12354359Sroberto[ -f "$BDIR/.buildcvo" ] || echo $CVO > $BDIR/.buildcvo
12454359Sroberto[ -f "$BDIR/.buildhost" ] || echo $IAM > $BDIR/.buildhost
12554359Sroberto
126200576Sroberto
12754359Srobertocd $BDIR
12854359Sroberto
129200576Sroberto#
130285612Sdelphij# Make sure we have a nice that works.
131285612Sdelphij# To disable use of nice, setenv NO_NICE_BUILD=1
132200576Sroberto#
133285612SdelphijNICEB=
134285612Sdelphij[ "$NO_NICE_BUILD" != "1" ] && nice true && NICEB=nice
135285612Sdelphij[ -z "$NICEB" ] && {
136285612Sdelphij	NICEB="./.nicebuild-$MYNAME-$SIG"
137285612Sdelphij	cat > $NICEB <<-HEREDOC
138285612Sdelphij		#! /bin/sh
139285612Sdelphij		shift
140285612Sdelphij		\$*
141285612SdelphijHEREDOC
142285612Sdelphij	chmod +x $NICEB
143285612Sdelphij}
144200576Sroberto
145285612Sdelphij#
146285612Sdelphij# Find a test which supports -nt, unlike Solaris /bin/sh builtin.
147285612Sdelphij#
148285612SdelphijTEST="${TEST-}"
149285612Sdelphijif [ -z "$TEST" ] ; then
150285612Sdelphij    for try in test /bin/test /usr/bin/test ; do
151285612Sdelphij	case `$try config.status -nt ../configure 2>&1` in
152285612Sdelphij	 '')
153285612Sdelphij	    TEST="$try"
154285612Sdelphij	    # echo "Using $TEST"
155285612Sdelphij	    break
156285612Sdelphij	    ;;
157285612Sdelphij	esac		
158285612Sdelphij    done
159285612Sdelphij    if [ -z "$TEST" ] ; then
160285612Sdelphij	echo "build: need help finding test binary" 1>&2
161285612Sdelphij	exit 1
162285612Sdelphij    fi
163285612Sdelphijfi
164200576Sroberto
165285612SdelphijCONFIGURE="../configure"
166285612Sdelphij# We need KEYSUF because of RAND_ and others, and -noopenssl"
167285612Sdelphij#CONFIGURE="$CONFIGURE --cache-file=../config.cache-$IAM$KEYSUF$CCSUF"
168285612SdelphijCONFIGURE="$CONFIGURE $CONFIG_ARGS"
16954359Sroberto
17082498Sroberto
171285612Sdelphij(	# This sequence of commands is logged to make.log.
172285612Sdelphij	# If config.status is newer than ../configure, and the same
173285612Sdelphij	# is true for sntp, we do not need to re-run configure.
174285612Sdelphij	# For libevent, the twist is we may not be configuring the
175285612Sdelphij	# tearoff, so only act if its config.status exists.
176285612Sdelphij	# Solaris /bin/sh doesn't grok -nt.
177285612Sdelphij
178285612Sdelphij	( "$TEST" config.status -nt ../configure &&
179285612Sdelphij	  "$TEST" sntp/config.status -nt ../sntp/configure &&
180285612Sdelphij	  ( "$TEST" '!' -f sntp/libevent/config.status ||
181285612Sdelphij	    "$TEST" sntp/libevent/config.status -nt ../sntp/libevent/configure ) ) ||
182285612Sdelphij		"$NICEB" -7 $CONFIGURE
183285612Sdelphij	"$TEST" Makefile -nt config.status ||
184285612Sdelphij		"$NICEB" -5 ./config.status
185285612Sdelphij	"$TEST" sntp/Makefile -nt sntp/config.status ||
186285612Sdelphij		( cd sntp && "$NICEB" -5 ./config.status )
187285612Sdelphij	"$TEST" '!' -f sntp/libevent/Makefile ||
188285612Sdelphij	  "$TEST" sntp/libevent/Makefile -nt sntp/libevent/config.status ||
189285612Sdelphij		( cd sntp/libevent && "$NICEB" -5 ./config.status )
190285612Sdelphij	"$NICEB" -14 ${MAKE-make} && "$NICEB" -11 ${MAKE-make} check
191285612Sdelphij) > $LOGF 2>&1
192285612Sdelphij
193285612SdelphijEXITCODE=$?
194285612Sdelphij
195285612Sdelphij# clean up if we made a dummy nice script
196285612Sdelphijcase "$NICEB" in
197285612Sdelphij nice)
198285612Sdelphij    ;;
199285612Sdelphij *)
200285612Sdelphij    rm "$NICEB"
201285612Sdelphij    ;;
20254359Srobertoesac
203285612Sdelphij
204285612Sdelphijexit $EXITCODE
205