xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision 85f469051e48ebfe221f6a0809a80e375de1712c)
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#
24bfed486aSAli Bahrami# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
287c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
297c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
327c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
337c478bd9Sstevel@tonic-gate#
347c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
35d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
36d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
377c478bd9Sstevel@tonic-gate#
387c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
437c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
447c478bd9Sstevel@tonic-gate#
457c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate# -A flag in NIGHTLY_OPTIONS checks ABI diffs in .so files
487c478bd9Sstevel@tonic-gate# This option requires a couple of scripts.
497c478bd9Sstevel@tonic-gate#
507c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
517c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
527c478bd9Sstevel@tonic-gate#
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate#
557c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
567c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
577c478bd9Sstevel@tonic-gate#
587c478bd9Sstevel@tonic-gateunset CDPATH
597c478bd9Sstevel@tonic-gate
60cdf0c1d5Smjnelson# Get the absolute path of the nightly script that the user invoked.  This
61cdf0c1d5Smjnelson# may be a relative path, and we need to do this before changing directory.
62cdf0c1d5Smjnelsonnightly_path=`whence $0`
6330635de9SJohn.Zolnowsky@Sun.COMnightly_ls="`ls -l $nightly_path`"
64cdf0c1d5Smjnelson
65cdf0c1d5Smjnelson#
66cdf0c1d5Smjnelson# Keep track of where we found nightly so we can invoke the matching
67cdf0c1d5Smjnelson# which_scm script.  If that doesn't work, don't go guessing, just rely
68cdf0c1d5Smjnelson# on the $PATH settings, which will generally give us either /opt/onbld
69cdf0c1d5Smjnelson# or the user's workspace.
70cdf0c1d5Smjnelson#
71cdf0c1d5SmjnelsonWHICH_SCM=$(dirname $nightly_path)/which_scm
72cdf0c1d5Smjnelsonif [[ ! -x $WHICH_SCM ]]; then
73cdf0c1d5Smjnelson	WHICH_SCM=which_scm
74cdf0c1d5Smjnelsonfi
75cdf0c1d5Smjnelson
764e5b757fSkupfer#
774e5b757fSkupfer# Print the tag string used to identify a build (e.g., "DEBUG
784e5b757fSkupfer# open-only")
794e5b757fSkupfer# usage: tagstring debug-part open-part
804e5b757fSkupfer#
814e5b757fSkupfertagstring() {
824e5b757fSkupfer	debug_part=$1
834e5b757fSkupfer	open_part=$2
844e5b757fSkupfer
854e5b757fSkupfer	if [ -n "$open_part" ]; then
864e5b757fSkupfer		echo "$debug_part $open_part"
874e5b757fSkupfer	else
884e5b757fSkupfer		echo "$debug_part"
894e5b757fSkupfer	fi
904e5b757fSkupfer}
914e5b757fSkupfer
924e5b757fSkupfer#
934e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
947c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
957c478bd9Sstevel@tonic-gate# non-DEBUG packages.
964e5b757fSkupfer#
974e5b757fSkupfer# usage: normal_build [-O]
9852a52aebSkupfer# -O	OpenSolaris delivery build.  Put the proto area and
9952a52aebSkupfer#	(eventually) packages in -open directories.  Use skeleton
10052a52aebSkupfer#	closed binaries.  Don't generate archives--that needs to be
10152a52aebSkupfer#	done later, after we've generated the closed binaries.  Also
10252a52aebSkupfer#	skip the package build (until 6414822 is fixed).
1034e5b757fSkupfer#
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gatenormal_build() {
1067c478bd9Sstevel@tonic-gate
10752a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
10852a52aebSkupfer	typeset orig_a_FLAG="$a_FLAG"
1094e5b757fSkupfer
1104e5b757fSkupfer	suffix=""
1114e5b757fSkupfer	open_only=""
1124e5b757fSkupfer	while getopts O FLAG $*; do
1134e5b757fSkupfer		case $FLAG in
1144e5b757fSkupfer		O)
1154e5b757fSkupfer			suffix="-open"
1164e5b757fSkupfer			open_only="open-only"
1174e5b757fSkupfer			p_FLAG=n
11852a52aebSkupfer			a_FLAG=n
1194e5b757fSkupfer			;;
1204e5b757fSkupfer		esac
1214e5b757fSkupfer	done
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
1264e5b757fSkupfer		set_non_debug_build_flags
1274e5b757fSkupfer		mytag=`tagstring "non-DEBUG" "$open_only"`
12852a52aebSkupfer		build "$mytag" "$suffix-nd" "$MULTI_PROTO"
1294e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1304e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1317c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
1327c478bd9Sstevel@tonic-gate		fi
1337c478bd9Sstevel@tonic-gate	else
13452a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1357c478bd9Sstevel@tonic-gate	fi
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate	# DEBUG build begins
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
1424e5b757fSkupfer		set_debug_build_flags
1434e5b757fSkupfer		mytag=`tagstring "DEBUG" "$open_only"`
14452a52aebSkupfer		build "$mytag" "$suffix" "$MULTI_PROTO"
1454e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1464e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1477c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
1487c478bd9Sstevel@tonic-gate		fi
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate	else
15152a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1527c478bd9Sstevel@tonic-gate	fi
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate	# DEBUG build ends
1554e5b757fSkupfer
15652a52aebSkupfer	p_FLAG="$orig_p_FLAG"
15752a52aebSkupfer	a_FLAG="$orig_a_FLAG"
1587c478bd9Sstevel@tonic-gate}
1597c478bd9Sstevel@tonic-gate
1601fe69678Skupfer#
16147703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
16247703246Ssommerfe#
16347703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
16447703246Ssommerfe# our logs and then run the command with ARGS
16547703246Ssommerfe#
16647703246Ssommerferun_hook() {
16747703246Ssommerfe	HOOKNAME=$1
16847703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
16947703246Ssommerfe	shift
17047703246Ssommerfe
17147703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
17247703246Ssommerfe	    	(
17347703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
17447703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
17547703246Ssommerfe			if [ "$?" -ne 0 ]; then
17647703246Ssommerfe			    	# Let exit status propagate up
17747703246Ssommerfe			    	touch $TMPDIR/abort
17847703246Ssommerfe			fi
17947703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
18047703246Ssommerfe
18147703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
18247703246Ssommerfe			build_ok=n
18347703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
18447703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
18547703246Ssommerfe			exit 1
18647703246Ssommerfe		fi
18747703246Ssommerfe	fi
18847703246Ssommerfe}
18947703246Ssommerfe
19047703246Ssommerfe#
1911fe69678Skupfer# usage: filelist DESTDIR PATTERN
1921fe69678Skupfer#
1937c478bd9Sstevel@tonic-gatefilelist() {
1947c478bd9Sstevel@tonic-gate	DEST=$1
1957c478bd9Sstevel@tonic-gate	PATTERN=$2
1967c478bd9Sstevel@tonic-gate	cd ${DEST}
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
1997c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
2007c478bd9Sstevel@tonic-gate		return;
2017c478bd9Sstevel@tonic-gate	fi
2021fe69678Skupfer	for i in `grep -v '^#' ${OBJFILES} | \
2037c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
2047c478bd9Sstevel@tonic-gate	do
2057c478bd9Sstevel@tonic-gate		# wildcard expansion
2067c478bd9Sstevel@tonic-gate		for j in $i
2077c478bd9Sstevel@tonic-gate		do
2087c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
2097c478bd9Sstevel@tonic-gate				echo $j
2107c478bd9Sstevel@tonic-gate			fi
2117c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
2127c478bd9Sstevel@tonic-gate				echo $j
2137c478bd9Sstevel@tonic-gate			fi
2147c478bd9Sstevel@tonic-gate		done
2157c478bd9Sstevel@tonic-gate	done | sort | uniq
2167c478bd9Sstevel@tonic-gate}
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
2197c478bd9Sstevel@tonic-gate# restoration
2207c478bd9Sstevel@tonic-gatesave_binaries() {
2217c478bd9Sstevel@tonic-gate	# save off list of binaries
2227c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
2237c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2247c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
2257c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
2267c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
2277c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
2287c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
2297c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
2307c478bd9Sstevel@tonic-gate}
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate# delete files
2331fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
2347c478bd9Sstevel@tonic-gatehybridize_files() {
2357c478bd9Sstevel@tonic-gate	DEST=$1
2367c478bd9Sstevel@tonic-gate	MAKETARG=$2
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
2397c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2407c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
2417c478bd9Sstevel@tonic-gate	do
2427c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2437c478bd9Sstevel@tonic-gate		rm -rf "${i}"
2447c478bd9Sstevel@tonic-gate	done
2457c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
2467c478bd9Sstevel@tonic-gate	do
2477c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2487c478bd9Sstevel@tonic-gate		rm -f ${i}+
2497c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
2507c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
2517c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
2527c478bd9Sstevel@tonic-gate	done
2537c478bd9Sstevel@tonic-gate}
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
2561fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
2577c478bd9Sstevel@tonic-gaterestore_binaries() {
2587c478bd9Sstevel@tonic-gate	DEST=$1
2597c478bd9Sstevel@tonic-gate	MAKETARG=$2
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
2627c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2637c478bd9Sstevel@tonic-gate	cd ${DEST}
2647c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
2657c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
2667c478bd9Sstevel@tonic-gate}
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate# rename files we save binaries of
2691fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
2707c478bd9Sstevel@tonic-gaterename_files() {
2717c478bd9Sstevel@tonic-gate	DEST=$1
2727c478bd9Sstevel@tonic-gate	MAKETARG=$2
2737c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
2747c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2757c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
2767c478bd9Sstevel@tonic-gate	do
2777c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
2787c478bd9Sstevel@tonic-gate		rm -f ${i}.export
2797c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
2807c478bd9Sstevel@tonic-gate	done
2817c478bd9Sstevel@tonic-gate}
2827c478bd9Sstevel@tonic-gate
2831fe69678Skupfer#
2841fe69678Skupfer# Copy some or all of the source tree.
285cdf0c1d5Smjnelson#
286cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
287cdf0c1d5Smjnelson#
2881fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
2891fe69678Skupfer#
2901fe69678Skupfercopy_source() {
2917c478bd9Sstevel@tonic-gate	WS=$1
2927c478bd9Sstevel@tonic-gate	DEST=$2
2931fe69678Skupfer	label=$3
2941fe69678Skupfer	srcroot=$4
2957c478bd9Sstevel@tonic-gate
296cdf0c1d5Smjnelson	printf "\n==== Creating %s source from %s (%s) ====\n\n" \
297cdf0c1d5Smjnelson	    "$DEST" "$WS" "$label" | tee -a $mail_msg_file >> $LOGFILE
298cdf0c1d5Smjnelson
299cdf0c1d5Smjnelson	printf "cleaning out %s\n" "$DEST." >> $LOGFILE
300cdf0c1d5Smjnelson	rm -rf "$DEST" >> $LOGFILE 2>&1
301cdf0c1d5Smjnelson
302cdf0c1d5Smjnelson	printf "creating %s\n" "$DEST." >> $LOGFILE
303cdf0c1d5Smjnelson	mkdir -p "$DEST" 2>> $LOGFILE
304cdf0c1d5Smjnelson
305cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
306cdf0c1d5Smjnelson		printf "failed to create %s\n" "$DEST" |
3077c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
308cdf0c1d5Smjnelson		build_ok=n
309cdf0c1d5Smjnelson		return 1
310cdf0c1d5Smjnelson	fi
311cdf0c1d5Smjnelson	cd "$WS"
3127c478bd9Sstevel@tonic-gate
313cdf0c1d5Smjnelson	printf "populating %s\n" "$DEST." >> $LOGFILE
3147c478bd9Sstevel@tonic-gate
315cdf0c1d5Smjnelson	case "$SCM_TYPE" in
316cdf0c1d5Smjnelson	teamware)
3171fe69678Skupfer		find $srcroot -name 's\.*' -a -type f -print | \
3187c478bd9Sstevel@tonic-gate		    sed -e 's,SCCS\/s.,,' | \
3197c478bd9Sstevel@tonic-gate		    grep -v '/\.del-*' | \
320cdf0c1d5Smjnelson		    cpio -pd $DEST >>$LOGFILE 2>&1
321cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
322cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$DEST" |
323cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
324cdf0c1d5Smjnelson		    build_ok=n
325cdf0c1d5Smjnelson		    return 1
326cdf0c1d5Smjnelson		fi
327cdf0c1d5Smjnelson		;;
328cdf0c1d5Smjnelson	mercurial)
329cdf0c1d5Smjnelson		copy_source_mercurial $DEST $srcroot
330cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
331cdf0c1d5Smjnelson		    build_ok=n
332cdf0c1d5Smjnelson		    return 1
333cdf0c1d5Smjnelson		fi
334cdf0c1d5Smjnelson		;;
335cdf0c1d5Smjnelson	*)
336cdf0c1d5Smjnelson		build_ok=n
337cdf0c1d5Smjnelson		echo "Tree copy is not supported for workspace type" \
338cdf0c1d5Smjnelson		    "$SCM_TYPE" | tee -a $mail_msg_file >> $LOGFILE
339cdf0c1d5Smjnelson		return 1
340cdf0c1d5Smjnelson		;;
341cdf0c1d5Smjnelson	esac
342cdf0c1d5Smjnelson
343cdf0c1d5Smjnelson	return 0
344cdf0c1d5Smjnelson}
345cdf0c1d5Smjnelson
346cdf0c1d5Smjnelson#
347cdf0c1d5Smjnelson# Mercurial-specific copy code for copy_source().  Handles the
348cdf0c1d5Smjnelson# combined open and closed trees.
349cdf0c1d5Smjnelson#
350cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
351cdf0c1d5Smjnelson#
352cdf0c1d5Smjnelson# usage: copy_source_mercurial destdir srcroot
353cdf0c1d5Smjnelson#
354cdf0c1d5Smjnelsonfunction copy_source_mercurial {
355cdf0c1d5Smjnelson	typeset dest=$1
356cdf0c1d5Smjnelson	typeset srcroot=$2
357cdf0c1d5Smjnelson	typeset open_top closed_top
358cdf0c1d5Smjnelson
359cdf0c1d5Smjnelson	case $srcroot in
360cdf0c1d5Smjnelson	usr)
361cdf0c1d5Smjnelson		open_top=usr
362cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = yes ]]; then
363cdf0c1d5Smjnelson			closed_top=usr/closed
364cdf0c1d5Smjnelson		fi
365cdf0c1d5Smjnelson		;;
366cdf0c1d5Smjnelson	usr/closed*)
367cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = no ]]; then
368cdf0c1d5Smjnelson			printf "can't copy %s: closed tree not present.\n" \
369cdf0c1d5Smjnelson			    "$srcroot" | tee -a $mail_msg_file >> $LOGFILE
370cdf0c1d5Smjnelson			return 1
371cdf0c1d5Smjnelson		fi
372cdf0c1d5Smjnelson		closed_top="$srcroot"
373cdf0c1d5Smjnelson		;;
374cdf0c1d5Smjnelson	*)
375cdf0c1d5Smjnelson		open_top="$srcroot"
376cdf0c1d5Smjnelson		;;
377cdf0c1d5Smjnelson	esac
378cdf0c1d5Smjnelson
379cdf0c1d5Smjnelson	if [[ -n "$open_top" ]]; then
380cdf0c1d5Smjnelson		hg locate -I "$open_top" | cpio -pd "$dest" >>$LOGFILE 2>&1
381cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
382cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$dest" |
383cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
384cdf0c1d5Smjnelson		    return 1
385cdf0c1d5Smjnelson		fi
386cdf0c1d5Smjnelson	fi
387cdf0c1d5Smjnelson
388cdf0c1d5Smjnelson	if [[ -n "$closed_top" ]]; then
389cdf0c1d5Smjnelson		mkdir -p "$dest/usr/closed" || return 1
390cdf0c1d5Smjnelson		if [[ "$closed_top" = usr/closed ]]; then
391cdf0c1d5Smjnelson			(cd usr/closed; hg locate |
392cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
393cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
394cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed\n" \
395cdf0c1d5Smjnelson				"$dest" | tee -a $mail_msg_file >> $LOGFILE
396cdf0c1d5Smjnelson			    return 1
397cdf0c1d5Smjnelson			fi
398cdf0c1d5Smjnelson		else
399cdf0c1d5Smjnelson			# copy subtree of usr/closed
400cdf0c1d5Smjnelson			closed_top=${closed_top#usr/closed/}
401cdf0c1d5Smjnelson			(cd usr/closed; hg locate -I "$closed_top" |
402cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
403cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
404cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed/%s\n" \
405cdf0c1d5Smjnelson				"$dest" "$closed_top" |
406cdf0c1d5Smjnelson				tee -a $mail_msg_file >> $LOGFILE
407cdf0c1d5Smjnelson			    return 1
408cdf0c1d5Smjnelson			fi
409cdf0c1d5Smjnelson		fi
410cdf0c1d5Smjnelson	fi
411cdf0c1d5Smjnelson
412cdf0c1d5Smjnelson	return 0
4131fe69678Skupfer}
4147c478bd9Sstevel@tonic-gate
4151fe69678Skupfer#
4161fe69678Skupfer# function to create (but not build) the export/crypt source tree.
4171fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
4181fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
4191fe69678Skupfer# builds the tree.
4201fe69678Skupfer#
4211fe69678Skupferset_up_source_build() {
4221fe69678Skupfer	WS=$1
4231fe69678Skupfer	DEST=$2
4241fe69678Skupfer	MAKETARG=$3
4251fe69678Skupfer
4261fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
427cdf0c1d5Smjnelson	if (( $? != 0 )); then
428cdf0c1d5Smjnelson	    echo "\nCould not copy source tree for source build." |
429cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
430cdf0c1d5Smjnelson	    build_ok=n
431cdf0c1d5Smjnelson	    return
432cdf0c1d5Smjnelson	fi
433cdf0c1d5Smjnelson
4347c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate	cd $SRC
4377c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
4387c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
4397c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
4407c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
4417c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
4427c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
4437c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
4447c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
4457c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
4487c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate	cd ${DEST}
4517c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
4527c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
4537c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
4547c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
4557c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
4567c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
4577c478bd9Sstevel@tonic-gate		do
4587c478bd9Sstevel@tonic-gate			# make sure the files exist
4597c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
4607c478bd9Sstevel@tonic-gate				continue
4617c478bd9Sstevel@tonic-gate			fi
4627c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
4637c478bd9Sstevel@tonic-gate				continue
4647c478bd9Sstevel@tonic-gate			fi
4657c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
4667c478bd9Sstevel@tonic-gate		done
4677c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
4687c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
4697c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
4707c478bd9Sstevel@tonic-gate	fi
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
4737c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
4747c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
4757c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
4767c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
4777c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
4787c478bd9Sstevel@tonic-gate		fi
4797c478bd9Sstevel@tonic-gate	fi
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate	# save the cleartext
4827c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
4837c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
4847c478bd9Sstevel@tonic-gate	cd ${DEST}
4857c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
486fb23a357Skupfer	find usr -depth -print | \
4877c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
4887c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
4897c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
4907c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
4917c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
4927c478bd9Sstevel@tonic-gate	fi
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
4957c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
4967c478bd9Sstevel@tonic-gate	fi
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate}
4997c478bd9Sstevel@tonic-gate
5004e5b757fSkupfer# Return library search directive as function of given root.
5014e5b757fSkupfermyldlibs() {
5024e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
5034e5b757fSkupfer}
5047c478bd9Sstevel@tonic-gate
5054e5b757fSkupfer# Return header search directive as function of given root.
5064e5b757fSkupfermyheaders() {
5074e5b757fSkupfer	echo "-I$1/usr/include"
5084e5b757fSkupfer}
5094e5b757fSkupfer
5104e5b757fSkupfer#
51152a52aebSkupfer# Wrapper over commands that generate BFU archives.  The entire
51252a52aebSkupfer# command output gets written to LOGFILE, and any unexpected messages
51352a52aebSkupfer# are written to the mail message.  Returns with the status of the
51452a52aebSkupfer# original command.
51552a52aebSkupfer#
51652a52aebSkupfermakebfu_filt() {
51752a52aebSkupfer	typeset tmplog
51852a52aebSkupfer	typeset errors
51952a52aebSkupfer	typeset cmd
52052a52aebSkupfer	integer cmd_stat
52152a52aebSkupfer
52252a52aebSkupfer	cmd="$1"
52352a52aebSkupfer	shift
52452a52aebSkupfer	tmplog="$TMPDIR/$cmd.out"
52552a52aebSkupfer	errors="$TMPDIR/$cmd-errors"
52652a52aebSkupfer	$cmd $* > "$tmplog" 2>&1
52752a52aebSkupfer	cmd_stat=$?
52852a52aebSkupfer	cat "$tmplog" >> "$LOGFILE"
52952a52aebSkupfer	grep -v "^Creating .* archive:" "$tmplog" | grep -v "^Making" | \
53052a52aebSkupfer	    grep -v "^$" | sort -u > "$errors"
53152a52aebSkupfer	if [[ -s "$errors" ]]; then
53252a52aebSkupfer		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
53352a52aebSkupfer		    >> "$mail_msg_file"
53452a52aebSkupfer		cat "$errors" >> "$mail_msg_file"
53552a52aebSkupfer	fi
53652a52aebSkupfer	rm -f "$tmplog" "$errors"
53752a52aebSkupfer	return $cmd_stat
53852a52aebSkupfer}
53952a52aebSkupfer
54052a52aebSkupfer#
5414e5b757fSkupfer# Function to do the build, including cpio archive and package generation.
5424e5b757fSkupfer# usage: build LABEL SUFFIX MULTIPROTO
5434e5b757fSkupfer# - LABEL is used to tag build output.
5444e5b757fSkupfer# - SUFFIX is used to distinguish files (e.g., debug vs non-debug).
5454e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
5464e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
5474e5b757fSkupfer#
5487c478bd9Sstevel@tonic-gatebuild() {
5497c478bd9Sstevel@tonic-gate	LABEL=$1
5507c478bd9Sstevel@tonic-gate	SUFFIX=$2
5514e5b757fSkupfer	MULTIPROTO=$3
5527c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
5537c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
5547c478bd9Sstevel@tonic-gate	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
5557c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
556d8fd4470Sjg	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
557d8fd4470Sjg		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
558d8fd4470Sjg	fi
5597c478bd9Sstevel@tonic-gate
5604e5b757fSkupfer	ORIGROOT=$ROOT
5614e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
5624e5b757fSkupfer
5634e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
5644e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
5654e5b757fSkupfer
5667c478bd9Sstevel@tonic-gate	this_build_ok=y
5677c478bd9Sstevel@tonic-gate	#
5687c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
5697c478bd9Sstevel@tonic-gate	#
5707c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
5717c478bd9Sstevel@tonic-gate		>> $LOGFILE
5727c478bd9Sstevel@tonic-gate
5737c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
5747c478bd9Sstevel@tonic-gate	cd $SRC
5757c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
5767c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
57732f1e47bSsommerfe
578cdf0c1d5Smjnelson	if [[ "$SCM_TYPE" = teamware ]]; then
57932f1e47bSsommerfe		echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
580cdf0c1d5Smjnelson		egrep 'sccs(check:| *get)' $SRC/${INSTALLOG}.out >> \
581cdf0c1d5Smjnelson			$mail_msg_file
582cdf0c1d5Smjnelson	fi
58332f1e47bSsommerfe
5847c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
5857c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
5867c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
5877c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
5887c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
5897c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
5907c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
5917c478bd9Sstevel@tonic-gate		build_ok=n
5927c478bd9Sstevel@tonic-gate		this_build_ok=n
5937c478bd9Sstevel@tonic-gate	fi
5947c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
5957c478bd9Sstevel@tonic-gate		>> $mail_msg_file
5967c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
5977c478bd9Sstevel@tonic-gate		build_ok=n
5987c478bd9Sstevel@tonic-gate		this_build_ok=n
5997c478bd9Sstevel@tonic-gate	fi
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
6027c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
6037c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
6047c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
6057c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
6067c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
6077c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
6087c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
6097c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6107c478bd9Sstevel@tonic-gate	fi
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
6137c478bd9Sstevel@tonic-gate		>> $LOGFILE
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
6167c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
6197c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
6207c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
6217c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
6227c478bd9Sstevel@tonic-gate		fi
6237c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
6247c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
6257c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
6267c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
6277c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
6287c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
6297c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
6307c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
6317c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
6327c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
6337c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
6347c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
6357c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
6367c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
6377c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
6387c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
6397c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
6407c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
6417c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
6427c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
6437c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
6447c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
6457c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
6467c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
6477c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
6487c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
6497c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
6507c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
6517c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
6527c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
6537c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
6547c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
6557c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
6567c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
6577c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
6587c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
6597c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
6607c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
6617c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
6627c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
6637c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
6647c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
6657c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
6667c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
6677c478bd9Sstevel@tonic-gate			| egrep -v '::' \
6687c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
669010b217aSwesolows			| egrep -v '^\+' \
67003eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
671c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
6727c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
6737c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
6747c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
6757c478bd9Sstevel@tonic-gate		fi
6767c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
6777c478bd9Sstevel@tonic-gate			>>$mail_msg_file
6787c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
6797c478bd9Sstevel@tonic-gate	fi
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate	#
68223259b79Srotondo	#	Re-sign selected binaries using signing server
68323259b79Srotondo	#	(gatekeeper builds only)
68423259b79Srotondo	#
6852210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
68623259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
68723259b79Srotondo		signing_file="${TMPDIR}/signing"
68823259b79Srotondo		rm -f ${signing_file}
68923259b79Srotondo		export CODESIGN_USER
69023259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
69123259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
69223259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
69323259b79Srotondo		    >> $LOGFILE
69423259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
69523259b79Srotondo		    >> $mail_msg_file
69623259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
697cdf0c1d5Smjnelson		if (( $? == 0 )) ; then
6982210853dSjohnz			build_ok=n
6992210853dSjohnz			this_build_ok=n
7002210853dSjohnz		fi
70123259b79Srotondo	fi
70223259b79Srotondo
70323259b79Srotondo	#
7047c478bd9Sstevel@tonic-gate	#	Create cpio archives for preintegration testing (PIT)
7057c478bd9Sstevel@tonic-gate	#
7067c478bd9Sstevel@tonic-gate	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
7077c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
7087c478bd9Sstevel@tonic-gate			>> $LOGFILE
70952a52aebSkupfer		makebfu_filt makebfu
7107c478bd9Sstevel@tonic-gate		# hack for test folks
7117c478bd9Sstevel@tonic-gate		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
7127c478bd9Sstevel@tonic-gate			X=/net/`uname -n`${CPIODIR}
7137c478bd9Sstevel@tonic-gate		else
7147c478bd9Sstevel@tonic-gate			X=${CPIODIR}
7157c478bd9Sstevel@tonic-gate		fi
7167c478bd9Sstevel@tonic-gate		echo "Archive_directory: ${X}" >${TMPDIR}/f
7179a6d9a08Sdm120769		cp ${TMPDIR}/f $(dirname $(dirname ${CPIODIR}))/.${MACH}_wgtrun
7187c478bd9Sstevel@tonic-gate		rm -f ${TMPDIR}/f
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate	else
7217c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL cpio archives ====\n" \
7227c478bd9Sstevel@tonic-gate			>> $LOGFILE
7237c478bd9Sstevel@tonic-gate	fi
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate	#
7267c478bd9Sstevel@tonic-gate	#	Building Packages
7277c478bd9Sstevel@tonic-gate	#
7287c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
7297c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL packages at `date` ====\n" \
7307c478bd9Sstevel@tonic-gate			>> $LOGFILE
7317c478bd9Sstevel@tonic-gate		rm -f $SRC/pkgdefs/${INSTALLOG}.out
7327c478bd9Sstevel@tonic-gate		echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
7337c478bd9Sstevel@tonic-gate		rm -rf $PKGARCHIVE
7347c478bd9Sstevel@tonic-gate		mkdir -p $PKGARCHIVE
735d8fd4470Sjg
736d8fd4470Sjg		#
737d8fd4470Sjg		# Optional build of sparc realmode on i386
738d8fd4470Sjg		#
739d8fd4470Sjg		if [ "$MACH" = "i386" ] && [ "${SPARC_RM_PKGARCHIVE}" ]; then
740d8fd4470Sjg			echo "Clearing out ${SPARC_RM_PKGARCHIVE} ..." \
741d8fd4470Sjg				>> $LOGFILE
742d8fd4470Sjg			rm -rf ${SPARC_RM_PKGARCHIVE}
743d8fd4470Sjg			mkdir -p ${SPARC_RM_PKGARCHIVE}
744d8fd4470Sjg		fi
745d8fd4470Sjg
7467c478bd9Sstevel@tonic-gate		cd $SRC/pkgdefs
7477c478bd9Sstevel@tonic-gate		$MAKE -e install 2>&1 | \
7487c478bd9Sstevel@tonic-gate			tee -a $SRC/pkgdefs/${INSTALLOG}.out >> $LOGFILE
7497c478bd9Sstevel@tonic-gate		echo "\n==== Package build errors ($LABEL) ====\n" \
7507c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7517c478bd9Sstevel@tonic-gate		egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/${INSTALLOG}.out | \
7527c478bd9Sstevel@tonic-gate			grep ':' | \
7537c478bd9Sstevel@tonic-gate			grep -v PSTAMP | \
7547c478bd9Sstevel@tonic-gate			egrep -v "Ignoring unknown host" \
7557c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7567c478bd9Sstevel@tonic-gate	else
7577c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
7587c478bd9Sstevel@tonic-gate	fi
7594e5b757fSkupfer
7604e5b757fSkupfer	ROOT=$ORIGROOT
7617c478bd9Sstevel@tonic-gate}
7627c478bd9Sstevel@tonic-gate
7631fe69678Skupfer# Usage: dolint /dir y|n
7647c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
7651fe69678Skupferdolint() {
7667c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
7671fe69678Skupfer		echo "dolint error: $1 is not a directory"
7687c478bd9Sstevel@tonic-gate		exit 1
7697c478bd9Sstevel@tonic-gate	fi
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
7721fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
7737c478bd9Sstevel@tonic-gate		exit 1
7747c478bd9Sstevel@tonic-gate	fi
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate	lintdir=$1
7777c478bd9Sstevel@tonic-gate	dodiff=$2
7787c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
7797c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
7807c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
7814e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
7824e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
7837c478bd9Sstevel@tonic-gate
7844e5b757fSkupfer	set_debug_build_flags
7857c478bd9Sstevel@tonic-gate
7867c478bd9Sstevel@tonic-gate	#
7877c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
7887c478bd9Sstevel@tonic-gate	#
7897c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate	# remove old lint.out
7927c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
7937c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
7947c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
7957c478bd9Sstevel@tonic-gate	fi
7967c478bd9Sstevel@tonic-gate
7977c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
7987c478bd9Sstevel@tonic-gate	cd $lintdir
7997c478bd9Sstevel@tonic-gate	#
8007c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
8017c478bd9Sstevel@tonic-gate	#
8027c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
803cdf0c1d5Smjnelson	    `find . \( -name SCCS -o -name .hg -o -name .svn \) \
804cdf0c1d5Smjnelson	    	-prune -o -type f -name '*.ln' -print `
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
8077c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
8087c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
8097c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
8107c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
8117c478bd9Sstevel@tonic-gate		>> $mail_msg_file
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
8167c478bd9Sstevel@tonic-gate		>>$mail_msg_file
8177c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
8207c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
8217c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
8227c478bd9Sstevel@tonic-gate	fi
8237c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
8247c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
8257c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
8267c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
8277c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
8287c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
8297c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
8307c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
8317c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
8327c478bd9Sstevel@tonic-gate	fi
8337c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
8347c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
8357c478bd9Sstevel@tonic-gate			>>$mail_msg_file
8367c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
8377c478bd9Sstevel@tonic-gate		# above
8387c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
8397c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
8407c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
8417c478bd9Sstevel@tonic-gate			>> $mail_msg_file
8427c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
8437c478bd9Sstevel@tonic-gate			>> $mail_msg_file
8447c478bd9Sstevel@tonic-gate	fi
8457c478bd9Sstevel@tonic-gate}
8467c478bd9Sstevel@tonic-gate
8477c478bd9Sstevel@tonic-gate# Install proto area from IHV build
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gatecopy_ihv_proto() {
8507c478bd9Sstevel@tonic-gate
8516fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
8527c478bd9Sstevel@tonic-gate		>> $LOGFILE
8537c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
8547c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
8557c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
8567c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
8577c478bd9Sstevel@tonic-gate		fi
8586fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
8597c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
8607c478bd9Sstevel@tonic-gate		tar -cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
8617c478bd9Sstevel@tonic-gate	else
8627c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
8637c478bd9Sstevel@tonic-gate	fi
8644e5b757fSkupfer
8654e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
8664e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
8674e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
8684e5b757fSkupfer			mkdir -p $ROOT-nd
8694e5b757fSkupfer		fi
8704e5b757fSkupfer		# If there's a non-debug version of the IHV proto area,
8714e5b757fSkupfer		# copy it, but copy something if there's not.
8724e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
8734e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
8744e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
8754e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
8764e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
8774e5b757fSkupfer			cd $IA32_IHV_ROOT
8784e5b757fSkupfer		else
8794e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
8804e5b757fSkupfer			return
8814e5b757fSkupfer		fi
8824e5b757fSkupfer		tar -cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
8834e5b757fSkupfer	fi
8847c478bd9Sstevel@tonic-gate}
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
8871fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
8887c478bd9Sstevel@tonic-gatecopy_ihv_pkgs() {
8897c478bd9Sstevel@tonic-gate	LABEL=$1
8907c478bd9Sstevel@tonic-gate	SUFFIX=$2
8917c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
8927c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
8937c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
8947c478bd9Sstevel@tonic-gate
8957c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
8967c478bd9Sstevel@tonic-gate		>> $LOGFILE
8977c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
8987c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
8997c478bd9Sstevel@tonic-gate		tar -cf - * | \
9007c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
9017c478bd9Sstevel@tonic-gate	else
9027c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
9037c478bd9Sstevel@tonic-gate	fi
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
9067c478bd9Sstevel@tonic-gate		>> $LOGFILE
9077c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
9087c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
9097c478bd9Sstevel@tonic-gate		tar -cf - * | \
9107c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
9117c478bd9Sstevel@tonic-gate	else
9127c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
9137c478bd9Sstevel@tonic-gate	fi
9147c478bd9Sstevel@tonic-gate}
9157c478bd9Sstevel@tonic-gate
9164e5b757fSkupfer#
9174e5b757fSkupfer# Build and install the onbld tools.
9184e5b757fSkupfer#
9191fe69678Skupfer# usage: build_tools DESTROOT
9204e5b757fSkupfer#
9214e5b757fSkupfer# returns non-zero status if the build was successful.
9224e5b757fSkupfer#
9237c478bd9Sstevel@tonic-gatebuild_tools() {
9247c478bd9Sstevel@tonic-gate	DESTROOT=$1
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
9297c478bd9Sstevel@tonic-gate		>> $LOGFILE
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
9327c478bd9Sstevel@tonic-gate	cd ${TOOLS}
9337c478bd9Sstevel@tonic-gate	/bin/time $MAKE ROOT=${DESTROOT} -e install 2>&1 | \
9347c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
9377c478bd9Sstevel@tonic-gate
9387c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
9397c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
9407c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
9417c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
9424e5b757fSkupfer	return $?
9434e5b757fSkupfer}
9444e5b757fSkupfer
9454e5b757fSkupfer#
9464e5b757fSkupfer# Set up to use locally installed tools.
9474e5b757fSkupfer#
9484e5b757fSkupfer# usage: use_tools TOOLSROOT
9494e5b757fSkupfer#
9504e5b757fSkupferuse_tools() {
9514e5b757fSkupfer	TOOLSROOT=$1
9524e5b757fSkupfer
9534e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
9547c478bd9Sstevel@tonic-gate	export STABS
9554e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
9567c478bd9Sstevel@tonic-gate	export CTFSTABS
9574e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
9587c478bd9Sstevel@tonic-gate	export GENOFFSETS
9597c478bd9Sstevel@tonic-gate
9604e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
9617c478bd9Sstevel@tonic-gate	export CTFCONVERT
9624e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
9637c478bd9Sstevel@tonic-gate	export CTFMERGE
9647c478bd9Sstevel@tonic-gate
9654e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
9667c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
9674e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
9687c478bd9Sstevel@tonic-gate	export CTFFINDMOD
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
9714e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
9727c478bd9Sstevel@tonic-gate	else
9734e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
9747c478bd9Sstevel@tonic-gate	fi
9757c478bd9Sstevel@tonic-gate	export ELFSIGN
9767c478bd9Sstevel@tonic-gate
9774e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
9784e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
9797c478bd9Sstevel@tonic-gate	export PATH
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
9827c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
9837c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
9847c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
9857c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
9867c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
9877c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
9887c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
9897c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
9907c478bd9Sstevel@tonic-gate}
9917c478bd9Sstevel@tonic-gate
9927c478bd9Sstevel@tonic-gatestaffer() {
9937c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
9947c478bd9Sstevel@tonic-gate		"$@"
9957c478bd9Sstevel@tonic-gate	else
9967c478bd9Sstevel@tonic-gate		arg="\"$1\""
9977c478bd9Sstevel@tonic-gate		shift
9987c478bd9Sstevel@tonic-gate		for i
9997c478bd9Sstevel@tonic-gate		do
10007c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
10017c478bd9Sstevel@tonic-gate		done
10027c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
10037c478bd9Sstevel@tonic-gate	fi
10047c478bd9Sstevel@tonic-gate}
10057c478bd9Sstevel@tonic-gate
1006085d331dSkupfer#
1007085d331dSkupfer# Verify that the closed tree is present if it needs to be.
1008085d331dSkupfer# Sets CLOSED_IS_PRESENT for future use.
1009085d331dSkupfer#
1010085d331dSkupfercheck_closed_tree() {
1011085d331dSkupfer	if [ -z "$CLOSED_IS_PRESENT" ]; then
10125c53ea7aSmjnelson		if [ -d $CODEMGR_WS/usr/closed ]; then
1013085d331dSkupfer			CLOSED_IS_PRESENT="yes"
1014085d331dSkupfer		else
1015085d331dSkupfer			CLOSED_IS_PRESENT="no"
1016085d331dSkupfer		fi
1017085d331dSkupfer		export CLOSED_IS_PRESENT
1018085d331dSkupfer	fi
1019085d331dSkupfer	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
1020085d331dSkupfer		#
1021085d331dSkupfer		# If it's an old (pre-split) tree or an empty
1022085d331dSkupfer		# workspace, don't complain.
1023085d331dSkupfer		#
1024085d331dSkupfer		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
1025085d331dSkupfer			echo "If the closed sources are not present," \
1026085d331dSkupfer			    "ON_CLOSED_BINS"
1027085d331dSkupfer			echo "must point to the closed binaries tree."
1028cdf0c1d5Smjnelson			build_ok=n
1029085d331dSkupfer			exit 1
1030085d331dSkupfer		fi
1031085d331dSkupfer	fi
1032085d331dSkupfer}
10337c478bd9Sstevel@tonic-gate
1034d77e7149Ssommerfeobsolete_build() {
1035d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
1036d77e7149Ssommerfe}
1037d77e7149Ssommerfe
10384e5b757fSkupfer#
10394e5b757fSkupfer# wrapper over wsdiff.
10404e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
10414e5b757fSkupfer#
10424e5b757fSkupferdo_wsdiff() {
10434e5b757fSkupfer	label=$1
10444e5b757fSkupfer	oldproto=$2
10454e5b757fSkupfer	newproto=$3
10464e5b757fSkupfer
10474e5b757fSkupfer	echo "\n==== Objects that differ since last build ($label) ====\n" | \
10484e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
10494e5b757fSkupfer
10504e5b757fSkupfer	wsdiff="wsdiff"
10514e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
10524e5b757fSkupfer
10534e5b757fSkupfer	$wsdiff -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
10544e5b757fSkupfer		    tee -a $LOGFILE >> $mail_msg_file
10554e5b757fSkupfer}
10564e5b757fSkupfer
10574e5b757fSkupfer#
10584e5b757fSkupfer# Functions for setting build flags (debug/non-debug).  Keep them
10594e5b757fSkupfer# together.
10604e5b757fSkupfer#
10614e5b757fSkupfer
10624e5b757fSkupferset_non_debug_build_flags() {
10634e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
10644e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
10654e5b757fSkupfer	unset EXTRA_OPTIONS
10664e5b757fSkupfer	unset EXTRA_CFLAGS
10674e5b757fSkupfer}
10684e5b757fSkupfer
10694e5b757fSkupferset_debug_build_flags() {
10704e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
10714e5b757fSkupfer	unset RELEASE_BUILD
10724e5b757fSkupfer	unset EXTRA_OPTIONS
10734e5b757fSkupfer	unset EXTRA_CFLAGS
10744e5b757fSkupfer}
10754e5b757fSkupfer
1076d77e7149Ssommerfe
10777c478bd9Sstevel@tonic-gateMACH=`uname -p`
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
10807c478bd9Sstevel@tonic-gate	OPTHOME=/opt
10817c478bd9Sstevel@tonic-gate	export OPTHOME
10827c478bd9Sstevel@tonic-gatefi
10837c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
10847c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
10857c478bd9Sstevel@tonic-gate	export TEAMWARE
10867c478bd9Sstevel@tonic-gatefi
10877c478bd9Sstevel@tonic-gate
10881fe69678SkupferUSAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H|O ] <env_file>
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gateWhere:
1091d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
10927c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
10937c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
10947c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
10957c478bd9Sstevel@tonic-gate		E - build exportable source
10967c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
10977c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
10981fe69678Skupfer		O - build (only) open source
10997c478bd9Sstevel@tonic-gate
11007c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
11017c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
11027c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
11037c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
11067c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
11097c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
11107c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
11117c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
11127c478bd9Sstevel@tonic-gate	-G	gate keeper default group of options (-au)
11137c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
11147c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
11157c478bd9Sstevel@tonic-gate	-N	do not run protocmp
11164e5b757fSkupfer	-O	generate OpenSolaris deliverables
11177c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
11187c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
11197c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
112004a42e3eSszhou	-X	copy x86 IHV proto area
11217c478bd9Sstevel@tonic-gate	-a	create cpio archives
11227c478bd9Sstevel@tonic-gate	-f	find unreferenced files
11237c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
11247c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
11257c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
11267c478bd9Sstevel@tonic-gate	-n      do not do a bringover
11277c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
11287c478bd9Sstevel@tonic-gate	-p	create packages
11297c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
11307c478bd9Sstevel@tonic-gate	-t	build and use the tools in $SRC/tools
11317c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
11327c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
113396ccc8cbSesaxe	-w	report on differences between previous and current proto areas
11347c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
11357c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
11367c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
11377c478bd9Sstevel@tonic-gate		E - build exportable source
11387c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
11397c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
11401fe69678Skupfer		O - build (only) open source
11417c478bd9Sstevel@tonic-gate'
11427c478bd9Sstevel@tonic-gate#
11437c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
11447c478bd9Sstevel@tonic-gate#
11457c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
11461c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
11477c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
11487c478bd9Sstevel@tonic-gate#
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
11517c478bd9Sstevel@tonic-gateA_FLAG=n
11527c478bd9Sstevel@tonic-gatea_FLAG=n
11537c478bd9Sstevel@tonic-gateC_FLAG=n
11546c3c9007SstevelD_FLAG=n
11557c478bd9Sstevel@tonic-gateF_FLAG=n
11567c478bd9Sstevel@tonic-gatef_FLAG=n
11577c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
11587c478bd9Sstevel@tonic-gatel_FLAG=n
11596c3c9007SstevelM_FLAG=n
11607c478bd9Sstevel@tonic-gatem_FLAG=n
11616c3c9007SstevelN_FLAG=n
11626c3c9007Ssteveln_FLAG=n
11634e5b757fSkupferO_FLAG=n
11646c3c9007Sstevelo_FLAG=n
11656c3c9007SstevelP_FLAG=n
11667c478bd9Sstevel@tonic-gatep_FLAG=n
11677c478bd9Sstevel@tonic-gater_FLAG=n
11686c3c9007SstevelT_FLAG=n
1169fd7cef36Ssuhat_FLAG=y
11707c478bd9Sstevel@tonic-gateU_FLAG=n
11716c3c9007Sstevelu_FLAG=n
11727c478bd9Sstevel@tonic-gateV_FLAG=n
11737c478bd9Sstevel@tonic-gateW_FLAG=n
11746c3c9007Sstevelw_FLAG=n
11756c3c9007SstevelX_FLAG=n
11766c3c9007Sstevelz_FLAG=n
11777c478bd9Sstevel@tonic-gateSD_FLAG=n
11786c3c9007SstevelSE_FLAG=n
11797c478bd9Sstevel@tonic-gateSH_FLAG=n
11801fe69678SkupferSO_FLAG=n
11817c478bd9Sstevel@tonic-gate#
11827c478bd9Sstevel@tonic-gateXMOD_OPT=
11837c478bd9Sstevel@tonic-gate#
11847c478bd9Sstevel@tonic-gatebuild_ok=y
11852e02daeeSRainer Orthtools_build_ok=y
11861fe69678Skupfer
11871fe69678Skupferis_source_build() {
11881fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
11891fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
11901fe69678Skupfer	return $?
11911fe69678Skupfer}
11921fe69678Skupfer
11937c478bd9Sstevel@tonic-gate#
11947c478bd9Sstevel@tonic-gate# examine arguments
11957c478bd9Sstevel@tonic-gate#
11967c478bd9Sstevel@tonic-gate
11971fe69678Skupfer#
11981fe69678Skupfer# single function for setting -S flag and doing error checking.
11991fe69678Skupfer# usage: set_S_flag <type>
12001fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
12011fe69678Skupfer#
12021fe69678Skupferset_S_flag() {
12031fe69678Skupfer	if is_source_build; then
12041fe69678Skupfer		echo "Can only build one source variant at a time."
12051fe69678Skupfer		exit 1
12061fe69678Skupfer	fi
12071fe69678Skupfer	if [ "$1" = "E" ]; then
12081fe69678Skupfer		SE_FLAG=y
12091fe69678Skupfer	elif [ "$1" = "D" ]; then
12101fe69678Skupfer		SD_FLAG=y
12111fe69678Skupfer	elif [ "$1" = "H" ]; then
12121fe69678Skupfer		SH_FLAG=y
12131fe69678Skupfer	elif [ "$1" = "O" ]; then
12141fe69678Skupfer		SO_FLAG=y
12151fe69678Skupfer	else
12161fe69678Skupfer		echo "$USAGE"
12171fe69678Skupfer		exit 1
12181fe69678Skupfer	fi
12191fe69678Skupfer}
12201fe69678Skupfer
12217c478bd9Sstevel@tonic-gateOPTIND=1
12226c3c9007Sstevelwhile getopts inS:tV: FLAG
12237c478bd9Sstevel@tonic-gatedo
12247c478bd9Sstevel@tonic-gate	case $FLAG in
12257c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
12267c478bd9Sstevel@tonic-gate		;;
12277c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
12287c478bd9Sstevel@tonic-gate		;;
12297c478bd9Sstevel@tonic-gate	  S )
12301fe69678Skupfer		set_S_flag $OPTARG
12317c478bd9Sstevel@tonic-gate		;;
1232fd7cef36Ssuha	 +t )	t_FLAG=n
12337c478bd9Sstevel@tonic-gate		;;
12346c3c9007Sstevel	  V )	V_FLAG=y
12356c3c9007Sstevel		V_ARG="$OPTARG"
12366c3c9007Sstevel		;;
12377c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
12387c478bd9Sstevel@tonic-gate		exit 1
12397c478bd9Sstevel@tonic-gate		;;
12407c478bd9Sstevel@tonic-gate	esac
12417c478bd9Sstevel@tonic-gatedone
12427c478bd9Sstevel@tonic-gate
12437c478bd9Sstevel@tonic-gate# correct argument count after options
12447c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
12457c478bd9Sstevel@tonic-gate
12467c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
12477c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
12487c478bd9Sstevel@tonic-gate	echo "$USAGE"
12497c478bd9Sstevel@tonic-gate	exit 1
12507c478bd9Sstevel@tonic-gatefi
12517c478bd9Sstevel@tonic-gate
12527c478bd9Sstevel@tonic-gate# check if user is running nightly as root
12537c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
12547c478bd9Sstevel@tonic-gate# when root invokes nightly.
12557c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
12567c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
12577c478bd9Sstevel@tonic-gate
12587c478bd9Sstevel@tonic-gate#
12597c478bd9Sstevel@tonic-gate# force locale to C
12607c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
12617c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
12627c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
12637c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
12647c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
12657c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
12667c478bd9Sstevel@tonic-gate
12677c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
12687c478bd9Sstevel@tonic-gateunset LD_OPTIONS
12697c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
12707c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
12717c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
12727c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
12737c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
12747c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
12757c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
12767c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
12777c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
12787c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
12797c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
12807c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
12817c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
12827c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
12837c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
12847c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
12857c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
12867c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
12877c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
12887c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
12897c478bd9Sstevel@tonic-gate
12907c478bd9Sstevel@tonic-gateunset CONFIG
12917c478bd9Sstevel@tonic-gateunset GROUP
12927c478bd9Sstevel@tonic-gateunset OWNER
12937c478bd9Sstevel@tonic-gateunset REMOTE
12947c478bd9Sstevel@tonic-gateunset ENV
12957c478bd9Sstevel@tonic-gateunset ARCH
12967c478bd9Sstevel@tonic-gateunset CLASSPATH
12977c478bd9Sstevel@tonic-gateunset NAME
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate#
13007c478bd9Sstevel@tonic-gate#	Setup environmental variables
13017c478bd9Sstevel@tonic-gate#
130247703246Ssommerfeif [ -f /etc/nightly.conf ]; then
130347703246Ssommerfe	. /etc/nightly.conf
130447703246Ssommerfefi
130547703246Ssommerfe
13067c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
13077c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
13087c478bd9Sstevel@tonic-gate		. $1
13097c478bd9Sstevel@tonic-gate	else
13107c478bd9Sstevel@tonic-gate		. ./$1
13117c478bd9Sstevel@tonic-gate	fi
13127c478bd9Sstevel@tonic-gateelse
13137c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
13147c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
13157c478bd9Sstevel@tonic-gate	else
13167c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
13177c478bd9Sstevel@tonic-gate		exit 1
13187c478bd9Sstevel@tonic-gate	fi
13197c478bd9Sstevel@tonic-gatefi
13207c478bd9Sstevel@tonic-gate
13211fe69678Skupfer# contents of stdenv.sh inserted after next line:
13221fe69678Skupfer# STDENV_START
13231fe69678Skupfer# STDENV_END
13241fe69678Skupfer
13257c478bd9Sstevel@tonic-gate#
13267c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
13277c478bd9Sstevel@tonic-gate#
13287c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
13297c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
13307c478bd9Sstevel@tonic-gateelse
13317c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
13327c478bd9Sstevel@tonic-gatefi
13337c478bd9Sstevel@tonic-gate
13347c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
13357c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate#
13387c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
13397c478bd9Sstevel@tonic-gate#
13407c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
13417c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
13427c478bd9Sstevel@tonic-gatefi
13437c478bd9Sstevel@tonic-gate
13447c478bd9Sstevel@tonic-gate#
13457c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
13467c478bd9Sstevel@tonic-gate#
13477c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
13487c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
13497c478bd9Sstevel@tonic-gatefi
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate#
1352cdf0c1d5Smjnelson# If CLOSED_BRINGOVER_WS was not specified, let it default to CLOSED_CLONE_WS
1353cdf0c1d5Smjnelson#
1354cdf0c1d5Smjnelsonif [ "$CLOSED_BRINGOVER_WS" = "" ]; then
1355cdf0c1d5Smjnelson	CLOSED_BRINGOVER_WS=$CLOSED_CLONE_WS
1356cdf0c1d5Smjnelsonfi
1357cdf0c1d5Smjnelson
1358cdf0c1d5Smjnelson#
1359fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1360a5c06a9eSmike_s#
1361a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1362fb23a357Skupfer	BRINGOVER_FILES="usr"
1363a5c06a9eSmike_sfi
1364a5c06a9eSmike_s
1365fb9f9b97Skupfer#
1366fb9f9b97Skupfer# If the closed sources are not present, the closed binaries must be
1367fb9f9b97Skupfer# present for the build to succeed.  If there's no pointer to the
1368fb9f9b97Skupfer# closed binaries, flag that now, rather than forcing the user to wait
1369fb9f9b97Skupfer# a couple hours (or more) to find out.
1370fb9f9b97Skupfer#
1371085d331dSkupferorig_closed_is_present="$CLOSED_IS_PRESENT"
1372085d331dSkupfercheck_closed_tree
1373fb9f9b97Skupfer
1374a5c06a9eSmike_s#
13757c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1376b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
13777c478bd9Sstevel@tonic-gate#
1378d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
13797c478bd9Sstevel@tonic-gateOPTIND=1
13804e5b757fSkupferwhile getopts AaBCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
13817c478bd9Sstevel@tonic-gatedo
13827c478bd9Sstevel@tonic-gate	case $FLAG in
13837c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
13847c478bd9Sstevel@tonic-gate		;;
13856c3c9007Sstevel	  a )	a_FLAG=y
13866c3c9007Sstevel		;;
13877c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
13887c478bd9Sstevel@tonic-gate		;; # old version of D
13896c3c9007Sstevel	  C )	C_FLAG=y
13907c478bd9Sstevel@tonic-gate		;;
13917c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
13927c478bd9Sstevel@tonic-gate		;;
13936c3c9007Sstevel	  F )	F_FLAG=y
13947c478bd9Sstevel@tonic-gate		;;
13956c3c9007Sstevel	  f )	f_FLAG=y
13967c478bd9Sstevel@tonic-gate		;;
13977c478bd9Sstevel@tonic-gate	  G )	a_FLAG=y
13987c478bd9Sstevel@tonic-gate		u_FLAG=y
13997c478bd9Sstevel@tonic-gate		;;
14007c478bd9Sstevel@tonic-gate	  I )	a_FLAG=y
14017c478bd9Sstevel@tonic-gate		m_FLAG=y
14027c478bd9Sstevel@tonic-gate		p_FLAG=y
14037c478bd9Sstevel@tonic-gate		u_FLAG=y
14047c478bd9Sstevel@tonic-gate		;;
14057c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
14067c478bd9Sstevel@tonic-gate		;;
14076c3c9007Sstevel	  l )	l_FLAG=y
14086c3c9007Sstevel		;;
14096c3c9007Sstevel	  M )	M_FLAG=y
14106c3c9007Sstevel		;;
14116c3c9007Sstevel	  m )	m_FLAG=y
14126c3c9007Sstevel		;;
14136c3c9007Sstevel	  N )	N_FLAG=y
14146c3c9007Sstevel		;;
14157c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
14167c478bd9Sstevel@tonic-gate		;;
14174e5b757fSkupfer	  O )	O_FLAG=y
14184e5b757fSkupfer		;;
14197c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
14207c478bd9Sstevel@tonic-gate		;;
14216c3c9007Sstevel	  P )	P_FLAG=y
14226c3c9007Sstevel		;; # obsolete
14237c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
14247c478bd9Sstevel@tonic-gate		;;
14256c3c9007Sstevel	  R )	m_FLAG=y
14266c3c9007Sstevel		p_FLAG=y
14276c3c9007Sstevel		;;
14287c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
14297c478bd9Sstevel@tonic-gate		;;
14306c3c9007Sstevel	  S )
14316c3c9007Sstevel		set_S_flag $OPTARG
14326c3c9007Sstevel		;;
14336c3c9007Sstevel	  T )	T_FLAG=y
14346c3c9007Sstevel		;; # obsolete
1435fd7cef36Ssuha	 +t )	t_FLAG=n
14367c478bd9Sstevel@tonic-gate		;;
14377c478bd9Sstevel@tonic-gate	  U )
14387c478bd9Sstevel@tonic-gate		if [ -z "${PARENT_ROOT}" ]; then
14397c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
14407c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
14417c478bd9Sstevel@tonic-gate			exit 1
14427c478bd9Sstevel@tonic-gate		fi
14437c478bd9Sstevel@tonic-gate		U_FLAG=y
14447c478bd9Sstevel@tonic-gate		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
14457c478bd9Sstevel@tonic-gate		;;
14466c3c9007Sstevel	  u )	u_FLAG=y
14477c478bd9Sstevel@tonic-gate		;;
14487c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
14497c478bd9Sstevel@tonic-gate		;;
14506c3c9007Sstevel
14516c3c9007Sstevel	  w )	w_FLAG=y
14527c478bd9Sstevel@tonic-gate		;;
14537c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
14547c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
14557c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
14567c478bd9Sstevel@tonic-gate			X_FLAG=y
14577c478bd9Sstevel@tonic-gate		fi
14587c478bd9Sstevel@tonic-gate		;;
14596c3c9007Sstevel	  x )	XMOD_OPT="-x"
14606c3c9007Sstevel		;;
14616c3c9007Sstevel	  z )	z_FLAG=y
14626c3c9007Sstevel		;;
14637c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
14647c478bd9Sstevel@tonic-gate		exit 1
14657c478bd9Sstevel@tonic-gate		;;
14667c478bd9Sstevel@tonic-gate	esac
14677c478bd9Sstevel@tonic-gatedone
14687c478bd9Sstevel@tonic-gate
14697c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
14707c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
14717c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
14727c478bd9Sstevel@tonic-gate		exit 1
14737c478bd9Sstevel@tonic-gate	fi
14747c478bd9Sstevel@tonic-gate
14757c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
14767c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
14777c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
14787c478bd9Sstevel@tonic-gate		export STAFFER
14797c478bd9Sstevel@tonic-gate	fi
14807c478bd9Sstevel@tonic-gatefi
14817c478bd9Sstevel@tonic-gate
14827c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
14837c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
14847c478bd9Sstevel@tonic-gate	export MAILTO
14857c478bd9Sstevel@tonic-gatefi
14867c478bd9Sstevel@tonic-gate
14877c478bd9Sstevel@tonic-gatePATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
14887c478bd9Sstevel@tonic-gatePATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
14897c478bd9Sstevel@tonic-gatePATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
14907c478bd9Sstevel@tonic-gateexport PATH
14917c478bd9Sstevel@tonic-gate
1492fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1493fb23a357Skupferrelsrcdirs="."
14945c53ea7aSmjnelsonif [[ -d $CODEMGR_WS/usr/closed && "$CLOSED_IS_PRESENT" != no ]]; then
1495fb9f9b97Skupfer	relsrcdirs="$relsrcdirs ../closed"
1496fb9f9b97Skupferfi
1497fb23a357Skupferabssrcdirs=""
1498fb23a357Skupferfor d in $relsrcdirs; do
1499fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1500fb23a357Skupferdone
1501fb23a357Skupfer
15027c478bd9Sstevel@tonic-gateunset CH
15037c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
15047c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
15057c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
15067c478bd9Sstevel@tonic-gate# the old ones still do.
15077c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
15087c478bd9Sstevel@tonic-gate	CH=
15097c478bd9Sstevel@tonic-gate	export CH
15107c478bd9Sstevel@tonic-gateelse
15117c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
15127c478bd9Sstevel@tonic-gatefi
15137c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
15147c478bd9Sstevel@tonic-gate
15157c478bd9Sstevel@tonic-gate# we export POUND_SIGN to speed up the build process -- prevents evaluation of
15167c478bd9Sstevel@tonic-gate# the Makefile.master definitions.
15176fec3625Sdduvallexport o_FLAG X_FLAG POUND_SIGN
15187c478bd9Sstevel@tonic-gate
15197c478bd9Sstevel@tonic-gatemaketype="distributed"
15207c478bd9Sstevel@tonic-gateMAKE=dmake
15217c478bd9Sstevel@tonic-gate# get the dmake version string alone
15227c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
15237c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
15247c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
15257c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
15267c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
15277c478bd9Sstevel@tonic-gate# extract the second (or final) integer
15287c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
15297c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
15307c478bd9Sstevel@tonic-gate# extract the first integer
15317c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
15327c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
15337c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
15347c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
15357c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
15367c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
15377c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
15387c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
15397c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
15407c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
15417c478bd9Sstevel@tonic-gate		exit 1
15427c478bd9Sstevel@tonic-gate	fi
15437c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
15447c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
15457c478bd9Sstevel@tonic-gate	cat <<EOF
15467c478bd9Sstevel@tonic-gate
15477c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
15487c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
15497c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
15507c478bd9Sstevel@tonic-gate
15517c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
15527c478bd9Sstevel@tonic-gateEOF
15537c478bd9Sstevel@tonic-gate	exit 1
15547c478bd9Sstevel@tonic-gatefi
15557c478bd9Sstevel@tonic-gateexport PATH
15567c478bd9Sstevel@tonic-gateexport MAKE
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
15597c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
15607c478bd9Sstevel@tonic-gate	export PATH
15617c478bd9Sstevel@tonic-gatefi
15627c478bd9Sstevel@tonic-gate
15637c478bd9Sstevel@tonic-gatehostname=`uname -n`
15647c478bd9Sstevel@tonic-gateif [ ! -f $HOME/.make.machines ]; then
15657c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS=4
15667c478bd9Sstevel@tonic-gateelse
15677c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
15687c478bd9Sstevel@tonic-gate	    tail -1 | awk -F= '{print $ 2;}'`"
15697c478bd9Sstevel@tonic-gate	if [ "$DMAKE_MAX_JOBS" = "" ]; then
15707c478bd9Sstevel@tonic-gate		DMAKE_MAX_JOBS=4
15717c478bd9Sstevel@tonic-gate	fi
15727c478bd9Sstevel@tonic-gatefi
15737c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
15747c478bd9Sstevel@tonic-gateexport DMAKE_MODE
15757c478bd9Sstevel@tonic-gateexport DMAKE_MAX_JOBS
15767c478bd9Sstevel@tonic-gate
15777c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
15787c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
15797c478bd9Sstevel@tonic-gate	exit 1
15807c478bd9Sstevel@tonic-gatefi
15817c478bd9Sstevel@tonic-gate
15827c478bd9Sstevel@tonic-gate#
15837c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
15847c478bd9Sstevel@tonic-gate#
15857c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
15867c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
15877c478bd9Sstevel@tonic-gatefi
15887c478bd9Sstevel@tonic-gate
158904a42e3eSszhou#
159004a42e3eSszhou# Check for IHV root for copying ihv proto area
159104a42e3eSszhou#
159204a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
159304a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
159404a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
159504a42e3eSszhou		args_ok=n
159604a42e3eSszhou        fi
159704a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
159804a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
159904a42e3eSszhou                args_ok=n
160004a42e3eSszhou        fi
16016fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
16026fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
16036fec3625Sdduvall		args_ok=n
16046fec3625Sdduvall        fi
16056fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
16066fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
16076fec3625Sdduvall                args_ok=n
16086fec3625Sdduvall        fi
160904a42e3eSszhoufi
161004a42e3eSszhou
16117c478bd9Sstevel@tonic-gate# Append source version
16127c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
16137c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
16147c478bd9Sstevel@tonic-gatefi
16157c478bd9Sstevel@tonic-gate
16167c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
16177c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
16187c478bd9Sstevel@tonic-gatefi
16197c478bd9Sstevel@tonic-gate
16207c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
16217c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
16227c478bd9Sstevel@tonic-gatefi
16237c478bd9Sstevel@tonic-gate
16241fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
16251fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
16261fe69678Skupferfi
16271fe69678Skupfer
16287c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
16297c478bd9Sstevel@tonic-gateexport TMPDIR
16307c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
16317c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
1632*85f46905SMark J. Nelsonchmod 777 $TMPDIR
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gate#
16357c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
16367c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
16377c478bd9Sstevel@tonic-gate# have the fix for 6271754
16387c478bd9Sstevel@tonic-gate#
16397c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
16407c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
16417c478bd9Sstevel@tonic-gate
16427c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
16437c478bd9Sstevel@tonic-gateTOOLS_PROTO=${TOOLS}/proto
16447c478bd9Sstevel@tonic-gate
16457c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
16467c478bd9Sstevel@tonic-gate
16477c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
16487c478bd9Sstevel@tonic-gate# fails to start correctly
16497c478bd9Sstevel@tonic-gatenewdir() {
16507c478bd9Sstevel@tonic-gate	dir=$1
16517c478bd9Sstevel@tonic-gate	toadd=
16527c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
16537c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
16547c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
16557c478bd9Sstevel@tonic-gate	done
16567c478bd9Sstevel@tonic-gate	torm=
16577c478bd9Sstevel@tonic-gate	newlist=
16587c478bd9Sstevel@tonic-gate	for dir in $toadd; do
16597c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
16607c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
16617c478bd9Sstevel@tonic-gate			torm="$dir $torm"
16627c478bd9Sstevel@tonic-gate		else
16637c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
16647c478bd9Sstevel@tonic-gate			return 1
16657c478bd9Sstevel@tonic-gate		fi
16667c478bd9Sstevel@tonic-gate	done
16677c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
16687c478bd9Sstevel@tonic-gate	return 0
16697c478bd9Sstevel@tonic-gate}
16707c478bd9Sstevel@tonic-gatenewdirlist=
16717c478bd9Sstevel@tonic-gate
16727c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
16737c478bd9Sstevel@tonic-gate
16747c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
16757c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
16767c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
16777c478bd9Sstevel@tonic-gate# built from this immediate source.
16787c478bd9Sstevel@tonic-gateENVLDLIBS1=
16797c478bd9Sstevel@tonic-gateENVLDLIBS2=
16807c478bd9Sstevel@tonic-gateENVLDLIBS3=
16817c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
16827c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
16837c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
16847c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
16857c478bd9Sstevel@tonic-gatePARENT_ROOT=
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
16887c478bd9Sstevel@tonic-gate	PARENT_ROOT
16897c478bd9Sstevel@tonic-gate
16907c478bd9Sstevel@tonic-gateCPIODIR_ORIG=$CPIODIR
16917c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
16927c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1693d8fd4470Sjgif [ "$SPARC_RM_PKGARCHIVE" ]; then
16947c478bd9Sstevel@tonic-gate	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1695d8fd4470Sjgfi
16967c478bd9Sstevel@tonic-gate
16977c478bd9Sstevel@tonic-gate#
16987c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
16997c478bd9Sstevel@tonic-gate#
17007c478bd9Sstevel@tonic-gate
17017c478bd9Sstevel@tonic-gatelogshuffle() {
1702fd7cef36Ssuha    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
17037c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
17047c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
17057c478bd9Sstevel@tonic-gate	fi
17067c478bd9Sstevel@tonic-gate	mkdir $LLOG
17074802ef38Srscott	export LLOG
17087c478bd9Sstevel@tonic-gate
17097c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
17107c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
171196ccc8cbSesaxe
17122e02daeeSRainer Orth		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
17132e02daeeSRainer Orth			mv $ATLOG/proto_list_tools_${MACH} $LLOG
17142e02daeeSRainer Orth	        fi
17152e02daeeSRainer Orth
171696ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
171796ccc8cbSesaxe		    	mv $TMPDIR/wsdiff.results $LLOG
171896ccc8cbSesaxe		fi
17194e5b757fSkupfer
17204e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
17214e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
17224e5b757fSkupfer		fi
17237c478bd9Sstevel@tonic-gate	fi
17247c478bd9Sstevel@tonic-gate
17257c478bd9Sstevel@tonic-gate	#
17267c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
17277c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
17287c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
17297c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
17307c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
17317c478bd9Sstevel@tonic-gate	#
17327c478bd9Sstevel@tonic-gate
17337c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
17347c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
17357c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
17367c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
17377c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
17387c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
17397c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
17407c478bd9Sstevel@tonic-gate	fi
17417c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
17427c478bd9Sstevel@tonic-gate
17437c478bd9Sstevel@tonic-gate	case "$build_ok" in
17447c478bd9Sstevel@tonic-gate		y)
17457c478bd9Sstevel@tonic-gate			state=Completed
17467c478bd9Sstevel@tonic-gate			;;
17477c478bd9Sstevel@tonic-gate		i)
17487c478bd9Sstevel@tonic-gate			state=Interrupted
17497c478bd9Sstevel@tonic-gate			;;
17507c478bd9Sstevel@tonic-gate		*)
17517c478bd9Sstevel@tonic-gate	    		state=Failed
17527c478bd9Sstevel@tonic-gate			;;
17537c478bd9Sstevel@tonic-gate	esac
175440bc9153Srscott	NIGHTLY_STATUS=$state
175540bc9153Srscott	export NIGHTLY_STATUS
17567c478bd9Sstevel@tonic-gate
175747703246Ssommerfe	run_hook POST_NIGHTLY $state
175847703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
17594802ef38Srscott
1760cdf0c1d5Smjnelson	cat $build_time_file $build_environ_file $mail_msg_file \
1761cdf0c1d5Smjnelson	    > ${LLOG}/mail_msg
17627c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
1763cdf0c1d5Smjnelson	    	cat ${LLOG}/mail_msg | /usr/bin/mailx -s \
17647c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
17657c478bd9Sstevel@tonic-gate			${MAILTO}
17667c478bd9Sstevel@tonic-gate	fi
17677c478bd9Sstevel@tonic-gate
17687c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
17697c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
17707c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
17717c478bd9Sstevel@tonic-gate	fi
17727c478bd9Sstevel@tonic-gate
17737c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
17747c478bd9Sstevel@tonic-gate}
17757c478bd9Sstevel@tonic-gate
17767c478bd9Sstevel@tonic-gate#
17777c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
17787c478bd9Sstevel@tonic-gate#
17797c478bd9Sstevel@tonic-gatecleanup() {
17807c478bd9Sstevel@tonic-gate    	logshuffle
17817c478bd9Sstevel@tonic-gate
17827c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
17837c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
17847c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
17857c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gate	set -- $newdirlist
17887c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
17897c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
17907c478bd9Sstevel@tonic-gate		shift; shift
17917c478bd9Sstevel@tonic-gate	done
17927c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
17937c478bd9Sstevel@tonic-gate}
17947c478bd9Sstevel@tonic-gate
17957c478bd9Sstevel@tonic-gatecleanup_signal() {
17967c478bd9Sstevel@tonic-gate    	build_ok=i
17977c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
17987c478bd9Sstevel@tonic-gate	exit 1
17997c478bd9Sstevel@tonic-gate}
18007c478bd9Sstevel@tonic-gate
18017c478bd9Sstevel@tonic-gatetrap cleanup 0
18027c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
18037c478bd9Sstevel@tonic-gate
18047c478bd9Sstevel@tonic-gate#
18057c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
18067c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
18077c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
18087c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
18097c478bd9Sstevel@tonic-gate# for the workspace).
1810cdf0c1d5Smjnelson#
18117c478bd9Sstevel@tonic-gatecreate_lock() {
18127c478bd9Sstevel@tonic-gate	lockf=$1
18137c478bd9Sstevel@tonic-gate	lockvar=$2
18148312e758Sdduvall
18157c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
18167c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
18177c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
18188312e758Sdduvall
18198312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
18208312e758Sdduvall		basews=`basename $CODEMGR_WS`
18218312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
18228312e758Sdduvall		if [ "$host" != "$hostname" ]; then
18238312e758Sdduvall			echo "$MACH build of $basews apparently" \
18248312e758Sdduvall			    "already started by $user on $host as $pid."
18258312e758Sdduvall			exit 1
18268312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
18278312e758Sdduvall			echo "$MACH build of $basews already started" \
18288312e758Sdduvall			    "by $user as $pid."
18298312e758Sdduvall			exit 1
18308312e758Sdduvall		else
18318312e758Sdduvall			# stale lock; clear it out and try again
18328312e758Sdduvall			rm -f $lockf
18338312e758Sdduvall		fi
18348312e758Sdduvall	done
18357c478bd9Sstevel@tonic-gate}
18367c478bd9Sstevel@tonic-gate
18374e5b757fSkupfer#
18384e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
18394e5b757fSkupfer# options.
18404e5b757fSkupfer#
18414e5b757fSkupferallprotos() {
18424e5b757fSkupfer	roots="$ROOT"
18434e5b757fSkupfer	if [ $O_FLAG = y ]; then
18444e5b757fSkupfer		# OpenSolaris deliveries require separate proto areas.
18454e5b757fSkupfer		[ $D_FLAG = y ] && roots="$roots $ROOT-open"
18464e5b757fSkupfer		[ $F_FLAG = n ] && roots="$roots $ROOT-open-nd"
18474e5b757fSkupfer	fi
18484e5b757fSkupfer	if [[ $D_FLAG = y && $F_FLAG = n ]]; then
18494e5b757fSkupfer		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd"
18504e5b757fSkupfer	fi
18514e5b757fSkupfer
18524e5b757fSkupfer	echo $roots
18534e5b757fSkupfer}
18544e5b757fSkupfer
18557c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
18567c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
18577c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
18587c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
18597c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
18607c478bd9Sstevel@tonic-gatefi
18617c478bd9Sstevel@tonic-gate#
18627c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
18637c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
18647c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
18657c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
18667c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
18677c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
18687c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
18697c478bd9Sstevel@tonic-gate#
18707c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
18717c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
18727c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
18737c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
18747c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
18757c478bd9Sstevel@tonic-gatefi
18767c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
18777c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
18787c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
18797c478bd9Sstevel@tonic-gatefi
18807c478bd9Sstevel@tonic-gate
18817c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
18827c478bd9Sstevel@tonic-gate# the directories we may have created so far.
18837c478bd9Sstevel@tonic-gatenewdirlist=
18847c478bd9Sstevel@tonic-gate
18857c478bd9Sstevel@tonic-gate#
18867c478bd9Sstevel@tonic-gate# Create mail_msg_file
18877c478bd9Sstevel@tonic-gate#
18887c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
18897c478bd9Sstevel@tonic-gatetouch $mail_msg_file
18907c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
1891cdf0c1d5Smjnelsonbuild_environ_file="${TMPDIR}/build_environ"
1892cdf0c1d5Smjnelsontouch $build_environ_file
18937c478bd9Sstevel@tonic-gate#
18947c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
18957c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
18967c478bd9Sstevel@tonic-gate#
18977c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
18987c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
18997c478bd9Sstevel@tonic-gatefi
19007c478bd9Sstevel@tonic-gate#
19017c478bd9Sstevel@tonic-gate#	Build OsNet source
19027c478bd9Sstevel@tonic-gate#
19037c478bd9Sstevel@tonic-gateSTART_DATE=`date`
19047c478bd9Sstevel@tonic-gateSECONDS=0
19057c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
19067c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
19077c478bd9Sstevel@tonic-gate
1908cdf0c1d5Smjnelsonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1909cdf0c1d5Smjnelson    tee -a $mail_msg_file >> $LOGFILE
1910cdf0c1d5Smjnelson
19117c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
19127c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
19137c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
19147c478bd9Sstevel@tonic-gate
191547703246Ssommerferun_hook SYS_PRE_NIGHTLY
191647703246Ssommerferun_hook PRE_NIGHTLY
191747703246Ssommerfe
19187c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
19197c478bd9Sstevel@tonic-gateenv >> $LOGFILE
19207c478bd9Sstevel@tonic-gate
19217c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
19227c478bd9Sstevel@tonic-gate
1923d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
1924d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1925d77e7149Ssommerfefi
1926d77e7149Ssommerfe
1927d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
1928d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1929d77e7149Ssommerfefi
1930d77e7149Ssommerfe
19311fe69678Skupferif is_source_build; then
19327c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
19337c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
19347c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
19357c478bd9Sstevel@tonic-gate		i_FLAG=n
19367c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
19377c478bd9Sstevel@tonic-gate	fi
19387c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
19397c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
19407c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
19417c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
19427c478bd9Sstevel@tonic-gate		N_FLAG=y
19437c478bd9Sstevel@tonic-gate	fi
19447c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
19457c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
19467c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
19477c478bd9Sstevel@tonic-gate		l_FLAG=n
19487c478bd9Sstevel@tonic-gate	fi
19497c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
19507c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
19517c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
19527c478bd9Sstevel@tonic-gate		C_FLAG=n
19537c478bd9Sstevel@tonic-gate	fi
19547c478bd9Sstevel@tonic-gateelse
19557c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
19567c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
19577c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
19587c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
19597c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
19607c478bd9Sstevel@tonic-gateEOF
19617c478bd9Sstevel@tonic-gate		else
19627c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
19637c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
19647c478bd9Sstevel@tonic-gateEOF
19657c478bd9Sstevel@tonic-gate		fi
19667c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
19677c478bd9Sstevel@tonic-gate	fi
19687c478bd9Sstevel@tonic-gatefi
19697c478bd9Sstevel@tonic-gate
19704e5b757fSkupferif [ "$O_FLAG" = "y" -a "$a_FLAG" = "n" ]; then
19714e5b757fSkupfer	echo "WARNING: OpenSolaris deliveries (-O) require archives;" \
19724e5b757fSkupfer	    "enabling the -a flag." | tee -a $mail_msg_file >> $LOGFILE
19734e5b757fSkupfer	a_FLAG=y
19744e5b757fSkupferfi
19754e5b757fSkupfer
19767c478bd9Sstevel@tonic-gateif [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
19777c478bd9Sstevel@tonic-gate	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
19787c478bd9Sstevel@tonic-gate	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
19797c478bd9Sstevel@tonic-gatefi
19807c478bd9Sstevel@tonic-gate
19817c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
19824e5b757fSkupfer	#
19834e5b757fSkupfer	# In the past we just complained but went ahead with the lint
19844e5b757fSkupfer	# pass, even though the proto area was built non-debug.  It's
19854e5b757fSkupfer	# unlikely that non-debug headers will make a difference, but
19864e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
19874e5b757fSkupfer	# to specify a debug build.
19884e5b757fSkupfer	#
19894e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
19907c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
19914e5b757fSkupfer	l_FLAG=n
19927c478bd9Sstevel@tonic-gatefi
19937c478bd9Sstevel@tonic-gate
19947c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
19957c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
19967c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
19977c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
19987c478bd9Sstevel@tonic-gate		f_FLAG=n
19997c478bd9Sstevel@tonic-gate	fi
20007c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
20017c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
20027c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
20037c478bd9Sstevel@tonic-gate		f_FLAG=n
20047c478bd9Sstevel@tonic-gate	fi
20057c478bd9Sstevel@tonic-gatefi
20067c478bd9Sstevel@tonic-gate
200796ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
20084e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
200996ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
201096ccc8cbSesaxe	w_FLAG=n
201196ccc8cbSesaxefi
201296ccc8cbSesaxe
20137c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
20147c478bd9Sstevel@tonic-gate	#
20157c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
20167c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
20177c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
20187c478bd9Sstevel@tonic-gate	#
20197c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
20207c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
20217c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
20227c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
20237c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
20247c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
20257c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
20267c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
20277c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
20287c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
20297c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
20307c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
20317c478bd9Sstevel@tonic-gate	fi
20327c478bd9Sstevel@tonic-gatefi
20337c478bd9Sstevel@tonic-gate
20344e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
20354e5b757fSkupfer
20364e5b757fSkupfercase $MULTI_PROTO in
20374e5b757fSkupferyes|no)	;;
20384e5b757fSkupfer*)
20394e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
20404e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
20414e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
20424e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
20434e5b757fSkupfer	export MULTI_PROTO=no
20444e5b757fSkupfer	;;
20454e5b757fSkupferesac
20464e5b757fSkupfer
20477c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
20487c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
20497c478bd9Sstevel@tonic-gate
205096ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
205196ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
205296ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
205396ccc8cbSesaxe	rm -rf $ROOT.prev
205496ccc8cbSesaxe    fi
205596ccc8cbSesaxe    mv $ROOT $ROOT.prev
205696ccc8cbSesaxefi
205796ccc8cbSesaxe
20584e5b757fSkupfer# Same for non-DEBUG proto area
20594e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
20604e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
20614e5b757fSkupfer		rm -rf $ROOT-nd.prev
20624e5b757fSkupfer	fi
20634e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
20644e5b757fSkupferfi
20654e5b757fSkupfer
206630635de9SJohn.Zolnowsky@Sun.COM# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
206730635de9SJohn.Zolnowsky@Sun.COMfunction wstypes {
206830635de9SJohn.Zolnowsky@Sun.COM	typeset parent_type child_type junk
206930635de9SJohn.Zolnowsky@Sun.COM
207030635de9SJohn.Zolnowsky@Sun.COM	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
207130635de9SJohn.Zolnowsky@Sun.COM	    | read parent_type junk
207230635de9SJohn.Zolnowsky@Sun.COM	if [[ -z "$parent_type" || "$parent_type" == unknown ]]; then
207330635de9SJohn.Zolnowsky@Sun.COM		# Probe BRINGOVER_WS to determine its type
207430635de9SJohn.Zolnowsky@Sun.COM		if [[ $BRINGOVER_WS == svn*://* ]]; then
207530635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
207630635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == file://* ]] &&
207730635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "This is a Subversion repository" \
207830635de9SJohn.Zolnowsky@Sun.COM		    ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
207930635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
208030635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == ssh://* ]]; then
208130635de9SJohn.Zolnowsky@Sun.COM			parent_type="mercurial"
208230635de9SJohn.Zolnowsky@Sun.COM		elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
208330635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
208430635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == http://* ]] && \
208530635de9SJohn.Zolnowsky@Sun.COM		    http_get "$BRINGOVER_WS/?cmd=heads" | \
208630635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "application/mercurial" 2> /dev/null; then
208730635de9SJohn.Zolnowsky@Sun.COM			parent_type="mercurial"
208830635de9SJohn.Zolnowsky@Sun.COM		else
208930635de9SJohn.Zolnowsky@Sun.COM			parent_type="none"
209030635de9SJohn.Zolnowsky@Sun.COM		fi
209130635de9SJohn.Zolnowsky@Sun.COM	fi
209230635de9SJohn.Zolnowsky@Sun.COM
209330635de9SJohn.Zolnowsky@Sun.COM	# Probe CODEMGR_WS to determine its type
209430635de9SJohn.Zolnowsky@Sun.COM	if [[ -d $CODEMGR_WS ]]; then
209530635de9SJohn.Zolnowsky@Sun.COM		$WHICH_SCM | read child_type junk || exit 1
209630635de9SJohn.Zolnowsky@Sun.COM	fi
209730635de9SJohn.Zolnowsky@Sun.COM
209830635de9SJohn.Zolnowsky@Sun.COM	# fold both unsupported and unrecognized results into "none"
209930635de9SJohn.Zolnowsky@Sun.COM	case "$parent_type" in
210030635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
210130635de9SJohn.Zolnowsky@Sun.COM		;;
210230635de9SJohn.Zolnowsky@Sun.COM	*)	parent_type=none
210330635de9SJohn.Zolnowsky@Sun.COM		;;
210430635de9SJohn.Zolnowsky@Sun.COM	esac
210530635de9SJohn.Zolnowsky@Sun.COM	case "$child_type" in
210630635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
210730635de9SJohn.Zolnowsky@Sun.COM		;;
210830635de9SJohn.Zolnowsky@Sun.COM	*)	child_type=none
210930635de9SJohn.Zolnowsky@Sun.COM		;;
211030635de9SJohn.Zolnowsky@Sun.COM	esac
211130635de9SJohn.Zolnowsky@Sun.COM
211230635de9SJohn.Zolnowsky@Sun.COM	echo $child_type $parent_type
211330635de9SJohn.Zolnowsky@Sun.COM}
211430635de9SJohn.Zolnowsky@Sun.COM
211530635de9SJohn.Zolnowsky@Sun.COMwstypes | read SCM_TYPE PARENT_SCM_TYPE
211630635de9SJohn.Zolnowsky@Sun.COMexport SCM_TYPE PARENT_SCM_TYPE
211730635de9SJohn.Zolnowsky@Sun.COM
21187c478bd9Sstevel@tonic-gate#
21197c478bd9Sstevel@tonic-gate#	Decide whether to clobber
21207c478bd9Sstevel@tonic-gate#
21217c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
21227c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
21237c478bd9Sstevel@tonic-gate
21247c478bd9Sstevel@tonic-gate	cd $SRC
21257c478bd9Sstevel@tonic-gate	# remove old clobber file
21267c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
21277c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
21287c478bd9Sstevel@tonic-gate
21297c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
21307c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
2131cdf0c1d5Smjnelson	find . \( -name SCCS -o -name .hg -o -name .svn \
2132cdf0c1d5Smjnelson		-o -name 'interfaces.*' \) -prune \
21337c478bd9Sstevel@tonic-gate		-o -name '.make.*' -print | xargs rm -f
21347c478bd9Sstevel@tonic-gate
21357c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
21367c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
21377c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
21387c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
21397c478bd9Sstevel@tonic-gate		>> $mail_msg_file
21407c478bd9Sstevel@tonic-gate
21414e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
21427c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
21437c478bd9Sstevel@tonic-gate		cd ${TOOLS}
21447c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
21457c478bd9Sstevel@tonic-gate		$MAKE -ek clobber 2>&1 | \
21467c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
21477c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
21487c478bd9Sstevel@tonic-gate			>> $mail_msg_file
21497c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
21507c478bd9Sstevel@tonic-gate			>> $mail_msg_file
21517c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
21527c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
21537c478bd9Sstevel@tonic-gate	fi
215496ccc8cbSesaxe
21554e5b757fSkupfer	rm -rf `allprotos`
21567c478bd9Sstevel@tonic-gate
21577c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
21587c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
21597c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2160fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2161cdf0c1d5Smjnelson	# under source code control, so leave them alone.
21627c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
21637c478bd9Sstevel@tonic-gate	cd $SRC
2164cdf0c1d5Smjnelson	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
2165cdf0c1d5Smjnelson	    -o -name 'interfaces.*' \) -prune -o \
21667c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2167fb23a357Skupfer	       -name '*.o' \) -print | \
2168fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
21697c478bd9Sstevel@tonic-gateelse
21707c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
21717c478bd9Sstevel@tonic-gatefi
21727c478bd9Sstevel@tonic-gate
2173cdf0c1d5Smjnelsontype bringover_teamware > /dev/null 2>&1 || bringover_teamware() {
21747c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
21757c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
21767c478bd9Sstevel@tonic-gate	do
21777c478bd9Sstevel@tonic-gate		sleep 120
21787c478bd9Sstevel@tonic-gate	done
21797c478bd9Sstevel@tonic-gate
2180fd7cef36Ssuha	if [[ -z $BRINGOVER ]]; then
2181fd7cef36Ssuha		BRINGOVER=$TEAMWARE/bin/bringover
2182fd7cef36Ssuha	fi
218332f1e47bSsommerfe
2184cdf0c1d5Smjnelson	staffer $BRINGOVER -c "nightly update" -p $BRINGOVER_WS \
218532f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
218632f1e47bSsommerfe		touch $TMPDIR/bringover_failed
218732f1e47bSsommerfe
2188d77e7149Ssommerfe        staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2189d77e7149Ssommerfe	if [ -s $TMPDIR/bringovercheck.out ]; then
2190d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2191d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2192d77e7149Ssommerfe	fi
2193cdf0c1d5Smjnelson}
219432f1e47bSsommerfe
2195cdf0c1d5Smjnelsontype bringover_mercurial > /dev/null 2>&1 || bringover_mercurial() {
2196cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2197cdf0c1d5Smjnelson
2198cdf0c1d5Smjnelson	# If the repository doesn't exist yet, then we want to populate it.
2199cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.hg ]]; then
2200cdf0c1d5Smjnelson		staffer hg init $CODEMGR_WS
22018cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
22028cca05f6SMark J. Nelson		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
2203f457028bSMark J. Nelson		touch $TMPDIR/new_repository
2204cdf0c1d5Smjnelson	fi
22055c53ea7aSmjnelson
22065c53ea7aSmjnelson	#
22075c53ea7aSmjnelson	# If the user set CLOSED_BRINGOVER_WS and didn't set CLOSED_IS_PRESENT
22085c53ea7aSmjnelson	# to "no," then we'll want to initialise the closed repository
22095c53ea7aSmjnelson	#
22105c53ea7aSmjnelson	# We use $orig_closed_is_present instead of $CLOSED_IS_PRESENT,
22115c53ea7aSmjnelson	# because for newly-created source trees, the latter will be "no"
22125c53ea7aSmjnelson	# until after the bringover completes.
22135c53ea7aSmjnelson	#
22145c53ea7aSmjnelson	if [[ "$orig_closed_is_present" != "no" && \
22155c53ea7aSmjnelson	    -n "$CLOSED_BRINGOVER_WS" && \
22165c53ea7aSmjnelson	    ! -d $CODEMGR_WS/usr/closed/.hg ]]; then
22175c53ea7aSmjnelson		staffer mkdir -p $CODEMGR_WS/usr/closed
22185c53ea7aSmjnelson		staffer hg init $CODEMGR_WS/usr/closed
22198cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/usr/closed/.hg/hgrc
22208cca05f6SMark J. Nelson		staffer echo "default=$CLOSED_BRINGOVER_WS" >> $CODEMGR_WS/usr/closed/.hg/hgrc
2221f457028bSMark J. Nelson		touch $TMPDIR/new_closed
22225c53ea7aSmjnelson		export CLOSED_IS_PRESENT=yes
2223cdf0c1d5Smjnelson	fi
2224cdf0c1d5Smjnelson
2225cdf0c1d5Smjnelson	typeset -x HGMERGE="/bin/false"
2226cdf0c1d5Smjnelson
2227cdf0c1d5Smjnelson	#
22285c53ea7aSmjnelson	# If the user has changes, regardless of whether those changes are
22295c53ea7aSmjnelson	# committed, and regardless of whether those changes conflict, then
22305c53ea7aSmjnelson	# we'll attempt to merge them either implicitly (uncommitted) or
22315c53ea7aSmjnelson	# explicitly (committed).
2232cdf0c1d5Smjnelson	#
22335c53ea7aSmjnelson	# These are the messages we'll use to help clarify mercurial output
22345c53ea7aSmjnelson	# in those cases.
22355c53ea7aSmjnelson	#
22365c53ea7aSmjnelson	typeset mergefailmsg="\
22375c53ea7aSmjnelson***\n\
22385c53ea7aSmjnelson*** nightly was unable to automatically merge your changes.  You should\n\
22395c53ea7aSmjnelson*** redo the full merge manually, following the steps outlined by mercurial\n\
22405c53ea7aSmjnelson*** above, then restart nightly.\n\
22415c53ea7aSmjnelson***\n"
22425c53ea7aSmjnelson	typeset mergepassmsg="\
22435c53ea7aSmjnelson***\n\
22445c53ea7aSmjnelson*** nightly successfully merged your changes.  This means that your working\n\
22455c53ea7aSmjnelson*** directory has been updated, but those changes are not yet committed.\n\
22465c53ea7aSmjnelson*** After nightly completes, you should validate the results of the merge,\n\
22475c53ea7aSmjnelson*** then use hg commit manually.\n\
22485c53ea7aSmjnelson***\n"
22495c53ea7aSmjnelson
22505c53ea7aSmjnelson	#
22515c53ea7aSmjnelson	# For each repository in turn:
22525c53ea7aSmjnelson	#
22535c53ea7aSmjnelson	# 1. Do the pull.  If this fails, dump the output and bail out.
22545c53ea7aSmjnelson	#
22555c53ea7aSmjnelson	# 2. If the pull resulted in an extra head, do an explicit merge.
22565c53ea7aSmjnelson	#    If this fails, dump the output and bail out.
22575c53ea7aSmjnelson	#
22585c53ea7aSmjnelson	# Because we can't rely on Mercurial to exit with a failure code
22595c53ea7aSmjnelson	# when a merge fails (Mercurial issue #186), we must grep the
22605c53ea7aSmjnelson	# output of pull/merge to check for attempted and/or failed merges.
22615c53ea7aSmjnelson	#
22625c53ea7aSmjnelson	# 3. If a merge failed, set the message and fail the bringover.
22635c53ea7aSmjnelson	#
22645c53ea7aSmjnelson	# 4. Otherwise, if a merge succeeded, set the message
22655c53ea7aSmjnelson	#
22665c53ea7aSmjnelson	# 5. Dump the output, and any message from step 3 or 4.
22675c53ea7aSmjnelson	#
22685c53ea7aSmjnelson
2269f457028bSMark J. Nelson	typeset HG_SOURCE=$BRINGOVER_WS
2270f457028bSMark J. Nelson	if [ ! -f $TMPDIR/new_repository ]; then
2271f457028bSMark J. Nelson		HG_SOURCE=$TMPDIR/open_bundle.hg
2272f457028bSMark J. Nelson		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
2273f457028bSMark J. Nelson		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
2274f457028bSMark J. Nelson
2275f457028bSMark J. Nelson		#
2276f457028bSMark J. Nelson		# If there are no incoming changesets, then incoming will
2277f457028bSMark J. Nelson		# fail, and there will be no bundle file.  Reset the source,
2278f457028bSMark J. Nelson		# to allow the remaining logic to complete with no false
2279f457028bSMark J. Nelson		# negatives.  (Unlike incoming, pull will return success
2280f457028bSMark J. Nelson		# for the no-change case.)
2281f457028bSMark J. Nelson		#
2282f457028bSMark J. Nelson		if (( $? != 0 )); then
2283f457028bSMark J. Nelson			HG_SOURCE=$BRINGOVER_WS
2284f457028bSMark J. Nelson		fi
2285f457028bSMark J. Nelson	fi
2286f457028bSMark J. Nelson
2287f457028bSMark J. Nelson	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
22885c53ea7aSmjnelson	    > $TMPDIR/pull_open.out 2>&1
22895c53ea7aSmjnelson	if (( $? != 0 )); then
22905c53ea7aSmjnelson		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
22915c53ea7aSmjnelson		cat $TMPDIR/pull_open.out
22925c53ea7aSmjnelson		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
22935c53ea7aSmjnelson			printf "$mergefailmsg"
22945c53ea7aSmjnelson		fi
22955c53ea7aSmjnelson		touch $TMPDIR/bringover_failed
22965c53ea7aSmjnelson		return
22975c53ea7aSmjnelson	fi
22985c53ea7aSmjnelson
2299cdf0c1d5Smjnelson	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
23005c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS merge \
23015c53ea7aSmjnelson		    >> $TMPDIR/pull_open.out 2>&1
23025c53ea7aSmjnelson		if (( $? != 0 )); then
23035c53ea7aSmjnelson			printf "%s: merge failed as follows:\n\n" \
23045c53ea7aSmjnelson			    "$CODEMGR_WS"
23055c53ea7aSmjnelson			cat $TMPDIR/pull_open.out
23065c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_open.out \
23075c53ea7aSmjnelson			    > /dev/null 2>&1; then
23085c53ea7aSmjnelson				printf "$mergefailmsg"
23095c53ea7aSmjnelson			fi
2310cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
23115c53ea7aSmjnelson			return
2312cdf0c1d5Smjnelson		fi
2313cdf0c1d5Smjnelson	fi
23145c53ea7aSmjnelson
23155c53ea7aSmjnelson	printf "updated %s with the following results:\n" "$CODEMGR_WS"
23165c53ea7aSmjnelson	cat $TMPDIR/pull_open.out
23175c53ea7aSmjnelson	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
23185c53ea7aSmjnelson		printf "$mergepassmsg"
23195c53ea7aSmjnelson	fi
23205c53ea7aSmjnelson	printf "\n"
23215c53ea7aSmjnelson
23225c53ea7aSmjnelson	#
23235c53ea7aSmjnelson	# We only want to update usr/closed if it exists, and we haven't been
23245c53ea7aSmjnelson	# told not to via $CLOSED_IS_PRESENT, and we actually know where to
23255c53ea7aSmjnelson	# pull from ($CLOSED_BRINGOVER_WS).
23265c53ea7aSmjnelson	#
23275c53ea7aSmjnelson	if [[ $CLOSED_IS_PRESENT = yes && \
23285c53ea7aSmjnelson	    -d $CODEMGR_WS/usr/closed/.hg && \
23295c53ea7aSmjnelson	    -n $CLOSED_BRINGOVER_WS ]]; then
23305c53ea7aSmjnelson
2331f457028bSMark J. Nelson		HG_SOURCE=$CLOSED_BRINGOVER_WS
2332f457028bSMark J. Nelson		if [ ! -f $TMPDIR/new_closed ]; then
2333f457028bSMark J. Nelson			HG_SOURCE=$TMPDIR/closed_bundle.hg
2334f457028bSMark J. Nelson			staffer hg --cwd $CODEMGR_WS/usr/closed incoming \
2335f457028bSMark J. Nelson			    --bundle $HG_SOURCE -v $CLOSED_BRINGOVER_WS \
2336f457028bSMark J. Nelson			    > $TMPDIR/incoming_closed.out
2337f457028bSMark J. Nelson
2338f457028bSMark J. Nelson			#
2339f457028bSMark J. Nelson			# If there are no incoming changesets, then incoming will
2340f457028bSMark J. Nelson			# fail, and there will be no bundle file.  Reset the source,
2341f457028bSMark J. Nelson			# to allow the remaining logic to complete with no false
2342f457028bSMark J. Nelson			# negatives.  (Unlike incoming, pull will return success
2343f457028bSMark J. Nelson			# for the no-change case.)
2344f457028bSMark J. Nelson			#
2345f457028bSMark J. Nelson			if (( $? != 0 )); then
2346f457028bSMark J. Nelson				HG_SOURCE=$CLOSED_BRINGOVER_WS
2347f457028bSMark J. Nelson			fi
2348f457028bSMark J. Nelson		fi
2349f457028bSMark J. Nelson
23505c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS/usr/closed pull -u \
2351f457028bSMark J. Nelson			$HG_SOURCE > $TMPDIR/pull_closed.out 2>&1
23525c53ea7aSmjnelson		if (( $? != 0 )); then
23535c53ea7aSmjnelson			printf "closed pull failed as follows:\n\n"
23545c53ea7aSmjnelson			cat $TMPDIR/pull_closed.out
23555c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_closed.out \
23565c53ea7aSmjnelson			    > /dev/null 2>&1; then
23575c53ea7aSmjnelson				printf "$mergefailmsg"
23585c53ea7aSmjnelson			fi
23595c53ea7aSmjnelson			touch $TMPDIR/bringover_failed
23605c53ea7aSmjnelson			return
23615c53ea7aSmjnelson		fi
23625c53ea7aSmjnelson
2363cdf0c1d5Smjnelson		if grep "not updating" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
23645c53ea7aSmjnelson			staffer hg --cwd $CODEMGR_WS/usr/closed merge \
23655c53ea7aSmjnelson			    >> $TMPDIR/pull_closed.out 2>&1
23665c53ea7aSmjnelson			if (( $? != 0 )); then
23675c53ea7aSmjnelson				printf "closed merge failed as follows:\n\n"
23685c53ea7aSmjnelson				cat $TMPDIR/pull_closed.out
23695c53ea7aSmjnelson				if grep "^merging.*failed" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
23705c53ea7aSmjnelson					printf "$mergefailmsg"
23715c53ea7aSmjnelson				fi
2372cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
23735c53ea7aSmjnelson				return
23745c53ea7aSmjnelson			fi
23755c53ea7aSmjnelson		fi
23765c53ea7aSmjnelson
23775c53ea7aSmjnelson		printf "updated %s with the following results:\n" \
23785c53ea7aSmjnelson		    "$CODEMGR_WS/usr/closed"
23795c53ea7aSmjnelson		cat $TMPDIR/pull_closed.out
23805c53ea7aSmjnelson		if grep "^merging" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
23815c53ea7aSmjnelson			printf "$mergepassmsg"
2382cdf0c1d5Smjnelson		fi
2383cdf0c1d5Smjnelson	fi
2384f457028bSMark J. Nelson
2385f457028bSMark J. Nelson	#
2386f457028bSMark J. Nelson	# Per-changeset output is neither useful nor manageable for a
2387f457028bSMark J. Nelson	# newly-created repository.
2388f457028bSMark J. Nelson	#
2389f457028bSMark J. Nelson	if [ -f $TMPDIR/new_repository ]; then
2390f457028bSMark J. Nelson		return
2391f457028bSMark J. Nelson	fi
2392f457028bSMark J. Nelson
2393f457028bSMark J. Nelson	printf "\nadded the following changesets to open repository:\n"
2394f457028bSMark J. Nelson	cat $TMPDIR/incoming_open.out
2395f457028bSMark J. Nelson
2396f457028bSMark J. Nelson	#
2397f457028bSMark J. Nelson	# The closed repository could have been newly created, even though
2398f457028bSMark J. Nelson	# the open one previously existed...
2399f457028bSMark J. Nelson	#
2400f457028bSMark J. Nelson	if [ -f $TMPDIR/new_closed ]; then
2401f457028bSMark J. Nelson		return
2402f457028bSMark J. Nelson	fi
2403f457028bSMark J. Nelson
2404f457028bSMark J. Nelson	if [ -f $TMPDIR/incoming_closed.out ]; then
2405f457028bSMark J. Nelson		printf "\nadded the following changesets to closed repository:\n"
2406f457028bSMark J. Nelson		cat $TMPDIR/incoming_closed.out
2407f457028bSMark J. Nelson	fi
2408cdf0c1d5Smjnelson}
2409cdf0c1d5Smjnelson
2410cdf0c1d5Smjnelsontype bringover_subversion > /dev/null 2>&1 || bringover_subversion() {
2411cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2412cdf0c1d5Smjnelson
2413cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.svn ]]; then
2414cdf0c1d5Smjnelson		staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2415cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2416cdf0c1d5Smjnelson	else
2417cdf0c1d5Smjnelson		typeset root
2418cdf0c1d5Smjnelson		root=$(staffer svn info $CODEMGR_WS |
2419cdf0c1d5Smjnelson			nawk '/^Repository Root:/ {print $NF}')
2420cdf0c1d5Smjnelson		if [[ $root != $BRINGOVER_WS ]]; then
2421cdf0c1d5Smjnelson			# We fail here because there's no way to update
2422cdf0c1d5Smjnelson			# from a named repo.
2423cdf0c1d5Smjnelson			cat <<-EOF
2424cdf0c1d5Smjnelson			\$BRINGOVER_WS doesn't match repository root:
2425cdf0c1d5Smjnelson			  \$BRINGOVER_WS:  $BRINGOVER_WS
2426cdf0c1d5Smjnelson			  Repository root: $root
2427cdf0c1d5Smjnelson			EOF
2428cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2429cdf0c1d5Smjnelson		else
2430cdf0c1d5Smjnelson			# If a conflict happens, svn still exits 0.
2431cdf0c1d5Smjnelson			staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2432cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2433cdf0c1d5Smjnelson			if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2434cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2435cdf0c1d5Smjnelson			fi
2436cdf0c1d5Smjnelson		fi
2437cdf0c1d5Smjnelson	fi
2438cdf0c1d5Smjnelson}
2439cdf0c1d5Smjnelson
2440cdf0c1d5Smjnelsontype bringover_none > /dev/null 2>&1 || bringover_none() {
2441cdf0c1d5Smjnelson	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2442cdf0c1d5Smjnelson	touch $TMPDIR/bringover_failed
2443cdf0c1d5Smjnelson}
2444cdf0c1d5Smjnelson
2445cdf0c1d5Smjnelson# Parse the URL.
2446cdf0c1d5Smjnelson# The other way to deal with empty components is to echo a string that can
2447cdf0c1d5Smjnelson# be eval'ed by the caller to associate values (possibly empty) with
2448cdf0c1d5Smjnelson# variables.  In that case, passing in a printf string would let the caller
2449cdf0c1d5Smjnelson# choose the variable names.
2450cdf0c1d5Smjnelsonparse_url() {
2451cdf0c1d5Smjnelson	typeset url method host port path
2452cdf0c1d5Smjnelson
2453cdf0c1d5Smjnelson	url=$1
2454cdf0c1d5Smjnelson	method=${url%%://*}
2455cdf0c1d5Smjnelson	host=${url#$method://}
2456cdf0c1d5Smjnelson	path=${host#*/}
2457cdf0c1d5Smjnelson	host=${host%%/*}
2458cdf0c1d5Smjnelson	if [[ $host == *:* ]]; then
2459cdf0c1d5Smjnelson		port=${host#*:}
2460cdf0c1d5Smjnelson		host=${host%:*}
2461cdf0c1d5Smjnelson	fi
2462cdf0c1d5Smjnelson
2463cdf0c1d5Smjnelson	# method can never be empty.  host can only be empty if method is
2464cdf0c1d5Smjnelson	# file, and that implies it's localhost.  path can default to / if
2465cdf0c1d5Smjnelson	# it's otherwise empty, leaving port as the only component without
2466cdf0c1d5Smjnelson	# a default, so it has to go last.
2467cdf0c1d5Smjnelson	echo $method ${host:-localhost} ${path:-/} $port
2468cdf0c1d5Smjnelson}
2469cdf0c1d5Smjnelson
2470cdf0c1d5Smjnelsonhttp_get() {
2471cdf0c1d5Smjnelson	typeset url method host port path
2472cdf0c1d5Smjnelson
2473cdf0c1d5Smjnelson	url=$1
2474cdf0c1d5Smjnelson
2475cdf0c1d5Smjnelson	if [[ -n $http_proxy ]]; then
2476cdf0c1d5Smjnelson		parse_url $http_proxy | read method host path port
2477cdf0c1d5Smjnelson		echo "GET $url HTTP/1.0\r\n" |
2478cdf0c1d5Smjnelson			mconnect -p ${port:-8080} $host
2479cdf0c1d5Smjnelson	else
2480cdf0c1d5Smjnelson		parse_url $url | read method host path port
2481cdf0c1d5Smjnelson		echo "GET $path HTTP/1.0\r\n" |
2482cdf0c1d5Smjnelson			mconnect -p ${port:-80} $host
2483cdf0c1d5Smjnelson	fi
2484cdf0c1d5Smjnelson}
2485cdf0c1d5Smjnelson
2486cdf0c1d5Smjnelson#
2487cdf0c1d5Smjnelson#	Decide whether to bringover to the codemgr workspace
2488cdf0c1d5Smjnelson#
2489cdf0c1d5Smjnelsonif [ "$n_FLAG" = "n" ]; then
2490ca0ac982Smjnelson
2491ca0ac982Smjnelson	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2492ca0ac982Smjnelson		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2493ca0ac982Smjnelson		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2494ca0ac982Smjnelson		exit 1
2495ca0ac982Smjnelson	fi
2496ca0ac982Smjnelson
2497cdf0c1d5Smjnelson	run_hook PRE_BRINGOVER
2498cdf0c1d5Smjnelson
2499cdf0c1d5Smjnelson	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2500cdf0c1d5Smjnelson	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2501cdf0c1d5Smjnelson
2502ca0ac982Smjnelson	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2503cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
250432f1e47bSsommerfe
250532f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
250632f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
250732f1e47bSsommerfe		build_ok=n
250832f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
25097c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
25107c478bd9Sstevel@tonic-gate		exit 1
25117c478bd9Sstevel@tonic-gate	fi
2512085d331dSkupfer
2513ca0ac982Smjnelson	#
2514ca0ac982Smjnelson	# It's possible that we used the bringover above to create
2515ca0ac982Smjnelson	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2516ca0ac982Smjnelson	# but should now be the same as $BRINGOVER_WS.
2517ca0ac982Smjnelson	#
2518ca0ac982Smjnelson	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2519ca0ac982Smjnelson
252047703246Ssommerfe	run_hook POST_BRINGOVER
252147703246Ssommerfe
2522085d331dSkupfer	#
2523085d331dSkupfer	# Possible transition from pre-split workspace to split
2524085d331dSkupfer	# workspace.  See if the bringover changed anything.
2525085d331dSkupfer	#
2526085d331dSkupfer	CLOSED_IS_PRESENT="$orig_closed_is_present"
2527085d331dSkupfer	check_closed_tree
25287c478bd9Sstevel@tonic-gateelse
25297c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
25307c478bd9Sstevel@tonic-gatefi
25317c478bd9Sstevel@tonic-gate
2532cdf0c1d5Smjnelsonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2533cdf0c1d5Smjnelson
2534cdf0c1d5Smjnelson# System
2535cdf0c1d5Smjnelsonwhence uname | tee -a $build_environ_file >> $LOGFILE
2536cdf0c1d5Smjnelsonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2537cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2538cdf0c1d5Smjnelson
2539cdf0c1d5Smjnelson# nightly
2540cdf0c1d5Smjnelsonecho "$0 $@" | tee -a $build_environ_file >> $LOGFILE
2541cdf0c1d5Smjnelsonif [[ $nightly_path = "/opt/onbld/bin/nightly" ]] &&
2542cdf0c1d5Smjnelson    pkginfo SUNWonbld > /dev/null 2>&1 ; then
2543cdf0c1d5Smjnelson	pkginfo -l SUNWonbld | egrep "PKGINST:|VERSION:|PSTAMP:"
2544cdf0c1d5Smjnelsonelse
254530635de9SJohn.Zolnowsky@Sun.COM	echo "$nightly_ls"
2546cdf0c1d5Smjnelsonfi | tee -a $build_environ_file >> $LOGFILE
2547cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2548cdf0c1d5Smjnelson
2549cdf0c1d5Smjnelson# make
2550cdf0c1d5Smjnelsonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
2551cdf0c1d5Smjnelson$MAKE -v | tee -a $build_environ_file >> $LOGFILE
2552cdf0c1d5Smjnelsonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2553cdf0c1d5Smjnelson    tee -a $build_environ_file >> $LOGFILE
2554cdf0c1d5Smjnelson
2555cdf0c1d5Smjnelson#
2556cdf0c1d5Smjnelson# Report the compiler versions.
2557cdf0c1d5Smjnelson#
2558cdf0c1d5Smjnelson
2559cdf0c1d5Smjnelsonif [[ ! -f $SRC/Makefile ]]; then
2560cdf0c1d5Smjnelson	build_ok=n
2561cdf0c1d5Smjnelson	echo "\nUnable to find \"Makefile\" in $SRC." | \
2562cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2563cdf0c1d5Smjnelson	exit 1
2564cdf0c1d5Smjnelsonfi
2565cdf0c1d5Smjnelson
2566cdf0c1d5Smjnelson( cd $SRC
2567cdf0c1d5Smjnelson  for target in cc-version cc64-version java-version; do
2568cdf0c1d5Smjnelson	echo
2569cdf0c1d5Smjnelson	#
2570cdf0c1d5Smjnelson	# Put statefile somewhere we know we can write to rather than trip
2571cdf0c1d5Smjnelson	# over a read-only $srcroot.
2572cdf0c1d5Smjnelson	#
2573cdf0c1d5Smjnelson	rm -f $TMPDIR/make-state
2574cdf0c1d5Smjnelson	export SRC
2575cdf0c1d5Smjnelson	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2576cdf0c1d5Smjnelson		continue
2577cdf0c1d5Smjnelson	fi
2578cdf0c1d5Smjnelson	touch $TMPDIR/nocompiler
2579cdf0c1d5Smjnelson  done
2580cdf0c1d5Smjnelson  echo
2581cdf0c1d5Smjnelson) | tee -a $build_environ_file >> $LOGFILE
2582cdf0c1d5Smjnelson
2583cdf0c1d5Smjnelsonif [ -f $TMPDIR/nocompiler ]; then
2584cdf0c1d5Smjnelson	rm -f $TMPDIR/nocompiler
2585cdf0c1d5Smjnelson	build_ok=n
2586cdf0c1d5Smjnelson	echo "Aborting due to missing compiler." |
2587cdf0c1d5Smjnelson		tee -a $build_environ_file >> $LOGFILE
2588cdf0c1d5Smjnelson	exit 1
2589cdf0c1d5Smjnelsonfi
2590cdf0c1d5Smjnelson
2591cdf0c1d5Smjnelson# as
2592cdf0c1d5Smjnelsonwhence as | tee -a $build_environ_file >> $LOGFILE
2593cdf0c1d5Smjnelsonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2594cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2595cdf0c1d5Smjnelson
2596cdf0c1d5Smjnelson# Check that we're running a capable link-editor
2597cdf0c1d5Smjnelsonwhence ld | tee -a $build_environ_file >> $LOGFILE
2598cdf0c1d5SmjnelsonLDVER=`ld -V 2>&1`
2599cdf0c1d5Smjnelsonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
2600cdf0c1d5SmjnelsonLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
2601cdf0c1d5Smjnelsonif [ `expr $LDVER \< 422` -eq 1 ]; then
2602cdf0c1d5Smjnelson	echo "The link-editor needs to be at version 422 or higher to build" | \
2603cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2604cdf0c1d5Smjnelson	echo "the latest stuff.  Hope your build works." | \
2605cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2606cdf0c1d5Smjnelsonfi
2607cdf0c1d5Smjnelson
26087c478bd9Sstevel@tonic-gate#
26094e5b757fSkupfer# Build and use the workspace's tools if requested
26107c478bd9Sstevel@tonic-gate#
26114e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
26124e5b757fSkupfer	set_non_debug_build_flags
26137c478bd9Sstevel@tonic-gate
26147c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
26152e02daeeSRainer Orth	if [[ $? = 0 ]]; then
26162e02daeeSRainer Orth		tools_build_ok=n
26172e02daeeSRainer Orth	fi
26184e5b757fSkupfer
26192e02daeeSRainer Orth	if [[ $tools_build_ok = y ]]; then
26202e02daeeSRainer Orth		echo "\n==== Creating protolist tools file at `date` ====" \
26212e02daeeSRainer Orth			>> $LOGFILE
26222e02daeeSRainer Orth		protolist $TOOLS_PROTO > $ATLOG/proto_list_tools_${MACH}
26232e02daeeSRainer Orth		echo "==== protolist tools file created at `date` ====\n" \
26242e02daeeSRainer Orth			>> $LOGFILE
26252e02daeeSRainer Orth
26262e02daeeSRainer Orth		if [ "$N_FLAG" != "y" ]; then
26272e02daeeSRainer Orth			echo "\n==== Impact on tools packages ====\n" \
26282e02daeeSRainer Orth				>> $mail_msg_file
26292e02daeeSRainer Orth
26302e02daeeSRainer Orth			# Use the current tools exception list.
26312e02daeeSRainer Orth			exc=etc/exception_list_$MACH
26322e02daeeSRainer Orth			if [ -f $SRC/tools/$exc ]; then
26332e02daeeSRainer Orth				TOOLS_ELIST="-e $SRC/tools/$exc"
26342e02daeeSRainer Orth			fi
26352e02daeeSRainer Orth			# Compare the build's proto list with current package
26362e02daeeSRainer Orth			# definitions to audit the quality of package
26372e02daeeSRainer Orth			# definitions and makefile install targets.
26382e02daeeSRainer Orth			$PROTOCMPTERSE \
26392e02daeeSRainer Orth			    "Files missing from the proto area:" \
26402e02daeeSRainer Orth			    "Files missing from packages:" \
26412e02daeeSRainer Orth			    "Inconsistencies between pkgdefs and proto area:" \
26422e02daeeSRainer Orth			    ${TOOLS_ELIST} \
26432e02daeeSRainer Orth			    -d $SRC/tools \
26442e02daeeSRainer Orth			    $ATLOG/proto_list_tools_${MACH} \
26452e02daeeSRainer Orth			    >> $mail_msg_file
26462e02daeeSRainer Orth		fi
26472e02daeeSRainer Orth	fi
26482e02daeeSRainer Orth
26492e02daeeSRainer Orth	if [[ $tools_build_ok = y && "$t_FLAG" = y ]]; then
26504e5b757fSkupfer		use_tools $TOOLS_PROTO
26514e5b757fSkupfer		export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
26524e5b757fSkupfer	fi
26537c478bd9Sstevel@tonic-gatefi
26547c478bd9Sstevel@tonic-gate
26556fec3625Sdduvall#
26566fec3625Sdduvall# copy ihv proto area in addition to the build itself
26576fec3625Sdduvall#
26586fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
26596fec3625Sdduvall	copy_ihv_proto
26606fec3625Sdduvallfi
26616fec3625Sdduvall
26627c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
26637c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
26647c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
26657c478bd9Sstevel@tonic-gateelse
26664e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
26674e5b757fSkupfer	touch $SRC/.build.tstamp
26684e5b757fSkupfer
26697c478bd9Sstevel@tonic-gate	normal_build
26707c478bd9Sstevel@tonic-gatefi
26717c478bd9Sstevel@tonic-gate
26724e5b757fSkupfer#
26735d715dd7Skupfer# Generate the THIRDPARTYLICENSE files if needed.  This is done before
26745d715dd7Skupfer# findunref to help identify license files that need to be added to
26755d715dd7Skupfer# the list.
26765d715dd7Skupfer#
26775d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
26785d715dd7Skupfer	echo "\n==== Generating THIRDPARTYLICENSE files ====\n" | \
26795d715dd7Skupfer	    tee -a $mail_msg_file >> $LOGFILE
26805d715dd7Skupfer
26815d715dd7Skupfer	mktpl usr/src/tools/opensolaris/license-list >>$LOGFILE 2>&1
2682cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
26835d715dd7Skupfer		echo "Couldn't create THIRDPARTYLICENSE files" |
26845d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
26855d715dd7Skupfer	fi
26865d715dd7Skupferfi
26875d715dd7Skupfer
26885d715dd7Skupfer#
26895d715dd7Skupfer# If OpenSolaris deliverables were requested, do the open-only build
26905d715dd7Skupfer# now, so that it happens at roughly the same point as the source
26915d715dd7Skupfer# product builds.  This lets us take advantage of checks that come
26925d715dd7Skupfer# later (e.g., the core file check).
26934e5b757fSkupfer#
26944e5b757fSkupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
26954e5b757fSkupfer	#
26964e5b757fSkupfer	# Generate skeleton (minimal) closed binaries for open-only
26974e5b757fSkupfer	# build.  There's no need to distinguish debug from non-debug
26984e5b757fSkupfer	# binaries, but it simplifies file management to have separate
26994e5b757fSkupfer	# trees.
27004e5b757fSkupfer	#
27014e5b757fSkupfer
27024e5b757fSkupfer	echo "\n==== Generating skeleton closed binaries for" \
27034e5b757fSkupfer	    "open-only build ====\n" | \
27044e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
27054e5b757fSkupfer
27064e5b757fSkupfer	rm -rf $CODEMGR_WS/closed.skel
27074e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
27084e5b757fSkupfer		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
27094e5b757fSkupfer		    >>$LOGFILE 2>&1
2710cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
27114e5b757fSkupfer			echo "Couldn't create skeleton DEBUG closed binaries." |
27124e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
27134e5b757fSkupfer		fi
27144e5b757fSkupfer	fi
27154e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
27164e5b757fSkupfer		mkclosed $MACH $ROOT-nd $CODEMGR_WS/closed.skel/root_$MACH-nd \
27174e5b757fSkupfer		    >>$LOGFILE 2>&1
2718cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
27194e5b757fSkupfer			echo "Couldn't create skeleton non-DEBUG closed binaries." |
27204e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
27214e5b757fSkupfer		fi
27224e5b757fSkupfer	fi
27234e5b757fSkupfer
27244e5b757fSkupfer	ORIG_CLOSED_IS_PRESENT=$CLOSED_IS_PRESENT
27254e5b757fSkupfer	export CLOSED_IS_PRESENT=no
27264e5b757fSkupfer
27274e5b757fSkupfer	ORIG_ON_CLOSED_BINS="$ON_CLOSED_BINS"
27284e5b757fSkupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
27294e5b757fSkupfer
27304e5b757fSkupfer	normal_build -O
27314e5b757fSkupfer
27324e5b757fSkupfer	ON_CLOSED_BINS=$ORIG_ON_CLOSED_BINS
27334e5b757fSkupfer	CLOSED_IS_PRESENT=$ORIG_CLOSED_IS_PRESENT
27344e5b757fSkupferfi
27354e5b757fSkupfer
27367c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
27377c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
27387c478bd9Sstevel@tonic-gate
27397c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
27407c478bd9Sstevel@tonic-gate	save_binaries
27417c478bd9Sstevel@tonic-gatefi
27427c478bd9Sstevel@tonic-gate
27437c478bd9Sstevel@tonic-gate
27447c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
27457c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
2746cdf0c1d5Smjnelson
27477c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2748cdf0c1d5Smjnelson	if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2749cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
27507c478bd9Sstevel@tonic-gate	fi
27517c478bd9Sstevel@tonic-gate
2752cdf0c1d5Smjnelson	if [ $build_ok = y ]; then
2753cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2754cdf0c1d5Smjnelson	fi
2755cdf0c1d5Smjnelsonfi
2756cdf0c1d5Smjnelson
2757cdf0c1d5Smjnelsonif [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
27587c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
27597c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
27607c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
27617c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
27627c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
27637c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
27647c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
27657c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
27667c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
27677c478bd9Sstevel@tonic-gate	else
27687c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
27697c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
27707c478bd9Sstevel@tonic-gate	fi
27717c478bd9Sstevel@tonic-gate
27727c478bd9Sstevel@tonic-gatefi
27737c478bd9Sstevel@tonic-gate
2774cdf0c1d5Smjnelsonif [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
27751fe69678Skupfer	#
27761fe69678Skupfer	# Copy the open sources into their own tree, set up the closed
27774e5b757fSkupfer	# binaries, and set up the environment.  The build looks for
27784e5b757fSkupfer	# the closed binaries in a location that depends on whether
27794e5b757fSkupfer	# it's a DEBUG build, so we might need to make two copies.
27801fe69678Skupfer	#
2781cdf0c1d5Smjnelson	# If copy_source fails, it will have already generated an
2782cdf0c1d5Smjnelson	# error message and set build_ok=n, so we don't need to worry
2783cdf0c1d5Smjnelson	# about that here.
2784cdf0c1d5Smjnelson	#
27851fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2786cdf0c1d5Smjnelsonfi
2787cdf0c1d5Smjnelson
2788cdf0c1d5Smjnelsonif [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
27891fe69678Skupfer	SRC=$OPEN_SRCDIR/usr/src
27901fe69678Skupfer
27911fe69678Skupfer	# Try not to clobber any user-provided closed binaries.
27921fe69678Skupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
27934e5b757fSkupfer
27944e5b757fSkupfer	echo "\n==== Copying skeleton closed binaries to" \
27954e5b757fSkupfer	    "$ON_CLOSED_BINS ====\n" | \
27961fe69678Skupfer	    tee -a $mail_msg_file >> $LOGFILE
27974e5b757fSkupfer
27984e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
27994e5b757fSkupfer		mkclosed $MACH $ROOT $ON_CLOSED_BINS/root_$MACH >>$LOGFILE 2>&1
2800cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
28011fe69678Skupfer			build_ok=n
28024e5b757fSkupfer			echo "Couldn't create DEBUG closed binaries." |
28031fe69678Skupfer			    tee -a $mail_msg_file >> $LOGFILE
28041fe69678Skupfer		fi
28054e5b757fSkupfer	fi
28064e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
28074e5b757fSkupfer		root=$ROOT
28084e5b757fSkupfer		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
28094e5b757fSkupfer		mkclosed $MACH $root $ON_CLOSED_BINS/root_$MACH-nd \
28104e5b757fSkupfer		    >>$LOGFILE 2>&1
2811cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
28124e5b757fSkupfer			build_ok=n
28134e5b757fSkupfer			echo "Couldn't create non-DEBUG closed binaries." |
28144e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
28154e5b757fSkupfer		fi
28164e5b757fSkupfer	fi
28174e5b757fSkupfer
28184e5b757fSkupfer	export CLOSED_IS_PRESENT=no
28191fe69678Skupferfi
28201fe69678Skupfer
28211fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
28224e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
28234e5b757fSkupfer	rm -rf `allprotos`
28247c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
28254e5b757fSkupfer		set_non_debug_build_flags
2826b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
28271fe69678Skupfer		#
28281fe69678Skupfer		# SRC was set earlier to point to the source build
28291fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
28301fe69678Skupfer		#
28311fe69678Skupfer		TOOLS=${SRC}/tools
28321fe69678Skupfer		build_tools ${SRC}/tools/proto
2833b91d9e0fSdanmcd		TOOLS=$ORIG_TOOLS
28347c478bd9Sstevel@tonic-gate	fi
28357c478bd9Sstevel@tonic-gate
28367c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
28377c478bd9Sstevel@tonic-gate	normal_build
28387c478bd9Sstevel@tonic-gatefi
28397c478bd9Sstevel@tonic-gate
28401fe69678Skupferif [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
28411fe69678Skupfer	rm -rf $ON_CLOSED_BINS
28421fe69678Skupferfi
28431fe69678Skupfer
28444e5b757fSkupfer#
28454e5b757fSkupfer# There are several checks that need to look at the proto area, but
28464e5b757fSkupfer# they only need to look at one, and they don't care whether it's
28474e5b757fSkupfer# DEBUG or non-DEBUG.
28484e5b757fSkupfer#
28494e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
28504e5b757fSkupfer	checkroot=$ROOT-nd
28514e5b757fSkupferelse
28524e5b757fSkupfer	checkroot=$ROOT
28534e5b757fSkupferfi
28544e5b757fSkupfer
28557c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
28567c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
28577c478bd9Sstevel@tonic-gate		>> $LOGFILE
28584e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
28597c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
28607c478bd9Sstevel@tonic-gate		>> $LOGFILE
28617c478bd9Sstevel@tonic-gate
28627c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
28637c478bd9Sstevel@tonic-gate		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
28647c478bd9Sstevel@tonic-gate
28657c478bd9Sstevel@tonic-gate		# If there is a reference proto list, compare the build's proto
28667c478bd9Sstevel@tonic-gate		# list with the reference to see changes in proto areas.
28677c478bd9Sstevel@tonic-gate		# Use the current exception list.
28687c478bd9Sstevel@tonic-gate		exc=etc/exception_list_$MACH
28697c478bd9Sstevel@tonic-gate		if [ -f $SRC/pkgdefs/$exc ]; then
28707c478bd9Sstevel@tonic-gate			ELIST="-e $SRC/pkgdefs/$exc"
28717c478bd9Sstevel@tonic-gate		fi
28726fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
28736fec3625Sdduvall			ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
28746fec3625Sdduvall		fi
28757c478bd9Sstevel@tonic-gate
28767c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
2877b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
2878b4add148Sdduvall			# IHV proto list to the reference list if the reference
2879b4add148Sdduvall			# was built without -X.
2880b4add148Sdduvall			#
2881b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
2882b4add148Sdduvall			# IHV proto list to the build's proto list if the
2883b4add148Sdduvall			# reference was built with -X.
2884b4add148Sdduvall			#
2885b4add148Sdduvall			# Use the presence of the first file entry of the cached
2886b4add148Sdduvall			# IHV proto list in the reference list to determine
2887b4add148Sdduvall			# whether it was build with -X or not.
2888b4add148Sdduvall			IHV_REF_PROTO_LIST=$SRC/pkgdefs/etc/proto_list_ihv_$MACH
2889b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2890b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
2891b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
2892b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
2893b4add148Sdduvall					grep -w "$grepfor" \
2894b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2895b4add148Sdduvall					if [ ! "$?" = "0" ]; then
2896b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2897b4add148Sdduvall					fi
2898b4add148Sdduvall				else
2899b4add148Sdduvall					grep -w "$grepfor" \
2900b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2901b4add148Sdduvall					if [ "$?" = "0" ]; then
2902b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2903b4add148Sdduvall					fi
2904b4add148Sdduvall				fi
2905b4add148Sdduvall			fi
2906b4add148Sdduvall
29077c478bd9Sstevel@tonic-gate			$PROTOCMPTERSE \
29087c478bd9Sstevel@tonic-gate			  "Files in yesterday's proto area, but not today's:" \
29097c478bd9Sstevel@tonic-gate			  "Files in today's proto area, but not yesterday's:" \
29107c478bd9Sstevel@tonic-gate			  "Files that changed between yesterday and today:" \
29117c478bd9Sstevel@tonic-gate			  ${ELIST} \
29127c478bd9Sstevel@tonic-gate			  -d $REF_PROTO_LIST \
2913b4add148Sdduvall			  $REF_IHV_PROTO \
29147c478bd9Sstevel@tonic-gate			  $ATLOG/proto_list_${MACH} \
2915b4add148Sdduvall			  $IHV_PROTO_LIST \
29167c478bd9Sstevel@tonic-gate				>> $mail_msg_file
29177c478bd9Sstevel@tonic-gate		fi
29187c478bd9Sstevel@tonic-gate		# Compare the build's proto list with current package
29197c478bd9Sstevel@tonic-gate		# definitions to audit the quality of package definitions
29207c478bd9Sstevel@tonic-gate		# and makefile install targets. Use the current exception list.
2921fb23a357Skupfer		PKGDEFS_LIST=""
2922fb23a357Skupfer		for d in $abssrcdirs; do
2923fb23a357Skupfer			if [ -d $d/pkgdefs ]; then
2924fb23a357Skupfer				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2925fb23a357Skupfer			fi
2926fb23a357Skupfer		done
29276fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
29286fec3625Sdduvall			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
29296fec3625Sdduvall		fi
29307c478bd9Sstevel@tonic-gate
29317c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
29327c478bd9Sstevel@tonic-gate		    "Files missing from the proto area:" \
29337c478bd9Sstevel@tonic-gate		    "Files missing from packages:" \
29347c478bd9Sstevel@tonic-gate		    "Inconsistencies between pkgdefs and proto area:" \
29357c478bd9Sstevel@tonic-gate		    ${ELIST} \
29367c478bd9Sstevel@tonic-gate		    ${PKGDEFS_LIST} \
29377c478bd9Sstevel@tonic-gate		    $ATLOG/proto_list_${MACH} \
29387c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
29397c478bd9Sstevel@tonic-gate	fi
29407c478bd9Sstevel@tonic-gatefi
29417c478bd9Sstevel@tonic-gate
29427c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
29437c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
29447c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
29457c478bd9Sstevel@tonic-gatefi
29467c478bd9Sstevel@tonic-gate
29477c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
29487c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
29497c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
29507c478bd9Sstevel@tonic-gate# the variable now.
29517c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
29527c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
29537c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
29547c478bd9Sstevel@tonic-gate	# The rm -rf command below produces predictable errors if
29557c478bd9Sstevel@tonic-gate	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
29567c478bd9Sstevel@tonic-gate	# and that directory is accessed via NFS.  This is because
29577c478bd9Sstevel@tonic-gate	# deleted-but-still-open files don't actually disappear as
29587c478bd9Sstevel@tonic-gate	# expected, but rather turn into .nfsXXXX junk files, leaving
29597c478bd9Sstevel@tonic-gate	# the directory non-empty.  Since this is a not-unusual usage
29607c478bd9Sstevel@tonic-gate	# pattern, and we still want to catch other errors here, we
29617c478bd9Sstevel@tonic-gate	# take the unusal step of moving aside 'nightly' from that
29627c478bd9Sstevel@tonic-gate	# directory (if we're using it).
2963cdf0c1d5Smjnelson	mypath=${nightly_path##*/root_$MACH/}
2964cdf0c1d5Smjnelson	if [ "$mypath" = $nightly_path ]; then
2965cdf0c1d5Smjnelson		mypath=opt/onbld/bin/${nightly_path##*/}
29667c478bd9Sstevel@tonic-gate	fi
2967cdf0c1d5Smjnelson	if [ $nightly_path -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
2968cdf0c1d5Smjnelson		mv -f $nightly_path $PARENT_WS/proto/root_$MACH
29697c478bd9Sstevel@tonic-gate	fi
29707c478bd9Sstevel@tonic-gate	rm -rf $PARENT_WS/proto/root_$MACH/*
29717c478bd9Sstevel@tonic-gate	unset Ulockfile
29727c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
29734e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
29747c478bd9Sstevel@tonic-gate		cd $ROOT
29754e5b757fSkupfer		( tar cf - . |
29764e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
29777c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
29787c478bd9Sstevel@tonic-gate	fi
29794e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
29804e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
29814e5b757fSkupfer		cd $ROOT-nd
29824e5b757fSkupfer		( tar cf - . |
29834e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
29844e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
29854e5b757fSkupfer	fi
29864e5b757fSkupferfi
29877c478bd9Sstevel@tonic-gate
29887c478bd9Sstevel@tonic-gate#
29897c478bd9Sstevel@tonic-gate# do shared library interface verification
29907c478bd9Sstevel@tonic-gate#
29917c478bd9Sstevel@tonic-gate
29927c478bd9Sstevel@tonic-gateif [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
29937c478bd9Sstevel@tonic-gate	echo "\n==== Check versioning and ABI information ====\n"  | \
29947c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
29957c478bd9Sstevel@tonic-gate
29967c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.ref
29977c478bd9Sstevel@tonic-gate	if [ -d $SRC/interfaces.out ]; then
29987c478bd9Sstevel@tonic-gate		mv $SRC/interfaces.out $SRC/interfaces.ref
29997c478bd9Sstevel@tonic-gate	fi
30007c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.out
30017c478bd9Sstevel@tonic-gate	mkdir -p $SRC/interfaces.out
30027c478bd9Sstevel@tonic-gate
30037c478bd9Sstevel@tonic-gate	intf_check -V -m -o -b $SRC/tools/abi/etc \
30044e5b757fSkupfer		-d $SRC/interfaces.out $checkroot 2>&1 | sort \
30057c478bd9Sstevel@tonic-gate		> $SRC/interfaces.out/log
30067c478bd9Sstevel@tonic-gate
30077c478bd9Sstevel@tonic-gate	# report any ERROR found in log file
30087c478bd9Sstevel@tonic-gate	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
30097c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30107c478bd9Sstevel@tonic-gate
30117c478bd9Sstevel@tonic-gate	if [ ! -d $SRC/interfaces.ref ] ; then
30127c478bd9Sstevel@tonic-gate		mkdir -p $SRC/interfaces.ref
30137c478bd9Sstevel@tonic-gate		if [ -d  $SRC/interfaces.out ]; then
30147c478bd9Sstevel@tonic-gate			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
30157c478bd9Sstevel@tonic-gate		fi
30167c478bd9Sstevel@tonic-gate	fi
30177c478bd9Sstevel@tonic-gate
30187c478bd9Sstevel@tonic-gate	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
30197c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
30207c478bd9Sstevel@tonic-gate
30217c478bd9Sstevel@tonic-gate	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
30227c478bd9Sstevel@tonic-gate	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
30237c478bd9Sstevel@tonic-gate
30247c478bd9Sstevel@tonic-gate	# Report any differences in WARNING messages between last
30257c478bd9Sstevel@tonic-gate	# and current build.
30267c478bd9Sstevel@tonic-gate	if [ "$out_vers" = "$ref_vers" ]; then
30277c478bd9Sstevel@tonic-gate		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
30287c478bd9Sstevel@tonic-gate		    fgrep 'WARNING' | sed 's/WARNING: //' | \
30297c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
30307c478bd9Sstevel@tonic-gate	fi
30317c478bd9Sstevel@tonic-gatefi
30327c478bd9Sstevel@tonic-gate
30337c478bd9Sstevel@tonic-gateif [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
30347c478bd9Sstevel@tonic-gate	echo "\n==== Check ELF runtime attributes ====\n" | \
30357c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
30367c478bd9Sstevel@tonic-gate
30377c478bd9Sstevel@tonic-gate	LDDWRONG="wrong class"
30387c478bd9Sstevel@tonic-gate	CRLERROR="^crle:"
30397c478bd9Sstevel@tonic-gate	CRLECONF="^crle: configuration file:"
30407c478bd9Sstevel@tonic-gate
3041900dc3b3Sjmcp	RUNTIMEREF=$SRC/runtime-${MACH}.ref
3042900dc3b3Sjmcp	RUNTIMEOUT=$SRC/runtime-${MACH}.out
3043900dc3b3Sjmcp
3044900dc3b3Sjmcp	rm -f $RUNTIMEREF
3045900dc3b3Sjmcp	if [ -f $RUNTIMEOUT ]; then
3046bfed486aSAli Bahrami		egrep -v "$LDDWRONG|$CRLERROR|$CRLECONF" \
3047900dc3b3Sjmcp			$RUNTIMEOUT > $RUNTIMEREF
30487c478bd9Sstevel@tonic-gate	fi
30497c478bd9Sstevel@tonic-gate
30507c478bd9Sstevel@tonic-gate	# If we're doing a debug build the proto area will be left with
30517c478bd9Sstevel@tonic-gate	# debuggable objects, thus don't assert -s.
30527c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
30537c478bd9Sstevel@tonic-gate		rtime_sflag=""
30547c478bd9Sstevel@tonic-gate	else
30557c478bd9Sstevel@tonic-gate		rtime_sflag="-s"
30567c478bd9Sstevel@tonic-gate	fi
3057bfed486aSAli Bahrami	check_rtime -d $checkroot -i -m -v -o $rtime_sflag $checkroot 2>&1 | \
30584e5b757fSkupfer	    egrep -v ": unreferenced object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
30594e5b757fSkupfer	    egrep -v ": unused object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
3060900dc3b3Sjmcp	    sort > $RUNTIMEOUT
30617c478bd9Sstevel@tonic-gate
30627c478bd9Sstevel@tonic-gate	# Determine any processing errors that will affect the final output
30637c478bd9Sstevel@tonic-gate	# and display these first.
3064900dc3b3Sjmcp	grep -l "$LDDWRONG" $RUNTIMEOUT > /dev/null
3065cdf0c1d5Smjnelson	if (( $? == 0 )) ; then
30667c478bd9Sstevel@tonic-gate	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
30677c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30687c478bd9Sstevel@tonic-gate	    echo "to execute an object, thus it could not be checked fully." | \
30697c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30707c478bd9Sstevel@tonic-gate	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
30717c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30727c478bd9Sstevel@tonic-gate	    echo "or an i386 object was encountered on a sparc system?\n" | \
30737c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30747c478bd9Sstevel@tonic-gate	fi
3075900dc3b3Sjmcp	grep -l "$CRLECONF" $RUNTIMEOUT > /dev/null
3076cdf0c1d5Smjnelson	if (( $? == 0 )) ; then
30777c478bd9Sstevel@tonic-gate	    echo "WARNING: creation of an alternative dependency cache failed." | \
30787c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30797c478bd9Sstevel@tonic-gate	    echo "Dependencies will bind to the base system libraries.\n" | \
30807c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
3081900dc3b3Sjmcp	    grep "$CRLECONF" $RUNTIMEOUT | \
30827c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
3083900dc3b3Sjmcp	    grep "$CRLERROR" $RUNTIMEOUT | grep -v "$CRLECONF" | \
30847c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
30857c478bd9Sstevel@tonic-gate	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
30867c478bd9Sstevel@tonic-gate	fi
30877c478bd9Sstevel@tonic-gate
3088900dc3b3Sjmcp	egrep '<dependency no longer necessary>' $RUNTIMEOUT | \
30897c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
30907c478bd9Sstevel@tonic-gate
3091bfed486aSAli Bahrami	# NEEDED= and RPATH= are generated by the -i option
3092bfed486aSAli Bahrami	# VERDEF= and VERSION= are generated by the -v option.
3093bfed486aSAli Bahrami	# These lines are informational; report anything else that we
30947c478bd9Sstevel@tonic-gate	# haven't already.
3095bfed486aSAli Bahrami	egrep -v "NEEDED=|RPATH=|VERDEF=|VERSION=" $RUNTIMEOUT \
3096bfed486aSAli Bahrami		| egrep -v "$LDDWRONG|$CRLERROR|$CRLECONF" \
3097bfed486aSAli Bahrami		| tee -a $LOGFILE >> $mail_msg_file
30987c478bd9Sstevel@tonic-gate
30997c478bd9Sstevel@tonic-gate	# probably should compare against a 'known ok runpaths' list
3100900dc3b3Sjmcp	if [ ! -f $RUNTIMEREF ]; then
3101bfed486aSAli Bahrami		egrep -v "$LDDWRONG|$CRLERROR|$CRLECONF" \
3102900dc3b3Sjmcp			$RUNTIMEOUT >  $RUNTIMEREF
31037c478bd9Sstevel@tonic-gate	fi
31047c478bd9Sstevel@tonic-gate
31057c478bd9Sstevel@tonic-gate	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
31067c478bd9Sstevel@tonic-gate	    >> $mail_msg_file
31077c478bd9Sstevel@tonic-gate
3108bfed486aSAli Bahrami	egrep -v "$LDDWRONG|$CRLERROR|$CRLECONF" $RUNTIMEOUT | \
3109900dc3b3Sjmcp	    diff $RUNTIMEREF - >> $mail_msg_file
31107c478bd9Sstevel@tonic-gatefi
31117c478bd9Sstevel@tonic-gate
31127c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
31137c478bd9Sstevel@tonic-gate
31147c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
31157c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
31167c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
31177c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
31187c478bd9Sstevel@tonic-gate	fi
31197c478bd9Sstevel@tonic-gate	set $LINTDIRS
31207c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
31217c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
31227c478bd9Sstevel@tonic-gate	done
31237c478bd9Sstevel@tonic-gateelse
31247c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
31257c478bd9Sstevel@tonic-gatefi
31267c478bd9Sstevel@tonic-gate
31277c478bd9Sstevel@tonic-gate# "make check" begins
31287c478bd9Sstevel@tonic-gate
31297c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
31307c478bd9Sstevel@tonic-gate	# remove old check.out
31317c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
31327c478bd9Sstevel@tonic-gate
31337c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
31347c478bd9Sstevel@tonic-gate	cd $SRC
31357c478bd9Sstevel@tonic-gate	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
31367c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
31377c478bd9Sstevel@tonic-gate
31387c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
31397c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
31407c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
31417c478bd9Sstevel@tonic-gateelse
31427c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
31437c478bd9Sstevel@tonic-gatefi
31447c478bd9Sstevel@tonic-gate
31457c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
31467c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
31477c478bd9Sstevel@tonic-gate
3148fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
31497c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
31507c478bd9Sstevel@tonic-gate
31517c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
31527c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
31537c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
31547c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
31557c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
31567c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
31577c478bd9Sstevel@tonic-gate	fi
31587c478bd9Sstevel@tonic-gate
3159cdf0c1d5Smjnelson	#
3160cdf0c1d5Smjnelson	# For any SCM other than teamware, we want to disable the
3161cdf0c1d5Smjnelson	# managed-by-SCCS test in findunref
3162cdf0c1d5Smjnelson	#
3163cdf0c1d5Smjnelson	findunref_all=""
3164cdf0c1d5Smjnelson	if [ "$SCM_TYPE" != teamware ]; then
3165cdf0c1d5Smjnelson		findunref_all="-a"
3166cdf0c1d5Smjnelson	fi
3167cdf0c1d5Smjnelson
3168cdf0c1d5Smjnelson	findunref $findunref_all -t $SRC/.build.tstamp $SRC/.. \
3169cdf0c1d5Smjnelson	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
3170cdf0c1d5Smjnelson	    sort | sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
3171fb23a357Skupfer	    > $SRC/unref-${MACH}.out
31727c478bd9Sstevel@tonic-gate
31737c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
31747c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
31757c478bd9Sstevel@tonic-gate	fi
31767c478bd9Sstevel@tonic-gate
31777c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
31787c478bd9Sstevel@tonic-gatefi
31797c478bd9Sstevel@tonic-gate
31805d715dd7Skupfer#
31815d715dd7Skupfer# Generate the OpenSolaris deliverables if requested.  Some of these
31825d715dd7Skupfer# steps need to come after findunref and are commented below.
31835d715dd7Skupfer#
31845d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
31855d715dd7Skupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
31865d715dd7Skupfer	    tee -a $mail_msg_file >> $LOGFILE
31875d715dd7Skupfer
31885d715dd7Skupfer	cd $CODEMGR_WS
31895d715dd7Skupfer
31905d715dd7Skupfer	#
31915d715dd7Skupfer	# This step grovels through the pkgdefs proto* files, so it
31925d715dd7Skupfer	# must come after findunref.
31935d715dd7Skupfer	#
31945d715dd7Skupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
31955d715dd7Skupfer	closed_basename=on-closed-bins
31965d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
31975d715dd7Skupfer		bindrop "$ROOT" "$ROOT-open" "$closed_basename" \
31985d715dd7Skupfer		    >>"$LOGFILE" 2>&1
3199cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
32005d715dd7Skupfer			echo "Couldn't create DEBUG closed binaries." |
32015d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
32025d715dd7Skupfer		fi
32035d715dd7Skupfer	fi
32045d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
32055d715dd7Skupfer		bindrop -n "$ROOT-nd" "$ROOT-open-nd" "$closed_basename-nd" \
32065d715dd7Skupfer		    >>"$LOGFILE" 2>&1
3207cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
32085d715dd7Skupfer			echo "Couldn't create non-DEBUG closed binaries." |
32095d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
32105d715dd7Skupfer		fi
32115d715dd7Skupfer	fi
32125d715dd7Skupfer
32135d715dd7Skupfer	echo "Generating SUNWonbld tarball..." >> $LOGFILE
32145d715dd7Skupfer	PKGARCHIVE=$PKGARCHIVE_ORIG
32155d715dd7Skupfer	onblddrop >> $LOGFILE 2>&1
3216cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
32175d715dd7Skupfer		echo "Couldn't create SUNWonbld tarball." |
32185d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
32195d715dd7Skupfer	fi
32205d715dd7Skupfer
32215d715dd7Skupfer	echo "Generating README.opensolaris..." >> $LOGFILE
32225d715dd7Skupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
32235d715dd7Skupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
3224cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
32255d715dd7Skupfer		echo "Couldn't create README.opensolaris." |
32265d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
32275d715dd7Skupfer	fi
32285d715dd7Skupfer
32295d715dd7Skupfer	# This step walks the source tree, so it must come after
32305d715dd7Skupfer	# findunref.  It depends on README.opensolaris.
32315d715dd7Skupfer	echo "Generating source tarball..." >> $LOGFILE
32325d715dd7Skupfer	sdrop >>$LOGFILE 2>&1
3233cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
32345d715dd7Skupfer		echo "Couldn't create source tarball." |
32355d715dd7Skupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
32365d715dd7Skupfer	fi
32375d715dd7Skupfer
32385d715dd7Skupfer	# This step depends on the closed binaries tarballs.
32395d715dd7Skupfer	echo "Generating BFU tarball(s)..." >> $LOGFILE
32405d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
32415d715dd7Skupfer		makebfu_filt bfudrop "$ROOT-open" \
32425d715dd7Skupfer		    "$closed_basename.$MACH.tar.bz2" nightly-osol
3243cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
32445d715dd7Skupfer			echo "Couldn't create DEBUG archives tarball." |
32455d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
32465d715dd7Skupfer		fi
32475d715dd7Skupfer	fi
32485d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
32495d715dd7Skupfer		makebfu_filt bfudrop -n "$ROOT-open-nd" \
32505d715dd7Skupfer		    "$closed_basename-nd.$MACH.tar.bz2" nightly-osol-nd
3251cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
32525d715dd7Skupfer			echo "Couldn't create non-DEBUG archives tarball." |
32535d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
32545d715dd7Skupfer		fi
32555d715dd7Skupfer	fi
32565d715dd7Skupferfi
32575d715dd7Skupfer
32587c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
32597c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
32607c478bd9Sstevel@tonic-gate# then don't check the proto area.
32617c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
32627c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
32637c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
32647c478bd9Sstevel@tonic-gate		>>$mail_msg_file
32657c478bd9Sstevel@tonic-gate	arg=-b
32667c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
32674e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
32687c478bd9Sstevel@tonic-gatefi
32697c478bd9Sstevel@tonic-gate
32707c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
32717c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
32727c478bd9Sstevel@tonic-gate		>> $mail_msg_file
32737c478bd9Sstevel@tonic-gate	#
32747c478bd9Sstevel@tonic-gate	# Get pkginfo files from usr/src/pkgdefs
32757c478bd9Sstevel@tonic-gate	#
32767c478bd9Sstevel@tonic-gate	pmodes -qvdP \
3277fb9f9b97Skupfer	`for d in $abssrcdirs; do
3278fb9f9b97Skupfer		if [ -d "$d/pkgdefs" ]
32797c478bd9Sstevel@tonic-gate		then
3280fb9f9b97Skupfer			find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
32817c478bd9Sstevel@tonic-gate		fi
32827c478bd9Sstevel@tonic-gate	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
32837c478bd9Sstevel@tonic-gatefi
32847c478bd9Sstevel@tonic-gate
328596ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
32864e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
32874e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
32884e5b757fSkupfer	fi
328996ccc8cbSesaxe
32904e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
32914e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
329296ccc8cbSesaxe	fi
329396ccc8cbSesaxefi
329496ccc8cbSesaxe
32957c478bd9Sstevel@tonic-gateEND_DATE=`date`
32967c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
32977c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
32987c478bd9Sstevel@tonic-gate
32997c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
33007c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
33017c478bd9Sstevel@tonic-gate
33027c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
33037c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
33047c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
33057c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
33067c478bd9Sstevel@tonic-gate
33077c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
33087c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
33097c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
33107c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
33117c478bd9Sstevel@tonic-gate
33127c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
33137c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
33147c478bd9Sstevel@tonic-gate
33157c478bd9Sstevel@tonic-gate	#
33167c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
33177c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
33187c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
33197c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
33207c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
33217c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
33227c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
33237c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
33247c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
33257c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
33267c478bd9Sstevel@tonic-gate	# which was already on the parent.
33277c478bd9Sstevel@tonic-gate	#
33287c478bd9Sstevel@tonic-gate
33297c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
33307c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
33317c478bd9Sstevel@tonic-gate	shift
33327c478bd9Sstevel@tonic-gate
33337c478bd9Sstevel@tonic-gate	for unreffile; do
33347c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
33357c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
33367c478bd9Sstevel@tonic-gate	done
33377c478bd9Sstevel@tonic-gate
33387c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
33397c478bd9Sstevel@tonic-gatefi
33407c478bd9Sstevel@tonic-gate
33417c478bd9Sstevel@tonic-gate#
33427c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
33437c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
33447c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
33457c478bd9Sstevel@tonic-gate#
33467c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
33477c478bd9Sstevel@tonic-gate	exit 0
33487c478bd9Sstevel@tonic-gatefi
33497c478bd9Sstevel@tonic-gateexit 1
3350