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