xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision 477032463b6ad98ae85035185348e42f6092fe3a)
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#
246c3c9007Sstevel# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
307c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
317c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
347c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
37d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
38d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
437c478bd9Sstevel@tonic-gate#
447c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
457c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
487c478bd9Sstevel@tonic-gate#
497c478bd9Sstevel@tonic-gate# -A flag in NIGHTLY_OPTIONS checks ABI diffs in .so files
507c478bd9Sstevel@tonic-gate# This option requires a couple of scripts.
517c478bd9Sstevel@tonic-gate#
527c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
537c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
547c478bd9Sstevel@tonic-gate#
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate#
577c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
587c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
597c478bd9Sstevel@tonic-gate#
607c478bd9Sstevel@tonic-gateunset CDPATH
617c478bd9Sstevel@tonic-gate
624e5b757fSkupfer#
634e5b757fSkupfer# Print the tag string used to identify a build (e.g., "DEBUG
644e5b757fSkupfer# open-only")
654e5b757fSkupfer# usage: tagstring debug-part open-part
664e5b757fSkupfer#
674e5b757fSkupfertagstring() {
684e5b757fSkupfer	debug_part=$1
694e5b757fSkupfer	open_part=$2
704e5b757fSkupfer
714e5b757fSkupfer	if [ -n "$open_part" ]; then
724e5b757fSkupfer		echo "$debug_part $open_part"
734e5b757fSkupfer	else
744e5b757fSkupfer		echo "$debug_part"
754e5b757fSkupfer	fi
764e5b757fSkupfer}
774e5b757fSkupfer
784e5b757fSkupfer#
794e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
807c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
817c478bd9Sstevel@tonic-gate# non-DEBUG packages.
824e5b757fSkupfer#
834e5b757fSkupfer# usage: normal_build [-O]
8452a52aebSkupfer# -O	OpenSolaris delivery build.  Put the proto area and
8552a52aebSkupfer#	(eventually) packages in -open directories.  Use skeleton
8652a52aebSkupfer#	closed binaries.  Don't generate archives--that needs to be
8752a52aebSkupfer#	done later, after we've generated the closed binaries.  Also
8852a52aebSkupfer#	skip the package build (until 6414822 is fixed).
894e5b757fSkupfer#
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gatenormal_build() {
927c478bd9Sstevel@tonic-gate
9352a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
9452a52aebSkupfer	typeset orig_a_FLAG="$a_FLAG"
954e5b757fSkupfer
964e5b757fSkupfer	suffix=""
974e5b757fSkupfer	open_only=""
984e5b757fSkupfer	while getopts O FLAG $*; do
994e5b757fSkupfer		case $FLAG in
1004e5b757fSkupfer		O)
1014e5b757fSkupfer			suffix="-open"
1024e5b757fSkupfer			open_only="open-only"
1034e5b757fSkupfer			p_FLAG=n
10452a52aebSkupfer			a_FLAG=n
1054e5b757fSkupfer			;;
1064e5b757fSkupfer		esac
1074e5b757fSkupfer	done
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
1124e5b757fSkupfer		set_non_debug_build_flags
1134e5b757fSkupfer		mytag=`tagstring "non-DEBUG" "$open_only"`
11452a52aebSkupfer		build "$mytag" "$suffix-nd" "$MULTI_PROTO"
1154e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1164e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1177c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
1187c478bd9Sstevel@tonic-gate		fi
1197c478bd9Sstevel@tonic-gate	else
12052a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1217c478bd9Sstevel@tonic-gate	fi
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	# DEBUG build begins
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
1284e5b757fSkupfer		set_debug_build_flags
1294e5b757fSkupfer		mytag=`tagstring "DEBUG" "$open_only"`
13052a52aebSkupfer		build "$mytag" "$suffix" "$MULTI_PROTO"
1314e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1324e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1337c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
1347c478bd9Sstevel@tonic-gate		fi
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate	else
13752a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1387c478bd9Sstevel@tonic-gate	fi
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate	# DEBUG build ends
1414e5b757fSkupfer
14252a52aebSkupfer	p_FLAG="$orig_p_FLAG"
14352a52aebSkupfer	a_FLAG="$orig_a_FLAG"
1447c478bd9Sstevel@tonic-gate}
1457c478bd9Sstevel@tonic-gate
1461fe69678Skupfer#
147*47703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
148*47703246Ssommerfe#
149*47703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
150*47703246Ssommerfe# our logs and then run the command with ARGS
151*47703246Ssommerfe#
152*47703246Ssommerferun_hook() {
153*47703246Ssommerfe	HOOKNAME=$1
154*47703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
155*47703246Ssommerfe	shift
156*47703246Ssommerfe
157*47703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
158*47703246Ssommerfe	    	(
159*47703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
160*47703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
161*47703246Ssommerfe			if [ "$?" -ne 0 ]; then
162*47703246Ssommerfe			    	# Let exit status propagate up
163*47703246Ssommerfe			    	touch $TMPDIR/abort
164*47703246Ssommerfe			fi
165*47703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
166*47703246Ssommerfe
167*47703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
168*47703246Ssommerfe			build_ok=n
169*47703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
170*47703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
171*47703246Ssommerfe			exit 1
172*47703246Ssommerfe		fi
173*47703246Ssommerfe	fi
174*47703246Ssommerfe}
175*47703246Ssommerfe
176*47703246Ssommerfe#
1771fe69678Skupfer# usage: filelist DESTDIR PATTERN
1781fe69678Skupfer#
1797c478bd9Sstevel@tonic-gatefilelist() {
1807c478bd9Sstevel@tonic-gate	DEST=$1
1817c478bd9Sstevel@tonic-gate	PATTERN=$2
1827c478bd9Sstevel@tonic-gate	cd ${DEST}
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
1857c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
1867c478bd9Sstevel@tonic-gate		return;
1877c478bd9Sstevel@tonic-gate	fi
1881fe69678Skupfer	for i in `grep -v '^#' ${OBJFILES} | \
1897c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
1907c478bd9Sstevel@tonic-gate	do
1917c478bd9Sstevel@tonic-gate		# wildcard expansion
1927c478bd9Sstevel@tonic-gate		for j in $i
1937c478bd9Sstevel@tonic-gate		do
1947c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
1957c478bd9Sstevel@tonic-gate				echo $j
1967c478bd9Sstevel@tonic-gate			fi
1977c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
1987c478bd9Sstevel@tonic-gate				echo $j
1997c478bd9Sstevel@tonic-gate			fi
2007c478bd9Sstevel@tonic-gate		done
2017c478bd9Sstevel@tonic-gate	done | sort | uniq
2027c478bd9Sstevel@tonic-gate}
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
2057c478bd9Sstevel@tonic-gate# restoration
2067c478bd9Sstevel@tonic-gatesave_binaries() {
2077c478bd9Sstevel@tonic-gate	# save off list of binaries
2087c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
2097c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2107c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
2117c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
2127c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
2137c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
2147c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
2157c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
2167c478bd9Sstevel@tonic-gate}
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate# delete files
2191fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
2207c478bd9Sstevel@tonic-gatehybridize_files() {
2217c478bd9Sstevel@tonic-gate	DEST=$1
2227c478bd9Sstevel@tonic-gate	MAKETARG=$2
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
2257c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2267c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
2277c478bd9Sstevel@tonic-gate	do
2287c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2297c478bd9Sstevel@tonic-gate		rm -rf "${i}"
2307c478bd9Sstevel@tonic-gate	done
2317c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
2327c478bd9Sstevel@tonic-gate	do
2337c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2347c478bd9Sstevel@tonic-gate		rm -f ${i}+
2357c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
2367c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
2377c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
2387c478bd9Sstevel@tonic-gate	done
2397c478bd9Sstevel@tonic-gate}
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
2421fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
2437c478bd9Sstevel@tonic-gaterestore_binaries() {
2447c478bd9Sstevel@tonic-gate	DEST=$1
2457c478bd9Sstevel@tonic-gate	MAKETARG=$2
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
2487c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2497c478bd9Sstevel@tonic-gate	cd ${DEST}
2507c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
2517c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
2527c478bd9Sstevel@tonic-gate}
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate# rename files we save binaries of
2551fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
2567c478bd9Sstevel@tonic-gaterename_files() {
2577c478bd9Sstevel@tonic-gate	DEST=$1
2587c478bd9Sstevel@tonic-gate	MAKETARG=$2
2597c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
2607c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2617c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
2627c478bd9Sstevel@tonic-gate	do
2637c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
2647c478bd9Sstevel@tonic-gate		rm -f ${i}.export
2657c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
2667c478bd9Sstevel@tonic-gate	done
2677c478bd9Sstevel@tonic-gate}
2687c478bd9Sstevel@tonic-gate
2691fe69678Skupfer#
2701fe69678Skupfer# Copy some or all of the source tree.
2711fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
2721fe69678Skupfer#
2731fe69678Skupfercopy_source() {
2747c478bd9Sstevel@tonic-gate	WS=$1
2757c478bd9Sstevel@tonic-gate	DEST=$2
2761fe69678Skupfer	label=$3
2771fe69678Skupfer	srcroot=$4
2787c478bd9Sstevel@tonic-gate
2791fe69678Skupfer	echo "\n==== Creating ${DEST} source from ${WS} ($label) ====\n" | \
2807c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate	echo "cleaning out ${DEST}." >> $LOGFILE
2837c478bd9Sstevel@tonic-gate	rm -rf "${DEST}" >> $LOGFILE 2>&1
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate	mkdir -p ${DEST}
2867c478bd9Sstevel@tonic-gate	cd ${WS}
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate	echo "creating ${DEST}." >> $LOGFILE
2891fe69678Skupfer	find $srcroot -name 's\.*' -a -type f -print | \
2907c478bd9Sstevel@tonic-gate	    sed -e 's,SCCS\/s.,,' | \
2917c478bd9Sstevel@tonic-gate	    grep -v '/\.del-*' | \
2927c478bd9Sstevel@tonic-gate	    cpio -pd ${DEST} >>$LOGFILE 2>&1
2931fe69678Skupfer}
2947c478bd9Sstevel@tonic-gate
2951fe69678Skupfer#
2961fe69678Skupfer# function to create (but not build) the export/crypt source tree.
2971fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
2981fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
2991fe69678Skupfer# builds the tree.
3001fe69678Skupfer#
3011fe69678Skupferset_up_source_build() {
3021fe69678Skupfer	WS=$1
3031fe69678Skupfer	DEST=$2
3041fe69678Skupfer	MAKETARG=$3
3051fe69678Skupfer
3061fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
3077c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate	cd $SRC
3107c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
3117c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
3127c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
3137c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
3147c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
3157c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
3167c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
3177c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
3187c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
3217c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate	cd ${DEST}
3247c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
3257c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
3267c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
3277c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
3287c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
3297c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
3307c478bd9Sstevel@tonic-gate		do
3317c478bd9Sstevel@tonic-gate			# make sure the files exist
3327c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
3337c478bd9Sstevel@tonic-gate				continue
3347c478bd9Sstevel@tonic-gate			fi
3357c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
3367c478bd9Sstevel@tonic-gate				continue
3377c478bd9Sstevel@tonic-gate			fi
3387c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
3397c478bd9Sstevel@tonic-gate		done
3407c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
3417c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
3427c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
3437c478bd9Sstevel@tonic-gate	fi
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
3467c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
3477c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
3487c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
3497c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
3507c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
3517c478bd9Sstevel@tonic-gate		fi
3527c478bd9Sstevel@tonic-gate	fi
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate	# save the cleartext
3557c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
3567c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3577c478bd9Sstevel@tonic-gate	cd ${DEST}
3587c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
359fb23a357Skupfer	find usr -depth -print | \
3607c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
3617c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
3627c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
3637c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
3647c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
3657c478bd9Sstevel@tonic-gate	fi
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
3687c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
3697c478bd9Sstevel@tonic-gate	fi
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate}
3727c478bd9Sstevel@tonic-gate
3734e5b757fSkupfer# Return library search directive as function of given root.
3744e5b757fSkupfermyldlibs() {
3754e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
3764e5b757fSkupfer}
3777c478bd9Sstevel@tonic-gate
3784e5b757fSkupfer# Return header search directive as function of given root.
3794e5b757fSkupfermyheaders() {
3804e5b757fSkupfer	echo "-I$1/usr/include"
3814e5b757fSkupfer}
3824e5b757fSkupfer
3834e5b757fSkupfer#
38452a52aebSkupfer# Wrapper over commands that generate BFU archives.  The entire
38552a52aebSkupfer# command output gets written to LOGFILE, and any unexpected messages
38652a52aebSkupfer# are written to the mail message.  Returns with the status of the
38752a52aebSkupfer# original command.
38852a52aebSkupfer#
38952a52aebSkupfermakebfu_filt() {
39052a52aebSkupfer	typeset tmplog
39152a52aebSkupfer	typeset errors
39252a52aebSkupfer	typeset cmd
39352a52aebSkupfer	integer cmd_stat
39452a52aebSkupfer
39552a52aebSkupfer	cmd="$1"
39652a52aebSkupfer	shift
39752a52aebSkupfer	tmplog="$TMPDIR/$cmd.out"
39852a52aebSkupfer	errors="$TMPDIR/$cmd-errors"
39952a52aebSkupfer	$cmd $* > "$tmplog" 2>&1
40052a52aebSkupfer	cmd_stat=$?
40152a52aebSkupfer	cat "$tmplog" >> "$LOGFILE"
40252a52aebSkupfer	grep -v "^Creating .* archive:" "$tmplog" | grep -v "^Making" | \
40352a52aebSkupfer	    grep -v "^$" | sort -u > "$errors"
40452a52aebSkupfer	if [[ -s "$errors" ]]; then
40552a52aebSkupfer		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
40652a52aebSkupfer		    >> "$mail_msg_file"
40752a52aebSkupfer		cat "$errors" >> "$mail_msg_file"
40852a52aebSkupfer	fi
40952a52aebSkupfer	rm -f "$tmplog" "$errors"
41052a52aebSkupfer	return $cmd_stat
41152a52aebSkupfer}
41252a52aebSkupfer
41352a52aebSkupfer#
4144e5b757fSkupfer# Function to do the build, including cpio archive and package generation.
4154e5b757fSkupfer# usage: build LABEL SUFFIX MULTIPROTO
4164e5b757fSkupfer# - LABEL is used to tag build output.
4174e5b757fSkupfer# - SUFFIX is used to distinguish files (e.g., debug vs non-debug).
4184e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
4194e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
4204e5b757fSkupfer#
4217c478bd9Sstevel@tonic-gatebuild() {
4227c478bd9Sstevel@tonic-gate	LABEL=$1
4237c478bd9Sstevel@tonic-gate	SUFFIX=$2
4244e5b757fSkupfer	MULTIPROTO=$3
4257c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
4267c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
4277c478bd9Sstevel@tonic-gate	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
4287c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
429d8fd4470Sjg	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
430d8fd4470Sjg		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
431d8fd4470Sjg	fi
4327c478bd9Sstevel@tonic-gate
4334e5b757fSkupfer	ORIGROOT=$ROOT
4344e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
4354e5b757fSkupfer
4364e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
4374e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
4384e5b757fSkupfer
4397c478bd9Sstevel@tonic-gate	this_build_ok=y
4407c478bd9Sstevel@tonic-gate	#
4417c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
4427c478bd9Sstevel@tonic-gate	#
4437c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
4447c478bd9Sstevel@tonic-gate		>> $LOGFILE
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
4477c478bd9Sstevel@tonic-gate	cd $SRC
4487c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
4497c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
45032f1e47bSsommerfe
45132f1e47bSsommerfe	echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
45232f1e47bSsommerfe
45332f1e47bSsommerfe	egrep 'sccs(check|  get)' $SRC/${INSTALLOG}.out >> $mail_msg_file
45432f1e47bSsommerfe
4557c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
4567c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
4577c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
4587c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
4597c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
4607c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
4617c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
4627c478bd9Sstevel@tonic-gate		build_ok=n
4637c478bd9Sstevel@tonic-gate		this_build_ok=n
4647c478bd9Sstevel@tonic-gate	fi
4657c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
4667c478bd9Sstevel@tonic-gate		>> $mail_msg_file
4677c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
4687c478bd9Sstevel@tonic-gate		build_ok=n
4697c478bd9Sstevel@tonic-gate		this_build_ok=n
4707c478bd9Sstevel@tonic-gate	fi
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
4737c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
4747c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
4757c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
4767c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
4777c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
4787c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
4797c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
4807c478bd9Sstevel@tonic-gate			>> $mail_msg_file
4817c478bd9Sstevel@tonic-gate	fi
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
4847c478bd9Sstevel@tonic-gate		>> $LOGFILE
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
4877c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
4907c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
4917c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
4927c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
4937c478bd9Sstevel@tonic-gate		fi
4947c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
4957c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
4967c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
4977c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
4987c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
4997c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
5007c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
5017c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
5027c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
5037c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
5047c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
5057c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
5067c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
5077c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
5087c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
5097c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
5107c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
5117c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
5127c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
5137c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
5147c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
5157c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
5167c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
5177c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
5187c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
5197c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
5207c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
5217c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
5227c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
5237c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
5247c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
5257c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
5267c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
5277c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
5287c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
5297c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
5307c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
5317c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
5327c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
5337c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
5347c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
5357c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
5367c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
5377c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
5387c478bd9Sstevel@tonic-gate			| egrep -v '::' \
5397c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
540010b217aSwesolows			| egrep -v '^\+' \
54103eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
542c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
5437c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
5447c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
5457c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
5467c478bd9Sstevel@tonic-gate		fi
5477c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
5487c478bd9Sstevel@tonic-gate			>>$mail_msg_file
5497c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
5507c478bd9Sstevel@tonic-gate	fi
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate	#
55323259b79Srotondo	#	Re-sign selected binaries using signing server
55423259b79Srotondo	#	(gatekeeper builds only)
55523259b79Srotondo	#
5562210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
55723259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
55823259b79Srotondo		signing_file="${TMPDIR}/signing"
55923259b79Srotondo		rm -f ${signing_file}
56023259b79Srotondo		export CODESIGN_USER
56123259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
56223259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
56323259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
56423259b79Srotondo		    >> $LOGFILE
56523259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
56623259b79Srotondo		    >> $mail_msg_file
56723259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
5682210853dSjohnz		if [ $? = 0 ]; then
5692210853dSjohnz			build_ok=n
5702210853dSjohnz			this_build_ok=n
5712210853dSjohnz		fi
57223259b79Srotondo	fi
57323259b79Srotondo
57423259b79Srotondo	#
5757c478bd9Sstevel@tonic-gate	#	Create cpio archives for preintegration testing (PIT)
5767c478bd9Sstevel@tonic-gate	#
5777c478bd9Sstevel@tonic-gate	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
5787c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
5797c478bd9Sstevel@tonic-gate			>> $LOGFILE
58052a52aebSkupfer		makebfu_filt makebfu
5817c478bd9Sstevel@tonic-gate		# hack for test folks
5827c478bd9Sstevel@tonic-gate		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
5837c478bd9Sstevel@tonic-gate			X=/net/`uname -n`${CPIODIR}
5847c478bd9Sstevel@tonic-gate		else
5857c478bd9Sstevel@tonic-gate			X=${CPIODIR}
5867c478bd9Sstevel@tonic-gate		fi
5877c478bd9Sstevel@tonic-gate		echo "Archive_directory: ${X}" >${TMPDIR}/f
5889a6d9a08Sdm120769		cp ${TMPDIR}/f $(dirname $(dirname ${CPIODIR}))/.${MACH}_wgtrun
5897c478bd9Sstevel@tonic-gate		rm -f ${TMPDIR}/f
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate	else
5927c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL cpio archives ====\n" \
5937c478bd9Sstevel@tonic-gate			>> $LOGFILE
5947c478bd9Sstevel@tonic-gate	fi
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate	#
5977c478bd9Sstevel@tonic-gate	#	Building Packages
5987c478bd9Sstevel@tonic-gate	#
5997c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
6007c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL packages at `date` ====\n" \
6017c478bd9Sstevel@tonic-gate			>> $LOGFILE
6027c478bd9Sstevel@tonic-gate		rm -f $SRC/pkgdefs/${INSTALLOG}.out
6037c478bd9Sstevel@tonic-gate		echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
6047c478bd9Sstevel@tonic-gate		rm -rf $PKGARCHIVE
6057c478bd9Sstevel@tonic-gate		mkdir -p $PKGARCHIVE
606d8fd4470Sjg
607d8fd4470Sjg		#
608d8fd4470Sjg		# Optional build of sparc realmode on i386
609d8fd4470Sjg		#
610d8fd4470Sjg		if [ "$MACH" = "i386" ] && [ "${SPARC_RM_PKGARCHIVE}" ]; then
611d8fd4470Sjg			echo "Clearing out ${SPARC_RM_PKGARCHIVE} ..." \
612d8fd4470Sjg				>> $LOGFILE
613d8fd4470Sjg			rm -rf ${SPARC_RM_PKGARCHIVE}
614d8fd4470Sjg			mkdir -p ${SPARC_RM_PKGARCHIVE}
615d8fd4470Sjg		fi
616d8fd4470Sjg
6177c478bd9Sstevel@tonic-gate		cd $SRC/pkgdefs
6187c478bd9Sstevel@tonic-gate		$MAKE -e install 2>&1 | \
6197c478bd9Sstevel@tonic-gate			tee -a $SRC/pkgdefs/${INSTALLOG}.out >> $LOGFILE
6207c478bd9Sstevel@tonic-gate		echo "\n==== Package build errors ($LABEL) ====\n" \
6217c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6227c478bd9Sstevel@tonic-gate		egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/${INSTALLOG}.out | \
6237c478bd9Sstevel@tonic-gate			grep ':' | \
6247c478bd9Sstevel@tonic-gate			grep -v PSTAMP | \
6257c478bd9Sstevel@tonic-gate			egrep -v "Ignoring unknown host" \
6267c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6277c478bd9Sstevel@tonic-gate	else
6287c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
6297c478bd9Sstevel@tonic-gate	fi
6304e5b757fSkupfer
6314e5b757fSkupfer	ROOT=$ORIGROOT
6327c478bd9Sstevel@tonic-gate}
6337c478bd9Sstevel@tonic-gate
6341fe69678Skupfer# Usage: dolint /dir y|n
6357c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
6361fe69678Skupferdolint() {
6377c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
6381fe69678Skupfer		echo "dolint error: $1 is not a directory"
6397c478bd9Sstevel@tonic-gate		exit 1
6407c478bd9Sstevel@tonic-gate	fi
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
6431fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
6447c478bd9Sstevel@tonic-gate		exit 1
6457c478bd9Sstevel@tonic-gate	fi
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate	lintdir=$1
6487c478bd9Sstevel@tonic-gate	dodiff=$2
6497c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
6507c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
6517c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
6524e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
6534e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
6547c478bd9Sstevel@tonic-gate
6554e5b757fSkupfer	set_debug_build_flags
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate	#
6587c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
6597c478bd9Sstevel@tonic-gate	#
6607c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate	# remove old lint.out
6637c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
6647c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
6657c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
6667c478bd9Sstevel@tonic-gate	fi
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
6697c478bd9Sstevel@tonic-gate	cd $lintdir
6707c478bd9Sstevel@tonic-gate	#
6717c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
6727c478bd9Sstevel@tonic-gate	#
6737c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
6747c478bd9Sstevel@tonic-gate	    `find . -name SCCS -prune -o -type f -name '*.ln' -print `
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
6777c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
6787c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
6797c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
6807c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
6817c478bd9Sstevel@tonic-gate		>> $mail_msg_file
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
6847c478bd9Sstevel@tonic-gate
6857c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
6867c478bd9Sstevel@tonic-gate		>>$mail_msg_file
6877c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
6907c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
6917c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
6927c478bd9Sstevel@tonic-gate	fi
6937c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
6947c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
6957c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
6967c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
6977c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
6987c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
6997c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
7007c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
7017c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
7027c478bd9Sstevel@tonic-gate	fi
7037c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
7047c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
7057c478bd9Sstevel@tonic-gate			>>$mail_msg_file
7067c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
7077c478bd9Sstevel@tonic-gate		# above
7087c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
7097c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
7107c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
7117c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7127c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
7137c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7147c478bd9Sstevel@tonic-gate	fi
7157c478bd9Sstevel@tonic-gate}
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate# Install proto area from IHV build
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gatecopy_ihv_proto() {
7207c478bd9Sstevel@tonic-gate
7216fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
7227c478bd9Sstevel@tonic-gate		>> $LOGFILE
7237c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
7247c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
7257c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
7267c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
7277c478bd9Sstevel@tonic-gate		fi
7286fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
7297c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
7307c478bd9Sstevel@tonic-gate		tar -cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7317c478bd9Sstevel@tonic-gate	else
7327c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
7337c478bd9Sstevel@tonic-gate	fi
7344e5b757fSkupfer
7354e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
7364e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
7374e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
7384e5b757fSkupfer			mkdir -p $ROOT-nd
7394e5b757fSkupfer		fi
7404e5b757fSkupfer		# If there's a non-debug version of the IHV proto area,
7414e5b757fSkupfer		# copy it, but copy something if there's not.
7424e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
7434e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
7444e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
7454e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
7464e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
7474e5b757fSkupfer			cd $IA32_IHV_ROOT
7484e5b757fSkupfer		else
7494e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
7504e5b757fSkupfer			return
7514e5b757fSkupfer		fi
7524e5b757fSkupfer		tar -cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7534e5b757fSkupfer	fi
7547c478bd9Sstevel@tonic-gate}
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
7571fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
7587c478bd9Sstevel@tonic-gatecopy_ihv_pkgs() {
7597c478bd9Sstevel@tonic-gate	LABEL=$1
7607c478bd9Sstevel@tonic-gate	SUFFIX=$2
7617c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
7627c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
7637c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
7667c478bd9Sstevel@tonic-gate		>> $LOGFILE
7677c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
7687c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
7697c478bd9Sstevel@tonic-gate		tar -cf - * | \
7707c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7717c478bd9Sstevel@tonic-gate	else
7727c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
7737c478bd9Sstevel@tonic-gate	fi
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
7767c478bd9Sstevel@tonic-gate		>> $LOGFILE
7777c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
7787c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
7797c478bd9Sstevel@tonic-gate		tar -cf - * | \
7807c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7817c478bd9Sstevel@tonic-gate	else
7827c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
7837c478bd9Sstevel@tonic-gate	fi
7847c478bd9Sstevel@tonic-gate}
7857c478bd9Sstevel@tonic-gate
7864e5b757fSkupfer#
7874e5b757fSkupfer# Build and install the onbld tools.
7884e5b757fSkupfer#
7891fe69678Skupfer# usage: build_tools DESTROOT
7904e5b757fSkupfer#
7914e5b757fSkupfer# returns non-zero status if the build was successful.
7924e5b757fSkupfer#
7937c478bd9Sstevel@tonic-gatebuild_tools() {
7947c478bd9Sstevel@tonic-gate	DESTROOT=$1
7957c478bd9Sstevel@tonic-gate
7967c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
7997c478bd9Sstevel@tonic-gate		>> $LOGFILE
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
8027c478bd9Sstevel@tonic-gate	cd ${TOOLS}
8037c478bd9Sstevel@tonic-gate	/bin/time $MAKE ROOT=${DESTROOT} -e install 2>&1 | \
8047c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
8097c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
8107c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
8117c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
8124e5b757fSkupfer	return $?
8134e5b757fSkupfer}
8144e5b757fSkupfer
8154e5b757fSkupfer#
8164e5b757fSkupfer# Set up to use locally installed tools.
8174e5b757fSkupfer#
8184e5b757fSkupfer# usage: use_tools TOOLSROOT
8194e5b757fSkupfer#
8204e5b757fSkupferuse_tools() {
8214e5b757fSkupfer	TOOLSROOT=$1
8224e5b757fSkupfer
8234e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
8247c478bd9Sstevel@tonic-gate	export STABS
8254e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
8267c478bd9Sstevel@tonic-gate	export CTFSTABS
8274e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
8287c478bd9Sstevel@tonic-gate	export GENOFFSETS
8297c478bd9Sstevel@tonic-gate
8304e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
8317c478bd9Sstevel@tonic-gate	export CTFCONVERT
8324e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
8337c478bd9Sstevel@tonic-gate	export CTFMERGE
8347c478bd9Sstevel@tonic-gate
8354e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
8367c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
8374e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
8387c478bd9Sstevel@tonic-gate	export CTFFINDMOD
8397c478bd9Sstevel@tonic-gate
8407c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
8414e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
8427c478bd9Sstevel@tonic-gate	else
8434e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
8447c478bd9Sstevel@tonic-gate	fi
8457c478bd9Sstevel@tonic-gate	export ELFSIGN
8467c478bd9Sstevel@tonic-gate
8474e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
8484e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
8497c478bd9Sstevel@tonic-gate	export PATH
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
8527c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
8537c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
8547c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
8557c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
8567c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
8577c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
8587c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
8597c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
8607c478bd9Sstevel@tonic-gate}
8617c478bd9Sstevel@tonic-gate
8627c478bd9Sstevel@tonic-gatestaffer() {
8637c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
8647c478bd9Sstevel@tonic-gate		"$@"
8657c478bd9Sstevel@tonic-gate	else
8667c478bd9Sstevel@tonic-gate		arg="\"$1\""
8677c478bd9Sstevel@tonic-gate		shift
8687c478bd9Sstevel@tonic-gate		for i
8697c478bd9Sstevel@tonic-gate		do
8707c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
8717c478bd9Sstevel@tonic-gate		done
8727c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
8737c478bd9Sstevel@tonic-gate	fi
8747c478bd9Sstevel@tonic-gate}
8757c478bd9Sstevel@tonic-gate
876085d331dSkupfer#
877085d331dSkupfer# Verify that the closed tree is present if it needs to be.
878085d331dSkupfer# Sets CLOSED_IS_PRESENT for future use.
879085d331dSkupfer#
880085d331dSkupfercheck_closed_tree() {
881085d331dSkupfer	if [ -z "$CLOSED_IS_PRESENT" ]; then
882085d331dSkupfer		if [ -d $SRC/../closed ]; then
883085d331dSkupfer			CLOSED_IS_PRESENT="yes"
884085d331dSkupfer		else
885085d331dSkupfer			CLOSED_IS_PRESENT="no"
886085d331dSkupfer		fi
887085d331dSkupfer		export CLOSED_IS_PRESENT
888085d331dSkupfer	fi
889085d331dSkupfer	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
890085d331dSkupfer		#
891085d331dSkupfer		# If it's an old (pre-split) tree or an empty
892085d331dSkupfer		# workspace, don't complain.
893085d331dSkupfer		#
894085d331dSkupfer		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
895085d331dSkupfer			echo "If the closed sources are not present," \
896085d331dSkupfer			    "ON_CLOSED_BINS"
897085d331dSkupfer			echo "must point to the closed binaries tree."
898085d331dSkupfer			exit 1
899085d331dSkupfer		fi
900085d331dSkupfer	fi
901085d331dSkupfer}
9027c478bd9Sstevel@tonic-gate
903d77e7149Ssommerfeobsolete_build() {
904d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
905d77e7149Ssommerfe}
906d77e7149Ssommerfe
9074e5b757fSkupfer#
9084e5b757fSkupfer# wrapper over wsdiff.
9094e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
9104e5b757fSkupfer#
9114e5b757fSkupferdo_wsdiff() {
9124e5b757fSkupfer	label=$1
9134e5b757fSkupfer	oldproto=$2
9144e5b757fSkupfer	newproto=$3
9154e5b757fSkupfer
9164e5b757fSkupfer	echo "\n==== Objects that differ since last build ($label) ====\n" | \
9174e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
9184e5b757fSkupfer
9194e5b757fSkupfer	wsdiff="wsdiff"
9204e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
9214e5b757fSkupfer
9224e5b757fSkupfer	$wsdiff -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
9234e5b757fSkupfer		    tee -a $LOGFILE >> $mail_msg_file
9244e5b757fSkupfer}
9254e5b757fSkupfer
9264e5b757fSkupfer#
9274e5b757fSkupfer# Functions for setting build flags (debug/non-debug).  Keep them
9284e5b757fSkupfer# together.
9294e5b757fSkupfer#
9304e5b757fSkupfer
9314e5b757fSkupferset_non_debug_build_flags() {
9324e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
9334e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
9344e5b757fSkupfer	unset EXTRA_OPTIONS
9354e5b757fSkupfer	unset EXTRA_CFLAGS
9364e5b757fSkupfer}
9374e5b757fSkupfer
9384e5b757fSkupferset_debug_build_flags() {
9394e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
9404e5b757fSkupfer	unset RELEASE_BUILD
9414e5b757fSkupfer	unset EXTRA_OPTIONS
9424e5b757fSkupfer	unset EXTRA_CFLAGS
9434e5b757fSkupfer}
9444e5b757fSkupfer
945d77e7149Ssommerfe
9467c478bd9Sstevel@tonic-gateMACH=`uname -p`
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
9497c478bd9Sstevel@tonic-gate	OPTHOME=/opt
9507c478bd9Sstevel@tonic-gate	export OPTHOME
9517c478bd9Sstevel@tonic-gatefi
9527c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
9537c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
9547c478bd9Sstevel@tonic-gate	export TEAMWARE
9557c478bd9Sstevel@tonic-gatefi
9567c478bd9Sstevel@tonic-gate
9571fe69678SkupferUSAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H|O ] <env_file>
9587c478bd9Sstevel@tonic-gate
9597c478bd9Sstevel@tonic-gateWhere:
960d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
9617c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
9627c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
9637c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
9647c478bd9Sstevel@tonic-gate		E - build exportable source
9657c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
9667c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
9671fe69678Skupfer		O - build (only) open source
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
9707c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
9717c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
9727c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
9737c478bd9Sstevel@tonic-gate
9747c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
9757c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
9787c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
9797c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
9807c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
9817c478bd9Sstevel@tonic-gate	-G	gate keeper default group of options (-au)
9827c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
9837c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
9847c478bd9Sstevel@tonic-gate	-N	do not run protocmp
9854e5b757fSkupfer	-O	generate OpenSolaris deliverables
9867c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
9877c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
9887c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
98904a42e3eSszhou	-X	copy x86 IHV proto area
9907c478bd9Sstevel@tonic-gate	-a	create cpio archives
9917c478bd9Sstevel@tonic-gate	-f	find unreferenced files
9927c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
9937c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
9947c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
9957c478bd9Sstevel@tonic-gate	-n      do not do a bringover
9967c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
9977c478bd9Sstevel@tonic-gate	-p	create packages
9987c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
9997c478bd9Sstevel@tonic-gate	-t	build and use the tools in $SRC/tools
10007c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
10017c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
100296ccc8cbSesaxe	-w	report on differences between previous and current proto areas
10037c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
10047c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
10057c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
10067c478bd9Sstevel@tonic-gate		E - build exportable source
10077c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
10087c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
10091fe69678Skupfer		O - build (only) open source
10107c478bd9Sstevel@tonic-gate'
10117c478bd9Sstevel@tonic-gate#
10127c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
10137c478bd9Sstevel@tonic-gate#
10147c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
10151c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
10167c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
10177c478bd9Sstevel@tonic-gate#
10187c478bd9Sstevel@tonic-gate
10197c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
10207c478bd9Sstevel@tonic-gateA_FLAG=n
10217c478bd9Sstevel@tonic-gatea_FLAG=n
10227c478bd9Sstevel@tonic-gateC_FLAG=n
10236c3c9007SstevelD_FLAG=n
10247c478bd9Sstevel@tonic-gateF_FLAG=n
10257c478bd9Sstevel@tonic-gatef_FLAG=n
10267c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
10277c478bd9Sstevel@tonic-gatel_FLAG=n
10286c3c9007SstevelM_FLAG=n
10297c478bd9Sstevel@tonic-gatem_FLAG=n
10306c3c9007SstevelN_FLAG=n
10316c3c9007Ssteveln_FLAG=n
10324e5b757fSkupferO_FLAG=n
10336c3c9007Sstevelo_FLAG=n
10346c3c9007SstevelP_FLAG=n
10357c478bd9Sstevel@tonic-gatep_FLAG=n
10367c478bd9Sstevel@tonic-gater_FLAG=n
10376c3c9007SstevelT_FLAG=n
10387c478bd9Sstevel@tonic-gatet_FLAG=n
10397c478bd9Sstevel@tonic-gateU_FLAG=n
10406c3c9007Sstevelu_FLAG=n
10417c478bd9Sstevel@tonic-gateV_FLAG=n
10427c478bd9Sstevel@tonic-gateW_FLAG=n
10436c3c9007Sstevelw_FLAG=n
10446c3c9007SstevelX_FLAG=n
10456c3c9007Sstevelz_FLAG=n
10467c478bd9Sstevel@tonic-gateSD_FLAG=n
10476c3c9007SstevelSE_FLAG=n
10487c478bd9Sstevel@tonic-gateSH_FLAG=n
10491fe69678SkupferSO_FLAG=n
10507c478bd9Sstevel@tonic-gate#
10517c478bd9Sstevel@tonic-gateXMOD_OPT=
10527c478bd9Sstevel@tonic-gate#
10537c478bd9Sstevel@tonic-gatebuild_ok=y
10541fe69678Skupfer
10551fe69678Skupferis_source_build() {
10561fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
10571fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
10581fe69678Skupfer	return $?
10591fe69678Skupfer}
10601fe69678Skupfer
10617c478bd9Sstevel@tonic-gate#
10627c478bd9Sstevel@tonic-gate# examine arguments
10637c478bd9Sstevel@tonic-gate#
10647c478bd9Sstevel@tonic-gate
10651fe69678Skupfer#
10661fe69678Skupfer# single function for setting -S flag and doing error checking.
10671fe69678Skupfer# usage: set_S_flag <type>
10681fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
10691fe69678Skupfer#
10701fe69678Skupferset_S_flag() {
10711fe69678Skupfer	if is_source_build; then
10721fe69678Skupfer		echo "Can only build one source variant at a time."
10731fe69678Skupfer		exit 1
10741fe69678Skupfer	fi
10751fe69678Skupfer	if [ "$1" = "E" ]; then
10761fe69678Skupfer		SE_FLAG=y
10771fe69678Skupfer	elif [ "$1" = "D" ]; then
10781fe69678Skupfer		SD_FLAG=y
10791fe69678Skupfer	elif [ "$1" = "H" ]; then
10801fe69678Skupfer		SH_FLAG=y
10811fe69678Skupfer	elif [ "$1" = "O" ]; then
10821fe69678Skupfer		SO_FLAG=y
10831fe69678Skupfer	else
10841fe69678Skupfer		echo "$USAGE"
10851fe69678Skupfer		exit 1
10861fe69678Skupfer	fi
10871fe69678Skupfer}
10881fe69678Skupfer
10897c478bd9Sstevel@tonic-gateOPTIND=1
10906c3c9007Sstevelwhile getopts inS:tV: FLAG
10917c478bd9Sstevel@tonic-gatedo
10927c478bd9Sstevel@tonic-gate	case $FLAG in
10937c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
10947c478bd9Sstevel@tonic-gate		;;
10957c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
10967c478bd9Sstevel@tonic-gate		;;
10977c478bd9Sstevel@tonic-gate	  S )
10981fe69678Skupfer		set_S_flag $OPTARG
10997c478bd9Sstevel@tonic-gate		;;
11007c478bd9Sstevel@tonic-gate	  t )	t_FLAG=y
11017c478bd9Sstevel@tonic-gate		;;
11026c3c9007Sstevel	  V )	V_FLAG=y
11036c3c9007Sstevel		V_ARG="$OPTARG"
11046c3c9007Sstevel		;;
11057c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
11067c478bd9Sstevel@tonic-gate		exit 1
11077c478bd9Sstevel@tonic-gate		;;
11087c478bd9Sstevel@tonic-gate	esac
11097c478bd9Sstevel@tonic-gatedone
11107c478bd9Sstevel@tonic-gate
11117c478bd9Sstevel@tonic-gate# correct argument count after options
11127c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
11137c478bd9Sstevel@tonic-gate
11147c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
11157c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
11167c478bd9Sstevel@tonic-gate	echo "$USAGE"
11177c478bd9Sstevel@tonic-gate	exit 1
11187c478bd9Sstevel@tonic-gatefi
11197c478bd9Sstevel@tonic-gate
11207c478bd9Sstevel@tonic-gate# check if user is running nightly as root
11217c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
11227c478bd9Sstevel@tonic-gate# when root invokes nightly.
11237c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
11247c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
11257c478bd9Sstevel@tonic-gate
11267c478bd9Sstevel@tonic-gate#
11277c478bd9Sstevel@tonic-gate# force locale to C
11287c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
11297c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
11307c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
11317c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
11327c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
11337c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
11347c478bd9Sstevel@tonic-gate
11357c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
11367c478bd9Sstevel@tonic-gateunset LD_OPTIONS
11377c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
11387c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
11397c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
11407c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
11417c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
11427c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
11437c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
11447c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
11457c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
11467c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
11477c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
11487c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
11497c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
11507c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
11517c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
11527c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
11537c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
11547c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
11557c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
11567c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
11577c478bd9Sstevel@tonic-gate
11587c478bd9Sstevel@tonic-gateunset CONFIG
11597c478bd9Sstevel@tonic-gateunset GROUP
11607c478bd9Sstevel@tonic-gateunset OWNER
11617c478bd9Sstevel@tonic-gateunset REMOTE
11627c478bd9Sstevel@tonic-gateunset ENV
11637c478bd9Sstevel@tonic-gateunset ARCH
11647c478bd9Sstevel@tonic-gateunset CLASSPATH
11657c478bd9Sstevel@tonic-gateunset NAME
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate#
11687c478bd9Sstevel@tonic-gate#	Setup environmental variables
11697c478bd9Sstevel@tonic-gate#
1170*47703246Ssommerfeif [ -f /etc/nightly.conf ]; then
1171*47703246Ssommerfe	. /etc/nightly.conf
1172*47703246Ssommerfefi
1173*47703246Ssommerfe
11747c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
11757c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
11767c478bd9Sstevel@tonic-gate		. $1
11777c478bd9Sstevel@tonic-gate	else
11787c478bd9Sstevel@tonic-gate		. ./$1
11797c478bd9Sstevel@tonic-gate	fi
11807c478bd9Sstevel@tonic-gateelse
11817c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
11827c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
11837c478bd9Sstevel@tonic-gate	else
11847c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
11857c478bd9Sstevel@tonic-gate		exit 1
11867c478bd9Sstevel@tonic-gate	fi
11877c478bd9Sstevel@tonic-gatefi
11887c478bd9Sstevel@tonic-gate
11891fe69678Skupfer# contents of stdenv.sh inserted after next line:
11901fe69678Skupfer# STDENV_START
11911fe69678Skupfer# STDENV_END
11921fe69678Skupfer
11937c478bd9Sstevel@tonic-gate#
11947c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
11957c478bd9Sstevel@tonic-gate#
11967c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
11977c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
11987c478bd9Sstevel@tonic-gateelse
11997c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
12007c478bd9Sstevel@tonic-gatefi
12017c478bd9Sstevel@tonic-gate
12027c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
12037c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
12047c478bd9Sstevel@tonic-gate
12057c478bd9Sstevel@tonic-gate#
12067c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
12077c478bd9Sstevel@tonic-gate#
12087c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
12097c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
12107c478bd9Sstevel@tonic-gatefi
12117c478bd9Sstevel@tonic-gate
12127c478bd9Sstevel@tonic-gate#
12137c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
12147c478bd9Sstevel@tonic-gate#
12157c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
12167c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
12177c478bd9Sstevel@tonic-gatefi
12187c478bd9Sstevel@tonic-gate
12197c478bd9Sstevel@tonic-gate#
1220fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1221a5c06a9eSmike_s#
1222a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1223fb23a357Skupfer	BRINGOVER_FILES="usr"
1224a5c06a9eSmike_sfi
1225a5c06a9eSmike_s
1226fb9f9b97Skupfer#
1227fb9f9b97Skupfer# If the closed sources are not present, the closed binaries must be
1228fb9f9b97Skupfer# present for the build to succeed.  If there's no pointer to the
1229fb9f9b97Skupfer# closed binaries, flag that now, rather than forcing the user to wait
1230fb9f9b97Skupfer# a couple hours (or more) to find out.
1231fb9f9b97Skupfer#
1232085d331dSkupferorig_closed_is_present="$CLOSED_IS_PRESENT"
1233085d331dSkupfercheck_closed_tree
1234fb9f9b97Skupfer
1235a5c06a9eSmike_s#
12367c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1237b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
12387c478bd9Sstevel@tonic-gate#
1239d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
12407c478bd9Sstevel@tonic-gateOPTIND=1
12414e5b757fSkupferwhile getopts AaBCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
12427c478bd9Sstevel@tonic-gatedo
12437c478bd9Sstevel@tonic-gate	case $FLAG in
12447c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
12457c478bd9Sstevel@tonic-gate		;;
12466c3c9007Sstevel	  a )	a_FLAG=y
12476c3c9007Sstevel		;;
12487c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
12497c478bd9Sstevel@tonic-gate		;; # old version of D
12506c3c9007Sstevel	  C )	C_FLAG=y
12517c478bd9Sstevel@tonic-gate		;;
12527c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
12537c478bd9Sstevel@tonic-gate		;;
12546c3c9007Sstevel	  F )	F_FLAG=y
12557c478bd9Sstevel@tonic-gate		;;
12566c3c9007Sstevel	  f )	f_FLAG=y
12577c478bd9Sstevel@tonic-gate		;;
12587c478bd9Sstevel@tonic-gate	  G )	a_FLAG=y
12597c478bd9Sstevel@tonic-gate		u_FLAG=y
12607c478bd9Sstevel@tonic-gate		;;
12617c478bd9Sstevel@tonic-gate	  I )	a_FLAG=y
12627c478bd9Sstevel@tonic-gate		m_FLAG=y
12637c478bd9Sstevel@tonic-gate		p_FLAG=y
12647c478bd9Sstevel@tonic-gate		u_FLAG=y
12657c478bd9Sstevel@tonic-gate		;;
12667c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
12677c478bd9Sstevel@tonic-gate		;;
12686c3c9007Sstevel	  l )	l_FLAG=y
12696c3c9007Sstevel		;;
12706c3c9007Sstevel	  M )	M_FLAG=y
12716c3c9007Sstevel		;;
12726c3c9007Sstevel	  m )	m_FLAG=y
12736c3c9007Sstevel		;;
12746c3c9007Sstevel	  N )	N_FLAG=y
12756c3c9007Sstevel		;;
12767c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
12777c478bd9Sstevel@tonic-gate		;;
12784e5b757fSkupfer	  O )	O_FLAG=y
12794e5b757fSkupfer		;;
12807c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
12817c478bd9Sstevel@tonic-gate		;;
12826c3c9007Sstevel	  P )	P_FLAG=y
12836c3c9007Sstevel		;; # obsolete
12847c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
12857c478bd9Sstevel@tonic-gate		;;
12866c3c9007Sstevel	  R )	m_FLAG=y
12876c3c9007Sstevel		p_FLAG=y
12886c3c9007Sstevel		;;
12897c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
12907c478bd9Sstevel@tonic-gate		;;
12916c3c9007Sstevel	  S )
12926c3c9007Sstevel		set_S_flag $OPTARG
12936c3c9007Sstevel		;;
12946c3c9007Sstevel	  T )	T_FLAG=y
12956c3c9007Sstevel		;; # obsolete
12967c478bd9Sstevel@tonic-gate	  t )	t_FLAG=y
12977c478bd9Sstevel@tonic-gate		;;
12987c478bd9Sstevel@tonic-gate	  U )
12997c478bd9Sstevel@tonic-gate		if [ -z "${PARENT_ROOT}" ]; then
13007c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
13017c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
13027c478bd9Sstevel@tonic-gate			exit 1
13037c478bd9Sstevel@tonic-gate		fi
13047c478bd9Sstevel@tonic-gate		U_FLAG=y
13057c478bd9Sstevel@tonic-gate		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
13067c478bd9Sstevel@tonic-gate		;;
13076c3c9007Sstevel	  u )	u_FLAG=y
13087c478bd9Sstevel@tonic-gate		;;
13097c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
13107c478bd9Sstevel@tonic-gate		;;
13116c3c9007Sstevel
13126c3c9007Sstevel	  w )	w_FLAG=y
13137c478bd9Sstevel@tonic-gate		;;
13147c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
13157c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
13167c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
13177c478bd9Sstevel@tonic-gate			X_FLAG=y
13187c478bd9Sstevel@tonic-gate		fi
13197c478bd9Sstevel@tonic-gate		;;
13206c3c9007Sstevel	  x )	XMOD_OPT="-x"
13216c3c9007Sstevel		;;
13226c3c9007Sstevel	  z )	z_FLAG=y
13236c3c9007Sstevel		;;
13247c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
13257c478bd9Sstevel@tonic-gate		exit 1
13267c478bd9Sstevel@tonic-gate		;;
13277c478bd9Sstevel@tonic-gate	esac
13287c478bd9Sstevel@tonic-gatedone
13297c478bd9Sstevel@tonic-gate
13307c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
13317c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
13327c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
13337c478bd9Sstevel@tonic-gate		exit 1
13347c478bd9Sstevel@tonic-gate	fi
13357c478bd9Sstevel@tonic-gate
13367c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
13377c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
13387c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
13397c478bd9Sstevel@tonic-gate		export STAFFER
13407c478bd9Sstevel@tonic-gate	fi
13417c478bd9Sstevel@tonic-gatefi
13427c478bd9Sstevel@tonic-gate
13437c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
13447c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
13457c478bd9Sstevel@tonic-gate	export MAILTO
13467c478bd9Sstevel@tonic-gatefi
13477c478bd9Sstevel@tonic-gate
13487c478bd9Sstevel@tonic-gatePATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
13497c478bd9Sstevel@tonic-gatePATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
13507c478bd9Sstevel@tonic-gatePATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
13517c478bd9Sstevel@tonic-gateexport PATH
13527c478bd9Sstevel@tonic-gate
1353fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1354fb23a357Skupferrelsrcdirs="."
1355fb9f9b97Skupferif [[ -d $SRC/../closed && "$CLOSED_IS_PRESENT" != no ]]; then
1356fb9f9b97Skupfer	relsrcdirs="$relsrcdirs ../closed"
1357fb9f9b97Skupferfi
1358fb23a357Skupferabssrcdirs=""
1359fb23a357Skupferfor d in $relsrcdirs; do
1360fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1361fb23a357Skupferdone
1362fb23a357Skupfer
13637c478bd9Sstevel@tonic-gateunset CH
13647c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
13657c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
13667c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
13677c478bd9Sstevel@tonic-gate# the old ones still do.
13687c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
13697c478bd9Sstevel@tonic-gate	CH=
13707c478bd9Sstevel@tonic-gate	export CH
13717c478bd9Sstevel@tonic-gateelse
13727c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
13737c478bd9Sstevel@tonic-gatefi
13747c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
13757c478bd9Sstevel@tonic-gate
13767c478bd9Sstevel@tonic-gate# we export POUND_SIGN to speed up the build process -- prevents evaluation of
13777c478bd9Sstevel@tonic-gate# the Makefile.master definitions.
13786fec3625Sdduvallexport o_FLAG X_FLAG POUND_SIGN
13797c478bd9Sstevel@tonic-gate
13807c478bd9Sstevel@tonic-gatemaketype="distributed"
13817c478bd9Sstevel@tonic-gateMAKE=dmake
13827c478bd9Sstevel@tonic-gate# get the dmake version string alone
13837c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
13847c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
13857c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
13867c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
13877c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
13887c478bd9Sstevel@tonic-gate# extract the second (or final) integer
13897c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
13907c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
13917c478bd9Sstevel@tonic-gate# extract the first integer
13927c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
13937c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
13947c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
13957c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
13967c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
13977c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
13987c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
13997c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
14007c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
14017c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
14027c478bd9Sstevel@tonic-gate		exit 1
14037c478bd9Sstevel@tonic-gate	fi
14047c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
14057c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
14067c478bd9Sstevel@tonic-gate	cat <<EOF
14077c478bd9Sstevel@tonic-gate
14087c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
14097c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
14107c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
14117c478bd9Sstevel@tonic-gate
14127c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
14137c478bd9Sstevel@tonic-gateEOF
14147c478bd9Sstevel@tonic-gate	exit 1
14157c478bd9Sstevel@tonic-gatefi
14167c478bd9Sstevel@tonic-gateexport PATH
14177c478bd9Sstevel@tonic-gateexport MAKE
14187c478bd9Sstevel@tonic-gate
14197c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
14207c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
14217c478bd9Sstevel@tonic-gate	export PATH
14227c478bd9Sstevel@tonic-gatefi
14237c478bd9Sstevel@tonic-gate
14247c478bd9Sstevel@tonic-gatehostname=`uname -n`
14257c478bd9Sstevel@tonic-gateif [ ! -f $HOME/.make.machines ]; then
14267c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS=4
14277c478bd9Sstevel@tonic-gateelse
14287c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
14297c478bd9Sstevel@tonic-gate	    tail -1 | awk -F= '{print $ 2;}'`"
14307c478bd9Sstevel@tonic-gate	if [ "$DMAKE_MAX_JOBS" = "" ]; then
14317c478bd9Sstevel@tonic-gate		DMAKE_MAX_JOBS=4
14327c478bd9Sstevel@tonic-gate	fi
14337c478bd9Sstevel@tonic-gatefi
14347c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
14357c478bd9Sstevel@tonic-gateexport DMAKE_MODE
14367c478bd9Sstevel@tonic-gateexport DMAKE_MAX_JOBS
14377c478bd9Sstevel@tonic-gate
14387c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
14397c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
14407c478bd9Sstevel@tonic-gate	exit 1
14417c478bd9Sstevel@tonic-gatefi
14427c478bd9Sstevel@tonic-gate
14437c478bd9Sstevel@tonic-gate#
14447c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
14457c478bd9Sstevel@tonic-gate#
14467c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
14477c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
14487c478bd9Sstevel@tonic-gatefi
14497c478bd9Sstevel@tonic-gate
145004a42e3eSszhou#
145104a42e3eSszhou# Check for IHV root for copying ihv proto area
145204a42e3eSszhou#
145304a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
145404a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
145504a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
145604a42e3eSszhou		args_ok=n
145704a42e3eSszhou        fi
145804a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
145904a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
146004a42e3eSszhou                args_ok=n
146104a42e3eSszhou        fi
14626fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
14636fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
14646fec3625Sdduvall		args_ok=n
14656fec3625Sdduvall        fi
14666fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
14676fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
14686fec3625Sdduvall                args_ok=n
14696fec3625Sdduvall        fi
147004a42e3eSszhoufi
147104a42e3eSszhou
14727c478bd9Sstevel@tonic-gate# Append source version
14737c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
14747c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
14757c478bd9Sstevel@tonic-gatefi
14767c478bd9Sstevel@tonic-gate
14777c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
14787c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
14797c478bd9Sstevel@tonic-gatefi
14807c478bd9Sstevel@tonic-gate
14817c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
14827c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
14837c478bd9Sstevel@tonic-gatefi
14847c478bd9Sstevel@tonic-gate
14851fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
14861fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
14871fe69678Skupferfi
14881fe69678Skupfer
14897c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
14907c478bd9Sstevel@tonic-gateexport TMPDIR
14917c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
14927c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
14937c478bd9Sstevel@tonic-gate
14947c478bd9Sstevel@tonic-gate#
14957c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
14967c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
14977c478bd9Sstevel@tonic-gate# have the fix for 6271754
14987c478bd9Sstevel@tonic-gate#
14997c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
15007c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
15017c478bd9Sstevel@tonic-gate
15027c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
15037c478bd9Sstevel@tonic-gateTOOLS_PROTO=${TOOLS}/proto
15047c478bd9Sstevel@tonic-gate
15057c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
15067c478bd9Sstevel@tonic-gate
15077c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
15087c478bd9Sstevel@tonic-gate# fails to start correctly
15097c478bd9Sstevel@tonic-gatenewdir() {
15107c478bd9Sstevel@tonic-gate	dir=$1
15117c478bd9Sstevel@tonic-gate	toadd=
15127c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
15137c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
15147c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
15157c478bd9Sstevel@tonic-gate	done
15167c478bd9Sstevel@tonic-gate	torm=
15177c478bd9Sstevel@tonic-gate	newlist=
15187c478bd9Sstevel@tonic-gate	for dir in $toadd; do
15197c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
15207c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
15217c478bd9Sstevel@tonic-gate			torm="$dir $torm"
15227c478bd9Sstevel@tonic-gate		else
15237c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
15247c478bd9Sstevel@tonic-gate			return 1
15257c478bd9Sstevel@tonic-gate		fi
15267c478bd9Sstevel@tonic-gate	done
15277c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
15287c478bd9Sstevel@tonic-gate	return 0
15297c478bd9Sstevel@tonic-gate}
15307c478bd9Sstevel@tonic-gatenewdirlist=
15317c478bd9Sstevel@tonic-gate
15327c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
15337c478bd9Sstevel@tonic-gate
15347c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
15357c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
15367c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
15377c478bd9Sstevel@tonic-gate# built from this immediate source.
15387c478bd9Sstevel@tonic-gateENVLDLIBS1=
15397c478bd9Sstevel@tonic-gateENVLDLIBS2=
15407c478bd9Sstevel@tonic-gateENVLDLIBS3=
15417c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
15427c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
15437c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
15447c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
15457c478bd9Sstevel@tonic-gatePARENT_ROOT=
15467c478bd9Sstevel@tonic-gate
15477c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
15487c478bd9Sstevel@tonic-gate	PARENT_ROOT
15497c478bd9Sstevel@tonic-gate
15507c478bd9Sstevel@tonic-gateCPIODIR_ORIG=$CPIODIR
15517c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
15527c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1553d8fd4470Sjgif [ "$SPARC_RM_PKGARCHIVE" ]; then
15547c478bd9Sstevel@tonic-gate	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1555d8fd4470Sjgfi
15567c478bd9Sstevel@tonic-gate
15577c478bd9Sstevel@tonic-gate#
15587c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
15597c478bd9Sstevel@tonic-gate#
15607c478bd9Sstevel@tonic-gate
15617c478bd9Sstevel@tonic-gatelogshuffle() {
15621c79753fSdarrenm    	LLOG="$ATLOG/log.`date '+%F'`"
15637c478bd9Sstevel@tonic-gate	rm -rf $ATLOG/log.??`date '+%d'`
15641c79753fSdarrenm	rm -rf $ATLOG/log.????-??-`date '+%d'`
15657c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
15667c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
15677c478bd9Sstevel@tonic-gate	fi
15687c478bd9Sstevel@tonic-gate	mkdir $LLOG
15694802ef38Srscott	export LLOG
15707c478bd9Sstevel@tonic-gate
15717c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
15727c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
157396ccc8cbSesaxe
157496ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
157596ccc8cbSesaxe		    mv $TMPDIR/wsdiff.results $LLOG
157696ccc8cbSesaxe		fi
15774e5b757fSkupfer
15784e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
15794e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
15804e5b757fSkupfer		fi
15817c478bd9Sstevel@tonic-gate	fi
15827c478bd9Sstevel@tonic-gate
15837c478bd9Sstevel@tonic-gate	#
15847c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
15857c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
15867c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
15877c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
15887c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
15897c478bd9Sstevel@tonic-gate	#
15907c478bd9Sstevel@tonic-gate
15917c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
15927c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
15937c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
15947c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
15957c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
15967c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
15977c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
15987c478bd9Sstevel@tonic-gate	fi
15997c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
16007c478bd9Sstevel@tonic-gate
16017c478bd9Sstevel@tonic-gate	case "$build_ok" in
16027c478bd9Sstevel@tonic-gate		y)
16037c478bd9Sstevel@tonic-gate			state=Completed
16047c478bd9Sstevel@tonic-gate			;;
16057c478bd9Sstevel@tonic-gate		i)
16067c478bd9Sstevel@tonic-gate			state=Interrupted
16077c478bd9Sstevel@tonic-gate			;;
16087c478bd9Sstevel@tonic-gate		*)
16097c478bd9Sstevel@tonic-gate	    		state=Failed
16107c478bd9Sstevel@tonic-gate			;;
16117c478bd9Sstevel@tonic-gate	esac
161240bc9153Srscott	NIGHTLY_STATUS=$state
161340bc9153Srscott	export NIGHTLY_STATUS
16147c478bd9Sstevel@tonic-gate
1615*47703246Ssommerfe	run_hook POST_NIGHTLY $state
1616*47703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
16174802ef38Srscott
16187c478bd9Sstevel@tonic-gate	cat $build_time_file $mail_msg_file > ${LLOG}/mail_msg
16197c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
16207c478bd9Sstevel@tonic-gate	    	cat $build_time_file $mail_msg_file |
16217c478bd9Sstevel@tonic-gate		    /usr/bin/mailx -s \
16227c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
16237c478bd9Sstevel@tonic-gate			${MAILTO}
16247c478bd9Sstevel@tonic-gate	fi
16257c478bd9Sstevel@tonic-gate
16267c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
16277c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
16287c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
16297c478bd9Sstevel@tonic-gate	fi
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
16327c478bd9Sstevel@tonic-gate}
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gate#
16357c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
16367c478bd9Sstevel@tonic-gate#
16377c478bd9Sstevel@tonic-gatecleanup() {
16387c478bd9Sstevel@tonic-gate    	logshuffle
16397c478bd9Sstevel@tonic-gate
16407c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
16417c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
16427c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
16437c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
16447c478bd9Sstevel@tonic-gate
16457c478bd9Sstevel@tonic-gate	set -- $newdirlist
16467c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
16477c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
16487c478bd9Sstevel@tonic-gate		shift; shift
16497c478bd9Sstevel@tonic-gate	done
16507c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
16517c478bd9Sstevel@tonic-gate}
16527c478bd9Sstevel@tonic-gate
16537c478bd9Sstevel@tonic-gatecleanup_signal() {
16547c478bd9Sstevel@tonic-gate    	build_ok=i
16557c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
16567c478bd9Sstevel@tonic-gate	exit 1
16577c478bd9Sstevel@tonic-gate}
16587c478bd9Sstevel@tonic-gate
16597c478bd9Sstevel@tonic-gatetrap cleanup 0
16607c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
16617c478bd9Sstevel@tonic-gate
16627c478bd9Sstevel@tonic-gate#
16637c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
16647c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
16657c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
16667c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
16677c478bd9Sstevel@tonic-gate# for the workspace).
16687c478bd9Sstevel@tonic-gatecreate_lock() {
16697c478bd9Sstevel@tonic-gate	lockf=$1
16707c478bd9Sstevel@tonic-gate	lockvar=$2
16718312e758Sdduvall
16727c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
16737c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
16747c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
16758312e758Sdduvall
16768312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
16778312e758Sdduvall		basews=`basename $CODEMGR_WS`
16788312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
16798312e758Sdduvall		if [ "$host" != "$hostname" ]; then
16808312e758Sdduvall			echo "$MACH build of $basews apparently" \
16818312e758Sdduvall			    "already started by $user on $host as $pid."
16828312e758Sdduvall			exit 1
16838312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
16848312e758Sdduvall			echo "$MACH build of $basews already started" \
16858312e758Sdduvall			    "by $user as $pid."
16868312e758Sdduvall			exit 1
16878312e758Sdduvall		else
16888312e758Sdduvall			# stale lock; clear it out and try again
16898312e758Sdduvall			rm -f $lockf
16908312e758Sdduvall		fi
16918312e758Sdduvall	done
16927c478bd9Sstevel@tonic-gate}
16937c478bd9Sstevel@tonic-gate
16944e5b757fSkupfer#
16954e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
16964e5b757fSkupfer# options.
16974e5b757fSkupfer#
16984e5b757fSkupferallprotos() {
16994e5b757fSkupfer	roots="$ROOT"
17004e5b757fSkupfer	if [ $O_FLAG = y ]; then
17014e5b757fSkupfer		# OpenSolaris deliveries require separate proto areas.
17024e5b757fSkupfer		[ $D_FLAG = y ] && roots="$roots $ROOT-open"
17034e5b757fSkupfer		[ $F_FLAG = n ] && roots="$roots $ROOT-open-nd"
17044e5b757fSkupfer	fi
17054e5b757fSkupfer	if [[ $D_FLAG = y && $F_FLAG = n ]]; then
17064e5b757fSkupfer		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd"
17074e5b757fSkupfer	fi
17084e5b757fSkupfer
17094e5b757fSkupfer	echo $roots
17104e5b757fSkupfer}
17114e5b757fSkupfer
17127c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
17137c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
17147c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
17157c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
17167c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
17177c478bd9Sstevel@tonic-gatefi
17187c478bd9Sstevel@tonic-gate#
17197c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
17207c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
17217c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
17227c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
17237c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
17247c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
17257c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
17267c478bd9Sstevel@tonic-gate#
17277c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
17287c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
17297c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
17307c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
17317c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
17327c478bd9Sstevel@tonic-gatefi
17337c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
17347c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
17357c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
17367c478bd9Sstevel@tonic-gatefi
17377c478bd9Sstevel@tonic-gate
17387c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
17397c478bd9Sstevel@tonic-gate# the directories we may have created so far.
17407c478bd9Sstevel@tonic-gatenewdirlist=
17417c478bd9Sstevel@tonic-gate
17427c478bd9Sstevel@tonic-gate#
17437c478bd9Sstevel@tonic-gate# Create mail_msg_file
17447c478bd9Sstevel@tonic-gate#
17457c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
17467c478bd9Sstevel@tonic-gatetouch $mail_msg_file
17477c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
17487c478bd9Sstevel@tonic-gate#
17497c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
17507c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
17517c478bd9Sstevel@tonic-gate#
17527c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
17537c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
17547c478bd9Sstevel@tonic-gatefi
17557c478bd9Sstevel@tonic-gate#
17567c478bd9Sstevel@tonic-gate#	Build OsNet source
17577c478bd9Sstevel@tonic-gate#
17587c478bd9Sstevel@tonic-gateSTART_DATE=`date`
17597c478bd9Sstevel@tonic-gateSECONDS=0
17607c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
17617c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
17627c478bd9Sstevel@tonic-gate
17637c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
17647c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
17657c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
17667c478bd9Sstevel@tonic-gate
1767*47703246Ssommerferun_hook SYS_PRE_NIGHTLY
1768*47703246Ssommerferun_hook PRE_NIGHTLY
1769*47703246Ssommerfe
17707c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
17717c478bd9Sstevel@tonic-gateenv >> $LOGFILE
17727c478bd9Sstevel@tonic-gate
17737c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
17747c478bd9Sstevel@tonic-gate
1775d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
1776d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1777d77e7149Ssommerfefi
1778d77e7149Ssommerfe
1779d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
1780d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1781d77e7149Ssommerfefi
1782d77e7149Ssommerfe
17831fe69678Skupferif is_source_build; then
17847c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
17857c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
17867c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
17877c478bd9Sstevel@tonic-gate		i_FLAG=n
17887c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
17897c478bd9Sstevel@tonic-gate	fi
17907c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
17917c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
17927c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
17937c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
17947c478bd9Sstevel@tonic-gate		N_FLAG=y
17957c478bd9Sstevel@tonic-gate	fi
17967c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
17977c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
17987c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
17997c478bd9Sstevel@tonic-gate		l_FLAG=n
18007c478bd9Sstevel@tonic-gate	fi
18017c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
18027c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
18037c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
18047c478bd9Sstevel@tonic-gate		C_FLAG=n
18057c478bd9Sstevel@tonic-gate	fi
18067c478bd9Sstevel@tonic-gateelse
18077c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
18087c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
18097c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
18107c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
18117c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
18127c478bd9Sstevel@tonic-gateEOF
18137c478bd9Sstevel@tonic-gate		else
18147c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
18157c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
18167c478bd9Sstevel@tonic-gateEOF
18177c478bd9Sstevel@tonic-gate		fi
18187c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
18197c478bd9Sstevel@tonic-gate	fi
18207c478bd9Sstevel@tonic-gatefi
18217c478bd9Sstevel@tonic-gate
18224e5b757fSkupferif [ "$O_FLAG" = "y" -a "$a_FLAG" = "n" ]; then
18234e5b757fSkupfer	echo "WARNING: OpenSolaris deliveries (-O) require archives;" \
18244e5b757fSkupfer	    "enabling the -a flag." | tee -a $mail_msg_file >> $LOGFILE
18254e5b757fSkupfer	a_FLAG=y
18264e5b757fSkupferfi
18274e5b757fSkupfer
18287c478bd9Sstevel@tonic-gateif [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
18297c478bd9Sstevel@tonic-gate	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
18307c478bd9Sstevel@tonic-gate	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
18317c478bd9Sstevel@tonic-gatefi
18327c478bd9Sstevel@tonic-gate
18337c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
18344e5b757fSkupfer	#
18354e5b757fSkupfer	# In the past we just complained but went ahead with the lint
18364e5b757fSkupfer	# pass, even though the proto area was built non-debug.  It's
18374e5b757fSkupfer	# unlikely that non-debug headers will make a difference, but
18384e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
18394e5b757fSkupfer	# to specify a debug build.
18404e5b757fSkupfer	#
18414e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
18427c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
18434e5b757fSkupfer	l_FLAG=n
18447c478bd9Sstevel@tonic-gatefi
18457c478bd9Sstevel@tonic-gate
18467c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
18477c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
18487c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
18497c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
18507c478bd9Sstevel@tonic-gate		f_FLAG=n
18517c478bd9Sstevel@tonic-gate	fi
18527c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
18537c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
18547c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18557c478bd9Sstevel@tonic-gate		f_FLAG=n
18567c478bd9Sstevel@tonic-gate	fi
18577c478bd9Sstevel@tonic-gatefi
18587c478bd9Sstevel@tonic-gate
185996ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
18604e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
186196ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
186296ccc8cbSesaxe	w_FLAG=n
186396ccc8cbSesaxefi
186496ccc8cbSesaxe
18657c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
18667c478bd9Sstevel@tonic-gate	#
18677c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
18687c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
18697c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
18707c478bd9Sstevel@tonic-gate	#
18717c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
18727c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
18737c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
18747c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
18757c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
18767c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
18777c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18787c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
18797c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
18807c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
18817c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
18827c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18837c478bd9Sstevel@tonic-gate	fi
18847c478bd9Sstevel@tonic-gatefi
18857c478bd9Sstevel@tonic-gate
18864e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
18874e5b757fSkupfer
18884e5b757fSkupfercase $MULTI_PROTO in
18894e5b757fSkupferyes|no)	;;
18904e5b757fSkupfer*)
18914e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
18924e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
18934e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
18944e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
18954e5b757fSkupfer	export MULTI_PROTO=no
18964e5b757fSkupfer	;;
18974e5b757fSkupferesac
18984e5b757fSkupfer
18997c478bd9Sstevel@tonic-gateecho "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
19007c478bd9Sstevel@tonic-gate
19017c478bd9Sstevel@tonic-gate# System
19027c478bd9Sstevel@tonic-gatewhence uname | tee -a $mail_msg_file >> $LOGFILE
19037c478bd9Sstevel@tonic-gateuname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
19047c478bd9Sstevel@tonic-gateecho | tee -a $mail_msg_file >> $LOGFILE
19057c478bd9Sstevel@tonic-gate
19067c478bd9Sstevel@tonic-gate# nightly (will fail in year 2100 due to SCCS flaw)
19077c478bd9Sstevel@tonic-gateecho "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
1908964296ffSrotondoecho "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
19097c478bd9Sstevel@tonic-gate
19107c478bd9Sstevel@tonic-gate# make
19117c478bd9Sstevel@tonic-gatewhence $MAKE | tee -a $mail_msg_file >> $LOGFILE
19127c478bd9Sstevel@tonic-gate$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
19137c478bd9Sstevel@tonic-gateecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
19147c478bd9Sstevel@tonic-gate    tee -a $mail_msg_file >> $LOGFILE
19157c478bd9Sstevel@tonic-gate
19167c478bd9Sstevel@tonic-gate#
19177c478bd9Sstevel@tonic-gate# Report the compiler versions.
19187c478bd9Sstevel@tonic-gate#
19197c478bd9Sstevel@tonic-gateif [ -f $SRC/Makefile ]; then
19207c478bd9Sstevel@tonic-gate	srcroot=$SRC
19217c478bd9Sstevel@tonic-gateelif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
19227c478bd9Sstevel@tonic-gate	srcroot=$BRINGOVER_WS/usr/src
19237c478bd9Sstevel@tonic-gateelse
19247c478bd9Sstevel@tonic-gate	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
19257c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
19267c478bd9Sstevel@tonic-gate	exit 1
19277c478bd9Sstevel@tonic-gatefi
19287c478bd9Sstevel@tonic-gate
19297c478bd9Sstevel@tonic-gate( cd $srcroot
19307c478bd9Sstevel@tonic-gate  for target in cc-version cc64-version java-version; do
19317c478bd9Sstevel@tonic-gate	echo
19327c478bd9Sstevel@tonic-gate	#
19337c478bd9Sstevel@tonic-gate	# Put statefile somewhere we know we can write to rather than trip
1934b84bdc30Smeem	# over a read-only $srcroot.
19357c478bd9Sstevel@tonic-gate	#
19367c478bd9Sstevel@tonic-gate	rm -f $TMPDIR/make-state
193732f1e47bSsommerfe	export SRC=$srcroot
1938b84bdc30Smeem	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
19397c478bd9Sstevel@tonic-gate		continue
19407c478bd9Sstevel@tonic-gate	fi
19417c478bd9Sstevel@tonic-gate	touch $TMPDIR/nocompiler
19427c478bd9Sstevel@tonic-gate  done
19437c478bd9Sstevel@tonic-gate  echo
19447c478bd9Sstevel@tonic-gate) | tee -a $mail_msg_file >> $LOGFILE
19457c478bd9Sstevel@tonic-gate
19467c478bd9Sstevel@tonic-gateif [ -f $TMPDIR/nocompiler ]; then
19477c478bd9Sstevel@tonic-gate	rm -f $TMPDIR/nocompiler
19487c478bd9Sstevel@tonic-gate	build_ok=n
19497c478bd9Sstevel@tonic-gate	echo "Aborting due to missing compiler." |
19507c478bd9Sstevel@tonic-gate		tee -a $mail_msg_file >> $LOGFILE
19517c478bd9Sstevel@tonic-gate	exit 1
19527c478bd9Sstevel@tonic-gatefi
19537c478bd9Sstevel@tonic-gate
19547c478bd9Sstevel@tonic-gate# as
19557c478bd9Sstevel@tonic-gatewhence as | tee -a $mail_msg_file >> $LOGFILE
19567c478bd9Sstevel@tonic-gateas -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
19577c478bd9Sstevel@tonic-gateecho | tee -a $mail_msg_file >> $LOGFILE
19587c478bd9Sstevel@tonic-gate
19597c478bd9Sstevel@tonic-gate# Check that we're running a capable link-editor
19607c478bd9Sstevel@tonic-gatewhence ld | tee -a $mail_msg_file >> $LOGFILE
19617c478bd9Sstevel@tonic-gateLDVER=`ld -V 2>&1`
19627c478bd9Sstevel@tonic-gateecho $LDVER | tee -a $mail_msg_file >> $LOGFILE
19637c478bd9Sstevel@tonic-gateLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
19647c478bd9Sstevel@tonic-gateif [ `expr $LDVER \< 422` -eq 1 ]; then
19657c478bd9Sstevel@tonic-gate	echo "The link-editor needs to be at version 422 or higher to build" | \
19667c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
19677c478bd9Sstevel@tonic-gate	echo "the latest stuff, hope your build works." | \
19687c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
19697c478bd9Sstevel@tonic-gatefi
19707c478bd9Sstevel@tonic-gate
19717c478bd9Sstevel@tonic-gateecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
19727c478bd9Sstevel@tonic-gate    tee -a $mail_msg_file >> $LOGFILE
19737c478bd9Sstevel@tonic-gate
19747c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
19757c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
19767c478bd9Sstevel@tonic-gate
197796ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
197896ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
197996ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
198096ccc8cbSesaxe	rm -rf $ROOT.prev
198196ccc8cbSesaxe    fi
198296ccc8cbSesaxe    mv $ROOT $ROOT.prev
198396ccc8cbSesaxefi
198496ccc8cbSesaxe
19854e5b757fSkupfer# Same for non-DEBUG proto area
19864e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
19874e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
19884e5b757fSkupfer		rm -rf $ROOT-nd.prev
19894e5b757fSkupfer	fi
19904e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
19914e5b757fSkupferfi
19924e5b757fSkupfer
19937c478bd9Sstevel@tonic-gate#
19947c478bd9Sstevel@tonic-gate#	Decide whether to clobber
19957c478bd9Sstevel@tonic-gate#
19967c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
19977c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
19987c478bd9Sstevel@tonic-gate
19997c478bd9Sstevel@tonic-gate	cd $SRC
20007c478bd9Sstevel@tonic-gate	# remove old clobber file
20017c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
20027c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
20037c478bd9Sstevel@tonic-gate
20047c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
20057c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
20067c478bd9Sstevel@tonic-gate	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
20077c478bd9Sstevel@tonic-gate	    -o -name '.make.*' -print | xargs rm -f
20087c478bd9Sstevel@tonic-gate
20097c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
20107c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
20117c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
20127c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
20137c478bd9Sstevel@tonic-gate		>> $mail_msg_file
20147c478bd9Sstevel@tonic-gate
20154e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
20167c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
20177c478bd9Sstevel@tonic-gate		cd ${TOOLS}
20187c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
20197c478bd9Sstevel@tonic-gate		$MAKE -ek clobber 2>&1 | \
20207c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
20217c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
20227c478bd9Sstevel@tonic-gate			>> $mail_msg_file
20237c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
20247c478bd9Sstevel@tonic-gate			>> $mail_msg_file
20257c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
20267c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
20277c478bd9Sstevel@tonic-gate	fi
202896ccc8cbSesaxe
20294e5b757fSkupfer	rm -rf `allprotos`
20307c478bd9Sstevel@tonic-gate
20317c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
20327c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
20337c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2034fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2035fb23a357Skupfer	# under SCCS, so leave them alone.
20367c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
20377c478bd9Sstevel@tonic-gate	cd $SRC
2038fb23a357Skupfer	find $relsrcdirs \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
20397c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2040fb23a357Skupfer	       -name '*.o' \) -print | \
2041fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
20427c478bd9Sstevel@tonic-gateelse
20437c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
20447c478bd9Sstevel@tonic-gatefi
20457c478bd9Sstevel@tonic-gate
20467c478bd9Sstevel@tonic-gate#
20477c478bd9Sstevel@tonic-gate#	Decide whether to bringover to the codemgr workspace
20487c478bd9Sstevel@tonic-gate#
20497c478bd9Sstevel@tonic-gateif [ "$n_FLAG" = "n" ]; then
2050*47703246Ssommerfe	run_hook PRE_BRINGOVER
2051*47703246Ssommerfe
20527c478bd9Sstevel@tonic-gate	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
20537c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
20547c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
20557c478bd9Sstevel@tonic-gate	do
20567c478bd9Sstevel@tonic-gate		sleep 120
20577c478bd9Sstevel@tonic-gate	done
20587c478bd9Sstevel@tonic-gate
20597c478bd9Sstevel@tonic-gate	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
206032f1e47bSsommerfe
206132f1e47bSsommerfe	(staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
206232f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
206332f1e47bSsommerfe		touch $TMPDIR/bringover_failed
206432f1e47bSsommerfe
2065d77e7149Ssommerfe         staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2066d77e7149Ssommerfe
2067d77e7149Ssommerfe	 if [ -s $TMPDIR/bringovercheck.out ]; then
2068d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2069d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2070d77e7149Ssommerfe	 fi
207132f1e47bSsommerfe
207232f1e47bSsommerfe	) | tee -a  $mail_msg_file >> $LOGFILE
207332f1e47bSsommerfe
207432f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
207532f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
207632f1e47bSsommerfe		build_ok=n
207732f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
20787c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
20797c478bd9Sstevel@tonic-gate		exit 1
20807c478bd9Sstevel@tonic-gate	fi
2081085d331dSkupfer
2082*47703246Ssommerfe	run_hook POST_BRINGOVER
2083*47703246Ssommerfe
2084085d331dSkupfer	#
2085085d331dSkupfer	# Possible transition from pre-split workspace to split
2086085d331dSkupfer	# workspace.  See if the bringover changed anything.
2087085d331dSkupfer	#
2088085d331dSkupfer	CLOSED_IS_PRESENT="$orig_closed_is_present"
2089085d331dSkupfer	check_closed_tree
20907c478bd9Sstevel@tonic-gateelse
20917c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
20927c478bd9Sstevel@tonic-gatefi
20937c478bd9Sstevel@tonic-gate
20947c478bd9Sstevel@tonic-gate#
20954e5b757fSkupfer# Build and use the workspace's tools if requested
20967c478bd9Sstevel@tonic-gate#
20974e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
20984e5b757fSkupfer	set_non_debug_build_flags
20997c478bd9Sstevel@tonic-gate
21007c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
21014e5b757fSkupfer
21024e5b757fSkupfer	if [[ $? -ne 0 && "$t_FLAG" = y ]]; then
21034e5b757fSkupfer		use_tools $TOOLS_PROTO
21044e5b757fSkupfer		export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
21054e5b757fSkupfer	fi
21067c478bd9Sstevel@tonic-gatefi
21077c478bd9Sstevel@tonic-gate
21086fec3625Sdduvall#
21096fec3625Sdduvall# copy ihv proto area in addition to the build itself
21106fec3625Sdduvall#
21116fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
21126fec3625Sdduvall	copy_ihv_proto
21136fec3625Sdduvallfi
21146fec3625Sdduvall
21157c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
21167c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
21177c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
21187c478bd9Sstevel@tonic-gateelse
21194e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
21204e5b757fSkupfer	touch $SRC/.build.tstamp
21214e5b757fSkupfer
21227c478bd9Sstevel@tonic-gate	normal_build
21237c478bd9Sstevel@tonic-gatefi
21247c478bd9Sstevel@tonic-gate
21254e5b757fSkupfer#
21264e5b757fSkupfer# Generate OpenSolaris deliverables if requested.
21274e5b757fSkupfer#
21284e5b757fSkupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
21294e5b757fSkupfer	#
21304e5b757fSkupfer	# Generate skeleton (minimal) closed binaries for open-only
21314e5b757fSkupfer	# build.  There's no need to distinguish debug from non-debug
21324e5b757fSkupfer	# binaries, but it simplifies file management to have separate
21334e5b757fSkupfer	# trees.
21344e5b757fSkupfer	#
21354e5b757fSkupfer
21364e5b757fSkupfer	echo "\n==== Generating skeleton closed binaries for" \
21374e5b757fSkupfer	    "open-only build ====\n" | \
21384e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
21394e5b757fSkupfer
21404e5b757fSkupfer	rm -rf $CODEMGR_WS/closed.skel
21414e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
21424e5b757fSkupfer		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
21434e5b757fSkupfer		    >>$LOGFILE 2>&1
21444e5b757fSkupfer		if [ $? -ne 0 ]; then
21454e5b757fSkupfer			echo "Couldn't create skeleton DEBUG closed binaries." |
21464e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21474e5b757fSkupfer		fi
21484e5b757fSkupfer	fi
21494e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
21504e5b757fSkupfer		mkclosed $MACH $ROOT-nd $CODEMGR_WS/closed.skel/root_$MACH-nd \
21514e5b757fSkupfer		    >>$LOGFILE 2>&1
21524e5b757fSkupfer		if [ $? -ne 0 ]; then
21534e5b757fSkupfer			echo "Couldn't create skeleton non-DEBUG closed binaries." |
21544e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21554e5b757fSkupfer		fi
21564e5b757fSkupfer	fi
21574e5b757fSkupfer
21584e5b757fSkupfer	ORIG_CLOSED_IS_PRESENT=$CLOSED_IS_PRESENT
21594e5b757fSkupfer	export CLOSED_IS_PRESENT=no
21604e5b757fSkupfer
21614e5b757fSkupfer	ORIG_ON_CLOSED_BINS="$ON_CLOSED_BINS"
21624e5b757fSkupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
21634e5b757fSkupfer
21644e5b757fSkupfer	normal_build -O
21654e5b757fSkupfer
21664e5b757fSkupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
21674e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
21684e5b757fSkupfer
21694e5b757fSkupfer	cd $CODEMGR_WS
21704e5b757fSkupfer
21714e5b757fSkupfer	echo "Generating THIRDPARTYLICENSE files..." >> $LOGFILE
21724e5b757fSkupfer
21734e5b757fSkupfer	mktpl usr/src/tools/opensolaris/license-list >>$LOGFILE 2>&1
21744e5b757fSkupfer	if [ $? -ne 0 ]; then
21754e5b757fSkupfer		echo "Couldn't create THIRDPARTYLICENSE files" |
21764e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
21774e5b757fSkupfer	fi
21784e5b757fSkupfer
21794e5b757fSkupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
218052a52aebSkupfer	closed_basename=on-closed-bins
21814e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
218252a52aebSkupfer		bindrop "$ROOT" "$ROOT-open" "$closed_basename" \
218352a52aebSkupfer		    >>"$LOGFILE" 2>&1
21844e5b757fSkupfer		if [ $? -ne 0 ]; then
21854e5b757fSkupfer			echo "Couldn't create DEBUG closed binaries." |
21864e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21874e5b757fSkupfer		fi
21884e5b757fSkupfer	fi
21894e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
219052a52aebSkupfer		bindrop -n "$ROOT-nd" "$ROOT-open-nd" "$closed_basename-nd" \
219152a52aebSkupfer		    >>"$LOGFILE" 2>&1
21924e5b757fSkupfer		if [ $? -ne 0 ]; then
21934e5b757fSkupfer			echo "Couldn't create non-DEBUG closed binaries." |
21944e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21954e5b757fSkupfer		fi
21964e5b757fSkupfer	fi
21974e5b757fSkupfer
21984e5b757fSkupfer	echo "Generating SUNWonbld tarball..." >> $LOGFILE
21994e5b757fSkupfer	PKGARCHIVE=$PKGARCHIVE_ORIG
22004e5b757fSkupfer	onblddrop >> $LOGFILE 2>&1
22014e5b757fSkupfer	if [ $? -ne 0 ]; then
22024e5b757fSkupfer		echo "Couldn't create SUNWonbld tarball." |
22034e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
22044e5b757fSkupfer	fi
22054e5b757fSkupfer
22064e5b757fSkupfer	echo "Generating README.opensolaris..." >> $LOGFILE
22074e5b757fSkupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
22084e5b757fSkupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
22094e5b757fSkupfer	if [ $? -ne 0 ]; then
22104e5b757fSkupfer		echo "Couldn't create README.opensolaris." |
22114e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
22124e5b757fSkupfer	fi
22134e5b757fSkupfer
22144e5b757fSkupfer	echo "Generating source tarball..." >> $LOGFILE
22154e5b757fSkupfer	sdrop >>$LOGFILE 2>&1
22164e5b757fSkupfer	if [ $? -ne 0 ]; then
22174e5b757fSkupfer		echo "Couldn't create source tarball." |
221852a52aebSkupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
22194e5b757fSkupfer	fi
22204e5b757fSkupfer
22214e5b757fSkupfer	echo "Generating BFU tarball(s)..." >> $LOGFILE
22224e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
222352a52aebSkupfer		makebfu_filt bfudrop "$ROOT-open" \
222452a52aebSkupfer		    "$closed_basename.$MACH.tar.bz2" nightly-osol
22254e5b757fSkupfer		if [ $? -ne 0 ]; then
22264e5b757fSkupfer			echo "Couldn't create DEBUG archives tarball." |
22274e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
22284e5b757fSkupfer		fi
22294e5b757fSkupfer	fi
22304e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
223152a52aebSkupfer		makebfu_filt bfudrop -n "$ROOT-open-nd" \
223252a52aebSkupfer		    "$closed_basename-nd.$MACH.tar.bz2" nightly-osol-nd
22334e5b757fSkupfer		if [ $? -ne 0 ]; then
22344e5b757fSkupfer			echo "Couldn't create non-DEBUG archives tarball." |
22354e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
22364e5b757fSkupfer		fi
22374e5b757fSkupfer	fi
22384e5b757fSkupfer
22394e5b757fSkupfer	ON_CLOSED_BINS=$ORIG_ON_CLOSED_BINS
22404e5b757fSkupfer	CLOSED_IS_PRESENT=$ORIG_CLOSED_IS_PRESENT
22414e5b757fSkupferfi
22424e5b757fSkupfer
22437c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
22447c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
22457c478bd9Sstevel@tonic-gate
22461fe69678Skupfer#
22471fe69678Skupfer# For the "open" build, we don't mung any source files, so skip this
22481fe69678Skupfer# step.
22491fe69678Skupfer#
22507c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
22517c478bd9Sstevel@tonic-gate	save_binaries
22527c478bd9Sstevel@tonic-gate
22537c478bd9Sstevel@tonic-gate	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
22547c478bd9Sstevel@tonic-gate	SCCSHELPER=${TMPDIR}/sccs-helper
22557c478bd9Sstevel@tonic-gate	rm -f ${SCCSHELPER}
22567c478bd9Sstevel@tonic-gatecat >${SCCSHELPER} <<EOF
22577c478bd9Sstevel@tonic-gate#!/bin/ksh
22587c478bd9Sstevel@tonic-gatecd \$1
22597c478bd9Sstevel@tonic-gatecd ..
22607c478bd9Sstevel@tonic-gatesccs get SCCS >/dev/null 2>&1
22617c478bd9Sstevel@tonic-gateEOF
22627c478bd9Sstevel@tonic-gate	cd $SRC
22637c478bd9Sstevel@tonic-gate	chmod +x ${SCCSHELPER}
2264fb23a357Skupfer	find $relsrcdirs -name SCCS | xargs -L 1 ${SCCSHELPER}
22657c478bd9Sstevel@tonic-gate	rm -f ${SCCSHELPER}
22667c478bd9Sstevel@tonic-gatefi
22677c478bd9Sstevel@tonic-gate
22687c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
22691fe69678Skupfer	set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
22707c478bd9Sstevel@tonic-gatefi
22717c478bd9Sstevel@tonic-gate
22727c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
22737c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
22747c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
22751fe69678Skupfer	set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
22767c478bd9Sstevel@tonic-gatefi
22777c478bd9Sstevel@tonic-gate
22787c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
22797c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
22807c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
22817c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
22827c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
22837c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
22847c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
22857c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
22867c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
22877c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
22887c478bd9Sstevel@tonic-gate	else
22897c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
22907c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
22917c478bd9Sstevel@tonic-gate	fi
22927c478bd9Sstevel@tonic-gate
22937c478bd9Sstevel@tonic-gatefi
22947c478bd9Sstevel@tonic-gate
22951fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
22961fe69678Skupfer	#
22971fe69678Skupfer	# Copy the open sources into their own tree, set up the closed
22984e5b757fSkupfer	# binaries, and set up the environment.  The build looks for
22994e5b757fSkupfer	# the closed binaries in a location that depends on whether
23004e5b757fSkupfer	# it's a DEBUG build, so we might need to make two copies.
23011fe69678Skupfer	#
23021fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
23031fe69678Skupfer	SRC=$OPEN_SRCDIR/usr/src
23041fe69678Skupfer
23051fe69678Skupfer	# Try not to clobber any user-provided closed binaries.
23061fe69678Skupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
23074e5b757fSkupfer
23084e5b757fSkupfer	echo "\n==== Copying skeleton closed binaries to" \
23094e5b757fSkupfer	    "$ON_CLOSED_BINS ====\n" | \
23101fe69678Skupfer	    tee -a $mail_msg_file >> $LOGFILE
23114e5b757fSkupfer
23124e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
23134e5b757fSkupfer		mkclosed $MACH $ROOT $ON_CLOSED_BINS/root_$MACH >>$LOGFILE 2>&1
23141fe69678Skupfer		if [ $? -ne 0 ]; then
23151fe69678Skupfer			build_ok=n
23164e5b757fSkupfer			echo "Couldn't create DEBUG closed binaries." |
23171fe69678Skupfer			    tee -a $mail_msg_file >> $LOGFILE
23181fe69678Skupfer		fi
23194e5b757fSkupfer	fi
23204e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
23214e5b757fSkupfer		root=$ROOT
23224e5b757fSkupfer		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
23234e5b757fSkupfer		mkclosed $MACH $root $ON_CLOSED_BINS/root_$MACH-nd \
23244e5b757fSkupfer		    >>$LOGFILE 2>&1
23254e5b757fSkupfer		if [ $? -ne 0 ]; then
23264e5b757fSkupfer			build_ok=n
23274e5b757fSkupfer			echo "Couldn't create non-DEBUG closed binaries." |
23284e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
23294e5b757fSkupfer		fi
23304e5b757fSkupfer	fi
23314e5b757fSkupfer
23324e5b757fSkupfer	export CLOSED_IS_PRESENT=no
23331fe69678Skupferfi
23341fe69678Skupfer
23351fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
23364e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
23374e5b757fSkupfer	rm -rf `allprotos`
23387c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
23394e5b757fSkupfer		set_non_debug_build_flags
2340b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
23411fe69678Skupfer		#
23421fe69678Skupfer		# SRC was set earlier to point to the source build
23431fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
23441fe69678Skupfer		#
23451fe69678Skupfer		TOOLS=${SRC}/tools
23461fe69678Skupfer		build_tools ${SRC}/tools/proto
2347b91d9e0fSdanmcd		TOOLS=$ORIG_TOOLS
23487c478bd9Sstevel@tonic-gate	fi
23497c478bd9Sstevel@tonic-gate
23507c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
23517c478bd9Sstevel@tonic-gate	normal_build
23527c478bd9Sstevel@tonic-gatefi
23537c478bd9Sstevel@tonic-gate
23541fe69678Skupferif [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
23551fe69678Skupfer	rm -rf $ON_CLOSED_BINS
23561fe69678Skupferfi
23571fe69678Skupfer
23584e5b757fSkupfer#
23594e5b757fSkupfer# There are several checks that need to look at the proto area, but
23604e5b757fSkupfer# they only need to look at one, and they don't care whether it's
23614e5b757fSkupfer# DEBUG or non-DEBUG.
23624e5b757fSkupfer#
23634e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
23644e5b757fSkupfer	checkroot=$ROOT-nd
23654e5b757fSkupferelse
23664e5b757fSkupfer	checkroot=$ROOT
23674e5b757fSkupferfi
23684e5b757fSkupfer
23697c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
23707c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
23717c478bd9Sstevel@tonic-gate		>> $LOGFILE
23724e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
23737c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
23747c478bd9Sstevel@tonic-gate		>> $LOGFILE
23757c478bd9Sstevel@tonic-gate
23767c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
23777c478bd9Sstevel@tonic-gate		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
23787c478bd9Sstevel@tonic-gate
23797c478bd9Sstevel@tonic-gate		# If there is a reference proto list, compare the build's proto
23807c478bd9Sstevel@tonic-gate		# list with the reference to see changes in proto areas.
23817c478bd9Sstevel@tonic-gate		# Use the current exception list.
23827c478bd9Sstevel@tonic-gate		exc=etc/exception_list_$MACH
23837c478bd9Sstevel@tonic-gate		if [ -f $SRC/pkgdefs/$exc ]; then
23847c478bd9Sstevel@tonic-gate			ELIST="-e $SRC/pkgdefs/$exc"
23857c478bd9Sstevel@tonic-gate		fi
23866fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
23876fec3625Sdduvall			ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
23886fec3625Sdduvall		fi
23897c478bd9Sstevel@tonic-gate
23907c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
2391b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
2392b4add148Sdduvall			# IHV proto list to the reference list if the reference
2393b4add148Sdduvall			# was built without -X.
2394b4add148Sdduvall			#
2395b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
2396b4add148Sdduvall			# IHV proto list to the build's proto list if the
2397b4add148Sdduvall			# reference was built with -X.
2398b4add148Sdduvall			#
2399b4add148Sdduvall			# Use the presence of the first file entry of the cached
2400b4add148Sdduvall			# IHV proto list in the reference list to determine
2401b4add148Sdduvall			# whether it was build with -X or not.
2402b4add148Sdduvall			IHV_REF_PROTO_LIST=$SRC/pkgdefs/etc/proto_list_ihv_$MACH
2403b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2404b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
2405b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
2406b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
2407b4add148Sdduvall					grep -w "$grepfor" \
2408b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2409b4add148Sdduvall					if [ ! "$?" = "0" ]; then
2410b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2411b4add148Sdduvall					fi
2412b4add148Sdduvall				else
2413b4add148Sdduvall					grep -w "$grepfor" \
2414b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2415b4add148Sdduvall					if [ "$?" = "0" ]; then
2416b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2417b4add148Sdduvall					fi
2418b4add148Sdduvall				fi
2419b4add148Sdduvall			fi
2420b4add148Sdduvall
24217c478bd9Sstevel@tonic-gate			$PROTOCMPTERSE \
24227c478bd9Sstevel@tonic-gate			  "Files in yesterday's proto area, but not today's:" \
24237c478bd9Sstevel@tonic-gate			  "Files in today's proto area, but not yesterday's:" \
24247c478bd9Sstevel@tonic-gate			  "Files that changed between yesterday and today:" \
24257c478bd9Sstevel@tonic-gate			  ${ELIST} \
24267c478bd9Sstevel@tonic-gate			  -d $REF_PROTO_LIST \
2427b4add148Sdduvall			  $REF_IHV_PROTO \
24287c478bd9Sstevel@tonic-gate			  $ATLOG/proto_list_${MACH} \
2429b4add148Sdduvall			  $IHV_PROTO_LIST \
24307c478bd9Sstevel@tonic-gate				>> $mail_msg_file
24317c478bd9Sstevel@tonic-gate		fi
24327c478bd9Sstevel@tonic-gate		# Compare the build's proto list with current package
24337c478bd9Sstevel@tonic-gate		# definitions to audit the quality of package definitions
24347c478bd9Sstevel@tonic-gate		# and makefile install targets. Use the current exception list.
2435fb23a357Skupfer		PKGDEFS_LIST=""
2436fb23a357Skupfer		for d in $abssrcdirs; do
2437fb23a357Skupfer			if [ -d $d/pkgdefs ]; then
2438fb23a357Skupfer				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2439fb23a357Skupfer			fi
2440fb23a357Skupfer		done
24416fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
24426fec3625Sdduvall			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
24436fec3625Sdduvall		fi
24447c478bd9Sstevel@tonic-gate
24457c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
24467c478bd9Sstevel@tonic-gate		    "Files missing from the proto area:" \
24477c478bd9Sstevel@tonic-gate		    "Files missing from packages:" \
24487c478bd9Sstevel@tonic-gate		    "Inconsistencies between pkgdefs and proto area:" \
24497c478bd9Sstevel@tonic-gate		    ${ELIST} \
24507c478bd9Sstevel@tonic-gate		    ${PKGDEFS_LIST} \
24517c478bd9Sstevel@tonic-gate		    $ATLOG/proto_list_${MACH} \
24527c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
24537c478bd9Sstevel@tonic-gate	fi
24547c478bd9Sstevel@tonic-gatefi
24557c478bd9Sstevel@tonic-gate
24567c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
24577c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
24587c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
24597c478bd9Sstevel@tonic-gatefi
24607c478bd9Sstevel@tonic-gate
24617c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
24627c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
24637c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
24647c478bd9Sstevel@tonic-gate# the variable now.
24657c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
24667c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
24677c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
24687c478bd9Sstevel@tonic-gate	# The rm -rf command below produces predictable errors if
24697c478bd9Sstevel@tonic-gate	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
24707c478bd9Sstevel@tonic-gate	# and that directory is accessed via NFS.  This is because
24717c478bd9Sstevel@tonic-gate	# deleted-but-still-open files don't actually disappear as
24727c478bd9Sstevel@tonic-gate	# expected, but rather turn into .nfsXXXX junk files, leaving
24737c478bd9Sstevel@tonic-gate	# the directory non-empty.  Since this is a not-unusual usage
24747c478bd9Sstevel@tonic-gate	# pattern, and we still want to catch other errors here, we
24757c478bd9Sstevel@tonic-gate	# take the unusal step of moving aside 'nightly' from that
24767c478bd9Sstevel@tonic-gate	# directory (if we're using it).
24777c478bd9Sstevel@tonic-gate	mypath=${0##*/root_$MACH/}
24787c478bd9Sstevel@tonic-gate	if [ "$mypath" = $0 ]; then
24797c478bd9Sstevel@tonic-gate		mypath=opt/onbld/bin/${0##*/}
24807c478bd9Sstevel@tonic-gate	fi
24817c478bd9Sstevel@tonic-gate	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
24827c478bd9Sstevel@tonic-gate		mv -f $0 $PARENT_WS/proto/root_$MACH
24837c478bd9Sstevel@tonic-gate	fi
24847c478bd9Sstevel@tonic-gate	rm -rf $PARENT_WS/proto/root_$MACH/*
24857c478bd9Sstevel@tonic-gate	unset Ulockfile
24867c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
24874e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
24887c478bd9Sstevel@tonic-gate		cd $ROOT
24894e5b757fSkupfer		( tar cf - . |
24904e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
24917c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
24927c478bd9Sstevel@tonic-gate	fi
24934e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
24944e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
24954e5b757fSkupfer		cd $ROOT-nd
24964e5b757fSkupfer		( tar cf - . |
24974e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
24984e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
24994e5b757fSkupfer	fi
25004e5b757fSkupferfi
25017c478bd9Sstevel@tonic-gate
25027c478bd9Sstevel@tonic-gate#
25037c478bd9Sstevel@tonic-gate# do shared library interface verification
25047c478bd9Sstevel@tonic-gate#
25057c478bd9Sstevel@tonic-gate
25067c478bd9Sstevel@tonic-gateif [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
25077c478bd9Sstevel@tonic-gate	echo "\n==== Check versioning and ABI information ====\n"  | \
25087c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25097c478bd9Sstevel@tonic-gate
25107c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.ref
25117c478bd9Sstevel@tonic-gate	if [ -d $SRC/interfaces.out ]; then
25127c478bd9Sstevel@tonic-gate		mv $SRC/interfaces.out $SRC/interfaces.ref
25137c478bd9Sstevel@tonic-gate	fi
25147c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.out
25157c478bd9Sstevel@tonic-gate	mkdir -p $SRC/interfaces.out
25167c478bd9Sstevel@tonic-gate
25177c478bd9Sstevel@tonic-gate	intf_check -V -m -o -b $SRC/tools/abi/etc \
25184e5b757fSkupfer		-d $SRC/interfaces.out $checkroot 2>&1 | sort \
25197c478bd9Sstevel@tonic-gate		> $SRC/interfaces.out/log
25207c478bd9Sstevel@tonic-gate
25217c478bd9Sstevel@tonic-gate	# report any ERROR found in log file
25227c478bd9Sstevel@tonic-gate	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
25237c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25247c478bd9Sstevel@tonic-gate
25257c478bd9Sstevel@tonic-gate	if [ ! -d $SRC/interfaces.ref ] ; then
25267c478bd9Sstevel@tonic-gate		mkdir -p $SRC/interfaces.ref
25277c478bd9Sstevel@tonic-gate		if [ -d  $SRC/interfaces.out ]; then
25287c478bd9Sstevel@tonic-gate			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
25297c478bd9Sstevel@tonic-gate		fi
25307c478bd9Sstevel@tonic-gate	fi
25317c478bd9Sstevel@tonic-gate
25327c478bd9Sstevel@tonic-gate	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
25337c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25347c478bd9Sstevel@tonic-gate
25357c478bd9Sstevel@tonic-gate	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
25367c478bd9Sstevel@tonic-gate	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
25377c478bd9Sstevel@tonic-gate
25387c478bd9Sstevel@tonic-gate	# Report any differences in WARNING messages between last
25397c478bd9Sstevel@tonic-gate	# and current build.
25407c478bd9Sstevel@tonic-gate	if [ "$out_vers" = "$ref_vers" ]; then
25417c478bd9Sstevel@tonic-gate		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
25427c478bd9Sstevel@tonic-gate		    fgrep 'WARNING' | sed 's/WARNING: //' | \
25437c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
25447c478bd9Sstevel@tonic-gate	fi
25457c478bd9Sstevel@tonic-gatefi
25467c478bd9Sstevel@tonic-gate
25477c478bd9Sstevel@tonic-gateif [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
25487c478bd9Sstevel@tonic-gate	echo "\n==== Check ELF runtime attributes ====\n" | \
25497c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25507c478bd9Sstevel@tonic-gate
25517c478bd9Sstevel@tonic-gate	LDDUSAGE="^ldd: does not support -e"
25527c478bd9Sstevel@tonic-gate	LDDWRONG="wrong class"
25537c478bd9Sstevel@tonic-gate	CRLERROR="^crle:"
25547c478bd9Sstevel@tonic-gate	CRLECONF="^crle: configuration file:"
25557c478bd9Sstevel@tonic-gate
25567c478bd9Sstevel@tonic-gate	rm -f $SRC/runtime.ref
25577c478bd9Sstevel@tonic-gate	if [ -f $SRC/runtime.out ]; then
25587c478bd9Sstevel@tonic-gate		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
25597c478bd9Sstevel@tonic-gate			$SRC/runtime.out > $SRC/runtime.ref
25607c478bd9Sstevel@tonic-gate	fi
25617c478bd9Sstevel@tonic-gate
25627c478bd9Sstevel@tonic-gate	# If we're doing a debug build the proto area will be left with
25637c478bd9Sstevel@tonic-gate	# debuggable objects, thus don't assert -s.
25647c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
25657c478bd9Sstevel@tonic-gate		rtime_sflag=""
25667c478bd9Sstevel@tonic-gate	else
25677c478bd9Sstevel@tonic-gate		rtime_sflag="-s"
25687c478bd9Sstevel@tonic-gate	fi
25694e5b757fSkupfer	check_rtime -d $checkroot -i -m -o $rtime_sflag $checkroot 2>&1 | \
25704e5b757fSkupfer	    egrep -v ": unreferenced object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
25714e5b757fSkupfer	    egrep -v ": unused object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
25727c478bd9Sstevel@tonic-gate	    sort >$SRC/runtime.out
25737c478bd9Sstevel@tonic-gate
25747c478bd9Sstevel@tonic-gate	# Determine any processing errors that will affect the final output
25757c478bd9Sstevel@tonic-gate	# and display these first.
25767c478bd9Sstevel@tonic-gate	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
25777c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
25787c478bd9Sstevel@tonic-gate	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
25797c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25807c478bd9Sstevel@tonic-gate	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
25817c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25827c478bd9Sstevel@tonic-gate	fi
25837c478bd9Sstevel@tonic-gate	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
25847c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
25857c478bd9Sstevel@tonic-gate	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
25867c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25877c478bd9Sstevel@tonic-gate	    echo "to execute an object, thus it could not be checked fully." | \
25887c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25897c478bd9Sstevel@tonic-gate	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
25907c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25917c478bd9Sstevel@tonic-gate	    echo "or an i386 object was encountered on a sparc system?\n" | \
25927c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25937c478bd9Sstevel@tonic-gate	fi
25947c478bd9Sstevel@tonic-gate	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
25957c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
25967c478bd9Sstevel@tonic-gate	    echo "WARNING: creation of an alternative dependency cache failed." | \
25977c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25987c478bd9Sstevel@tonic-gate	    echo "Dependencies will bind to the base system libraries.\n" | \
25997c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
26007c478bd9Sstevel@tonic-gate	    grep "$CRLECONF" $SRC/runtime.out | \
26017c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
26027c478bd9Sstevel@tonic-gate	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
26037c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
26047c478bd9Sstevel@tonic-gate	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
26057c478bd9Sstevel@tonic-gate	fi
26067c478bd9Sstevel@tonic-gate
26077c478bd9Sstevel@tonic-gate	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
26087c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
26097c478bd9Sstevel@tonic-gate
26107c478bd9Sstevel@tonic-gate	# NEEDED= and RPATH= are informational; report anything else that we
26117c478bd9Sstevel@tonic-gate	# haven't already.
26127c478bd9Sstevel@tonic-gate	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
26137c478bd9Sstevel@tonic-gate	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
26147c478bd9Sstevel@tonic-gate
26157c478bd9Sstevel@tonic-gate	# probably should compare against a 'known ok runpaths' list
26167c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/runtime.ref ]; then
26177c478bd9Sstevel@tonic-gate		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
26187c478bd9Sstevel@tonic-gate			$SRC/runtime.out >  $SRC/runtime.ref
26197c478bd9Sstevel@tonic-gate	fi
26207c478bd9Sstevel@tonic-gate
26217c478bd9Sstevel@tonic-gate	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
26227c478bd9Sstevel@tonic-gate	    >> $mail_msg_file
26237c478bd9Sstevel@tonic-gate
26247c478bd9Sstevel@tonic-gate	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
26257c478bd9Sstevel@tonic-gate	    diff $SRC/runtime.ref - >> $mail_msg_file
26267c478bd9Sstevel@tonic-gatefi
26277c478bd9Sstevel@tonic-gate
26287c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
26297c478bd9Sstevel@tonic-gate
26307c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
26317c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
26327c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
26337c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
26347c478bd9Sstevel@tonic-gate	fi
26357c478bd9Sstevel@tonic-gate	set $LINTDIRS
26367c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
26377c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
26387c478bd9Sstevel@tonic-gate	done
26397c478bd9Sstevel@tonic-gateelse
26407c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
26417c478bd9Sstevel@tonic-gatefi
26427c478bd9Sstevel@tonic-gate
26437c478bd9Sstevel@tonic-gate# "make check" begins
26447c478bd9Sstevel@tonic-gate
26457c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
26467c478bd9Sstevel@tonic-gate	# remove old check.out
26477c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
26487c478bd9Sstevel@tonic-gate
26497c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
26507c478bd9Sstevel@tonic-gate	cd $SRC
26517c478bd9Sstevel@tonic-gate	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
26527c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
26537c478bd9Sstevel@tonic-gate
26547c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
26557c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
26567c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
26577c478bd9Sstevel@tonic-gateelse
26587c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
26597c478bd9Sstevel@tonic-gatefi
26607c478bd9Sstevel@tonic-gate
26617c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
26627c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
26637c478bd9Sstevel@tonic-gate
2664fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
26657c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
26667c478bd9Sstevel@tonic-gate
26677c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
26687c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
26697c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
26707c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
26717c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
26727c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
26737c478bd9Sstevel@tonic-gate	fi
26747c478bd9Sstevel@tonic-gate
2675fb23a357Skupfer	findunref -t $SRC/.build.tstamp $SRC/.. \
2676fb23a357Skupfer	    ${TOOLS}/findunref/exception_list \
2677fb23a357Skupfer	    2>> $mail_msg_file | sort | \
2678fb23a357Skupfer	    sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
2679fb23a357Skupfer	    > $SRC/unref-${MACH}.out
26807c478bd9Sstevel@tonic-gate
26817c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
26827c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
26837c478bd9Sstevel@tonic-gate	fi
26847c478bd9Sstevel@tonic-gate
26857c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
26867c478bd9Sstevel@tonic-gatefi
26877c478bd9Sstevel@tonic-gate
26887c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
26897c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
26907c478bd9Sstevel@tonic-gate# then don't check the proto area.
26917c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
26927c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
26937c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
26947c478bd9Sstevel@tonic-gate		>>$mail_msg_file
26957c478bd9Sstevel@tonic-gate	arg=-b
26967c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
26974e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
26987c478bd9Sstevel@tonic-gatefi
26997c478bd9Sstevel@tonic-gate
27007c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
27017c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
27027c478bd9Sstevel@tonic-gate		>> $mail_msg_file
27037c478bd9Sstevel@tonic-gate	#
27047c478bd9Sstevel@tonic-gate	# Get pkginfo files from usr/src/pkgdefs
27057c478bd9Sstevel@tonic-gate	#
27067c478bd9Sstevel@tonic-gate	pmodes -qvdP \
2707fb9f9b97Skupfer	`for d in $abssrcdirs; do
2708fb9f9b97Skupfer		if [ -d "$d/pkgdefs" ]
27097c478bd9Sstevel@tonic-gate		then
2710fb9f9b97Skupfer			find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
27117c478bd9Sstevel@tonic-gate		fi
27127c478bd9Sstevel@tonic-gate	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
27137c478bd9Sstevel@tonic-gatefi
27147c478bd9Sstevel@tonic-gate
271596ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
27164e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
27174e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
27184e5b757fSkupfer	fi
271996ccc8cbSesaxe
27204e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
27214e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
272296ccc8cbSesaxe	fi
272396ccc8cbSesaxefi
272496ccc8cbSesaxe
27257c478bd9Sstevel@tonic-gateEND_DATE=`date`
27267c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
27277c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
27287c478bd9Sstevel@tonic-gate
27297c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
27307c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
27317c478bd9Sstevel@tonic-gate
27327c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
27337c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
27347c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
27357c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
27367c478bd9Sstevel@tonic-gate
27377c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
27387c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
27397c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
27407c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
27417c478bd9Sstevel@tonic-gate
27427c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
27437c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
27447c478bd9Sstevel@tonic-gate
27457c478bd9Sstevel@tonic-gate	#
27467c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
27477c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
27487c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
27497c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
27507c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
27517c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
27527c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
27537c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
27547c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
27557c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
27567c478bd9Sstevel@tonic-gate	# which was already on the parent.
27577c478bd9Sstevel@tonic-gate	#
27587c478bd9Sstevel@tonic-gate
27597c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
27607c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
27617c478bd9Sstevel@tonic-gate	shift
27627c478bd9Sstevel@tonic-gate
27637c478bd9Sstevel@tonic-gate	for unreffile; do
27647c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
27657c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
27667c478bd9Sstevel@tonic-gate	done
27677c478bd9Sstevel@tonic-gate
27687c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
27697c478bd9Sstevel@tonic-gatefi
27707c478bd9Sstevel@tonic-gate
27717c478bd9Sstevel@tonic-gate#
27727c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
27737c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
27747c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
27757c478bd9Sstevel@tonic-gate#
27767c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
27777c478bd9Sstevel@tonic-gate	exit 0
27787c478bd9Sstevel@tonic-gatefi
27797c478bd9Sstevel@tonic-gateexit 1
2780