xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision fdd1ecae0dfe07e6aa8ee90687e2e91c876dc189)
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 ${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	if [ -f $lockf ]; then
1641		basews=`basename $CODEMGR_WS`
1642		if read host user pid < $lockf; then
1643			if [ "$host" != "$hostname" ]; then
1644				echo "$MACH build of $basews apparently" \
1645				    "already started by $user on $host as $pid."
1646			elif kill -s 0 $pid 2>/dev/null; then
1647				echo "$MACH build of $basews already started" \
1648				    "by $user as $pid."
1649			else
1650				# stale lock; clear it out and continue
1651				rm -f $lockf
1652			fi
1653		else
1654			echo "$MACH build of $basews already running."
1655		fi
1656	fi
1657	if [ -f $lockf ]; then
1658		echo "Lock file is $lockf."
1659		exit 1
1660	fi
1661	ldir=`dirname $lockf`
1662	[ -d $ldir ] || newdir $ldir || exit 1
1663	eval $lockvar=$lockf
1664	staffer sh -c "echo $hostname $STAFFER $$ > $lockf" || exit 1
1665}
1666
1667#
1668# Return the list of interesting proto areas, depending on the current
1669# options.
1670#
1671allprotos() {
1672	roots="$ROOT"
1673	if [ $O_FLAG = y ]; then
1674		# OpenSolaris deliveries require separate proto areas.
1675		[ $D_FLAG = y ] && roots="$roots $ROOT-open"
1676		[ $F_FLAG = n ] && roots="$roots $ROOT-open-nd"
1677	fi
1678	if [[ $D_FLAG = y && $F_FLAG = n ]]; then
1679		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd"
1680	fi
1681
1682	echo $roots
1683}
1684
1685# Ensure no other instance of this script is running on this host.
1686# LOCKNAME can be set in <env_file>, and is by default, but is not
1687# required due to the use of $ATLOG below.
1688if [ -n "$LOCKNAME" ]; then
1689	create_lock /tmp/$LOCKNAME "lockfile"
1690fi
1691#
1692# Create from one, two, or three other locks:
1693#	$ATLOG/nightly.lock
1694#		- protects against multiple builds in same workspace
1695#	$PARENT_WS/usr/src/nightly.$MACH.lock
1696#		- protects against multiple 'u' copy-backs
1697#	$NIGHTLY_PARENT_ROOT/nightly.lock
1698#		- protects against multiple 'U' copy-backs
1699#
1700# Overriding ISUSER to 1 causes the lock to be created as root if the
1701# script is run as root.  The default is to create it as $STAFFER.
1702ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1703if [ "$u_FLAG" = "y" ]; then
1704	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1705fi
1706if [ "$U_FLAG" = "y" ]; then
1707	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1708	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1709fi
1710
1711# Locks have been taken, so we're doing a build and we're committed to
1712# the directories we may have created so far.
1713newdirlist=
1714
1715#
1716# Create mail_msg_file
1717#
1718mail_msg_file="${TMPDIR}/mail_msg"
1719touch $mail_msg_file
1720build_time_file="${TMPDIR}/build_time"
1721#
1722#	Move old LOGFILE aside
1723#	ATLOG directory already made by 'create_lock' above
1724#
1725if [ -f $LOGFILE ]; then
1726	mv -f $LOGFILE ${LOGFILE}-
1727fi
1728#
1729#	Build OsNet source
1730#
1731START_DATE=`date`
1732SECONDS=0
1733echo "\n==== Nightly $maketype build started:   $START_DATE ====" \
1734    | tee -a $LOGFILE > $build_time_file
1735
1736# make sure we log only to the nightly build file
1737build_noise_file="${TMPDIR}/build_noise"
1738exec </dev/null >$build_noise_file 2>&1
1739
1740echo "\n==== list of environment variables ====\n" >> $LOGFILE
1741env >> $LOGFILE
1742
1743echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1744
1745if [ "$P_FLAG" = "y" ]; then
1746	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1747fi
1748
1749if [ "$T_FLAG" = "y" ]; then
1750	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1751fi
1752
1753if is_source_build; then
1754	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
1755		echo "WARNING: the -S flags do not support incremental" \
1756		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
1757		i_FLAG=n
1758		i_CMD_LINE_FLAG=n
1759	fi
1760	if [ "$N_FLAG" = "n" ]; then
1761		echo "WARNING: the -S flags do not support protocmp;" \
1762		    "protocmp disabled\n" | \
1763		    tee -a $mail_msg_file >> $LOGFILE
1764		N_FLAG=y
1765	fi
1766	if [ "$l_FLAG" = "y" ]; then
1767		echo "WARNING: the -S flags do not support lint;" \
1768		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1769		l_FLAG=n
1770	fi
1771	if [ "$C_FLAG" = "y" ]; then
1772		echo "WARNING: the -S flags do not support cstyle;" \
1773		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1774		C_FLAG=n
1775	fi
1776else
1777	if [ "$N_FLAG" = "y" ]; then
1778		if [ "$p_FLAG" = "y" ]; then
1779			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1780WARNING: the p option (create packages) is set, but so is the N option (do
1781         not run protocmp); this is dangerous; you should unset the N option
1782EOF
1783		else
1784			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1785Warning: the N option (do not run protocmp) is set; it probably shouldn't be
1786EOF
1787		fi
1788		echo "" | tee -a $mail_msg_file >> $LOGFILE
1789	fi
1790fi
1791
1792if [ "$O_FLAG" = "y" -a "$a_FLAG" = "n" ]; then
1793	echo "WARNING: OpenSolaris deliveries (-O) require archives;" \
1794	    "enabling the -a flag." | tee -a $mail_msg_file >> $LOGFILE
1795	a_FLAG=y
1796fi
1797
1798if [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
1799	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
1800	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
1801fi
1802
1803if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1804	#
1805	# In the past we just complained but went ahead with the lint
1806	# pass, even though the proto area was built non-debug.  It's
1807	# unlikely that non-debug headers will make a difference, but
1808	# rather than assuming it's a safe combination, force the user
1809	# to specify a debug build.
1810	#
1811	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
1812	    | tee -a $mail_msg_file >> $LOGFILE
1813	l_FLAG=n
1814fi
1815
1816if [ "$f_FLAG" = "y" ]; then
1817	if [ "$i_FLAG" = "y" ]; then
1818		echo "WARNING: the -f flag cannot be used during incremental" \
1819		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1820		f_FLAG=n
1821	fi
1822	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
1823		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
1824		    tee -a $mail_msg_file >> $LOGFILE
1825		f_FLAG=n
1826	fi
1827fi
1828
1829if [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
1830	echo "WARNING: -w specified, but $ROOT does not exist;" \
1831	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
1832	w_FLAG=n
1833fi
1834
1835if [ "$t_FLAG" = "n" ]; then
1836	#
1837	# We're not doing a tools build, so make sure elfsign(1) is
1838	# new enough to safely sign non-crypto binaries.  We test
1839	# debugging output from elfsign to detect the old version.
1840	#
1841	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
1842	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
1843	    | egrep algorithmOID`
1844	if [ -z "$newelfsigntest" ]; then
1845		echo "WARNING: /usr/bin/elfsign out of date;" \
1846		    "will only sign crypto modules\n" | \
1847		    tee -a $mail_msg_file >> $LOGFILE
1848		export ELFSIGN_OBJECT=true
1849	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
1850		echo "WARNING: VERIFY_ELFSIGN=y requires" \
1851		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
1852		    tee -a $mail_msg_file >> $LOGFILE
1853	fi
1854fi
1855
1856[ "$O_FLAG" = y ] && MULTI_PROTO=yes
1857
1858case $MULTI_PROTO in
1859yes|no)	;;
1860*)
1861	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
1862	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
1863	echo "Setting MULTI_PROTO to \"no\".\n" | \
1864	    tee -a $mail_msg_file >> $LOGFILE
1865	export MULTI_PROTO=no
1866	;;
1867esac
1868
1869echo "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
1870
1871# System
1872whence uname | tee -a $mail_msg_file >> $LOGFILE
1873uname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
1874echo | tee -a $mail_msg_file >> $LOGFILE
1875
1876# nightly (will fail in year 2100 due to SCCS flaw)
1877echo "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
1878echo "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
1879
1880# make
1881whence $MAKE | tee -a $mail_msg_file >> $LOGFILE
1882$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
1883echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1884    tee -a $mail_msg_file >> $LOGFILE
1885
1886#
1887# Report the compiler versions.
1888#
1889if [ -f $SRC/Makefile ]; then
1890	srcroot=$SRC
1891elif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
1892	srcroot=$BRINGOVER_WS/usr/src
1893else
1894	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
1895	    tee -a $mail_msg_file >> $LOGFILE
1896	exit 1
1897fi
1898
1899( cd $srcroot
1900  for target in cc-version cc64-version java-version; do
1901	echo
1902	#
1903	# Put statefile somewhere we know we can write to rather than trip
1904	# over a read-only $srcroot.
1905	#
1906	rm -f $TMPDIR/make-state
1907	export SRC=$srcroot
1908	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
1909		continue
1910	fi
1911	touch $TMPDIR/nocompiler
1912  done
1913  echo
1914) | tee -a $mail_msg_file >> $LOGFILE
1915
1916if [ -f $TMPDIR/nocompiler ]; then
1917	rm -f $TMPDIR/nocompiler
1918	build_ok=n
1919	echo "Aborting due to missing compiler." |
1920		tee -a $mail_msg_file >> $LOGFILE
1921	exit 1
1922fi
1923
1924# as
1925whence as | tee -a $mail_msg_file >> $LOGFILE
1926as -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
1927echo | tee -a $mail_msg_file >> $LOGFILE
1928
1929# Check that we're running a capable link-editor
1930whence ld | tee -a $mail_msg_file >> $LOGFILE
1931LDVER=`ld -V 2>&1`
1932echo $LDVER | tee -a $mail_msg_file >> $LOGFILE
1933LDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
1934if [ `expr $LDVER \< 422` -eq 1 ]; then
1935	echo "The link-editor needs to be at version 422 or higher to build" | \
1936	    tee -a $mail_msg_file >> $LOGFILE
1937	echo "the latest stuff, hope your build works." | \
1938	    tee -a $mail_msg_file >> $LOGFILE
1939fi
1940
1941echo "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1942    tee -a $mail_msg_file >> $LOGFILE
1943
1944echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1945echo $VERSION | tee -a $mail_msg_file >> $LOGFILE
1946
1947# Save the current proto area if we're comparing against the last build
1948if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
1949    if [ -d "$ROOT.prev" ]; then
1950	rm -rf $ROOT.prev
1951    fi
1952    mv $ROOT $ROOT.prev
1953fi
1954
1955# Same for non-DEBUG proto area
1956if [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
1957	if [ -d "$ROOT-nd.prev" ]; then
1958		rm -rf $ROOT-nd.prev
1959	fi
1960	mv $ROOT-nd $ROOT-nd.prev
1961fi
1962
1963#
1964#	Decide whether to clobber
1965#
1966if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
1967	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
1968
1969	cd $SRC
1970	# remove old clobber file
1971	rm -f $SRC/clobber.out
1972	rm -f $SRC/clobber-${MACH}.out
1973
1974	# Remove all .make.state* files, just in case we are restarting
1975	# the build after having interrupted a previous 'make clobber'.
1976	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
1977	    -o -name '.make.*' -print | xargs rm -f
1978
1979	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
1980	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
1981	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1982		egrep -v "Ignoring unknown host" \
1983		>> $mail_msg_file
1984
1985	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
1986		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
1987		cd ${TOOLS}
1988		rm -f ${TOOLS}/clobber-${MACH}.out
1989		$MAKE -ek clobber 2>&1 | \
1990			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
1991		echo "\n==== Make tools clobber ERRORS ====\n" \
1992			>> $mail_msg_file
1993		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1994			>> $mail_msg_file
1995		rm -rf ${TOOLS_PROTO}
1996		mkdir -p ${TOOLS_PROTO}
1997	fi
1998
1999	rm -rf `allprotos`
2000
2001	# Get back to a clean workspace as much as possible to catch
2002	# problems that only occur on fresh workspaces.
2003	# Remove all .make.state* files, libraries, and .o's that may
2004	# have been omitted from clobber.  A couple of libraries are
2005	# under SCCS, so leave them alone.
2006	# We should probably blow away temporary directories too.
2007	cd $SRC
2008	find $relsrcdirs \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
2009	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2010	       -name '*.o' \) -print | \
2011	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
2012else
2013	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
2014fi
2015
2016#
2017#	Decide whether to bringover to the codemgr workspace
2018#
2019if [ "$n_FLAG" = "n" ]; then
2020	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2021	# sleep on the parent workspace's lock
2022	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
2023	do
2024		sleep 120
2025	done
2026
2027	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2028
2029	(staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
2030	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
2031		touch $TMPDIR/bringover_failed
2032
2033         staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2034
2035	 if [ -s $TMPDIR/bringovercheck.out ]; then
2036		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2037		cat $TMPDIR/bringovercheck.out
2038	 fi
2039
2040	) | tee -a  $mail_msg_file >> $LOGFILE
2041
2042	if [ -f $TMPDIR/bringover_failed ]; then
2043		rm -f $TMPDIR/bringover_failed
2044		build_ok=n
2045		echo "trouble with bringover, quitting at `date`." |
2046			tee -a $mail_msg_file >> $LOGFILE
2047		exit 1
2048	fi
2049
2050	#
2051	# Possible transition from pre-split workspace to split
2052	# workspace.  See if the bringover changed anything.
2053	#
2054	CLOSED_IS_PRESENT="$orig_closed_is_present"
2055	check_closed_tree
2056else
2057	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
2058fi
2059
2060#
2061# Build and use the workspace's tools if requested
2062#
2063if [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
2064	set_non_debug_build_flags
2065
2066	build_tools ${TOOLS_PROTO}
2067
2068	if [[ $? -ne 0 && "$t_FLAG" = y ]]; then
2069		use_tools $TOOLS_PROTO
2070		export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
2071	fi
2072fi
2073
2074#
2075# copy ihv proto area in addition to the build itself
2076#
2077if [ "$X_FLAG" = "y" ]; then
2078	copy_ihv_proto
2079fi
2080
2081if [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
2082	echo "\n==== NOT Building base OS-Net source ====\n" | \
2083	    tee -a $LOGFILE >> $mail_msg_file
2084else
2085	# timestamp the start of the normal build; the findunref tool uses it.
2086	touch $SRC/.build.tstamp
2087
2088	normal_build
2089fi
2090
2091#
2092# Generate OpenSolaris deliverables if requested.
2093#
2094if [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2095	#
2096	# Generate skeleton (minimal) closed binaries for open-only
2097	# build.  There's no need to distinguish debug from non-debug
2098	# binaries, but it simplifies file management to have separate
2099	# trees.
2100	#
2101
2102	echo "\n==== Generating skeleton closed binaries for" \
2103	    "open-only build ====\n" | \
2104	    tee -a $LOGFILE >> $mail_msg_file
2105
2106	rm -rf $CODEMGR_WS/closed.skel
2107	if [ "$D_FLAG" = y ]; then
2108		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
2109		    >>$LOGFILE 2>&1
2110		if [ $? -ne 0 ]; then
2111			echo "Couldn't create skeleton DEBUG closed binaries." |
2112			    tee -a $mail_msg_file >> $LOGFILE
2113		fi
2114	fi
2115	if [ "$F_FLAG" = n ]; then
2116		mkclosed $MACH $ROOT-nd $CODEMGR_WS/closed.skel/root_$MACH-nd \
2117		    >>$LOGFILE 2>&1
2118		if [ $? -ne 0 ]; then
2119			echo "Couldn't create skeleton non-DEBUG closed binaries." |
2120			    tee -a $mail_msg_file >> $LOGFILE
2121		fi
2122	fi
2123
2124	ORIG_CLOSED_IS_PRESENT=$CLOSED_IS_PRESENT
2125	export CLOSED_IS_PRESENT=no
2126
2127	ORIG_ON_CLOSED_BINS="$ON_CLOSED_BINS"
2128	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
2129
2130	normal_build -O
2131
2132	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
2133	    tee -a $LOGFILE >> $mail_msg_file
2134
2135	cd $CODEMGR_WS
2136
2137	echo "Generating THIRDPARTYLICENSE files..." >> $LOGFILE
2138
2139	mktpl usr/src/tools/opensolaris/license-list >>$LOGFILE 2>&1
2140	if [ $? -ne 0 ]; then
2141		echo "Couldn't create THIRDPARTYLICENSE files" |
2142		    tee -a $mail_msg_file >> $LOGFILE
2143	fi
2144
2145	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
2146	closed_basename=on-closed-bins
2147	if [ "$D_FLAG" = y ]; then
2148		bindrop "$ROOT" "$ROOT-open" "$closed_basename" \
2149		    >>"$LOGFILE" 2>&1
2150		if [ $? -ne 0 ]; then
2151			echo "Couldn't create DEBUG closed binaries." |
2152			    tee -a $mail_msg_file >> $LOGFILE
2153		fi
2154	fi
2155	if [ "$F_FLAG" = n ]; then
2156		bindrop -n "$ROOT-nd" "$ROOT-open-nd" "$closed_basename-nd" \
2157		    >>"$LOGFILE" 2>&1
2158		if [ $? -ne 0 ]; then
2159			echo "Couldn't create non-DEBUG closed binaries." |
2160			    tee -a $mail_msg_file >> $LOGFILE
2161		fi
2162	fi
2163
2164	echo "Generating SUNWonbld tarball..." >> $LOGFILE
2165	PKGARCHIVE=$PKGARCHIVE_ORIG
2166	onblddrop >> $LOGFILE 2>&1
2167	if [ $? -ne 0 ]; then
2168		echo "Couldn't create SUNWonbld tarball." |
2169		    tee -a $mail_msg_file >> $LOGFILE
2170	fi
2171
2172	echo "Generating README.opensolaris..." >> $LOGFILE
2173	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
2174	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
2175	if [ $? -ne 0 ]; then
2176		echo "Couldn't create README.opensolaris." |
2177		    tee -a $mail_msg_file >> $LOGFILE
2178	fi
2179
2180	echo "Generating source tarball..." >> $LOGFILE
2181	sdrop >>$LOGFILE 2>&1
2182	if [ $? -ne 0 ]; then
2183		echo "Couldn't create source tarball." |
2184		    tee -a "$mail_msg_file" >> "$LOGFILE"
2185	fi
2186
2187	echo "Generating BFU tarball(s)..." >> $LOGFILE
2188	if [ "$D_FLAG" = y ]; then
2189		makebfu_filt bfudrop "$ROOT-open" \
2190		    "$closed_basename.$MACH.tar.bz2" nightly-osol
2191		if [ $? -ne 0 ]; then
2192			echo "Couldn't create DEBUG archives tarball." |
2193			    tee -a $mail_msg_file >> $LOGFILE
2194		fi
2195	fi
2196	if [ "$F_FLAG" = n ]; then
2197		makebfu_filt bfudrop -n "$ROOT-open-nd" \
2198		    "$closed_basename-nd.$MACH.tar.bz2" nightly-osol-nd
2199		if [ $? -ne 0 ]; then
2200			echo "Couldn't create non-DEBUG archives tarball." |
2201			    tee -a $mail_msg_file >> $LOGFILE
2202		fi
2203	fi
2204
2205	ON_CLOSED_BINS=$ORIG_ON_CLOSED_BINS
2206	CLOSED_IS_PRESENT=$ORIG_CLOSED_IS_PRESENT
2207fi
2208
2209ORIG_SRC=$SRC
2210BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
2211
2212#
2213# For the "open" build, we don't mung any source files, so skip this
2214# step.
2215#
2216if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2217	save_binaries
2218
2219	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
2220	SCCSHELPER=${TMPDIR}/sccs-helper
2221	rm -f ${SCCSHELPER}
2222cat >${SCCSHELPER} <<EOF
2223#!/bin/ksh
2224cd \$1
2225cd ..
2226sccs get SCCS >/dev/null 2>&1
2227EOF
2228	cd $SRC
2229	chmod +x ${SCCSHELPER}
2230	find $relsrcdirs -name SCCS | xargs -L 1 ${SCCSHELPER}
2231	rm -f ${SCCSHELPER}
2232fi
2233
2234if [ "$SD_FLAG" = "y" ]; then
2235	set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
2236fi
2237
2238# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
2239# $SRC pointing to the export_source usr/src.
2240if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2241	set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2242fi
2243
2244if [ "$SD_FLAG" = "y" ]; then
2245	# drop the crypt files in place.
2246	cd ${EXPORT_SRC}
2247	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
2248	    >> ${LOGFILE}
2249	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
2250	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
2251	if [ "$?" = "0" ]; then
2252		echo "\n==== DOMESTIC extraction succeeded ====\n" \
2253		    >> $mail_msg_file
2254	else
2255		echo "\n==== DOMESTIC extraction failed ====\n" \
2256		    >> $mail_msg_file
2257	fi
2258
2259fi
2260
2261if [ "$SO_FLAG" = "y" ]; then
2262	#
2263	# Copy the open sources into their own tree, set up the closed
2264	# binaries, and set up the environment.  The build looks for
2265	# the closed binaries in a location that depends on whether
2266	# it's a DEBUG build, so we might need to make two copies.
2267	#
2268	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2269	SRC=$OPEN_SRCDIR/usr/src
2270
2271	# Try not to clobber any user-provided closed binaries.
2272	export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
2273
2274	echo "\n==== Copying skeleton closed binaries to" \
2275	    "$ON_CLOSED_BINS ====\n" | \
2276	    tee -a $mail_msg_file >> $LOGFILE
2277
2278	if [ "$D_FLAG" = y ]; then
2279		mkclosed $MACH $ROOT $ON_CLOSED_BINS/root_$MACH >>$LOGFILE 2>&1
2280		if [ $? -ne 0 ]; then
2281			build_ok=n
2282			echo "Couldn't create DEBUG closed binaries." |
2283			    tee -a $mail_msg_file >> $LOGFILE
2284		fi
2285	fi
2286	if [ "$F_FLAG" = n ]; then
2287		root=$ROOT
2288		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
2289		mkclosed $MACH $root $ON_CLOSED_BINS/root_$MACH-nd \
2290		    >>$LOGFILE 2>&1
2291		if [ $? -ne 0 ]; then
2292			build_ok=n
2293			echo "Couldn't create non-DEBUG closed binaries." |
2294			    tee -a $mail_msg_file >> $LOGFILE
2295		fi
2296	fi
2297
2298	export CLOSED_IS_PRESENT=no
2299fi
2300
2301if is_source_build && [ $build_ok = y ] ; then
2302	# remove proto area(s) here, since we don't clobber
2303	rm -rf `allprotos`
2304	if [ "$t_FLAG" = "y" ]; then
2305		set_non_debug_build_flags
2306		ORIG_TOOLS=$TOOLS
2307		#
2308		# SRC was set earlier to point to the source build
2309		# source tree (e.g., $EXPORT_SRC).
2310		#
2311		TOOLS=${SRC}/tools
2312		build_tools ${SRC}/tools/proto
2313		TOOLS=$ORIG_TOOLS
2314	fi
2315
2316	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
2317	normal_build
2318fi
2319
2320if [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
2321	rm -rf $ON_CLOSED_BINS
2322fi
2323
2324#
2325# There are several checks that need to look at the proto area, but
2326# they only need to look at one, and they don't care whether it's
2327# DEBUG or non-DEBUG.
2328#
2329if [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
2330	checkroot=$ROOT-nd
2331else
2332	checkroot=$ROOT
2333fi
2334
2335if [ "$build_ok" = "y" ]; then
2336	echo "\n==== Creating protolist system file at `date` ====" \
2337		>> $LOGFILE
2338	protolist $checkroot > $ATLOG/proto_list_${MACH}
2339	echo "==== protolist system file created at `date` ====\n" \
2340		>> $LOGFILE
2341
2342	if [ "$N_FLAG" != "y" ]; then
2343		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
2344
2345		# If there is a reference proto list, compare the build's proto
2346		# list with the reference to see changes in proto areas.
2347		# Use the current exception list.
2348		exc=etc/exception_list_$MACH
2349		if [ -f $SRC/pkgdefs/$exc ]; then
2350			ELIST="-e $SRC/pkgdefs/$exc"
2351		fi
2352		if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
2353			ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
2354		fi
2355
2356		if [ -f "$REF_PROTO_LIST" ]; then
2357			# For builds that copy the IHV proto area (-X), add the
2358			# IHV proto list to the reference list if the reference
2359			# was built without -X.
2360			#
2361			# For builds that don't copy the IHV proto area, add the
2362			# IHV proto list to the build's proto list if the
2363			# reference was built with -X.
2364			#
2365			# Use the presence of the first file entry of the cached
2366			# IHV proto list in the reference list to determine
2367			# whether it was build with -X or not.
2368			IHV_REF_PROTO_LIST=$SRC/pkgdefs/etc/proto_list_ihv_$MACH
2369			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2370				$IHV_REF_PROTO_LIST 2> /dev/null)
2371			if [ $? = 0 -a -n "$grepfor" ]; then
2372				if [ "$X_FLAG" = "y" ]; then
2373					grep -w "$grepfor" \
2374						$REF_PROTO_LIST > /dev/null
2375					if [ ! "$?" = "0" ]; then
2376						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2377					fi
2378				else
2379					grep -w "$grepfor" \
2380						$REF_PROTO_LIST > /dev/null
2381					if [ "$?" = "0" ]; then
2382						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2383					fi
2384				fi
2385			fi
2386
2387			$PROTOCMPTERSE \
2388			  "Files in yesterday's proto area, but not today's:" \
2389			  "Files in today's proto area, but not yesterday's:" \
2390			  "Files that changed between yesterday and today:" \
2391			  ${ELIST} \
2392			  -d $REF_PROTO_LIST \
2393			  $REF_IHV_PROTO \
2394			  $ATLOG/proto_list_${MACH} \
2395			  $IHV_PROTO_LIST \
2396				>> $mail_msg_file
2397		fi
2398		# Compare the build's proto list with current package
2399		# definitions to audit the quality of package definitions
2400		# and makefile install targets. Use the current exception list.
2401		PKGDEFS_LIST=""
2402		for d in $abssrcdirs; do
2403			if [ -d $d/pkgdefs ]; then
2404				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2405			fi
2406		done
2407		if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
2408			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
2409		fi
2410
2411		$PROTOCMPTERSE \
2412		    "Files missing from the proto area:" \
2413		    "Files missing from packages:" \
2414		    "Inconsistencies between pkgdefs and proto area:" \
2415		    ${ELIST} \
2416		    ${PKGDEFS_LIST} \
2417		    $ATLOG/proto_list_${MACH} \
2418		    >> $mail_msg_file
2419	fi
2420fi
2421
2422if [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
2423	staffer cp $ATLOG/proto_list_${MACH} \
2424		$PARENT_WS/usr/src/proto_list_${MACH}
2425fi
2426
2427# Update parent proto area if necessary. This is done now
2428# so that the proto area has either DEBUG or non-DEBUG kernels.
2429# Note that this clears out the lock file, so we can dispense with
2430# the variable now.
2431if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
2432	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
2433	    tee -a $LOGFILE >> $mail_msg_file
2434	# The rm -rf command below produces predictable errors if
2435	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
2436	# and that directory is accessed via NFS.  This is because
2437	# deleted-but-still-open files don't actually disappear as
2438	# expected, but rather turn into .nfsXXXX junk files, leaving
2439	# the directory non-empty.  Since this is a not-unusual usage
2440	# pattern, and we still want to catch other errors here, we
2441	# take the unusal step of moving aside 'nightly' from that
2442	# directory (if we're using it).
2443	mypath=${0##*/root_$MACH/}
2444	if [ "$mypath" = $0 ]; then
2445		mypath=opt/onbld/bin/${0##*/}
2446	fi
2447	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
2448		mv -f $0 $PARENT_WS/proto/root_$MACH
2449	fi
2450	rm -rf $PARENT_WS/proto/root_$MACH/*
2451	unset Ulockfile
2452	mkdir -p $NIGHTLY_PARENT_ROOT
2453	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2454		cd $ROOT
2455		( tar cf - . |
2456		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
2457		    tee -a $mail_msg_file >> $LOGFILE
2458	fi
2459	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2460		mkdir -p $NIGHTLY_PARENT_ROOT-nd
2461		cd $ROOT-nd
2462		( tar cf - . |
2463		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
2464		    tee -a $mail_msg_file >> $LOGFILE
2465	fi
2466fi
2467
2468#
2469# do shared library interface verification
2470#
2471
2472if [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
2473	echo "\n==== Check versioning and ABI information ====\n"  | \
2474	    tee -a $LOGFILE >> $mail_msg_file
2475
2476	rm -rf $SRC/interfaces.ref
2477	if [ -d $SRC/interfaces.out ]; then
2478		mv $SRC/interfaces.out $SRC/interfaces.ref
2479	fi
2480	rm -rf $SRC/interfaces.out
2481	mkdir -p $SRC/interfaces.out
2482
2483	intf_check -V -m -o -b $SRC/tools/abi/etc \
2484		-d $SRC/interfaces.out $checkroot 2>&1 | sort \
2485		> $SRC/interfaces.out/log
2486
2487	# report any ERROR found in log file
2488	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
2489		tee -a $LOGFILE >> $mail_msg_file
2490
2491	if [ ! -d $SRC/interfaces.ref ] ; then
2492		mkdir -p $SRC/interfaces.ref
2493		if [ -d  $SRC/interfaces.out ]; then
2494			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
2495		fi
2496	fi
2497
2498	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
2499	    tee -a $LOGFILE >> $mail_msg_file
2500
2501	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
2502	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
2503
2504	# Report any differences in WARNING messages between last
2505	# and current build.
2506	if [ "$out_vers" = "$ref_vers" ]; then
2507		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
2508		    fgrep 'WARNING' | sed 's/WARNING: //' | \
2509		    tee -a $LOGFILE >> $mail_msg_file
2510	fi
2511fi
2512
2513if [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
2514	echo "\n==== Check ELF runtime attributes ====\n" | \
2515	    tee -a $LOGFILE >> $mail_msg_file
2516
2517	LDDUSAGE="^ldd: does not support -e"
2518	LDDWRONG="wrong class"
2519	CRLERROR="^crle:"
2520	CRLECONF="^crle: configuration file:"
2521
2522	rm -f $SRC/runtime.ref
2523	if [ -f $SRC/runtime.out ]; then
2524		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2525			$SRC/runtime.out > $SRC/runtime.ref
2526	fi
2527
2528	# If we're doing a debug build the proto area will be left with
2529	# debuggable objects, thus don't assert -s.
2530	if [ "$D_FLAG" = "y" ]; then
2531		rtime_sflag=""
2532	else
2533		rtime_sflag="-s"
2534	fi
2535	check_rtime -d $checkroot -i -m -o $rtime_sflag $checkroot 2>&1 | \
2536	    egrep -v ": unreferenced object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
2537	    egrep -v ": unused object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
2538	    sort >$SRC/runtime.out
2539
2540	# Determine any processing errors that will affect the final output
2541	# and display these first.
2542	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
2543	if [ $? -eq 0 ]; then
2544	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
2545		tee -a $LOGFILE >> $mail_msg_file
2546	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
2547		tee -a $LOGFILE >> $mail_msg_file
2548	fi
2549	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
2550	if [ $? -eq 0 ]; then
2551	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
2552		tee -a $LOGFILE >> $mail_msg_file
2553	    echo "to execute an object, thus it could not be checked fully." | \
2554		tee -a $LOGFILE >> $mail_msg_file
2555	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
2556		tee -a $LOGFILE >> $mail_msg_file
2557	    echo "or an i386 object was encountered on a sparc system?\n" | \
2558		tee -a $LOGFILE >> $mail_msg_file
2559	fi
2560	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
2561	if [ $? -eq 0 ]; then
2562	    echo "WARNING: creation of an alternative dependency cache failed." | \
2563		tee -a $LOGFILE >> $mail_msg_file
2564	    echo "Dependencies will bind to the base system libraries.\n" | \
2565		tee -a $LOGFILE >> $mail_msg_file
2566	    grep "$CRLECONF" $SRC/runtime.out | \
2567		tee -a $LOGFILE >> $mail_msg_file
2568	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
2569		tee -a $LOGFILE >> $mail_msg_file
2570	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
2571	fi
2572
2573	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
2574	    tee -a $LOGFILE >> $mail_msg_file
2575
2576	# NEEDED= and RPATH= are informational; report anything else that we
2577	# haven't already.
2578	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2579	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
2580
2581	# probably should compare against a 'known ok runpaths' list
2582	if [ ! -f $SRC/runtime.ref ]; then
2583		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2584			$SRC/runtime.out >  $SRC/runtime.ref
2585	fi
2586
2587	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
2588	    >> $mail_msg_file
2589
2590	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
2591	    diff $SRC/runtime.ref - >> $mail_msg_file
2592fi
2593
2594# DEBUG lint of kernel begins
2595
2596if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2597	if [ "$LINTDIRS" = "" ]; then
2598		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2599		LINTDIRS="$SRC y"
2600	fi
2601	set $LINTDIRS
2602	while [ $# -gt 0 ]; do
2603		dolint $1 $2; shift; shift
2604	done
2605else
2606	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2607fi
2608
2609# "make check" begins
2610
2611if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2612	# remove old check.out
2613	rm -f $SRC/check.out
2614
2615	rm -f $SRC/check-${MACH}.out
2616	cd $SRC
2617	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
2618	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2619
2620	grep ":" $SRC/check-${MACH}.out |
2621		egrep -v "Ignoring unknown host" | \
2622		sort | uniq >> $mail_msg_file
2623else
2624	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2625fi
2626
2627echo "\n==== Find core files ====\n" | \
2628    tee -a $LOGFILE >> $mail_msg_file
2629
2630find $abssrcdirs -name core -a -type f -exec file {} \; | \
2631	tee -a $LOGFILE >> $mail_msg_file
2632
2633if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2634	echo "\n==== Diff unreferenced files (since last build) ====\n" \
2635	    | tee -a $LOGFILE >>$mail_msg_file
2636	rm -f $SRC/unref-${MACH}.ref
2637	if [ -f $SRC/unref-${MACH}.out ]; then
2638		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2639	fi
2640
2641	findunref -t $SRC/.build.tstamp $SRC/.. \
2642	    ${TOOLS}/findunref/exception_list \
2643	    2>> $mail_msg_file | sort | \
2644	    sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
2645	    > $SRC/unref-${MACH}.out
2646
2647	if [ ! -f $SRC/unref-${MACH}.ref ]; then
2648		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2649	fi
2650
2651	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
2652fi
2653
2654# Verify that the usual lists of files, such as exception lists,
2655# contain only valid references to files.  If the build has failed,
2656# then don't check the proto area.
2657CHECK_PATHS=${CHECK_PATHS:-y}
2658if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
2659	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
2660		>>$mail_msg_file
2661	arg=-b
2662	[ "$build_ok" = y ] && arg=
2663	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
2664fi
2665
2666if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2667	echo "\n==== Impact on file permissions ====\n" \
2668		>> $mail_msg_file
2669	#
2670	# Get pkginfo files from usr/src/pkgdefs
2671	#
2672	pmodes -qvdP \
2673	`for d in $abssrcdirs; do
2674		if [ -d "$d/pkgdefs" ]
2675		then
2676			find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
2677		fi
2678	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
2679fi
2680
2681if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
2682	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2683		do_wsdiff DEBUG $ROOT.prev $ROOT
2684	fi
2685
2686	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2687		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
2688	fi
2689fi
2690
2691END_DATE=`date`
2692echo "==== Nightly $maketype build completed: $END_DATE ====" | \
2693    tee -a $LOGFILE >> $build_time_file
2694
2695typeset -Z2 minutes
2696typeset -Z2 seconds
2697
2698elapsed_time=$SECONDS
2699((hours = elapsed_time / 3600 ))
2700((minutes = elapsed_time / 60  % 60))
2701((seconds = elapsed_time % 60))
2702
2703echo "\n==== Total build time ====" | \
2704    tee -a $LOGFILE >> $build_time_file
2705echo "\nreal    ${hours}:${minutes}:${seconds}" | \
2706    tee -a $LOGFILE >> $build_time_file
2707
2708if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2709	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
2710
2711	#
2712	# Produce a master list of unreferenced files -- ideally, we'd
2713	# generate the master just once after all of the nightlies
2714	# have finished, but there's no simple way to know when that
2715	# will be.  Instead, we assume that we're the last nightly to
2716	# finish and merge all of the unref-${MACH}.out files in
2717	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
2718	# finish, then this file will be the authoritative master
2719	# list.  Otherwise, another ${MACH}'s nightly will eventually
2720	# overwrite ours with its own master, but in the meantime our
2721	# temporary "master" will be no worse than any older master
2722	# which was already on the parent.
2723	#
2724
2725	set -- $PARENT_WS/usr/src/unref-*.out
2726	cp "$1" ${TMPDIR}/unref.merge
2727	shift
2728
2729	for unreffile; do
2730		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
2731		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
2732	done
2733
2734	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
2735fi
2736
2737#
2738# All done save for the sweeping up.
2739# (whichever exit we hit here will trigger the "cleanup" trap which
2740# optionally sends mail on completion).
2741#
2742if [ "$build_ok" = "y" ]; then
2743	exit 0
2744fi
2745exit 1
2746