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