xref: /titanic_51/usr/src/tools/scripts/nightly.sh (revision 9512fe850e98fdd448c638ca63fdd92a8a510255)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28# Based on the nightly script from the integration folks,
29# Mostly modified and owned by mike_s.
30# Changes also by kjc, dmk.
31#
32# BRINGOVER_WS may be specified in the env file.
33# The default is the old behavior of CLONE_WS
34#
35# -i on the command line, means fast options, so when it's on the
36# command line (only), lint and check builds are skipped no matter what
37# the setting of their individual flags are in NIGHTLY_OPTIONS.
38#
39# LINTDIRS can be set in the env file, format is a list of:
40#
41#	/dirname-to-run-lint-on flag
42#
43#	Where flag is:	y - enable lint noise diff output
44#			n - disable lint noise diff output
45#
46#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
47#
48# -A flag in NIGHTLY_OPTIONS checks ABI diffs in .so files
49# This option requires a couple of scripts.
50#
51# OPTHOME and TEAMWARE may be set in the environment to override /opt
52# and /opt/teamware defaults.
53#
54
55#
56# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
57# under certain circumstances, which can really screw things up; unset it.
58#
59unset CDPATH
60
61# function to do a DEBUG and non-DEBUG build. Needed because we might
62# need to do another for the source build, and since we only deliver DEBUG or
63# non-DEBUG packages.
64
65normal_build() {
66
67	# timestamp the start of a nightly build; the findunref tool uses it.
68	touch $SRC/.build.tstamp
69
70	# non-DEBUG build begins
71
72	if [ "$F_FLAG" = "n" ]; then
73		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
74		export RELEASE_BUILD ; RELEASE_BUILD=
75		unset EXTRA_OPTIONS
76		unset EXTRA_CFLAGS
77
78		build non-DEBUG -nd
79
80		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a "$p_FLAG" = "y" ]; then
81			copy_ihv_pkgs non-DEBUG -nd
82		fi
83	else
84		echo "\n==== No non-DEBUG build ====\n" >> $LOGFILE
85	fi
86
87	# non-DEBUG build ends
88
89	# DEBUG build begins
90
91	if [ "$D_FLAG" = "y" ]; then
92
93		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
94		unset RELEASE_BUILD
95		unset EXTRA_OPTIONS
96		unset EXTRA_CFLAGS
97
98		build DEBUG ""
99
100		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a "$p_FLAG" = "y" ]; then
101			copy_ihv_pkgs DEBUG ""
102		fi
103
104	else
105		echo "\n==== No DEBUG build ====\n" >> $LOGFILE
106	fi
107
108	# DEBUG build ends
109}
110
111filelist() {
112	if  [ $# -ne 2 ]; then
113		echo "usage: filelist DESTDIR PATTERN"
114		exit 1;
115	fi
116	DEST=$1
117	PATTERN=$2
118	cd ${DEST}
119
120	OBJFILES=${ORIG_SRC}/xmod/obj_files
121	if [ ! -f ${OBJFILES} ]; then
122		return;
123	fi
124	for i in `grep -v '^#' ${ORIG_SRC}/xmod/obj_files | \
125	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
126	do
127		# wildcard expansion
128		for j in $i
129		do
130			if [ -f "$j" ]; then
131				echo $j
132			fi
133			if [ -d "$j" ]; then
134				echo $j
135			fi
136		done
137	done | sort | uniq
138}
139
140# function to save off binaries after a full build for later
141# restoration
142save_binaries() {
143	# save off list of binaries
144	echo "\n==== Saving binaries from build at `date` ====\n" | \
145	    tee -a $mail_msg_file >> $LOGFILE
146	rm -f ${BINARCHIVE}
147	cd ${CODEMGR_WS}
148	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
149	filelist ${CODEMGR_WS} '^preserve:' | \
150	    cpio -ocB 2>/dev/null | compress \
151	    > ${BINARCHIVE}
152}
153
154# delete files
155hybridize_files() {
156	if  [ $# -ne 2 ]; then
157		echo "usage: hybridize_files DESTDIR MAKE_TARGET"
158		exit 1;
159	fi
160
161	DEST=$1
162	MAKETARG=$2
163
164	echo "\n==== Hybridizing files at `date` ====\n" | \
165	    tee -a $mail_msg_file >> $LOGFILE
166	for i in `filelist ${DEST} '^delete:'`
167	do
168		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
169		rm -rf "${i}"
170	done
171	for i in `filelist ${DEST} '^hybridize:' `
172	do
173		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
174		rm -f ${i}+
175		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
176		    < ${i} > ${i}+
177		mv ${i}+ ${i}
178	done
179}
180
181# restore binaries into the proper source tree.
182restore_binaries() {
183	if  [ $# -ne 2 ]; then
184		echo "usage: restore_binaries DESTDIR MAKE_TARGET"
185		exit 1;
186	fi
187
188	DEST=$1
189	MAKETARG=$2
190
191	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
192	    tee -a $mail_msg_file >> $LOGFILE
193	cd ${DEST}
194	zcat ${BINARCHIVE} | \
195	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
196}
197
198# rename files we save binaries of
199rename_files() {
200	if  [ $# -ne 2 ]; then
201		echo "usage: rename_files DESTDIR MAKE_TARGET"
202		exit 1;
203	fi
204
205	DEST=$1
206	MAKETARG=$2
207	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
208	    tee -a $mail_msg_file >> $LOGFILE
209	for i in `filelist ${DEST} '^rename:'`
210	do
211		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
212		rm -f ${i}.export
213		mv ${i} ${i}.export
214	done
215}
216
217# function to create the export/crypt source tree
218# usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET
219
220clone_source() {
221
222	if  [ $# -ne 3 ]; then
223		echo "usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET"
224		exit 1;
225	fi
226	WS=$1
227	DEST=$2
228	MAKETARG=$3
229
230	echo "\n==== Creating ${DEST} source from ${WS} (${MAKETARG}) ====\n" | \
231	    tee -a $mail_msg_file >> $LOGFILE
232
233	echo "cleaning out ${DEST}." >> $LOGFILE
234	rm -rf "${DEST}" >> $LOGFILE 2>&1
235
236	mkdir -p ${DEST}
237	cd ${WS}
238
239	echo "creating ${DEST}." >> $LOGFILE
240	find usr -name 's\.*' -a -type f -print | \
241	    sed -e 's,SCCS\/s.,,' | \
242	    grep -v '/\.del-*' | \
243	    cpio -pd ${DEST} >>$LOGFILE 2>&1
244
245	SRC=${DEST}/usr/src
246
247	cd $SRC
248	rm -f ${MAKETARG}.out
249	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
250	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
251	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
252	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
253	egrep ":" $SRC/${MAKETARG}.out | \
254		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
255		egrep -v "Ignoring unknown host" | \
256		egrep -v "warning" >> $mail_msg_file
257
258	echo "clearing state files." >> $LOGFILE
259	find . -name '.make*' -exec rm -f {} \;
260
261	cd ${DEST}
262	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
263		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
264		echo "\n==== xmod/cry_files that don't exist ====\n" | \
265		    tee -a $mail_msg_file >> $LOGFILE
266		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
267		for i in `cat ${CRYPT_FILES}`
268		do
269			# make sure the files exist
270			if [ -f "$i" ]; then
271				continue
272			fi
273			if [ -d "$i" ]; then
274				continue
275			fi
276			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
277		done
278		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
279		    cpio -ocB 2>/dev/null | \
280		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
281	fi
282
283	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
284		# rename first, since we might restore a file
285		# of the same name (mapfiles)
286		rename_files ${EXPORT_SRC} EXPORT_SRC
287		if [ "$SH_FLAG" = "y" ]; then
288			hybridize_files ${EXPORT_SRC} EXPORT_SRC
289		fi
290	fi
291
292	# save the cleartext
293	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
294	    tee -a $mail_msg_file >> $LOGFILE
295	cd ${DEST}
296	rm -f ${MAKETARG}.cpio.Z
297	find usr -depth -print | \
298	    grep -v usr/src/${MAKETARG}.out | \
299	    cpio -ocB 2>/dev/null | \
300	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
301	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
302		restore_binaries ${EXPORT_SRC} EXPORT_SRC
303	fi
304
305	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
306		restore_binaries ${CRYPT_SRC} CRYPT_SRC
307	fi
308
309}
310
311setroot() {
312	typeset suffix=$1
313
314	# Save the original $ROOT
315	ROOT_=$ROOT
316	ROOT=$ROOT$suffix
317
318	ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
319	ENVCPPFLAGS1="-I$ROOT/usr/include"
320}
321
322resetroot() {
323	ROOT=$ROOT_
324
325	ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
326	ENVCPPFLAGS1="-I$ROOT/usr/include"
327}
328
329# function to do the build.
330# usage: build LABEL SUFFIX
331
332build() {
333
334	if  [ $# -ne 2 ]; then
335		echo "usage: build LABEL SUFFIX"
336		exit 1;
337	fi
338
339	LABEL=$1
340	SUFFIX=$2
341	INSTALLOG=install${SUFFIX}-${MACH}
342	NOISE=noise${SUFFIX}-${MACH}
343	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
344	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
345	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
346		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
347	fi
348
349	#remove old logs
350	OLDINSTALLOG=install${SUFFIX}
351	OLDNOISE=noise${SUFFIX}
352	rm -f $SRC/${OLDINSTALLOG}.out
353	rm -f $SRC/${OLDNOISE}.ref
354	if [ -f $SRC/${OLDNOISE}.out ]; then
355		mv $SRC/${OLDNOISE}.out $SRC/${NOISE}.ref
356	fi
357
358	setroot $SUFFIX
359
360	this_build_ok=y
361	#
362	#	Build OS-Networking source
363	#
364	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
365		>> $LOGFILE
366
367	rm -f $SRC/${INSTALLOG}.out
368	cd $SRC
369	/bin/time $MAKE -e install 2>&1 | \
370	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
371
372	echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
373
374	egrep 'sccs(check|  get)' $SRC/${INSTALLOG}.out >> $mail_msg_file
375
376	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
377	egrep ":" $SRC/${INSTALLOG}.out |
378		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
379		egrep -v "Ignoring unknown host" | \
380		egrep -v "cc .* -o error " | \
381		egrep -v "warning" >> $mail_msg_file
382	if [ "$?" = "0" ]; then
383		build_ok=n
384		this_build_ok=n
385	fi
386	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
387		>> $mail_msg_file
388	if [ "$?" = "0" ]; then
389		build_ok=n
390		this_build_ok=n
391	fi
392
393	if [ "$W_FLAG" = "n" ]; then
394		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
395		egrep -i warning: $SRC/${INSTALLOG}.out \
396			| egrep -v '^tic:' \
397			| egrep -v "symbol \`timezone' has differing types:" \
398		        | egrep -v "parameter <PSTAMP> set to" \
399			| egrep -v "Ignoring unknown host" \
400			| egrep -v "redefining segment flags attribute for" \
401			>> $mail_msg_file
402	fi
403
404	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
405		>> $LOGFILE
406
407	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
408	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
409
410	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
411		rm -f $SRC/${NOISE}.ref
412		if [ -f $SRC/${NOISE}.out ]; then
413			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
414		fi
415		grep : $SRC/${INSTALLOG}.out \
416			| egrep -v '^/' \
417			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
418			| egrep -v '^tic:' \
419			| egrep -v '^mcs' \
420			| egrep -v '^LD_LIBRARY_PATH=' \
421			| egrep -v 'ar: creating' \
422			| egrep -v 'ar: writing' \
423			| egrep -v 'conflicts:' \
424			| egrep -v ':saved created' \
425			| egrep -v '^stty.*c:' \
426			| egrep -v '^mfgname.c:' \
427			| egrep -v '^uname-i.c:' \
428			| egrep -v '^volumes.c:' \
429			| egrep -v '^lint library construction:' \
430			| egrep -v 'tsort: INFORM:' \
431			| egrep -v 'stripalign:' \
432			| egrep -v 'chars, width' \
433			| egrep -v "symbol \`timezone' has differing types:" \
434			| egrep -v 'PSTAMP' \
435			| egrep -v '|%WHOANDWHERE%|' \
436			| egrep -v '^Manifying' \
437			| egrep -v 'Ignoring unknown host' \
438			| egrep -v 'Processing method:' \
439			| egrep -v '^Writing' \
440			| egrep -v 'spellin1:' \
441			| egrep -v '^adding:' \
442			| egrep -v "^echo 'msgid" \
443			| egrep -v '^echo ' \
444			| egrep -v '\.c:$' \
445			| egrep -v '^Adding file:' \
446			| egrep -v 'CLASSPATH=' \
447			| egrep -v '\/var\/mail\/:saved' \
448			| egrep -v -- '-DUTS_VERSION=' \
449			| egrep -v '^Running Mkbootstrap' \
450			| egrep -v '^Applet length read:' \
451			| egrep -v 'bytes written:' \
452			| egrep -v '^File:SolarisAuthApplet.bin' \
453			| egrep -v -i 'jibversion' \
454			| egrep -v '^Output size:' \
455			| egrep -v '^Solo size statistics:' \
456			| egrep -v '^Using ROM API Version' \
457			| egrep -v '^Zero Signature length:' \
458			| egrep -v '^Note \(probably harmless\):' \
459			| egrep -v '::' \
460			| egrep -v -- '-xcache' \
461			| egrep -v '^\+' \
462			| egrep -v '^cc1: note: -fwritable-strings' \
463			| egrep -v 'svc:/' \
464			| sort | uniq >$SRC/${NOISE}.out
465		if [ ! -f $SRC/${NOISE}.ref ]; then
466			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
467		fi
468		echo "\n==== Build noise differences ($LABEL) ====\n" \
469			>>$mail_msg_file
470		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
471	fi
472
473	#
474	#	Create cpio archives for preintegration testing (PIT)
475	#
476	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
477		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
478			>> $LOGFILE
479		makebfu_file="${TMPDIR}/makebfu"
480		rm -f ${makebfu_file}
481		makebfu 2>&1 | \
482			tee -a ${makebfu_file} >> $LOGFILE
483		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
484			>> $mail_msg_file
485		grep -v "^Creating .* archive:" ${makebfu_file} | \
486			grep -v "^Making" | \
487			grep -v "^$" | \
488			sort | uniq >> $mail_msg_file
489		rm -f ${makebfu_file}
490		# hack for test folks
491		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
492			X=/net/`uname -n`${CPIODIR}
493		else
494			X=${CPIODIR}
495		fi
496		echo "Archive_directory: ${X}" >${TMPDIR}/f
497		cp ${TMPDIR}/f ${CPIODIR}/../../.${MACH}_wgtrun
498		rm -f ${TMPDIR}/f
499
500	else
501		echo "\n==== Not creating $LABEL cpio archives ====\n" \
502			>> $LOGFILE
503	fi
504
505	#
506	#	Building Packages
507	#
508	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
509		echo "\n==== Creating $LABEL packages at `date` ====\n" \
510			>> $LOGFILE
511		rm -f $SRC/pkgdefs/${INSTALLOG}.out
512		echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
513		rm -rf $PKGARCHIVE
514		mkdir -p $PKGARCHIVE
515
516		#
517		# Optional build of sparc realmode on i386
518		#
519		if [ "$MACH" = "i386" ] && [ "${SPARC_RM_PKGARCHIVE}" ]; then
520			echo "Clearing out ${SPARC_RM_PKGARCHIVE} ..." \
521				>> $LOGFILE
522			rm -rf ${SPARC_RM_PKGARCHIVE}
523			mkdir -p ${SPARC_RM_PKGARCHIVE}
524		fi
525
526		cd $SRC/pkgdefs
527		$MAKE -e install 2>&1 | \
528			tee -a $SRC/pkgdefs/${INSTALLOG}.out >> $LOGFILE
529		echo "\n==== Package build errors ($LABEL) ====\n" \
530			>> $mail_msg_file
531		egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/${INSTALLOG}.out | \
532			grep ':' | \
533			grep -v PSTAMP | \
534			egrep -v "Ignoring unknown host" \
535			>> $mail_msg_file
536	else
537		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
538	fi
539
540	resetroot
541}
542
543dolint() {
544
545	#
546	# Arg. 2 is a flag to turn on/off the lint diff output
547	#
548	dl_usage="Usage: dolint /dir y|n"
549
550	if [ $# -ne 2 ]; then
551		echo $dl_usage
552		exit 1
553	fi
554
555	if [ ! -d "$1" ]; then
556		echo $dl_usage
557		exit 1
558	fi
559
560	if [ "$2" != "y" -a "$2" != "n" ]; then
561		echo $dl_usage
562		exit 1
563	fi
564
565	lintdir=$1
566	dodiff=$2
567	base=`basename $lintdir`
568	LINTOUT=$lintdir/lint-${MACH}.out
569	LINTNOISE=$lintdir/lint-noise-${MACH}
570
571	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
572	unset RELEASE_BUILD
573	unset EXTRA_OPTIONS
574	unset EXTRA_CFLAGS
575
576	#
577	#	'$MAKE lint' in $lintdir
578	#
579	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
580
581	# remove old lint.out
582	rm -f $lintdir/lint.out $lintdir/lint-noise.out
583	if [ -f $lintdir/lint-noise.ref ]; then
584		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
585	fi
586
587	rm -f $LINTOUT
588	cd $lintdir
589	#
590	# Remove all .ln files to ensure a full reference file
591	#
592	rm -f Nothing_to_remove \
593	    `find . -name SCCS -prune -o -type f -name '*.ln' -print `
594
595	/bin/time $MAKE -ek lint 2>&1 | \
596	    tee -a $LINTOUT >> $LOGFILE
597	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
598	grep "$MAKE:" $LINTOUT |
599		egrep -v "Ignoring unknown host" \
600		>> $mail_msg_file
601
602	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
603
604	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
605		>>$mail_msg_file
606	tail -3  $LINTOUT >>$mail_msg_file
607
608	rm -f ${LINTNOISE}.ref
609	if [ -f ${LINTNOISE}.out ]; then
610		mv ${LINTNOISE}.out ${LINTNOISE}.ref
611	fi
612        grep : $LINTOUT | \
613		egrep -v '^(real|user|sys)' |
614		egrep -v '(library construction)' | \
615		egrep -v ': global crosschecks' | \
616		egrep -v 'Ignoring unknown host' | \
617		egrep -v '\.c:$' | \
618		sort | uniq > ${LINTNOISE}.out
619	if [ ! -f ${LINTNOISE}.ref ]; then
620		cp ${LINTNOISE}.out ${LINTNOISE}.ref
621	fi
622	if [ "$dodiff" != "n" ]; then
623		echo "\n==== lint warnings $base ====\n" \
624			>>$mail_msg_file
625		# should be none, though there are a few that were filtered out
626		# above
627		egrep -i '(warning|lint):' ${LINTNOISE}.out \
628			| sort | uniq >> $mail_msg_file
629		echo "\n==== lint noise differences $base ====\n" \
630			>> $mail_msg_file
631		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
632			>> $mail_msg_file
633	fi
634}
635
636# Install proto area from IHV build
637
638copy_ihv_proto() {
639
640	echo "\n==== Installing IHV_ROOT ====\n" \
641		>> $LOGFILE
642	if [ -d "$IA32_IHV_ROOT" ]; then
643		if [ ! -d "$ROOT" ]; then
644			echo "mkdir -p $ROOT" >> $LOGFILE
645			mkdir -p $ROOT
646		fi
647		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
648		cd $IA32_IHV_ROOT
649		tar -cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
650	else
651		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
652	fi
653
654	if [ "$SINGLE_PROTO" = "no" ]; then
655		if [ ! -d "$ROOT-nd" ]; then
656			echo "mkdir -p $ROOT-nd" >> $LOGFILE
657			mkdir -p $ROOT-nd
658		fi
659		# If there's a non-debug version of the IHV proto area,
660		# copy it, but copy something if there's not.
661		if [ -d "$IA32_IHV_ROOT-nd" ]; then
662			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd \n" >> $LOGFILE
663			cd $IA32_IHV_ROOT-nd
664		elif [ -d "$IA32_IHV_ROOT" ]; then
665			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
666			cd $IA32_IHV_ROOT
667		else
668			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
669			return
670		fi
671		tar -cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
672	fi
673}
674
675# Install IHV packages in PKGARCHIVE
676
677copy_ihv_pkgs() {
678
679	if  [ $# -ne 2 ]; then
680		echo "usage: copy_ihv_pkgs LABEL SUFFIX"
681		exit 1;
682	fi
683
684	LABEL=$1
685	SUFFIX=$2
686	# always use non-DEBUG IHV packages
687	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
688	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
689
690	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
691		>> $LOGFILE
692	if [ -d "$IA32_IHV_PKGS" ]; then
693		cd $IA32_IHV_PKGS
694		tar -cf - * | \
695		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
696	else
697		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
698	fi
699
700	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
701		>> $LOGFILE
702	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
703		cd $IA32_IHV_BINARY_PKGS
704		tar -cf - * | \
705		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
706	else
707		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
708	fi
709}
710
711build_tools() {
712
713	if  [ $# -ne 1 ]; then
714		echo "usage: build_tools DESTROOT"
715		exit 1;
716	fi
717
718	DESTROOT=$1
719
720	INSTALLOG=install-${MACH}
721
722	echo "\n==== Building tools at `date` ====\n" \
723		>> $LOGFILE
724
725	rm -f ${TOOLS}/${INSTALLOG}.out
726	cd ${TOOLS}
727	/bin/time $MAKE ROOT=${DESTROOT} -e install 2>&1 | \
728	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
729
730	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
731
732	egrep ":" ${TOOLS}/${INSTALLOG}.out |
733		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
734		egrep -v "Ignoring unknown host" | \
735		egrep -v warning >> $mail_msg_file
736	if [ "$?" != "0" ]; then
737		STABS=${DESTROOT}/opt/onbld/bin/${MACH}/stabs
738		export STABS
739		CTFSTABS=${DESTROOT}/opt/onbld/bin/${MACH}/ctfstabs
740		export CTFSTABS
741		GENOFFSETS=${DESTROOT}/opt/onbld/bin/genoffsets
742		export GENOFFSETS
743
744		CTFCONVERT=${DESTROOT}/opt/onbld/bin/${MACH}/ctfconvert
745		export CTFCONVERT
746		CTFMERGE=${DESTROOT}/opt/onbld/bin/${MACH}/ctfmerge
747		export CTFMERGE
748
749		CTFCVTPTBL=${DESTROOT}/opt/onbld/bin/ctfcvtptbl
750		export CTFCVTPTBL
751		CTFFINDMOD=${DESTROOT}/opt/onbld/bin/ctffindmod
752		export CTFFINDMOD
753
754		if [ "$VERIFY_ELFSIGN" = "y" ]; then
755			ELFSIGN=${DESTROOT}/opt/onbld/bin/elfsigncmp
756		else
757			ELFSIGN=${DESTROOT}/opt/onbld/bin/${MACH}/elfsign
758		fi
759		export ELFSIGN
760
761		PATH="${DESTROOT}/opt/onbld/bin/${MACH}:${PATH}"
762		PATH="${DESTROOT}/opt/onbld/bin:${PATH}"
763		export PATH
764
765		echo "\n==== New environment settings. ====\n" >> $LOGFILE
766		echo "STABS=${STABS}" >> $LOGFILE
767		echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
768		echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
769		echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
770		echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
771		echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
772		echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
773		echo "PATH=${PATH}" >> $LOGFILE
774	fi
775}
776
777staffer() {
778	if [ $ISUSER -ne 0 ]; then
779		"$@"
780	else
781		arg="\"$1\""
782		shift
783		for i
784		do
785			arg="$arg \"$i\""
786		done
787		eval su $STAFFER -c \'$arg\'
788	fi
789}
790
791#
792# Verify that the closed tree is present if it needs to be.
793# Sets CLOSED_IS_PRESENT for future use.
794#
795check_closed_tree() {
796	if [ -z "$CLOSED_IS_PRESENT" ]; then
797		if [ -d $SRC/../closed ]; then
798			CLOSED_IS_PRESENT="yes"
799		else
800			CLOSED_IS_PRESENT="no"
801		fi
802		export CLOSED_IS_PRESENT
803	fi
804	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
805		#
806		# If it's an old (pre-split) tree or an empty
807		# workspace, don't complain.
808		#
809		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
810			echo "If the closed sources are not present," \
811			    "ON_CLOSED_BINS"
812			echo "must point to the closed binaries tree."
813			exit 1
814		fi
815	fi
816}
817
818obsolete_build() {
819    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
820}
821
822
823MACH=`uname -p`
824
825if [ "$OPTHOME" = "" ]; then
826	OPTHOME=/opt
827	export OPTHOME
828fi
829if [ "$TEAMWARE" = "" ]; then
830	TEAMWARE=$OPTHOME/teamware
831	export TEAMWARE
832fi
833
834USAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H ] <env_file>
835
836Where:
837	-i	Fast incremental options (no clobber, lint, check)
838	-n      Do not do a bringover
839	-V VERS set the build version string to VERS
840	-S	Build a variant of the source product
841		E - build exportable source
842		D - build domestic source (exportable + crypt)
843		H - build hybrid source (binaries + deleted source)
844
845	<env_file>  file in Bourne shell syntax that sets and exports
846	variables that configure the operation of this script and many of
847	the scripts this one calls. If <env_file> does not exist,
848	it will be looked for in $OPTHOME/onbld/env.
849
850non-DEBUG is the default build type. Build options can be set in the
851NIGHTLY_OPTIONS variable in the <env_file> as follows:
852
853	-A	check for ABI differences in .so files
854	-C	check for cstyle/hdrchk errors
855	-D	do a build with DEBUG on
856	-F	do _not_ do a non-DEBUG build
857	-G	gate keeper default group of options (-au)
858	-I	integration engineer default group of options (-ampu)
859	-M	do not run pmodes (safe file permission checker)
860	-N	do not run protocmp
861	-R	default group of options for building a release (-mp)
862	-U	update proto area in the parent
863	-V VERS set the build version string to VERS
864	-X	copy x86 IHV proto area
865	-a	create cpio archives
866	-f	find unreferenced files
867	-i	do an incremental build (no "make clobber")
868	-l	do "make lint" in $LINTDIRS (default: $SRC y)
869	-m	send mail to $MAILTO at end of build
870	-n      do not do a bringover
871	-o	build using root privileges to set OWNER/GROUP (old style)
872	-p	create packages
873	-r	check ELF runtime attributes in the proto area
874	-t	build and use the tools in $SRC/tools
875	-u	update proto_list_$MACH and friends in the parent workspace;
876		when used with -f, also build an unrefmaster.out in the parent
877	-w	report on differences between previous and current proto areas
878	-z	compress cpio archives with gzip
879	-W	Do not report warnings (freeware gate ONLY)
880	-S	Build a variant of the source product
881		E - build exportable source
882		D - build domestic source (exportable + crypt)
883		H - build hybrid source (binaries + deleted source)
884'
885#
886#	-x	less public handling of xmod source for the source product
887#
888#	A log file will be generated under the name $LOGFILE
889#	for partially completed build and log.`date '+%F'`
890#	in the same directory for fully completed builds.
891#
892
893# default values for low-level FLAGS; G I R are group FLAGS
894A_FLAG=n
895a_FLAG=n
896C_FLAG=n
897F_FLAG=n
898f_FLAG=n
899D_FLAG=n
900P_FLAG=n
901T_FLAG=n
902n_FLAG=n
903o_FLAG=n
904i_FLAG=n; i_CMD_LINE_FLAG=n
905l_FLAG=n
906m_FLAG=n
907p_FLAG=n
908r_FLAG=n
909t_FLAG=n
910u_FLAG=n
911U_FLAG=n
912V_FLAG=n
913M_FLAG=n
914N_FLAG=n
915z_FLAG=n
916w_FLAG=n
917W_FLAG=n
918SE_FLAG=n
919SD_FLAG=n
920SH_FLAG=n
921X_FLAG=n
922#
923XMOD_OPT=
924#
925build_ok=y
926#
927# examine arguments
928#
929
930OPTIND=1
931while getopts inV:S:t FLAG
932do
933	case $FLAG in
934	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
935		;;
936	  n )	n_FLAG=y
937		;;
938	  V )	V_FLAG=y
939		V_ARG="$OPTARG"
940		;;
941	  S )
942		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
943			echo "Can only build one source variant at a time."
944			exit 1
945		fi
946		if [ "${OPTARG}" = "E" ]; then
947			SE_FLAG=y
948		elif [ "${OPTARG}" = "D" ]; then
949			SD_FLAG=y
950		elif [ "${OPTARG}" = "H" ]; then
951			SH_FLAG=y
952		else
953			echo "$USAGE"
954			exit 1
955		fi
956		;;
957	  t )	t_FLAG=y
958		;;
959	 \? )	echo "$USAGE"
960		exit 1
961		;;
962	esac
963done
964
965# correct argument count after options
966shift `expr $OPTIND - 1`
967
968# test that the path to the environment-setting file was given
969if [ $# -ne 1 ]; then
970	echo "$USAGE"
971	exit 1
972fi
973
974# check if user is running nightly as root
975# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
976# when root invokes nightly.
977/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
978ISUSER=$?;	export ISUSER
979
980#
981# force locale to C
982LC_COLLATE=C;	export LC_COLLATE
983LC_CTYPE=C;	export LC_CTYPE
984LC_MESSAGES=C;	export LC_MESSAGES
985LC_MONETARY=C;	export LC_MONETARY
986LC_NUMERIC=C;	export LC_NUMERIC
987LC_TIME=C;	export LC_TIME
988
989# clear environment variables we know to be bad for the build
990unset LD_OPTIONS
991unset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
992unset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
993unset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
994unset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
995unset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
996unset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
997unset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
998unset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
999unset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
1000unset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
1001unset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
1002unset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
1003unset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
1004unset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
1005unset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
1006unset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
1007unset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
1008unset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
1009unset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
1010unset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
1011
1012unset CONFIG
1013unset GROUP
1014unset OWNER
1015unset REMOTE
1016unset ENV
1017unset ARCH
1018unset CLASSPATH
1019unset NAME
1020
1021#
1022#	Setup environmental variables
1023#
1024if [ -f $1 ]; then
1025	if [[ $1 = */* ]]; then
1026		. $1
1027	else
1028		. ./$1
1029	fi
1030else
1031	if [ -f $OPTHOME/onbld/env/$1 ]; then
1032		. $OPTHOME/onbld/env/$1
1033	else
1034		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
1035		exit 1
1036	fi
1037fi
1038
1039#
1040# place ourselves in a new task, respecting BUILD_PROJECT if set.
1041#
1042if [ -z "$BUILD_PROJECT" ]; then
1043	/usr/bin/newtask -c $$
1044else
1045	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
1046fi
1047
1048ps -o taskid= -p $$ | read build_taskid
1049ps -o project= -p $$ | read build_project
1050
1051#
1052# See if NIGHTLY_OPTIONS is set
1053#
1054if [ "$NIGHTLY_OPTIONS" = "" ]; then
1055	NIGHTLY_OPTIONS="-aBm"
1056fi
1057
1058#
1059# If BRINGOVER_WS was not specified, let it default to CLONE_WS
1060#
1061if [ "$BRINGOVER_WS" = "" ]; then
1062	BRINGOVER_WS=$CLONE_WS
1063fi
1064
1065#
1066# If BRINGOVER_FILES was not specified, default to usr
1067#
1068if [ "$BRINGOVER_FILES" = "" ]; then
1069	BRINGOVER_FILES="usr"
1070fi
1071
1072#
1073# If SINGLE_PROTO was not specified, default to a single proto area
1074#
1075if [ "$SINGLE_PROTO" = "" ]; then
1076	SINGLE_PROTO="yes"
1077fi
1078
1079#
1080# If the closed sources are not present, the closed binaries must be
1081# present for the build to succeed.  If there's no pointer to the
1082# closed binaries, flag that now, rather than forcing the user to wait
1083# a couple hours (or more) to find out.
1084#
1085orig_closed_is_present="$CLOSED_IS_PRESENT"
1086check_closed_tree
1087
1088#
1089# Note: changes to the option letters here should also be applied to the
1090#	bldenv script.  `d' is listed for backward compatibility.
1091#
1092NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
1093OPTIND=1
1094while getopts ABDFNMPTCGIRafinlmoptuUxdrtwzWS:X FLAG $NIGHTLY_OPTIONS
1095do
1096	case $FLAG in
1097	  A )	A_FLAG=y
1098		;;
1099	  B )	D_FLAG=y
1100		;; # old version of D
1101	  F )	F_FLAG=y
1102		;;
1103	  D )	D_FLAG=y
1104		;;
1105	  P )	P_FLAG=y
1106		;; # obsolete
1107	  T )	T_FLAG=y
1108		;; # obsolete
1109	  C )	C_FLAG=y
1110		;;
1111	  M )	M_FLAG=y
1112		;;
1113	  N )	N_FLAG=y
1114		;;
1115	  G )	a_FLAG=y
1116		u_FLAG=y
1117		;;
1118	  I )	a_FLAG=y
1119		m_FLAG=y
1120		p_FLAG=y
1121		u_FLAG=y
1122		;;
1123	  R )	m_FLAG=y
1124		p_FLAG=y
1125		;;
1126	  a )	a_FLAG=y
1127		;;
1128	  f )	f_FLAG=y
1129		;;
1130	  i )	i_FLAG=y
1131		;;
1132	  n )	n_FLAG=y
1133		;;
1134	  o )	o_FLAG=y
1135		;;
1136	  l )	l_FLAG=y
1137		;;
1138	  m )	m_FLAG=y
1139		;;
1140	  p )	p_FLAG=y
1141		;;
1142	  r )	r_FLAG=y
1143		;;
1144	  t )	t_FLAG=y
1145		;;
1146	  u )	u_FLAG=y
1147		;;
1148	  w )	w_FLAG=y
1149		;;
1150	  z )	z_FLAG=y
1151		;;
1152	  U )
1153		if [ -z "${PARENT_ROOT}" ]; then
1154			echo "PARENT_ROOT must be set if the U flag is" \
1155			    "present in NIGHTLY_OPTIONS."
1156			exit 1
1157		fi
1158		U_FLAG=y
1159		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
1160		;;
1161	  x )	XMOD_OPT="-x"
1162		;;
1163	  W )	W_FLAG=y
1164		;;
1165	  S )
1166		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1167			echo "Can only build one source variant at a time."
1168			exit 1
1169		fi
1170		if [ "${OPTARG}" = "E" ]; then
1171			SE_FLAG=y
1172		elif [ "${OPTARG}" = "D" ]; then
1173			SD_FLAG=y
1174		elif [ "${OPTARG}" = "H" ]; then
1175			SH_FLAG=y
1176		else
1177			echo "$USAGE"
1178			exit 1
1179		fi
1180		;;
1181	  X )	# now that we no longer need realmode builds, just
1182		# copy IHV packages.  only meaningful on x86.
1183		if [ "$MACH" = "i386" ]; then
1184			X_FLAG=y
1185		fi
1186		;;
1187	 \? )	echo "$USAGE"
1188		exit 1
1189		;;
1190	esac
1191done
1192
1193if [ $ISUSER -ne 0 ]; then
1194	if [ "$o_FLAG" = "y" ]; then
1195		echo "Old-style build requires root permission."
1196		exit 1
1197	fi
1198
1199	# Set default value for STAFFER, if needed.
1200	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
1201		STAFFER=`/usr/xpg4/bin/id -un`
1202		export STAFFER
1203	fi
1204fi
1205
1206if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
1207	MAILTO=$STAFFER
1208	export MAILTO
1209fi
1210
1211PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
1212PATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
1213PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
1214export PATH
1215
1216# roots of source trees, both relative to $SRC and absolute.
1217relsrcdirs="."
1218if [[ -d $SRC/../closed && "$CLOSED_IS_PRESENT" != no ]]; then
1219	relsrcdirs="$relsrcdirs ../closed"
1220fi
1221abssrcdirs=""
1222for d in $relsrcdirs; do
1223	abssrcdirs="$abssrcdirs $SRC/$d"
1224done
1225
1226unset CH
1227if [ "$o_FLAG" = "y" ]; then
1228# root invoked old-style build -- make sure it works as it always has
1229# by exporting 'CH'.  The current Makefile.master doesn't use this, but
1230# the old ones still do.
1231	PROTOCMPTERSE="protocmp.terse"
1232	CH=
1233	export CH
1234else
1235	PROTOCMPTERSE="protocmp.terse -gu"
1236fi
1237POUND_SIGN="#"
1238
1239# we export POUND_SIGN to speed up the build process -- prevents evaluation of
1240# the Makefile.master definitions.
1241export o_FLAG X_FLAG POUND_SIGN
1242
1243maketype="distributed"
1244MAKE=dmake
1245# get the dmake version string alone
1246DMAKE_VERSION=$( $MAKE -v )
1247DMAKE_VERSION=${DMAKE_VERSION#*: }
1248# focus in on just the dotted version number alone
1249DMAKE_MAJOR=$( echo $DMAKE_VERSION | \
1250	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
1251# extract the second (or final) integer
1252DMAKE_MINOR=${DMAKE_MAJOR#*.}
1253DMAKE_MINOR=${DMAKE_MINOR%%.*}
1254# extract the first integer
1255DMAKE_MAJOR=${DMAKE_MAJOR%%.*}
1256CHECK_DMAKE=${CHECK_DMAKE:-y}
1257# x86 was built on the 12th, sparc on the 13th.
1258if [ "$CHECK_DMAKE" = "y" -a \
1259     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
1260     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
1261     "$DMAKE_MAJOR" -lt 7 -o \
1262     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
1263	if [ -z "$DMAKE_VERSION" ]; then
1264		echo "$MAKE is missing."
1265		exit 1
1266	fi
1267	echo `whence $MAKE`" version is:"
1268	echo "  ${DMAKE_VERSION}"
1269	cat <<EOF
1270
1271This version may not be safe for use.  Either set TEAMWARE to a better
1272path or (if you really want to use this version of dmake anyway), add
1273the following to your environment to disable this check:
1274
1275  CHECK_DMAKE=n
1276EOF
1277	exit 1
1278fi
1279export PATH
1280export MAKE
1281
1282if [ "${SUNWSPRO}" != "" ]; then
1283	PATH="${SUNWSPRO}/bin:$PATH"
1284	export PATH
1285fi
1286
1287hostname=`uname -n`
1288if [ ! -f $HOME/.make.machines ]; then
1289	DMAKE_MAX_JOBS=4
1290else
1291	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
1292	    tail -1 | awk -F= '{print $ 2;}'`"
1293	if [ "$DMAKE_MAX_JOBS" = "" ]; then
1294		DMAKE_MAX_JOBS=4
1295	fi
1296fi
1297DMAKE_MODE=parallel;
1298export DMAKE_MODE
1299export DMAKE_MAX_JOBS
1300
1301if [ -z "${ROOT}" ]; then
1302	echo "ROOT must be set."
1303	exit 1
1304fi
1305
1306if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
1307        if [ -z "${EXPORT_SRC}" ]; then
1308		echo "EXPORT_SRC must be set for a source build."
1309		exit 1
1310	fi
1311        if [ -z "${CRYPT_SRC}" ]; then
1312		echo "CRYPT_SRC must be set for a source build."
1313		exit 1
1314	fi
1315fi
1316
1317if [ "$SH_FLAG" = "y" ]; then
1318        if [ -z "${EXPORT_SRC}" ]; then
1319		echo "EXPORT_SRC must be set for a source build."
1320		exit 1
1321	fi
1322fi
1323
1324#
1325# if -V flag was given, reset VERSION to V_ARG
1326#
1327if [ "$V_FLAG" = "y" ]; then
1328	VERSION=$V_ARG
1329fi
1330
1331#
1332# Check for IHV root for copying ihv proto area
1333#
1334if [ "$X_FLAG" = "y" ]; then
1335        if [ "$IA32_IHV_ROOT" = "" ]; then
1336		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
1337		args_ok=n
1338        fi
1339        if [ ! -d "$IA32_IHV_ROOT" ]; then
1340                echo "$IA32_IHV_ROOT: not found"
1341                args_ok=n
1342        fi
1343        if [ "$IA32_IHV_WS" = "" ]; then
1344		echo "IA32_IHV_WS: must be set for copying ihv proto"
1345		args_ok=n
1346        fi
1347        if [ ! -d "$IA32_IHV_WS" ]; then
1348                echo "$IA32_IHV_WS: not found"
1349                args_ok=n
1350        fi
1351fi
1352
1353# Append source version
1354if [ "$SE_FLAG" = "y" ]; then
1355	VERSION="${VERSION}:EXPORT"
1356fi
1357
1358if [ "$SD_FLAG" = "y" ]; then
1359	VERSION="${VERSION}:DOMESTIC"
1360fi
1361
1362if [ "$SH_FLAG" = "y" ]; then
1363	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
1364fi
1365
1366TMPDIR="/tmp/nightly.tmpdir.$$"
1367export TMPDIR
1368rm -rf ${TMPDIR}
1369mkdir -p $TMPDIR || exit 1
1370
1371#
1372# Keep elfsign's use of pkcs11_softtoken from looking in the user home
1373# directory, which doesn't always work.   Needed until all build machines
1374# have the fix for 6271754
1375#
1376SOFTTOKEN_DIR=$TMPDIR
1377export SOFTTOKEN_DIR
1378
1379TOOLS=${SRC}/tools
1380TOOLS_PROTO=${TOOLS}/proto
1381
1382unset   CFLAGS LD_LIBRARY_PATH LDFLAGS
1383
1384# create directories that are automatically removed if the nightly script
1385# fails to start correctly
1386newdir() {
1387	dir=$1
1388	toadd=
1389	while [ ! -d $dir ]; do
1390		toadd="$dir $toadd"
1391		dir=`dirname $dir`
1392	done
1393	torm=
1394	newlist=
1395	for dir in $toadd; do
1396		if staffer mkdir $dir; then
1397			newlist="$ISUSER $dir $newlist"
1398			torm="$dir $torm"
1399		else
1400			[ -z "$torm" ] || staffer rmdir $torm
1401			return 1
1402		fi
1403	done
1404	newdirlist="$newlist $newdirlist"
1405	return 0
1406}
1407newdirlist=
1408
1409[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
1410
1411# since this script assumes the build is from full source, it nullifies
1412# variables likely to have been set by a "ws" script; nullification
1413# confines the search space for headers and libraries to the proto area
1414# built from this immediate source.
1415ENVLDLIBS1=
1416ENVLDLIBS2=
1417ENVLDLIBS3=
1418ENVCPPFLAGS1=
1419ENVCPPFLAGS2=
1420ENVCPPFLAGS3=
1421ENVCPPFLAGS4=
1422PARENT_ROOT=
1423
1424export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1425	PARENT_ROOT
1426
1427ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
1428ENVCPPFLAGS1="-I$ROOT/usr/include"
1429
1430export ENVLDLIBS1 ENVLDLIBS2
1431
1432CPIODIR_ORIG=$CPIODIR
1433PKGARCHIVE_ORIG=$PKGARCHIVE
1434IA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1435if [ "$SPARC_RM_PKGARCHIVE" ]; then
1436	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1437fi
1438
1439#
1440# Juggle the logs and optionally send mail on completion.
1441#
1442
1443logshuffle() {
1444    	LLOG="$ATLOG/log.`date '+%F'`"
1445	rm -rf $ATLOG/log.??`date '+%d'`
1446	rm -rf $ATLOG/log.????-??-`date '+%d'`
1447	if [ -f $LLOG -o -d $LLOG ]; then
1448	    	LLOG=$LLOG.$$
1449	fi
1450	mkdir $LLOG
1451	export LLOG
1452
1453	if [ "$build_ok" = "y" ]; then
1454		mv $ATLOG/proto_list_${MACH} $LLOG
1455
1456		if [ -f $TMPDIR/wsdiff.results ]; then
1457		    mv $TMPDIR/wsdiff.results $LLOG
1458		fi
1459
1460		if [ -f $TMPDIR/wsdiff-nd.results ]; then
1461		    mv $TMPDIR/wsdiff-nd.results $LLOG
1462		fi
1463	fi
1464
1465	#
1466	# Now that we're about to send mail, it's time to check the noise
1467	# file.  In the event that an error occurs beyond this point, it will
1468	# be recorded in the nightly.log file, but nowhere else.  This would
1469	# include only errors that cause the copying of the noise log to fail
1470	# or the mail itself not to be sent.
1471	#
1472
1473	exec >>$LOGFILE 2>&1
1474	if [ -s $build_noise_file ]; then
1475	    	echo "\n==== Nightly build noise ====\n" |
1476		    tee -a $LOGFILE >>$mail_msg_file
1477		cat $build_noise_file >>$LOGFILE
1478		cat $build_noise_file >>$mail_msg_file
1479		echo | tee -a $LOGFILE >>$mail_msg_file
1480	fi
1481	rm -f $build_noise_file
1482
1483	case "$build_ok" in
1484		y)
1485			state=Completed
1486			;;
1487		i)
1488			state=Interrupted
1489			;;
1490		*)
1491	    		state=Failed
1492			;;
1493	esac
1494	NIGHTLY_STATUS=$state
1495	export NIGHTLY_STATUS
1496
1497	if [ -n "$POST_NIGHTLY" ]; then
1498		echo "\n==== Running POST_NIGHTLY command:" \
1499		    "$POST_NIGHTLY ====\n" | tee -a $mail_msg_file >> $LOGFILE
1500		$POST_NIGHTLY $state 2>&1 | tee -a $mail_msg_file >> $LOGFILE
1501	fi
1502
1503	cat $build_time_file $mail_msg_file > ${LLOG}/mail_msg
1504	if [ "$m_FLAG" = "y" ]; then
1505	    	cat $build_time_file $mail_msg_file |
1506		    /usr/bin/mailx -s \
1507	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
1508			${MAILTO}
1509	fi
1510
1511	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
1512	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
1513		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
1514	fi
1515
1516	mv $LOGFILE $LLOG
1517}
1518
1519#
1520#	Remove the locks and temporary files on any exit
1521#
1522cleanup() {
1523    	logshuffle
1524
1525	[ -z "$lockfile" ] || staffer rm -f $lockfile
1526	[ -z "$atloglockfile" ] || rm -f $atloglockfile
1527	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
1528	[ -z "$Ulockfile" ] || rm -f $Ulockfile
1529
1530	set -- $newdirlist
1531	while [ $# -gt 0 ]; do
1532		ISUSER=$1 staffer rmdir $2
1533		shift; shift
1534	done
1535	rm -rf $TMPDIR
1536}
1537
1538cleanup_signal() {
1539    	build_ok=i
1540	# this will trigger cleanup(), above.
1541	exit 1
1542}
1543
1544trap cleanup 0
1545trap cleanup_signal 1 2 3 15
1546
1547#
1548# Generic lock file processing -- make sure that the lock file doesn't
1549# exist.  If it does, it should name the build host and PID.  If it
1550# doesn't, then make sure we can create it.  Clean up locks that are
1551# known to be stale (assumes host name is unique among build systems
1552# for the workspace).
1553create_lock() {
1554	lockf=$1
1555	lockvar=$2
1556	if [ -f $lockf ]; then
1557		basews=`basename $CODEMGR_WS`
1558		if read host user pid < $lockf; then
1559			if [ "$host" != "$hostname" ]; then
1560				echo "$MACH build of $basews apparently" \
1561				    "already started by $user on $host as $pid."
1562			elif kill -s 0 $pid 2>/dev/null; then
1563				echo "$MACH build of $basews already started" \
1564				    "by $user as $pid."
1565			else
1566				# stale lock; clear it out and continue
1567				rm -f $lockf
1568			fi
1569		else
1570			echo "$MACH build of $basews already running."
1571		fi
1572	fi
1573	if [ -f $lockf ]; then
1574		echo "Lock file is $lockf."
1575		exit 1
1576	fi
1577	ldir=`dirname $lockf`
1578	[ -d $ldir ] || newdir $ldir || exit 1
1579	eval $lockvar=$lockf
1580	staffer sh -c "echo $hostname $STAFFER $$ > $lockf" || exit 1
1581}
1582
1583# Ensure no other instance of this script is running on this host.
1584# LOCKNAME can be set in <env_file>, and is by default, but is not
1585# required due to the use of $ATLOG below.
1586if [ -n "$LOCKNAME" ]; then
1587	create_lock /tmp/$LOCKNAME "lockfile"
1588fi
1589#
1590# Create from one, two, or three other locks:
1591#	$ATLOG/nightly.lock
1592#		- protects against multiple builds in same workspace
1593#	$PARENT_WS/usr/src/nightly.$MACH.lock
1594#		- protects against multiple 'u' copy-backs
1595#	$NIGHTLY_PARENT_ROOT/nightly.lock
1596#		- protects against multiple 'U' copy-backs
1597#
1598# Overriding ISUSER to 1 causes the lock to be created as root if the
1599# script is run as root.  The default is to create it as $STAFFER.
1600ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1601if [ "$u_FLAG" = "y" ]; then
1602	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1603fi
1604if [ "$U_FLAG" = "y" ]; then
1605	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1606	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1607fi
1608
1609# Locks have been taken, so we're doing a build and we're committed to
1610# the directories we may have created so far.
1611newdirlist=
1612
1613#
1614# Create mail_msg_file
1615#
1616mail_msg_file="${TMPDIR}/mail_msg"
1617touch $mail_msg_file
1618build_time_file="${TMPDIR}/build_time"
1619#
1620#	Move old LOGFILE aside
1621#	ATLOG directory already made by 'create_lock' above
1622#
1623if [ -f $LOGFILE ]; then
1624	mv -f $LOGFILE ${LOGFILE}-
1625fi
1626#
1627#	Build OsNet source
1628#
1629START_DATE=`date`
1630SECONDS=0
1631echo "\n==== Nightly $maketype build started:   $START_DATE ====" \
1632    | tee -a $LOGFILE > $build_time_file
1633
1634# make sure we log only to the nightly build file
1635build_noise_file="${TMPDIR}/build_noise"
1636exec </dev/null >$build_noise_file 2>&1
1637
1638echo "\n==== list of environment variables ====\n" >> $LOGFILE
1639env >> $LOGFILE
1640
1641echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1642
1643if [ "$P_FLAG" = "y" ]; then
1644	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1645fi
1646
1647if [ "$T_FLAG" = "y" ]; then
1648	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1649fi
1650
1651if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1652	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
1653		echo "WARNING: the -S flags do not support incremental" \
1654		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
1655		i_FLAG=n
1656		i_CMD_LINE_FLAG=n
1657	fi
1658	if [ "$N_FLAG" = "n" ]; then
1659		echo "WARNING: the -S flags do not support protocmp;" \
1660		    "protocmp disabled\n" | \
1661		    tee -a $mail_msg_file >> $LOGFILE
1662		N_FLAG=y
1663	fi
1664	if [ "$l_FLAG" = "y" ]; then
1665		echo "WARNING: the -S flags do not support lint;" \
1666		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1667		l_FLAG=n
1668	fi
1669	if [ "$C_FLAG" = "y" ]; then
1670		echo "WARNING: the -S flags do not support cstyle;" \
1671		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1672		C_FLAG=n
1673	fi
1674else
1675	if [ "$N_FLAG" = "y" ]; then
1676		if [ "$p_FLAG" = "y" ]; then
1677			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1678WARNING: the p option (create packages) is set, but so is the N option (do
1679         not run protocmp); this is dangerous; you should unset the N option
1680EOF
1681		else
1682			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1683Warning: the N option (do not run protocmp) is set; it probably shouldn't be
1684EOF
1685		fi
1686		echo "" | tee -a $mail_msg_file >> $LOGFILE
1687	fi
1688fi
1689
1690if [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
1691	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
1692	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
1693fi
1694
1695if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1696	echo "WARNING: DEBUG build not requested, but lint will be with" \
1697	    "DEBUG enabled.\n" \
1698	    | tee -a $mail_msg_file >> $LOGFILE
1699fi
1700
1701if [ "$f_FLAG" = "y" ]; then
1702	if [ "$i_FLAG" = "y" ]; then
1703		echo "WARNING: the -f flag cannot be used during incremental" \
1704		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1705		f_FLAG=n
1706	fi
1707	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
1708		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
1709		    tee -a $mail_msg_file >> $LOGFILE
1710		f_FLAG=n
1711	fi
1712fi
1713
1714if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
1715	echo "WARNING: -w specified, but no pre-existing proto area found;" \
1716	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
1717	w_FLAG=n
1718fi
1719
1720if [ "$t_FLAG" = "n" ]; then
1721	#
1722	# We're not doing a tools build, so make sure elfsign(1) is
1723	# new enough to safely sign non-crypto binaries.  We test
1724	# debugging output from elfsign to detect the old version.
1725	#
1726	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
1727	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
1728	    | egrep algorithmOID`
1729	if [ -z "$newelfsigntest" ]; then
1730		echo "WARNING: /usr/bin/elfsign out of date;" \
1731		    "will only sign crypto modules\n" | \
1732		    tee -a $mail_msg_file >> $LOGFILE
1733		export ELFSIGN_OBJECT=true
1734	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
1735		echo "WARNING: VERIFY_ELFSIGN=y requires" \
1736		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
1737		    tee -a $mail_msg_file >> $LOGFILE
1738	fi
1739fi
1740
1741echo "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
1742
1743# System
1744whence uname | tee -a $mail_msg_file >> $LOGFILE
1745uname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
1746echo | tee -a $mail_msg_file >> $LOGFILE
1747
1748# nightly (will fail in year 2100 due to SCCS flaw)
1749echo "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
1750echo "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
1751
1752# make
1753whence $MAKE | tee -a $mail_msg_file >> $LOGFILE
1754$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
1755echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1756    tee -a $mail_msg_file >> $LOGFILE
1757
1758#
1759# Report the compiler versions.
1760#
1761if [ -f $SRC/Makefile ]; then
1762	srcroot=$SRC
1763elif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
1764	srcroot=$BRINGOVER_WS/usr/src
1765else
1766	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
1767	    tee -a $mail_msg_file >> $LOGFILE
1768	exit 1
1769fi
1770
1771( cd $srcroot
1772  for target in cc-version cc64-version java-version; do
1773	echo
1774	#
1775	# Put statefile somewhere we know we can write to rather than trip
1776	# over a read-only $srcroot.
1777	#
1778	rm -f $TMPDIR/make-state
1779	export SRC=$srcroot
1780	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
1781		continue
1782	fi
1783	touch $TMPDIR/nocompiler
1784  done
1785  echo
1786) | tee -a $mail_msg_file >> $LOGFILE
1787
1788if [ -f $TMPDIR/nocompiler ]; then
1789	rm -f $TMPDIR/nocompiler
1790	build_ok=n
1791	echo "Aborting due to missing compiler." |
1792		tee -a $mail_msg_file >> $LOGFILE
1793	exit 1
1794fi
1795
1796# as
1797whence as | tee -a $mail_msg_file >> $LOGFILE
1798as -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
1799echo | tee -a $mail_msg_file >> $LOGFILE
1800
1801# Check that we're running a capable link-editor
1802whence ld | tee -a $mail_msg_file >> $LOGFILE
1803LDVER=`ld -V 2>&1`
1804echo $LDVER | tee -a $mail_msg_file >> $LOGFILE
1805LDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
1806if [ `expr $LDVER \< 422` -eq 1 ]; then
1807	echo "The link-editor needs to be at version 422 or higher to build" | \
1808	    tee -a $mail_msg_file >> $LOGFILE
1809	echo "the latest stuff, hope your build works." | \
1810	    tee -a $mail_msg_file >> $LOGFILE
1811fi
1812
1813echo "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1814    tee -a $mail_msg_file >> $LOGFILE
1815
1816echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1817echo $VERSION | tee -a $mail_msg_file >> $LOGFILE
1818
1819# Save the current proto area if we're comparing against the last build
1820if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
1821    if [ -d "$ROOT.prev" ]; then
1822	rm -rf $ROOT.prev
1823    fi
1824    mv $ROOT $ROOT.prev
1825fi
1826
1827# Same for non-DEBUG proto area
1828if [ "$w_FLAG" = "y" -a "$SINGLE_PROTO" = "no" -a -d "$ROOT-nd" ]; then
1829	if [ -d "$ROOT-nd.prev" ]; then
1830		rm -rf $ROOT-nd.prev
1831	fi
1832	mv $ROOT-nd $ROOT-nd.prev
1833fi
1834
1835#
1836#	Decide whether to clobber
1837#
1838if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
1839	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
1840
1841	cd $SRC
1842	# remove old clobber file
1843	rm -f $SRC/clobber.out
1844	rm -f $SRC/clobber-${MACH}.out
1845
1846	# Remove all .make.state* files, just in case we are restarting
1847	# the build after having interrupted a previous 'make clobber'.
1848	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
1849	    -o -name '.make.*' -print | xargs rm -f
1850
1851	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
1852	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
1853	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1854		egrep -v "Ignoring unknown host" \
1855		>> $mail_msg_file
1856
1857	if [ "$t_FLAG" = "y" ]; then
1858		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
1859		cd ${TOOLS}
1860		rm -f ${TOOLS}/clobber-${MACH}.out
1861		$MAKE -ek clobber 2>&1 | \
1862			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
1863		echo "\n==== Make tools clobber ERRORS ====\n" \
1864			>> $mail_msg_file
1865		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1866			>> $mail_msg_file
1867		rm -rf ${TOOLS_PROTO}
1868		mkdir -p ${TOOLS_PROTO}
1869	fi
1870
1871	rm -rf $ROOT $ROOT-nd
1872
1873	# Get back to a clean workspace as much as possible to catch
1874	# problems that only occur on fresh workspaces.
1875	# Remove all .make.state* files, libraries, and .o's that may
1876	# have been omitted from clobber.  A couple of libraries are
1877	# under SCCS, so leave them alone.
1878	# We should probably blow away temporary directories too.
1879	cd $SRC
1880	find $relsrcdirs \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
1881	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1882	       -name '*.o' \) -print | \
1883	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
1884else
1885	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
1886fi
1887
1888#
1889#	Decide whether to bringover to the codemgr workspace
1890#
1891if [ "$n_FLAG" = "n" ]; then
1892	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
1893	# sleep on the parent workspace's lock
1894	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
1895	do
1896		sleep 120
1897	done
1898
1899	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
1900
1901	(staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
1902	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
1903		touch $TMPDIR/bringover_failed
1904
1905         staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
1906
1907	 if [ -s $TMPDIR/bringovercheck.out ]; then
1908		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
1909		cat $TMPDIR/bringovercheck.out
1910	 fi
1911
1912	) | tee -a  $mail_msg_file >> $LOGFILE
1913
1914	if [ -f $TMPDIR/bringover_failed ]; then
1915		rm -f $TMPDIR/bringover_failed
1916		build_ok=n
1917		echo "trouble with bringover, quitting at `date`." |
1918			tee -a $mail_msg_file >> $LOGFILE
1919		exit 1
1920	fi
1921
1922	#
1923	# Possible transition from pre-split workspace to split
1924	# workspace.  See if the bringover changed anything.
1925	#
1926	CLOSED_IS_PRESENT="$orig_closed_is_present"
1927	check_closed_tree
1928else
1929	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
1930fi
1931
1932#
1933# Build tools if requested
1934#
1935if [ "$t_FLAG" = "y" ]; then
1936	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
1937	export RELEASE_BUILD ; RELEASE_BUILD=
1938	unset EXTRA_OPTIONS
1939	unset EXTRA_CFLAGS
1940
1941	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
1942	build_tools ${TOOLS_PROTO}
1943fi
1944
1945#
1946# copy ihv proto area in addition to the build itself
1947#
1948if [ "$X_FLAG" = "y" ]; then
1949	copy_ihv_proto
1950fi
1951
1952if [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
1953	echo "\n==== NOT Building base OS-Net source ====\n" | \
1954	    tee -a $LOGFILE >> $mail_msg_file
1955else
1956	normal_build
1957fi
1958
1959ORIG_SRC=$SRC
1960BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
1961
1962if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1963	save_binaries
1964
1965	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
1966	SCCSHELPER=${TMPDIR}/sccs-helper
1967	rm -f ${SCCSHELPER}
1968cat >${SCCSHELPER} <<EOF
1969#!/bin/ksh
1970cd \$1
1971cd ..
1972sccs get SCCS >/dev/null 2>&1
1973EOF
1974	cd $SRC
1975	chmod +x ${SCCSHELPER}
1976	find $relsrcdirs -name SCCS | xargs -L 1 ${SCCSHELPER}
1977	rm -f ${SCCSHELPER}
1978fi
1979
1980if [ "$SD_FLAG" = "y" ]; then
1981	clone_source ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
1982fi
1983
1984# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
1985# $SRC pointing to the export_source usr/src.
1986if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1987	clone_source ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
1988fi
1989
1990if [ "$SD_FLAG" = "y" ]; then
1991	# drop the crypt files in place.
1992	cd ${EXPORT_SRC}
1993	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
1994	    >> ${LOGFILE}
1995	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
1996	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
1997	if [ "$?" = "0" ]; then
1998		echo "\n==== DOMESTIC extraction succeeded ====\n" \
1999		    >> $mail_msg_file
2000	else
2001		echo "\n==== DOMESTIC extraction failed ====\n" \
2002		    >> $mail_msg_file
2003	fi
2004
2005fi
2006
2007if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2008	# remove proto area here, since we don't clobber
2009	rm -rf "$ROOT" "$ROOT-nd"
2010	if [ "$t_FLAG" = "y" ]; then
2011		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
2012		export RELEASE_BUILD ; RELEASE_BUILD=
2013		unset EXTRA_OPTIONS
2014		unset EXTRA_CFLAGS
2015		ORIG_TOOLS=$TOOLS
2016		TOOLS=${EXPORT_SRC}/usr/src/tools
2017		build_tools ${EXPORT_SRC}/usr/src/tools/proto
2018		TOOLS=$ORIG_TOOLS
2019	fi
2020
2021	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
2022	normal_build
2023fi
2024
2025if [ "$build_ok" = "y" ]; then
2026	echo "\n==== Creating protolist system file at `date` ====" \
2027		>> $LOGFILE
2028	protolist $ROOT > $ATLOG/proto_list_${MACH}
2029	echo "==== protolist system file created at `date` ====\n" \
2030		>> $LOGFILE
2031
2032	if [ "$N_FLAG" != "y" ]; then
2033		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
2034
2035		# If there is a reference proto list, compare the build's proto
2036		# list with the reference to see changes in proto areas.
2037		# Use the current exception list.
2038		exc=etc/exception_list_$MACH
2039		if [ -f $SRC/pkgdefs/$exc ]; then
2040			ELIST="-e $SRC/pkgdefs/$exc"
2041		fi
2042		if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
2043			ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
2044		fi
2045
2046		if [ -f "$REF_PROTO_LIST" ]; then
2047			$PROTOCMPTERSE \
2048			  "Files in yesterday's proto area, but not today's:" \
2049			  "Files in today's proto area, but not yesterday's:" \
2050			  "Files that changed between yesterday and today:" \
2051			  ${ELIST} \
2052			  -d $REF_PROTO_LIST \
2053			  $ATLOG/proto_list_${MACH} \
2054				>> $mail_msg_file
2055		fi
2056		# Compare the build's proto list with current package
2057		# definitions to audit the quality of package definitions
2058		# and makefile install targets. Use the current exception list.
2059		PKGDEFS_LIST=""
2060		for d in $abssrcdirs; do
2061			if [ -d $d/pkgdefs ]; then
2062				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2063			fi
2064		done
2065		if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
2066			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
2067		fi
2068
2069		$PROTOCMPTERSE \
2070		    "Files missing from the proto area:" \
2071		    "Files missing from packages:" \
2072		    "Inconsistencies between pkgdefs and proto area:" \
2073		    ${ELIST} \
2074		    ${PKGDEFS_LIST} \
2075		    $ATLOG/proto_list_${MACH} \
2076		    >> $mail_msg_file
2077	fi
2078fi
2079
2080if [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
2081	staffer cp $ATLOG/proto_list_${MACH} \
2082		$PARENT_WS/usr/src/proto_list_${MACH}
2083fi
2084
2085# Update parent proto area if necessary. This is done now
2086# so that the proto area has either DEBUG or non-DEBUG kernels.
2087# Note that this clears out the lock file, so we can dispense with
2088# the variable now.
2089if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
2090	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
2091	    tee -a $LOGFILE >> $mail_msg_file
2092	# The rm -rf command below produces predictable errors if
2093	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
2094	# and that directory is accessed via NFS.  This is because
2095	# deleted-but-still-open files don't actually disappear as
2096	# expected, but rather turn into .nfsXXXX junk files, leaving
2097	# the directory non-empty.  Since this is a not-unusual usage
2098	# pattern, and we still want to catch other errors here, we
2099	# take the unusal step of moving aside 'nightly' from that
2100	# directory (if we're using it).
2101	mypath=${0##*/root_$MACH/}
2102	if [ "$mypath" = $0 ]; then
2103		mypath=opt/onbld/bin/${0##*/}
2104	fi
2105	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
2106		mv -f $0 $PARENT_WS/proto/root_$MACH
2107	fi
2108	rm -rf $PARENT_WS/proto/root_$MACH/*
2109	unset Ulockfile
2110	mkdir -p $NIGHTLY_PARENT_ROOT
2111	cd $ROOT
2112	( tar cf - . | ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
2113		tee -a $mail_msg_file >> $LOGFILE
2114	if [ "$SINGLE_PROTO" = "no" ]; then
2115		mkdir -p $NIGHTLY_PARENT_ROOT-nd
2116		cd $ROOT-nd
2117		( tar cf - . |
2118			( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
2119			tee -a $mail_msg_file >> $LOGFILE
2120	fi
2121fi
2122
2123#
2124# do shared library interface verification
2125#
2126
2127if [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
2128	echo "\n==== Check versioning and ABI information ====\n"  | \
2129	    tee -a $LOGFILE >> $mail_msg_file
2130
2131	rm -rf $SRC/interfaces.ref
2132	if [ -d $SRC/interfaces.out ]; then
2133		mv $SRC/interfaces.out $SRC/interfaces.ref
2134	fi
2135	rm -rf $SRC/interfaces.out
2136	mkdir -p $SRC/interfaces.out
2137
2138	intf_check -V -m -o -b $SRC/tools/abi/etc \
2139		-d $SRC/interfaces.out $ROOT 2>&1 | sort \
2140		> $SRC/interfaces.out/log
2141
2142	# report any ERROR found in log file
2143	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
2144		tee -a $LOGFILE >> $mail_msg_file
2145
2146	if [ ! -d $SRC/interfaces.ref ] ; then
2147		mkdir -p $SRC/interfaces.ref
2148		if [ -d  $SRC/interfaces.out ]; then
2149			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
2150		fi
2151	fi
2152
2153	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
2154	    tee -a $LOGFILE >> $mail_msg_file
2155
2156	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
2157	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
2158
2159	# Report any differences in WARNING messages between last
2160	# and current build.
2161	if [ "$out_vers" = "$ref_vers" ]; then
2162		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
2163		    fgrep 'WARNING' | sed 's/WARNING: //' | \
2164		    tee -a $LOGFILE >> $mail_msg_file
2165	fi
2166fi
2167
2168if [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
2169	echo "\n==== Check ELF runtime attributes ====\n" | \
2170	    tee -a $LOGFILE >> $mail_msg_file
2171
2172	LDDUSAGE="^ldd: does not support -e"
2173	LDDWRONG="wrong class"
2174	CRLERROR="^crle:"
2175	CRLECONF="^crle: configuration file:"
2176
2177	rm -f $SRC/runtime.ref
2178	if [ -f $SRC/runtime.out ]; then
2179		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2180			$SRC/runtime.out > $SRC/runtime.ref
2181	fi
2182
2183	# If we're doing a debug build the proto area will be left with
2184	# debuggable objects, thus don't assert -s.
2185	if [ "$D_FLAG" = "y" ]; then
2186		rtime_sflag=""
2187	else
2188		rtime_sflag="-s"
2189	fi
2190	check_rtime -d $ROOT -i -m -o $rtime_sflag $ROOT 2>&1 | \
2191	    egrep -v ": unreferenced object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
2192	    egrep -v ": unused object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
2193	    sort >$SRC/runtime.out
2194
2195	# Determine any processing errors that will affect the final output
2196	# and display these first.
2197	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
2198	if [ $? -eq 0 ]; then
2199	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
2200		tee -a $LOGFILE >> $mail_msg_file
2201	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
2202		tee -a $LOGFILE >> $mail_msg_file
2203	fi
2204	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
2205	if [ $? -eq 0 ]; then
2206	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
2207		tee -a $LOGFILE >> $mail_msg_file
2208	    echo "to execute an object, thus it could not be checked fully." | \
2209		tee -a $LOGFILE >> $mail_msg_file
2210	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
2211		tee -a $LOGFILE >> $mail_msg_file
2212	    echo "or an i386 object was encountered on a sparc system?\n" | \
2213		tee -a $LOGFILE >> $mail_msg_file
2214	fi
2215	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
2216	if [ $? -eq 0 ]; then
2217	    echo "WARNING: creation of an alternative dependency cache failed." | \
2218		tee -a $LOGFILE >> $mail_msg_file
2219	    echo "Dependencies will bind to the base system libraries.\n" | \
2220		tee -a $LOGFILE >> $mail_msg_file
2221	    grep "$CRLECONF" $SRC/runtime.out | \
2222		tee -a $LOGFILE >> $mail_msg_file
2223	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
2224		tee -a $LOGFILE >> $mail_msg_file
2225	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
2226	fi
2227
2228	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
2229	    tee -a $LOGFILE >> $mail_msg_file
2230
2231	# NEEDED= and RPATH= are informational; report anything else that we
2232	# haven't already.
2233	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2234	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
2235
2236	# probably should compare against a 'known ok runpaths' list
2237	if [ ! -f $SRC/runtime.ref ]; then
2238		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2239			$SRC/runtime.out >  $SRC/runtime.ref
2240	fi
2241
2242	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
2243	    >> $mail_msg_file
2244
2245	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
2246	    diff $SRC/runtime.ref - >> $mail_msg_file
2247fi
2248
2249# DEBUG lint of kernel begins
2250
2251if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2252	if [ "$LINTDIRS" = "" ]; then
2253		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2254		LINTDIRS="$SRC y"
2255	fi
2256	set $LINTDIRS
2257	while [ $# -gt 0 ]; do
2258		dolint $1 $2; shift; shift
2259	done
2260else
2261	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2262fi
2263
2264# "make check" begins
2265
2266if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2267	# remove old check.out
2268	rm -f $SRC/check.out
2269
2270	rm -f $SRC/check-${MACH}.out
2271	cd $SRC
2272	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
2273	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2274
2275	grep ":" $SRC/check-${MACH}.out |
2276		egrep -v "Ignoring unknown host" | \
2277		sort | uniq >> $mail_msg_file
2278else
2279	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2280fi
2281
2282echo "\n==== Find core files ====\n" | \
2283    tee -a $LOGFILE >> $mail_msg_file
2284
2285find $abssrcdirs -name core -a -type f -exec file {} \; | \
2286	tee -a $LOGFILE >> $mail_msg_file
2287
2288if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2289	echo "\n==== Diff unreferenced files (since last build) ====\n" \
2290	    | tee -a $LOGFILE >>$mail_msg_file
2291	rm -f $SRC/unref-${MACH}.ref
2292	if [ -f $SRC/unref-${MACH}.out ]; then
2293		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2294	fi
2295
2296	findunref -t $SRC/.build.tstamp $SRC/.. \
2297	    ${TOOLS}/findunref/exception_list \
2298	    2>> $mail_msg_file | sort | \
2299	    sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
2300	    > $SRC/unref-${MACH}.out
2301
2302	if [ ! -f $SRC/unref-${MACH}.ref ]; then
2303		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2304	fi
2305
2306	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
2307fi
2308
2309# Verify that the usual lists of files, such as exception lists,
2310# contain only valid references to files.  If the build has failed,
2311# then don't check the proto area.
2312CHECK_PATHS=${CHECK_PATHS:-y}
2313if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
2314	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
2315		>>$mail_msg_file
2316	arg=-b
2317	[ "$build_ok" = y ] && arg=
2318	checkpaths $arg $ROOT 2>&1 | tee -a $LOGFILE >>$mail_msg_file
2319fi
2320
2321if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2322	echo "\n==== Impact on file permissions ====\n" \
2323		>> $mail_msg_file
2324	#
2325	# Get pkginfo files from usr/src/pkgdefs
2326	#
2327	pmodes -qvdP \
2328	`for d in $abssrcdirs; do
2329		if [ -d "$d/pkgdefs" ]
2330		then
2331			find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
2332		fi
2333	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
2334fi
2335
2336if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
2337	echo "\n==== Objects that differ since last build ====\n" |
2338		tee -a $LOGFILE >> $mail_msg_file
2339
2340	if [ "$t_FLAG" = "y" ]; then
2341		wsdiff -t -r ${TMPDIR}/wsdiff.results $ROOT.prev $ROOT |
2342			tee -a $LOGFILE >> $mail_msg_file
2343	else
2344		wsdiff -r ${TMPDIR}/wsdiff.results $ROOT.prev $ROOT  |
2345			tee -a $LOGFILE >> $mail_msg_file
2346	fi
2347
2348	if [ "$SINGLE_PROTO" = "no" ]; then
2349		echo "\n==== Objects that differ since last build (non-DEBUG) ====\n" |
2350			tee -a $LOGFILE >> $mail_msg_file
2351
2352		if [ "$t_FLAG" = "y" ]; then
2353			wsdiff -t -r ${TMPDIR}/wsdiff-nd.results \
2354				$ROOT-nd.prev $ROOT-nd |
2355					tee -a $LOGFILE >> $mail_msg_file
2356		else
2357			wsdiff -r ${TMPDIR}/wsdiff-nd.results \
2358				$ROOT-nd.prev $ROOT-nd |
2359					tee -a $LOGFILE >> $mail_msg_file
2360		fi
2361	fi
2362fi
2363
2364END_DATE=`date`
2365echo "==== Nightly $maketype build completed: $END_DATE ====" | \
2366    tee -a $LOGFILE >> $build_time_file
2367
2368typeset -Z2 minutes
2369typeset -Z2 seconds
2370
2371elapsed_time=$SECONDS
2372((hours = elapsed_time / 3600 ))
2373((minutes = elapsed_time / 60  % 60))
2374((seconds = elapsed_time % 60))
2375
2376echo "\n==== Total build time ====" | \
2377    tee -a $LOGFILE >> $build_time_file
2378echo "\nreal    ${hours}:${minutes}:${seconds}" | \
2379    tee -a $LOGFILE >> $build_time_file
2380
2381if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2382	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
2383
2384	#
2385	# Produce a master list of unreferenced files -- ideally, we'd
2386	# generate the master just once after all of the nightlies
2387	# have finished, but there's no simple way to know when that
2388	# will be.  Instead, we assume that we're the last nightly to
2389	# finish and merge all of the unref-${MACH}.out files in
2390	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
2391	# finish, then this file will be the authoritative master
2392	# list.  Otherwise, another ${MACH}'s nightly will eventually
2393	# overwrite ours with its own master, but in the meantime our
2394	# temporary "master" will be no worse than any older master
2395	# which was already on the parent.
2396	#
2397
2398	set -- $PARENT_WS/usr/src/unref-*.out
2399	cp "$1" ${TMPDIR}/unref.merge
2400	shift
2401
2402	for unreffile; do
2403		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
2404		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
2405	done
2406
2407	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
2408fi
2409
2410#
2411# All done save for the sweeping up.
2412# (whichever exit we hit here will trigger the "cleanup" trap which
2413# optionally sends mail on completion).
2414#
2415if [ "$build_ok" = "y" ]; then
2416	exit 0
2417fi
2418exit 1
2419