xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision c0e7977a434048a8bc7386ea0e8befaa77a646cf)
17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6fb23a357Skupfer# Common Development and Distribution License (the "License").
7fb23a357Skupfer# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
224e5b757fSkupfer
237c478bd9Sstevel@tonic-gate#
24b83ec4edSjmcp# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25445b6314SRichard Lowe# Copyright 2008, 2010, Richard Lowe
26d7693b08SRoland Mainz# Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
273cb00cf1SJoshua M. Clulow# Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
307c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
317c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
347c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
37d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
38d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
437c478bd9Sstevel@tonic-gate#
447c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
457c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
487c478bd9Sstevel@tonic-gate#
497c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
507c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
517c478bd9Sstevel@tonic-gate#
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate#
547c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
557c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
567c478bd9Sstevel@tonic-gate#
577c478bd9Sstevel@tonic-gateunset CDPATH
587c478bd9Sstevel@tonic-gate
59cdf0c1d5Smjnelson# Get the absolute path of the nightly script that the user invoked.  This
60cdf0c1d5Smjnelson# may be a relative path, and we need to do this before changing directory.
61cdf0c1d5Smjnelsonnightly_path=`whence $0`
62cdf0c1d5Smjnelson
63cdf0c1d5Smjnelson#
64cdf0c1d5Smjnelson# Keep track of where we found nightly so we can invoke the matching
65cdf0c1d5Smjnelson# which_scm script.  If that doesn't work, don't go guessing, just rely
66cdf0c1d5Smjnelson# on the $PATH settings, which will generally give us either /opt/onbld
67cdf0c1d5Smjnelson# or the user's workspace.
68cdf0c1d5Smjnelson#
69cdf0c1d5SmjnelsonWHICH_SCM=$(dirname $nightly_path)/which_scm
70cdf0c1d5Smjnelsonif [[ ! -x $WHICH_SCM ]]; then
71cdf0c1d5Smjnelson	WHICH_SCM=which_scm
72cdf0c1d5Smjnelsonfi
73cdf0c1d5Smjnelson
74d7693b08SRoland Mainzfunction fatal_error
75d7693b08SRoland Mainz{
76d7693b08SRoland Mainz	print -u2 "nightly: $*"
77d7693b08SRoland Mainz	exit 1
78d7693b08SRoland Mainz}
79d7693b08SRoland Mainz
804e5b757fSkupfer#
814e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
827c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
837c478bd9Sstevel@tonic-gate# non-DEBUG packages.
844e5b757fSkupfer#
85b83ec4edSjmcp# usage: normal_build
86ead1f93eSLiane Praza#
87597bd30bSMike Kupferfunction normal_build {
887c478bd9Sstevel@tonic-gate
8952a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
90597bd30bSMike Kupfer	typeset crypto_signer="$CODESIGN_USER"
914e5b757fSkupfer
924e5b757fSkupfer	suffix=""
93ead1f93eSLiane Praza
947c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
974e5b757fSkupfer		set_non_debug_build_flags
98597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
996ea3c060SGarrett D'Amore		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
1004e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1014e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1027c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
1037c478bd9Sstevel@tonic-gate		fi
1047c478bd9Sstevel@tonic-gate	else
10552a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1067c478bd9Sstevel@tonic-gate	fi
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate	# DEBUG build begins
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
1134e5b757fSkupfer		set_debug_build_flags
114597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
1156ea3c060SGarrett D'Amore		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
1164e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1174e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1187c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
1197c478bd9Sstevel@tonic-gate		fi
1207c478bd9Sstevel@tonic-gate	else
12152a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1227c478bd9Sstevel@tonic-gate	fi
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate	# DEBUG build ends
1254e5b757fSkupfer
12652a52aebSkupfer	p_FLAG="$orig_p_FLAG"
1277c478bd9Sstevel@tonic-gate}
1287c478bd9Sstevel@tonic-gate
1291fe69678Skupfer#
13047703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
13147703246Ssommerfe#
13247703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
13347703246Ssommerfe# our logs and then run the command with ARGS
13447703246Ssommerfe#
135597bd30bSMike Kupferfunction run_hook {
13647703246Ssommerfe	HOOKNAME=$1
13747703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
13847703246Ssommerfe	shift
13947703246Ssommerfe
14047703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
14147703246Ssommerfe	    	(
14247703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
14347703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
14447703246Ssommerfe			if [ "$?" -ne 0 ]; then
14547703246Ssommerfe			    	# Let exit status propagate up
14647703246Ssommerfe			    	touch $TMPDIR/abort
14747703246Ssommerfe			fi
14847703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
14947703246Ssommerfe
15047703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
15147703246Ssommerfe			build_ok=n
15247703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
15347703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
15447703246Ssommerfe			exit 1
15547703246Ssommerfe		fi
15647703246Ssommerfe	fi
15747703246Ssommerfe}
15847703246Ssommerfe
15947703246Ssommerfe#
1601fe69678Skupfer# usage: filelist DESTDIR PATTERN
1611fe69678Skupfer#
162597bd30bSMike Kupferfunction filelist {
1637c478bd9Sstevel@tonic-gate	DEST=$1
1647c478bd9Sstevel@tonic-gate	PATTERN=$2
1657c478bd9Sstevel@tonic-gate	cd ${DEST}
1667c478bd9Sstevel@tonic-gate}
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
1697c478bd9Sstevel@tonic-gate# restoration
170597bd30bSMike Kupferfunction save_binaries {
1717c478bd9Sstevel@tonic-gate	# save off list of binaries
1727c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
1737c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1747c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
1757c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
1767c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
1777c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
1787c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
1797c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
1807c478bd9Sstevel@tonic-gate}
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate# delete files
1831fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
184597bd30bSMike Kupferfunction hybridize_files {
1857c478bd9Sstevel@tonic-gate	DEST=$1
1867c478bd9Sstevel@tonic-gate	MAKETARG=$2
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
1897c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1907c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
1917c478bd9Sstevel@tonic-gate	do
1927c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
1937c478bd9Sstevel@tonic-gate		rm -rf "${i}"
1947c478bd9Sstevel@tonic-gate	done
1957c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
1967c478bd9Sstevel@tonic-gate	do
1977c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
1987c478bd9Sstevel@tonic-gate		rm -f ${i}+
1997c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
2007c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
2017c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
2027c478bd9Sstevel@tonic-gate	done
2037c478bd9Sstevel@tonic-gate}
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
2061fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
207597bd30bSMike Kupferfunction restore_binaries {
2087c478bd9Sstevel@tonic-gate	DEST=$1
2097c478bd9Sstevel@tonic-gate	MAKETARG=$2
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
2127c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2137c478bd9Sstevel@tonic-gate	cd ${DEST}
2147c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
2157c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
2167c478bd9Sstevel@tonic-gate}
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate# rename files we save binaries of
2191fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
220597bd30bSMike Kupferfunction rename_files {
2217c478bd9Sstevel@tonic-gate	DEST=$1
2227c478bd9Sstevel@tonic-gate	MAKETARG=$2
2237c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
2247c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2257c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
2267c478bd9Sstevel@tonic-gate	do
2277c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
2287c478bd9Sstevel@tonic-gate		rm -f ${i}.export
2297c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
2307c478bd9Sstevel@tonic-gate	done
2317c478bd9Sstevel@tonic-gate}
2327c478bd9Sstevel@tonic-gate
2331fe69678Skupfer#
2341fe69678Skupfer# Copy some or all of the source tree.
235cdf0c1d5Smjnelson#
236cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
237cdf0c1d5Smjnelson#
2381fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
2391fe69678Skupfer#
240597bd30bSMike Kupferfunction copy_source {
2417c478bd9Sstevel@tonic-gate	WS=$1
2427c478bd9Sstevel@tonic-gate	DEST=$2
2431fe69678Skupfer	label=$3
2441fe69678Skupfer	srcroot=$4
2457c478bd9Sstevel@tonic-gate
246cdf0c1d5Smjnelson	printf "\n==== Creating %s source from %s (%s) ====\n\n" \
247cdf0c1d5Smjnelson	    "$DEST" "$WS" "$label" | tee -a $mail_msg_file >> $LOGFILE
248cdf0c1d5Smjnelson
249cdf0c1d5Smjnelson	printf "cleaning out %s\n" "$DEST." >> $LOGFILE
250cdf0c1d5Smjnelson	rm -rf "$DEST" >> $LOGFILE 2>&1
251cdf0c1d5Smjnelson
252cdf0c1d5Smjnelson	printf "creating %s\n" "$DEST." >> $LOGFILE
253cdf0c1d5Smjnelson	mkdir -p "$DEST" 2>> $LOGFILE
254cdf0c1d5Smjnelson
255cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
256cdf0c1d5Smjnelson		printf "failed to create %s\n" "$DEST" |
2577c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
258cdf0c1d5Smjnelson		build_ok=n
259cdf0c1d5Smjnelson		return 1
260cdf0c1d5Smjnelson	fi
261cdf0c1d5Smjnelson	cd "$WS"
2627c478bd9Sstevel@tonic-gate
263cdf0c1d5Smjnelson	printf "populating %s\n" "$DEST." >> $LOGFILE
2647c478bd9Sstevel@tonic-gate
265cdf0c1d5Smjnelson	case "$SCM_TYPE" in
266cdf0c1d5Smjnelson	teamware)
2671fe69678Skupfer		find $srcroot -name 's\.*' -a -type f -print | \
2687c478bd9Sstevel@tonic-gate		    sed -e 's,SCCS\/s.,,' | \
2697c478bd9Sstevel@tonic-gate		    grep -v '/\.del-*' | \
270cdf0c1d5Smjnelson		    cpio -pd $DEST >>$LOGFILE 2>&1
271cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
272cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$DEST" |
273cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
274cdf0c1d5Smjnelson		    build_ok=n
275cdf0c1d5Smjnelson		    return 1
276cdf0c1d5Smjnelson		fi
277cdf0c1d5Smjnelson		;;
278cdf0c1d5Smjnelson	mercurial)
279cdf0c1d5Smjnelson		copy_source_mercurial $DEST $srcroot
280cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
281cdf0c1d5Smjnelson		    build_ok=n
282cdf0c1d5Smjnelson		    return 1
283cdf0c1d5Smjnelson		fi
284cdf0c1d5Smjnelson		;;
285cdf0c1d5Smjnelson	*)
286cdf0c1d5Smjnelson		build_ok=n
287cdf0c1d5Smjnelson		echo "Tree copy is not supported for workspace type" \
288cdf0c1d5Smjnelson		    "$SCM_TYPE" | tee -a $mail_msg_file >> $LOGFILE
289cdf0c1d5Smjnelson		return 1
290cdf0c1d5Smjnelson		;;
291cdf0c1d5Smjnelson	esac
292cdf0c1d5Smjnelson
293cdf0c1d5Smjnelson	return 0
294cdf0c1d5Smjnelson}
295cdf0c1d5Smjnelson
296cdf0c1d5Smjnelson#
297*c0e7977aSJosef 'Jeff' Sipek# Mercurial-specific copy code for copy_source().
298cdf0c1d5Smjnelson#
299cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
300cdf0c1d5Smjnelson#
301cdf0c1d5Smjnelson# usage: copy_source_mercurial destdir srcroot
302cdf0c1d5Smjnelson#
303cdf0c1d5Smjnelsonfunction copy_source_mercurial {
304cdf0c1d5Smjnelson	typeset dest=$1
305cdf0c1d5Smjnelson	typeset srcroot=$2
306cdf0c1d5Smjnelson
307*c0e7977aSJosef 'Jeff' Sipek	hg locate -I "$srcroot" | cpio -pd "$dest" >>$LOGFILE 2>&1
308cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
309cdf0c1d5Smjnelson	    printf "cpio failed for %s\n" "$dest" |
310cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
311cdf0c1d5Smjnelson	    return 1
312cdf0c1d5Smjnelson	fi
313cdf0c1d5Smjnelson
314cdf0c1d5Smjnelson	return 0
3151fe69678Skupfer}
3167c478bd9Sstevel@tonic-gate
3171fe69678Skupfer#
3181fe69678Skupfer# function to create (but not build) the export/crypt source tree.
3191fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
3201fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
3211fe69678Skupfer# builds the tree.
3221fe69678Skupfer#
323597bd30bSMike Kupferfunction set_up_source_build {
3241fe69678Skupfer	WS=$1
3251fe69678Skupfer	DEST=$2
3261fe69678Skupfer	MAKETARG=$3
3271fe69678Skupfer
3281fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
329cdf0c1d5Smjnelson	if (( $? != 0 )); then
330cdf0c1d5Smjnelson	    echo "\nCould not copy source tree for source build." |
331cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
332cdf0c1d5Smjnelson	    build_ok=n
333cdf0c1d5Smjnelson	    return
334cdf0c1d5Smjnelson	fi
335cdf0c1d5Smjnelson
3367c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate	cd $SRC
3397c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
3407c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
3417c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
3427c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
3437c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
3447c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
3457c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
3467c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
3477c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
3507c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
3517c478bd9Sstevel@tonic-gate}
3527c478bd9Sstevel@tonic-gate
3534e5b757fSkupfer# Return library search directive as function of given root.
354597bd30bSMike Kupferfunction myldlibs {
3554e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
3564e5b757fSkupfer}
3577c478bd9Sstevel@tonic-gate
3584e5b757fSkupfer# Return header search directive as function of given root.
359597bd30bSMike Kupferfunction myheaders {
3604e5b757fSkupfer	echo "-I$1/usr/include"
3614e5b757fSkupfer}
3624e5b757fSkupfer
3634e5b757fSkupfer#
36478add226Sjmcp# Function to do the build, including package generation.
3656ea3c060SGarrett D'Amore# usage: build LABEL SUFFIX ND MULTIPROTO
3664e5b757fSkupfer# - LABEL is used to tag build output.
367ead1f93eSLiane Praza# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
368597bd30bSMike Kupfer#   open-only vs full tree).
369ead1f93eSLiane Praza# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
3704e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
3714e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
3724e5b757fSkupfer#
373597bd30bSMike Kupferfunction build {
3747c478bd9Sstevel@tonic-gate	LABEL=$1
3757c478bd9Sstevel@tonic-gate	SUFFIX=$2
376597bd30bSMike Kupfer	ND=$3
377597bd30bSMike Kupfer	MULTIPROTO=$4
3787c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
3797c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
3807c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
3817c478bd9Sstevel@tonic-gate
3824e5b757fSkupfer	ORIGROOT=$ROOT
3834e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
3844e5b757fSkupfer
385b83ec4edSjmcp	if [[ "$O_FLAG" = y ]]; then
386b83ec4edSjmcp		echo "\nSetting CLOSEDROOT= ${ROOT}-closed\n" >> $LOGFILE
387b83ec4edSjmcp		export CLOSEDROOT=${ROOT}-closed
388b83ec4edSjmcp	fi
389b83ec4edSjmcp
3904e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
3914e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
3924e5b757fSkupfer
3937c478bd9Sstevel@tonic-gate	this_build_ok=y
3947c478bd9Sstevel@tonic-gate	#
3957c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
3967c478bd9Sstevel@tonic-gate	#
3977c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
3987c478bd9Sstevel@tonic-gate		>> $LOGFILE
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
4017c478bd9Sstevel@tonic-gate	cd $SRC
4027c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
4037c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
40432f1e47bSsommerfe
405cdf0c1d5Smjnelson	if [[ "$SCM_TYPE" = teamware ]]; then
40632f1e47bSsommerfe		echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
407cdf0c1d5Smjnelson		egrep 'sccs(check:| *get)' $SRC/${INSTALLOG}.out >> \
408cdf0c1d5Smjnelson			$mail_msg_file
409cdf0c1d5Smjnelson	fi
41032f1e47bSsommerfe
4117c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
4127c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
4137c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
4147c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
4157c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
4167c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
4177c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
4187c478bd9Sstevel@tonic-gate		build_ok=n
4197c478bd9Sstevel@tonic-gate		this_build_ok=n
4207c478bd9Sstevel@tonic-gate	fi
4217c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
4227c478bd9Sstevel@tonic-gate		>> $mail_msg_file
4237c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
4247c478bd9Sstevel@tonic-gate		build_ok=n
4257c478bd9Sstevel@tonic-gate		this_build_ok=n
4267c478bd9Sstevel@tonic-gate	fi
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
4297c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
4307c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
4317c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
43220272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
4337c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
4347c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
4357c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
4367c478bd9Sstevel@tonic-gate			>> $mail_msg_file
4377c478bd9Sstevel@tonic-gate	fi
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
4407c478bd9Sstevel@tonic-gate		>> $LOGFILE
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
4437c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
4467c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
4477c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
4487c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
4497c478bd9Sstevel@tonic-gate		fi
4507c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
4517c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
4527c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
4537c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
4547c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
4557c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
4567c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
4577c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
4587c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
4597c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
4607c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
4617c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
4627c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
4637c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
4647c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
4657c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
4667c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
4677c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
46820272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
4697c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
4707c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
4717c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
4727c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
4737c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
4747c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
4757c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
4767c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
4777c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
4787c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
4797c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
4807c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
4817c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
4827c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
4837c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
4847c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
4857c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
4867c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
4877c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
4887c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
4897c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
4907c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
4917c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
4927c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
4937c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
4947c478bd9Sstevel@tonic-gate			| egrep -v '::' \
4957c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
496010b217aSwesolows			| egrep -v '^\+' \
49703eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
498c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
4997c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
5007c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
5017c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
5027c478bd9Sstevel@tonic-gate		fi
5037c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
5047c478bd9Sstevel@tonic-gate			>>$mail_msg_file
5057c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
5067c478bd9Sstevel@tonic-gate	fi
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate	#
50923259b79Srotondo	#	Re-sign selected binaries using signing server
51023259b79Srotondo	#	(gatekeeper builds only)
51123259b79Srotondo	#
5122210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
51323259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
51423259b79Srotondo		signing_file="${TMPDIR}/signing"
51523259b79Srotondo		rm -f ${signing_file}
51623259b79Srotondo		export CODESIGN_USER
51723259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
51823259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
51923259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
52023259b79Srotondo		    >> $LOGFILE
52123259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
52223259b79Srotondo		    >> $mail_msg_file
52323259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
524cdf0c1d5Smjnelson		if (( $? == 0 )) ; then
5252210853dSjohnz			build_ok=n
5262210853dSjohnz			this_build_ok=n
5272210853dSjohnz		fi
52823259b79Srotondo	fi
52923259b79Srotondo
53023259b79Srotondo	#
5317c478bd9Sstevel@tonic-gate	#	Building Packages
5327c478bd9Sstevel@tonic-gate	#
5337c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
534ead1f93eSLiane Praza		if [ -d $SRC/pkg -o -d $SRC/pkgdefs ]; then
5357c478bd9Sstevel@tonic-gate			echo "\n==== Creating $LABEL packages at `date` ====\n" \
5367c478bd9Sstevel@tonic-gate				>> $LOGFILE
537ead1f93eSLiane Praza			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
5386798c3f0SMark J. Nelson			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
5396798c3f0SMark J. Nelson			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
540d8fd4470Sjg
541ead1f93eSLiane Praza			for d in pkg pkgdefs; do
5426798c3f0SMark J. Nelson				if [ ! -f "$SRC/$d/Makefile" ]; then
543ead1f93eSLiane Praza					continue
544ead1f93eSLiane Praza				fi
545ead1f93eSLiane Praza				rm -f $SRC/$d/${INSTALLOG}.out
546ead1f93eSLiane Praza				cd $SRC/$d
547ead1f93eSLiane Praza				/bin/time $MAKE -e install 2>&1 | \
548ead1f93eSLiane Praza					tee -a $SRC/$d/${INSTALLOG}.out >> $LOGFILE
549ead1f93eSLiane Praza			done
550ead1f93eSLiane Praza
551ead1f93eSLiane Praza			echo "\n==== package build errors ($LABEL) ====\n" \
552ead1f93eSLiane Praza				>> $mail_msg_file
553ead1f93eSLiane Praza
554ead1f93eSLiane Praza			for d in pkg pkgdefs; do
5556798c3f0SMark J. Nelson				if [ ! -f "$SRC/$d/Makefile" ]; then
556ead1f93eSLiane Praza					continue
557d8fd4470Sjg				fi
558d8fd4470Sjg
559ead1f93eSLiane Praza				egrep "${MAKE}|ERROR|WARNING" $SRC/$d/${INSTALLOG}.out | \
5607c478bd9Sstevel@tonic-gate					grep ':' | \
5617c478bd9Sstevel@tonic-gate					grep -v PSTAMP | \
5627c478bd9Sstevel@tonic-gate					egrep -v "Ignoring unknown host" \
5637c478bd9Sstevel@tonic-gate					>> $mail_msg_file
564ead1f93eSLiane Praza			done
565ead1f93eSLiane Praza		else
566ead1f93eSLiane Praza			#
567ead1f93eSLiane Praza			# Handle it gracefully if -p was set but there are
568ead1f93eSLiane Praza			# neither pkg nor pkgdefs directories.
569ead1f93eSLiane Praza			#
570ead1f93eSLiane Praza			echo "\n==== No $LABEL packages to build ====\n" \
571ead1f93eSLiane Praza				>> $LOGFILE
572ead1f93eSLiane Praza		fi
5737c478bd9Sstevel@tonic-gate	else
5747c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
5757c478bd9Sstevel@tonic-gate	fi
5764e5b757fSkupfer
5774e5b757fSkupfer	ROOT=$ORIGROOT
5787c478bd9Sstevel@tonic-gate}
5797c478bd9Sstevel@tonic-gate
5801fe69678Skupfer# Usage: dolint /dir y|n
5817c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
582597bd30bSMike Kupferfunction dolint {
5837c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
5841fe69678Skupfer		echo "dolint error: $1 is not a directory"
5857c478bd9Sstevel@tonic-gate		exit 1
5867c478bd9Sstevel@tonic-gate	fi
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
5891fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
5907c478bd9Sstevel@tonic-gate		exit 1
5917c478bd9Sstevel@tonic-gate	fi
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate	lintdir=$1
5947c478bd9Sstevel@tonic-gate	dodiff=$2
5957c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
5967c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
5977c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
5984e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
5994e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
6007c478bd9Sstevel@tonic-gate
6014e5b757fSkupfer	set_debug_build_flags
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate	#
6047c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
6057c478bd9Sstevel@tonic-gate	#
6067c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate	# remove old lint.out
6097c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
6107c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
6117c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
6127c478bd9Sstevel@tonic-gate	fi
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
6157c478bd9Sstevel@tonic-gate	cd $lintdir
6167c478bd9Sstevel@tonic-gate	#
6177c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
6187c478bd9Sstevel@tonic-gate	#
6197c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
6208bcea973SRichard Lowe	    `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \
621cdf0c1d5Smjnelson	    	-prune -o -type f -name '*.ln' -print `
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
6247c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
6257c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
6267c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
6277c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
6287c478bd9Sstevel@tonic-gate		>> $mail_msg_file
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
6337c478bd9Sstevel@tonic-gate		>>$mail_msg_file
6347c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
6377c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
6387c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
6397c478bd9Sstevel@tonic-gate	fi
6407c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
6417c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
6427c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
6437c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
6447c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
6457c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
6467c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
6477c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
6487c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
6497c478bd9Sstevel@tonic-gate	fi
6507c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
6517c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
6527c478bd9Sstevel@tonic-gate			>>$mail_msg_file
6537c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
6547c478bd9Sstevel@tonic-gate		# above
6557c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
6567c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
6577c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
6587c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6597c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
6607c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6617c478bd9Sstevel@tonic-gate	fi
6627c478bd9Sstevel@tonic-gate}
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate# Install proto area from IHV build
6657c478bd9Sstevel@tonic-gate
666597bd30bSMike Kupferfunction copy_ihv_proto {
6677c478bd9Sstevel@tonic-gate
6686fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
6697c478bd9Sstevel@tonic-gate		>> $LOGFILE
6707c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
6717c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
6727c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
6737c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
6747c478bd9Sstevel@tonic-gate		fi
6756fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
6767c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
677b83ec4edSjmcp		tar cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
6787c478bd9Sstevel@tonic-gate	else
6797c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
6807c478bd9Sstevel@tonic-gate	fi
6814e5b757fSkupfer
6824e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
6834e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
6844e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
6854e5b757fSkupfer			mkdir -p $ROOT-nd
6864e5b757fSkupfer		fi
687ead1f93eSLiane Praza		# If there's a non-DEBUG version of the IHV proto area,
6884e5b757fSkupfer		# copy it, but copy something if there's not.
6894e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
6904e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
6914e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
6924e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
6934e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
6944e5b757fSkupfer			cd $IA32_IHV_ROOT
6954e5b757fSkupfer		else
6964e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
6974e5b757fSkupfer			return
6984e5b757fSkupfer		fi
699b83ec4edSjmcp		tar cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7004e5b757fSkupfer	fi
7017c478bd9Sstevel@tonic-gate}
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
7041fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
705597bd30bSMike Kupferfunction copy_ihv_pkgs {
7067c478bd9Sstevel@tonic-gate	LABEL=$1
7077c478bd9Sstevel@tonic-gate	SUFFIX=$2
7087c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
7097c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
7107c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
7117c478bd9Sstevel@tonic-gate
7127c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
7137c478bd9Sstevel@tonic-gate		>> $LOGFILE
7147c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
7157c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
716b83ec4edSjmcp		tar cf - * | \
7177c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7187c478bd9Sstevel@tonic-gate	else
7197c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
7207c478bd9Sstevel@tonic-gate	fi
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
7237c478bd9Sstevel@tonic-gate		>> $LOGFILE
7247c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
7257c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
726b83ec4edSjmcp		tar cf - * | \
7277c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7287c478bd9Sstevel@tonic-gate	else
7297c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
7307c478bd9Sstevel@tonic-gate	fi
7317c478bd9Sstevel@tonic-gate}
7327c478bd9Sstevel@tonic-gate
7334e5b757fSkupfer#
7344e5b757fSkupfer# Build and install the onbld tools.
7354e5b757fSkupfer#
7361fe69678Skupfer# usage: build_tools DESTROOT
7374e5b757fSkupfer#
7384e5b757fSkupfer# returns non-zero status if the build was successful.
7394e5b757fSkupfer#
740597bd30bSMike Kupferfunction build_tools {
7417c478bd9Sstevel@tonic-gate	DESTROOT=$1
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
7467c478bd9Sstevel@tonic-gate		>> $LOGFILE
7477c478bd9Sstevel@tonic-gate
7487c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
7497c478bd9Sstevel@tonic-gate	cd ${TOOLS}
750ead1f93eSLiane Praza	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
7517c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
7567c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
7577c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
7587c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
7594e5b757fSkupfer	return $?
7604e5b757fSkupfer}
7614e5b757fSkupfer
7624e5b757fSkupfer#
7634e5b757fSkupfer# Set up to use locally installed tools.
7644e5b757fSkupfer#
7654e5b757fSkupfer# usage: use_tools TOOLSROOT
7664e5b757fSkupfer#
767597bd30bSMike Kupferfunction use_tools {
7684e5b757fSkupfer	TOOLSROOT=$1
7694e5b757fSkupfer
770c168ccb7SMark J. Nelson	#
771c168ccb7SMark J. Nelson	# If we're not building ON workspace, then the TOOLSROOT
772c168ccb7SMark J. Nelson	# settings here are clearly ignored by the workspace
773c168ccb7SMark J. Nelson	# makefiles, prepending nonexistent directories to PATH is
774c168ccb7SMark J. Nelson	# harmless, and we clearly do not wish to override
775c168ccb7SMark J. Nelson	# ONBLD_TOOLS.
776c168ccb7SMark J. Nelson	#
777c168ccb7SMark J. Nelson	# If we're building an ON workspace, then the prepended PATH
778c168ccb7SMark J. Nelson	# elements should supercede the preexisting ONBLD_TOOLS paths,
779c168ccb7SMark J. Nelson	# and we want to override ONBLD_TOOLS to catch the tools that
780c168ccb7SMark J. Nelson	# don't have specific path env vars here.
781c168ccb7SMark J. Nelson	#
782c168ccb7SMark J. Nelson	# So the only conditional behavior is overriding ONBLD_TOOLS,
783c168ccb7SMark J. Nelson	# and we check for "an ON workspace" by looking for
784c168ccb7SMark J. Nelson	# ${TOOLSROOT}/opt/onbld.
785c168ccb7SMark J. Nelson	#
786c168ccb7SMark J. Nelson
7874e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
7887c478bd9Sstevel@tonic-gate	export STABS
7894e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
7907c478bd9Sstevel@tonic-gate	export CTFSTABS
7914e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
7927c478bd9Sstevel@tonic-gate	export GENOFFSETS
7937c478bd9Sstevel@tonic-gate
7944e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
7957c478bd9Sstevel@tonic-gate	export CTFCONVERT
7964e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
7977c478bd9Sstevel@tonic-gate	export CTFMERGE
7987c478bd9Sstevel@tonic-gate
7994e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
8007c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
8014e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
8027c478bd9Sstevel@tonic-gate	export CTFFINDMOD
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
8054e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
8067c478bd9Sstevel@tonic-gate	else
8074e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
8087c478bd9Sstevel@tonic-gate	fi
8097c478bd9Sstevel@tonic-gate	export ELFSIGN
8107c478bd9Sstevel@tonic-gate
811c168ccb7SMark J. Nelson	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
8124e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
8137c478bd9Sstevel@tonic-gate	export PATH
8147c478bd9Sstevel@tonic-gate
815c168ccb7SMark J. Nelson	if [ -d "${TOOLSROOT}/opt/onbld" ]; then
816b06f2c55SMark J. Nelson		ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
8171d9a8b8dSDan Mick		export ONBLD_TOOLS
818c168ccb7SMark J. Nelson	fi
8191d9a8b8dSDan Mick
8207c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
8217c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
8227c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
8237c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
8247c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
8257c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
8267c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
8277c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
8287c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
8291d9a8b8dSDan Mick	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
8307c478bd9Sstevel@tonic-gate}
8317c478bd9Sstevel@tonic-gate
832597bd30bSMike Kupferfunction staffer {
8337c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
8347c478bd9Sstevel@tonic-gate		"$@"
8357c478bd9Sstevel@tonic-gate	else
8367c478bd9Sstevel@tonic-gate		arg="\"$1\""
8377c478bd9Sstevel@tonic-gate		shift
8387c478bd9Sstevel@tonic-gate		for i
8397c478bd9Sstevel@tonic-gate		do
8407c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
8417c478bd9Sstevel@tonic-gate		done
8427c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
8437c478bd9Sstevel@tonic-gate	fi
8447c478bd9Sstevel@tonic-gate}
8457c478bd9Sstevel@tonic-gate
846085d331dSkupfer#
847085d331dSkupfer# Verify that the closed tree is present if it needs to be.
848085d331dSkupfer#
849597bd30bSMike Kupferfunction check_closed_tree {
850*c0e7977aSJosef 'Jeff' Sipek	if [[ ! -d "$ON_CLOSED_BINS" ]]; then
851*c0e7977aSJosef 'Jeff' Sipek		echo "ON_CLOSED_BINS must point to the closed binaries tree."
852cdf0c1d5Smjnelson		build_ok=n
853085d331dSkupfer		exit 1
854085d331dSkupfer	fi
855085d331dSkupfer}
8567c478bd9Sstevel@tonic-gate
857597bd30bSMike Kupferfunction obsolete_build {
858d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
859d77e7149Ssommerfe}
860d77e7149Ssommerfe
8614e5b757fSkupfer#
8624e5b757fSkupfer# wrapper over wsdiff.
8634e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
8644e5b757fSkupfer#
865597bd30bSMike Kupferfunction do_wsdiff {
8664e5b757fSkupfer	label=$1
8674e5b757fSkupfer	oldproto=$2
8684e5b757fSkupfer	newproto=$3
8694e5b757fSkupfer
8704e5b757fSkupfer	wsdiff="wsdiff"
8714e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
8724e5b757fSkupfer
873598cc7dfSVladimir Kotal	echo "\n==== Getting object changes since last build at `date`" \
874598cc7dfSVladimir Kotal	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
875598cc7dfSVladimir Kotal	$wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
876598cc7dfSVladimir Kotal		    tee -a $LOGFILE >> $mail_msg_file
877598cc7dfSVladimir Kotal	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
8784e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
8794e5b757fSkupfer}
8804e5b757fSkupfer
8814e5b757fSkupfer#
882ead1f93eSLiane Praza# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
8834e5b757fSkupfer# together.
8844e5b757fSkupfer#
8854e5b757fSkupfer
886597bd30bSMike Kupferfunction set_non_debug_build_flags {
8874e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
8884e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
8894e5b757fSkupfer	unset EXTRA_OPTIONS
8904e5b757fSkupfer	unset EXTRA_CFLAGS
8914e5b757fSkupfer}
8924e5b757fSkupfer
893597bd30bSMike Kupferfunction set_debug_build_flags {
8944e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
8954e5b757fSkupfer	unset RELEASE_BUILD
8964e5b757fSkupfer	unset EXTRA_OPTIONS
8974e5b757fSkupfer	unset EXTRA_CFLAGS
8984e5b757fSkupfer}
8994e5b757fSkupfer
900d77e7149Ssommerfe
9017c478bd9Sstevel@tonic-gateMACH=`uname -p`
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
9047c478bd9Sstevel@tonic-gate	OPTHOME=/opt
9057c478bd9Sstevel@tonic-gate	export OPTHOME
9067c478bd9Sstevel@tonic-gatefi
9077c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
9087c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
9097c478bd9Sstevel@tonic-gate	export TEAMWARE
9107c478bd9Sstevel@tonic-gatefi
9117c478bd9Sstevel@tonic-gate
9125e1b109eSPeter Dennis - Sustaining EngineerUSAGE='Usage: nightly [-in] [+t] [-V VERS ] [ -S E|D|H|O ] <env_file>
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gateWhere:
915d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
9167c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
9175e1b109eSPeter Dennis - Sustaining Engineer	+t	Use the build tools in $ONBLD_TOOLS/bin
9187c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
9197c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
9207c478bd9Sstevel@tonic-gate		E - build exportable source
9217c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
9227c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
9231fe69678Skupfer		O - build (only) open source
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
9267c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
9277c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
9287c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
9297c478bd9Sstevel@tonic-gate
9307c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
9317c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
9347c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
9357c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
9367c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
9373c6aa570SMark J. Nelson	-G	gate keeper default group of options (-au)
9387c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
9397c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
9407c478bd9Sstevel@tonic-gate	-N	do not run protocmp
9414e5b757fSkupfer	-O	generate OpenSolaris deliverables
9427c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
9437c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
9447c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
94504a42e3eSszhou	-X	copy x86 IHV proto area
9467c478bd9Sstevel@tonic-gate	-f	find unreferenced files
9477c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
9487c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
9497c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
9507c478bd9Sstevel@tonic-gate	-n      do not do a bringover
9517c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
9527c478bd9Sstevel@tonic-gate	-p	create packages
9537c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
9545e1b109eSPeter Dennis - Sustaining Engineer	-t	build and use the tools in $SRC/tools (default setting)
9555e1b109eSPeter Dennis - Sustaining Engineer	+t	Use the build tools in $ONBLD_TOOLS/bin
9567c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
9577c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
95896ccc8cbSesaxe	-w	report on differences between previous and current proto areas
9597c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
9607c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
9617c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
9627c478bd9Sstevel@tonic-gate		E - build exportable source
9637c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
9647c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
9651fe69678Skupfer		O - build (only) open source
9667c478bd9Sstevel@tonic-gate'
9677c478bd9Sstevel@tonic-gate#
9687c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
9691c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
9707c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
9717c478bd9Sstevel@tonic-gate#
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
9747c478bd9Sstevel@tonic-gateA_FLAG=n
9757c478bd9Sstevel@tonic-gateC_FLAG=n
9766c3c9007SstevelD_FLAG=n
9777c478bd9Sstevel@tonic-gateF_FLAG=n
9787c478bd9Sstevel@tonic-gatef_FLAG=n
9797c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
9807c478bd9Sstevel@tonic-gatel_FLAG=n
9816c3c9007SstevelM_FLAG=n
9827c478bd9Sstevel@tonic-gatem_FLAG=n
9836c3c9007SstevelN_FLAG=n
9846c3c9007Ssteveln_FLAG=n
9854e5b757fSkupferO_FLAG=n
9866c3c9007Sstevelo_FLAG=n
9876c3c9007SstevelP_FLAG=n
9887c478bd9Sstevel@tonic-gatep_FLAG=n
9897c478bd9Sstevel@tonic-gater_FLAG=n
9906c3c9007SstevelT_FLAG=n
991fd7cef36Ssuhat_FLAG=y
9927c478bd9Sstevel@tonic-gateU_FLAG=n
9936c3c9007Sstevelu_FLAG=n
9947c478bd9Sstevel@tonic-gateV_FLAG=n
9957c478bd9Sstevel@tonic-gateW_FLAG=n
9966c3c9007Sstevelw_FLAG=n
9976c3c9007SstevelX_FLAG=n
9987c478bd9Sstevel@tonic-gateSD_FLAG=n
9996c3c9007SstevelSE_FLAG=n
10007c478bd9Sstevel@tonic-gateSH_FLAG=n
10011fe69678SkupferSO_FLAG=n
10027c478bd9Sstevel@tonic-gate#
10037c478bd9Sstevel@tonic-gateXMOD_OPT=
10047c478bd9Sstevel@tonic-gate#
10057c478bd9Sstevel@tonic-gatebuild_ok=y
10061fe69678Skupfer
1007597bd30bSMike Kupferfunction is_source_build {
10081fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
10091fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
10101fe69678Skupfer	return $?
10111fe69678Skupfer}
10121fe69678Skupfer
10137c478bd9Sstevel@tonic-gate#
10147c478bd9Sstevel@tonic-gate# examine arguments
10157c478bd9Sstevel@tonic-gate#
10167c478bd9Sstevel@tonic-gate
10171fe69678Skupfer#
10181fe69678Skupfer# single function for setting -S flag and doing error checking.
10191fe69678Skupfer# usage: set_S_flag <type>
10201fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
10211fe69678Skupfer#
1022597bd30bSMike Kupferfunction set_S_flag {
10231fe69678Skupfer	if is_source_build; then
10241fe69678Skupfer		echo "Can only build one source variant at a time."
10251fe69678Skupfer		exit 1
10261fe69678Skupfer	fi
10271fe69678Skupfer	if [ "$1" = "E" ]; then
10281fe69678Skupfer		SE_FLAG=y
10291fe69678Skupfer	elif [ "$1" = "D" ]; then
10301fe69678Skupfer		SD_FLAG=y
10311fe69678Skupfer	elif [ "$1" = "H" ]; then
10321fe69678Skupfer		SH_FLAG=y
10331fe69678Skupfer	elif [ "$1" = "O" ]; then
10341fe69678Skupfer		SO_FLAG=y
10351fe69678Skupfer	else
10361fe69678Skupfer		echo "$USAGE"
10371fe69678Skupfer		exit 1
10381fe69678Skupfer	fi
10391fe69678Skupfer}
10401fe69678Skupfer
10417c478bd9Sstevel@tonic-gateOPTIND=1
10425e1b109eSPeter Dennis - Sustaining Engineerwhile getopts +inS:tV: FLAG
10437c478bd9Sstevel@tonic-gatedo
10447c478bd9Sstevel@tonic-gate	case $FLAG in
10457c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
10467c478bd9Sstevel@tonic-gate		;;
10477c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
10487c478bd9Sstevel@tonic-gate		;;
10497c478bd9Sstevel@tonic-gate	  S )
10501fe69678Skupfer		set_S_flag $OPTARG
10517c478bd9Sstevel@tonic-gate		;;
1052fd7cef36Ssuha	 +t )	t_FLAG=n
10537c478bd9Sstevel@tonic-gate		;;
10546c3c9007Sstevel	  V )	V_FLAG=y
10556c3c9007Sstevel		V_ARG="$OPTARG"
10566c3c9007Sstevel		;;
10577c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
10587c478bd9Sstevel@tonic-gate		exit 1
10597c478bd9Sstevel@tonic-gate		;;
10607c478bd9Sstevel@tonic-gate	esac
10617c478bd9Sstevel@tonic-gatedone
10627c478bd9Sstevel@tonic-gate
10637c478bd9Sstevel@tonic-gate# correct argument count after options
10647c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
10657c478bd9Sstevel@tonic-gate
10667c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
10677c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
10687c478bd9Sstevel@tonic-gate	echo "$USAGE"
10697c478bd9Sstevel@tonic-gate	exit 1
10707c478bd9Sstevel@tonic-gatefi
10717c478bd9Sstevel@tonic-gate
10727c478bd9Sstevel@tonic-gate# check if user is running nightly as root
10737c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
10747c478bd9Sstevel@tonic-gate# when root invokes nightly.
10757c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
10767c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
10777c478bd9Sstevel@tonic-gate
10787c478bd9Sstevel@tonic-gate#
10797c478bd9Sstevel@tonic-gate# force locale to C
10807c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
10817c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
10827c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
10837c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
10847c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
10857c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
10867c478bd9Sstevel@tonic-gate
10877c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
10887c478bd9Sstevel@tonic-gateunset LD_OPTIONS
10897c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
10907c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
10917c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
10927c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
10937c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
10947c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
10957c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
10967c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
10977c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
10987c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
10997c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
11007c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
11017c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
11027c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
11037c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
11047c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
11057c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
11067c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
11077c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
11087c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
11097c478bd9Sstevel@tonic-gate
11107c478bd9Sstevel@tonic-gateunset CONFIG
11117c478bd9Sstevel@tonic-gateunset GROUP
11127c478bd9Sstevel@tonic-gateunset OWNER
11137c478bd9Sstevel@tonic-gateunset REMOTE
11147c478bd9Sstevel@tonic-gateunset ENV
11157c478bd9Sstevel@tonic-gateunset ARCH
11167c478bd9Sstevel@tonic-gateunset CLASSPATH
11177c478bd9Sstevel@tonic-gateunset NAME
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gate#
1120ead1f93eSLiane Praza# To get ONBLD_TOOLS from the environment, it must come from the env file.
1121ead1f93eSLiane Praza# If it comes interactively, it is generally TOOLS_PROTO, which will be
1122ead1f93eSLiane Praza# clobbered before the compiler version checks, which will therefore fail.
1123ead1f93eSLiane Praza#
1124ead1f93eSLiane Prazaunset ONBLD_TOOLS
1125ead1f93eSLiane Praza
1126ead1f93eSLiane Praza#
11277c478bd9Sstevel@tonic-gate#	Setup environmental variables
11287c478bd9Sstevel@tonic-gate#
112947703246Ssommerfeif [ -f /etc/nightly.conf ]; then
113047703246Ssommerfe	. /etc/nightly.conf
113147703246Ssommerfefi
113247703246Ssommerfe
11337c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
11347c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
11357c478bd9Sstevel@tonic-gate		. $1
11367c478bd9Sstevel@tonic-gate	else
11377c478bd9Sstevel@tonic-gate		. ./$1
11387c478bd9Sstevel@tonic-gate	fi
11397c478bd9Sstevel@tonic-gateelse
11407c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
11417c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
11427c478bd9Sstevel@tonic-gate	else
11437c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
11447c478bd9Sstevel@tonic-gate		exit 1
11457c478bd9Sstevel@tonic-gate	fi
11467c478bd9Sstevel@tonic-gatefi
11477c478bd9Sstevel@tonic-gate
11481fe69678Skupfer# contents of stdenv.sh inserted after next line:
11491fe69678Skupfer# STDENV_START
11501fe69678Skupfer# STDENV_END
11511fe69678Skupfer
1152d7693b08SRoland Mainz# Check if we have sufficient data to continue...
1153d7693b08SRoland Mainz[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
1154220399b7SRoland Mainzif  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
1155220399b7SRoland Mainz	# Check if the gate data are valid if we don't do a "bringover" below
1156220399b7SRoland Mainz	[[ -d "${CODEMGR_WS}" ]] || \
1157220399b7SRoland Mainz		fatal_error "Error: ${CODEMGR_WS} is not a directory."
1158220399b7SRoland Mainz	[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
1159220399b7SRoland Mainz		fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
1160220399b7SRoland Mainzfi
1161d7693b08SRoland Mainz
11627c478bd9Sstevel@tonic-gate#
11637c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
11647c478bd9Sstevel@tonic-gate#
11657c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
11667c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
11677c478bd9Sstevel@tonic-gateelse
11687c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
11697c478bd9Sstevel@tonic-gatefi
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
11727c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
11737c478bd9Sstevel@tonic-gate
11747c478bd9Sstevel@tonic-gate#
11757c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
11767c478bd9Sstevel@tonic-gate#
11777c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
11787c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
11797c478bd9Sstevel@tonic-gatefi
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gate#
11827c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
11837c478bd9Sstevel@tonic-gate#
11847c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
11857c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
11867c478bd9Sstevel@tonic-gatefi
11877c478bd9Sstevel@tonic-gate
11887c478bd9Sstevel@tonic-gate#
1189cdf0c1d5Smjnelson# If CLOSED_BRINGOVER_WS was not specified, let it default to CLOSED_CLONE_WS
1190cdf0c1d5Smjnelson#
1191cdf0c1d5Smjnelsonif [ "$CLOSED_BRINGOVER_WS" = "" ]; then
1192cdf0c1d5Smjnelson	CLOSED_BRINGOVER_WS=$CLOSED_CLONE_WS
1193cdf0c1d5Smjnelsonfi
1194cdf0c1d5Smjnelson
1195cdf0c1d5Smjnelson#
1196fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1197a5c06a9eSmike_s#
1198a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1199fb23a357Skupfer	BRINGOVER_FILES="usr"
1200a5c06a9eSmike_sfi
1201a5c06a9eSmike_s
1202085d331dSkupfercheck_closed_tree
1203fb9f9b97Skupfer
1204a5c06a9eSmike_s#
12057c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1206b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
12077c478bd9Sstevel@tonic-gate#
1208d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
12097c478bd9Sstevel@tonic-gateOPTIND=1
121078add226Sjmcpwhile getopts +ABCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
12117c478bd9Sstevel@tonic-gatedo
12127c478bd9Sstevel@tonic-gate	case $FLAG in
12137c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
12147c478bd9Sstevel@tonic-gate		;;
12157c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
12167c478bd9Sstevel@tonic-gate		;; # old version of D
12176c3c9007Sstevel	  C )	C_FLAG=y
12187c478bd9Sstevel@tonic-gate		;;
12197c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
12207c478bd9Sstevel@tonic-gate		;;
12216c3c9007Sstevel	  F )	F_FLAG=y
12227c478bd9Sstevel@tonic-gate		;;
12236c3c9007Sstevel	  f )	f_FLAG=y
12247c478bd9Sstevel@tonic-gate		;;
122578add226Sjmcp	  G )   u_FLAG=y
12267c478bd9Sstevel@tonic-gate		;;
122778add226Sjmcp	  I )	m_FLAG=y
12287c478bd9Sstevel@tonic-gate		p_FLAG=y
12297c478bd9Sstevel@tonic-gate		u_FLAG=y
12307c478bd9Sstevel@tonic-gate		;;
12317c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
12327c478bd9Sstevel@tonic-gate		;;
12336c3c9007Sstevel	  l )	l_FLAG=y
12346c3c9007Sstevel		;;
12356c3c9007Sstevel	  M )	M_FLAG=y
12366c3c9007Sstevel		;;
12376c3c9007Sstevel	  m )	m_FLAG=y
12386c3c9007Sstevel		;;
12396c3c9007Sstevel	  N )	N_FLAG=y
12406c3c9007Sstevel		;;
12417c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
12427c478bd9Sstevel@tonic-gate		;;
12434e5b757fSkupfer	  O )	O_FLAG=y
12444e5b757fSkupfer		;;
12457c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
12467c478bd9Sstevel@tonic-gate		;;
12476c3c9007Sstevel	  P )	P_FLAG=y
12486c3c9007Sstevel		;; # obsolete
12497c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
12507c478bd9Sstevel@tonic-gate		;;
12516c3c9007Sstevel	  R )	m_FLAG=y
12526c3c9007Sstevel		p_FLAG=y
12536c3c9007Sstevel		;;
12547c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
12557c478bd9Sstevel@tonic-gate		;;
12566c3c9007Sstevel	  S )
12576c3c9007Sstevel		set_S_flag $OPTARG
12586c3c9007Sstevel		;;
12596c3c9007Sstevel	  T )	T_FLAG=y
12606c3c9007Sstevel		;; # obsolete
1261fd7cef36Ssuha	 +t )	t_FLAG=n
12627c478bd9Sstevel@tonic-gate		;;
12636798c3f0SMark J. Nelson	  U )   if [ -z "${PARENT_ROOT}" ]; then
12647c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
12657c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
12667c478bd9Sstevel@tonic-gate			exit 1
12677c478bd9Sstevel@tonic-gate		fi
12686798c3f0SMark J. Nelson		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
12696798c3f0SMark J. Nelson		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
12706798c3f0SMark J. Nelson			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
1271ead1f93eSLiane Praza		fi
12727c478bd9Sstevel@tonic-gate		U_FLAG=y
12737c478bd9Sstevel@tonic-gate		;;
12746c3c9007Sstevel	  u )	u_FLAG=y
12757c478bd9Sstevel@tonic-gate		;;
12767c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
12777c478bd9Sstevel@tonic-gate		;;
12786c3c9007Sstevel
12796c3c9007Sstevel	  w )	w_FLAG=y
12807c478bd9Sstevel@tonic-gate		;;
12817c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
12827c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
12837c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
12847c478bd9Sstevel@tonic-gate			X_FLAG=y
12857c478bd9Sstevel@tonic-gate		fi
12867c478bd9Sstevel@tonic-gate		;;
12876c3c9007Sstevel	  x )	XMOD_OPT="-x"
12886c3c9007Sstevel		;;
12897c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
12907c478bd9Sstevel@tonic-gate		exit 1
12917c478bd9Sstevel@tonic-gate		;;
12927c478bd9Sstevel@tonic-gate	esac
12937c478bd9Sstevel@tonic-gatedone
12947c478bd9Sstevel@tonic-gate
12957c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
12967c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
12977c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
12987c478bd9Sstevel@tonic-gate		exit 1
12997c478bd9Sstevel@tonic-gate	fi
13007c478bd9Sstevel@tonic-gate
13017c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
13027c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
13037c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
13047c478bd9Sstevel@tonic-gate		export STAFFER
13057c478bd9Sstevel@tonic-gate	fi
13067c478bd9Sstevel@tonic-gatefi
13077c478bd9Sstevel@tonic-gate
13087c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
13097c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
13107c478bd9Sstevel@tonic-gate	export MAILTO
13117c478bd9Sstevel@tonic-gatefi
13127c478bd9Sstevel@tonic-gate
1313c168ccb7SMark J. NelsonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
1314c168ccb7SMark J. NelsonPATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
1315c168ccb7SMark J. NelsonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
13167c478bd9Sstevel@tonic-gateexport PATH
13177c478bd9Sstevel@tonic-gate
1318fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1319fb23a357Skupferrelsrcdirs="."
1320*c0e7977aSJosef 'Jeff' Sipekabssrcdirs="$SRC"
1321fb23a357Skupfer
13227c478bd9Sstevel@tonic-gateunset CH
13237c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
13247c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
13257c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
13267c478bd9Sstevel@tonic-gate# the old ones still do.
13277c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
13287c478bd9Sstevel@tonic-gate	CH=
13297c478bd9Sstevel@tonic-gate	export CH
13307c478bd9Sstevel@tonic-gateelse
13317c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
13327c478bd9Sstevel@tonic-gatefi
13337c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
133448bc00d6Sjmcp# have we set RELEASE_DATE in our env file?
133548bc00d6Sjmcpif [ -z "$RELEASE_DATE" ]; then
133648bc00d6Sjmcp	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
133748bc00d6Sjmcpfi
133848bc00d6SjmcpBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
133948bc00d6SjmcpBASEWSDIR=$(basename $CODEMGR_WS)
134048bc00d6SjmcpDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
13417c478bd9Sstevel@tonic-gate
134248bc00d6Sjmcp# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
134348bc00d6Sjmcp# by avoiding repeated shell invocations to evaluate Makefile.master definitions.
13443c6aa570SMark J. Nelson# we export o_FLAG and X_FLAG for use by makebfu, and by usr/src/pkg/Makefile
134548bc00d6Sjmcpexport o_FLAG X_FLAG POUND_SIGN RELEASE_DATE DEV_CM
13467c478bd9Sstevel@tonic-gate
13477c478bd9Sstevel@tonic-gatemaketype="distributed"
13487c478bd9Sstevel@tonic-gateMAKE=dmake
13497c478bd9Sstevel@tonic-gate# get the dmake version string alone
13507c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
13517c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
13527c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
13537c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
13547c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
13557c478bd9Sstevel@tonic-gate# extract the second (or final) integer
13567c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
13577c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
13587c478bd9Sstevel@tonic-gate# extract the first integer
13597c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
13607c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
13617c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
13627c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
13637c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
13647c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
13657c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
13667c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
13677c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
13687c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
13697c478bd9Sstevel@tonic-gate		exit 1
13707c478bd9Sstevel@tonic-gate	fi
13717c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
13727c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
13737c478bd9Sstevel@tonic-gate	cat <<EOF
13747c478bd9Sstevel@tonic-gate
13757c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
13767c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
13777c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
13807c478bd9Sstevel@tonic-gateEOF
13817c478bd9Sstevel@tonic-gate	exit 1
13827c478bd9Sstevel@tonic-gatefi
13837c478bd9Sstevel@tonic-gateexport PATH
13847c478bd9Sstevel@tonic-gateexport MAKE
13857c478bd9Sstevel@tonic-gate
13867c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
13877c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
13887c478bd9Sstevel@tonic-gate	export PATH
13897c478bd9Sstevel@tonic-gatefi
13907c478bd9Sstevel@tonic-gate
139199e4a37bSWill Fiveashhostname=$(uname -n)
139299e4a37bSWill Fiveashif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
139399e4a37bSWill Fiveashthen
139499e4a37bSWill Fiveash	maxjobs=
139599e4a37bSWill Fiveash	if [[ -f $HOME/.make.machines ]]
139699e4a37bSWill Fiveash	then
139799e4a37bSWill Fiveash		# Note: there is a hard tab and space character in the []s
139899e4a37bSWill Fiveash		# below.
139999e4a37bSWill Fiveash		egrep -i "^[ 	]*$hostname[ 	\.]" \
140099e4a37bSWill Fiveash			$HOME/.make.machines | read host jobs
140199e4a37bSWill Fiveash		maxjobs=${jobs##*=}
14027c478bd9Sstevel@tonic-gate	fi
140399e4a37bSWill Fiveash
140499e4a37bSWill Fiveash	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
140599e4a37bSWill Fiveash	then
140699e4a37bSWill Fiveash		# default
140799e4a37bSWill Fiveash		maxjobs=4
14087c478bd9Sstevel@tonic-gate	fi
140999e4a37bSWill Fiveash
141099e4a37bSWill Fiveash	export DMAKE_MAX_JOBS=$maxjobs
141199e4a37bSWill Fiveashfi
141299e4a37bSWill Fiveash
14137c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
14147c478bd9Sstevel@tonic-gateexport DMAKE_MODE
14157c478bd9Sstevel@tonic-gate
14167c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
14177c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
14187c478bd9Sstevel@tonic-gate	exit 1
14197c478bd9Sstevel@tonic-gatefi
14207c478bd9Sstevel@tonic-gate
14217c478bd9Sstevel@tonic-gate#
14227c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
14237c478bd9Sstevel@tonic-gate#
14247c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
14257c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
14267c478bd9Sstevel@tonic-gatefi
14277c478bd9Sstevel@tonic-gate
142804a42e3eSszhou#
142904a42e3eSszhou# Check for IHV root for copying ihv proto area
143004a42e3eSszhou#
143104a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
143204a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
143304a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
143404a42e3eSszhou		args_ok=n
143504a42e3eSszhou        fi
143604a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
143704a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
143804a42e3eSszhou                args_ok=n
143904a42e3eSszhou        fi
14406fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
14416fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
14426fec3625Sdduvall		args_ok=n
14436fec3625Sdduvall        fi
14446fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
14456fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
14466fec3625Sdduvall                args_ok=n
14476fec3625Sdduvall        fi
144804a42e3eSszhoufi
144904a42e3eSszhou
14507c478bd9Sstevel@tonic-gate# Append source version
14517c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
14527c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
14537c478bd9Sstevel@tonic-gatefi
14547c478bd9Sstevel@tonic-gate
14557c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
14567c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
14577c478bd9Sstevel@tonic-gatefi
14587c478bd9Sstevel@tonic-gate
14597c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
14607c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
14617c478bd9Sstevel@tonic-gatefi
14627c478bd9Sstevel@tonic-gate
14631fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
14641fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
14651fe69678Skupferfi
14661fe69678Skupfer
14677c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
14687c478bd9Sstevel@tonic-gateexport TMPDIR
14697c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
14707c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
147185f46905SMark J. Nelsonchmod 777 $TMPDIR
14727c478bd9Sstevel@tonic-gate
14737c478bd9Sstevel@tonic-gate#
14747c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
14757c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
14767c478bd9Sstevel@tonic-gate# have the fix for 6271754
14777c478bd9Sstevel@tonic-gate#
14787c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
14797c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
14807c478bd9Sstevel@tonic-gate
1481ead1f93eSLiane Praza#
1482ead1f93eSLiane Praza# Tools should only be built non-DEBUG.  Keep track of the tools proto
1483ead1f93eSLiane Praza# area path relative to $TOOLS, because the latter changes in an
1484ead1f93eSLiane Praza# export build.
1485ead1f93eSLiane Praza#
1486ead1f93eSLiane Praza# TOOLS_PROTO is included below for builds other than usr/src/tools
1487ead1f93eSLiane Praza# that look for this location.  For usr/src/tools, this will be
1488ead1f93eSLiane Praza# overridden on the $MAKE command line in build_tools().
1489ead1f93eSLiane Praza#
14907c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
1491ead1f93eSLiane PrazaTOOLS_PROTO_REL=proto/root_${MACH}-nd
1492ead1f93eSLiane PrazaTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
1493ead1f93eSLiane Praza
14947c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
14957c478bd9Sstevel@tonic-gate
14967c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
14977c478bd9Sstevel@tonic-gate# fails to start correctly
1498597bd30bSMike Kupferfunction newdir {
14997c478bd9Sstevel@tonic-gate	dir=$1
15007c478bd9Sstevel@tonic-gate	toadd=
15017c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
15027c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
15037c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
15047c478bd9Sstevel@tonic-gate	done
15057c478bd9Sstevel@tonic-gate	torm=
15067c478bd9Sstevel@tonic-gate	newlist=
15077c478bd9Sstevel@tonic-gate	for dir in $toadd; do
15087c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
15097c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
15107c478bd9Sstevel@tonic-gate			torm="$dir $torm"
15117c478bd9Sstevel@tonic-gate		else
15127c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
15137c478bd9Sstevel@tonic-gate			return 1
15147c478bd9Sstevel@tonic-gate		fi
15157c478bd9Sstevel@tonic-gate	done
15167c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
15177c478bd9Sstevel@tonic-gate	return 0
15187c478bd9Sstevel@tonic-gate}
15197c478bd9Sstevel@tonic-gatenewdirlist=
15207c478bd9Sstevel@tonic-gate
15217c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
15227c478bd9Sstevel@tonic-gate
15237c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
15247c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
15257c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
15267c478bd9Sstevel@tonic-gate# built from this immediate source.
15277c478bd9Sstevel@tonic-gateENVLDLIBS1=
15287c478bd9Sstevel@tonic-gateENVLDLIBS2=
15297c478bd9Sstevel@tonic-gateENVLDLIBS3=
15307c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
15317c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
15327c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
15337c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
15347c478bd9Sstevel@tonic-gatePARENT_ROOT=
15357c478bd9Sstevel@tonic-gate
15367c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1537494f7e12SKeith M Wesolowski	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
15407c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
15417c478bd9Sstevel@tonic-gate
15427c478bd9Sstevel@tonic-gate#
15437c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
15447c478bd9Sstevel@tonic-gate#
15457c478bd9Sstevel@tonic-gate
1546597bd30bSMike Kupferfunction logshuffle {
1547fd7cef36Ssuha    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
15487c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
15497c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
15507c478bd9Sstevel@tonic-gate	fi
15517c478bd9Sstevel@tonic-gate	mkdir $LLOG
15524802ef38Srscott	export LLOG
15537c478bd9Sstevel@tonic-gate
15547c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
15557c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
155696ccc8cbSesaxe
15572e02daeeSRainer Orth		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
15582e02daeeSRainer Orth			mv $ATLOG/proto_list_tools_${MACH} $LLOG
15592e02daeeSRainer Orth	        fi
15602e02daeeSRainer Orth
156196ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
156296ccc8cbSesaxe		    	mv $TMPDIR/wsdiff.results $LLOG
156396ccc8cbSesaxe		fi
15644e5b757fSkupfer
15654e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
15664e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
15674e5b757fSkupfer		fi
15687c478bd9Sstevel@tonic-gate	fi
15697c478bd9Sstevel@tonic-gate
15707c478bd9Sstevel@tonic-gate	#
15717c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
15727c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
15737c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
15747c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
15757c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
15767c478bd9Sstevel@tonic-gate	#
15777c478bd9Sstevel@tonic-gate
15787c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
15797c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
15807c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
15817c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
15827c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
15837c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
15847c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
15857c478bd9Sstevel@tonic-gate	fi
15867c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
15877c478bd9Sstevel@tonic-gate
15887c478bd9Sstevel@tonic-gate	case "$build_ok" in
15897c478bd9Sstevel@tonic-gate		y)
15907c478bd9Sstevel@tonic-gate			state=Completed
15917c478bd9Sstevel@tonic-gate			;;
15927c478bd9Sstevel@tonic-gate		i)
15937c478bd9Sstevel@tonic-gate			state=Interrupted
15947c478bd9Sstevel@tonic-gate			;;
15957c478bd9Sstevel@tonic-gate		*)
15967c478bd9Sstevel@tonic-gate	    		state=Failed
15977c478bd9Sstevel@tonic-gate			;;
15987c478bd9Sstevel@tonic-gate	esac
159940bc9153Srscott	NIGHTLY_STATUS=$state
160040bc9153Srscott	export NIGHTLY_STATUS
16017c478bd9Sstevel@tonic-gate
160247703246Ssommerfe	run_hook POST_NIGHTLY $state
160347703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
16044802ef38Srscott
16053cb00cf1SJoshua M. Clulow	#
16063cb00cf1SJoshua M. Clulow	# mailx(1) sets From: based on the -r flag
16073cb00cf1SJoshua M. Clulow	# if it is given.
16083cb00cf1SJoshua M. Clulow	#
16093cb00cf1SJoshua M. Clulow	mailx_r=
16103cb00cf1SJoshua M. Clulow	if [[ -n "${MAILFROM}" ]]; then
16113cb00cf1SJoshua M. Clulow		mailx_r="-r ${MAILFROM}"
16123cb00cf1SJoshua M. Clulow	fi
16133cb00cf1SJoshua M. Clulow
1614cdf0c1d5Smjnelson	cat $build_time_file $build_environ_file $mail_msg_file \
1615cdf0c1d5Smjnelson	    > ${LLOG}/mail_msg
16167c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
16173cb00cf1SJoshua M. Clulow	    	cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
16187c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
16197c478bd9Sstevel@tonic-gate			${MAILTO}
16207c478bd9Sstevel@tonic-gate	fi
16217c478bd9Sstevel@tonic-gate
16227c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
16237c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
16247c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
16257c478bd9Sstevel@tonic-gate	fi
16267c478bd9Sstevel@tonic-gate
16277c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
16287c478bd9Sstevel@tonic-gate}
16297c478bd9Sstevel@tonic-gate
16307c478bd9Sstevel@tonic-gate#
16317c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
16327c478bd9Sstevel@tonic-gate#
1633597bd30bSMike Kupferfunction cleanup {
16347c478bd9Sstevel@tonic-gate    	logshuffle
16357c478bd9Sstevel@tonic-gate
16367c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
16377c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
16387c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
16397c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
16407c478bd9Sstevel@tonic-gate
16417c478bd9Sstevel@tonic-gate	set -- $newdirlist
16427c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
16437c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
16447c478bd9Sstevel@tonic-gate		shift; shift
16457c478bd9Sstevel@tonic-gate	done
16467c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
16477c478bd9Sstevel@tonic-gate}
16487c478bd9Sstevel@tonic-gate
1649597bd30bSMike Kupferfunction cleanup_signal {
16507c478bd9Sstevel@tonic-gate    	build_ok=i
16517c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
16527c478bd9Sstevel@tonic-gate	exit 1
16537c478bd9Sstevel@tonic-gate}
16547c478bd9Sstevel@tonic-gate
16557c478bd9Sstevel@tonic-gatetrap cleanup 0
16567c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
16577c478bd9Sstevel@tonic-gate
16587c478bd9Sstevel@tonic-gate#
16597c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
16607c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
16617c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
16627c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
16637c478bd9Sstevel@tonic-gate# for the workspace).
1664cdf0c1d5Smjnelson#
1665597bd30bSMike Kupferfunction create_lock {
16667c478bd9Sstevel@tonic-gate	lockf=$1
16677c478bd9Sstevel@tonic-gate	lockvar=$2
16688312e758Sdduvall
16697c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
16707c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
16717c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
16728312e758Sdduvall
16738312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
16748312e758Sdduvall		basews=`basename $CODEMGR_WS`
16758312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
16768312e758Sdduvall		if [ "$host" != "$hostname" ]; then
16778312e758Sdduvall			echo "$MACH build of $basews apparently" \
16788312e758Sdduvall			    "already started by $user on $host as $pid."
16798312e758Sdduvall			exit 1
16808312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
16818312e758Sdduvall			echo "$MACH build of $basews already started" \
16828312e758Sdduvall			    "by $user as $pid."
16838312e758Sdduvall			exit 1
16848312e758Sdduvall		else
16858312e758Sdduvall			# stale lock; clear it out and try again
16868312e758Sdduvall			rm -f $lockf
16878312e758Sdduvall		fi
16888312e758Sdduvall	done
16897c478bd9Sstevel@tonic-gate}
16907c478bd9Sstevel@tonic-gate
16914e5b757fSkupfer#
16924e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
16934e5b757fSkupfer# options.
16944e5b757fSkupfer#
1695597bd30bSMike Kupferfunction allprotos {
1696c7453724SMike Kupfer	typeset roots="$ROOT"
1697b83ec4edSjmcp
1698c7453724SMike Kupfer	if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
1699c7453724SMike Kupfer		roots="$roots $ROOT-nd"
17004e5b757fSkupfer	fi
17014e5b757fSkupfer
1702b83ec4edSjmcp	if [[ $O_FLAG = y ]]; then
1703b83ec4edSjmcp		roots="$roots $ROOT-closed"
1704b83ec4edSjmcp		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd-closed"
1705b83ec4edSjmcp	fi
1706b83ec4edSjmcp
17074e5b757fSkupfer	echo $roots
17084e5b757fSkupfer}
17094e5b757fSkupfer
17107c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
17117c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
17127c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
17137c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
17147c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
17157c478bd9Sstevel@tonic-gatefi
17167c478bd9Sstevel@tonic-gate#
17177c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
17187c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
17197c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
17207c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
17217c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
17227c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
17237c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
17247c478bd9Sstevel@tonic-gate#
17257c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
17267c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
17277c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
17287c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
17297c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
17307c478bd9Sstevel@tonic-gatefi
17317c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
17327c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
17337c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
17347c478bd9Sstevel@tonic-gatefi
17357c478bd9Sstevel@tonic-gate
17367c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
17377c478bd9Sstevel@tonic-gate# the directories we may have created so far.
17387c478bd9Sstevel@tonic-gatenewdirlist=
17397c478bd9Sstevel@tonic-gate
17407c478bd9Sstevel@tonic-gate#
17417c478bd9Sstevel@tonic-gate# Create mail_msg_file
17427c478bd9Sstevel@tonic-gate#
17437c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
17447c478bd9Sstevel@tonic-gatetouch $mail_msg_file
17457c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
1746cdf0c1d5Smjnelsonbuild_environ_file="${TMPDIR}/build_environ"
1747cdf0c1d5Smjnelsontouch $build_environ_file
17487c478bd9Sstevel@tonic-gate#
17497c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
17507c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
17517c478bd9Sstevel@tonic-gate#
17527c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
17537c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
17547c478bd9Sstevel@tonic-gatefi
17557c478bd9Sstevel@tonic-gate#
17567c478bd9Sstevel@tonic-gate#	Build OsNet source
17577c478bd9Sstevel@tonic-gate#
17587c478bd9Sstevel@tonic-gateSTART_DATE=`date`
17597c478bd9Sstevel@tonic-gateSECONDS=0
17607c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
17617c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
17627c478bd9Sstevel@tonic-gate
1763cdf0c1d5Smjnelsonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1764cdf0c1d5Smjnelson    tee -a $mail_msg_file >> $LOGFILE
1765cdf0c1d5Smjnelson
17667c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
17677c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
17687c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
17697c478bd9Sstevel@tonic-gate
177047703246Ssommerferun_hook SYS_PRE_NIGHTLY
177147703246Ssommerferun_hook PRE_NIGHTLY
177247703246Ssommerfe
17737c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
17747c478bd9Sstevel@tonic-gateenv >> $LOGFILE
17757c478bd9Sstevel@tonic-gate
17767c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
17777c478bd9Sstevel@tonic-gate
1778d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
1779d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1780d77e7149Ssommerfefi
1781d77e7149Ssommerfe
1782d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
1783d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1784d77e7149Ssommerfefi
1785d77e7149Ssommerfe
17861fe69678Skupferif is_source_build; then
17877c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
17887c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
17897c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
17907c478bd9Sstevel@tonic-gate		i_FLAG=n
17917c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
17927c478bd9Sstevel@tonic-gate	fi
17937c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
17947c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
17957c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
17967c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
17977c478bd9Sstevel@tonic-gate		N_FLAG=y
17987c478bd9Sstevel@tonic-gate	fi
17997c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
18007c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
18017c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
18027c478bd9Sstevel@tonic-gate		l_FLAG=n
18037c478bd9Sstevel@tonic-gate	fi
18047c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
18057c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
18067c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
18077c478bd9Sstevel@tonic-gate		C_FLAG=n
18087c478bd9Sstevel@tonic-gate	fi
18097c478bd9Sstevel@tonic-gateelse
18107c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
18117c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
18127c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
18137c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
18147c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
18157c478bd9Sstevel@tonic-gateEOF
18167c478bd9Sstevel@tonic-gate		else
18177c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
18187c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
18197c478bd9Sstevel@tonic-gateEOF
18207c478bd9Sstevel@tonic-gate		fi
18217c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
18227c478bd9Sstevel@tonic-gate	fi
18237c478bd9Sstevel@tonic-gatefi
18247c478bd9Sstevel@tonic-gate
18257c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
18264e5b757fSkupfer	#
18274e5b757fSkupfer	# In the past we just complained but went ahead with the lint
1828ead1f93eSLiane Praza	# pass, even though the proto area was built non-DEBUG.  It's
1829ead1f93eSLiane Praza	# unlikely that non-DEBUG headers will make a difference, but
18304e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
1831ead1f93eSLiane Praza	# to specify a DEBUG build.
18324e5b757fSkupfer	#
18334e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
18347c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
18354e5b757fSkupfer	l_FLAG=n
18367c478bd9Sstevel@tonic-gatefi
18377c478bd9Sstevel@tonic-gate
18387c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
18397c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
18407c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
18417c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
18427c478bd9Sstevel@tonic-gate		f_FLAG=n
18437c478bd9Sstevel@tonic-gate	fi
184411a78ea0SMark J. Nelson	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
184511a78ea0SMark J. Nelson		echo "WARNING: the -f flag requires -l, and -p;" \
184611a78ea0SMark J. Nelson		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
18477c478bd9Sstevel@tonic-gate		f_FLAG=n
18487c478bd9Sstevel@tonic-gate	fi
18497c478bd9Sstevel@tonic-gatefi
18507c478bd9Sstevel@tonic-gate
185196ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
18524e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
185396ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
185496ccc8cbSesaxe	w_FLAG=n
185596ccc8cbSesaxefi
185696ccc8cbSesaxe
18577c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
18587c478bd9Sstevel@tonic-gate	#
18597c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
18607c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
18617c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
18627c478bd9Sstevel@tonic-gate	#
18637c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
18647c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
18657c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
18667c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
18677c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
18687c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
18697c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18707c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
18717c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
18727c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
18737c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
18747c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18757c478bd9Sstevel@tonic-gate	fi
18767c478bd9Sstevel@tonic-gatefi
18777c478bd9Sstevel@tonic-gate
18784e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
18794e5b757fSkupfer
18804e5b757fSkupfercase $MULTI_PROTO in
18814e5b757fSkupferyes|no)	;;
18824e5b757fSkupfer*)
18834e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
18844e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
18854e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
18864e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
18874e5b757fSkupfer	export MULTI_PROTO=no
18884e5b757fSkupfer	;;
18894e5b757fSkupferesac
18904e5b757fSkupfer
18917c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
18927c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
18937c478bd9Sstevel@tonic-gate
189496ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
189596ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
189696ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
189796ccc8cbSesaxe	rm -rf $ROOT.prev
189896ccc8cbSesaxe    fi
189996ccc8cbSesaxe    mv $ROOT $ROOT.prev
190096ccc8cbSesaxefi
190196ccc8cbSesaxe
19024e5b757fSkupfer# Same for non-DEBUG proto area
19034e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
19044e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
19054e5b757fSkupfer		rm -rf $ROOT-nd.prev
19064e5b757fSkupfer	fi
19074e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
19084e5b757fSkupferfi
19094e5b757fSkupfer
1910445b6314SRichard Lowe#
1911445b6314SRichard Lowe# Echo the SCM type of the parent workspace, this can't just be which_scm
1912445b6314SRichard Lowe# as that does not know how to identify various network repositories.
1913445b6314SRichard Lowe#
1914445b6314SRichard Lowefunction parent_wstype {
1915445b6314SRichard Lowe	typeset scm_type junk
191630635de9SJohn.Zolnowsky@Sun.COM
191730635de9SJohn.Zolnowsky@Sun.COM	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
1918445b6314SRichard Lowe	    | read scm_type junk
1919445b6314SRichard Lowe	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
192030635de9SJohn.Zolnowsky@Sun.COM		# Probe BRINGOVER_WS to determine its type
192130635de9SJohn.Zolnowsky@Sun.COM		if [[ $BRINGOVER_WS == svn*://* ]]; then
1922445b6314SRichard Lowe			scm_type="subversion"
192330635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == file://* ]] &&
192430635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "This is a Subversion repository" \
192530635de9SJohn.Zolnowsky@Sun.COM		    ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
1926445b6314SRichard Lowe			scm_type="subversion"
192730635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == ssh://* ]]; then
1928445b6314SRichard Lowe			scm_type="mercurial"
192930635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == http://* ]] && \
1930445b6314SRichard Lowe		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
193130635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "application/mercurial" 2> /dev/null; then
1932445b6314SRichard Lowe			scm_type="mercurial"
1933445b6314SRichard Lowe		elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
1934445b6314SRichard Lowe			scm_type="subversion"
193530635de9SJohn.Zolnowsky@Sun.COM		else
1936445b6314SRichard Lowe			scm_type="none"
193730635de9SJohn.Zolnowsky@Sun.COM		fi
193830635de9SJohn.Zolnowsky@Sun.COM	fi
193930635de9SJohn.Zolnowsky@Sun.COM
194030635de9SJohn.Zolnowsky@Sun.COM	# fold both unsupported and unrecognized results into "none"
1941445b6314SRichard Lowe	case "$scm_type" in
194230635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
194330635de9SJohn.Zolnowsky@Sun.COM		;;
1944445b6314SRichard Lowe	*)	scm_type=none
194530635de9SJohn.Zolnowsky@Sun.COM		;;
194630635de9SJohn.Zolnowsky@Sun.COM	esac
194730635de9SJohn.Zolnowsky@Sun.COM
1948445b6314SRichard Lowe	echo $scm_type
194930635de9SJohn.Zolnowsky@Sun.COM}
195030635de9SJohn.Zolnowsky@Sun.COM
1951445b6314SRichard Lowe# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
1952445b6314SRichard Lowefunction child_wstype {
1953445b6314SRichard Lowe	typeset scm_type junk
1954445b6314SRichard Lowe
1955445b6314SRichard Lowe	# Probe CODEMGR_WS to determine its type
1956445b6314SRichard Lowe	if [[ -d $CODEMGR_WS ]]; then
1957445b6314SRichard Lowe		$WHICH_SCM | read scm_type junk || exit 1
1958445b6314SRichard Lowe	fi
1959445b6314SRichard Lowe
1960445b6314SRichard Lowe	case "$scm_type" in
19611b1e41ddSRichard Lowe	none|subversion|git|teamware|mercurial)
1962445b6314SRichard Lowe		;;
1963445b6314SRichard Lowe	*)	scm_type=none
1964445b6314SRichard Lowe		;;
1965445b6314SRichard Lowe	esac
1966445b6314SRichard Lowe
1967445b6314SRichard Lowe	echo $scm_type
1968445b6314SRichard Lowe}
1969445b6314SRichard Lowe
19705c70f01eSRichard LoweSCM_TYPE=$(child_wstype)
197130635de9SJohn.Zolnowsky@Sun.COM
19727c478bd9Sstevel@tonic-gate#
19737c478bd9Sstevel@tonic-gate#	Decide whether to clobber
19747c478bd9Sstevel@tonic-gate#
19757c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
19767c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
19777c478bd9Sstevel@tonic-gate
19787c478bd9Sstevel@tonic-gate	cd $SRC
19797c478bd9Sstevel@tonic-gate	# remove old clobber file
19807c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
19817c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
19827c478bd9Sstevel@tonic-gate
19837c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
19847c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
19858bcea973SRichard Lowe	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
1986cdf0c1d5Smjnelson		-o -name 'interfaces.*' \) -prune \
19877c478bd9Sstevel@tonic-gate		-o -name '.make.*' -print | xargs rm -f
19887c478bd9Sstevel@tonic-gate
19897c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
19907c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
19917c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
19927c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
19937c478bd9Sstevel@tonic-gate		>> $mail_msg_file
19947c478bd9Sstevel@tonic-gate
19954e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
19967c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
19977c478bd9Sstevel@tonic-gate		cd ${TOOLS}
19987c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
1999ead1f93eSLiane Praza		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
20007c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
20017c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
20027c478bd9Sstevel@tonic-gate			>> $mail_msg_file
20037c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
20047c478bd9Sstevel@tonic-gate			>> $mail_msg_file
20057c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
20067c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
20077c478bd9Sstevel@tonic-gate	fi
200896ccc8cbSesaxe
2009c7453724SMike Kupfer	typeset roots=$(allprotos)
2010c7453724SMike Kupfer	echo "\n\nClearing $roots" >> "$LOGFILE"
2011c7453724SMike Kupfer	rm -rf $roots
20127c478bd9Sstevel@tonic-gate
20137c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
20147c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
20157c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2016fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2017cdf0c1d5Smjnelson	# under source code control, so leave them alone.
20187c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
20197c478bd9Sstevel@tonic-gate	cd $SRC
2020cdf0c1d5Smjnelson	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
20218bcea973SRichard Lowe	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
20227c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2023fb23a357Skupfer	       -name '*.o' \) -print | \
2024fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
20257c478bd9Sstevel@tonic-gateelse
20267c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
20277c478bd9Sstevel@tonic-gatefi
20287c478bd9Sstevel@tonic-gate
2029597bd30bSMike Kupfertype bringover_teamware > /dev/null 2>&1 || function bringover_teamware {
20307c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
20317c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
20327c478bd9Sstevel@tonic-gate	do
20337c478bd9Sstevel@tonic-gate		sleep 120
20347c478bd9Sstevel@tonic-gate	done
20357c478bd9Sstevel@tonic-gate
2036fd7cef36Ssuha	if [[ -z $BRINGOVER ]]; then
2037fd7cef36Ssuha		BRINGOVER=$TEAMWARE/bin/bringover
2038fd7cef36Ssuha	fi
203932f1e47bSsommerfe
2040cdf0c1d5Smjnelson	staffer $BRINGOVER -c "nightly update" -p $BRINGOVER_WS \
204132f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
204232f1e47bSsommerfe		touch $TMPDIR/bringover_failed
204332f1e47bSsommerfe
2044d77e7149Ssommerfe        staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2045d77e7149Ssommerfe	if [ -s $TMPDIR/bringovercheck.out ]; then
2046d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2047d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2048d77e7149Ssommerfe	fi
2049cdf0c1d5Smjnelson}
205032f1e47bSsommerfe
2051597bd30bSMike Kupfertype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
2052cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2053cdf0c1d5Smjnelson
2054cdf0c1d5Smjnelson	# If the repository doesn't exist yet, then we want to populate it.
2055cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.hg ]]; then
2056cdf0c1d5Smjnelson		staffer hg init $CODEMGR_WS
20578cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
20588cca05f6SMark J. Nelson		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
2059f457028bSMark J. Nelson		touch $TMPDIR/new_repository
2060cdf0c1d5Smjnelson	fi
20615c53ea7aSmjnelson
2062cdf0c1d5Smjnelson	typeset -x HGMERGE="/bin/false"
2063cdf0c1d5Smjnelson
2064cdf0c1d5Smjnelson	#
20655c53ea7aSmjnelson	# If the user has changes, regardless of whether those changes are
20665c53ea7aSmjnelson	# committed, and regardless of whether those changes conflict, then
20675c53ea7aSmjnelson	# we'll attempt to merge them either implicitly (uncommitted) or
20685c53ea7aSmjnelson	# explicitly (committed).
2069cdf0c1d5Smjnelson	#
20705c53ea7aSmjnelson	# These are the messages we'll use to help clarify mercurial output
20715c53ea7aSmjnelson	# in those cases.
20725c53ea7aSmjnelson	#
20735c53ea7aSmjnelson	typeset mergefailmsg="\
20745c53ea7aSmjnelson***\n\
20755c53ea7aSmjnelson*** nightly was unable to automatically merge your changes.  You should\n\
20765c53ea7aSmjnelson*** redo the full merge manually, following the steps outlined by mercurial\n\
20775c53ea7aSmjnelson*** above, then restart nightly.\n\
20785c53ea7aSmjnelson***\n"
20795c53ea7aSmjnelson	typeset mergepassmsg="\
20805c53ea7aSmjnelson***\n\
20815c53ea7aSmjnelson*** nightly successfully merged your changes.  This means that your working\n\
20825c53ea7aSmjnelson*** directory has been updated, but those changes are not yet committed.\n\
20835c53ea7aSmjnelson*** After nightly completes, you should validate the results of the merge,\n\
20845c53ea7aSmjnelson*** then use hg commit manually.\n\
20855c53ea7aSmjnelson***\n"
20865c53ea7aSmjnelson
20875c53ea7aSmjnelson	#
20885c53ea7aSmjnelson	# For each repository in turn:
20895c53ea7aSmjnelson	#
20905c53ea7aSmjnelson	# 1. Do the pull.  If this fails, dump the output and bail out.
20915c53ea7aSmjnelson	#
20925c53ea7aSmjnelson	# 2. If the pull resulted in an extra head, do an explicit merge.
20935c53ea7aSmjnelson	#    If this fails, dump the output and bail out.
20945c53ea7aSmjnelson	#
20955c53ea7aSmjnelson	# Because we can't rely on Mercurial to exit with a failure code
20965c53ea7aSmjnelson	# when a merge fails (Mercurial issue #186), we must grep the
20975c53ea7aSmjnelson	# output of pull/merge to check for attempted and/or failed merges.
20985c53ea7aSmjnelson	#
20995c53ea7aSmjnelson	# 3. If a merge failed, set the message and fail the bringover.
21005c53ea7aSmjnelson	#
21015c53ea7aSmjnelson	# 4. Otherwise, if a merge succeeded, set the message
21025c53ea7aSmjnelson	#
21035c53ea7aSmjnelson	# 5. Dump the output, and any message from step 3 or 4.
21045c53ea7aSmjnelson	#
21055c53ea7aSmjnelson
2106f457028bSMark J. Nelson	typeset HG_SOURCE=$BRINGOVER_WS
2107f457028bSMark J. Nelson	if [ ! -f $TMPDIR/new_repository ]; then
2108f457028bSMark J. Nelson		HG_SOURCE=$TMPDIR/open_bundle.hg
2109f457028bSMark J. Nelson		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
2110f457028bSMark J. Nelson		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
2111f457028bSMark J. Nelson
2112f457028bSMark J. Nelson		#
2113f457028bSMark J. Nelson		# If there are no incoming changesets, then incoming will
2114f457028bSMark J. Nelson		# fail, and there will be no bundle file.  Reset the source,
2115f457028bSMark J. Nelson		# to allow the remaining logic to complete with no false
2116f457028bSMark J. Nelson		# negatives.  (Unlike incoming, pull will return success
2117f457028bSMark J. Nelson		# for the no-change case.)
2118f457028bSMark J. Nelson		#
2119f457028bSMark J. Nelson		if (( $? != 0 )); then
2120f457028bSMark J. Nelson			HG_SOURCE=$BRINGOVER_WS
2121f457028bSMark J. Nelson		fi
2122f457028bSMark J. Nelson	fi
2123f457028bSMark J. Nelson
2124f457028bSMark J. Nelson	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
21255c53ea7aSmjnelson	    > $TMPDIR/pull_open.out 2>&1
21265c53ea7aSmjnelson	if (( $? != 0 )); then
21275c53ea7aSmjnelson		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
21285c53ea7aSmjnelson		cat $TMPDIR/pull_open.out
21295c53ea7aSmjnelson		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
21305c53ea7aSmjnelson			printf "$mergefailmsg"
21315c53ea7aSmjnelson		fi
21325c53ea7aSmjnelson		touch $TMPDIR/bringover_failed
21335c53ea7aSmjnelson		return
21345c53ea7aSmjnelson	fi
21355c53ea7aSmjnelson
2136cdf0c1d5Smjnelson	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
21375c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS merge \
21385c53ea7aSmjnelson		    >> $TMPDIR/pull_open.out 2>&1
21395c53ea7aSmjnelson		if (( $? != 0 )); then
21405c53ea7aSmjnelson			printf "%s: merge failed as follows:\n\n" \
21415c53ea7aSmjnelson			    "$CODEMGR_WS"
21425c53ea7aSmjnelson			cat $TMPDIR/pull_open.out
21435c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_open.out \
21445c53ea7aSmjnelson			    > /dev/null 2>&1; then
21455c53ea7aSmjnelson				printf "$mergefailmsg"
21465c53ea7aSmjnelson			fi
2147cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
21485c53ea7aSmjnelson			return
2149cdf0c1d5Smjnelson		fi
2150cdf0c1d5Smjnelson	fi
21515c53ea7aSmjnelson
21525c53ea7aSmjnelson	printf "updated %s with the following results:\n" "$CODEMGR_WS"
21535c53ea7aSmjnelson	cat $TMPDIR/pull_open.out
21545c53ea7aSmjnelson	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
21555c53ea7aSmjnelson		printf "$mergepassmsg"
21565c53ea7aSmjnelson	fi
21575c53ea7aSmjnelson	printf "\n"
21585c53ea7aSmjnelson
21595c53ea7aSmjnelson	#
2160f457028bSMark J. Nelson	# Per-changeset output is neither useful nor manageable for a
2161f457028bSMark J. Nelson	# newly-created repository.
2162f457028bSMark J. Nelson	#
2163f457028bSMark J. Nelson	if [ -f $TMPDIR/new_repository ]; then
2164f457028bSMark J. Nelson		return
2165f457028bSMark J. Nelson	fi
2166f457028bSMark J. Nelson
2167f457028bSMark J. Nelson	printf "\nadded the following changesets to open repository:\n"
2168f457028bSMark J. Nelson	cat $TMPDIR/incoming_open.out
2169f457028bSMark J. Nelson
2170f457028bSMark J. Nelson	#
2171f457028bSMark J. Nelson	# The closed repository could have been newly created, even though
2172f457028bSMark J. Nelson	# the open one previously existed...
2173f457028bSMark J. Nelson	#
2174f457028bSMark J. Nelson	if [ -f $TMPDIR/new_closed ]; then
2175f457028bSMark J. Nelson		return
2176f457028bSMark J. Nelson	fi
2177f457028bSMark J. Nelson
2178f457028bSMark J. Nelson	if [ -f $TMPDIR/incoming_closed.out ]; then
2179f457028bSMark J. Nelson		printf "\nadded the following changesets to closed repository:\n"
2180f457028bSMark J. Nelson		cat $TMPDIR/incoming_closed.out
2181f457028bSMark J. Nelson	fi
2182cdf0c1d5Smjnelson}
2183cdf0c1d5Smjnelson
2184597bd30bSMike Kupfertype bringover_subversion > /dev/null 2>&1 || function bringover_subversion {
2185cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2186cdf0c1d5Smjnelson
2187cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.svn ]]; then
2188cdf0c1d5Smjnelson		staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2189cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2190cdf0c1d5Smjnelson	else
2191cdf0c1d5Smjnelson		typeset root
2192cdf0c1d5Smjnelson		root=$(staffer svn info $CODEMGR_WS |
2193cdf0c1d5Smjnelson			nawk '/^Repository Root:/ {print $NF}')
2194cdf0c1d5Smjnelson		if [[ $root != $BRINGOVER_WS ]]; then
2195cdf0c1d5Smjnelson			# We fail here because there's no way to update
2196cdf0c1d5Smjnelson			# from a named repo.
2197cdf0c1d5Smjnelson			cat <<-EOF
2198cdf0c1d5Smjnelson			\$BRINGOVER_WS doesn't match repository root:
2199cdf0c1d5Smjnelson			  \$BRINGOVER_WS:  $BRINGOVER_WS
2200cdf0c1d5Smjnelson			  Repository root: $root
2201cdf0c1d5Smjnelson			EOF
2202cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2203cdf0c1d5Smjnelson		else
2204cdf0c1d5Smjnelson			# If a conflict happens, svn still exits 0.
2205cdf0c1d5Smjnelson			staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2206cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2207cdf0c1d5Smjnelson			if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2208cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2209cdf0c1d5Smjnelson			fi
2210cdf0c1d5Smjnelson		fi
2211cdf0c1d5Smjnelson	fi
2212cdf0c1d5Smjnelson}
2213cdf0c1d5Smjnelson
2214597bd30bSMike Kupfertype bringover_none > /dev/null 2>&1 || function bringover_none {
2215cdf0c1d5Smjnelson	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2216cdf0c1d5Smjnelson	touch $TMPDIR/bringover_failed
2217cdf0c1d5Smjnelson}
2218cdf0c1d5Smjnelson
2219cdf0c1d5Smjnelson#
2220cdf0c1d5Smjnelson#	Decide whether to bringover to the codemgr workspace
2221cdf0c1d5Smjnelson#
2222cdf0c1d5Smjnelsonif [ "$n_FLAG" = "n" ]; then
2223445b6314SRichard Lowe	PARENT_SCM_TYPE=$(parent_wstype)
2224ca0ac982Smjnelson
2225ca0ac982Smjnelson	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2226ca0ac982Smjnelson		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2227ca0ac982Smjnelson		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2228ca0ac982Smjnelson		exit 1
2229ca0ac982Smjnelson	fi
2230ca0ac982Smjnelson
2231cdf0c1d5Smjnelson	run_hook PRE_BRINGOVER
2232cdf0c1d5Smjnelson
2233cdf0c1d5Smjnelson	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2234cdf0c1d5Smjnelson	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2235cdf0c1d5Smjnelson
2236ca0ac982Smjnelson	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2237cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
223832f1e47bSsommerfe
223932f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
224032f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
224132f1e47bSsommerfe		build_ok=n
224232f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
22437c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
22447c478bd9Sstevel@tonic-gate		exit 1
22457c478bd9Sstevel@tonic-gate	fi
2246085d331dSkupfer
2247ca0ac982Smjnelson	#
2248ca0ac982Smjnelson	# It's possible that we used the bringover above to create
2249ca0ac982Smjnelson	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2250ca0ac982Smjnelson	# but should now be the same as $BRINGOVER_WS.
2251ca0ac982Smjnelson	#
2252ca0ac982Smjnelson	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2253ca0ac982Smjnelson
225447703246Ssommerfe	run_hook POST_BRINGOVER
225547703246Ssommerfe
2256085d331dSkupfer	check_closed_tree
2257b83ec4edSjmcp
22587c478bd9Sstevel@tonic-gateelse
22597c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
22607c478bd9Sstevel@tonic-gatefi
22617c478bd9Sstevel@tonic-gate
2262*c0e7977aSJosef 'Jeff' Sipekif [[ "$O_FLAG" = y ]]; then
2263b83ec4edSjmcp	build_ok=n
2264b83ec4edSjmcp	echo "OpenSolaris binary deliverables need usr/closed." \
2265b83ec4edSjmcp	    | tee -a "$mail_msg_file" >> $LOGFILE
2266b83ec4edSjmcp	exit 1
2267b83ec4edSjmcpfi
2268b83ec4edSjmcp
2269220399b7SRoland Mainz# Safeguards
2270220399b7SRoland Mainz[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
2271220399b7SRoland Mainz[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
2272220399b7SRoland Mainz[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
2273220399b7SRoland Mainz
2274cdf0c1d5Smjnelsonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2275cdf0c1d5Smjnelson
2276cdf0c1d5Smjnelson# System
2277cdf0c1d5Smjnelsonwhence uname | tee -a $build_environ_file >> $LOGFILE
2278cdf0c1d5Smjnelsonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2279cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2280cdf0c1d5Smjnelson
2281cdf0c1d5Smjnelson# make
2282cdf0c1d5Smjnelsonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
2283cdf0c1d5Smjnelson$MAKE -v | tee -a $build_environ_file >> $LOGFILE
2284cdf0c1d5Smjnelsonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2285cdf0c1d5Smjnelson    tee -a $build_environ_file >> $LOGFILE
2286cdf0c1d5Smjnelson
2287cdf0c1d5Smjnelson#
2288cdf0c1d5Smjnelson# Report the compiler versions.
2289cdf0c1d5Smjnelson#
2290cdf0c1d5Smjnelson
2291cdf0c1d5Smjnelsonif [[ ! -f $SRC/Makefile ]]; then
2292cdf0c1d5Smjnelson	build_ok=n
2293cdf0c1d5Smjnelson	echo "\nUnable to find \"Makefile\" in $SRC." | \
2294cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2295cdf0c1d5Smjnelson	exit 1
2296cdf0c1d5Smjnelsonfi
2297cdf0c1d5Smjnelson
2298cdf0c1d5Smjnelson( cd $SRC
2299cdf0c1d5Smjnelson  for target in cc-version cc64-version java-version; do
2300cdf0c1d5Smjnelson	echo
2301cdf0c1d5Smjnelson	#
2302cdf0c1d5Smjnelson	# Put statefile somewhere we know we can write to rather than trip
2303cdf0c1d5Smjnelson	# over a read-only $srcroot.
2304cdf0c1d5Smjnelson	#
2305cdf0c1d5Smjnelson	rm -f $TMPDIR/make-state
2306cdf0c1d5Smjnelson	export SRC
2307cdf0c1d5Smjnelson	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2308cdf0c1d5Smjnelson		continue
2309cdf0c1d5Smjnelson	fi
2310cdf0c1d5Smjnelson	touch $TMPDIR/nocompiler
2311cdf0c1d5Smjnelson  done
2312cdf0c1d5Smjnelson  echo
2313cdf0c1d5Smjnelson) | tee -a $build_environ_file >> $LOGFILE
2314cdf0c1d5Smjnelson
2315cdf0c1d5Smjnelsonif [ -f $TMPDIR/nocompiler ]; then
2316cdf0c1d5Smjnelson	rm -f $TMPDIR/nocompiler
2317cdf0c1d5Smjnelson	build_ok=n
2318cdf0c1d5Smjnelson	echo "Aborting due to missing compiler." |
2319cdf0c1d5Smjnelson		tee -a $build_environ_file >> $LOGFILE
2320cdf0c1d5Smjnelson	exit 1
2321cdf0c1d5Smjnelsonfi
2322cdf0c1d5Smjnelson
2323cdf0c1d5Smjnelson# as
2324cdf0c1d5Smjnelsonwhence as | tee -a $build_environ_file >> $LOGFILE
2325cdf0c1d5Smjnelsonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2326cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2327cdf0c1d5Smjnelson
2328cdf0c1d5Smjnelson# Check that we're running a capable link-editor
2329cdf0c1d5Smjnelsonwhence ld | tee -a $build_environ_file >> $LOGFILE
2330cdf0c1d5SmjnelsonLDVER=`ld -V 2>&1`
2331cdf0c1d5Smjnelsonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
233270087ad3SRichard LoweLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
2333cdf0c1d5Smjnelsonif [ `expr $LDVER \< 422` -eq 1 ]; then
2334cdf0c1d5Smjnelson	echo "The link-editor needs to be at version 422 or higher to build" | \
2335cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2336cdf0c1d5Smjnelson	echo "the latest stuff.  Hope your build works." | \
2337cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2338cdf0c1d5Smjnelsonfi
2339cdf0c1d5Smjnelson
23407c478bd9Sstevel@tonic-gate#
23414e5b757fSkupfer# Build and use the workspace's tools if requested
23427c478bd9Sstevel@tonic-gate#
23434e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
23444e5b757fSkupfer	set_non_debug_build_flags
23457c478bd9Sstevel@tonic-gate
23467c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
2347ead1f93eSLiane Praza	if [[ $? != 0  && "$t_FLAG" = y ]]; then
23484e5b757fSkupfer		use_tools $TOOLS_PROTO
23494e5b757fSkupfer	fi
23507c478bd9Sstevel@tonic-gatefi
23517c478bd9Sstevel@tonic-gate
23526fec3625Sdduvall#
23536fec3625Sdduvall# copy ihv proto area in addition to the build itself
23546fec3625Sdduvall#
23556fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
23566fec3625Sdduvall	copy_ihv_proto
23576fec3625Sdduvallfi
23586fec3625Sdduvall
23597c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
23607c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
23617c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
23627c478bd9Sstevel@tonic-gateelse
23634e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
23644e5b757fSkupfer	touch $SRC/.build.tstamp
23654e5b757fSkupfer
23667c478bd9Sstevel@tonic-gate	normal_build
23677c478bd9Sstevel@tonic-gatefi
23687c478bd9Sstevel@tonic-gate
23694e5b757fSkupfer#
2370597bd30bSMike Kupfer# Generate the THIRDPARTYLICENSE files if needed.  This is done after
2371597bd30bSMike Kupfer# the build, so that dynamically-created license files are there.
2372597bd30bSMike Kupfer# It's done before findunref to help identify license files that need
2373597bd30bSMike Kupfer# to be added to tools/opensolaris/license-list.
23745d715dd7Skupfer#
23755d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2376597bd30bSMike Kupfer	echo "\n==== Generating THIRDPARTYLICENSE files ====\n" |
2377597bd30bSMike Kupfer	    tee -a "$mail_msg_file" >> "$LOGFILE"
23785d715dd7Skupfer
23795084e753SMark J. Nelson	if [ -d $ROOT/licenses/usr ]; then
23805084e753SMark J. Nelson		( cd $ROOT/licenses ; \
23815084e753SMark J. Nelson		    mktpl $SRC/pkg/license-list ) >> "$LOGFILE" 2>&1
2382cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
23835d715dd7Skupfer			echo "Couldn't create THIRDPARTYLICENSE files" |
2384597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
23855d715dd7Skupfer		fi
23865084e753SMark J. Nelson	else
23875084e753SMark J. Nelson		echo "No licenses found under $ROOT/licenses" |
23885084e753SMark J. Nelson		    tee -a "$mail_msg_file" >> "$LOGFILE"
23895084e753SMark J. Nelson	fi
23905d715dd7Skupferfi
23915d715dd7Skupfer
23927c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
23937c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
23947c478bd9Sstevel@tonic-gate
23957c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
23967c478bd9Sstevel@tonic-gate	save_binaries
23977c478bd9Sstevel@tonic-gatefi
23987c478bd9Sstevel@tonic-gate
23997c478bd9Sstevel@tonic-gate
24007c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
24017c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
2402cdf0c1d5Smjnelson
24037c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2404cdf0c1d5Smjnelson	if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2405cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
24067c478bd9Sstevel@tonic-gate	fi
24077c478bd9Sstevel@tonic-gate
2408cdf0c1d5Smjnelson	if [ $build_ok = y ]; then
2409cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2410cdf0c1d5Smjnelson	fi
2411cdf0c1d5Smjnelsonfi
2412cdf0c1d5Smjnelson
2413cdf0c1d5Smjnelsonif [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
24147c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
24157c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
24167c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
24177c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
24187c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
24197c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
24207c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
24217c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
24227c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
24237c478bd9Sstevel@tonic-gate	else
24247c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
24257c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
24267c478bd9Sstevel@tonic-gate	fi
24277c478bd9Sstevel@tonic-gate
24287c478bd9Sstevel@tonic-gatefi
24297c478bd9Sstevel@tonic-gate
2430c7453724SMike Kupferif [ "$SO_FLAG" = "y" -a "$build_ok" = y ]; then
24311fe69678Skupfer	#
2432db957641SGarrett D'Amore	# Copy the open sources into their own tree.
2433cdf0c1d5Smjnelson	# If copy_source fails, it will have already generated an
2434cdf0c1d5Smjnelson	# error message and set build_ok=n, so we don't need to worry
2435cdf0c1d5Smjnelson	# about that here.
2436cdf0c1d5Smjnelson	#
24371fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2438cdf0c1d5Smjnelsonfi
2439cdf0c1d5Smjnelson
2440c7453724SMike Kupferif [ "$SO_FLAG" = "y" -a "$build_ok" = y ]; then
2441b83ec4edSjmcp	SRC=$OPEN_SRCDIR/usr/src
24421fe69678Skupferfi
24431fe69678Skupfer
24441fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
24454e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
24464e5b757fSkupfer	rm -rf `allprotos`
24477c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
24484e5b757fSkupfer		set_non_debug_build_flags
2449b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
24501fe69678Skupfer		#
24511fe69678Skupfer		# SRC was set earlier to point to the source build
24521fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
24531fe69678Skupfer		#
24541fe69678Skupfer		TOOLS=${SRC}/tools
2455b06f2c55SMark J. Nelson		TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
2456b06f2c55SMark J. Nelson		build_tools ${TOOLS_PROTO}
2457b06f2c55SMark J. Nelson		if [[ $? != 0 ]]; then
2458b06f2c55SMark J. Nelson			use_tools ${TOOLS_PROTO}
2459b06f2c55SMark J. Nelson		fi
24607c478bd9Sstevel@tonic-gate	fi
24617c478bd9Sstevel@tonic-gate
24627c478bd9Sstevel@tonic-gate	normal_build
24637c478bd9Sstevel@tonic-gatefi
24647c478bd9Sstevel@tonic-gate
24654e5b757fSkupfer#
24664e5b757fSkupfer# There are several checks that need to look at the proto area, but
24674e5b757fSkupfer# they only need to look at one, and they don't care whether it's
24684e5b757fSkupfer# DEBUG or non-DEBUG.
24694e5b757fSkupfer#
24704e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
24714e5b757fSkupfer	checkroot=$ROOT-nd
24724e5b757fSkupferelse
24734e5b757fSkupfer	checkroot=$ROOT
24744e5b757fSkupferfi
24754e5b757fSkupfer
24767c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
24777c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
24787c478bd9Sstevel@tonic-gate		>> $LOGFILE
24794e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
24807c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
24817c478bd9Sstevel@tonic-gate		>> $LOGFILE
24827c478bd9Sstevel@tonic-gate
24837c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
24847c478bd9Sstevel@tonic-gate
2485ead1f93eSLiane Praza		E1=
2486ead1f93eSLiane Praza		f1=
2487ead1f93eSLiane Praza		if [ -d "$SRC/pkgdefs" ]; then
2488ead1f93eSLiane Praza			f1="$SRC/pkgdefs/etc/exception_list_$MACH"
2489ead1f93eSLiane Praza			if [ "$X_FLAG" = "y" ]; then
2490ead1f93eSLiane Praza				f1="$f1 $IA32_IHV_WS/usr/src/pkgdefs/etc/exception_list_$MACH"
24917c478bd9Sstevel@tonic-gate			fi
24926fec3625Sdduvall		fi
24937c478bd9Sstevel@tonic-gate
2494ead1f93eSLiane Praza		for f in $f1; do
2495ead1f93eSLiane Praza			if [ -f "$f" ]; then
2496ead1f93eSLiane Praza				E1="$E1 -e $f"
2497ead1f93eSLiane Praza			fi
2498ead1f93eSLiane Praza		done
2499ead1f93eSLiane Praza
2500ead1f93eSLiane Praza		E2=
2501ead1f93eSLiane Praza		f2=
2502ead1f93eSLiane Praza		if [ -d "$SRC/pkg" ]; then
2503ead1f93eSLiane Praza			f2="$f2 exceptions/packaging"
2504ead1f93eSLiane Praza		fi
2505ead1f93eSLiane Praza
2506ead1f93eSLiane Praza		for f in $f2; do
2507ead1f93eSLiane Praza			if [ -f "$f" ]; then
2508ead1f93eSLiane Praza				E2="$E2 -e $f"
2509ead1f93eSLiane Praza			fi
2510ead1f93eSLiane Praza		done
2511ead1f93eSLiane Praza
25127c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
2513ead1f93eSLiane Praza			#
2514b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
2515b4add148Sdduvall			# IHV proto list to the reference list if the reference
2516b4add148Sdduvall			# was built without -X.
2517b4add148Sdduvall			#
2518b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
2519b4add148Sdduvall			# IHV proto list to the build's proto list if the
2520b4add148Sdduvall			# reference was built with -X.
2521b4add148Sdduvall			#
2522b4add148Sdduvall			# Use the presence of the first file entry of the cached
2523b4add148Sdduvall			# IHV proto list in the reference list to determine
2524ead1f93eSLiane Praza			# whether it was built with -X or not.
2525ead1f93eSLiane Praza			#
2526a51a9b36SMark J. Nelson			IHV_REF_PROTO_LIST=$SRC/pkg/proto_list_ihv_$MACH
2527b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2528b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
2529b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
2530b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
2531b4add148Sdduvall					grep -w "$grepfor" \
2532b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2533b4add148Sdduvall					if [ ! "$?" = "0" ]; then
2534b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2535b4add148Sdduvall					fi
2536b4add148Sdduvall				else
2537b4add148Sdduvall					grep -w "$grepfor" \
2538b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2539b4add148Sdduvall					if [ "$?" = "0" ]; then
2540b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2541b4add148Sdduvall					fi
2542b4add148Sdduvall				fi
2543b4add148Sdduvall			fi
2544ead1f93eSLiane Praza		fi
2545ead1f93eSLiane Praza	fi
2546b4add148Sdduvall
254787916a32SMark J. Nelson	if [ "$N_FLAG" != "y" -a -f $SRC/pkgdefs/Makefile ]; then
2548ead1f93eSLiane Praza		echo "\n==== Impact on SVr4 packages ====\n" >> $mail_msg_file
2549ead1f93eSLiane Praza		#
2550ead1f93eSLiane Praza		# Compare the build's proto list with current package
2551ead1f93eSLiane Praza		# definitions to audit the quality of package
2552ead1f93eSLiane Praza		# definitions and makefile install targets. Use the
2553ead1f93eSLiane Praza		# current exception list.
2554ead1f93eSLiane Praza		#
2555ead1f93eSLiane Praza		PKGDEFS_LIST=""
2556ead1f93eSLiane Praza		for d in $abssrcdirs; do
2557ead1f93eSLiane Praza			if [ -d $d/pkgdefs ]; then
2558ead1f93eSLiane Praza				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2559ead1f93eSLiane Praza			fi
2560ead1f93eSLiane Praza		done
2561ead1f93eSLiane Praza		if [ "$X_FLAG" = "y" -a \
2562ead1f93eSLiane Praza		    -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
2563ead1f93eSLiane Praza			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
2564ead1f93eSLiane Praza		fi
2565ead1f93eSLiane Praza		$PROTOCMPTERSE \
2566ead1f93eSLiane Praza		    "Files missing from the proto area:" \
2567ead1f93eSLiane Praza		    "Files missing from packages:" \
2568ead1f93eSLiane Praza		    "Inconsistencies between pkgdefs and proto area:" \
2569ead1f93eSLiane Praza		    ${E1} \
2570ead1f93eSLiane Praza		    ${PKGDEFS_LIST} \
2571ead1f93eSLiane Praza		    $ATLOG/proto_list_${MACH} \
2572ead1f93eSLiane Praza		    >> $mail_msg_file
2573ead1f93eSLiane Praza	fi
2574ead1f93eSLiane Praza
2575ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
2576ead1f93eSLiane Praza		echo "\n==== Validating manifests against proto area ====\n" \
2577ead1f93eSLiane Praza		    >> $mail_msg_file
2578ead1f93eSLiane Praza		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) \
2579ead1f93eSLiane Praza		    >> $mail_msg_file
2580ead1f93eSLiane Praza
2581ead1f93eSLiane Praza	fi
2582ead1f93eSLiane Praza
2583ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
2584ead1f93eSLiane Praza		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
2585ead1f93eSLiane Praza		if [ -n "$E2" ]; then
2586ead1f93eSLiane Praza			ELIST=$E2
2587ead1f93eSLiane Praza		else
2588ead1f93eSLiane Praza			ELIST=$E1
2589ead1f93eSLiane Praza		fi
25907c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
25917c478bd9Sstevel@tonic-gate			"Files in yesterday's proto area, but not today's:" \
25927c478bd9Sstevel@tonic-gate			"Files in today's proto area, but not yesterday's:" \
25937c478bd9Sstevel@tonic-gate			"Files that changed between yesterday and today:" \
25947c478bd9Sstevel@tonic-gate			${ELIST} \
25957c478bd9Sstevel@tonic-gate			-d $REF_PROTO_LIST \
2596b4add148Sdduvall			$REF_IHV_PROTO \
25977c478bd9Sstevel@tonic-gate			$ATLOG/proto_list_${MACH} \
2598b4add148Sdduvall			$IHV_PROTO_LIST \
25997c478bd9Sstevel@tonic-gate			>> $mail_msg_file
26007c478bd9Sstevel@tonic-gate	fi
26017c478bd9Sstevel@tonic-gatefi
26027c478bd9Sstevel@tonic-gate
26037c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
26047c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
26057c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
26067c478bd9Sstevel@tonic-gatefi
26077c478bd9Sstevel@tonic-gate
26087c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
26097c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
26107c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
26117c478bd9Sstevel@tonic-gate# the variable now.
26127c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
26137c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
26147c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
2615ead1f93eSLiane Praza	rm -rf $NIGHTLY_PARENT_ROOT/*
26167c478bd9Sstevel@tonic-gate	unset Ulockfile
26177c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
26184e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2619ead1f93eSLiane Praza		( cd $ROOT; tar cf - . |
26204e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
26217c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
26227c478bd9Sstevel@tonic-gate	fi
26234e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2624ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
26254e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
26264e5b757fSkupfer		cd $ROOT-nd
26274e5b757fSkupfer		( tar cf - . |
26284e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
26294e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
26304e5b757fSkupfer	fi
26316798c3f0SMark J. Nelson	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
2632ead1f93eSLiane Praza		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
2633ead1f93eSLiane Praza		    tee -a $LOGFILE >> $mail_msg_file
2634ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
2635ead1f93eSLiane Praza		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
2636ead1f93eSLiane Praza		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2637ead1f93eSLiane Praza			( cd $TOOLS_PROTO; tar cf - . |
26386798c3f0SMark J. Nelson			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
26396798c3f0SMark J. Nelson			    umask 0; tar xpf - ) ) 2>&1 |
2640ead1f93eSLiane Praza			    tee -a $mail_msg_file >> $LOGFILE
2641ead1f93eSLiane Praza		fi
26424e5b757fSkupfer	fi
26436798c3f0SMark J. Nelsonfi
26447c478bd9Sstevel@tonic-gate
26457c478bd9Sstevel@tonic-gate#
264675ce41a5SAli Bahrami# ELF verification: ABI (-A) and runtime (-r) checks
26477c478bd9Sstevel@tonic-gate#
264875ce41a5SAli Bahramiif [[ ($build_ok = y) && ( ($A_FLAG = y) || ($r_FLAG = y) ) ]]; then
264975ce41a5SAli Bahrami	# Directory ELF-data.$MACH holds the files produced by these tests.
265075ce41a5SAli Bahrami	elf_ddir=$SRC/ELF-data.$MACH
26517c478bd9Sstevel@tonic-gate
265275ce41a5SAli Bahrami	# If there is a previous ELF-data backup directory, remove it. Then,
265375ce41a5SAli Bahrami	# rotate current ELF-data directory into its place and create a new
265475ce41a5SAli Bahrami	# empty directory
265575ce41a5SAli Bahrami	rm -rf $elf_ddir.ref
265675ce41a5SAli Bahrami	if [[ -d $elf_ddir ]]; then
265775ce41a5SAli Bahrami		mv $elf_ddir $elf_ddir.ref
265875ce41a5SAli Bahrami	fi
265975ce41a5SAli Bahrami	mkdir -p $elf_ddir
266075ce41a5SAli Bahrami
266175ce41a5SAli Bahrami	# Call find_elf to produce a list of the ELF objects in the proto area.
266275ce41a5SAli Bahrami	# This list is passed to check_rtime and interface_check, preventing
266375ce41a5SAli Bahrami	# them from separately calling find_elf to do the same work twice.
266475ce41a5SAli Bahrami	find_elf -fr $checkroot > $elf_ddir/object_list
266575ce41a5SAli Bahrami
266675ce41a5SAli Bahrami	if [[ $A_FLAG = y ]]; then
26677c478bd9Sstevel@tonic-gate	       	echo "\n==== Check versioning and ABI information ====\n"  | \
26687c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
26697c478bd9Sstevel@tonic-gate
267075ce41a5SAli Bahrami		# Produce interface description for the proto. Report errors.
267175ce41a5SAli Bahrami		interface_check -o -w $elf_ddir -f object_list \
267275ce41a5SAli Bahrami			-i interface -E interface.err
267375ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.err ]]; then
267475ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.err \
267575ce41a5SAli Bahrami				>> $mail_msg_file
26767c478bd9Sstevel@tonic-gate		fi
26777c478bd9Sstevel@tonic-gate
26785253169eSAli Bahrami		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
26795253169eSAli Bahrami		# description file to that from the baseline gate. Issue a
26805253169eSAli Bahrami		# warning if the baseline is not present, and keep going.
26815253169eSAli Bahrami		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
26825253169eSAli Bahrami			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
26837c478bd9Sstevel@tonic-gate
26845253169eSAli Bahrami		       	echo "\n==== Compare versioning and ABI information" \
2685e599109eSAli Bahrami			    "to baseline ====\n"  | \
26865253169eSAli Bahrami			    tee -a $LOGFILE >> $mail_msg_file
2687e599109eSAli Bahrami		       	echo "Baseline:  $base_ifile\n" >> $LOGFILE
26885253169eSAli Bahrami
26895253169eSAli Bahrami			if [[ -f $base_ifile ]]; then
26905253169eSAli Bahrami				interface_cmp -d -o $base_ifile \
269175ce41a5SAli Bahrami				    $elf_ddir/interface > $elf_ddir/interface.cmp
269275ce41a5SAli Bahrami				if [[ -s $elf_ddir/interface.cmp ]]; then
26935253169eSAli Bahrami					echo | tee -a $LOGFILE >> $mail_msg_file
26945253169eSAli Bahrami					tee -a $LOGFILE < \
26955253169eSAli Bahrami					    $elf_ddir/interface.cmp \
269675ce41a5SAli Bahrami					    >> $mail_msg_file
26977c478bd9Sstevel@tonic-gate				fi
26985253169eSAli Bahrami			else
26995253169eSAli Bahrami			       	echo "baseline not available. comparison" \
27005253169eSAli Bahrami                                    "skipped" | \
27015253169eSAli Bahrami				    tee -a $LOGFILE >> $mail_msg_file
27025253169eSAli Bahrami			fi
27035253169eSAli Bahrami
27045253169eSAli Bahrami		fi
27057c478bd9Sstevel@tonic-gate	fi
27067c478bd9Sstevel@tonic-gate
270775ce41a5SAli Bahrami	if [[ $r_FLAG = y ]]; then
27087c478bd9Sstevel@tonic-gate		echo "\n==== Check ELF runtime attributes ====\n" | \
27097c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
27107c478bd9Sstevel@tonic-gate
2711ead1f93eSLiane Praza		# If we're doing a DEBUG build the proto area will be left
271275ce41a5SAli Bahrami		# with debuggable objects, thus don't assert -s.
271375ce41a5SAli Bahrami		if [[ $D_FLAG = y ]]; then
27147c478bd9Sstevel@tonic-gate			rtime_sflag=""
27157c478bd9Sstevel@tonic-gate		else
27167c478bd9Sstevel@tonic-gate			rtime_sflag="-s"
27177c478bd9Sstevel@tonic-gate		fi
271875ce41a5SAli Bahrami		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
271975ce41a5SAli Bahrami			-D object_list  -f object_list -E runtime.err \
2720622090e3SAli Bahrami			-I runtime.attr.raw
2721622090e3SAli Bahrami
2722622090e3SAli Bahrami		# check_rtime -I output needs to be sorted in order to
2723622090e3SAli Bahrami		# compare it to that from previous builds.
2724622090e3SAli Bahrami		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
2725622090e3SAli Bahrami		rm $elf_ddir/runtime.attr.raw
27267c478bd9Sstevel@tonic-gate
272775ce41a5SAli Bahrami		# Report errors
272875ce41a5SAli Bahrami		if [[ -s $elf_ddir/runtime.err ]]; then
272975ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/runtime.err \
27307c478bd9Sstevel@tonic-gate				>> $mail_msg_file
273175ce41a5SAli Bahrami		fi
27327c478bd9Sstevel@tonic-gate
273375ce41a5SAli Bahrami		# If there is an ELF-data directory from a previous build,
273475ce41a5SAli Bahrami		# then diff the attr files. These files contain information
273575ce41a5SAli Bahrami		# about dependencies, versioning, and runpaths. There is some
273675ce41a5SAli Bahrami		# overlap with the ABI checking done above, but this also
273775ce41a5SAli Bahrami		# flushes out non-ABI interface differences along with the
273875ce41a5SAli Bahrami		# other information.
273975ce41a5SAli Bahrami		echo "\n==== Diff ELF runtime attributes" \
274075ce41a5SAli Bahrami		    "(since last build) ====\n" | \
274175ce41a5SAli Bahrami		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
274275ce41a5SAli Bahrami
274375ce41a5SAli Bahrami		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
274475ce41a5SAli Bahrami			diff $elf_ddir.ref/runtime.attr \
274575ce41a5SAli Bahrami				$elf_ddir/runtime.attr \
274675ce41a5SAli Bahrami				>> $mail_msg_file
274775ce41a5SAli Bahrami		fi
274875ce41a5SAli Bahrami	fi
27495253169eSAli Bahrami
27505253169eSAli Bahrami	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
27515253169eSAli Bahrami	if [[ "$u_FLAG" = "y" ]]; then
27525253169eSAli Bahrami		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
27535253169eSAli Bahrami
27545253169eSAli Bahrami		# If parent lacks the ELF-data.$MACH directory, create it
27555253169eSAli Bahrami		if [[ ! -d $p_elf_ddir ]]; then
27565253169eSAli Bahrami			staffer mkdir -p $p_elf_ddir
27575253169eSAli Bahrami		fi
27585253169eSAli Bahrami
27595253169eSAli Bahrami		# These files are used asynchronously by other builds for ABI
27605253169eSAli Bahrami		# verification, as above for the -A option. As such, we require
27615253169eSAli Bahrami		# the file replacement to be atomic. Copy the data to a temp
27625253169eSAli Bahrami		# file in the same filesystem and then rename into place.
27635253169eSAli Bahrami		(
27645253169eSAli Bahrami			cd $elf_ddir
27655253169eSAli Bahrami			for elf_dfile in *; do
27665253169eSAli Bahrami				staffer cp $elf_dfile \
27675253169eSAli Bahrami				    ${p_elf_ddir}/${elf_dfile}.new
27685253169eSAli Bahrami				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
27695253169eSAli Bahrami				    ${p_elf_ddir}/${elf_dfile}
27705253169eSAli Bahrami			done
27715253169eSAli Bahrami		)
27725253169eSAli Bahrami	fi
27737c478bd9Sstevel@tonic-gatefi
27747c478bd9Sstevel@tonic-gate
27757c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
27767c478bd9Sstevel@tonic-gate
27777c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
27787c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
27797c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
27807c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
27817c478bd9Sstevel@tonic-gate	fi
27827c478bd9Sstevel@tonic-gate	set $LINTDIRS
27837c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
27847c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
27857c478bd9Sstevel@tonic-gate	done
27867c478bd9Sstevel@tonic-gateelse
27877c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
27887c478bd9Sstevel@tonic-gatefi
27897c478bd9Sstevel@tonic-gate
27907c478bd9Sstevel@tonic-gate# "make check" begins
27917c478bd9Sstevel@tonic-gate
27927c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
27937c478bd9Sstevel@tonic-gate	# remove old check.out
27947c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
27957c478bd9Sstevel@tonic-gate
27967c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
27977c478bd9Sstevel@tonic-gate	cd $SRC
2798170832d3SAlbert Lee	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
2799170832d3SAlbert Lee	    >> $LOGFILE
28007c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
28017c478bd9Sstevel@tonic-gate
28027c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
28037c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
28047c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
28057c478bd9Sstevel@tonic-gateelse
28067c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
28077c478bd9Sstevel@tonic-gatefi
28087c478bd9Sstevel@tonic-gate
28097c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
28107c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
28117c478bd9Sstevel@tonic-gate
2812fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
28137c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
28147c478bd9Sstevel@tonic-gate
28157c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
28167c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
28177c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
28187c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
28197c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
28207c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
28217c478bd9Sstevel@tonic-gate	fi
28227c478bd9Sstevel@tonic-gate
28239730304dSmeem	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
2824cdf0c1d5Smjnelson	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
28259730304dSmeem	    sort > $SRC/unref-${MACH}.out
28267c478bd9Sstevel@tonic-gate
28277c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
28287c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
28297c478bd9Sstevel@tonic-gate	fi
28307c478bd9Sstevel@tonic-gate
28317c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
28327c478bd9Sstevel@tonic-gatefi
28337c478bd9Sstevel@tonic-gate
28345d715dd7Skupfer#
28355d715dd7Skupfer# Generate the OpenSolaris deliverables if requested.  Some of these
28365d715dd7Skupfer# steps need to come after findunref and are commented below.
28375d715dd7Skupfer#
2838597bd30bSMike Kupfer
2839b83ec4edSjmcp# If we are doing an OpenSolaris _source_ build (-S O) then we do
2840b83ec4edSjmcp# not have usr/closed available to us to generate closedbins from,
2841b83ec4edSjmcp# so skip this part.
2842b83ec4edSjmcpif [ "$SO_FLAG" = n -a "$O_FLAG" = y -a "$build_ok" = y ]; then
28435d715dd7Skupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
28445d715dd7Skupfer	    tee -a $mail_msg_file >> $LOGFILE
28455d715dd7Skupfer
28465d715dd7Skupfer	cd $CODEMGR_WS
28475d715dd7Skupfer
28485d715dd7Skupfer	#
2849ead1f93eSLiane Praza	# This step grovels through the package manifests, so it
28505d715dd7Skupfer	# must come after findunref.
28515d715dd7Skupfer	#
2852ead1f93eSLiane Praza	# We assume no DEBUG vs non-DEBUG package content variation
2853ead1f93eSLiane Praza	# here; if that changes, then the "make all" in $SRC/pkg will
2854ead1f93eSLiane Praza	# need to be moved into the conditionals and repeated for each
2855ead1f93eSLiane Praza	# different build.
2856ead1f93eSLiane Praza	#
28575d715dd7Skupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
28585d715dd7Skupfer	closed_basename=on-closed-bins
28595d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
2860b83ec4edSjmcp		bindrop "$closed_basename" >>"$LOGFILE" 2>&1
2861cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
28625d715dd7Skupfer			echo "Couldn't create DEBUG closed binaries." |
28635d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
2864c7453724SMike Kupfer			build_ok=n
28655d715dd7Skupfer		fi
28665d715dd7Skupfer	fi
28675d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
2868b83ec4edSjmcp		bindrop -n "$closed_basename-nd" >>"$LOGFILE" 2>&1
2869cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
28705d715dd7Skupfer			echo "Couldn't create non-DEBUG closed binaries." |
28715d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
2872c7453724SMike Kupfer			build_ok=n
28735d715dd7Skupfer		fi
28745d715dd7Skupfer	fi
28755d715dd7Skupfer
28765d715dd7Skupfer	echo "Generating README.opensolaris..." >> $LOGFILE
28775d715dd7Skupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
28785d715dd7Skupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
2879cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
28805d715dd7Skupfer		echo "Couldn't create README.opensolaris." |
28815d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
2882c7453724SMike Kupfer		build_ok=n
28835d715dd7Skupfer	fi
28845d715dd7Skupferfi
28855d715dd7Skupfer
28867c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
28877c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
28887c478bd9Sstevel@tonic-gate# then don't check the proto area.
28897c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
28907c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
28917c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
28927c478bd9Sstevel@tonic-gate		>>$mail_msg_file
28937c478bd9Sstevel@tonic-gate	arg=-b
28947c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
28954e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
28967c478bd9Sstevel@tonic-gatefi
28977c478bd9Sstevel@tonic-gate
28987c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
28997c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
29007c478bd9Sstevel@tonic-gate		>> $mail_msg_file
2901ead1f93eSLiane Praza
2902ead1f93eSLiane Praza	abspkgdefs=
2903ead1f93eSLiane Praza	abspkg=
2904ead1f93eSLiane Praza	for d in $abssrcdirs; do
2905ead1f93eSLiane Praza		if [ -d "$d/pkgdefs" ]; then
2906ead1f93eSLiane Praza			abspkgdefs="$abspkgdefs $d"
29077c478bd9Sstevel@tonic-gate		fi
2908ead1f93eSLiane Praza		if [ -d "$d/pkg" ]; then
2909ead1f93eSLiane Praza			abspkg="$abspkg $d"
2910ead1f93eSLiane Praza		fi
2911ead1f93eSLiane Praza	done
2912ead1f93eSLiane Praza
2913ead1f93eSLiane Praza	if [ -n "$abspkgdefs" ]; then
2914ead1f93eSLiane Praza		pmodes -qvdP \
2915ead1f93eSLiane Praza		    `find $abspkgdefs -name pkginfo.tmpl -print -o \
2916ead1f93eSLiane Praza		    -name .del\* -prune | sed -e 's:/pkginfo.tmpl$::' | \
2917ead1f93eSLiane Praza		    sort -u` >> $mail_msg_file
2918ead1f93eSLiane Praza	fi
2919ead1f93eSLiane Praza
2920ead1f93eSLiane Praza	if [ -n "$abspkg" ]; then
2921ead1f93eSLiane Praza		for d in "$abspkg"; do
2922ead1f93eSLiane Praza			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
2923ead1f93eSLiane Praza		done
2924ead1f93eSLiane Praza	fi
29257c478bd9Sstevel@tonic-gatefi
29267c478bd9Sstevel@tonic-gate
292796ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
29284e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
29294e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
29304e5b757fSkupfer	fi
293196ccc8cbSesaxe
29324e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
29334e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
293496ccc8cbSesaxe	fi
293596ccc8cbSesaxefi
293696ccc8cbSesaxe
29377c478bd9Sstevel@tonic-gateEND_DATE=`date`
29387c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
29397c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
29407c478bd9Sstevel@tonic-gate
2941c341b28aSDarren Moffattypeset -i10 hours
29427c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
29437c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
29447c478bd9Sstevel@tonic-gate
29457c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
29467c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
29477c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
29487c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
29497c478bd9Sstevel@tonic-gate
29507c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
29517c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
29527c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
29537c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
29547c478bd9Sstevel@tonic-gate
29557c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
29567c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
29577c478bd9Sstevel@tonic-gate
29587c478bd9Sstevel@tonic-gate	#
29597c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
29607c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
29617c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
29627c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
29637c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
29647c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
29657c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
29667c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
29677c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
29687c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
29697c478bd9Sstevel@tonic-gate	# which was already on the parent.
29707c478bd9Sstevel@tonic-gate	#
29717c478bd9Sstevel@tonic-gate
29727c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
29737c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
29747c478bd9Sstevel@tonic-gate	shift
29757c478bd9Sstevel@tonic-gate
29767c478bd9Sstevel@tonic-gate	for unreffile; do
29777c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
29787c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
29797c478bd9Sstevel@tonic-gate	done
29807c478bd9Sstevel@tonic-gate
29817c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
29827c478bd9Sstevel@tonic-gatefi
29837c478bd9Sstevel@tonic-gate
29847c478bd9Sstevel@tonic-gate#
29857c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
29867c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
29877c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
29887c478bd9Sstevel@tonic-gate#
29897c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
29907c478bd9Sstevel@tonic-gate	exit 0
29917c478bd9Sstevel@tonic-gatefi
29927c478bd9Sstevel@tonic-gateexit 1
2993