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