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