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