xref: /titanic_41/usr/src/tools/scripts/nightly.sh (revision 4610e4a00999c6d2291b3fc263926b890ec500a5)
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 proto area
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#
1261# Check for IHV root for copying ihv proto area
1262#
1263if [ "$X_FLAG" = "y" ]; then
1264        if [ "$IA32_IHV_ROOT" = "" ]; then
1265		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
1266		args_ok=n
1267        fi
1268        if [ ! -d "$IA32_IHV_ROOT" ]; then
1269                echo "$IA32_IHV_ROOT: not found"
1270                args_ok=n
1271        fi
1272fi
1273
1274# Append source version
1275if [ "$SE_FLAG" = "y" ]; then
1276	VERSION="${VERSION}:EXPORT"
1277fi
1278
1279if [ "$SD_FLAG" = "y" ]; then
1280	VERSION="${VERSION}:DOMESTIC"
1281fi
1282
1283if [ "$SH_FLAG" = "y" ]; then
1284	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
1285fi
1286
1287TMPDIR="/tmp/nightly.tmpdir.$$"
1288export TMPDIR
1289rm -rf ${TMPDIR}
1290mkdir -p $TMPDIR || exit 1
1291
1292#
1293# Keep elfsign's use of pkcs11_softtoken from looking in the user home
1294# directory, which doesn't always work.   Needed until all build machines
1295# have the fix for 6271754
1296#
1297SOFTTOKEN_DIR=$TMPDIR
1298export SOFTTOKEN_DIR
1299
1300TOOLS=${SRC}/tools
1301TOOLS_PROTO=${TOOLS}/proto
1302
1303unset   CFLAGS LD_LIBRARY_PATH LDFLAGS
1304
1305# create directories that are automatically removed if the nightly script
1306# fails to start correctly
1307newdir() {
1308	dir=$1
1309	toadd=
1310	while [ ! -d $dir ]; do
1311		toadd="$dir $toadd"
1312		dir=`dirname $dir`
1313	done
1314	torm=
1315	newlist=
1316	for dir in $toadd; do
1317		if staffer mkdir $dir; then
1318			newlist="$ISUSER $dir $newlist"
1319			torm="$dir $torm"
1320		else
1321			[ -z "$torm" ] || staffer rmdir $torm
1322			return 1
1323		fi
1324	done
1325	newdirlist="$newlist $newdirlist"
1326	return 0
1327}
1328newdirlist=
1329
1330[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
1331
1332# since this script assumes the build is from full source, it nullifies
1333# variables likely to have been set by a "ws" script; nullification
1334# confines the search space for headers and libraries to the proto area
1335# built from this immediate source.
1336ENVLDLIBS1=
1337ENVLDLIBS2=
1338ENVLDLIBS3=
1339ENVCPPFLAGS1=
1340ENVCPPFLAGS2=
1341ENVCPPFLAGS3=
1342ENVCPPFLAGS4=
1343PARENT_ROOT=
1344
1345export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1346	PARENT_ROOT
1347
1348ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
1349ENVCPPFLAGS1="-I$ROOT/usr/include"
1350
1351export ENVLDLIBS1 ENVLDLIBS2
1352
1353CPIODIR_ORIG=$CPIODIR
1354PKGARCHIVE_ORIG=$PKGARCHIVE
1355IA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1356if [ "$SPARC_RM_PKGARCHIVE" ]; then
1357	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1358fi
1359
1360#
1361# Juggle the logs and optionally send mail on completion.
1362#
1363
1364logshuffle() {
1365    	LLOG="$ATLOG/log.`date '+%m%d'`"
1366	rm -rf $ATLOG/log.??`date '+%d'`
1367	if [ -f $LLOG -o -d $LLOG ]; then
1368	    	LLOG=$LLOG.$$
1369	fi
1370	mkdir $LLOG
1371
1372	if [ "$build_ok" = "y" ]; then
1373		mv $ATLOG/proto_list_${MACH} $LLOG
1374	fi
1375
1376	#
1377	# Now that we're about to send mail, it's time to check the noise
1378	# file.  In the event that an error occurs beyond this point, it will
1379	# be recorded in the nightly.log file, but nowhere else.  This would
1380	# include only errors that cause the copying of the noise log to fail
1381	# or the mail itself not to be sent.
1382	#
1383
1384	exec >>$LOGFILE 2>&1
1385	if [ -s $build_noise_file ]; then
1386	    	echo "\n==== Nightly build noise ====\n" |
1387		    tee -a $LOGFILE >>$mail_msg_file
1388		cat $build_noise_file >>$LOGFILE
1389		cat $build_noise_file >>$mail_msg_file
1390		echo | tee -a $LOGFILE >>$mail_msg_file
1391	fi
1392	rm -f $build_noise_file
1393
1394	case "$build_ok" in
1395		y)
1396			state=Completed
1397			;;
1398		i)
1399			state=Interrupted
1400			;;
1401		*)
1402	    		state=Failed
1403			;;
1404	esac
1405
1406	cat $build_time_file $mail_msg_file > ${LLOG}/mail_msg
1407	if [ "$m_FLAG" = "y" ]; then
1408	    	cat $build_time_file $mail_msg_file |
1409		    /usr/bin/mailx -s \
1410	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
1411			${MAILTO}
1412	fi
1413
1414	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
1415	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
1416		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
1417	fi
1418
1419	mv $LOGFILE $LLOG
1420}
1421
1422#
1423#	Remove the locks and temporary files on any exit
1424#
1425cleanup() {
1426    	logshuffle
1427
1428	[ -z "$lockfile" ] || staffer rm -f $lockfile
1429	[ -z "$atloglockfile" ] || rm -f $atloglockfile
1430	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
1431	[ -z "$Ulockfile" ] || rm -f $Ulockfile
1432
1433	set -- $newdirlist
1434	while [ $# -gt 0 ]; do
1435		ISUSER=$1 staffer rmdir $2
1436		shift; shift
1437	done
1438	rm -rf $TMPDIR
1439}
1440
1441cleanup_signal() {
1442    	build_ok=i
1443	# this will trigger cleanup(), above.
1444	exit 1
1445}
1446
1447trap cleanup 0
1448trap cleanup_signal 1 2 3 15
1449
1450#
1451# Generic lock file processing -- make sure that the lock file doesn't
1452# exist.  If it does, it should name the build host and PID.  If it
1453# doesn't, then make sure we can create it.  Clean up locks that are
1454# known to be stale (assumes host name is unique among build systems
1455# for the workspace).
1456create_lock() {
1457	lockf=$1
1458	lockvar=$2
1459	if [ -f $lockf ]; then
1460		basews=`basename $CODEMGR_WS`
1461		if read host user pid < $lockf; then
1462			if [ "$host" != "$hostname" ]; then
1463				echo "$MACH build of $basews apparently" \
1464				    "already started by $user on $host as $pid."
1465			elif kill -s 0 $pid 2>/dev/null; then
1466				echo "$MACH build of $basews already started" \
1467				    "by $user as $pid."
1468			else
1469				# stale lock; clear it out and continue
1470				rm -f $lockf
1471			fi
1472		else
1473			echo "$MACH build of $basews already running."
1474		fi
1475	fi
1476	if [ -f $lockf ]; then
1477		echo "Lock file is $lockf."
1478		exit 1
1479	fi
1480	ldir=`dirname $lockf`
1481	[ -d $ldir ] || newdir $ldir || exit 1
1482	eval $lockvar=$lockf
1483	staffer sh -c "echo $hostname $STAFFER $$ > $lockf" || exit 1
1484}
1485
1486# Ensure no other instance of this script is running on this host.
1487# LOCKNAME can be set in <env_file>, and is by default, but is not
1488# required due to the use of $ATLOG below.
1489if [ -n "$LOCKNAME" ]; then
1490	create_lock /tmp/$LOCKNAME "lockfile"
1491fi
1492#
1493# Create from one, two, or three other locks:
1494#	$ATLOG/nightly.lock
1495#		- protects against multiple builds in same workspace
1496#	$PARENT_WS/usr/src/nightly.$MACH.lock
1497#		- protects against multiple 'u' copy-backs
1498#	$NIGHTLY_PARENT_ROOT/nightly.lock
1499#		- protects against multiple 'U' copy-backs
1500#
1501# Overriding ISUSER to 1 causes the lock to be created as root if the
1502# script is run as root.  The default is to create it as $STAFFER.
1503ISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
1504if [ "$u_FLAG" = "y" ]; then
1505	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
1506fi
1507if [ "$U_FLAG" = "y" ]; then
1508	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
1509	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
1510fi
1511
1512# Locks have been taken, so we're doing a build and we're committed to
1513# the directories we may have created so far.
1514newdirlist=
1515
1516#
1517# Create mail_msg_file
1518#
1519mail_msg_file="${TMPDIR}/mail_msg"
1520touch $mail_msg_file
1521build_time_file="${TMPDIR}/build_time"
1522#
1523#	Move old LOGFILE aside
1524#	ATLOG directory already made by 'create_lock' above
1525#
1526if [ -f $LOGFILE ]; then
1527	mv -f $LOGFILE ${LOGFILE}-
1528fi
1529#
1530#	Build OsNet source
1531#
1532START_DATE=`date`
1533SECONDS=0
1534echo "\n==== Nightly $maketype build started:   $START_DATE ====" \
1535    | tee -a $LOGFILE > $build_time_file
1536
1537# make sure we log only to the nightly build file
1538build_noise_file="${TMPDIR}/build_noise"
1539exec </dev/null >$build_noise_file 2>&1
1540
1541echo "\n==== list of environment variables ====\n" >> $LOGFILE
1542env >> $LOGFILE
1543
1544echo "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
1545
1546if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1547	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
1548		echo "WARNING: the -S flags do not support incremental" \
1549		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
1550		i_FLAG=n
1551		i_CMD_LINE_FLAG=n
1552	fi
1553	if [ "$N_FLAG" = "n" ]; then
1554		echo "WARNING: the -S flags do not support protocmp;" \
1555		    "protocmp disabled\n" | \
1556		    tee -a $mail_msg_file >> $LOGFILE
1557		N_FLAG=y
1558	fi
1559	if [ "$l_FLAG" = "y" ]; then
1560		echo "WARNING: the -S flags do not support lint;" \
1561		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1562		l_FLAG=n
1563	fi
1564	if [ "$C_FLAG" = "y" ]; then
1565		echo "WARNING: the -S flags do not support cstyle;" \
1566		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
1567		C_FLAG=n
1568	fi
1569else
1570	if [ "$N_FLAG" = "y" ]; then
1571		if [ "$p_FLAG" = "y" ]; then
1572			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1573WARNING: the p option (create packages) is set, but so is the N option (do
1574         not run protocmp); this is dangerous; you should unset the N option
1575EOF
1576		else
1577			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
1578Warning: the N option (do not run protocmp) is set; it probably shouldn't be
1579EOF
1580		fi
1581		echo "" | tee -a $mail_msg_file >> $LOGFILE
1582	fi
1583fi
1584
1585if [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
1586	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
1587	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
1588fi
1589
1590if [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
1591	echo "WARNING: DEBUG build not requested, but lint will be with" \
1592	    "DEBUG enabled.\n" \
1593	    | tee -a $mail_msg_file >> $LOGFILE
1594fi
1595
1596if [ "$f_FLAG" = "y" ]; then
1597	if [ "$i_FLAG" = "y" ]; then
1598		echo "WARNING: the -f flag cannot be used during incremental" \
1599		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
1600		f_FLAG=n
1601	fi
1602	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
1603		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
1604		    tee -a $mail_msg_file >> $LOGFILE
1605		f_FLAG=n
1606	fi
1607fi
1608
1609if [ "$T_FLAG" = "y" -a -d $SRC/uts/common/dtrace ]; then
1610	echo "WARNING: TRACE build requested but workspace contains DTrace;" \
1611	    "-T will have no effect\n" | tee -a $mail_msg_file >> $LOGFILE
1612fi
1613
1614if [ "$t_FLAG" = "n" ]; then
1615	#
1616	# We're not doing a tools build, so make sure elfsign(1) is
1617	# new enough to safely sign non-crypto binaries.  We test
1618	# debugging output from elfsign to detect the old version.
1619	#
1620	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
1621	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
1622	    | egrep algorithmOID`
1623	if [ -z "$newelfsigntest" ]; then
1624		echo "WARNING: /usr/bin/elfsign out of date;" \
1625		    "will only sign crypto modules\n" | \
1626		    tee -a $mail_msg_file >> $LOGFILE
1627		export ELFSIGN_OBJECT=true
1628	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
1629		echo "WARNING: VERIFY_ELFSIGN=y requires" \
1630		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
1631		    tee -a $mail_msg_file >> $LOGFILE
1632	fi
1633fi
1634
1635# copy ihv proto area in addition to the build itself
1636
1637if [ "$X_FLAG" = "y" ]; then
1638
1639	# Install IA32 IHV proto area
1640	copy_ihv_proto
1641fi
1642
1643echo "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
1644
1645# System
1646whence uname | tee -a $mail_msg_file >> $LOGFILE
1647uname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
1648echo | tee -a $mail_msg_file >> $LOGFILE
1649
1650# nightly (will fail in year 2100 due to SCCS flaw)
1651echo "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
1652echo "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
1653
1654# make
1655whence $MAKE | tee -a $mail_msg_file >> $LOGFILE
1656if [ "$d_FLAG" = "y" ]; then
1657	$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
1658fi
1659echo "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1660    tee -a $mail_msg_file >> $LOGFILE
1661
1662#
1663# Report the compiler versions.
1664#
1665if [ -f $SRC/Makefile ]; then
1666	srcroot=$SRC
1667elif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
1668	srcroot=$BRINGOVER_WS/usr/src
1669else
1670	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
1671	    tee -a $mail_msg_file >> $LOGFILE
1672	exit 1
1673fi
1674
1675( cd $srcroot
1676  for target in cc-version cc64-version java-version; do
1677	echo
1678	#
1679	# Put statefile somewhere we know we can write to rather than trip
1680	# over a read-only $srcroot.  Use /usr/ccs/bin/make here because
1681	# it supports -K and ParallelMake doesn't.
1682	#
1683	rm -f $TMPDIR/make-state
1684	if /usr/ccs/bin/make -K $TMPDIR/make-state -e $target 2>/dev/null; then
1685		continue
1686	fi
1687	touch $TMPDIR/nocompiler
1688  done
1689  echo
1690) | tee -a $mail_msg_file >> $LOGFILE
1691
1692if [ -f $TMPDIR/nocompiler ]; then
1693	rm -f $TMPDIR/nocompiler
1694	build_ok=n
1695	echo "Aborting due to missing compiler." |
1696		tee -a $mail_msg_file >> $LOGFILE
1697	exit 1
1698fi
1699
1700# as
1701whence as | tee -a $mail_msg_file >> $LOGFILE
1702as -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
1703echo | tee -a $mail_msg_file >> $LOGFILE
1704
1705# Check that we're running a capable link-editor
1706whence ld | tee -a $mail_msg_file >> $LOGFILE
1707LDVER=`ld -V 2>&1`
1708echo $LDVER | tee -a $mail_msg_file >> $LOGFILE
1709LDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
1710if [ `expr $LDVER \< 422` -eq 1 ]; then
1711	echo "The link-editor needs to be at version 422 or higher to build" | \
1712	    tee -a $mail_msg_file >> $LOGFILE
1713	echo "the latest stuff, hope your build works." | \
1714	    tee -a $mail_msg_file >> $LOGFILE
1715fi
1716
1717echo "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1718    tee -a $mail_msg_file >> $LOGFILE
1719
1720echo "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
1721echo $VERSION | tee -a $mail_msg_file >> $LOGFILE
1722
1723#
1724#	Decide whether to clobber
1725#
1726if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
1727	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
1728
1729	cd $SRC
1730	# remove old clobber file
1731	rm -f $SRC/clobber.out
1732	rm -f $SRC/clobber-${MACH}.out
1733
1734	# Remove all .make.state* files, just in case we are restarting
1735	# the build after having interrupted a previous 'make clobber'.
1736	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
1737	    -o -name '.make.*' -print | xargs rm -f
1738
1739	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
1740	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
1741	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1742		egrep -v "Ignoring unknown host" \
1743		>> $mail_msg_file
1744
1745	if [ "$t_FLAG" = "y" ]; then
1746		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
1747		cd ${TOOLS}
1748		rm -f ${TOOLS}/clobber-${MACH}.out
1749		$MAKE -ek clobber 2>&1 | \
1750			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
1751		echo "\n==== Make tools clobber ERRORS ====\n" \
1752			>> $mail_msg_file
1753		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
1754			>> $mail_msg_file
1755		rm -rf ${TOOLS_PROTO}
1756		mkdir -p ${TOOLS_PROTO}
1757	fi
1758	rm -rf $ROOT
1759
1760	# Get back to a clean workspace as much as possible to catch
1761	# problems that only occur on fresh workspaces.
1762	# Remove all .make.state* files, libraries, and .o's that may
1763	# have been ommitted from clobber.
1764	# We should probably blow away temporary directories too.
1765	cd $SRC
1766	find . \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
1767	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1768	       -name '*.o' \) -print | xargs rm -f
1769else
1770	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
1771fi
1772
1773#
1774#	Decide whether to bringover to the codemgr workspace
1775#
1776if [ "$n_FLAG" = "n" ]; then
1777	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
1778	# sleep on the parent workspace's lock
1779	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
1780	do
1781		sleep 120
1782	done
1783
1784	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
1785	staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
1786	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 | \
1787		tee -a  $mail_msg_file >> $LOGFILE
1788	if [ $? -eq 1 ]
1789	then
1790		echo "trouble with bringover, quitting at `date`." >> $LOGFILE
1791		exit 1
1792	fi
1793	if [ -d $SRC/cmd/lp/cmd/lpsched/lpsched -a \
1794	    ! -f $SRC/cmd/lp/cmd/lpsched/lpsched/Makefile ]; then
1795		# on297 printing
1796		rm -rf $SRC/cmd/lp/cmd/lpsched/lpsched
1797	fi
1798	if [ -d $SRC/cmd/localedef/localedef -a \
1799	    ! -f $SRC/cmd/localedef/localedef/Makefile ]; then
1800		# on297 CSI project
1801		rm -rf $SRC/cmd/localedef/localedef
1802	fi
1803else
1804	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
1805fi
1806
1807#
1808# Build tools if requested
1809#
1810if [ "$t_FLAG" = "y" ]; then
1811	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
1812	export RELEASE_BUILD ; RELEASE_BUILD=
1813	unset EXTRA_OPTIONS
1814	unset EXTRA_CFLAGS
1815
1816	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
1817	build_tools ${TOOLS_PROTO}
1818fi
1819
1820if [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
1821	echo "\n==== NOT Building base OS-Net source ====\n" | \
1822	    tee -a $LOGFILE >> $mail_msg_file
1823else
1824	normal_build
1825fi
1826
1827ORIG_SRC=$SRC
1828BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
1829
1830if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1831	save_binaries
1832
1833	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
1834	SCCSHELPER=${TMPDIR}/sccs-helper
1835	rm -f ${SCCSHELPER}
1836cat >${SCCSHELPER} <<EOF
1837#!/bin/ksh
1838cd \$1
1839cd ..
1840sccs get SCCS >/dev/null 2>&1
1841EOF
1842	cd $SRC
1843	chmod +x ${SCCSHELPER}
1844	find . -name SCCS | xargs -L 1 ${SCCSHELPER}
1845	rm -f ${SCCSHELPER}
1846fi
1847
1848if [ "$SD_FLAG" = "y" ]; then
1849	clone_source ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
1850fi
1851
1852# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
1853# $SRC pointing to the export_source usr/src.
1854if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1855	clone_source ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
1856fi
1857
1858if [ "$SD_FLAG" = "y" ]; then
1859	# drop the crypt files in place.
1860	cd ${EXPORT_SRC}
1861	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
1862	    >> ${LOGFILE}
1863	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
1864	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
1865	if [ "$?" = "0" ]; then
1866		echo "\n==== DOMESTIC extraction succeeded ====\n" \
1867		    >> $mail_msg_file
1868	else
1869		echo "\n==== DOMESTIC extraction failed ====\n" \
1870		    >> $mail_msg_file
1871	fi
1872
1873fi
1874
1875if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
1876	# remove proto area here, since we don't clobber
1877	rm -rf "$ROOT"
1878	if [ "$t_FLAG" = "y" ]; then
1879		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
1880		export RELEASE_BUILD ; RELEASE_BUILD=
1881		unset EXTRA_OPTIONS
1882		unset EXTRA_CFLAGS
1883
1884		build_tools ${EXPORT_SRC}/usr/src/tools/proto
1885	fi
1886
1887	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
1888	normal_build
1889fi
1890
1891if [ "$build_ok" = "y" ]; then
1892	echo "\n==== Creating protolist system file at `date` ====" \
1893		>> $LOGFILE
1894	protolist $ROOT > $ATLOG/proto_list_${MACH}
1895	echo "==== protolist system file created at `date` ====\n" \
1896		>> $LOGFILE
1897
1898	if [ "$N_FLAG" != "y" ]; then
1899		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
1900
1901		# If there is a reference proto list, compare the build's proto
1902		# list with the reference to see changes in proto areas.
1903		# Use the current exception list.
1904		exc=etc/exception_list_$MACH
1905		if [ -f $SRC/pkgdefs/$exc ]; then
1906			ELIST="-e $SRC/pkgdefs/$exc"
1907		fi
1908
1909		if [ -f "$REF_PROTO_LIST" ]; then
1910			$PROTOCMPTERSE \
1911			  "Files in yesterday's proto area, but not today's:" \
1912			  "Files in today's proto area, but not yesterday's:" \
1913			  "Files that changed between yesterday and today:" \
1914			  ${ELIST} \
1915			  -d $REF_PROTO_LIST \
1916			  $ATLOG/proto_list_${MACH} \
1917				>> $mail_msg_file
1918		fi
1919		# Compare the build's proto list with current package
1920		# definitions to audit the quality of package definitions
1921		# and makefile install targets. Use the current exception list.
1922		PKGDEFS_LIST="-d $SRC/pkgdefs"
1923
1924		$PROTOCMPTERSE \
1925		    "Files missing from the proto area:" \
1926		    "Files missing from packages:" \
1927		    "Inconsistencies between pkgdefs and proto area:" \
1928		    ${ELIST} \
1929		    ${PKGDEFS_LIST} \
1930		    $ATLOG/proto_list_${MACH} \
1931		    >> $mail_msg_file
1932	fi
1933fi
1934
1935if [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
1936	staffer cp $ATLOG/proto_list_${MACH} \
1937		$PARENT_WS/usr/src/proto_list_${MACH}
1938fi
1939
1940# Update parent proto area if necessary. This is done now
1941# so that the proto area has either DEBUG or non-DEBUG kernels.
1942# Note that this clears out the lock file, so we can dispense with
1943# the variable now.
1944if [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
1945	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
1946	    tee -a $LOGFILE >> $mail_msg_file
1947	# The rm -rf command below produces predictable errors if
1948	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
1949	# and that directory is accessed via NFS.  This is because
1950	# deleted-but-still-open files don't actually disappear as
1951	# expected, but rather turn into .nfsXXXX junk files, leaving
1952	# the directory non-empty.  Since this is a not-unusual usage
1953	# pattern, and we still want to catch other errors here, we
1954	# take the unusal step of moving aside 'nightly' from that
1955	# directory (if we're using it).
1956	mypath=${0##*/root_$MACH/}
1957	if [ "$mypath" = $0 ]; then
1958		mypath=opt/onbld/bin/${0##*/}
1959	fi
1960	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
1961		mv -f $0 $PARENT_WS/proto/root_$MACH
1962	fi
1963	rm -rf $PARENT_WS/proto/root_$MACH/*
1964	unset Ulockfile
1965	mkdir -p $NIGHTLY_PARENT_ROOT
1966	cd $ROOT
1967	( tar cf - . | ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
1968		tee -a $mail_msg_file >> $LOGFILE
1969fi
1970
1971#
1972# do shared library interface verification
1973#
1974
1975if [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
1976	echo "\n==== Check versioning and ABI information ====\n"  | \
1977	    tee -a $LOGFILE >> $mail_msg_file
1978
1979	rm -rf $SRC/interfaces.ref
1980	if [ -d $SRC/interfaces.out ]; then
1981		mv $SRC/interfaces.out $SRC/interfaces.ref
1982	fi
1983	rm -rf $SRC/interfaces.out
1984	mkdir -p $SRC/interfaces.out
1985
1986	intf_check -V -m -o -b $SRC/tools/abi/etc \
1987		-d $SRC/interfaces.out $ROOT 2>&1 | sort \
1988		> $SRC/interfaces.out/log
1989
1990	# report any ERROR found in log file
1991	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
1992		tee -a $LOGFILE >> $mail_msg_file
1993
1994	if [ ! -d $SRC/interfaces.ref ] ; then
1995		mkdir -p $SRC/interfaces.ref
1996		if [ -d  $SRC/interfaces.out ]; then
1997			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
1998		fi
1999	fi
2000
2001	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
2002	    tee -a $LOGFILE >> $mail_msg_file
2003
2004	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
2005	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
2006
2007	# Report any differences in WARNING messages between last
2008	# and current build.
2009	if [ "$out_vers" = "$ref_vers" ]; then
2010		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
2011		    fgrep 'WARNING' | sed 's/WARNING: //' | \
2012		    tee -a $LOGFILE >> $mail_msg_file
2013	fi
2014fi
2015
2016if [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
2017	echo "\n==== Check ELF runtime attributes ====\n" | \
2018	    tee -a $LOGFILE >> $mail_msg_file
2019
2020	LDDUSAGE="^ldd: does not support -e"
2021	LDDWRONG="wrong class"
2022	CRLERROR="^crle:"
2023	CRLECONF="^crle: configuration file:"
2024
2025	rm -f $SRC/runtime.ref
2026	if [ -f $SRC/runtime.out ]; then
2027		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2028			$SRC/runtime.out > $SRC/runtime.ref
2029	fi
2030
2031	# If we're doing a debug build the proto area will be left with
2032	# debuggable objects, thus don't assert -s.
2033	if [ "$D_FLAG" = "y" ]; then
2034		rtime_sflag=""
2035	else
2036		rtime_sflag="-s"
2037	fi
2038	check_rtime -d $ROOT -i -m -o $rtime_sflag $ROOT 2>&1 | \
2039	    egrep -v ": unreferenced object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
2040	    egrep -v ": unused object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
2041	    sort >$SRC/runtime.out
2042
2043	# Determine any processing errors that will affect the final output
2044	# and display these first.
2045	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
2046	if [ $? -eq 0 ]; then
2047	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
2048		tee -a $LOGFILE >> $mail_msg_file
2049	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
2050		tee -a $LOGFILE >> $mail_msg_file
2051	fi
2052	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
2053	if [ $? -eq 0 ]; then
2054	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
2055		tee -a $LOGFILE >> $mail_msg_file
2056	    echo "to execute an object, thus it could not be checked fully." | \
2057		tee -a $LOGFILE >> $mail_msg_file
2058	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
2059		tee -a $LOGFILE >> $mail_msg_file
2060	    echo "or an i386 object was encountered on a sparc system?\n" | \
2061		tee -a $LOGFILE >> $mail_msg_file
2062	fi
2063	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
2064	if [ $? -eq 0 ]; then
2065	    echo "WARNING: creation of an alternative dependency cache failed." | \
2066		tee -a $LOGFILE >> $mail_msg_file
2067	    echo "Dependencies will bind to the base system libraries.\n" | \
2068		tee -a $LOGFILE >> $mail_msg_file
2069	    grep "$CRLECONF" $SRC/runtime.out | \
2070		tee -a $LOGFILE >> $mail_msg_file
2071	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
2072		tee -a $LOGFILE >> $mail_msg_file
2073	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
2074	fi
2075
2076	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
2077	    tee -a $LOGFILE >> $mail_msg_file
2078
2079	# NEEDED= and RPATH= are informational; report anything else that we
2080	# haven't already.
2081	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2082	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
2083
2084	# probably should compare against a 'known ok runpaths' list
2085	if [ ! -f $SRC/runtime.ref ]; then
2086		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
2087			$SRC/runtime.out >  $SRC/runtime.ref
2088	fi
2089
2090	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
2091	    >> $mail_msg_file
2092
2093	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
2094	    diff $SRC/runtime.ref - >> $mail_msg_file
2095fi
2096
2097# For now, don't make archives or packages for GPROF/TRACE builds
2098a_FLAG=n
2099p_FLAG=n
2100
2101# GPROF build begins
2102
2103if [ "$i_CMD_LINE_FLAG" = "n" -a "$P_FLAG" = "y" ]; then
2104
2105	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
2106	export RELEASE_BUILD ; RELEASE_BUILD=
2107	export EXTRA_OPTIONS ; EXTRA_OPTIONS="-DGPROF"
2108	export EXTRA_CFLAGS ; EXTRA_CFLAGS="-xpg"
2109
2110	build GPROF -prof
2111
2112else
2113	echo "\n==== No GPROF build ====\n" >> $LOGFILE
2114fi
2115
2116# GPROF build ends
2117
2118# TRACE build begins
2119
2120if [ "$i_CMD_LINE_FLAG" = "n" -a "$T_FLAG" = "y" ]; then
2121
2122	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
2123	export RELEASE_BUILD ; RELEASE_BUILD=
2124	export EXTRA_OPTIONS ; EXTRA_OPTIONS="-DTRACE"
2125	unset EXTRA_CFLAGS
2126
2127	build TRACE -trace
2128
2129else
2130	echo "\n==== No TRACE build ====\n" >> $LOGFILE
2131fi
2132
2133# TRACE build ends
2134
2135# DEBUG lint of kernel begins
2136
2137if [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
2138	if [ "$LINTDIRS" = "" ]; then
2139		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
2140		LINTDIRS="$SRC y"
2141	fi
2142	set $LINTDIRS
2143	while [ $# -gt 0 ]; do
2144		dolint $1 $2; shift; shift
2145	done
2146else
2147	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
2148fi
2149
2150# "make check" begins
2151
2152if [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
2153	# remove old check.out
2154	rm -f $SRC/check.out
2155
2156	rm -f $SRC/check-${MACH}.out
2157	cd $SRC
2158	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
2159	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
2160
2161	grep ":" $SRC/check-${MACH}.out |
2162		egrep -v "Ignoring unknown host" | \
2163		sort | uniq >> $mail_msg_file
2164else
2165	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
2166fi
2167
2168echo "\n==== Find core files ====\n" | \
2169    tee -a $LOGFILE >> $mail_msg_file
2170
2171find $SRC -name core -a -type f -exec file {} \; | \
2172	tee -a $LOGFILE >> $mail_msg_file
2173
2174if [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2175	echo "\n==== Diff unreferenced files (since last build) ====\n" \
2176	    | tee -a $LOGFILE >>$mail_msg_file
2177	rm -f $SRC/unref-${MACH}.ref
2178	if [ -f $SRC/unref-${MACH}.out ]; then
2179		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2180	fi
2181
2182	findunref $SRC ${TOOLS}/findunref/exception_list \
2183	    2>> $mail_msg_file | sort > $SRC/unref-${MACH}.out
2184
2185	if [ ! -f $SRC/unref-${MACH}.ref ]; then
2186		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
2187	fi
2188
2189	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
2190fi
2191
2192# Verify that the usual lists of files, such as exception lists,
2193# contain only valid references to files.  If the build has failed,
2194# then don't check the proto area.
2195CHECK_PATHS=${CHECK_PATHS:-y}
2196if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
2197	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
2198		>>$mail_msg_file
2199	arg=-b
2200	[ "$build_ok" = y ] && arg=
2201	checkpaths $arg $ROOT 2>&1 | tee -a $LOGFILE >>$mail_msg_file
2202fi
2203
2204if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2205	echo "\n==== Impact on file permissions ====\n" \
2206		>> $mail_msg_file
2207	#
2208	# Get pkginfo files from usr/src/pkgdefs
2209	#
2210	pmodes -qvdP \
2211	`for d in $SRC/pkgdefs; do
2212		if [ -d "$d" ]
2213		then
2214			find $d -name pkginfo.tmpl -print -o -name .del\* -prune
2215		fi
2216	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
2217fi
2218
2219END_DATE=`date`
2220echo "==== Nightly $maketype build completed: $END_DATE ====" | \
2221    tee -a $LOGFILE >> $build_time_file
2222
2223typeset -Z2 minutes
2224typeset -Z2 seconds
2225
2226elapsed_time=$SECONDS
2227((hours = elapsed_time / 3600 ))
2228((minutes = elapsed_time / 60  % 60))
2229((seconds = elapsed_time % 60))
2230
2231echo "\n==== Total build time ====" | \
2232    tee -a $LOGFILE >> $build_time_file
2233echo "\nreal    ${hours}:${minutes}:${seconds}" | \
2234    tee -a $LOGFILE >> $build_time_file
2235
2236if [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
2237	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
2238
2239	#
2240	# Produce a master list of unreferenced files -- ideally, we'd
2241	# generate the master just once after all of the nightlies
2242	# have finished, but there's no simple way to know when that
2243	# will be.  Instead, we assume that we're the last nightly to
2244	# finish and merge all of the unref-${MACH}.out files in
2245	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
2246	# finish, then this file will be the authoritative master
2247	# list.  Otherwise, another ${MACH}'s nightly will eventually
2248	# overwrite ours with its own master, but in the meantime our
2249	# temporary "master" will be no worse than any older master
2250	# which was already on the parent.
2251	#
2252
2253	set -- $PARENT_WS/usr/src/unref-*.out
2254	cp "$1" ${TMPDIR}/unref.merge
2255	shift
2256
2257	for unreffile; do
2258		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
2259		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
2260	done
2261
2262	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
2263fi
2264
2265#
2266# All done save for the sweeping up.
2267# (whichever exit we hit here will trigger the "cleanup" trap which
2268# optionally sends mail on completion).
2269#
2270if [ "$build_ok" = "y" ]; then
2271	exit 0
2272fi
2273exit 1
2274