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