xref: /titanic_50/usr/src/tools/scripts/nightly (revision 6b72f1c00ce6f09bcb01b7a635dcc38bf9b3ed2b)
1*6b72f1c0SJohn Levon#!/bin/ksh -p
2*6b72f1c0SJohn Levon#
3*6b72f1c0SJohn Levon# CDDL HEADER START
4*6b72f1c0SJohn Levon#
5*6b72f1c0SJohn Levon# The contents of this file are subject to the terms of the
6*6b72f1c0SJohn Levon# Common Development and Distribution License (the "License").
7*6b72f1c0SJohn Levon# You may not use this file except in compliance with the License.
8*6b72f1c0SJohn Levon#
9*6b72f1c0SJohn Levon# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*6b72f1c0SJohn Levon# or http://www.opensolaris.org/os/licensing.
11*6b72f1c0SJohn Levon# See the License for the specific language governing permissions
12*6b72f1c0SJohn Levon# and limitations under the License.
13*6b72f1c0SJohn Levon#
14*6b72f1c0SJohn Levon# When distributing Covered Code, include this CDDL HEADER in each
15*6b72f1c0SJohn Levon# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*6b72f1c0SJohn Levon# If applicable, add the following below this CDDL HEADER, with the
17*6b72f1c0SJohn Levon# fields enclosed by brackets "[]" replaced with your own identifying
18*6b72f1c0SJohn Levon# information: Portions Copyright [yyyy] [name of copyright owner]
19*6b72f1c0SJohn Levon#
20*6b72f1c0SJohn Levon# CDDL HEADER END
21*6b72f1c0SJohn Levon#
22*6b72f1c0SJohn Levon
23*6b72f1c0SJohn Levon#
24*6b72f1c0SJohn Levon# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25*6b72f1c0SJohn Levon# Copyright 2008, 2010, Richard Lowe
26*6b72f1c0SJohn Levon# Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
27*6b72f1c0SJohn Levon# Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
28*6b72f1c0SJohn Levon# Copyright 2020 Joyent, Inc.
29*6b72f1c0SJohn Levon#
30*6b72f1c0SJohn Levon# Based on the nightly script from the integration folks,
31*6b72f1c0SJohn Levon# Mostly modified and owned by mike_s.
32*6b72f1c0SJohn Levon# Changes also by kjc, dmk.
33*6b72f1c0SJohn Levon#
34*6b72f1c0SJohn Levon# BRINGOVER_WS may be specified in the env file.
35*6b72f1c0SJohn Levon# The default is the old behavior of CLONE_WS
36*6b72f1c0SJohn Levon#
37*6b72f1c0SJohn Levon# -i on the command line, means fast options, so when it's on the
38*6b72f1c0SJohn Levon# command line (only), lint and check builds are skipped no matter what
39*6b72f1c0SJohn Levon# the setting of their individual flags are in NIGHTLY_OPTIONS.
40*6b72f1c0SJohn Levon#
41*6b72f1c0SJohn Levon# LINTDIRS can be set in the env file, format is a list of:
42*6b72f1c0SJohn Levon#
43*6b72f1c0SJohn Levon#	/dirname-to-run-lint-on flag
44*6b72f1c0SJohn Levon#
45*6b72f1c0SJohn Levon#	Where flag is:	y - enable lint noise diff output
46*6b72f1c0SJohn Levon#			n - disable lint noise diff output
47*6b72f1c0SJohn Levon#
48*6b72f1c0SJohn Levon#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
49*6b72f1c0SJohn Levon#
50*6b72f1c0SJohn Levon# OPTHOME  may be set in the environment to override /opt
51*6b72f1c0SJohn Levon#
52*6b72f1c0SJohn Levon
53*6b72f1c0SJohn Levon#
54*6b72f1c0SJohn Levon# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
55*6b72f1c0SJohn Levon# under certain circumstances, which can really screw things up; unset it.
56*6b72f1c0SJohn Levon#
57*6b72f1c0SJohn Levonunset CDPATH
58*6b72f1c0SJohn Levon
59*6b72f1c0SJohn Levon# Get the absolute path of the nightly script that the user invoked.  This
60*6b72f1c0SJohn Levon# may be a relative path, and we need to do this before changing directory.
61*6b72f1c0SJohn Levonnightly_path=`whence $0`
62*6b72f1c0SJohn Levon
63*6b72f1c0SJohn Levon#
64*6b72f1c0SJohn Levon# Keep track of where we found nightly so we can invoke the matching
65*6b72f1c0SJohn Levon# which_scm script.  If that doesn't work, don't go guessing, just rely
66*6b72f1c0SJohn Levon# on the $PATH settings, which will generally give us either /opt/onbld
67*6b72f1c0SJohn Levon# or the user's workspace.
68*6b72f1c0SJohn Levon#
69*6b72f1c0SJohn LevonWHICH_SCM=$(dirname $nightly_path)/which_scm
70*6b72f1c0SJohn Levonif [[ ! -x $WHICH_SCM ]]; then
71*6b72f1c0SJohn Levon	WHICH_SCM=which_scm
72*6b72f1c0SJohn Levonfi
73*6b72f1c0SJohn Levon
74*6b72f1c0SJohn Levonfunction fatal_error
75*6b72f1c0SJohn Levon{
76*6b72f1c0SJohn Levon	print -u2 "nightly: $*"
77*6b72f1c0SJohn Levon	exit 1
78*6b72f1c0SJohn Levon}
79*6b72f1c0SJohn Levon
80*6b72f1c0SJohn Levon#
81*6b72f1c0SJohn Levon# Function to do a DEBUG and non-DEBUG build. Needed because we might
82*6b72f1c0SJohn Levon# need to do another for the source build, and since we only deliver DEBUG or
83*6b72f1c0SJohn Levon# non-DEBUG packages.
84*6b72f1c0SJohn Levon#
85*6b72f1c0SJohn Levon# usage: normal_build
86*6b72f1c0SJohn Levon#
87*6b72f1c0SJohn Levonfunction normal_build {
88*6b72f1c0SJohn Levon
89*6b72f1c0SJohn Levon	typeset orig_p_FLAG="$p_FLAG"
90*6b72f1c0SJohn Levon	typeset crypto_signer="$CODESIGN_USER"
91*6b72f1c0SJohn Levon
92*6b72f1c0SJohn Levon	suffix=""
93*6b72f1c0SJohn Levon
94*6b72f1c0SJohn Levon	# non-DEBUG build begins
95*6b72f1c0SJohn Levon
96*6b72f1c0SJohn Levon	if [ "$F_FLAG" = "n" ]; then
97*6b72f1c0SJohn Levon		set_non_debug_build_flags
98*6b72f1c0SJohn Levon		CODESIGN_USER="$crypto_signer" \
99*6b72f1c0SJohn Levon		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
100*6b72f1c0SJohn Levon	else
101*6b72f1c0SJohn Levon		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
102*6b72f1c0SJohn Levon	fi
103*6b72f1c0SJohn Levon
104*6b72f1c0SJohn Levon	# non-DEBUG build ends
105*6b72f1c0SJohn Levon
106*6b72f1c0SJohn Levon	# DEBUG build begins
107*6b72f1c0SJohn Levon
108*6b72f1c0SJohn Levon	if [ "$D_FLAG" = "y" ]; then
109*6b72f1c0SJohn Levon		set_debug_build_flags
110*6b72f1c0SJohn Levon		CODESIGN_USER="$crypto_signer" \
111*6b72f1c0SJohn Levon		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
112*6b72f1c0SJohn Levon	else
113*6b72f1c0SJohn Levon		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
114*6b72f1c0SJohn Levon	fi
115*6b72f1c0SJohn Levon
116*6b72f1c0SJohn Levon	# DEBUG build ends
117*6b72f1c0SJohn Levon
118*6b72f1c0SJohn Levon	p_FLAG="$orig_p_FLAG"
119*6b72f1c0SJohn Levon}
120*6b72f1c0SJohn Levon
121*6b72f1c0SJohn Levon#
122*6b72f1c0SJohn Levon# usage: run_hook HOOKNAME ARGS...
123*6b72f1c0SJohn Levon#
124*6b72f1c0SJohn Levon# If variable "$HOOKNAME" is defined, insert a section header into
125*6b72f1c0SJohn Levon# our logs and then run the command with ARGS
126*6b72f1c0SJohn Levon#
127*6b72f1c0SJohn Levonfunction run_hook {
128*6b72f1c0SJohn Levon	HOOKNAME=$1
129*6b72f1c0SJohn Levon    	eval HOOKCMD=\$$HOOKNAME
130*6b72f1c0SJohn Levon	shift
131*6b72f1c0SJohn Levon
132*6b72f1c0SJohn Levon	if [ -n "$HOOKCMD" ]; then
133*6b72f1c0SJohn Levon	    	(
134*6b72f1c0SJohn Levon			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
135*6b72f1c0SJohn Levon		    	( $HOOKCMD "$@" 2>&1 )
136*6b72f1c0SJohn Levon			if [ "$?" -ne 0 ]; then
137*6b72f1c0SJohn Levon			    	# Let exit status propagate up
138*6b72f1c0SJohn Levon			    	touch $TMPDIR/abort
139*6b72f1c0SJohn Levon			fi
140*6b72f1c0SJohn Levon		) | tee -a $mail_msg_file >> $LOGFILE
141*6b72f1c0SJohn Levon
142*6b72f1c0SJohn Levon		if [ -f $TMPDIR/abort ]; then
143*6b72f1c0SJohn Levon			build_ok=n
144*6b72f1c0SJohn Levon			echo "\nAborting at request of $HOOKNAME" |
145*6b72f1c0SJohn Levon				tee -a $mail_msg_file >> $LOGFILE
146*6b72f1c0SJohn Levon			exit 1
147*6b72f1c0SJohn Levon		fi
148*6b72f1c0SJohn Levon	fi
149*6b72f1c0SJohn Levon}
150*6b72f1c0SJohn Levon
151*6b72f1c0SJohn Levon# Return library search directive as function of given root.
152*6b72f1c0SJohn Levonfunction myldlibs {
153*6b72f1c0SJohn Levon	echo "-L$1/lib -L$1/usr/lib"
154*6b72f1c0SJohn Levon}
155*6b72f1c0SJohn Levon
156*6b72f1c0SJohn Levon# Return header search directive as function of given root.
157*6b72f1c0SJohn Levonfunction myheaders {
158*6b72f1c0SJohn Levon	echo "-I$1/usr/include"
159*6b72f1c0SJohn Levon}
160*6b72f1c0SJohn Levon
161*6b72f1c0SJohn Levon#
162*6b72f1c0SJohn Levon# Function to do the build, including package generation.
163*6b72f1c0SJohn Levon# usage: build LABEL SUFFIX ND MULTIPROTO
164*6b72f1c0SJohn Levon# - LABEL is used to tag build output.
165*6b72f1c0SJohn Levon# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
166*6b72f1c0SJohn Levon#   open-only vs full tree).
167*6b72f1c0SJohn Levon# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
168*6b72f1c0SJohn Levon# - If MULTIPROTO is "yes", it means to name the proto area according to
169*6b72f1c0SJohn Levon#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
170*6b72f1c0SJohn Levon#
171*6b72f1c0SJohn Levonfunction build {
172*6b72f1c0SJohn Levon	LABEL=$1
173*6b72f1c0SJohn Levon	SUFFIX=$2
174*6b72f1c0SJohn Levon	ND=$3
175*6b72f1c0SJohn Levon	MULTIPROTO=$4
176*6b72f1c0SJohn Levon	INSTALLOG=install${SUFFIX}-${MACH}
177*6b72f1c0SJohn Levon	NOISE=noise${SUFFIX}-${MACH}
178*6b72f1c0SJohn Levon	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
179*6b72f1c0SJohn Levon
180*6b72f1c0SJohn Levon	ORIGROOT=$ROOT
181*6b72f1c0SJohn Levon	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
182*6b72f1c0SJohn Levon
183*6b72f1c0SJohn Levon	export ENVLDLIBS1=`myldlibs $ROOT`
184*6b72f1c0SJohn Levon	export ENVCPPFLAGS1=`myheaders $ROOT`
185*6b72f1c0SJohn Levon
186*6b72f1c0SJohn Levon	this_build_ok=y
187*6b72f1c0SJohn Levon	#
188*6b72f1c0SJohn Levon	#	Build OS-Networking source
189*6b72f1c0SJohn Levon	#
190*6b72f1c0SJohn Levon	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
191*6b72f1c0SJohn Levon		>> $LOGFILE
192*6b72f1c0SJohn Levon
193*6b72f1c0SJohn Levon	rm -f $SRC/${INSTALLOG}.out
194*6b72f1c0SJohn Levon	cd $SRC
195*6b72f1c0SJohn Levon	/bin/time $MAKE -e install 2>&1 | \
196*6b72f1c0SJohn Levon	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
197*6b72f1c0SJohn Levon
198*6b72f1c0SJohn Levon	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
199*6b72f1c0SJohn Levon	egrep ":" $SRC/${INSTALLOG}.out |
200*6b72f1c0SJohn Levon		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
201*6b72f1c0SJohn Levon		egrep -v "Ignoring unknown host" | \
202*6b72f1c0SJohn Levon		egrep -v "cc .* -o error " | \
203*6b72f1c0SJohn Levon		egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \
204*6b72f1c0SJohn Levon		>> $mail_msg_file
205*6b72f1c0SJohn Levon	if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then
206*6b72f1c0SJohn Levon		build_ok=n
207*6b72f1c0SJohn Levon		this_build_ok=n
208*6b72f1c0SJohn Levon	fi
209*6b72f1c0SJohn Levon	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
210*6b72f1c0SJohn Levon		>> $mail_msg_file
211*6b72f1c0SJohn Levon	if [ "$?" = "0" ]; then
212*6b72f1c0SJohn Levon		build_ok=n
213*6b72f1c0SJohn Levon		this_build_ok=n
214*6b72f1c0SJohn Levon	fi
215*6b72f1c0SJohn Levon
216*6b72f1c0SJohn Levon	echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
217*6b72f1c0SJohn Levon	egrep -i warning: $SRC/${INSTALLOG}.out \
218*6b72f1c0SJohn Levon		| egrep -v '^tic:' \
219*6b72f1c0SJohn Levon		| egrep -v "symbol (\`|')timezone' has differing types:" \
220*6b72f1c0SJohn Levon		| egrep -v "parameter <PSTAMP> set to" \
221*6b72f1c0SJohn Levon		| egrep -v "Ignoring unknown host" \
222*6b72f1c0SJohn Levon		| egrep -v "redefining segment flags attribute for" \
223*6b72f1c0SJohn Levon		| tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file
224*6b72f1c0SJohn Levon	if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then
225*6b72f1c0SJohn Levon		build_ok=n
226*6b72f1c0SJohn Levon		this_build_ok=n
227*6b72f1c0SJohn Levon	fi
228*6b72f1c0SJohn Levon
229*6b72f1c0SJohn Levon	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
230*6b72f1c0SJohn Levon		>> $LOGFILE
231*6b72f1c0SJohn Levon
232*6b72f1c0SJohn Levon	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
233*6b72f1c0SJohn Levon	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
234*6b72f1c0SJohn Levon
235*6b72f1c0SJohn Levon	if [ "$i_FLAG" = "n" ]; then
236*6b72f1c0SJohn Levon		rm -f $SRC/${NOISE}.ref
237*6b72f1c0SJohn Levon		if [ -f $SRC/${NOISE}.out ]; then
238*6b72f1c0SJohn Levon			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
239*6b72f1c0SJohn Levon		fi
240*6b72f1c0SJohn Levon		grep : $SRC/${INSTALLOG}.out \
241*6b72f1c0SJohn Levon			| egrep -v '^/' \
242*6b72f1c0SJohn Levon			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
243*6b72f1c0SJohn Levon			| egrep -v '^tic:' \
244*6b72f1c0SJohn Levon			| egrep -v '^mcs' \
245*6b72f1c0SJohn Levon			| egrep -v '^LD_LIBRARY_PATH=' \
246*6b72f1c0SJohn Levon			| egrep -v 'ar: creating' \
247*6b72f1c0SJohn Levon			| egrep -v 'ar: writing' \
248*6b72f1c0SJohn Levon			| egrep -v 'conflicts:' \
249*6b72f1c0SJohn Levon			| egrep -v ':saved created' \
250*6b72f1c0SJohn Levon			| egrep -v '^stty.*c:' \
251*6b72f1c0SJohn Levon			| egrep -v '^mfgname.c:' \
252*6b72f1c0SJohn Levon			| egrep -v '^uname-i.c:' \
253*6b72f1c0SJohn Levon			| egrep -v '^volumes.c:' \
254*6b72f1c0SJohn Levon			| egrep -v '^lint library construction:' \
255*6b72f1c0SJohn Levon			| egrep -v 'tsort: INFORM:' \
256*6b72f1c0SJohn Levon			| egrep -v 'stripalign:' \
257*6b72f1c0SJohn Levon			| egrep -v 'chars, width' \
258*6b72f1c0SJohn Levon			| egrep -v "symbol (\`|')timezone' has differing types:" \
259*6b72f1c0SJohn Levon			| egrep -v 'PSTAMP' \
260*6b72f1c0SJohn Levon			| egrep -v '|%WHOANDWHERE%|' \
261*6b72f1c0SJohn Levon			| egrep -v '^Manifying' \
262*6b72f1c0SJohn Levon			| egrep -v 'Ignoring unknown host' \
263*6b72f1c0SJohn Levon			| egrep -v 'Processing method:' \
264*6b72f1c0SJohn Levon			| egrep -v '^Writing' \
265*6b72f1c0SJohn Levon			| egrep -v 'spellin1:' \
266*6b72f1c0SJohn Levon			| egrep -v '^adding:' \
267*6b72f1c0SJohn Levon			| egrep -v "^echo 'msgid" \
268*6b72f1c0SJohn Levon			| egrep -v '^echo ' \
269*6b72f1c0SJohn Levon			| egrep -v '\.c:$' \
270*6b72f1c0SJohn Levon			| egrep -v '^Adding file:' \
271*6b72f1c0SJohn Levon			| egrep -v 'CLASSPATH=' \
272*6b72f1c0SJohn Levon			| egrep -v '\/var\/mail\/:saved' \
273*6b72f1c0SJohn Levon			| egrep -v -- '-DUTS_VERSION=' \
274*6b72f1c0SJohn Levon			| egrep -v '^Running Mkbootstrap' \
275*6b72f1c0SJohn Levon			| egrep -v '^Applet length read:' \
276*6b72f1c0SJohn Levon			| egrep -v 'bytes written:' \
277*6b72f1c0SJohn Levon			| egrep -v '^File:SolarisAuthApplet.bin' \
278*6b72f1c0SJohn Levon			| egrep -v -i 'jibversion' \
279*6b72f1c0SJohn Levon			| egrep -v '^Output size:' \
280*6b72f1c0SJohn Levon			| egrep -v '^Solo size statistics:' \
281*6b72f1c0SJohn Levon			| egrep -v '^Using ROM API Version' \
282*6b72f1c0SJohn Levon			| egrep -v '^Zero Signature length:' \
283*6b72f1c0SJohn Levon			| egrep -v '^Note \(probably harmless\):' \
284*6b72f1c0SJohn Levon			| egrep -v '::' \
285*6b72f1c0SJohn Levon			| egrep -v -- '-xcache' \
286*6b72f1c0SJohn Levon			| egrep -v '^\+' \
287*6b72f1c0SJohn Levon			| egrep -v '^cc1: note: -fwritable-strings' \
288*6b72f1c0SJohn Levon			| egrep -v 'svccfg-native -s svc:/' \
289*6b72f1c0SJohn Levon			| sort | uniq >$SRC/${NOISE}.out
290*6b72f1c0SJohn Levon		if [ ! -f $SRC/${NOISE}.ref ]; then
291*6b72f1c0SJohn Levon			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
292*6b72f1c0SJohn Levon		fi
293*6b72f1c0SJohn Levon		echo "\n==== Build noise differences ($LABEL) ====\n" \
294*6b72f1c0SJohn Levon			>>$mail_msg_file
295*6b72f1c0SJohn Levon		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
296*6b72f1c0SJohn Levon	fi
297*6b72f1c0SJohn Levon
298*6b72f1c0SJohn Levon	#
299*6b72f1c0SJohn Levon	#	Re-sign selected binaries using signing server
300*6b72f1c0SJohn Levon	#	(gatekeeper builds only)
301*6b72f1c0SJohn Levon	#
302*6b72f1c0SJohn Levon	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
303*6b72f1c0SJohn Levon		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
304*6b72f1c0SJohn Levon		signing_file="${TMPDIR}/signing"
305*6b72f1c0SJohn Levon		rm -f ${signing_file}
306*6b72f1c0SJohn Levon		export CODESIGN_USER
307*6b72f1c0SJohn Levon		signproto $SRC/tools/codesign/creds 2>&1 | \
308*6b72f1c0SJohn Levon			tee -a ${signing_file} >> $LOGFILE
309*6b72f1c0SJohn Levon		echo "\n==== Finished signing proto area at `date` ====\n" \
310*6b72f1c0SJohn Levon		    >> $LOGFILE
311*6b72f1c0SJohn Levon		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
312*6b72f1c0SJohn Levon		    >> $mail_msg_file
313*6b72f1c0SJohn Levon		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
314*6b72f1c0SJohn Levon		if (( $? == 0 )) ; then
315*6b72f1c0SJohn Levon			build_ok=n
316*6b72f1c0SJohn Levon			this_build_ok=n
317*6b72f1c0SJohn Levon		fi
318*6b72f1c0SJohn Levon	fi
319*6b72f1c0SJohn Levon
320*6b72f1c0SJohn Levon	#
321*6b72f1c0SJohn Levon	#	Building Packages
322*6b72f1c0SJohn Levon	#
323*6b72f1c0SJohn Levon	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
324*6b72f1c0SJohn Levon		if [ -d $SRC/pkg ]; then
325*6b72f1c0SJohn Levon			echo "\n==== Creating $LABEL packages at `date` ====\n" \
326*6b72f1c0SJohn Levon				>> $LOGFILE
327*6b72f1c0SJohn Levon			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
328*6b72f1c0SJohn Levon			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
329*6b72f1c0SJohn Levon			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
330*6b72f1c0SJohn Levon
331*6b72f1c0SJohn Levon			rm -f $SRC/pkg/${INSTALLOG}.out
332*6b72f1c0SJohn Levon			cd $SRC/pkg
333*6b72f1c0SJohn Levon			/bin/time $MAKE -e install 2>&1 | \
334*6b72f1c0SJohn Levon			    tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE
335*6b72f1c0SJohn Levon
336*6b72f1c0SJohn Levon			echo "\n==== package build errors ($LABEL) ====\n" \
337*6b72f1c0SJohn Levon				>> $mail_msg_file
338*6b72f1c0SJohn Levon
339*6b72f1c0SJohn Levon			egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \
340*6b72f1c0SJohn Levon				grep ':' | \
341*6b72f1c0SJohn Levon				grep -v PSTAMP | \
342*6b72f1c0SJohn Levon				egrep -v "Ignoring unknown host" | \
343*6b72f1c0SJohn Levon				tee $TMPDIR/package >> $mail_msg_file
344*6b72f1c0SJohn Levon			if [[ -s $TMPDIR/package ]]; then
345*6b72f1c0SJohn Levon				build_extras_ok=n
346*6b72f1c0SJohn Levon				this_build_ok=n
347*6b72f1c0SJohn Levon			fi
348*6b72f1c0SJohn Levon		else
349*6b72f1c0SJohn Levon			#
350*6b72f1c0SJohn Levon			# Handle it gracefully if -p was set but there so
351*6b72f1c0SJohn Levon			# no pkg directory.
352*6b72f1c0SJohn Levon			#
353*6b72f1c0SJohn Levon			echo "\n==== No $LABEL packages to build ====\n" \
354*6b72f1c0SJohn Levon				>> $LOGFILE
355*6b72f1c0SJohn Levon		fi
356*6b72f1c0SJohn Levon	else
357*6b72f1c0SJohn Levon		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
358*6b72f1c0SJohn Levon	fi
359*6b72f1c0SJohn Levon
360*6b72f1c0SJohn Levon	ROOT=$ORIGROOT
361*6b72f1c0SJohn Levon}
362*6b72f1c0SJohn Levon
363*6b72f1c0SJohn Levon# Usage: dolint /dir y|n
364*6b72f1c0SJohn Levon# Arg. 2 is a flag to turn on/off the lint diff output
365*6b72f1c0SJohn Levonfunction dolint {
366*6b72f1c0SJohn Levon	if [ ! -d "$1" ]; then
367*6b72f1c0SJohn Levon		echo "dolint error: $1 is not a directory"
368*6b72f1c0SJohn Levon		exit 1
369*6b72f1c0SJohn Levon	fi
370*6b72f1c0SJohn Levon
371*6b72f1c0SJohn Levon	if [ "$2" != "y" -a "$2" != "n" ]; then
372*6b72f1c0SJohn Levon		echo "dolint internal error: $2 should be 'y' or 'n'"
373*6b72f1c0SJohn Levon		exit 1
374*6b72f1c0SJohn Levon	fi
375*6b72f1c0SJohn Levon
376*6b72f1c0SJohn Levon	lintdir=$1
377*6b72f1c0SJohn Levon	dodiff=$2
378*6b72f1c0SJohn Levon	base=`basename $lintdir`
379*6b72f1c0SJohn Levon	LINTOUT=$lintdir/lint-${MACH}.out
380*6b72f1c0SJohn Levon	LINTNOISE=$lintdir/lint-noise-${MACH}
381*6b72f1c0SJohn Levon	export ENVLDLIBS1=`myldlibs $ROOT`
382*6b72f1c0SJohn Levon	export ENVCPPFLAGS1=`myheaders $ROOT`
383*6b72f1c0SJohn Levon
384*6b72f1c0SJohn Levon	set_debug_build_flags
385*6b72f1c0SJohn Levon
386*6b72f1c0SJohn Levon	#
387*6b72f1c0SJohn Levon	#	'$MAKE lint' in $lintdir
388*6b72f1c0SJohn Levon	#
389*6b72f1c0SJohn Levon	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
390*6b72f1c0SJohn Levon
391*6b72f1c0SJohn Levon	# remove old lint.out
392*6b72f1c0SJohn Levon	rm -f $lintdir/lint.out $lintdir/lint-noise.out
393*6b72f1c0SJohn Levon	if [ -f $lintdir/lint-noise.ref ]; then
394*6b72f1c0SJohn Levon		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
395*6b72f1c0SJohn Levon	fi
396*6b72f1c0SJohn Levon
397*6b72f1c0SJohn Levon	rm -f $LINTOUT
398*6b72f1c0SJohn Levon	cd $lintdir
399*6b72f1c0SJohn Levon	#
400*6b72f1c0SJohn Levon	# Remove all .ln files to ensure a full reference file
401*6b72f1c0SJohn Levon	#
402*6b72f1c0SJohn Levon	rm -f Nothing_to_remove \
403*6b72f1c0SJohn Levon	    `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \
404*6b72f1c0SJohn Levon	    	-prune -o -type f -name '*.ln' -print `
405*6b72f1c0SJohn Levon
406*6b72f1c0SJohn Levon	/bin/time $MAKE -ek lint 2>&1 | \
407*6b72f1c0SJohn Levon	    tee -a $LINTOUT >> $LOGFILE
408*6b72f1c0SJohn Levon
409*6b72f1c0SJohn Levon	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
410*6b72f1c0SJohn Levon
411*6b72f1c0SJohn Levon	grep "$MAKE:" $LINTOUT |
412*6b72f1c0SJohn Levon		egrep -v "Ignoring unknown host" | \
413*6b72f1c0SJohn Levon		tee $TMPDIR/lint_errs >> $mail_msg_file
414*6b72f1c0SJohn Levon	if [[ -s $TMPDIR/lint_errs ]]; then
415*6b72f1c0SJohn Levon		build_extras_ok=n
416*6b72f1c0SJohn Levon	fi
417*6b72f1c0SJohn Levon
418*6b72f1c0SJohn Levon	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
419*6b72f1c0SJohn Levon
420*6b72f1c0SJohn Levon	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
421*6b72f1c0SJohn Levon		>>$mail_msg_file
422*6b72f1c0SJohn Levon	tail -3  $LINTOUT >>$mail_msg_file
423*6b72f1c0SJohn Levon
424*6b72f1c0SJohn Levon	rm -f ${LINTNOISE}.ref
425*6b72f1c0SJohn Levon	if [ -f ${LINTNOISE}.out ]; then
426*6b72f1c0SJohn Levon		mv ${LINTNOISE}.out ${LINTNOISE}.ref
427*6b72f1c0SJohn Levon	fi
428*6b72f1c0SJohn Levon        grep : $LINTOUT | \
429*6b72f1c0SJohn Levon		egrep -v '^(real|user|sys)' |
430*6b72f1c0SJohn Levon		egrep -v '(library construction)' | \
431*6b72f1c0SJohn Levon		egrep -v ': global crosschecks' | \
432*6b72f1c0SJohn Levon		egrep -v 'Ignoring unknown host' | \
433*6b72f1c0SJohn Levon		egrep -v '\.c:$' | \
434*6b72f1c0SJohn Levon		sort | uniq > ${LINTNOISE}.out
435*6b72f1c0SJohn Levon	if [ ! -f ${LINTNOISE}.ref ]; then
436*6b72f1c0SJohn Levon		cp ${LINTNOISE}.out ${LINTNOISE}.ref
437*6b72f1c0SJohn Levon	fi
438*6b72f1c0SJohn Levon
439*6b72f1c0SJohn Levon	if [ "$dodiff" != "n" ]; then
440*6b72f1c0SJohn Levon		echo "\n==== lint warnings $base ====\n" \
441*6b72f1c0SJohn Levon			>>$mail_msg_file
442*6b72f1c0SJohn Levon		# should be none, though there are a few that were filtered out
443*6b72f1c0SJohn Levon		# above
444*6b72f1c0SJohn Levon		egrep -i '(warning|lint):' ${LINTNOISE}.out \
445*6b72f1c0SJohn Levon			| sort | uniq | tee $TMPDIR/lint_warns >> $mail_msg_file
446*6b72f1c0SJohn Levon		if [[ -s $TMPDIR/lint_warns ]]; then
447*6b72f1c0SJohn Levon			build_extras_ok=n
448*6b72f1c0SJohn Levon		fi
449*6b72f1c0SJohn Levon		echo "\n==== lint noise differences $base ====\n" \
450*6b72f1c0SJohn Levon			>> $mail_msg_file
451*6b72f1c0SJohn Levon		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
452*6b72f1c0SJohn Levon			>> $mail_msg_file
453*6b72f1c0SJohn Levon	fi
454*6b72f1c0SJohn Levon}
455*6b72f1c0SJohn Levon
456*6b72f1c0SJohn Levon#
457*6b72f1c0SJohn Levon# Build and install the onbld tools.
458*6b72f1c0SJohn Levon#
459*6b72f1c0SJohn Levon# usage: build_tools DESTROOT
460*6b72f1c0SJohn Levon#
461*6b72f1c0SJohn Levon# returns non-zero status if the build was successful.
462*6b72f1c0SJohn Levon#
463*6b72f1c0SJohn Levonfunction build_tools {
464*6b72f1c0SJohn Levon	DESTROOT=$1
465*6b72f1c0SJohn Levon
466*6b72f1c0SJohn Levon	INSTALLOG=install-${MACH}
467*6b72f1c0SJohn Levon
468*6b72f1c0SJohn Levon	echo "\n==== Building tools at `date` ====\n" \
469*6b72f1c0SJohn Levon		>> $LOGFILE
470*6b72f1c0SJohn Levon
471*6b72f1c0SJohn Levon	rm -f ${TOOLS}/${INSTALLOG}.out
472*6b72f1c0SJohn Levon	cd ${TOOLS}
473*6b72f1c0SJohn Levon	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
474*6b72f1c0SJohn Levon	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
475*6b72f1c0SJohn Levon
476*6b72f1c0SJohn Levon	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
477*6b72f1c0SJohn Levon
478*6b72f1c0SJohn Levon	egrep ":" ${TOOLS}/${INSTALLOG}.out |
479*6b72f1c0SJohn Levon		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
480*6b72f1c0SJohn Levon		egrep -v "Ignoring unknown host" | \
481*6b72f1c0SJohn Levon		egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file
482*6b72f1c0SJohn Levon
483*6b72f1c0SJohn Levon	if [[ -s $TMPDIR/tools_errors ]]; then
484*6b72f1c0SJohn Levon		return 1
485*6b72f1c0SJohn Levon	fi
486*6b72f1c0SJohn Levon	return 0
487*6b72f1c0SJohn Levon}
488*6b72f1c0SJohn Levon
489*6b72f1c0SJohn Levon#
490*6b72f1c0SJohn Levon# Set up to use locally installed tools.
491*6b72f1c0SJohn Levon#
492*6b72f1c0SJohn Levon# usage: use_tools TOOLSROOT
493*6b72f1c0SJohn Levon#
494*6b72f1c0SJohn Levonfunction use_tools {
495*6b72f1c0SJohn Levon	TOOLSROOT=$1
496*6b72f1c0SJohn Levon
497*6b72f1c0SJohn Levon	#
498*6b72f1c0SJohn Levon	# If we're not building ON workspace, then the TOOLSROOT
499*6b72f1c0SJohn Levon	# settings here are clearly ignored by the workspace
500*6b72f1c0SJohn Levon	# makefiles, prepending nonexistent directories to PATH is
501*6b72f1c0SJohn Levon	# harmless, and we clearly do not wish to override
502*6b72f1c0SJohn Levon	# ONBLD_TOOLS.
503*6b72f1c0SJohn Levon	#
504*6b72f1c0SJohn Levon	# If we're building an ON workspace, then the prepended PATH
505*6b72f1c0SJohn Levon	# elements should supercede the preexisting ONBLD_TOOLS paths,
506*6b72f1c0SJohn Levon	# and we want to override ONBLD_TOOLS to catch the tools that
507*6b72f1c0SJohn Levon	# don't have specific path env vars here.
508*6b72f1c0SJohn Levon	#
509*6b72f1c0SJohn Levon	# So the only conditional behavior is overriding ONBLD_TOOLS,
510*6b72f1c0SJohn Levon	# and we check for "an ON workspace" by looking for
511*6b72f1c0SJohn Levon	# ${TOOLSROOT}/opt/onbld.
512*6b72f1c0SJohn Levon	#
513*6b72f1c0SJohn Levon
514*6b72f1c0SJohn Levon	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
515*6b72f1c0SJohn Levon	export STABS
516*6b72f1c0SJohn Levon	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
517*6b72f1c0SJohn Levon	export CTFSTABS
518*6b72f1c0SJohn Levon	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
519*6b72f1c0SJohn Levon	export GENOFFSETS
520*6b72f1c0SJohn Levon
521*6b72f1c0SJohn Levon	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
522*6b72f1c0SJohn Levon	export CTFCONVERT
523*6b72f1c0SJohn Levon	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
524*6b72f1c0SJohn Levon	export CTFMERGE
525*6b72f1c0SJohn Levon
526*6b72f1c0SJohn Levon	if [ "$VERIFY_ELFSIGN" = "y" ]; then
527*6b72f1c0SJohn Levon		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
528*6b72f1c0SJohn Levon	else
529*6b72f1c0SJohn Levon		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
530*6b72f1c0SJohn Levon	fi
531*6b72f1c0SJohn Levon	export ELFSIGN
532*6b72f1c0SJohn Levon
533*6b72f1c0SJohn Levon	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
534*6b72f1c0SJohn Levon	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
535*6b72f1c0SJohn Levon	export PATH
536*6b72f1c0SJohn Levon
537*6b72f1c0SJohn Levon	if [ -d "${TOOLSROOT}/opt/onbld" ]; then
538*6b72f1c0SJohn Levon		ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
539*6b72f1c0SJohn Levon		export ONBLD_TOOLS
540*6b72f1c0SJohn Levon	fi
541*6b72f1c0SJohn Levon
542*6b72f1c0SJohn Levon	echo "\n==== New environment settings. ====\n" >> $LOGFILE
543*6b72f1c0SJohn Levon	echo "STABS=${STABS}" >> $LOGFILE
544*6b72f1c0SJohn Levon	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
545*6b72f1c0SJohn Levon	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
546*6b72f1c0SJohn Levon	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
547*6b72f1c0SJohn Levon	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
548*6b72f1c0SJohn Levon	echo "PATH=${PATH}" >> $LOGFILE
549*6b72f1c0SJohn Levon	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
550*6b72f1c0SJohn Levon}
551*6b72f1c0SJohn Levon
552*6b72f1c0SJohn Levonfunction staffer {
553*6b72f1c0SJohn Levon	if [ $ISUSER -ne 0 ]; then
554*6b72f1c0SJohn Levon		"$@"
555*6b72f1c0SJohn Levon	else
556*6b72f1c0SJohn Levon		arg="\"$1\""
557*6b72f1c0SJohn Levon		shift
558*6b72f1c0SJohn Levon		for i
559*6b72f1c0SJohn Levon		do
560*6b72f1c0SJohn Levon			arg="$arg \"$i\""
561*6b72f1c0SJohn Levon		done
562*6b72f1c0SJohn Levon		eval su $STAFFER -c \'$arg\'
563*6b72f1c0SJohn Levon	fi
564*6b72f1c0SJohn Levon}
565*6b72f1c0SJohn Levon
566*6b72f1c0SJohn Levon#
567*6b72f1c0SJohn Levon# Verify that the closed bins are present
568*6b72f1c0SJohn Levon#
569*6b72f1c0SJohn Levonfunction check_closed_bins {
570*6b72f1c0SJohn Levon	if [[ ! -d "$ON_CLOSED_BINS" ]]; then
571*6b72f1c0SJohn Levon		echo "ON_CLOSED_BINS must point to the closed binaries tree."
572*6b72f1c0SJohn Levon		build_ok=n
573*6b72f1c0SJohn Levon		exit 1
574*6b72f1c0SJohn Levon	fi
575*6b72f1c0SJohn Levon}
576*6b72f1c0SJohn Levon
577*6b72f1c0SJohn Levon#
578*6b72f1c0SJohn Levon# wrapper over wsdiff.
579*6b72f1c0SJohn Levon# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
580*6b72f1c0SJohn Levon#
581*6b72f1c0SJohn Levonfunction do_wsdiff {
582*6b72f1c0SJohn Levon	label=$1
583*6b72f1c0SJohn Levon	oldproto=$2
584*6b72f1c0SJohn Levon	newproto=$3
585*6b72f1c0SJohn Levon
586*6b72f1c0SJohn Levon	wsdiff="wsdiff"
587*6b72f1c0SJohn Levon	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
588*6b72f1c0SJohn Levon
589*6b72f1c0SJohn Levon	echo "\n==== Getting object changes since last build at `date`" \
590*6b72f1c0SJohn Levon	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
591*6b72f1c0SJohn Levon	$wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
592*6b72f1c0SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
593*6b72f1c0SJohn Levon	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
594*6b72f1c0SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
595*6b72f1c0SJohn Levon}
596*6b72f1c0SJohn Levon
597*6b72f1c0SJohn Levon#
598*6b72f1c0SJohn Levon# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
599*6b72f1c0SJohn Levon# together.
600*6b72f1c0SJohn Levon#
601*6b72f1c0SJohn Levon
602*6b72f1c0SJohn Levonfunction set_non_debug_build_flags {
603*6b72f1c0SJohn Levon	export RELEASE_BUILD ; RELEASE_BUILD=
604*6b72f1c0SJohn Levon	unset EXTRA_OPTIONS
605*6b72f1c0SJohn Levon	unset EXTRA_CFLAGS
606*6b72f1c0SJohn Levon}
607*6b72f1c0SJohn Levon
608*6b72f1c0SJohn Levonfunction set_debug_build_flags {
609*6b72f1c0SJohn Levon	unset RELEASE_BUILD
610*6b72f1c0SJohn Levon	unset EXTRA_OPTIONS
611*6b72f1c0SJohn Levon	unset EXTRA_CFLAGS
612*6b72f1c0SJohn Levon}
613*6b72f1c0SJohn Levon
614*6b72f1c0SJohn Levon
615*6b72f1c0SJohn LevonMACH=`uname -p`
616*6b72f1c0SJohn Levon
617*6b72f1c0SJohn Levonif [ "$OPTHOME" = "" ]; then
618*6b72f1c0SJohn Levon	OPTHOME=/opt
619*6b72f1c0SJohn Levon	export OPTHOME
620*6b72f1c0SJohn Levonfi
621*6b72f1c0SJohn Levon
622*6b72f1c0SJohn LevonUSAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file>
623*6b72f1c0SJohn Levon
624*6b72f1c0SJohn LevonWhere:
625*6b72f1c0SJohn Levon	-i	Fast incremental options (no clobber, lint, check)
626*6b72f1c0SJohn Levon	-n      Do not do a bringover
627*6b72f1c0SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
628*6b72f1c0SJohn Levon	-V VERS set the build version string to VERS
629*6b72f1c0SJohn Levon
630*6b72f1c0SJohn Levon	<env_file>  file in Bourne shell syntax that sets and exports
631*6b72f1c0SJohn Levon	variables that configure the operation of this script and many of
632*6b72f1c0SJohn Levon	the scripts this one calls. If <env_file> does not exist,
633*6b72f1c0SJohn Levon	it will be looked for in $OPTHOME/onbld/env.
634*6b72f1c0SJohn Levon
635*6b72f1c0SJohn Levonnon-DEBUG is the default build type. Build options can be set in the
636*6b72f1c0SJohn LevonNIGHTLY_OPTIONS variable in the <env_file> as follows:
637*6b72f1c0SJohn Levon
638*6b72f1c0SJohn Levon	-A	check for ABI differences in .so files
639*6b72f1c0SJohn Levon	-C	check for cstyle/hdrchk errors
640*6b72f1c0SJohn Levon	-D	do a build with DEBUG on
641*6b72f1c0SJohn Levon	-F	do _not_ do a non-DEBUG build
642*6b72f1c0SJohn Levon	-G	gate keeper default group of options (-au)
643*6b72f1c0SJohn Levon	-I	integration engineer default group of options (-ampu)
644*6b72f1c0SJohn Levon	-M	do not run pmodes (safe file permission checker)
645*6b72f1c0SJohn Levon	-N	do not run protocmp
646*6b72f1c0SJohn Levon	-R	default group of options for building a release (-mp)
647*6b72f1c0SJohn Levon	-U	update proto area in the parent
648*6b72f1c0SJohn Levon	-V VERS set the build version string to VERS
649*6b72f1c0SJohn Levon	-f	find unreferenced files
650*6b72f1c0SJohn Levon	-i	do an incremental build (no "make clobber")
651*6b72f1c0SJohn Levon	-l	do "make lint" in $LINTDIRS (default: $SRC y)
652*6b72f1c0SJohn Levon	-m	send mail to $MAILTO at end of build
653*6b72f1c0SJohn Levon	-n      do not do a bringover
654*6b72f1c0SJohn Levon	-p	create packages
655*6b72f1c0SJohn Levon	-r	check ELF runtime attributes in the proto area
656*6b72f1c0SJohn Levon	-t	build and use the tools in $SRC/tools (default setting)
657*6b72f1c0SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
658*6b72f1c0SJohn Levon	-u	update proto_list_$MACH and friends in the parent workspace;
659*6b72f1c0SJohn Levon		when used with -f, also build an unrefmaster.out in the parent
660*6b72f1c0SJohn Levon	-w	report on differences between previous and current proto areas
661*6b72f1c0SJohn Levon'
662*6b72f1c0SJohn Levon#
663*6b72f1c0SJohn Levon#	A log file will be generated under the name $LOGFILE
664*6b72f1c0SJohn Levon#	for partially completed build and log.`date '+%F'`
665*6b72f1c0SJohn Levon#	in the same directory for fully completed builds.
666*6b72f1c0SJohn Levon#
667*6b72f1c0SJohn Levon
668*6b72f1c0SJohn Levon# default values for low-level FLAGS; G I R are group FLAGS
669*6b72f1c0SJohn LevonA_FLAG=n
670*6b72f1c0SJohn LevonC_FLAG=n
671*6b72f1c0SJohn LevonD_FLAG=n
672*6b72f1c0SJohn LevonF_FLAG=n
673*6b72f1c0SJohn Levonf_FLAG=n
674*6b72f1c0SJohn Levoni_FLAG=n; i_CMD_LINE_FLAG=n
675*6b72f1c0SJohn Levonl_FLAG=n
676*6b72f1c0SJohn LevonM_FLAG=n
677*6b72f1c0SJohn Levonm_FLAG=n
678*6b72f1c0SJohn LevonN_FLAG=n
679*6b72f1c0SJohn Levonn_FLAG=n
680*6b72f1c0SJohn Levonp_FLAG=n
681*6b72f1c0SJohn Levonr_FLAG=n
682*6b72f1c0SJohn Levont_FLAG=y
683*6b72f1c0SJohn LevonU_FLAG=n
684*6b72f1c0SJohn Levonu_FLAG=n
685*6b72f1c0SJohn LevonV_FLAG=n
686*6b72f1c0SJohn Levonw_FLAG=n
687*6b72f1c0SJohn LevonW_FLAG=n
688*6b72f1c0SJohn Levon#
689*6b72f1c0SJohn Levonbuild_ok=y
690*6b72f1c0SJohn Levonbuild_extras_ok=y
691*6b72f1c0SJohn Levon
692*6b72f1c0SJohn Levon#
693*6b72f1c0SJohn Levon# examine arguments
694*6b72f1c0SJohn Levon#
695*6b72f1c0SJohn Levon
696*6b72f1c0SJohn LevonOPTIND=1
697*6b72f1c0SJohn Levonwhile getopts +intV:W FLAG
698*6b72f1c0SJohn Levondo
699*6b72f1c0SJohn Levon	case $FLAG in
700*6b72f1c0SJohn Levon	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
701*6b72f1c0SJohn Levon		;;
702*6b72f1c0SJohn Levon	  n )	n_FLAG=y
703*6b72f1c0SJohn Levon		;;
704*6b72f1c0SJohn Levon	 +t )	t_FLAG=n
705*6b72f1c0SJohn Levon		;;
706*6b72f1c0SJohn Levon	  V )	V_FLAG=y
707*6b72f1c0SJohn Levon		V_ARG="$OPTARG"
708*6b72f1c0SJohn Levon		;;
709*6b72f1c0SJohn Levon	  W )   W_FLAG=y
710*6b72f1c0SJohn Levon		;;
711*6b72f1c0SJohn Levon	 \? )	echo "$USAGE"
712*6b72f1c0SJohn Levon		exit 1
713*6b72f1c0SJohn Levon		;;
714*6b72f1c0SJohn Levon	esac
715*6b72f1c0SJohn Levondone
716*6b72f1c0SJohn Levon
717*6b72f1c0SJohn Levon# correct argument count after options
718*6b72f1c0SJohn Levonshift `expr $OPTIND - 1`
719*6b72f1c0SJohn Levon
720*6b72f1c0SJohn Levon# test that the path to the environment-setting file was given
721*6b72f1c0SJohn Levonif [ $# -ne 1 ]; then
722*6b72f1c0SJohn Levon	echo "$USAGE"
723*6b72f1c0SJohn Levon	exit 1
724*6b72f1c0SJohn Levonfi
725*6b72f1c0SJohn Levon
726*6b72f1c0SJohn Levon# check if user is running nightly as root
727*6b72f1c0SJohn Levon# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
728*6b72f1c0SJohn Levon# when root invokes nightly.
729*6b72f1c0SJohn Levon/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
730*6b72f1c0SJohn LevonISUSER=$?;	export ISUSER
731*6b72f1c0SJohn Levon
732*6b72f1c0SJohn Levon#
733*6b72f1c0SJohn Levon# force locale to C
734*6b72f1c0SJohn LevonLANG=C;		export LANG
735*6b72f1c0SJohn LevonLC_ALL=C;	export LC_ALL
736*6b72f1c0SJohn LevonLC_COLLATE=C;	export LC_COLLATE
737*6b72f1c0SJohn LevonLC_CTYPE=C;	export LC_CTYPE
738*6b72f1c0SJohn LevonLC_MESSAGES=C;	export LC_MESSAGES
739*6b72f1c0SJohn LevonLC_MONETARY=C;	export LC_MONETARY
740*6b72f1c0SJohn LevonLC_NUMERIC=C;	export LC_NUMERIC
741*6b72f1c0SJohn LevonLC_TIME=C;	export LC_TIME
742*6b72f1c0SJohn Levon
743*6b72f1c0SJohn Levon# clear environment variables we know to be bad for the build
744*6b72f1c0SJohn Levonunset LD_OPTIONS
745*6b72f1c0SJohn Levonunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
746*6b72f1c0SJohn Levonunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
747*6b72f1c0SJohn Levonunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
748*6b72f1c0SJohn Levonunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
749*6b72f1c0SJohn Levonunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
750*6b72f1c0SJohn Levonunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
751*6b72f1c0SJohn Levonunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
752*6b72f1c0SJohn Levonunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
753*6b72f1c0SJohn Levonunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
754*6b72f1c0SJohn Levonunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
755*6b72f1c0SJohn Levonunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
756*6b72f1c0SJohn Levonunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
757*6b72f1c0SJohn Levonunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
758*6b72f1c0SJohn Levonunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
759*6b72f1c0SJohn Levonunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
760*6b72f1c0SJohn Levonunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
761*6b72f1c0SJohn Levonunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
762*6b72f1c0SJohn Levonunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
763*6b72f1c0SJohn Levonunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
764*6b72f1c0SJohn Levonunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
765*6b72f1c0SJohn Levon
766*6b72f1c0SJohn Levonunset CONFIG
767*6b72f1c0SJohn Levonunset GROUP
768*6b72f1c0SJohn Levonunset OWNER
769*6b72f1c0SJohn Levonunset REMOTE
770*6b72f1c0SJohn Levonunset ENV
771*6b72f1c0SJohn Levonunset ARCH
772*6b72f1c0SJohn Levonunset CLASSPATH
773*6b72f1c0SJohn Levonunset NAME
774*6b72f1c0SJohn Levon
775*6b72f1c0SJohn Levon#
776*6b72f1c0SJohn Levon# To get ONBLD_TOOLS from the environment, it must come from the env file.
777*6b72f1c0SJohn Levon# If it comes interactively, it is generally TOOLS_PROTO, which will be
778*6b72f1c0SJohn Levon# clobbered before the compiler version checks, which will therefore fail.
779*6b72f1c0SJohn Levon#
780*6b72f1c0SJohn Levonunset ONBLD_TOOLS
781*6b72f1c0SJohn Levon
782*6b72f1c0SJohn Levon#
783*6b72f1c0SJohn Levon#	Setup environmental variables
784*6b72f1c0SJohn Levon#
785*6b72f1c0SJohn Levonif [ -f /etc/nightly.conf ]; then
786*6b72f1c0SJohn Levon	. /etc/nightly.conf
787*6b72f1c0SJohn Levonfi
788*6b72f1c0SJohn Levon
789*6b72f1c0SJohn Levonif [ -f $1 ]; then
790*6b72f1c0SJohn Levon	if [[ $1 = */* ]]; then
791*6b72f1c0SJohn Levon		. $1
792*6b72f1c0SJohn Levon	else
793*6b72f1c0SJohn Levon		. ./$1
794*6b72f1c0SJohn Levon	fi
795*6b72f1c0SJohn Levonelse
796*6b72f1c0SJohn Levon	if [ -f $OPTHOME/onbld/env/$1 ]; then
797*6b72f1c0SJohn Levon		. $OPTHOME/onbld/env/$1
798*6b72f1c0SJohn Levon	else
799*6b72f1c0SJohn Levon		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
800*6b72f1c0SJohn Levon		exit 1
801*6b72f1c0SJohn Levon	fi
802*6b72f1c0SJohn Levonfi
803*6b72f1c0SJohn Levon
804*6b72f1c0SJohn Levon# Check if we have sufficient data to continue...
805*6b72f1c0SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
806*6b72f1c0SJohn Levonif  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
807*6b72f1c0SJohn Levon	# Check if the gate data are valid if we don't do a "bringover" below
808*6b72f1c0SJohn Levon	[[ -d "${CODEMGR_WS}" ]] || \
809*6b72f1c0SJohn Levon		fatal_error "Error: ${CODEMGR_WS} is not a directory."
810*6b72f1c0SJohn Levon	[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
811*6b72f1c0SJohn Levon		fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
812*6b72f1c0SJohn Levonfi
813*6b72f1c0SJohn Levon
814*6b72f1c0SJohn Levon#
815*6b72f1c0SJohn Levon# place ourselves in a new task, respecting BUILD_PROJECT if set.
816*6b72f1c0SJohn Levon#
817*6b72f1c0SJohn Levonif [ -z "$BUILD_PROJECT" ]; then
818*6b72f1c0SJohn Levon	/usr/bin/newtask -c $$
819*6b72f1c0SJohn Levonelse
820*6b72f1c0SJohn Levon	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
821*6b72f1c0SJohn Levonfi
822*6b72f1c0SJohn Levon
823*6b72f1c0SJohn Levonps -o taskid= -p $$ | read build_taskid
824*6b72f1c0SJohn Levonps -o project= -p $$ | read build_project
825*6b72f1c0SJohn Levon
826*6b72f1c0SJohn Levon#
827*6b72f1c0SJohn Levon# See if NIGHTLY_OPTIONS is set
828*6b72f1c0SJohn Levon#
829*6b72f1c0SJohn Levonif [ "$NIGHTLY_OPTIONS" = "" ]; then
830*6b72f1c0SJohn Levon	NIGHTLY_OPTIONS="-aBm"
831*6b72f1c0SJohn Levonfi
832*6b72f1c0SJohn Levon
833*6b72f1c0SJohn Levon#
834*6b72f1c0SJohn Levon# If BRINGOVER_WS was not specified, let it default to CLONE_WS
835*6b72f1c0SJohn Levon#
836*6b72f1c0SJohn Levonif [ "$BRINGOVER_WS" = "" ]; then
837*6b72f1c0SJohn Levon	BRINGOVER_WS=$CLONE_WS
838*6b72f1c0SJohn Levonfi
839*6b72f1c0SJohn Levon
840*6b72f1c0SJohn Levon#
841*6b72f1c0SJohn Levon# If BRINGOVER_FILES was not specified, default to usr
842*6b72f1c0SJohn Levon#
843*6b72f1c0SJohn Levonif [ "$BRINGOVER_FILES" = "" ]; then
844*6b72f1c0SJohn Levon	BRINGOVER_FILES="usr"
845*6b72f1c0SJohn Levonfi
846*6b72f1c0SJohn Levon
847*6b72f1c0SJohn Levoncheck_closed_bins
848*6b72f1c0SJohn Levon
849*6b72f1c0SJohn Levon#
850*6b72f1c0SJohn Levon# Note: changes to the option letters here should also be applied to the
851*6b72f1c0SJohn Levon#	bldenv script.  `d' is listed for backward compatibility.
852*6b72f1c0SJohn Levon#
853*6b72f1c0SJohn LevonNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
854*6b72f1c0SJohn LevonOPTIND=1
855*6b72f1c0SJohn Levonwhile getopts +ABCDdFfGIilMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS
856*6b72f1c0SJohn Levondo
857*6b72f1c0SJohn Levon	case $FLAG in
858*6b72f1c0SJohn Levon	  A )	A_FLAG=y
859*6b72f1c0SJohn Levon		;;
860*6b72f1c0SJohn Levon	  B )	D_FLAG=y
861*6b72f1c0SJohn Levon		;; # old version of D
862*6b72f1c0SJohn Levon	  C )	C_FLAG=y
863*6b72f1c0SJohn Levon		;;
864*6b72f1c0SJohn Levon	  D )	D_FLAG=y
865*6b72f1c0SJohn Levon		;;
866*6b72f1c0SJohn Levon	  F )	F_FLAG=y
867*6b72f1c0SJohn Levon		;;
868*6b72f1c0SJohn Levon	  f )	f_FLAG=y
869*6b72f1c0SJohn Levon		;;
870*6b72f1c0SJohn Levon	  G )   u_FLAG=y
871*6b72f1c0SJohn Levon		;;
872*6b72f1c0SJohn Levon	  I )	m_FLAG=y
873*6b72f1c0SJohn Levon		p_FLAG=y
874*6b72f1c0SJohn Levon		u_FLAG=y
875*6b72f1c0SJohn Levon		;;
876*6b72f1c0SJohn Levon	  i )	i_FLAG=y
877*6b72f1c0SJohn Levon		;;
878*6b72f1c0SJohn Levon	  l )	l_FLAG=y
879*6b72f1c0SJohn Levon		;;
880*6b72f1c0SJohn Levon	  M )	M_FLAG=y
881*6b72f1c0SJohn Levon		;;
882*6b72f1c0SJohn Levon	  m )	m_FLAG=y
883*6b72f1c0SJohn Levon		;;
884*6b72f1c0SJohn Levon	  N )	N_FLAG=y
885*6b72f1c0SJohn Levon		;;
886*6b72f1c0SJohn Levon	  n )	n_FLAG=y
887*6b72f1c0SJohn Levon		;;
888*6b72f1c0SJohn Levon	  p )	p_FLAG=y
889*6b72f1c0SJohn Levon		;;
890*6b72f1c0SJohn Levon	  R )	m_FLAG=y
891*6b72f1c0SJohn Levon		p_FLAG=y
892*6b72f1c0SJohn Levon		;;
893*6b72f1c0SJohn Levon	  r )	r_FLAG=y
894*6b72f1c0SJohn Levon		;;
895*6b72f1c0SJohn Levon	 +t )	t_FLAG=n
896*6b72f1c0SJohn Levon		;;
897*6b72f1c0SJohn Levon	  U )   if [ -z "${PARENT_ROOT}" ]; then
898*6b72f1c0SJohn Levon			echo "PARENT_ROOT must be set if the U flag is" \
899*6b72f1c0SJohn Levon			    "present in NIGHTLY_OPTIONS."
900*6b72f1c0SJohn Levon			exit 1
901*6b72f1c0SJohn Levon		fi
902*6b72f1c0SJohn Levon		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
903*6b72f1c0SJohn Levon		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
904*6b72f1c0SJohn Levon			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
905*6b72f1c0SJohn Levon		fi
906*6b72f1c0SJohn Levon		U_FLAG=y
907*6b72f1c0SJohn Levon		;;
908*6b72f1c0SJohn Levon	  u )	u_FLAG=y
909*6b72f1c0SJohn Levon		;;
910*6b72f1c0SJohn Levon	  w )	w_FLAG=y
911*6b72f1c0SJohn Levon		;;
912*6b72f1c0SJohn Levon	  W )   W_FLAG=y
913*6b72f1c0SJohn Levon		;;
914*6b72f1c0SJohn Levon	 \? )	echo "$USAGE"
915*6b72f1c0SJohn Levon		exit 1
916*6b72f1c0SJohn Levon		;;
917*6b72f1c0SJohn Levon	esac
918*6b72f1c0SJohn Levondone
919*6b72f1c0SJohn Levon
920*6b72f1c0SJohn Levonif [ $ISUSER -ne 0 ]; then
921*6b72f1c0SJohn Levon	# Set default value for STAFFER, if needed.
922*6b72f1c0SJohn Levon	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
923*6b72f1c0SJohn Levon		STAFFER=`/usr/xpg4/bin/id -un`
924*6b72f1c0SJohn Levon		export STAFFER
925*6b72f1c0SJohn Levon	fi
926*6b72f1c0SJohn Levonfi
927*6b72f1c0SJohn Levon
928*6b72f1c0SJohn Levonif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
929*6b72f1c0SJohn Levon	MAILTO=$STAFFER
930*6b72f1c0SJohn Levon	export MAILTO
931*6b72f1c0SJohn Levonfi
932*6b72f1c0SJohn Levon
933*6b72f1c0SJohn LevonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
934*6b72f1c0SJohn LevonPATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
935*6b72f1c0SJohn LevonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
936*6b72f1c0SJohn Levonexport PATH
937*6b72f1c0SJohn Levon
938*6b72f1c0SJohn Levon# roots of source trees, both relative to $SRC and absolute.
939*6b72f1c0SJohn Levonrelsrcdirs="."
940*6b72f1c0SJohn Levonabssrcdirs="$SRC"
941*6b72f1c0SJohn Levon
942*6b72f1c0SJohn LevonPROTOCMPTERSE="protocmp.terse -gu"
943*6b72f1c0SJohn LevonPOUND_SIGN="#"
944*6b72f1c0SJohn Levon# have we set RELEASE_DATE in our env file?
945*6b72f1c0SJohn Levonif [ -z "$RELEASE_DATE" ]; then
946*6b72f1c0SJohn Levon	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
947*6b72f1c0SJohn Levonfi
948*6b72f1c0SJohn LevonBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
949*6b72f1c0SJohn LevonBASEWSDIR=$(basename $CODEMGR_WS)
950*6b72f1c0SJohn LevonDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
951*6b72f1c0SJohn Levon
952*6b72f1c0SJohn Levon# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
953*6b72f1c0SJohn Levon# by avoiding repeated shell invocations to evaluate Makefile.master
954*6b72f1c0SJohn Levon# definitions.
955*6b72f1c0SJohn Levonexport POUND_SIGN RELEASE_DATE DEV_CM
956*6b72f1c0SJohn Levon
957*6b72f1c0SJohn Levonmaketype="distributed"
958*6b72f1c0SJohn Levonif [[ -z "$MAKE" ]]; then
959*6b72f1c0SJohn Levon	MAKE=dmake
960*6b72f1c0SJohn Levonelif [[ ! -x "$MAKE" ]]; then
961*6b72f1c0SJohn Levon	echo "\$MAKE is set to garbage in the environment"
962*6b72f1c0SJohn Levon	exit 1
963*6b72f1c0SJohn Levonfi
964*6b72f1c0SJohn Levonexport PATH
965*6b72f1c0SJohn Levonexport MAKE
966*6b72f1c0SJohn Levon
967*6b72f1c0SJohn Levonif [ "${SUNWSPRO}" != "" ]; then
968*6b72f1c0SJohn Levon	PATH="${SUNWSPRO}/bin:$PATH"
969*6b72f1c0SJohn Levon	export PATH
970*6b72f1c0SJohn Levonfi
971*6b72f1c0SJohn Levon
972*6b72f1c0SJohn Levonhostname=$(uname -n)
973*6b72f1c0SJohn Levonif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
974*6b72f1c0SJohn Levonthen
975*6b72f1c0SJohn Levon	maxjobs=
976*6b72f1c0SJohn Levon	if [[ -f $HOME/.make.machines ]]
977*6b72f1c0SJohn Levon	then
978*6b72f1c0SJohn Levon		# Note: there is a hard tab and space character in the []s
979*6b72f1c0SJohn Levon		# below.
980*6b72f1c0SJohn Levon		egrep -i "^[ 	]*$hostname[ 	\.]" \
981*6b72f1c0SJohn Levon			$HOME/.make.machines | read host jobs
982*6b72f1c0SJohn Levon		maxjobs=${jobs##*=}
983*6b72f1c0SJohn Levon	fi
984*6b72f1c0SJohn Levon
985*6b72f1c0SJohn Levon	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
986*6b72f1c0SJohn Levon	then
987*6b72f1c0SJohn Levon		# default
988*6b72f1c0SJohn Levon		maxjobs=4
989*6b72f1c0SJohn Levon	fi
990*6b72f1c0SJohn Levon
991*6b72f1c0SJohn Levon	export DMAKE_MAX_JOBS=$maxjobs
992*6b72f1c0SJohn Levonfi
993*6b72f1c0SJohn Levon
994*6b72f1c0SJohn LevonDMAKE_MODE=parallel;
995*6b72f1c0SJohn Levonexport DMAKE_MODE
996*6b72f1c0SJohn Levon
997*6b72f1c0SJohn Levonif [ -z "${ROOT}" ]; then
998*6b72f1c0SJohn Levon	echo "ROOT must be set."
999*6b72f1c0SJohn Levon	exit 1
1000*6b72f1c0SJohn Levonfi
1001*6b72f1c0SJohn Levon
1002*6b72f1c0SJohn Levon#
1003*6b72f1c0SJohn Levon# if -V flag was given, reset VERSION to V_ARG
1004*6b72f1c0SJohn Levon#
1005*6b72f1c0SJohn Levonif [ "$V_FLAG" = "y" ]; then
1006*6b72f1c0SJohn Levon	VERSION=$V_ARG
1007*6b72f1c0SJohn Levonfi
1008*6b72f1c0SJohn Levon
1009*6b72f1c0SJohn LevonTMPDIR="/tmp/nightly.tmpdir.$$"
1010*6b72f1c0SJohn Levonexport TMPDIR
1011*6b72f1c0SJohn Levonrm -rf ${TMPDIR}
1012*6b72f1c0SJohn Levonmkdir -p $TMPDIR || exit 1
1013*6b72f1c0SJohn Levonchmod 777 $TMPDIR
1014*6b72f1c0SJohn Levon
1015*6b72f1c0SJohn Levon#
1016*6b72f1c0SJohn Levon# Keep elfsign's use of pkcs11_softtoken from looking in the user home
1017*6b72f1c0SJohn Levon# directory, which doesn't always work.   Needed until all build machines
1018*6b72f1c0SJohn Levon# have the fix for 6271754
1019*6b72f1c0SJohn Levon#
1020*6b72f1c0SJohn LevonSOFTTOKEN_DIR=$TMPDIR
1021*6b72f1c0SJohn Levonexport SOFTTOKEN_DIR
1022*6b72f1c0SJohn Levon
1023*6b72f1c0SJohn Levon#
1024*6b72f1c0SJohn Levon# Tools should only be built non-DEBUG.  Keep track of the tools proto
1025*6b72f1c0SJohn Levon# area path relative to $TOOLS, because the latter changes in an
1026*6b72f1c0SJohn Levon# export build.
1027*6b72f1c0SJohn Levon#
1028*6b72f1c0SJohn Levon# TOOLS_PROTO is included below for builds other than usr/src/tools
1029*6b72f1c0SJohn Levon# that look for this location.  For usr/src/tools, this will be
1030*6b72f1c0SJohn Levon# overridden on the $MAKE command line in build_tools().
1031*6b72f1c0SJohn Levon#
1032*6b72f1c0SJohn LevonTOOLS=${SRC}/tools
1033*6b72f1c0SJohn LevonTOOLS_PROTO_REL=proto/root_${MACH}-nd
1034*6b72f1c0SJohn LevonTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
1035*6b72f1c0SJohn Levon
1036*6b72f1c0SJohn Levonunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
1037*6b72f1c0SJohn Levon
1038*6b72f1c0SJohn Levon# create directories that are automatically removed if the nightly script
1039*6b72f1c0SJohn Levon# fails to start correctly
1040*6b72f1c0SJohn Levonfunction newdir {
1041*6b72f1c0SJohn Levon	dir=$1
1042*6b72f1c0SJohn Levon	toadd=
1043*6b72f1c0SJohn Levon	while [ ! -d $dir ]; do
1044*6b72f1c0SJohn Levon		toadd="$dir $toadd"
1045*6b72f1c0SJohn Levon		dir=`dirname $dir`
1046*6b72f1c0SJohn Levon	done
1047*6b72f1c0SJohn Levon	torm=
1048*6b72f1c0SJohn Levon	newlist=
1049*6b72f1c0SJohn Levon	for dir in $toadd; do
1050*6b72f1c0SJohn Levon		if staffer mkdir $dir; then
1051*6b72f1c0SJohn Levon			newlist="$ISUSER $dir $newlist"
1052*6b72f1c0SJohn Levon			torm="$dir $torm"
1053*6b72f1c0SJohn Levon		else
1054*6b72f1c0SJohn Levon			[ -z "$torm" ] || staffer rmdir $torm
1055*6b72f1c0SJohn Levon			return 1
1056*6b72f1c0SJohn Levon		fi
1057*6b72f1c0SJohn Levon	done
1058*6b72f1c0SJohn Levon	newdirlist="$newlist $newdirlist"
1059*6b72f1c0SJohn Levon	return 0
1060*6b72f1c0SJohn Levon}
1061*6b72f1c0SJohn Levonnewdirlist=
1062*6b72f1c0SJohn Levon
1063*6b72f1c0SJohn Levon[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
1064*6b72f1c0SJohn Levon
1065*6b72f1c0SJohn Levon# since this script assumes the build is from full source, it nullifies
1066*6b72f1c0SJohn Levon# variables likely to have been set by a "ws" script; nullification
1067*6b72f1c0SJohn Levon# confines the search space for headers and libraries to the proto area
1068*6b72f1c0SJohn Levon# built from this immediate source.
1069*6b72f1c0SJohn LevonENVLDLIBS1=
1070*6b72f1c0SJohn LevonENVLDLIBS2=
1071*6b72f1c0SJohn LevonENVLDLIBS3=
1072*6b72f1c0SJohn LevonENVCPPFLAGS1=
1073*6b72f1c0SJohn LevonENVCPPFLAGS2=
1074*6b72f1c0SJohn LevonENVCPPFLAGS3=
1075*6b72f1c0SJohn LevonENVCPPFLAGS4=
1076*6b72f1c0SJohn LevonPARENT_ROOT=
1077*6b72f1c0SJohn Levon
1078*6b72f1c0SJohn Levonexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1079*6b72f1c0SJohn Levon	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
1080*6b72f1c0SJohn Levon
1081*6b72f1c0SJohn LevonPKGARCHIVE_ORIG=$PKGARCHIVE
1082*6b72f1c0SJohn Levon
1083*6b72f1c0SJohn Levon#
1084*6b72f1c0SJohn Levon# Juggle the logs and optionally send mail on completion.
1085*6b72f1c0SJohn Levon#
1086*6b72f1c0SJohn Levon
1087*6b72f1c0SJohn Levonfunction logshuffle {
1088*6b72f1c0SJohn Levon    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
1089*6b72f1c0SJohn Levon	if [ -f $LLOG -o -d $LLOG ]; then
1090*6b72f1c0SJohn Levon	    	LLOG=$LLOG.$$
1091*6b72f1c0SJohn Levon	fi
1092*6b72f1c0SJohn Levon	mkdir $LLOG
1093*6b72f1c0SJohn Levon	export LLOG
1094*6b72f1c0SJohn Levon
1095*6b72f1c0SJohn Levon	if [ "$build_ok" = "y" ]; then
1096*6b72f1c0SJohn Levon		mv $ATLOG/proto_list_${MACH} $LLOG
1097*6b72f1c0SJohn Levon
1098*6b72f1c0SJohn Levon		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
1099*6b72f1c0SJohn Levon			mv $ATLOG/proto_list_tools_${MACH} $LLOG
1100*6b72f1c0SJohn Levon	        fi
1101*6b72f1c0SJohn Levon
1102*6b72f1c0SJohn Levon		if [ -f $TMPDIR/wsdiff.results ]; then
1103*6b72f1c0SJohn Levon		    	mv $TMPDIR/wsdiff.results $LLOG
1104*6b72f1c0SJohn Levon		fi
1105*6b72f1c0SJohn Levon
1106*6b72f1c0SJohn Levon		if [ -f $TMPDIR/wsdiff-nd.results ]; then
1107*6b72f1c0SJohn Levon			mv $TMPDIR/wsdiff-nd.results $LLOG
1108*6b72f1c0SJohn Levon		fi
1109*6b72f1c0SJohn Levon	fi
1110*6b72f1c0SJohn Levon
1111*6b72f1c0SJohn Levon	#
1112*6b72f1c0SJohn Levon	# Now that we're about to send mail, it's time to check the noise
1113*6b72f1c0SJohn Levon	# file.  In the event that an error occurs beyond this point, it will
1114*6b72f1c0SJohn Levon	# be recorded in the nightly.log file, but nowhere else.  This would
1115*6b72f1c0SJohn Levon	# include only errors that cause the copying of the noise log to fail
1116*6b72f1c0SJohn Levon	# or the mail itself not to be sent.
1117*6b72f1c0SJohn Levon	#
1118*6b72f1c0SJohn Levon
1119*6b72f1c0SJohn Levon	exec >>$LOGFILE 2>&1
1120*6b72f1c0SJohn Levon	if [ -s $build_noise_file ]; then
1121*6b72f1c0SJohn Levon	    	echo "\n==== Nightly build noise ====\n" |
1122*6b72f1c0SJohn Levon		    tee -a $LOGFILE >>$mail_msg_file
1123*6b72f1c0SJohn Levon		cat $build_noise_file >>$LOGFILE
1124*6b72f1c0SJohn Levon		cat $build_noise_file >>$mail_msg_file
1125*6b72f1c0SJohn Levon		echo | tee -a $LOGFILE >>$mail_msg_file
1126*6b72f1c0SJohn Levon	fi
1127*6b72f1c0SJohn Levon	rm -f $build_noise_file
1128*6b72f1c0SJohn Levon
1129*6b72f1c0SJohn Levon	case "$build_ok" in
1130*6b72f1c0SJohn Levon		y)
1131*6b72f1c0SJohn Levon			state=Completed
1132*6b72f1c0SJohn Levon			;;
1133*6b72f1c0SJohn Levon		i)
1134*6b72f1c0SJohn Levon			state=Interrupted
1135*6b72f1c0SJohn Levon			;;
1136*6b72f1c0SJohn Levon		*)
1137*6b72f1c0SJohn Levon	    		state=Failed
1138*6b72f1c0SJohn Levon			;;
1139*6b72f1c0SJohn Levon	esac
1140*6b72f1c0SJohn Levon
1141*6b72f1c0SJohn Levon	if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
1142*6b72f1c0SJohn Levon		state=Failed
1143*6b72f1c0SJohn Levon	fi
1144*6b72f1c0SJohn Levon
1145*6b72f1c0SJohn Levon	NIGHTLY_STATUS=$state
1146*6b72f1c0SJohn Levon	export NIGHTLY_STATUS
1147*6b72f1c0SJohn Levon
1148*6b72f1c0SJohn Levon	run_hook POST_NIGHTLY $state
1149*6b72f1c0SJohn Levon	run_hook SYS_POST_NIGHTLY $state
1150*6b72f1c0SJohn Levon
1151*6b72f1c0SJohn Levon	#
1152*6b72f1c0SJohn Levon	# mailx(1) sets From: based on the -r flag
1153*6b72f1c0SJohn Levon	# if it is given.
1154*6b72f1c0SJohn Levon	#
1155*6b72f1c0SJohn Levon	mailx_r=
1156*6b72f1c0SJohn Levon	if [[ -n "${MAILFROM}" ]]; then
1157*6b72f1c0SJohn Levon		mailx_r="-r ${MAILFROM}"
1158*6b72f1c0SJohn Levon	fi
1159*6b72f1c0SJohn Levon
1160*6b72f1c0SJohn Levon	cat $build_time_file $build_environ_file $mail_msg_file \
1161*6b72f1c0SJohn Levon	    > ${LLOG}/mail_msg
1162*6b72f1c0SJohn Levon	if [ "$m_FLAG" = "y" ]; then
1163*6b72f1c0SJohn Levon	    	cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
1164*6b72f1c0SJohn Levon	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
1165*6b72f1c0SJohn Levon			${MAILTO}
1166*6b72f1c0SJohn Levon	fi
1167*6b72f1c0SJohn Levon
1168*6b72f1c0SJohn Levon	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
1169*6b72f1c0SJohn Levon	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
1170*6b72f1c0SJohn Levon		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
1171*6b72f1c0SJohn Levon	fi
1172*6b72f1c0SJohn Levon
1173*6b72f1c0SJohn Levon	mv $LOGFILE $LLOG
1174*6b72f1c0SJohn Levon}
1175*6b72f1c0SJohn Levon
1176*6b72f1c0SJohn Levon#
1177*6b72f1c0SJohn Levon#	Remove the locks and temporary files on any exit
1178*6b72f1c0SJohn Levon#
1179*6b72f1c0SJohn Levonfunction cleanup {
1180*6b72f1c0SJohn Levon    	logshuffle
1181*6b72f1c0SJohn Levon
1182*6b72f1c0SJohn Levon	[ -z "$lockfile" ] || staffer rm -f $lockfile
1183*6b72f1c0SJohn Levon	[ -z "$atloglockfile" ] || rm -f $atloglockfile
1184*6b72f1c0SJohn Levon	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
1185*6b72f1c0SJohn Levon	[ -z "$Ulockfile" ] || rm -f $Ulockfile
1186*6b72f1c0SJohn Levon
1187*6b72f1c0SJohn Levon	set -- $newdirlist
1188*6b72f1c0SJohn Levon	while [ $# -gt 0 ]; do
1189*6b72f1c0SJohn Levon		ISUSER=$1 staffer rmdir $2
1190*6b72f1c0SJohn Levon		shift; shift
1191*6b72f1c0SJohn Levon	done
1192*6b72f1c0SJohn Levon	rm -rf $TMPDIR
1193*6b72f1c0SJohn Levon}
1194*6b72f1c0SJohn Levon
1195*6b72f1c0SJohn Levonfunction cleanup_signal {
1196*6b72f1c0SJohn Levon    	build_ok=i
1197*6b72f1c0SJohn Levon	# this will trigger cleanup(), above.
1198*6b72f1c0SJohn Levon	exit 1
1199*6b72f1c0SJohn Levon}
1200*6b72f1c0SJohn Levon
1201*6b72f1c0SJohn Levontrap cleanup 0
1202*6b72f1c0SJohn Levontrap cleanup_signal 1 2 3 15
1203*6b72f1c0SJohn Levon
1204*6b72f1c0SJohn Levon#
1205*6b72f1c0SJohn Levon# Generic lock file processing -- make sure that the lock file doesn't
1206*6b72f1c0SJohn Levon# exist.  If it does, it should name the build host and PID.  If it
1207*6b72f1c0SJohn Levon# doesn't, then make sure we can create it.  Clean up locks that are
1208*6b72f1c0SJohn Levon# known to be stale (assumes host name is unique among build systems
1209*6b72f1c0SJohn Levon# for the workspace).
1210*6b72f1c0SJohn Levon#
1211*6b72f1c0SJohn Levonfunction create_lock {
1212*6b72f1c0SJohn Levon	lockf=$1
1213*6b72f1c0SJohn Levon	lockvar=$2
1214*6b72f1c0SJohn Levon
1215*6b72f1c0SJohn Levon	ldir=`dirname $lockf`
1216*6b72f1c0SJohn Levon	[ -d $ldir ] || newdir $ldir || exit 1
1217*6b72f1c0SJohn Levon	eval $lockvar=$lockf
1218*6b72f1c0SJohn Levon
1219*6b72f1c0SJohn Levon	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
1220*6b72f1c0SJohn Levon		basews=`basename $CODEMGR_WS`
1221*6b72f1c0SJohn Levon		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
1222*6b72f1c0SJohn Levon		if [ "$host" != "$hostname" ]; then
1223*6b72f1c0SJohn Levon			echo "$MACH build of $basews apparently" \
1224*6b72f1c0SJohn Levon			    "already started by $user on $host as $pid."
1225*6b72f1c0SJohn Levon			exit 1
1226*6b72f1c0SJohn Levon		elif kill -s 0 $pid 2>/dev/null; then
1227*6b72f1c0SJohn Levon			echo "$MACH build of $basews already started" \
1228*6b72f1c0SJohn Levon			    "by $user as $pid."
1229*6b72f1c0SJohn Levon			exit 1
1230*6b72f1c0SJohn Levon		else
1231*6b72f1c0SJohn Levon			# stale lock; clear it out and try again
1232*6b72f1c0SJohn Levon			rm -f $lockf
1233*6b72f1c0SJohn Levon		fi
1234*6b72f1c0SJohn Levon	done
1235*6b72f1c0SJohn Levon}
1236*6b72f1c0SJohn Levon
1237*6b72f1c0SJohn Levon#
1238*6b72f1c0SJohn Levon# Return the list of interesting proto areas, depending on the current
1239*6b72f1c0SJohn Levon# options.
1240*6b72f1c0SJohn Levon#
1241*6b72f1c0SJohn Levonfunction allprotos {
1242*6b72f1c0SJohn Levon	typeset roots="$ROOT"
1243*6b72f1c0SJohn Levon
1244*6b72f1c0SJohn Levon	if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
1245*6b72f1c0SJohn Levon		roots="$roots $ROOT-nd"
1246*6b72f1c0SJohn Levon	fi
1247*6b72f1c0SJohn Levon
1248*6b72f1c0SJohn Levon	echo $roots
1249*6b72f1c0SJohn Levon}
1250*6b72f1c0SJohn Levon
1251*6b72f1c0SJohn Levon# Ensure no other instance of this script is running on this host.
1252*6b72f1c0SJohn Levon# LOCKNAME can be set in <env_file>, and is by default, but is not
1253*6b72f1c0SJohn Levon# required due to the use of $ATLOG below.
1254*6b72f1c0SJohn Levonif [ -n "$LOCKNAME" ]; then
1255*6b72f1c0SJohn Levon	create_lock /tmp/$LOCKNAME "lockfile"
1256*6b72f1c0SJohn Levonfi
1257*6b72f1c0SJohn Levon#
1258*6b72f1c0SJohn Levon# Create from one, two, or three other locks:
1259*6b72f1c0SJohn Levon#	$ATLOG/nightly.lock
1260*6b72f1c0SJohn Levon#		- protects against multiple builds in same workspace
1261*6b72f1c0SJohn Levon#	$PARENT_WS/usr/src/nightly.$MACH.lock
1262*6b72f1c0SJohn Levon#		- protects against multiple 'u' copy-backs
1263*6b72f1c0SJohn Levon#	$NIGHTLY_PARENT_ROOT/nightly.lock
1264*6b72f1c0SJohn Levon#		- protects against multiple 'U' copy-backs
1265*6b72f1c0SJohn Levon#
1266*6b72f1c0SJohn Levon# Overriding ISUSER to 1 causes the lock to be created as root if the
1267*6b72f1c0SJohn Levon# script is run as root.  The default is to create it as $STAFFER.
1268*6b72f1c0SJohn LevonISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1269*6b72f1c0SJohn Levonif [ "$u_FLAG" = "y" ]; then
1270*6b72f1c0SJohn Levon	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1271*6b72f1c0SJohn Levonfi
1272*6b72f1c0SJohn Levonif [ "$U_FLAG" = "y" ]; then
1273*6b72f1c0SJohn Levon	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1274*6b72f1c0SJohn Levon	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1275*6b72f1c0SJohn Levonfi
1276*6b72f1c0SJohn Levon
1277*6b72f1c0SJohn Levon# Locks have been taken, so we're doing a build and we're committed to
1278*6b72f1c0SJohn Levon# the directories we may have created so far.
1279*6b72f1c0SJohn Levonnewdirlist=
1280*6b72f1c0SJohn Levon
1281*6b72f1c0SJohn Levon#
1282*6b72f1c0SJohn Levon# Create mail_msg_file
1283*6b72f1c0SJohn Levon#
1284*6b72f1c0SJohn Levonmail_msg_file="${TMPDIR}/mail_msg"
1285*6b72f1c0SJohn Levontouch $mail_msg_file
1286*6b72f1c0SJohn Levonbuild_time_file="${TMPDIR}/build_time"
1287*6b72f1c0SJohn Levonbuild_environ_file="${TMPDIR}/build_environ"
1288*6b72f1c0SJohn Levontouch $build_environ_file
1289*6b72f1c0SJohn Levon#
1290*6b72f1c0SJohn Levon#	Move old LOGFILE aside
1291*6b72f1c0SJohn Levon#	ATLOG directory already made by 'create_lock' above
1292*6b72f1c0SJohn Levon#
1293*6b72f1c0SJohn Levonif [ -f $LOGFILE ]; then
1294*6b72f1c0SJohn Levon	mv -f $LOGFILE ${LOGFILE}-
1295*6b72f1c0SJohn Levonfi
1296*6b72f1c0SJohn Levon#
1297*6b72f1c0SJohn Levon#	Build OsNet source
1298*6b72f1c0SJohn Levon#
1299*6b72f1c0SJohn LevonSTART_DATE=`date`
1300*6b72f1c0SJohn LevonSECONDS=0
1301*6b72f1c0SJohn Levonecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
1302*6b72f1c0SJohn Levon    | tee -a $LOGFILE > $build_time_file
1303*6b72f1c0SJohn Levon
1304*6b72f1c0SJohn Levonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1305*6b72f1c0SJohn Levon    tee -a $mail_msg_file >> $LOGFILE
1306*6b72f1c0SJohn Levon
1307*6b72f1c0SJohn Levon# make sure we log only to the nightly build file
1308*6b72f1c0SJohn Levonbuild_noise_file="${TMPDIR}/build_noise"
1309*6b72f1c0SJohn Levonexec </dev/null >$build_noise_file 2>&1
1310*6b72f1c0SJohn Levon
1311*6b72f1c0SJohn Levonrun_hook SYS_PRE_NIGHTLY
1312*6b72f1c0SJohn Levonrun_hook PRE_NIGHTLY
1313*6b72f1c0SJohn Levon
1314*6b72f1c0SJohn Levonecho "\n==== list of environment variables ====\n" >> $LOGFILE
1315*6b72f1c0SJohn Levonenv >> $LOGFILE
1316*6b72f1c0SJohn Levon
1317*6b72f1c0SJohn Levonecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1318*6b72f1c0SJohn Levon
1319*6b72f1c0SJohn Levonif [ "$N_FLAG" = "y" ]; then
1320*6b72f1c0SJohn Levon	if [ "$p_FLAG" = "y" ]; then
1321*6b72f1c0SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1322*6b72f1c0SJohn LevonWARNING: the p option (create packages) is set, but so is the N option (do
1323*6b72f1c0SJohn Levon         not run protocmp); this is dangerous; you should unset the N option
1324*6b72f1c0SJohn LevonEOF
1325*6b72f1c0SJohn Levon	else
1326*6b72f1c0SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1327*6b72f1c0SJohn LevonWarning: the N option (do not run protocmp) is set; it probably shouldn't be
1328*6b72f1c0SJohn LevonEOF
1329*6b72f1c0SJohn Levon	fi
1330*6b72f1c0SJohn Levon	echo "" | tee -a $mail_msg_file >> $LOGFILE
1331*6b72f1c0SJohn Levonfi
1332*6b72f1c0SJohn Levon
1333*6b72f1c0SJohn Levonif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1334*6b72f1c0SJohn Levon	#
1335*6b72f1c0SJohn Levon	# In the past we just complained but went ahead with the lint
1336*6b72f1c0SJohn Levon	# pass, even though the proto area was built non-DEBUG.  It's
1337*6b72f1c0SJohn Levon	# unlikely that non-DEBUG headers will make a difference, but
1338*6b72f1c0SJohn Levon	# rather than assuming it's a safe combination, force the user
1339*6b72f1c0SJohn Levon	# to specify a DEBUG build.
1340*6b72f1c0SJohn Levon	#
1341*6b72f1c0SJohn Levon	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
1342*6b72f1c0SJohn Levon	    | tee -a $mail_msg_file >> $LOGFILE
1343*6b72f1c0SJohn Levon	l_FLAG=n
1344*6b72f1c0SJohn Levonfi
1345*6b72f1c0SJohn Levon
1346*6b72f1c0SJohn Levonif [ "$f_FLAG" = "y" ]; then
1347*6b72f1c0SJohn Levon	if [ "$i_FLAG" = "y" ]; then
1348*6b72f1c0SJohn Levon		echo "WARNING: the -f flag cannot be used during incremental" \
1349*6b72f1c0SJohn Levon		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1350*6b72f1c0SJohn Levon		f_FLAG=n
1351*6b72f1c0SJohn Levon	fi
1352*6b72f1c0SJohn Levon	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
1353*6b72f1c0SJohn Levon		echo "WARNING: the -f flag requires -l, and -p;" \
1354*6b72f1c0SJohn Levon		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1355*6b72f1c0SJohn Levon		f_FLAG=n
1356*6b72f1c0SJohn Levon	fi
1357*6b72f1c0SJohn Levonfi
1358*6b72f1c0SJohn Levon
1359*6b72f1c0SJohn Levonif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
1360*6b72f1c0SJohn Levon	echo "WARNING: -w specified, but $ROOT does not exist;" \
1361*6b72f1c0SJohn Levon	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
1362*6b72f1c0SJohn Levon	w_FLAG=n
1363*6b72f1c0SJohn Levonfi
1364*6b72f1c0SJohn Levon
1365*6b72f1c0SJohn Levonif [ "$t_FLAG" = "n" ]; then
1366*6b72f1c0SJohn Levon	#
1367*6b72f1c0SJohn Levon	# We're not doing a tools build, so make sure elfsign(1) is
1368*6b72f1c0SJohn Levon	# new enough to safely sign non-crypto binaries.  We test
1369*6b72f1c0SJohn Levon	# debugging output from elfsign to detect the old version.
1370*6b72f1c0SJohn Levon	#
1371*6b72f1c0SJohn Levon	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
1372*6b72f1c0SJohn Levon	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
1373*6b72f1c0SJohn Levon	    | egrep algorithmOID`
1374*6b72f1c0SJohn Levon	if [ -z "$newelfsigntest" ]; then
1375*6b72f1c0SJohn Levon		echo "WARNING: /usr/bin/elfsign out of date;" \
1376*6b72f1c0SJohn Levon		    "will only sign crypto modules\n" | \
1377*6b72f1c0SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
1378*6b72f1c0SJohn Levon		export ELFSIGN_OBJECT=true
1379*6b72f1c0SJohn Levon	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
1380*6b72f1c0SJohn Levon		echo "WARNING: VERIFY_ELFSIGN=y requires" \
1381*6b72f1c0SJohn Levon		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
1382*6b72f1c0SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
1383*6b72f1c0SJohn Levon	fi
1384*6b72f1c0SJohn Levonfi
1385*6b72f1c0SJohn Levon
1386*6b72f1c0SJohn Levoncase $MULTI_PROTO in
1387*6b72f1c0SJohn Levonyes|no)	;;
1388*6b72f1c0SJohn Levon*)
1389*6b72f1c0SJohn Levon	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
1390*6b72f1c0SJohn Levon	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
1391*6b72f1c0SJohn Levon	echo "Setting MULTI_PROTO to \"no\".\n" | \
1392*6b72f1c0SJohn Levon	    tee -a $mail_msg_file >> $LOGFILE
1393*6b72f1c0SJohn Levon	export MULTI_PROTO=no
1394*6b72f1c0SJohn Levon	;;
1395*6b72f1c0SJohn Levonesac
1396*6b72f1c0SJohn Levon
1397*6b72f1c0SJohn Levonecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1398*6b72f1c0SJohn Levonecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
1399*6b72f1c0SJohn Levon
1400*6b72f1c0SJohn Levon# Save the current proto area if we're comparing against the last build
1401*6b72f1c0SJohn Levonif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
1402*6b72f1c0SJohn Levon    if [ -d "$ROOT.prev" ]; then
1403*6b72f1c0SJohn Levon	rm -rf $ROOT.prev
1404*6b72f1c0SJohn Levon    fi
1405*6b72f1c0SJohn Levon    mv $ROOT $ROOT.prev
1406*6b72f1c0SJohn Levonfi
1407*6b72f1c0SJohn Levon
1408*6b72f1c0SJohn Levon# Same for non-DEBUG proto area
1409*6b72f1c0SJohn Levonif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
1410*6b72f1c0SJohn Levon	if [ -d "$ROOT-nd.prev" ]; then
1411*6b72f1c0SJohn Levon		rm -rf $ROOT-nd.prev
1412*6b72f1c0SJohn Levon	fi
1413*6b72f1c0SJohn Levon	mv $ROOT-nd $ROOT-nd.prev
1414*6b72f1c0SJohn Levonfi
1415*6b72f1c0SJohn Levon
1416*6b72f1c0SJohn Levon#
1417*6b72f1c0SJohn Levon# Echo the SCM type of the parent workspace, this can't just be which_scm
1418*6b72f1c0SJohn Levon# as that does not know how to identify various network repositories.
1419*6b72f1c0SJohn Levon#
1420*6b72f1c0SJohn Levonfunction parent_wstype {
1421*6b72f1c0SJohn Levon	typeset scm_type junk
1422*6b72f1c0SJohn Levon
1423*6b72f1c0SJohn Levon	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
1424*6b72f1c0SJohn Levon	    | read scm_type junk
1425*6b72f1c0SJohn Levon	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
1426*6b72f1c0SJohn Levon		# Probe BRINGOVER_WS to determine its type
1427*6b72f1c0SJohn Levon		if [[ $BRINGOVER_WS == ssh://* ]]; then
1428*6b72f1c0SJohn Levon			scm_type="mercurial"
1429*6b72f1c0SJohn Levon		elif [[ $BRINGOVER_WS == http://* ]] && \
1430*6b72f1c0SJohn Levon		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
1431*6b72f1c0SJohn Levon		    egrep -s "application/mercurial" 2> /dev/null; then
1432*6b72f1c0SJohn Levon			scm_type="mercurial"
1433*6b72f1c0SJohn Levon		else
1434*6b72f1c0SJohn Levon			scm_type="none"
1435*6b72f1c0SJohn Levon		fi
1436*6b72f1c0SJohn Levon	fi
1437*6b72f1c0SJohn Levon
1438*6b72f1c0SJohn Levon	# fold both unsupported and unrecognized results into "none"
1439*6b72f1c0SJohn Levon	case "$scm_type" in
1440*6b72f1c0SJohn Levon	mercurial)
1441*6b72f1c0SJohn Levon		;;
1442*6b72f1c0SJohn Levon	*)	scm_type=none
1443*6b72f1c0SJohn Levon		;;
1444*6b72f1c0SJohn Levon	esac
1445*6b72f1c0SJohn Levon
1446*6b72f1c0SJohn Levon	echo $scm_type
1447*6b72f1c0SJohn Levon}
1448*6b72f1c0SJohn Levon
1449*6b72f1c0SJohn Levon# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
1450*6b72f1c0SJohn Levonfunction child_wstype {
1451*6b72f1c0SJohn Levon	typeset scm_type junk
1452*6b72f1c0SJohn Levon
1453*6b72f1c0SJohn Levon	# Probe CODEMGR_WS to determine its type
1454*6b72f1c0SJohn Levon	if [[ -d $CODEMGR_WS ]]; then
1455*6b72f1c0SJohn Levon		$WHICH_SCM | read scm_type junk || exit 1
1456*6b72f1c0SJohn Levon	fi
1457*6b72f1c0SJohn Levon
1458*6b72f1c0SJohn Levon	case "$scm_type" in
1459*6b72f1c0SJohn Levon	none|git|mercurial)
1460*6b72f1c0SJohn Levon		;;
1461*6b72f1c0SJohn Levon	*)	scm_type=none
1462*6b72f1c0SJohn Levon		;;
1463*6b72f1c0SJohn Levon	esac
1464*6b72f1c0SJohn Levon
1465*6b72f1c0SJohn Levon	echo $scm_type
1466*6b72f1c0SJohn Levon}
1467*6b72f1c0SJohn Levon
1468*6b72f1c0SJohn LevonSCM_TYPE=$(child_wstype)
1469*6b72f1c0SJohn Levon
1470*6b72f1c0SJohn Levon#
1471*6b72f1c0SJohn Levon#	Decide whether to clobber
1472*6b72f1c0SJohn Levon#
1473*6b72f1c0SJohn Levonif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
1474*6b72f1c0SJohn Levon	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
1475*6b72f1c0SJohn Levon
1476*6b72f1c0SJohn Levon	cd $SRC
1477*6b72f1c0SJohn Levon	# remove old clobber file
1478*6b72f1c0SJohn Levon	rm -f $SRC/clobber.out
1479*6b72f1c0SJohn Levon	rm -f $SRC/clobber-${MACH}.out
1480*6b72f1c0SJohn Levon
1481*6b72f1c0SJohn Levon	# Remove all .make.state* files, just in case we are restarting
1482*6b72f1c0SJohn Levon	# the build after having interrupted a previous 'make clobber'.
1483*6b72f1c0SJohn Levon	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
1484*6b72f1c0SJohn Levon		-o -name 'interfaces.*' \) -prune \
1485*6b72f1c0SJohn Levon		-o -name '.make.*' -print | xargs rm -f
1486*6b72f1c0SJohn Levon
1487*6b72f1c0SJohn Levon	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
1488*6b72f1c0SJohn Levon	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
1489*6b72f1c0SJohn Levon	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1490*6b72f1c0SJohn Levon		egrep -v "Ignoring unknown host" | \
1491*6b72f1c0SJohn Levon		tee $TMPDIR/clobber_errs >> $mail_msg_file
1492*6b72f1c0SJohn Levon
1493*6b72f1c0SJohn Levon	if [[ -s $TMPDIR/clobber_errs ]]; then
1494*6b72f1c0SJohn Levon		build_extras_ok=n
1495*6b72f1c0SJohn Levon	fi
1496*6b72f1c0SJohn Levon
1497*6b72f1c0SJohn Levon	if [[ "$t_FLAG" = "y" ]]; then
1498*6b72f1c0SJohn Levon		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
1499*6b72f1c0SJohn Levon		cd ${TOOLS}
1500*6b72f1c0SJohn Levon		rm -f ${TOOLS}/clobber-${MACH}.out
1501*6b72f1c0SJohn Levon		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
1502*6b72f1c0SJohn Levon			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
1503*6b72f1c0SJohn Levon		echo "\n==== Make tools clobber ERRORS ====\n" \
1504*6b72f1c0SJohn Levon			>> $mail_msg_file
1505*6b72f1c0SJohn Levon		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1506*6b72f1c0SJohn Levon			>> $mail_msg_file
1507*6b72f1c0SJohn Levon		if (( $? == 0 )); then
1508*6b72f1c0SJohn Levon			build_extras_ok=n
1509*6b72f1c0SJohn Levon		fi
1510*6b72f1c0SJohn Levon		rm -rf ${TOOLS_PROTO}
1511*6b72f1c0SJohn Levon		mkdir -p ${TOOLS_PROTO}
1512*6b72f1c0SJohn Levon	fi
1513*6b72f1c0SJohn Levon
1514*6b72f1c0SJohn Levon	typeset roots=$(allprotos)
1515*6b72f1c0SJohn Levon	echo "\n\nClearing $roots" >> "$LOGFILE"
1516*6b72f1c0SJohn Levon	rm -rf $roots
1517*6b72f1c0SJohn Levon
1518*6b72f1c0SJohn Levon	# Get back to a clean workspace as much as possible to catch
1519*6b72f1c0SJohn Levon	# problems that only occur on fresh workspaces.
1520*6b72f1c0SJohn Levon	# Remove all .make.state* files, libraries, and .o's that may
1521*6b72f1c0SJohn Levon	# have been omitted from clobber.  A couple of libraries are
1522*6b72f1c0SJohn Levon	# under source code control, so leave them alone.
1523*6b72f1c0SJohn Levon	# We should probably blow away temporary directories too.
1524*6b72f1c0SJohn Levon	cd $SRC
1525*6b72f1c0SJohn Levon	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
1526*6b72f1c0SJohn Levon	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
1527*6b72f1c0SJohn Levon	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1528*6b72f1c0SJohn Levon	       -name '*.o' \) -print | \
1529*6b72f1c0SJohn Levon	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
1530*6b72f1c0SJohn Levonelse
1531*6b72f1c0SJohn Levon	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
1532*6b72f1c0SJohn Levonfi
1533*6b72f1c0SJohn Levon
1534*6b72f1c0SJohn Levontype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
1535*6b72f1c0SJohn Levon	typeset -x PATH=$PATH
1536*6b72f1c0SJohn Levon
1537*6b72f1c0SJohn Levon	# If the repository doesn't exist yet, then we want to populate it.
1538*6b72f1c0SJohn Levon	if [[ ! -d $CODEMGR_WS/.hg ]]; then
1539*6b72f1c0SJohn Levon		staffer hg init $CODEMGR_WS
1540*6b72f1c0SJohn Levon		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
1541*6b72f1c0SJohn Levon		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
1542*6b72f1c0SJohn Levon		touch $TMPDIR/new_repository
1543*6b72f1c0SJohn Levon	fi
1544*6b72f1c0SJohn Levon
1545*6b72f1c0SJohn Levon	typeset -x HGMERGE="/bin/false"
1546*6b72f1c0SJohn Levon
1547*6b72f1c0SJohn Levon	#
1548*6b72f1c0SJohn Levon	# If the user has changes, regardless of whether those changes are
1549*6b72f1c0SJohn Levon	# committed, and regardless of whether those changes conflict, then
1550*6b72f1c0SJohn Levon	# we'll attempt to merge them either implicitly (uncommitted) or
1551*6b72f1c0SJohn Levon	# explicitly (committed).
1552*6b72f1c0SJohn Levon	#
1553*6b72f1c0SJohn Levon	# These are the messages we'll use to help clarify mercurial output
1554*6b72f1c0SJohn Levon	# in those cases.
1555*6b72f1c0SJohn Levon	#
1556*6b72f1c0SJohn Levon	typeset mergefailmsg="\
1557*6b72f1c0SJohn Levon***\n\
1558*6b72f1c0SJohn Levon*** nightly was unable to automatically merge your changes.  You should\n\
1559*6b72f1c0SJohn Levon*** redo the full merge manually, following the steps outlined by mercurial\n\
1560*6b72f1c0SJohn Levon*** above, then restart nightly.\n\
1561*6b72f1c0SJohn Levon***\n"
1562*6b72f1c0SJohn Levon	typeset mergepassmsg="\
1563*6b72f1c0SJohn Levon***\n\
1564*6b72f1c0SJohn Levon*** nightly successfully merged your changes.  This means that your working\n\
1565*6b72f1c0SJohn Levon*** directory has been updated, but those changes are not yet committed.\n\
1566*6b72f1c0SJohn Levon*** After nightly completes, you should validate the results of the merge,\n\
1567*6b72f1c0SJohn Levon*** then use hg commit manually.\n\
1568*6b72f1c0SJohn Levon***\n"
1569*6b72f1c0SJohn Levon
1570*6b72f1c0SJohn Levon	#
1571*6b72f1c0SJohn Levon	# For each repository in turn:
1572*6b72f1c0SJohn Levon	#
1573*6b72f1c0SJohn Levon	# 1. Do the pull.  If this fails, dump the output and bail out.
1574*6b72f1c0SJohn Levon	#
1575*6b72f1c0SJohn Levon	# 2. If the pull resulted in an extra head, do an explicit merge.
1576*6b72f1c0SJohn Levon	#    If this fails, dump the output and bail out.
1577*6b72f1c0SJohn Levon	#
1578*6b72f1c0SJohn Levon	# Because we can't rely on Mercurial to exit with a failure code
1579*6b72f1c0SJohn Levon	# when a merge fails (Mercurial issue #186), we must grep the
1580*6b72f1c0SJohn Levon	# output of pull/merge to check for attempted and/or failed merges.
1581*6b72f1c0SJohn Levon	#
1582*6b72f1c0SJohn Levon	# 3. If a merge failed, set the message and fail the bringover.
1583*6b72f1c0SJohn Levon	#
1584*6b72f1c0SJohn Levon	# 4. Otherwise, if a merge succeeded, set the message
1585*6b72f1c0SJohn Levon	#
1586*6b72f1c0SJohn Levon	# 5. Dump the output, and any message from step 3 or 4.
1587*6b72f1c0SJohn Levon	#
1588*6b72f1c0SJohn Levon
1589*6b72f1c0SJohn Levon	typeset HG_SOURCE=$BRINGOVER_WS
1590*6b72f1c0SJohn Levon	if [ ! -f $TMPDIR/new_repository ]; then
1591*6b72f1c0SJohn Levon		HG_SOURCE=$TMPDIR/open_bundle.hg
1592*6b72f1c0SJohn Levon		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
1593*6b72f1c0SJohn Levon		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
1594*6b72f1c0SJohn Levon
1595*6b72f1c0SJohn Levon		#
1596*6b72f1c0SJohn Levon		# If there are no incoming changesets, then incoming will
1597*6b72f1c0SJohn Levon		# fail, and there will be no bundle file.  Reset the source,
1598*6b72f1c0SJohn Levon		# to allow the remaining logic to complete with no false
1599*6b72f1c0SJohn Levon		# negatives.  (Unlike incoming, pull will return success
1600*6b72f1c0SJohn Levon		# for the no-change case.)
1601*6b72f1c0SJohn Levon		#
1602*6b72f1c0SJohn Levon		if (( $? != 0 )); then
1603*6b72f1c0SJohn Levon			HG_SOURCE=$BRINGOVER_WS
1604*6b72f1c0SJohn Levon		fi
1605*6b72f1c0SJohn Levon	fi
1606*6b72f1c0SJohn Levon
1607*6b72f1c0SJohn Levon	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
1608*6b72f1c0SJohn Levon	    > $TMPDIR/pull_open.out 2>&1
1609*6b72f1c0SJohn Levon	if (( $? != 0 )); then
1610*6b72f1c0SJohn Levon		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
1611*6b72f1c0SJohn Levon		cat $TMPDIR/pull_open.out
1612*6b72f1c0SJohn Levon		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
1613*6b72f1c0SJohn Levon			printf "$mergefailmsg"
1614*6b72f1c0SJohn Levon		fi
1615*6b72f1c0SJohn Levon		touch $TMPDIR/bringover_failed
1616*6b72f1c0SJohn Levon		return
1617*6b72f1c0SJohn Levon	fi
1618*6b72f1c0SJohn Levon
1619*6b72f1c0SJohn Levon	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
1620*6b72f1c0SJohn Levon		staffer hg --cwd $CODEMGR_WS merge \
1621*6b72f1c0SJohn Levon		    >> $TMPDIR/pull_open.out 2>&1
1622*6b72f1c0SJohn Levon		if (( $? != 0 )); then
1623*6b72f1c0SJohn Levon			printf "%s: merge failed as follows:\n\n" \
1624*6b72f1c0SJohn Levon			    "$CODEMGR_WS"
1625*6b72f1c0SJohn Levon			cat $TMPDIR/pull_open.out
1626*6b72f1c0SJohn Levon			if grep "^merging.*failed" $TMPDIR/pull_open.out \
1627*6b72f1c0SJohn Levon			    > /dev/null 2>&1; then
1628*6b72f1c0SJohn Levon				printf "$mergefailmsg"
1629*6b72f1c0SJohn Levon			fi
1630*6b72f1c0SJohn Levon			touch $TMPDIR/bringover_failed
1631*6b72f1c0SJohn Levon			return
1632*6b72f1c0SJohn Levon		fi
1633*6b72f1c0SJohn Levon	fi
1634*6b72f1c0SJohn Levon
1635*6b72f1c0SJohn Levon	printf "updated %s with the following results:\n" "$CODEMGR_WS"
1636*6b72f1c0SJohn Levon	cat $TMPDIR/pull_open.out
1637*6b72f1c0SJohn Levon	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
1638*6b72f1c0SJohn Levon		printf "$mergepassmsg"
1639*6b72f1c0SJohn Levon	fi
1640*6b72f1c0SJohn Levon	printf "\n"
1641*6b72f1c0SJohn Levon
1642*6b72f1c0SJohn Levon	#
1643*6b72f1c0SJohn Levon	# Per-changeset output is neither useful nor manageable for a
1644*6b72f1c0SJohn Levon	# newly-created repository.
1645*6b72f1c0SJohn Levon	#
1646*6b72f1c0SJohn Levon	if [ -f $TMPDIR/new_repository ]; then
1647*6b72f1c0SJohn Levon		return
1648*6b72f1c0SJohn Levon	fi
1649*6b72f1c0SJohn Levon
1650*6b72f1c0SJohn Levon	printf "\nadded the following changesets to open repository:\n"
1651*6b72f1c0SJohn Levon	cat $TMPDIR/incoming_open.out
1652*6b72f1c0SJohn Levon}
1653*6b72f1c0SJohn Levon
1654*6b72f1c0SJohn Levontype bringover_none > /dev/null 2>&1 || function bringover_none {
1655*6b72f1c0SJohn Levon	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
1656*6b72f1c0SJohn Levon	touch $TMPDIR/bringover_failed
1657*6b72f1c0SJohn Levon}
1658*6b72f1c0SJohn Levon
1659*6b72f1c0SJohn Levon#
1660*6b72f1c0SJohn Levon#	Decide whether to bringover to the codemgr workspace
1661*6b72f1c0SJohn Levon#
1662*6b72f1c0SJohn Levonif [ "$n_FLAG" = "n" ]; then
1663*6b72f1c0SJohn Levon	PARENT_SCM_TYPE=$(parent_wstype)
1664*6b72f1c0SJohn Levon
1665*6b72f1c0SJohn Levon	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
1666*6b72f1c0SJohn Levon		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
1667*6b72f1c0SJohn Levon		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
1668*6b72f1c0SJohn Levon		exit 1
1669*6b72f1c0SJohn Levon	fi
1670*6b72f1c0SJohn Levon
1671*6b72f1c0SJohn Levon	run_hook PRE_BRINGOVER
1672*6b72f1c0SJohn Levon
1673*6b72f1c0SJohn Levon	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
1674*6b72f1c0SJohn Levon	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
1675*6b72f1c0SJohn Levon
1676*6b72f1c0SJohn Levon	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
1677*6b72f1c0SJohn Levon		tee -a $mail_msg_file >> $LOGFILE
1678*6b72f1c0SJohn Levon
1679*6b72f1c0SJohn Levon	if [ -f $TMPDIR/bringover_failed ]; then
1680*6b72f1c0SJohn Levon		rm -f $TMPDIR/bringover_failed
1681*6b72f1c0SJohn Levon		build_ok=n
1682*6b72f1c0SJohn Levon		echo "trouble with bringover, quitting at `date`." |
1683*6b72f1c0SJohn Levon			tee -a $mail_msg_file >> $LOGFILE
1684*6b72f1c0SJohn Levon		exit 1
1685*6b72f1c0SJohn Levon	fi
1686*6b72f1c0SJohn Levon
1687*6b72f1c0SJohn Levon	#
1688*6b72f1c0SJohn Levon	# It's possible that we used the bringover above to create
1689*6b72f1c0SJohn Levon	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
1690*6b72f1c0SJohn Levon	# but should now be the same as $BRINGOVER_WS.
1691*6b72f1c0SJohn Levon	#
1692*6b72f1c0SJohn Levon	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
1693*6b72f1c0SJohn Levon
1694*6b72f1c0SJohn Levon	run_hook POST_BRINGOVER
1695*6b72f1c0SJohn Levon
1696*6b72f1c0SJohn Levon	check_closed_bins
1697*6b72f1c0SJohn Levon
1698*6b72f1c0SJohn Levonelse
1699*6b72f1c0SJohn Levon	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
1700*6b72f1c0SJohn Levonfi
1701*6b72f1c0SJohn Levon
1702*6b72f1c0SJohn Levon# Safeguards
1703*6b72f1c0SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
1704*6b72f1c0SJohn Levon[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
1705*6b72f1c0SJohn Levon[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
1706*6b72f1c0SJohn Levon
1707*6b72f1c0SJohn Levonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
1708*6b72f1c0SJohn Levon
1709*6b72f1c0SJohn Levon# System
1710*6b72f1c0SJohn Levonwhence uname | tee -a $build_environ_file >> $LOGFILE
1711*6b72f1c0SJohn Levonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
1712*6b72f1c0SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
1713*6b72f1c0SJohn Levon
1714*6b72f1c0SJohn Levon# make
1715*6b72f1c0SJohn Levonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
1716*6b72f1c0SJohn Levon$MAKE -v | tee -a $build_environ_file >> $LOGFILE
1717*6b72f1c0SJohn Levonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1718*6b72f1c0SJohn Levon    tee -a $build_environ_file >> $LOGFILE
1719*6b72f1c0SJohn Levon
1720*6b72f1c0SJohn Levon#
1721*6b72f1c0SJohn Levon# Report the compiler versions.
1722*6b72f1c0SJohn Levon#
1723*6b72f1c0SJohn Levon
1724*6b72f1c0SJohn Levonif [[ ! -f $SRC/Makefile ]]; then
1725*6b72f1c0SJohn Levon	build_ok=n
1726*6b72f1c0SJohn Levon	echo "\nUnable to find \"Makefile\" in $SRC." | \
1727*6b72f1c0SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
1728*6b72f1c0SJohn Levon	exit 1
1729*6b72f1c0SJohn Levonfi
1730*6b72f1c0SJohn Levon
1731*6b72f1c0SJohn Levon( cd $SRC
1732*6b72f1c0SJohn Levon  for target in cc-version cc64-version java-version; do
1733*6b72f1c0SJohn Levon	echo
1734*6b72f1c0SJohn Levon	#
1735*6b72f1c0SJohn Levon	# Put statefile somewhere we know we can write to rather than trip
1736*6b72f1c0SJohn Levon	# over a read-only $srcroot.
1737*6b72f1c0SJohn Levon	#
1738*6b72f1c0SJohn Levon	rm -f $TMPDIR/make-state
1739*6b72f1c0SJohn Levon	export SRC
1740*6b72f1c0SJohn Levon	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
1741*6b72f1c0SJohn Levon		continue
1742*6b72f1c0SJohn Levon	fi
1743*6b72f1c0SJohn Levon	touch $TMPDIR/nocompiler
1744*6b72f1c0SJohn Levon  done
1745*6b72f1c0SJohn Levon  echo
1746*6b72f1c0SJohn Levon) | tee -a $build_environ_file >> $LOGFILE
1747*6b72f1c0SJohn Levon
1748*6b72f1c0SJohn Levonif [ -f $TMPDIR/nocompiler ]; then
1749*6b72f1c0SJohn Levon	rm -f $TMPDIR/nocompiler
1750*6b72f1c0SJohn Levon	build_ok=n
1751*6b72f1c0SJohn Levon	echo "Aborting due to missing compiler." |
1752*6b72f1c0SJohn Levon		tee -a $build_environ_file >> $LOGFILE
1753*6b72f1c0SJohn Levon	exit 1
1754*6b72f1c0SJohn Levonfi
1755*6b72f1c0SJohn Levon
1756*6b72f1c0SJohn Levon# as
1757*6b72f1c0SJohn Levonwhence as | tee -a $build_environ_file >> $LOGFILE
1758*6b72f1c0SJohn Levonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
1759*6b72f1c0SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
1760*6b72f1c0SJohn Levon
1761*6b72f1c0SJohn Levon# Check that we're running a capable link-editor
1762*6b72f1c0SJohn Levonwhence ld | tee -a $build_environ_file >> $LOGFILE
1763*6b72f1c0SJohn LevonLDVER=`ld -V 2>&1`
1764*6b72f1c0SJohn Levonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
1765*6b72f1c0SJohn LevonLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
1766*6b72f1c0SJohn Levonif [ `expr $LDVER \< 422` -eq 1 ]; then
1767*6b72f1c0SJohn Levon	echo "The link-editor needs to be at version 422 or higher to build" | \
1768*6b72f1c0SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
1769*6b72f1c0SJohn Levon	echo "the latest stuff.  Hope your build works." | \
1770*6b72f1c0SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
1771*6b72f1c0SJohn Levonfi
1772*6b72f1c0SJohn Levon
1773*6b72f1c0SJohn Levon#
1774*6b72f1c0SJohn Levon# Build and use the workspace's tools if requested
1775*6b72f1c0SJohn Levon#
1776*6b72f1c0SJohn Levonif [[ "$t_FLAG" = "y" ]]; then
1777*6b72f1c0SJohn Levon	set_non_debug_build_flags
1778*6b72f1c0SJohn Levon
1779*6b72f1c0SJohn Levon	build_tools ${TOOLS_PROTO}
1780*6b72f1c0SJohn Levon	if (( $? != 0 )); then
1781*6b72f1c0SJohn Levon		build_ok=n
1782*6b72f1c0SJohn Levon	else
1783*6b72f1c0SJohn Levon		use_tools $TOOLS_PROTO
1784*6b72f1c0SJohn Levon	fi
1785*6b72f1c0SJohn Levonfi
1786*6b72f1c0SJohn Levon
1787*6b72f1c0SJohn Levon# timestamp the start of the normal build; the findunref tool uses it.
1788*6b72f1c0SJohn Levontouch $SRC/.build.tstamp
1789*6b72f1c0SJohn Levon
1790*6b72f1c0SJohn Levonnormal_build
1791*6b72f1c0SJohn Levon
1792*6b72f1c0SJohn LevonORIG_SRC=$SRC
1793*6b72f1c0SJohn LevonBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
1794*6b72f1c0SJohn Levon
1795*6b72f1c0SJohn Levon
1796*6b72f1c0SJohn Levon#
1797*6b72f1c0SJohn Levon# There are several checks that need to look at the proto area, but
1798*6b72f1c0SJohn Levon# they only need to look at one, and they don't care whether it's
1799*6b72f1c0SJohn Levon# DEBUG or non-DEBUG.
1800*6b72f1c0SJohn Levon#
1801*6b72f1c0SJohn Levonif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
1802*6b72f1c0SJohn Levon	checkroot=$ROOT-nd
1803*6b72f1c0SJohn Levonelse
1804*6b72f1c0SJohn Levon	checkroot=$ROOT
1805*6b72f1c0SJohn Levonfi
1806*6b72f1c0SJohn Levon
1807*6b72f1c0SJohn Levonif [ "$build_ok" = "y" ]; then
1808*6b72f1c0SJohn Levon	echo "\n==== Creating protolist system file at `date` ====" \
1809*6b72f1c0SJohn Levon		>> $LOGFILE
1810*6b72f1c0SJohn Levon	protolist $checkroot > $ATLOG/proto_list_${MACH}
1811*6b72f1c0SJohn Levon	echo "==== protolist system file created at `date` ====\n" \
1812*6b72f1c0SJohn Levon		>> $LOGFILE
1813*6b72f1c0SJohn Levon
1814*6b72f1c0SJohn Levon	if [ "$N_FLAG" != "y" ]; then
1815*6b72f1c0SJohn Levon
1816*6b72f1c0SJohn Levon		E1=
1817*6b72f1c0SJohn Levon		f1=
1818*6b72f1c0SJohn Levon		for f in $f1; do
1819*6b72f1c0SJohn Levon			if [ -f "$f" ]; then
1820*6b72f1c0SJohn Levon				E1="$E1 -e $f"
1821*6b72f1c0SJohn Levon			fi
1822*6b72f1c0SJohn Levon		done
1823*6b72f1c0SJohn Levon
1824*6b72f1c0SJohn Levon		E2=
1825*6b72f1c0SJohn Levon		f2=
1826*6b72f1c0SJohn Levon		if [ -d "$SRC/pkg" ]; then
1827*6b72f1c0SJohn Levon			f2="$f2 exceptions/packaging"
1828*6b72f1c0SJohn Levon		fi
1829*6b72f1c0SJohn Levon
1830*6b72f1c0SJohn Levon		for f in $f2; do
1831*6b72f1c0SJohn Levon			if [ -f "$f" ]; then
1832*6b72f1c0SJohn Levon				E2="$E2 -e $f"
1833*6b72f1c0SJohn Levon			fi
1834*6b72f1c0SJohn Levon		done
1835*6b72f1c0SJohn Levon	fi
1836*6b72f1c0SJohn Levon
1837*6b72f1c0SJohn Levon	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
1838*6b72f1c0SJohn Levon		echo "\n==== Validating manifests against proto area ====\n" \
1839*6b72f1c0SJohn Levon		    >> $mail_msg_file
1840*6b72f1c0SJohn Levon		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
1841*6b72f1c0SJohn Levon		    tee $TMPDIR/protocmp_noise >> $mail_msg_file
1842*6b72f1c0SJohn Levon		if [[ -s $TMPDIR/protocmp_noise ]]; then
1843*6b72f1c0SJohn Levon			build_extras_ok=n
1844*6b72f1c0SJohn Levon		fi
1845*6b72f1c0SJohn Levon	fi
1846*6b72f1c0SJohn Levon
1847*6b72f1c0SJohn Levon	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
1848*6b72f1c0SJohn Levon		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
1849*6b72f1c0SJohn Levon		if [ -n "$E2" ]; then
1850*6b72f1c0SJohn Levon			ELIST=$E2
1851*6b72f1c0SJohn Levon		else
1852*6b72f1c0SJohn Levon			ELIST=$E1
1853*6b72f1c0SJohn Levon		fi
1854*6b72f1c0SJohn Levon		$PROTOCMPTERSE \
1855*6b72f1c0SJohn Levon			"Files in yesterday's proto area, but not today's:" \
1856*6b72f1c0SJohn Levon			"Files in today's proto area, but not yesterday's:" \
1857*6b72f1c0SJohn Levon			"Files that changed between yesterday and today:" \
1858*6b72f1c0SJohn Levon			${ELIST} \
1859*6b72f1c0SJohn Levon			-d $REF_PROTO_LIST \
1860*6b72f1c0SJohn Levon			$ATLOG/proto_list_${MACH} \
1861*6b72f1c0SJohn Levon			>> $mail_msg_file
1862*6b72f1c0SJohn Levon	fi
1863*6b72f1c0SJohn Levonfi
1864*6b72f1c0SJohn Levon
1865*6b72f1c0SJohn Levonif [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
1866*6b72f1c0SJohn Levon    "$build_extras_ok" == "y" ]]; then
1867*6b72f1c0SJohn Levon	staffer cp $ATLOG/proto_list_${MACH} \
1868*6b72f1c0SJohn Levon		$PARENT_WS/usr/src/proto_list_${MACH}
1869*6b72f1c0SJohn Levonfi
1870*6b72f1c0SJohn Levon
1871*6b72f1c0SJohn Levon# Update parent proto area if necessary. This is done now
1872*6b72f1c0SJohn Levon# so that the proto area has either DEBUG or non-DEBUG kernels.
1873*6b72f1c0SJohn Levon# Note that this clears out the lock file, so we can dispense with
1874*6b72f1c0SJohn Levon# the variable now.
1875*6b72f1c0SJohn Levonif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
1876*6b72f1c0SJohn Levon	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
1877*6b72f1c0SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
1878*6b72f1c0SJohn Levon	rm -rf $NIGHTLY_PARENT_ROOT/*
1879*6b72f1c0SJohn Levon	unset Ulockfile
1880*6b72f1c0SJohn Levon	mkdir -p $NIGHTLY_PARENT_ROOT
1881*6b72f1c0SJohn Levon	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
1882*6b72f1c0SJohn Levon		( cd $ROOT; tar cf - . |
1883*6b72f1c0SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
1884*6b72f1c0SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
1885*6b72f1c0SJohn Levon	fi
1886*6b72f1c0SJohn Levon	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
1887*6b72f1c0SJohn Levon		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
1888*6b72f1c0SJohn Levon		mkdir -p $NIGHTLY_PARENT_ROOT-nd
1889*6b72f1c0SJohn Levon		cd $ROOT-nd
1890*6b72f1c0SJohn Levon		( tar cf - . |
1891*6b72f1c0SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
1892*6b72f1c0SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
1893*6b72f1c0SJohn Levon	fi
1894*6b72f1c0SJohn Levon	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
1895*6b72f1c0SJohn Levon		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
1896*6b72f1c0SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
1897*6b72f1c0SJohn Levon		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
1898*6b72f1c0SJohn Levon		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
1899*6b72f1c0SJohn Levon		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
1900*6b72f1c0SJohn Levon			( cd $TOOLS_PROTO; tar cf - . |
1901*6b72f1c0SJohn Levon			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
1902*6b72f1c0SJohn Levon			    umask 0; tar xpf - ) ) 2>&1 |
1903*6b72f1c0SJohn Levon			    tee -a $mail_msg_file >> $LOGFILE
1904*6b72f1c0SJohn Levon		fi
1905*6b72f1c0SJohn Levon	fi
1906*6b72f1c0SJohn Levonfi
1907*6b72f1c0SJohn Levon
1908*6b72f1c0SJohn Levon#
1909*6b72f1c0SJohn Levon# ELF verification: ABI (-A) and runtime (-r) checks
1910*6b72f1c0SJohn Levon#
1911*6b72f1c0SJohn Levonif [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
1912*6b72f1c0SJohn Levon	# Directory ELF-data.$MACH holds the files produced by these tests.
1913*6b72f1c0SJohn Levon	elf_ddir=$SRC/ELF-data.$MACH
1914*6b72f1c0SJohn Levon
1915*6b72f1c0SJohn Levon	# If there is a previous ELF-data backup directory, remove it. Then,
1916*6b72f1c0SJohn Levon	# rotate current ELF-data directory into its place and create a new
1917*6b72f1c0SJohn Levon	# empty directory
1918*6b72f1c0SJohn Levon	rm -rf $elf_ddir.ref
1919*6b72f1c0SJohn Levon	if [[ -d $elf_ddir ]]; then
1920*6b72f1c0SJohn Levon		mv $elf_ddir $elf_ddir.ref
1921*6b72f1c0SJohn Levon	fi
1922*6b72f1c0SJohn Levon	mkdir -p $elf_ddir
1923*6b72f1c0SJohn Levon
1924*6b72f1c0SJohn Levon	# Call find_elf to produce a list of the ELF objects in the proto area.
1925*6b72f1c0SJohn Levon	# This list is passed to check_rtime and interface_check, preventing
1926*6b72f1c0SJohn Levon	# them from separately calling find_elf to do the same work twice.
1927*6b72f1c0SJohn Levon	find_elf -fr $checkroot > $elf_ddir/object_list
1928*6b72f1c0SJohn Levon
1929*6b72f1c0SJohn Levon	if [[ $A_FLAG = y ]]; then
1930*6b72f1c0SJohn Levon	       	echo "\n==== Check versioning and ABI information ====\n"  | \
1931*6b72f1c0SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
1932*6b72f1c0SJohn Levon
1933*6b72f1c0SJohn Levon		# Produce interface description for the proto. Report errors.
1934*6b72f1c0SJohn Levon		interface_check -o -w $elf_ddir -f object_list \
1935*6b72f1c0SJohn Levon			-i interface -E interface.err
1936*6b72f1c0SJohn Levon		if [[ -s $elf_ddir/interface.err ]]; then
1937*6b72f1c0SJohn Levon			tee -a $LOGFILE < $elf_ddir/interface.err \
1938*6b72f1c0SJohn Levon			    >> $mail_msg_file
1939*6b72f1c0SJohn Levon			build_extras_ok=n
1940*6b72f1c0SJohn Levon		fi
1941*6b72f1c0SJohn Levon
1942*6b72f1c0SJohn Levon		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
1943*6b72f1c0SJohn Levon		# description file to that from the baseline gate. Issue a
1944*6b72f1c0SJohn Levon		# warning if the baseline is not present, and keep going.
1945*6b72f1c0SJohn Levon		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
1946*6b72f1c0SJohn Levon			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
1947*6b72f1c0SJohn Levon
1948*6b72f1c0SJohn Levon		       	echo "\n==== Compare versioning and ABI information" \
1949*6b72f1c0SJohn Levon			    "to baseline ====\n"  | \
1950*6b72f1c0SJohn Levon			    tee -a $LOGFILE >> $mail_msg_file
1951*6b72f1c0SJohn Levon		       	echo "Baseline:  $base_ifile\n" >> $LOGFILE
1952*6b72f1c0SJohn Levon
1953*6b72f1c0SJohn Levon			if [[ -f $base_ifile ]]; then
1954*6b72f1c0SJohn Levon				interface_cmp -d -o $base_ifile \
1955*6b72f1c0SJohn Levon				    $elf_ddir/interface > $elf_ddir/interface.cmp
1956*6b72f1c0SJohn Levon				if [[ -s $elf_ddir/interface.cmp ]]; then
1957*6b72f1c0SJohn Levon					echo | tee -a $LOGFILE >> $mail_msg_file
1958*6b72f1c0SJohn Levon					tee -a $LOGFILE < \
1959*6b72f1c0SJohn Levon					    $elf_ddir/interface.cmp \
1960*6b72f1c0SJohn Levon					    >> $mail_msg_file
1961*6b72f1c0SJohn Levon					build_extras_ok=n
1962*6b72f1c0SJohn Levon				fi
1963*6b72f1c0SJohn Levon			else
1964*6b72f1c0SJohn Levon			       	echo "baseline not available. comparison" \
1965*6b72f1c0SJohn Levon                                    "skipped" | \
1966*6b72f1c0SJohn Levon				    tee -a $LOGFILE >> $mail_msg_file
1967*6b72f1c0SJohn Levon			fi
1968*6b72f1c0SJohn Levon
1969*6b72f1c0SJohn Levon		fi
1970*6b72f1c0SJohn Levon	fi
1971*6b72f1c0SJohn Levon
1972*6b72f1c0SJohn Levon	if [[ $r_FLAG = y ]]; then
1973*6b72f1c0SJohn Levon		echo "\n==== Check ELF runtime attributes ====\n" | \
1974*6b72f1c0SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
1975*6b72f1c0SJohn Levon
1976*6b72f1c0SJohn Levon		# If we're doing a DEBUG build the proto area will be left
1977*6b72f1c0SJohn Levon		# with debuggable objects, thus don't assert -s.
1978*6b72f1c0SJohn Levon		if [[ $D_FLAG = y ]]; then
1979*6b72f1c0SJohn Levon			rtime_sflag=""
1980*6b72f1c0SJohn Levon		else
1981*6b72f1c0SJohn Levon			rtime_sflag="-s"
1982*6b72f1c0SJohn Levon		fi
1983*6b72f1c0SJohn Levon		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
1984*6b72f1c0SJohn Levon			-D object_list  -f object_list -E runtime.err \
1985*6b72f1c0SJohn Levon			-I runtime.attr.raw
1986*6b72f1c0SJohn Levon		if (( $? != 0 )); then
1987*6b72f1c0SJohn Levon			build_extras_ok=n
1988*6b72f1c0SJohn Levon		fi
1989*6b72f1c0SJohn Levon
1990*6b72f1c0SJohn Levon		# check_rtime -I output needs to be sorted in order to
1991*6b72f1c0SJohn Levon		# compare it to that from previous builds.
1992*6b72f1c0SJohn Levon		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
1993*6b72f1c0SJohn Levon		rm $elf_ddir/runtime.attr.raw
1994*6b72f1c0SJohn Levon
1995*6b72f1c0SJohn Levon		# Report errors
1996*6b72f1c0SJohn Levon		if [[ -s $elf_ddir/runtime.err ]]; then
1997*6b72f1c0SJohn Levon			tee -a $LOGFILE < $elf_ddir/runtime.err \
1998*6b72f1c0SJohn Levon				>> $mail_msg_file
1999*6b72f1c0SJohn Levon			build_extras_ok=n
2000*6b72f1c0SJohn Levon		fi
2001*6b72f1c0SJohn Levon
2002*6b72f1c0SJohn Levon		# If there is an ELF-data directory from a previous build,
2003*6b72f1c0SJohn Levon		# then diff the attr files. These files contain information
2004*6b72f1c0SJohn Levon		# about dependencies, versioning, and runpaths. There is some
2005*6b72f1c0SJohn Levon		# overlap with the ABI checking done above, but this also
2006*6b72f1c0SJohn Levon		# flushes out non-ABI interface differences along with the
2007*6b72f1c0SJohn Levon		# other information.
2008*6b72f1c0SJohn Levon		echo "\n==== Diff ELF runtime attributes" \
2009*6b72f1c0SJohn Levon		    "(since last build) ====\n" | \
2010*6b72f1c0SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
2011*6b72f1c0SJohn Levon
2012*6b72f1c0SJohn Levon		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
2013*6b72f1c0SJohn Levon			diff $elf_ddir.ref/runtime.attr \
2014*6b72f1c0SJohn Levon				$elf_ddir/runtime.attr \
2015*6b72f1c0SJohn Levon				>> $mail_msg_file
2016*6b72f1c0SJohn Levon		fi
2017*6b72f1c0SJohn Levon	fi
2018*6b72f1c0SJohn Levon
2019*6b72f1c0SJohn Levon	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
2020*6b72f1c0SJohn Levon	if [[ "$u_FLAG" = "y" ]]; then
2021*6b72f1c0SJohn Levon		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
2022*6b72f1c0SJohn Levon
2023*6b72f1c0SJohn Levon		# If parent lacks the ELF-data.$MACH directory, create it
2024*6b72f1c0SJohn Levon		if [[ ! -d $p_elf_ddir ]]; then
2025*6b72f1c0SJohn Levon			staffer mkdir -p $p_elf_ddir
2026*6b72f1c0SJohn Levon		fi
2027*6b72f1c0SJohn Levon
2028*6b72f1c0SJohn Levon		# These files are used asynchronously by other builds for ABI
2029*6b72f1c0SJohn Levon		# verification, as above for the -A option. As such, we require
2030*6b72f1c0SJohn Levon		# the file replacement to be atomic. Copy the data to a temp
2031*6b72f1c0SJohn Levon		# file in the same filesystem and then rename into place.
2032*6b72f1c0SJohn Levon		(
2033*6b72f1c0SJohn Levon			cd $elf_ddir
2034*6b72f1c0SJohn Levon			for elf_dfile in *; do
2035*6b72f1c0SJohn Levon				staffer cp $elf_dfile \
2036*6b72f1c0SJohn Levon				    ${p_elf_ddir}/${elf_dfile}.new
2037*6b72f1c0SJohn Levon				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
2038*6b72f1c0SJohn Levon				    ${p_elf_ddir}/${elf_dfile}
2039*6b72f1c0SJohn Levon			done
2040*6b72f1c0SJohn Levon		)
2041*6b72f1c0SJohn Levon	fi
2042*6b72f1c0SJohn Levonfi
2043*6b72f1c0SJohn Levon
2044*6b72f1c0SJohn Levon# DEBUG lint of kernel begins
2045*6b72f1c0SJohn Levon
2046*6b72f1c0SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2047*6b72f1c0SJohn Levon	if [ "$LINTDIRS" = "" ]; then
2048*6b72f1c0SJohn Levon		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2049*6b72f1c0SJohn Levon		LINTDIRS="$SRC y"
2050*6b72f1c0SJohn Levon	fi
2051*6b72f1c0SJohn Levon	set $LINTDIRS
2052*6b72f1c0SJohn Levon	while [ $# -gt 0 ]; do
2053*6b72f1c0SJohn Levon		dolint $1 $2; shift; shift
2054*6b72f1c0SJohn Levon	done
2055*6b72f1c0SJohn Levonelse
2056*6b72f1c0SJohn Levon	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2057*6b72f1c0SJohn Levonfi
2058*6b72f1c0SJohn Levon
2059*6b72f1c0SJohn Levon# "make check" begins
2060*6b72f1c0SJohn Levon
2061*6b72f1c0SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2062*6b72f1c0SJohn Levon	# remove old check.out
2063*6b72f1c0SJohn Levon	rm -f $SRC/check.out
2064*6b72f1c0SJohn Levon
2065*6b72f1c0SJohn Levon	rm -f $SRC/check-${MACH}.out
2066*6b72f1c0SJohn Levon	cd $SRC
2067*6b72f1c0SJohn Levon	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
2068*6b72f1c0SJohn Levon	    >> $LOGFILE
2069*6b72f1c0SJohn Levon	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2070*6b72f1c0SJohn Levon
2071*6b72f1c0SJohn Levon	grep ":" $SRC/check-${MACH}.out |
2072*6b72f1c0SJohn Levon		egrep -v "Ignoring unknown host" | \
2073*6b72f1c0SJohn Levon		sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
2074*6b72f1c0SJohn Levon
2075*6b72f1c0SJohn Levon	if [[ -s $TMPDIR/check_errors ]]; then
2076*6b72f1c0SJohn Levon		build_extras_ok=n
2077*6b72f1c0SJohn Levon	fi
2078*6b72f1c0SJohn Levonelse
2079*6b72f1c0SJohn Levon	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2080*6b72f1c0SJohn Levonfi
2081*6b72f1c0SJohn Levon
2082*6b72f1c0SJohn Levonecho "\n==== Find core files ====\n" | \
2083*6b72f1c0SJohn Levon    tee -a $LOGFILE >> $mail_msg_file
2084*6b72f1c0SJohn Levon
2085*6b72f1c0SJohn Levonfind $abssrcdirs -name core -a -type f -exec file {} \; | \
2086*6b72f1c0SJohn Levon	tee -a $LOGFILE >> $mail_msg_file
2087*6b72f1c0SJohn Levon
2088*6b72f1c0SJohn Levonif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2089*6b72f1c0SJohn Levon	echo "\n==== Diff unreferenced files (since last build) ====\n" \
2090*6b72f1c0SJohn Levon	    | tee -a $LOGFILE >>$mail_msg_file
2091*6b72f1c0SJohn Levon	rm -f $SRC/unref-${MACH}.ref
2092*6b72f1c0SJohn Levon	if [ -f $SRC/unref-${MACH}.out ]; then
2093*6b72f1c0SJohn Levon		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2094*6b72f1c0SJohn Levon	fi
2095*6b72f1c0SJohn Levon
2096*6b72f1c0SJohn Levon	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
2097*6b72f1c0SJohn Levon	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
2098*6b72f1c0SJohn Levon	    sort > $SRC/unref-${MACH}.out
2099*6b72f1c0SJohn Levon
2100*6b72f1c0SJohn Levon	if [ ! -f $SRC/unref-${MACH}.ref ]; then
2101*6b72f1c0SJohn Levon		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2102*6b72f1c0SJohn Levon	fi
2103*6b72f1c0SJohn Levon
2104*6b72f1c0SJohn Levon	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
2105*6b72f1c0SJohn Levonfi
2106*6b72f1c0SJohn Levon
2107*6b72f1c0SJohn Levon# Verify that the usual lists of files, such as exception lists,
2108*6b72f1c0SJohn Levon# contain only valid references to files.  If the build has failed,
2109*6b72f1c0SJohn Levon# then don't check the proto area.
2110*6b72f1c0SJohn LevonCHECK_PATHS=${CHECK_PATHS:-y}
2111*6b72f1c0SJohn Levonif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
2112*6b72f1c0SJohn Levon	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
2113*6b72f1c0SJohn Levon		>>$mail_msg_file
2114*6b72f1c0SJohn Levon	arg=-b
2115*6b72f1c0SJohn Levon	[ "$build_ok" = y ] && arg=
2116*6b72f1c0SJohn Levon	checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1
2117*6b72f1c0SJohn Levon	if [[ -s $SRC/check-paths.out ]]; then
2118*6b72f1c0SJohn Levon		tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file
2119*6b72f1c0SJohn Levon		build_extras_ok=n
2120*6b72f1c0SJohn Levon	fi
2121*6b72f1c0SJohn Levonfi
2122*6b72f1c0SJohn Levon
2123*6b72f1c0SJohn Levonif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2124*6b72f1c0SJohn Levon	echo "\n==== Impact on file permissions ====\n" \
2125*6b72f1c0SJohn Levon		>> $mail_msg_file
2126*6b72f1c0SJohn Levon
2127*6b72f1c0SJohn Levon	abspkg=
2128*6b72f1c0SJohn Levon	for d in $abssrcdirs; do
2129*6b72f1c0SJohn Levon		if [ -d "$d/pkg" ]; then
2130*6b72f1c0SJohn Levon			abspkg="$abspkg $d"
2131*6b72f1c0SJohn Levon		fi
2132*6b72f1c0SJohn Levon	done
2133*6b72f1c0SJohn Levon
2134*6b72f1c0SJohn Levon	if [ -n "$abspkg" ]; then
2135*6b72f1c0SJohn Levon		for d in "$abspkg"; do
2136*6b72f1c0SJohn Levon			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
2137*6b72f1c0SJohn Levon		done
2138*6b72f1c0SJohn Levon	fi
2139*6b72f1c0SJohn Levonfi
2140*6b72f1c0SJohn Levon
2141*6b72f1c0SJohn Levonif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
2142*6b72f1c0SJohn Levon	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2143*6b72f1c0SJohn Levon		do_wsdiff DEBUG $ROOT.prev $ROOT
2144*6b72f1c0SJohn Levon	fi
2145*6b72f1c0SJohn Levon
2146*6b72f1c0SJohn Levon	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2147*6b72f1c0SJohn Levon		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
2148*6b72f1c0SJohn Levon	fi
2149*6b72f1c0SJohn Levonfi
2150*6b72f1c0SJohn Levon
2151*6b72f1c0SJohn LevonEND_DATE=`date`
2152*6b72f1c0SJohn Levonecho "==== Nightly $maketype build completed: $END_DATE ====" | \
2153*6b72f1c0SJohn Levon    tee -a $LOGFILE >> $build_time_file
2154*6b72f1c0SJohn Levon
2155*6b72f1c0SJohn Levontypeset -i10 hours
2156*6b72f1c0SJohn Levontypeset -Z2 minutes
2157*6b72f1c0SJohn Levontypeset -Z2 seconds
2158*6b72f1c0SJohn Levon
2159*6b72f1c0SJohn Levonelapsed_time=$SECONDS
2160*6b72f1c0SJohn Levon((hours = elapsed_time / 3600 ))
2161*6b72f1c0SJohn Levon((minutes = elapsed_time / 60  % 60))
2162*6b72f1c0SJohn Levon((seconds = elapsed_time % 60))
2163*6b72f1c0SJohn Levon
2164*6b72f1c0SJohn Levonecho "\n==== Total build time ====" | \
2165*6b72f1c0SJohn Levon    tee -a $LOGFILE >> $build_time_file
2166*6b72f1c0SJohn Levonecho "\nreal    ${hours}:${minutes}:${seconds}" | \
2167*6b72f1c0SJohn Levon    tee -a $LOGFILE >> $build_time_file
2168*6b72f1c0SJohn Levon
2169*6b72f1c0SJohn Levonif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2170*6b72f1c0SJohn Levon	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
2171*6b72f1c0SJohn Levon
2172*6b72f1c0SJohn Levon	#
2173*6b72f1c0SJohn Levon	# Produce a master list of unreferenced files -- ideally, we'd
2174*6b72f1c0SJohn Levon	# generate the master just once after all of the nightlies
2175*6b72f1c0SJohn Levon	# have finished, but there's no simple way to know when that
2176*6b72f1c0SJohn Levon	# will be.  Instead, we assume that we're the last nightly to
2177*6b72f1c0SJohn Levon	# finish and merge all of the unref-${MACH}.out files in
2178*6b72f1c0SJohn Levon	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
2179*6b72f1c0SJohn Levon	# finish, then this file will be the authoritative master
2180*6b72f1c0SJohn Levon	# list.  Otherwise, another ${MACH}'s nightly will eventually
2181*6b72f1c0SJohn Levon	# overwrite ours with its own master, but in the meantime our
2182*6b72f1c0SJohn Levon	# temporary "master" will be no worse than any older master
2183*6b72f1c0SJohn Levon	# which was already on the parent.
2184*6b72f1c0SJohn Levon	#
2185*6b72f1c0SJohn Levon
2186*6b72f1c0SJohn Levon	set -- $PARENT_WS/usr/src/unref-*.out
2187*6b72f1c0SJohn Levon	cp "$1" ${TMPDIR}/unref.merge
2188*6b72f1c0SJohn Levon	shift
2189*6b72f1c0SJohn Levon
2190*6b72f1c0SJohn Levon	for unreffile; do
2191*6b72f1c0SJohn Levon		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
2192*6b72f1c0SJohn Levon		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
2193*6b72f1c0SJohn Levon	done
2194*6b72f1c0SJohn Levon
2195*6b72f1c0SJohn Levon	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
2196*6b72f1c0SJohn Levonfi
2197*6b72f1c0SJohn Levon
2198*6b72f1c0SJohn Levon#
2199*6b72f1c0SJohn Levon# All done save for the sweeping up.
2200*6b72f1c0SJohn Levon# (whichever exit we hit here will trigger the "cleanup" trap which
2201*6b72f1c0SJohn Levon# optionally sends mail on completion).
2202*6b72f1c0SJohn Levon#
2203*6b72f1c0SJohn Levonif [[ "$build_ok" == "y" ]]; then
2204*6b72f1c0SJohn Levon	if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
2205*6b72f1c0SJohn Levon		exit 0
2206*6b72f1c0SJohn Levon	fi
2207*6b72f1c0SJohn Levonfi
2208*6b72f1c0SJohn Levon
2209*6b72f1c0SJohn Levonexit 1
2210