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