xref: /freebsd/contrib/ntp/build (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
1#! /bin/sh
2
3LOGF=make.log
4IAM=`hostname || uname -n`
5MYNAME=`IFS=. ; set $IAM ; echo $1`
6SIG=
7
8case "$1" in
9 0.*)
10    SIG=$1
11    shift
12    CONFIG_ARGS="$@"
13    KEY=`sed -e q < .buildkey-$MYNAME`
14    case "$SIG" in
15     $KEY) ;;
16     *)
17	echo "Wrong directory for build on host $IAM"
18	echo "This is <`pwd`>"
19	echo "SIG is <$SIG>"
20	echo "KEY is <$KEY>"
21	exit 1
22	;;
23    esac
24    ;;
25 *)
26    CONFIG_ARGS="$@"
27    ;;
28esac
29
30#set -e
31#set -x
32
33if [ ! -r sntp/libevent/build-aux/config.guess ] ; then
34	echo "Error: bootstrap required." 1>&2 && exit 1
35fi
36
37# sntp/scripts/cvo.sh invokes config.guess, and we want it to use the copy
38# in the build-aux directory if there's not another config.guess earlier
39# on the path, so we invoke it using env to append to the PATH.
40
41CVO=`env PATH="$PATH:./sntp/libevent/build-aux" sntp/scripts/cvo.sh @cvo@`
42case "$CVO" in
43 *-*-*-*) echo "sntp/scripts/cvo.sh returned <$CVO>, which makes no sense to me."
44    exit 1
45    ;;
46 *-*-*) ;;
47 *) echo "sntp/scripts/cvo.sh returned <$CVO>, which makes no sense to me."
48    exit 1
49    ;;
50esac
51
52case "$NTP_BDIR" in
53 '')
54    case "$IAM" in
55     *.ntp.org | *.ntfo.org)
56	NTP_BDIR=host
57	;;
58     *.udel.edu)
59	NTP_BDIR=host
60	# HMS: --enable-local-libopts is the default now...
61	#CONFIG_ARGS="$CONFIG_ARGS --enable-local-libopts"
62	case "$CVO" in
63	 *-*-ultrix*)
64	    CONFIG_ARGS="$CONFIG_ARGS --with-libregex=/usr/local"
65	    ;;
66	esac
67	;;
68     *)
69	NTP_BDIR=cvo
70	;;
71     esac
72     ;;
73esac
74
75case "$NTP_BDIR" in
76 host)
77    BASEDIR=A.$MYNAME
78    ;;
79 cvo)
80    BASEDIR=A.$CVO
81    ;;
82 *)
83    echo "build: NTP_BDIR must be either 'cvo' or 'host'!" 1>&2
84    exit 1
85    ;;
86esac
87
88KEYSUF=""
89
90case "$CONFIG_ARGS" in
91 *--with-crypto=autokey*)
92    KEYSUF="-autokey"
93    ;;
94 *--without-crypto*)
95    KEYSUF="-noopenssl"
96    ;;
97esac
98
99case "$CONFIG_ARGS" in
100 *--disable-all-clocks*)
101    KEYSUF="$KEYSUF-no-refclocks"
102    ;;
103esac
104
105case "$CONFIG_ARGS" in
106 *--disable-debugging*)
107    KEYSUF="$KEYSUF-nodebug"
108    ;;
109esac
110
111case "$CC" in
112 '')
113    CCSUF=""
114    ;;
115 *)
116    CCSUF="-`echo $CC | sed -e 's: :_:g' -e's:/:+:g'`"
117    ;;
118esac
119
120BDIR="$BASEDIR$KEYSUF$CCSUF"
121
122[ -d "$BDIR" ] || mkdir $BDIR
123[ -f "$BDIR/.buildcvo" ] || echo $CVO > $BDIR/.buildcvo
124[ -f "$BDIR/.buildhost" ] || echo $IAM > $BDIR/.buildhost
125
126
127cd $BDIR
128
129#
130# Make sure we have a nice that works.
131# To disable use of nice, setenv NO_NICE_BUILD=1
132#
133NICEB=
134[ "$NO_NICE_BUILD" != "1" ] && nice true && NICEB=nice
135[ -z "$NICEB" ] && {
136	NICEB="./.nicebuild-$MYNAME-$SIG"
137	cat > $NICEB <<-HEREDOC
138		#! /bin/sh
139		shift
140		\$*
141HEREDOC
142	chmod +x $NICEB
143}
144
145#
146# Find a test which supports -nt, unlike Solaris /bin/sh builtin.
147#
148TEST="${TEST-}"
149if [ -z "$TEST" ] ; then
150    for try in test /bin/test /usr/bin/test ; do
151	case `$try config.status -nt ../configure 2>&1` in
152	 '')
153	    TEST="$try"
154	    # echo "Using $TEST"
155	    break
156	    ;;
157	esac
158    done
159    if [ -z "$TEST" ] ; then
160	echo "build: need help finding test binary" 1>&2
161	exit 1
162    fi
163fi
164
165CONFIGURE="../configure"
166# We need KEYSUF because of RAND_ and others, and -noopenssl"
167#CONFIGURE="$CONFIGURE --cache-file=../config.cache-$IAM$KEYSUF$CCSUF"
168CONFIGURE="$CONFIGURE $CONFIG_ARGS"
169
170
171(	# This sequence of commands is logged to make.log.
172	# If config.status is newer than ../configure, and the same
173	# is true for sntp, we do not need to re-run configure.
174	# For libevent, the twist is we may not be configuring the
175	# tearoff, so only act if its config.status exists.
176	# Solaris /bin/sh doesn't grok -nt.
177
178	( "$TEST" config.status -nt ../configure &&
179	  "$TEST" sntp/config.status -nt ../sntp/configure &&
180	  ( "$TEST" '!' -f sntp/libevent/config.status ||
181	    "$TEST" sntp/libevent/config.status -nt ../sntp/libevent/configure ) ) ||
182		"$NICEB" -7 $CONFIGURE
183	"$TEST" Makefile -nt config.status ||
184		"$NICEB" -5 ./config.status
185	"$TEST" sntp/Makefile -nt sntp/config.status ||
186		( cd sntp && "$NICEB" -5 ./config.status )
187	"$TEST" '!' -f sntp/libevent/Makefile ||
188	  "$TEST" sntp/libevent/Makefile -nt sntp/libevent/config.status ||
189		( cd sntp/libevent && "$NICEB" -5 ./config.status )
190	"$NICEB" -14 ${MAKE-make} && "$NICEB" -11 ${MAKE-make} check
191) > $LOGF 2>&1
192
193EXITCODE=$?
194
195# clean up if we made a dummy nice script
196case "$NICEB" in
197 nice)
198    ;;
199 *)
200    rm "$NICEB"
201    ;;
202esac
203
204exit $EXITCODE
205