xref: /titanic_50/usr/src/tools/scripts/nightly.sh (revision d1a180b0452ce86577a43be3245d2eacdeec1a34)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28# Based on the nightly script from the integration folks,
29# Mostly modified and owned by mike_s.
30# Changes also by kjc, dmk.
31#
32# BRINGOVER_WS may be specified in the env file.
33# The default is the old behavior of CLONE_WS
34#
35# -i on the command line, means fast options, so when it's on the
36# command line (only), lint, check, GPROF and TRACE builds are skipped
37# no matter what the setting of their individual flags are in NIGHTLY_OPTIONS.
38#
39# LINTDIRS can be set in the env file, format is a list of:
40#
41#	/dirname-to-run-lint-on flag
42#
43#	Where flag is:	y - enable lint noise diff output
44#			n - disable lint noise diff output
45#
46#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
47#
48# -A flag in NIGHTLY_OPTIONS checks ABI diffs in .so files
49# This option requires a couple of scripts.
50#
51# OPTHOME and TEAMWARE may be set in the environment to override /opt
52# and /opt/teamware defaults.
53#
54
55#
56# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
57# under certain circumstances, which can really screw things up; unset it.
58#
59unset CDPATH
60
61# function to do a DEBUG and non-DEBUG build. Needed because we might
62# need to do another for the source build, and since we only deliver DEBUG or
63# non-DEBUG packages.
64
65normal_build() {
66
67	# timestamp the start of a nightly build; the findunref tool uses it.
68	touch $SRC/.build.tstamp
69
70	# non-DEBUG build begins
71
72	if [ "$F_FLAG" = "n" ]; then
73		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
74		export RELEASE_BUILD ; RELEASE_BUILD=
75		unset EXTRA_OPTIONS
76		unset EXTRA_CFLAGS
77
78		build non-DEBUG -nd
79
80		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a "$p_FLAG" = "y" ]; then
81			copy_ihv_pkgs non-DEBUG -nd
82		fi
83	else
84		echo "\n==== No non-DEBUG build ====\n" >> $LOGFILE
85	fi
86
87	# non-DEBUG build ends
88
89	# DEBUG build begins
90
91	if [ "$D_FLAG" = "y" ]; then
92
93		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
94		unset RELEASE_BUILD
95		unset EXTRA_OPTIONS
96		unset EXTRA_CFLAGS
97
98		build DEBUG ""
99
100		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a "$p_FLAG" = "y" ]; then
101			copy_ihv_pkgs DEBUG ""
102		fi
103
104	else
105		echo "\n==== No DEBUG build ====\n" >> $LOGFILE
106	fi
107
108	# DEBUG build ends
109}
110
111filelist() {
112	if  [ $# -ne 2 ]; then
113		echo "usage: filelist DESTDIR PATTERN"
114		exit 1;
115	fi
116	DEST=$1
117	PATTERN=$2
118	cd ${DEST}
119
120	OBJFILES=${ORIG_SRC}/xmod/obj_files
121	if [ ! -f ${OBJFILES} ]; then
122		return;
123	fi
124	for i in `grep -v '^#' ${ORIG_SRC}/xmod/obj_files | \
125	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
126	do
127		# wildcard expansion
128		for j in $i
129		do
130			if [ -f "$j" ]; then
131				echo $j
132			fi
133			if [ -d "$j" ]; then
134				echo $j
135			fi
136		done
137	done | sort | uniq
138}
139
140# function to save off binaries after a full build for later
141# restoration
142save_binaries() {
143	# save off list of binaries
144	echo "\n==== Saving binaries from build at `date` ====\n" | \
145	    tee -a $mail_msg_file >> $LOGFILE
146	rm -f ${BINARCHIVE}
147	cd ${CODEMGR_WS}
148	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
149	filelist ${CODEMGR_WS} '^preserve:' | \
150	    cpio -ocB 2>/dev/null | compress \
151	    > ${BINARCHIVE}
152}
153
154# delete files
155hybridize_files() {
156	if  [ $# -ne 2 ]; then
157		echo "usage: hybridize_files DESTDIR MAKE_TARGET"
158		exit 1;
159	fi
160
161	DEST=$1
162	MAKETARG=$2
163
164	echo "\n==== Hybridizing files at `date` ====\n" | \
165	    tee -a $mail_msg_file >> $LOGFILE
166	for i in `filelist ${DEST} '^delete:'`
167	do
168		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
169		rm -rf "${i}"
170	done
171	for i in `filelist ${DEST} '^hybridize:' `
172	do
173		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
174		rm -f ${i}+
175		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
176		    < ${i} > ${i}+
177		mv ${i}+ ${i}
178	done
179}
180
181# restore binaries into the proper source tree.
182restore_binaries() {
183	if  [ $# -ne 2 ]; then
184		echo "usage: restore_binaries DESTDIR MAKE_TARGET"
185		exit 1;
186	fi
187
188	DEST=$1
189	MAKETARG=$2
190
191	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
192	    tee -a $mail_msg_file >> $LOGFILE
193	cd ${DEST}
194	zcat ${BINARCHIVE} | \
195	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
196}
197
198# rename files we save binaries of
199rename_files() {
200	if  [ $# -ne 2 ]; then
201		echo "usage: rename_files DESTDIR MAKE_TARGET"
202		exit 1;
203	fi
204
205	DEST=$1
206	MAKETARG=$2
207	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
208	    tee -a $mail_msg_file >> $LOGFILE
209	for i in `filelist ${DEST} '^rename:'`
210	do
211		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
212		rm -f ${i}.export
213		mv ${i} ${i}.export
214	done
215}
216
217# function to create the export/crypt source tree
218# usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET
219
220clone_source() {
221
222	if  [ $# -ne 3 ]; then
223		echo "usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET"
224		exit 1;
225	fi
226	WS=$1
227	DEST=$2
228	MAKETARG=$3
229
230	echo "\n==== Creating ${DEST} source from ${WS} (${MAKETARG}) ====\n" | \
231	    tee -a $mail_msg_file >> $LOGFILE
232
233	echo "cleaning out ${DEST}." >> $LOGFILE
234	rm -rf "${DEST}" >> $LOGFILE 2>&1
235
236	mkdir -p ${DEST}
237	cd ${WS}
238
239	echo "creating ${DEST}." >> $LOGFILE
240	find usr -name 's\.*' -a -type f -print | \
241	    sed -e 's,SCCS\/s.,,' | \
242	    grep -v '/\.del-*' | \
243	    cpio -pd ${DEST} >>$LOGFILE 2>&1
244
245	SRC=${DEST}/usr/src
246
247	cd $SRC
248	rm -f ${MAKETARG}.out
249	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
250	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
251	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
252	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
253	egrep ":" $SRC/${MAKETARG}.out | \
254		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
255		egrep -v "Ignoring unknown host" | \
256		egrep -v "warning" >> $mail_msg_file
257
258	echo "clearing state files." >> $LOGFILE
259	find . -name '.make*' -exec rm -f {} \;
260
261	cd ${DEST}
262	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
263		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
264		echo "\n==== xmod/cry_files that don't exist ====\n" | \
265		    tee -a $mail_msg_file >> $LOGFILE
266		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
267		for i in `cat ${CRYPT_FILES}`
268		do
269			# make sure the files exist
270			if [ -f "$i" ]; then
271				continue
272			fi
273			if [ -d "$i" ]; then
274				continue
275			fi
276			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
277		done
278		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
279		    cpio -ocB 2>/dev/null | \
280		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
281	fi
282
283	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
284		# rename first, since we might restore a file
285		# of the same name (mapfiles)
286		rename_files ${EXPORT_SRC} EXPORT_SRC
287		if [ "$SH_FLAG" = "y" ]; then
288			hybridize_files ${EXPORT_SRC} EXPORT_SRC
289		fi
290	fi
291
292	# save the cleartext
293	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
294	    tee -a $mail_msg_file >> $LOGFILE
295	cd ${DEST}
296	rm -f ${MAKETARG}.cpio.Z
297	find usr -depth -print | \
298	    grep -v usr/src/${MAKETARG}.out | \
299	    cpio -ocB 2>/dev/null | \
300	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
301	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
302		restore_binaries ${EXPORT_SRC} EXPORT_SRC
303	fi
304
305	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
306		restore_binaries ${CRYPT_SRC} CRYPT_SRC
307	fi
308
309}
310
311# function to do the build.
312# usage: build LABEL SUFFIX
313
314build() {
315
316	if  [ $# -ne 2 ]; then
317		echo "usage: build LABEL SUFFIX"
318		exit 1;
319	fi
320
321	LABEL=$1
322	SUFFIX=$2
323	INSTALLOG=install${SUFFIX}-${MACH}
324	NOISE=noise${SUFFIX}-${MACH}
325	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
326	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
327	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
328		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
329	fi
330
331	#remove old logs
332	OLDINSTALLOG=install${SUFFIX}
333	OLDNOISE=noise${SUFFIX}
334	rm -f $SRC/${OLDINSTALLOG}.out
335	rm -f $SRC/${OLDNOISE}.ref
336	if [ -f $SRC/${OLDNOISE}.out ]; then
337		mv $SRC/${OLDNOISE}.out $SRC/${NOISE}.ref
338	fi
339
340	this_build_ok=y
341	#
342	#	Build OS-Networking source
343	#
344	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
345		>> $LOGFILE
346
347	rm -f $SRC/${INSTALLOG}.out
348	cd $SRC
349	/bin/time $MAKE -e install 2>&1 | \
350	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
351	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
352	egrep ":" $SRC/${INSTALLOG}.out |
353		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
354		egrep -v "Ignoring unknown host" | \
355		egrep -v "cc .* -o error " | \
356		egrep -v "warning" >> $mail_msg_file
357	if [ "$?" = "0" ]; then
358		build_ok=n
359		this_build_ok=n
360	fi
361	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
362		>> $mail_msg_file
363	if [ "$?" = "0" ]; then
364		build_ok=n
365		this_build_ok=n
366	fi
367
368	if [ "$W_FLAG" = "n" ]; then
369		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
370		# should be none, but there are a few that are pmake
371		# related, and a couple of silly ones.
372		egrep -i warning: $SRC/${INSTALLOG}.out \
373			| egrep -v '^tic:' \
374			| egrep -v '^mcs:' \
375			| egrep -v '^LD_LIBRARY_PATH=' \
376			| egrep -v 'multiple use of -K option' \
377			| egrep -v 'option -I appears more than once' \
378			| egrep -v 'ar: creating' \
379			| egrep -v 'ar: writing' \
380			| egrep -v 'conflicts:' \
381			| egrep -v ':saved created' \
382			| egrep -v '^stty.*c:' \
383			| egrep -v '^mfgname.c:' \
384			| egrep -v '^uname-i.c:' \
385			| egrep -v '^volumes.c:' \
386			| egrep -v '^lint library construction:' \
387			| egrep -v 'tsort: INFORM:' \
388			| egrep -v 'stripalign:' \
389			| egrep -v 'chars, width' \
390			| egrep -v 'option -zdefs/nodefs appears more than' \
391			| egrep -v "symbol \`timezone' has differing types:" \
392			| egrep -v "parameter <PSTAMP> set to" \
393			| egrep -v "^Manifying" \
394			| egrep -v "Ignoring unknown host" \
395			| egrep -v "redefining segment flags attribute for" \
396			>> $mail_msg_file
397	fi
398
399	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
400		>> $LOGFILE
401
402	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
403	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
404
405	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
406		rm -f $SRC/${NOISE}.ref
407		if [ -f $SRC/${NOISE}.out ]; then
408			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
409		fi
410		grep : $SRC/${INSTALLOG}.out \
411			| egrep -v '^/' \
412			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
413			| egrep -v '^tic:' \
414			| egrep -v '^mcs' \
415			| egrep -v '^LD_LIBRARY_PATH=' \
416			| egrep -v 'multiple use of -K option' \
417			| egrep -v 'option -I appears more than once' \
418			| egrep -v 'ar: creating' \
419			| egrep -v 'ar: writing' \
420			| egrep -v 'conflicts:' \
421			| egrep -v ':saved created' \
422			| egrep -v '^stty.*c:' \
423			| egrep -v '^mfgname.c:' \
424			| egrep -v '^uname-i.c:' \
425			| egrep -v '^volumes.c:' \
426			| egrep -v '^lint library construction:' \
427			| egrep -v 'tsort: INFORM:' \
428			| egrep -v 'stripalign:' \
429			| egrep -v 'chars, width' \
430			| egrep -v 'option -zdefs/nodefs appears more than' \
431			| egrep -v "symbol \`timezone' has differing types:" \
432			| egrep -v 'PSTAMP' \
433			| egrep -v '|%WHOANDWHERE%|' \
434			| egrep -v '^Manifying' \
435			| egrep -v 'Ignoring unknown host' \
436			| egrep -v 'Processing method:' \
437			| egrep -v '^Writing' \
438			| egrep -v 'spellin1:' \
439			| egrep -v '^adding:' \
440			| egrep -v "^echo 'msgid" \
441			| egrep -v '^echo ' \
442			| egrep -v '\.c:$' \
443			| egrep -v '^Adding file:' \
444			| egrep -v 'CLASSPATH=' \
445			| egrep -v '\/var\/mail\/:saved' \
446			| egrep -v -- '-DUTS_VERSION=' \
447			| egrep -v '^Running Mkbootstrap' \
448			| egrep -v '^Applet length read:' \
449			| egrep -v 'bytes written:' \
450			| egrep -v '^File:SolarisAuthApplet.bin' \
451			| egrep -v -i 'jibversion' \
452			| egrep -v '^Output size:' \
453			| egrep -v '^Solo size statistics:' \
454			| egrep -v '^Using ROM API Version' \
455			| egrep -v '^Zero Signature length:' \
456			| egrep -v '^Note \(probably harmless\):' \
457			| egrep -v '::' \
458			| egrep -v -- '-xcache' \
459			| egrep -v '^\+' \
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 proto area
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# If BRINGOVER_FILES was not specified, default to usr
1016#
1017if [ "$BRINGOVER_FILES" = "" ]; then
1018	BRINGOVER_FILES="usr"
1019fi
1020
1021#
1022# Note: changes to the option letters here should also be applied to the
1023#	bldenv script.
1024#
1025OPTIND=1
1026while getopts ABDFNMPTCGIRafinlmoptuUxdrtzWS:X FLAG $NIGHTLY_OPTIONS
1027do
1028	case $FLAG in
1029	  A )	A_FLAG=y
1030		;;
1031	  B )	D_FLAG=y
1032		;; # old version of D
1033	  F )	F_FLAG=y
1034		;;
1035	  D )	D_FLAG=y
1036		;;
1037	  P )	P_FLAG=y
1038		;;
1039	  T )	T_FLAG=y
1040		;;
1041	  C )	C_FLAG=y
1042		;;
1043	  M )	M_FLAG=y
1044		;;
1045	  N )	N_FLAG=y
1046		;;
1047	  G )	a_FLAG=y
1048		u_FLAG=y
1049		;;
1050	  I )	a_FLAG=y
1051		m_FLAG=y
1052		p_FLAG=y
1053		u_FLAG=y
1054		;;
1055	  R )	m_FLAG=y
1056		p_FLAG=y
1057		;;
1058	  a )	a_FLAG=y
1059		;;
1060	  d )	d_FLAG=y
1061		;;
1062	  f )	f_FLAG=y
1063		;;
1064	  i )	i_FLAG=y
1065		;;
1066	  n )	n_FLAG=y
1067		;;
1068	  o )	o_FLAG=y
1069		;;
1070	  l )	l_FLAG=y
1071		;;
1072	  m )	m_FLAG=y
1073		;;
1074	  p )	p_FLAG=y
1075		;;
1076	  r )	r_FLAG=y
1077		;;
1078	  t )	t_FLAG=y
1079		;;
1080	  u )	u_FLAG=y
1081		;;
1082	  z )	z_FLAG=y
1083		;;
1084	  U )
1085		if [ -z "${PARENT_ROOT}" ]; then
1086			echo "PARENT_ROOT must be set if the U flag is" \
1087			    "present in NIGHTLY_OPTIONS."
1088			exit 1
1089		fi
1090		U_FLAG=y
1091		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
1092		;;
1093	  x )	XMOD_OPT="-x"
1094		;;
1095	  W )	W_FLAG=y
1096		;;
1097	  S )
1098		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1099			echo "Can only build one source variant at a time."
1100			exit 1
1101		fi
1102		if [ "${OPTARG}" = "E" ]; then
1103			SE_FLAG=y
1104		elif [ "${OPTARG}" = "D" ]; then
1105			SD_FLAG=y
1106		elif [ "${OPTARG}" = "H" ]; then
1107			SH_FLAG=y
1108		else
1109			echo "$USAGE"
1110			exit 1
1111		fi
1112		;;
1113	  X )	# now that we no longer need realmode builds, just
1114		# copy IHV packages.  only meaningful on x86.
1115		if [ "$MACH" = "i386" ]; then
1116			X_FLAG=y
1117		fi
1118		;;
1119	 \? )	echo "$USAGE"
1120		exit 1
1121		;;
1122	esac
1123done
1124
1125if [ $ISUSER -ne 0 ]; then
1126	if [ "$o_FLAG" = "y" ]; then
1127		echo "Old-style build requires root permission."
1128		exit 1
1129	fi
1130
1131	# Set default value for STAFFER, if needed.
1132	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
1133		STAFFER=`/usr/xpg4/bin/id -un`
1134		export STAFFER
1135	fi
1136fi
1137
1138if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
1139	MAILTO=$STAFFER
1140	export MAILTO
1141fi
1142
1143PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
1144PATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
1145PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
1146export PATH
1147
1148# roots of source trees, both relative to $SRC and absolute.
1149relsrcdirs="."
1150[ -d $SRC/../closed ] && relsrcdirs="$relsrcdirs ../closed"
1151abssrcdirs=""
1152for d in $relsrcdirs; do
1153	abssrcdirs="$abssrcdirs $SRC/$d"
1154done
1155
1156unset CH
1157if [ "$o_FLAG" = "y" ]; then
1158# root invoked old-style build -- make sure it works as it always has
1159# by exporting 'CH'.  The current Makefile.master doesn't use this, but
1160# the old ones still do.
1161	PROTOCMPTERSE="protocmp.terse"
1162	CH=
1163	export CH
1164else
1165	PROTOCMPTERSE="protocmp.terse -gu"
1166fi
1167POUND_SIGN="#"
1168
1169# we export POUND_SIGN to speed up the build process -- prevents evaluation of
1170# the Makefile.master definitions.
1171export o_FLAG POUND_SIGN
1172
1173if [ "$d_FLAG" = "y" ]; then
1174	maketype="distributed"
1175	MAKE=dmake
1176	# get the dmake version string alone
1177	DMAKE_VERSION=$( $MAKE -v )
1178	DMAKE_VERSION=${DMAKE_VERSION#*: }
1179	# focus in on just the dotted version number alone
1180	DMAKE_MAJOR=$( echo $DMAKE_VERSION | \
1181		sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
1182	# extract the second (or final) integer
1183	DMAKE_MINOR=${DMAKE_MAJOR#*.}
1184	DMAKE_MINOR=${DMAKE_MINOR%%.*}
1185	# extract the first integer
1186	DMAKE_MAJOR=${DMAKE_MAJOR%%.*}
1187	CHECK_DMAKE=${CHECK_DMAKE:-y}
1188	# x86 was built on the 12th, sparc on the 13th.
1189	if [ "$CHECK_DMAKE" = "y" -a \
1190	     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
1191	     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
1192	     "$DMAKE_MAJOR" -lt 7 -o \
1193	     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
1194		if [ -z "$DMAKE_VERSION" ]; then
1195			echo "$MAKE is missing."
1196			exit 1
1197		fi
1198		echo `whence $MAKE`" version is:"
1199		echo "  ${DMAKE_VERSION}"
1200		cat <<EOF
1201
1202This version may not be safe for use.  Either set TEAMWARE to a better
1203path or (if you really want to use this version of dmake anyway), add
1204the following to your environment to disable this check:
1205
1206  CHECK_DMAKE=n
1207EOF
1208		exit 1
1209	fi
1210else
1211	PATH="$TEAMWARE/ParallelMake/bin:$PATH"
1212	maketype="parallel"
1213	MAKE=make
1214fi
1215export PATH
1216export MAKE
1217
1218if [ "${SUNWSPRO}" != "" ]; then
1219	PATH="${SUNWSPRO}/bin:$PATH"
1220	export PATH
1221fi
1222
1223hostname=`uname -n`
1224if [ ! -f $HOME/.make.machines ]; then
1225	DMAKE_MAX_JOBS=4
1226else
1227	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
1228	    tail -1 | awk -F= '{print $ 2;}'`"
1229	if [ "$DMAKE_MAX_JOBS" = "" ]; then
1230		DMAKE_MAX_JOBS=4
1231	fi
1232fi
1233DMAKE_MODE=parallel;
1234export DMAKE_MODE
1235export DMAKE_MAX_JOBS
1236
1237if [ -z "${ROOT}" ]; then
1238	echo "ROOT must be set."
1239	exit 1
1240fi
1241
1242if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
1243        if [ -z "${EXPORT_SRC}" ]; then
1244		echo "EXPORT_SRC must be set for a source build."
1245		exit 1
1246	fi
1247        if [ -z "${CRYPT_SRC}" ]; then
1248		echo "CRYPT_SRC must be set for a source build."
1249		exit 1
1250	fi
1251fi
1252
1253if [ "$SH_FLAG" = "y" ]; then
1254        if [ -z "${EXPORT_SRC}" ]; then
1255		echo "EXPORT_SRC must be set for a source build."
1256		exit 1
1257	fi
1258fi
1259
1260#
1261# if -V flag was given, reset VERSION to V_ARG
1262#
1263if [ "$V_FLAG" = "y" ]; then
1264	VERSION=$V_ARG
1265fi
1266
1267#
1268# Check for IHV root for copying ihv proto area
1269#
1270if [ "$X_FLAG" = "y" ]; then
1271        if [ "$IA32_IHV_ROOT" = "" ]; then
1272		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
1273		args_ok=n
1274        fi
1275        if [ ! -d "$IA32_IHV_ROOT" ]; then
1276                echo "$IA32_IHV_ROOT: not found"
1277                args_ok=n
1278        fi
1279fi
1280
1281# Append source version
1282if [ "$SE_FLAG" = "y" ]; then
1283	VERSION="${VERSION}:EXPORT"
1284fi
1285
1286if [ "$SD_FLAG" = "y" ]; then
1287	VERSION="${VERSION}:DOMESTIC"
1288fi
1289
1290if [ "$SH_FLAG" = "y" ]; then
1291	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
1292fi
1293
1294TMPDIR="/tmp/nightly.tmpdir.$$"
1295export TMPDIR
1296rm -rf ${TMPDIR}
1297mkdir -p $TMPDIR || exit 1
1298
1299#
1300# Keep elfsign's use of pkcs11_softtoken from looking in the user home
1301# directory, which doesn't always work.   Needed until all build machines
1302# have the fix for 6271754
1303#
1304SOFTTOKEN_DIR=$TMPDIR
1305export SOFTTOKEN_DIR
1306
1307TOOLS=${SRC}/tools
1308TOOLS_PROTO=${TOOLS}/proto
1309
1310unset   CFLAGS LD_LIBRARY_PATH LDFLAGS
1311
1312# create directories that are automatically removed if the nightly script
1313# fails to start correctly
1314newdir() {
1315	dir=$1
1316	toadd=
1317	while [ ! -d $dir ]; do
1318		toadd="$dir $toadd"
1319		dir=`dirname $dir`
1320	done
1321	torm=
1322	newlist=
1323	for dir in $toadd; do
1324		if staffer mkdir $dir; then
1325			newlist="$ISUSER $dir $newlist"
1326			torm="$dir $torm"
1327		else
1328			[ -z "$torm" ] || staffer rmdir $torm
1329			return 1
1330		fi
1331	done
1332	newdirlist="$newlist $newdirlist"
1333	return 0
1334}
1335newdirlist=
1336
1337[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
1338
1339# since this script assumes the build is from full source, it nullifies
1340# variables likely to have been set by a "ws" script; nullification
1341# confines the search space for headers and libraries to the proto area
1342# built from this immediate source.
1343ENVLDLIBS1=
1344ENVLDLIBS2=
1345ENVLDLIBS3=
1346ENVCPPFLAGS1=
1347ENVCPPFLAGS2=
1348ENVCPPFLAGS3=
1349ENVCPPFLAGS4=
1350PARENT_ROOT=
1351
1352export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1353	PARENT_ROOT
1354
1355ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
1356ENVCPPFLAGS1="-I$ROOT/usr/include"
1357
1358export ENVLDLIBS1 ENVLDLIBS2
1359
1360CPIODIR_ORIG=$CPIODIR
1361PKGARCHIVE_ORIG=$PKGARCHIVE
1362IA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1363if [ "$SPARC_RM_PKGARCHIVE" ]; then
1364	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1365fi
1366
1367#
1368# Juggle the logs and optionally send mail on completion.
1369#
1370
1371logshuffle() {
1372    	LLOG="$ATLOG/log.`date '+%m%d'`"
1373	rm -rf $ATLOG/log.??`date '+%d'`
1374	if [ -f $LLOG -o -d $LLOG ]; then
1375	    	LLOG=$LLOG.$$
1376	fi
1377	mkdir $LLOG
1378
1379	if [ "$build_ok" = "y" ]; then
1380		mv $ATLOG/proto_list_${MACH} $LLOG
1381	fi
1382
1383	#
1384	# Now that we're about to send mail, it's time to check the noise
1385	# file.  In the event that an error occurs beyond this point, it will
1386	# be recorded in the nightly.log file, but nowhere else.  This would
1387	# include only errors that cause the copying of the noise log to fail
1388	# or the mail itself not to be sent.
1389	#
1390
1391	exec >>$LOGFILE 2>&1
1392	if [ -s $build_noise_file ]; then
1393	    	echo "\n==== Nightly build noise ====\n" |
1394		    tee -a $LOGFILE >>$mail_msg_file
1395		cat $build_noise_file >>$LOGFILE
1396		cat $build_noise_file >>$mail_msg_file
1397		echo | tee -a $LOGFILE >>$mail_msg_file
1398	fi
1399	rm -f $build_noise_file
1400
1401	case "$build_ok" in
1402		y)
1403			state=Completed
1404			;;
1405		i)
1406			state=Interrupted
1407			;;
1408		*)
1409	    		state=Failed
1410			;;
1411	esac
1412
1413	cat $build_time_file $mail_msg_file > ${LLOG}/mail_msg
1414	if [ "$m_FLAG" = "y" ]; then
1415	    	cat $build_time_file $mail_msg_file |
1416		    /usr/bin/mailx -s \
1417	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
1418			${MAILTO}
1419	fi
1420
1421	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
1422	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
1423		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
1424	fi
1425
1426	mv $LOGFILE $LLOG
1427}
1428
1429#
1430#	Remove the locks and temporary files on any exit
1431#
1432cleanup() {
1433    	logshuffle
1434
1435	[ -z "$lockfile" ] || staffer rm -f $lockfile
1436	[ -z "$atloglockfile" ] || rm -f $atloglockfile
1437	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
1438	[ -z "$Ulockfile" ] || rm -f $Ulockfile
1439
1440	set -- $newdirlist
1441	while [ $# -gt 0 ]; do
1442		ISUSER=$1 staffer rmdir $2
1443		shift; shift
1444	done
1445	rm -rf $TMPDIR
1446}
1447
1448cleanup_signal() {
1449    	build_ok=i
1450	# this will trigger cleanup(), above.
1451	exit 1
1452}
1453
1454trap cleanup 0
1455trap cleanup_signal 1 2 3 15
1456
1457#
1458# Generic lock file processing -- make sure that the lock file doesn't
1459# exist.  If it does, it should name the build host and PID.  If it
1460# doesn't, then make sure we can create it.  Clean up locks that are
1461# known to be stale (assumes host name is unique among build systems
1462# for the workspace).
1463create_lock() {
1464	lockf=$1
1465	lockvar=$2
1466	if [ -f $lockf ]; then
1467		basews=`basename $CODEMGR_WS`
1468		if read host user pid < $lockf; then
1469			if [ "$host" != "$hostname" ]; then
1470				echo "$MACH build of $basews apparently" \
1471				    "already started by $user on $host as $pid."
1472			elif kill -s 0 $pid 2>/dev/null; then
1473				echo "$MACH build of $basews already started" \
1474				    "by $user as $pid."
1475			else
1476				# stale lock; clear it out and continue
1477				rm -f $lockf
1478			fi
1479		else
1480			echo "$MACH build of $basews already running."
1481		fi
1482	fi
1483	if [ -f $lockf ]; then
1484		echo "Lock file is $lockf."
1485		exit 1
1486	fi
1487	ldir=`dirname $lockf`
1488	[ -d $ldir ] || newdir $ldir || exit 1
1489	eval $lockvar=$lockf
1490	staffer sh -c "echo $hostname $STAFFER $$ > $lockf" || exit 1
1491}
1492
1493# Ensure no other instance of this script is running on this host.
1494# LOCKNAME can be set in <env_file>, and is by default, but is not
1495# required due to the use of $ATLOG below.
1496if [ -n "$LOCKNAME" ]; then
1497	create_lock /tmp/$LOCKNAME "lockfile"
1498fi
1499#
1500# Create from one, two, or three other locks:
1501#	$ATLOG/nightly.lock
1502#		- protects against multiple builds in same workspace
1503#	$PARENT_WS/usr/src/nightly.$MACH.lock
1504#		- protects against multiple 'u' copy-backs
1505#	$NIGHTLY_PARENT_ROOT/nightly.lock
1506#		- protects against multiple 'U' copy-backs
1507#
1508# Overriding ISUSER to 1 causes the lock to be created as root if the
1509# script is run as root.  The default is to create it as $STAFFER.
1510ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1511if [ "$u_FLAG" = "y" ]; then
1512	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1513fi
1514if [ "$U_FLAG" = "y" ]; then
1515	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1516	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1517fi
1518
1519# Locks have been taken, so we're doing a build and we're committed to
1520# the directories we may have created so far.
1521newdirlist=
1522
1523#
1524# Create mail_msg_file
1525#
1526mail_msg_file="${TMPDIR}/mail_msg"
1527touch $mail_msg_file
1528build_time_file="${TMPDIR}/build_time"
1529#
1530#	Move old LOGFILE aside
1531#	ATLOG directory already made by 'create_lock' above
1532#
1533if [ -f $LOGFILE ]; then
1534	mv -f $LOGFILE ${LOGFILE}-
1535fi
1536#
1537#	Build OsNet source
1538#
1539START_DATE=`date`
1540SECONDS=0
1541echo "\n==== Nightly $maketype build started:   $START_DATE ====" \
1542    | tee -a $LOGFILE > $build_time_file
1543
1544# make sure we log only to the nightly build file
1545build_noise_file="${TMPDIR}/build_noise"
1546exec </dev/null >$build_noise_file 2>&1
1547
1548echo "\n==== list of environment variables ====\n" >> $LOGFILE
1549env >> $LOGFILE
1550
1551echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1552
1553if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1554	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
1555		echo "WARNING: the -S flags do not support incremental" \
1556		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
1557		i_FLAG=n
1558		i_CMD_LINE_FLAG=n
1559	fi
1560	if [ "$N_FLAG" = "n" ]; then
1561		echo "WARNING: the -S flags do not support protocmp;" \
1562		    "protocmp disabled\n" | \
1563		    tee -a $mail_msg_file >> $LOGFILE
1564		N_FLAG=y
1565	fi
1566	if [ "$l_FLAG" = "y" ]; then
1567		echo "WARNING: the -S flags do not support lint;" \
1568		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1569		l_FLAG=n
1570	fi
1571	if [ "$C_FLAG" = "y" ]; then
1572		echo "WARNING: the -S flags do not support cstyle;" \
1573		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1574		C_FLAG=n
1575	fi
1576else
1577	if [ "$N_FLAG" = "y" ]; then
1578		if [ "$p_FLAG" = "y" ]; then
1579			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1580WARNING: the p option (create packages) is set, but so is the N option (do
1581         not run protocmp); this is dangerous; you should unset the N option
1582EOF
1583		else
1584			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1585Warning: the N option (do not run protocmp) is set; it probably shouldn't be
1586EOF
1587		fi
1588		echo "" | tee -a $mail_msg_file >> $LOGFILE
1589	fi
1590fi
1591
1592if [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
1593	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
1594	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
1595fi
1596
1597if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1598	echo "WARNING: DEBUG build not requested, but lint will be with" \
1599	    "DEBUG enabled.\n" \
1600	    | tee -a $mail_msg_file >> $LOGFILE
1601fi
1602
1603if [ "$f_FLAG" = "y" ]; then
1604	if [ "$i_FLAG" = "y" ]; then
1605		echo "WARNING: the -f flag cannot be used during incremental" \
1606		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1607		f_FLAG=n
1608	fi
1609	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
1610		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
1611		    tee -a $mail_msg_file >> $LOGFILE
1612		f_FLAG=n
1613	fi
1614fi
1615
1616if [ "$T_FLAG" = "y" -a -d $SRC/uts/common/dtrace ]; then
1617	echo "WARNING: TRACE build requested but workspace contains DTrace;" \
1618	    "-T will have no effect\n" | tee -a $mail_msg_file >> $LOGFILE
1619fi
1620
1621if [ "$t_FLAG" = "n" ]; then
1622	#
1623	# We're not doing a tools build, so make sure elfsign(1) is
1624	# new enough to safely sign non-crypto binaries.  We test
1625	# debugging output from elfsign to detect the old version.
1626	#
1627	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
1628	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
1629	    | egrep algorithmOID`
1630	if [ -z "$newelfsigntest" ]; then
1631		echo "WARNING: /usr/bin/elfsign out of date;" \
1632		    "will only sign crypto modules\n" | \
1633		    tee -a $mail_msg_file >> $LOGFILE
1634		export ELFSIGN_OBJECT=true
1635	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
1636		echo "WARNING: VERIFY_ELFSIGN=y requires" \
1637		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
1638		    tee -a $mail_msg_file >> $LOGFILE
1639	fi
1640fi
1641
1642# copy ihv proto area in addition to the build itself
1643
1644if [ "$X_FLAG" = "y" ]; then
1645
1646	# Install IA32 IHV proto area
1647	copy_ihv_proto
1648fi
1649
1650echo "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
1651
1652# System
1653whence uname | tee -a $mail_msg_file >> $LOGFILE
1654uname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
1655echo | tee -a $mail_msg_file >> $LOGFILE
1656
1657# nightly (will fail in year 2100 due to SCCS flaw)
1658echo "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
1659echo "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
1660
1661# make
1662whence $MAKE | tee -a $mail_msg_file >> $LOGFILE
1663if [ "$d_FLAG" = "y" ]; then
1664	$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
1665fi
1666echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1667    tee -a $mail_msg_file >> $LOGFILE
1668
1669#
1670# Report the compiler versions.
1671#
1672if [ -f $SRC/Makefile ]; then
1673	srcroot=$SRC
1674elif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
1675	srcroot=$BRINGOVER_WS/usr/src
1676else
1677	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
1678	    tee -a $mail_msg_file >> $LOGFILE
1679	exit 1
1680fi
1681
1682( cd $srcroot
1683  for target in cc-version cc64-version java-version; do
1684	echo
1685	#
1686	# Put statefile somewhere we know we can write to rather than trip
1687	# over a read-only $srcroot.  Use /usr/ccs/bin/make here because
1688	# it supports -K and ParallelMake doesn't.
1689	#
1690	rm -f $TMPDIR/make-state
1691	if /usr/ccs/bin/make -K $TMPDIR/make-state -e $target 2>/dev/null; then
1692		continue
1693	fi
1694	touch $TMPDIR/nocompiler
1695  done
1696  echo
1697) | tee -a $mail_msg_file >> $LOGFILE
1698
1699if [ -f $TMPDIR/nocompiler ]; then
1700	rm -f $TMPDIR/nocompiler
1701	build_ok=n
1702	echo "Aborting due to missing compiler." |
1703		tee -a $mail_msg_file >> $LOGFILE
1704	exit 1
1705fi
1706
1707# as
1708whence as | tee -a $mail_msg_file >> $LOGFILE
1709as -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
1710echo | tee -a $mail_msg_file >> $LOGFILE
1711
1712# Check that we're running a capable link-editor
1713whence ld | tee -a $mail_msg_file >> $LOGFILE
1714LDVER=`ld -V 2>&1`
1715echo $LDVER | tee -a $mail_msg_file >> $LOGFILE
1716LDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
1717if [ `expr $LDVER \< 422` -eq 1 ]; then
1718	echo "The link-editor needs to be at version 422 or higher to build" | \
1719	    tee -a $mail_msg_file >> $LOGFILE
1720	echo "the latest stuff, hope your build works." | \
1721	    tee -a $mail_msg_file >> $LOGFILE
1722fi
1723
1724echo "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1725    tee -a $mail_msg_file >> $LOGFILE
1726
1727echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1728echo $VERSION | tee -a $mail_msg_file >> $LOGFILE
1729
1730#
1731#	Decide whether to clobber
1732#
1733if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
1734	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
1735
1736	cd $SRC
1737	# remove old clobber file
1738	rm -f $SRC/clobber.out
1739	rm -f $SRC/clobber-${MACH}.out
1740
1741	# Remove all .make.state* files, just in case we are restarting
1742	# the build after having interrupted a previous 'make clobber'.
1743	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
1744	    -o -name '.make.*' -print | xargs rm -f
1745
1746	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
1747	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
1748	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1749		egrep -v "Ignoring unknown host" \
1750		>> $mail_msg_file
1751
1752	if [ "$t_FLAG" = "y" ]; then
1753		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
1754		cd ${TOOLS}
1755		rm -f ${TOOLS}/clobber-${MACH}.out
1756		$MAKE -ek clobber 2>&1 | \
1757			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
1758		echo "\n==== Make tools clobber ERRORS ====\n" \
1759			>> $mail_msg_file
1760		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1761			>> $mail_msg_file
1762		rm -rf ${TOOLS_PROTO}
1763		mkdir -p ${TOOLS_PROTO}
1764	fi
1765	rm -rf $ROOT
1766
1767	# Get back to a clean workspace as much as possible to catch
1768	# problems that only occur on fresh workspaces.
1769	# Remove all .make.state* files, libraries, and .o's that may
1770	# have been omitted from clobber.  A couple of libraries are
1771	# under SCCS, so leave them alone.
1772	# We should probably blow away temporary directories too.
1773	cd $SRC
1774	find $relsrcdirs \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
1775	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1776	       -name '*.o' \) -print | \
1777	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
1778else
1779	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
1780fi
1781
1782#
1783#	Decide whether to bringover to the codemgr workspace
1784#
1785if [ "$n_FLAG" = "n" ]; then
1786	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
1787	# sleep on the parent workspace's lock
1788	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
1789	do
1790		sleep 120
1791	done
1792
1793	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
1794	staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
1795	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 | \
1796		tee -a  $mail_msg_file >> $LOGFILE
1797	if [ $? -eq 1 ]
1798	then
1799		echo "trouble with bringover, quitting at `date`." >> $LOGFILE
1800		exit 1
1801	fi
1802else
1803	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
1804fi
1805
1806#
1807# Build tools if requested
1808#
1809if [ "$t_FLAG" = "y" ]; then
1810	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
1811	export RELEASE_BUILD ; RELEASE_BUILD=
1812	unset EXTRA_OPTIONS
1813	unset EXTRA_CFLAGS
1814
1815	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
1816	build_tools ${TOOLS_PROTO}
1817fi
1818
1819if [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
1820	echo "\n==== NOT Building base OS-Net source ====\n" | \
1821	    tee -a $LOGFILE >> $mail_msg_file
1822else
1823	normal_build
1824fi
1825
1826ORIG_SRC=$SRC
1827BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
1828
1829if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1830	save_binaries
1831
1832	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
1833	SCCSHELPER=${TMPDIR}/sccs-helper
1834	rm -f ${SCCSHELPER}
1835cat >${SCCSHELPER} <<EOF
1836#!/bin/ksh
1837cd \$1
1838cd ..
1839sccs get SCCS >/dev/null 2>&1
1840EOF
1841	cd $SRC
1842	chmod +x ${SCCSHELPER}
1843	find $relsrcdirs -name SCCS | xargs -L 1 ${SCCSHELPER}
1844	rm -f ${SCCSHELPER}
1845fi
1846
1847if [ "$SD_FLAG" = "y" ]; then
1848	clone_source ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
1849fi
1850
1851# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
1852# $SRC pointing to the export_source usr/src.
1853if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1854	clone_source ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
1855fi
1856
1857if [ "$SD_FLAG" = "y" ]; then
1858	# drop the crypt files in place.
1859	cd ${EXPORT_SRC}
1860	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
1861	    >> ${LOGFILE}
1862	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
1863	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
1864	if [ "$?" = "0" ]; then
1865		echo "\n==== DOMESTIC extraction succeeded ====\n" \
1866		    >> $mail_msg_file
1867	else
1868		echo "\n==== DOMESTIC extraction failed ====\n" \
1869		    >> $mail_msg_file
1870	fi
1871
1872fi
1873
1874if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1875	# remove proto area here, since we don't clobber
1876	rm -rf "$ROOT"
1877	if [ "$t_FLAG" = "y" ]; then
1878		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
1879		export RELEASE_BUILD ; RELEASE_BUILD=
1880		unset EXTRA_OPTIONS
1881		unset EXTRA_CFLAGS
1882
1883		build_tools ${EXPORT_SRC}/usr/src/tools/proto
1884	fi
1885
1886	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
1887	normal_build
1888fi
1889
1890if [ "$build_ok" = "y" ]; then
1891	echo "\n==== Creating protolist system file at `date` ====" \
1892		>> $LOGFILE
1893	protolist $ROOT > $ATLOG/proto_list_${MACH}
1894	echo "==== protolist system file created at `date` ====\n" \
1895		>> $LOGFILE
1896
1897	if [ "$N_FLAG" != "y" ]; then
1898		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
1899
1900		# If there is a reference proto list, compare the build's proto
1901		# list with the reference to see changes in proto areas.
1902		# Use the current exception list.
1903		exc=etc/exception_list_$MACH
1904		if [ -f $SRC/pkgdefs/$exc ]; then
1905			ELIST="-e $SRC/pkgdefs/$exc"
1906		fi
1907
1908		if [ -f "$REF_PROTO_LIST" ]; then
1909			$PROTOCMPTERSE \
1910			  "Files in yesterday's proto area, but not today's:" \
1911			  "Files in today's proto area, but not yesterday's:" \
1912			  "Files that changed between yesterday and today:" \
1913			  ${ELIST} \
1914			  -d $REF_PROTO_LIST \
1915			  $ATLOG/proto_list_${MACH} \
1916				>> $mail_msg_file
1917		fi
1918		# Compare the build's proto list with current package
1919		# definitions to audit the quality of package definitions
1920		# and makefile install targets. Use the current exception list.
1921		PKGDEFS_LIST=""
1922		for d in $abssrcdirs; do
1923			if [ -d $d/pkgdefs ]; then
1924				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
1925			fi
1926		done
1927
1928		$PROTOCMPTERSE \
1929		    "Files missing from the proto area:" \
1930		    "Files missing from packages:" \
1931		    "Inconsistencies between pkgdefs and proto area:" \
1932		    ${ELIST} \
1933		    ${PKGDEFS_LIST} \
1934		    $ATLOG/proto_list_${MACH} \
1935		    >> $mail_msg_file
1936	fi
1937fi
1938
1939if [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
1940	staffer cp $ATLOG/proto_list_${MACH} \
1941		$PARENT_WS/usr/src/proto_list_${MACH}
1942fi
1943
1944# Update parent proto area if necessary. This is done now
1945# so that the proto area has either DEBUG or non-DEBUG kernels.
1946# Note that this clears out the lock file, so we can dispense with
1947# the variable now.
1948if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
1949	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
1950	    tee -a $LOGFILE >> $mail_msg_file
1951	# The rm -rf command below produces predictable errors if
1952	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
1953	# and that directory is accessed via NFS.  This is because
1954	# deleted-but-still-open files don't actually disappear as
1955	# expected, but rather turn into .nfsXXXX junk files, leaving
1956	# the directory non-empty.  Since this is a not-unusual usage
1957	# pattern, and we still want to catch other errors here, we
1958	# take the unusal step of moving aside 'nightly' from that
1959	# directory (if we're using it).
1960	mypath=${0##*/root_$MACH/}
1961	if [ "$mypath" = $0 ]; then
1962		mypath=opt/onbld/bin/${0##*/}
1963	fi
1964	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
1965		mv -f $0 $PARENT_WS/proto/root_$MACH
1966	fi
1967	rm -rf $PARENT_WS/proto/root_$MACH/*
1968	unset Ulockfile
1969	mkdir -p $NIGHTLY_PARENT_ROOT
1970	cd $ROOT
1971	( tar cf - . | ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
1972		tee -a $mail_msg_file >> $LOGFILE
1973fi
1974
1975#
1976# do shared library interface verification
1977#
1978
1979if [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
1980	echo "\n==== Check versioning and ABI information ====\n"  | \
1981	    tee -a $LOGFILE >> $mail_msg_file
1982
1983	rm -rf $SRC/interfaces.ref
1984	if [ -d $SRC/interfaces.out ]; then
1985		mv $SRC/interfaces.out $SRC/interfaces.ref
1986	fi
1987	rm -rf $SRC/interfaces.out
1988	mkdir -p $SRC/interfaces.out
1989
1990	intf_check -V -m -o -b $SRC/tools/abi/etc \
1991		-d $SRC/interfaces.out $ROOT 2>&1 | sort \
1992		> $SRC/interfaces.out/log
1993
1994	# report any ERROR found in log file
1995	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
1996		tee -a $LOGFILE >> $mail_msg_file
1997
1998	if [ ! -d $SRC/interfaces.ref ] ; then
1999		mkdir -p $SRC/interfaces.ref
2000		if [ -d  $SRC/interfaces.out ]; then
2001			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
2002		fi
2003	fi
2004
2005	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
2006	    tee -a $LOGFILE >> $mail_msg_file
2007
2008	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
2009	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
2010
2011	# Report any differences in WARNING messages between last
2012	# and current build.
2013	if [ "$out_vers" = "$ref_vers" ]; then
2014		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
2015		    fgrep 'WARNING' | sed 's/WARNING: //' | \
2016		    tee -a $LOGFILE >> $mail_msg_file
2017	fi
2018fi
2019
2020if [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
2021	echo "\n==== Check ELF runtime attributes ====\n" | \
2022	    tee -a $LOGFILE >> $mail_msg_file
2023
2024	LDDUSAGE="^ldd: does not support -e"
2025	LDDWRONG="wrong class"
2026	CRLERROR="^crle:"
2027	CRLECONF="^crle: configuration file:"
2028
2029	rm -f $SRC/runtime.ref
2030	if [ -f $SRC/runtime.out ]; then
2031		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2032			$SRC/runtime.out > $SRC/runtime.ref
2033	fi
2034
2035	# If we're doing a debug build the proto area will be left with
2036	# debuggable objects, thus don't assert -s.
2037	if [ "$D_FLAG" = "y" ]; then
2038		rtime_sflag=""
2039	else
2040		rtime_sflag="-s"
2041	fi
2042	check_rtime -d $ROOT -i -m -o $rtime_sflag $ROOT 2>&1 | \
2043	    egrep -v ": unreferenced object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
2044	    egrep -v ": unused object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
2045	    sort >$SRC/runtime.out
2046
2047	# Determine any processing errors that will affect the final output
2048	# and display these first.
2049	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
2050	if [ $? -eq 0 ]; then
2051	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
2052		tee -a $LOGFILE >> $mail_msg_file
2053	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
2054		tee -a $LOGFILE >> $mail_msg_file
2055	fi
2056	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
2057	if [ $? -eq 0 ]; then
2058	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
2059		tee -a $LOGFILE >> $mail_msg_file
2060	    echo "to execute an object, thus it could not be checked fully." | \
2061		tee -a $LOGFILE >> $mail_msg_file
2062	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
2063		tee -a $LOGFILE >> $mail_msg_file
2064	    echo "or an i386 object was encountered on a sparc system?\n" | \
2065		tee -a $LOGFILE >> $mail_msg_file
2066	fi
2067	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
2068	if [ $? -eq 0 ]; then
2069	    echo "WARNING: creation of an alternative dependency cache failed." | \
2070		tee -a $LOGFILE >> $mail_msg_file
2071	    echo "Dependencies will bind to the base system libraries.\n" | \
2072		tee -a $LOGFILE >> $mail_msg_file
2073	    grep "$CRLECONF" $SRC/runtime.out | \
2074		tee -a $LOGFILE >> $mail_msg_file
2075	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
2076		tee -a $LOGFILE >> $mail_msg_file
2077	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
2078	fi
2079
2080	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
2081	    tee -a $LOGFILE >> $mail_msg_file
2082
2083	# NEEDED= and RPATH= are informational; report anything else that we
2084	# haven't already.
2085	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2086	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
2087
2088	# probably should compare against a 'known ok runpaths' list
2089	if [ ! -f $SRC/runtime.ref ]; then
2090		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2091			$SRC/runtime.out >  $SRC/runtime.ref
2092	fi
2093
2094	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
2095	    >> $mail_msg_file
2096
2097	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
2098	    diff $SRC/runtime.ref - >> $mail_msg_file
2099fi
2100
2101# For now, don't make archives or packages for GPROF/TRACE builds
2102a_FLAG=n
2103p_FLAG=n
2104
2105# GPROF build begins
2106
2107if [ "$i_CMD_LINE_FLAG" = "n" -a "$P_FLAG" = "y" ]; then
2108
2109	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
2110	export RELEASE_BUILD ; RELEASE_BUILD=
2111	export EXTRA_OPTIONS ; EXTRA_OPTIONS="-DGPROF"
2112	export EXTRA_CFLAGS ; EXTRA_CFLAGS="-xpg"
2113
2114	build GPROF -prof
2115
2116else
2117	echo "\n==== No GPROF build ====\n" >> $LOGFILE
2118fi
2119
2120# GPROF build ends
2121
2122# TRACE build begins
2123
2124if [ "$i_CMD_LINE_FLAG" = "n" -a "$T_FLAG" = "y" ]; then
2125
2126	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
2127	export RELEASE_BUILD ; RELEASE_BUILD=
2128	export EXTRA_OPTIONS ; EXTRA_OPTIONS="-DTRACE"
2129	unset EXTRA_CFLAGS
2130
2131	build TRACE -trace
2132
2133else
2134	echo "\n==== No TRACE build ====\n" >> $LOGFILE
2135fi
2136
2137# TRACE build ends
2138
2139# DEBUG lint of kernel begins
2140
2141if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2142	if [ "$LINTDIRS" = "" ]; then
2143		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2144		LINTDIRS="$SRC y"
2145	fi
2146	set $LINTDIRS
2147	while [ $# -gt 0 ]; do
2148		dolint $1 $2; shift; shift
2149	done
2150else
2151	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2152fi
2153
2154# "make check" begins
2155
2156if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2157	# remove old check.out
2158	rm -f $SRC/check.out
2159
2160	rm -f $SRC/check-${MACH}.out
2161	cd $SRC
2162	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
2163	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2164
2165	grep ":" $SRC/check-${MACH}.out |
2166		egrep -v "Ignoring unknown host" | \
2167		sort | uniq >> $mail_msg_file
2168else
2169	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2170fi
2171
2172echo "\n==== Find core files ====\n" | \
2173    tee -a $LOGFILE >> $mail_msg_file
2174
2175find $abssrcdirs -name core -a -type f -exec file {} \; | \
2176	tee -a $LOGFILE >> $mail_msg_file
2177
2178if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2179	echo "\n==== Diff unreferenced files (since last build) ====\n" \
2180	    | tee -a $LOGFILE >>$mail_msg_file
2181	rm -f $SRC/unref-${MACH}.ref
2182	if [ -f $SRC/unref-${MACH}.out ]; then
2183		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2184	fi
2185
2186	findunref -t $SRC/.build.tstamp $SRC/.. \
2187	    ${TOOLS}/findunref/exception_list \
2188	    2>> $mail_msg_file | sort | \
2189	    sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
2190	    > $SRC/unref-${MACH}.out
2191
2192	if [ ! -f $SRC/unref-${MACH}.ref ]; then
2193		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2194	fi
2195
2196	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
2197fi
2198
2199# Verify that the usual lists of files, such as exception lists,
2200# contain only valid references to files.  If the build has failed,
2201# then don't check the proto area.
2202CHECK_PATHS=${CHECK_PATHS:-y}
2203if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
2204	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
2205		>>$mail_msg_file
2206	arg=-b
2207	[ "$build_ok" = y ] && arg=
2208	checkpaths $arg $ROOT 2>&1 | tee -a $LOGFILE >>$mail_msg_file
2209fi
2210
2211if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2212	echo "\n==== Impact on file permissions ====\n" \
2213		>> $mail_msg_file
2214	#
2215	# Get pkginfo files from usr/src/pkgdefs
2216	#
2217	pmodes -qvdP \
2218	`for d in $SRC/pkgdefs $SRC/../closed/pkgdefs; do
2219		if [ -d "$d" ]
2220		then
2221			find $d -name pkginfo.tmpl -print -o -name .del\* -prune
2222		fi
2223	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
2224fi
2225
2226END_DATE=`date`
2227echo "==== Nightly $maketype build completed: $END_DATE ====" | \
2228    tee -a $LOGFILE >> $build_time_file
2229
2230typeset -Z2 minutes
2231typeset -Z2 seconds
2232
2233elapsed_time=$SECONDS
2234((hours = elapsed_time / 3600 ))
2235((minutes = elapsed_time / 60  % 60))
2236((seconds = elapsed_time % 60))
2237
2238echo "\n==== Total build time ====" | \
2239    tee -a $LOGFILE >> $build_time_file
2240echo "\nreal    ${hours}:${minutes}:${seconds}" | \
2241    tee -a $LOGFILE >> $build_time_file
2242
2243if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2244	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
2245
2246	#
2247	# Produce a master list of unreferenced files -- ideally, we'd
2248	# generate the master just once after all of the nightlies
2249	# have finished, but there's no simple way to know when that
2250	# will be.  Instead, we assume that we're the last nightly to
2251	# finish and merge all of the unref-${MACH}.out files in
2252	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
2253	# finish, then this file will be the authoritative master
2254	# list.  Otherwise, another ${MACH}'s nightly will eventually
2255	# overwrite ours with its own master, but in the meantime our
2256	# temporary "master" will be no worse than any older master
2257	# which was already on the parent.
2258	#
2259
2260	set -- $PARENT_WS/usr/src/unref-*.out
2261	cp "$1" ${TMPDIR}/unref.merge
2262	shift
2263
2264	for unreffile; do
2265		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
2266		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
2267	done
2268
2269	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
2270fi
2271
2272#
2273# All done save for the sweeping up.
2274# (whichever exit we hit here will trigger the "cleanup" trap which
2275# optionally sends mail on completion).
2276#
2277if [ "$build_ok" = "y" ]; then
2278	exit 0
2279fi
2280exit 1
2281