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