xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision c168ccb765b0a617be17ad2b42fb3a85266fbea4)
17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6fb23a357Skupfer# Common Development and Distribution License (the "License").
7fb23a357Skupfer# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
224e5b757fSkupfer
237c478bd9Sstevel@tonic-gate#
24b83ec4edSjmcp# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
277c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
287c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
317c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
34d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
35d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
367c478bd9Sstevel@tonic-gate#
377c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
387c478bd9Sstevel@tonic-gate#
397c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
407c478bd9Sstevel@tonic-gate#
417c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
427c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
437c478bd9Sstevel@tonic-gate#
447c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
457c478bd9Sstevel@tonic-gate#
467c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
477c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
487c478bd9Sstevel@tonic-gate#
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate#
517c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
527c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
537c478bd9Sstevel@tonic-gate#
547c478bd9Sstevel@tonic-gateunset CDPATH
557c478bd9Sstevel@tonic-gate
56cdf0c1d5Smjnelson# Get the absolute path of the nightly script that the user invoked.  This
57cdf0c1d5Smjnelson# may be a relative path, and we need to do this before changing directory.
58cdf0c1d5Smjnelsonnightly_path=`whence $0`
5930635de9SJohn.Zolnowsky@Sun.COMnightly_ls="`ls -l $nightly_path`"
60cdf0c1d5Smjnelson
61cdf0c1d5Smjnelson#
62cdf0c1d5Smjnelson# Keep track of where we found nightly so we can invoke the matching
63cdf0c1d5Smjnelson# which_scm script.  If that doesn't work, don't go guessing, just rely
64cdf0c1d5Smjnelson# on the $PATH settings, which will generally give us either /opt/onbld
65cdf0c1d5Smjnelson# or the user's workspace.
66cdf0c1d5Smjnelson#
67cdf0c1d5SmjnelsonWHICH_SCM=$(dirname $nightly_path)/which_scm
68cdf0c1d5Smjnelsonif [[ ! -x $WHICH_SCM ]]; then
69cdf0c1d5Smjnelson	WHICH_SCM=which_scm
70cdf0c1d5Smjnelsonfi
71cdf0c1d5Smjnelson
724e5b757fSkupfer#
73597bd30bSMike Kupfer# Datestamp for crypto tarballs.  We don't use BUILD_DATE because it
74597bd30bSMike Kupfer# doesn't sort right and it uses English abbreviations for the month.
75597bd30bSMike Kupfer# We want to guarantee a consistent string, so just invoke date(1)
76597bd30bSMike Kupfer# once and save the result in a global variable.  YYYY-MM-DD is easier
77597bd30bSMike Kupfer# to parse visually than YYYYMMDD.
78597bd30bSMike Kupfer#
79597bd30bSMike Kupfercryptostamp=$(date +%Y-%m-%d)
80597bd30bSMike Kupfer
81597bd30bSMike Kupfer#
82597bd30bSMike Kupfer# Echo the path for depositing a crypto tarball, creating the target
83597bd30bSMike Kupfer# directory if it doesn't already exist.
84597bd30bSMike Kupfer# usage: cryptodest suffix
85597bd30bSMike Kupfer# where "suffix" is "" or "-nd".
86597bd30bSMike Kupfer#
87597bd30bSMike Kupferfunction cryptodest {
88597bd30bSMike Kupfer	typeset suffix=$1
89597bd30bSMike Kupfer	#
90597bd30bSMike Kupfer	# $PKGARCHIVE gets wiped out with each build, so put the
91597bd30bSMike Kupfer	# tarball one level up.
92597bd30bSMike Kupfer	#
93597bd30bSMike Kupfer	typeset dir=$(dirname "$PKGARCHIVE")
94597bd30bSMike Kupfer	[ -d "$dir" ] || mkdir -p "$dir" >> "$LOGFILE" 2>&1
95597bd30bSMike Kupfer	#
96597bd30bSMike Kupfer	# Put the suffix after the datestamp to make it easier for
97597bd30bSMike Kupfer	# gatelings to use crypto from a specific date (no need to
98597bd30bSMike Kupfer	# copy and rename the gate tarball).
99597bd30bSMike Kupfer	#
100597bd30bSMike Kupfer	echo "$dir/on-crypto-$cryptostamp$suffix.$MACH.tar"
101597bd30bSMike Kupfer}
102597bd30bSMike Kupfer
103597bd30bSMike Kupfer#
104597bd30bSMike Kupfer# Create a non-stamped symlink to the given crypto tarball.
105597bd30bSMike Kupfer# Return 0 on success, non-zero on failure.
106597bd30bSMike Kupfer#
107597bd30bSMike Kupferfunction cryptolink {
108597bd30bSMike Kupfer	typeset targpath=$1
109597bd30bSMike Kupfer	typeset suffix=$2
110597bd30bSMike Kupfer	if [ ! -f "$targpath" ]; then
111597bd30bSMike Kupfer		echo "no crypto at $targpath"
112597bd30bSMike Kupfer		return 1
113597bd30bSMike Kupfer	fi
114597bd30bSMike Kupfer	typeset dir=$(dirname "$targpath")
115597bd30bSMike Kupfer	typeset targfile=$(basename "$targpath")
116597bd30bSMike Kupfer	typeset link=on-crypto$suffix.$MACH.tar.bz2
117597bd30bSMike Kupfer	(cd "$dir"; rm -f "$link")
118597bd30bSMike Kupfer	(cd "$dir"; ln -s "$targfile" "$link")
119597bd30bSMike Kupfer	return $?
120597bd30bSMike Kupfer}
121597bd30bSMike Kupfer
122597bd30bSMike Kupfer#
123597bd30bSMike Kupfer# Generate a crypto tarball from the proto area and put it in the
124597bd30bSMike Kupfer# canonical location, along with the datestamp-free symlink.
125597bd30bSMike Kupfer# Sets build_ok to "n" if there is a problem.
126597bd30bSMike Kupfer#
127597bd30bSMike Kupferfunction crypto_from_proto {
128597bd30bSMike Kupfer	typeset label=$1
129597bd30bSMike Kupfer	typeset suffix=$2
130597bd30bSMike Kupfer	typeset -i stat
131597bd30bSMike Kupfer	typeset to
132597bd30bSMike Kupfer
133597bd30bSMike Kupfer	echo "Creating $label crypto tarball..." >> "$LOGFILE"
134597bd30bSMike Kupfer
135597bd30bSMike Kupfer	#
136597bd30bSMike Kupfer	# Generate the crypto THIRDPARTYLICENSE file.  This needs to
137597bd30bSMike Kupfer	# be done after the build has finished and before we run
138597bd30bSMike Kupfer	# cryptodrop.  We'll generate the file twice if we're building
139ead1f93eSLiane Praza	# both DEBUG and non-DEBUG, but it's a cheap operation and not
140597bd30bSMike Kupfer	# worth the complexity to only do once.
141597bd30bSMike Kupfer	#
142597bd30bSMike Kupfer	mktpl -c usr/src/tools/opensolaris/license-list >> "$LOGFILE" 2>&1
143597bd30bSMike Kupfer	if (( $? != 0 )) ; then
144597bd30bSMike Kupfer		echo "Couldn't create crypto THIRDPARTYLICENSE file." |
145597bd30bSMike Kupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
146597bd30bSMike Kupfer		build_ok=n
147597bd30bSMike Kupfer		return
148597bd30bSMike Kupfer	fi
149597bd30bSMike Kupfer
150597bd30bSMike Kupfer	to=$(cryptodest "$suffix")
151597bd30bSMike Kupfer	if [ "$suffix" = "-nd" ]; then
152597bd30bSMike Kupfer		cryptodrop -n "$to" >> "$LOGFILE" 2>&1
153597bd30bSMike Kupfer	else
154597bd30bSMike Kupfer		cryptodrop "$to" >> "$LOGFILE" 2>&1
155597bd30bSMike Kupfer	fi
156597bd30bSMike Kupfer	if (( $? != 0 )) ; then
157597bd30bSMike Kupfer		echo "\nCould not create $label crypto tarball." |
158597bd30bSMike Kupfer		   tee -a "$mail_msg_file" >> "$LOGFILE"
159597bd30bSMike Kupfer		build_ok=n
160597bd30bSMike Kupfer	else
161597bd30bSMike Kupfer		cryptolink "$to.bz2" "$suffix" >> "$LOGFILE" 2>&1
162597bd30bSMike Kupfer		if (( $? != 0 )) ; then
163597bd30bSMike Kupfer			build_ok=n
164597bd30bSMike Kupfer		fi
165597bd30bSMike Kupfer	fi
166597bd30bSMike Kupfer}
167597bd30bSMike Kupfer
168597bd30bSMike Kupfer#
1694e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
1707c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
1717c478bd9Sstevel@tonic-gate# non-DEBUG packages.
1724e5b757fSkupfer#
173b83ec4edSjmcp# usage: normal_build
174ead1f93eSLiane Praza#
175597bd30bSMike Kupferfunction normal_build {
1767c478bd9Sstevel@tonic-gate
17752a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
17852a52aebSkupfer	typeset orig_a_FLAG="$a_FLAG"
179597bd30bSMike Kupfer	typeset crypto_in="$ON_CRYPTO_BINS"
180597bd30bSMike Kupfer	typeset crypto_signer="$CODESIGN_USER"
181597bd30bSMike Kupfer	typeset gencrypto=no
1824e5b757fSkupfer
1834e5b757fSkupfer	suffix=""
184597bd30bSMike Kupfer	[ -n "$CODESIGN_USER" ] && gencrypto=yes
185ead1f93eSLiane Praza
1867c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
1894e5b757fSkupfer		set_non_debug_build_flags
190597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
191b83ec4edSjmcp		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO" \
192597bd30bSMike Kupfer		    $(ndcrypto "$crypto_in")
1934e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1944e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1957c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
1967c478bd9Sstevel@tonic-gate		fi
197597bd30bSMike Kupfer
198597bd30bSMike Kupfer		if [[ "$gencrypto" = yes && "$build_ok" = y ]]; then
199597bd30bSMike Kupfer			crypto_from_proto non-DEBUG -nd
200597bd30bSMike Kupfer		fi
2017c478bd9Sstevel@tonic-gate	else
20252a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
2037c478bd9Sstevel@tonic-gate	fi
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate	# DEBUG build begins
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
2104e5b757fSkupfer		set_debug_build_flags
211597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
212b83ec4edSjmcp		    build "DEBUG" "$suffix" "" "$MULTI_PROTO" "$crypto_in"
2134e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
2144e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
2157c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
2167c478bd9Sstevel@tonic-gate		fi
2177c478bd9Sstevel@tonic-gate
218597bd30bSMike Kupfer		if [[ "$gencrypto" = yes && "$build_ok" = y ]]; then
219597bd30bSMike Kupfer			crypto_from_proto DEBUG ""
220597bd30bSMike Kupfer		fi
2217c478bd9Sstevel@tonic-gate	else
22252a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
2237c478bd9Sstevel@tonic-gate	fi
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate	# DEBUG build ends
2264e5b757fSkupfer
22752a52aebSkupfer	p_FLAG="$orig_p_FLAG"
22852a52aebSkupfer	a_FLAG="$orig_a_FLAG"
2297c478bd9Sstevel@tonic-gate}
2307c478bd9Sstevel@tonic-gate
2311fe69678Skupfer#
23247703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
23347703246Ssommerfe#
23447703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
23547703246Ssommerfe# our logs and then run the command with ARGS
23647703246Ssommerfe#
237597bd30bSMike Kupferfunction run_hook {
23847703246Ssommerfe	HOOKNAME=$1
23947703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
24047703246Ssommerfe	shift
24147703246Ssommerfe
24247703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
24347703246Ssommerfe	    	(
24447703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
24547703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
24647703246Ssommerfe			if [ "$?" -ne 0 ]; then
24747703246Ssommerfe			    	# Let exit status propagate up
24847703246Ssommerfe			    	touch $TMPDIR/abort
24947703246Ssommerfe			fi
25047703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
25147703246Ssommerfe
25247703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
25347703246Ssommerfe			build_ok=n
25447703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
25547703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
25647703246Ssommerfe			exit 1
25747703246Ssommerfe		fi
25847703246Ssommerfe	fi
25947703246Ssommerfe}
26047703246Ssommerfe
26147703246Ssommerfe#
2621fe69678Skupfer# usage: filelist DESTDIR PATTERN
2631fe69678Skupfer#
264597bd30bSMike Kupferfunction filelist {
2657c478bd9Sstevel@tonic-gate	DEST=$1
2667c478bd9Sstevel@tonic-gate	PATTERN=$2
2677c478bd9Sstevel@tonic-gate	cd ${DEST}
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
2707c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
2717c478bd9Sstevel@tonic-gate		return;
2727c478bd9Sstevel@tonic-gate	fi
2731fe69678Skupfer	for i in `grep -v '^#' ${OBJFILES} | \
2747c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
2757c478bd9Sstevel@tonic-gate	do
2767c478bd9Sstevel@tonic-gate		# wildcard expansion
2777c478bd9Sstevel@tonic-gate		for j in $i
2787c478bd9Sstevel@tonic-gate		do
2797c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
2807c478bd9Sstevel@tonic-gate				echo $j
2817c478bd9Sstevel@tonic-gate			fi
2827c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
2837c478bd9Sstevel@tonic-gate				echo $j
2847c478bd9Sstevel@tonic-gate			fi
2857c478bd9Sstevel@tonic-gate		done
2867c478bd9Sstevel@tonic-gate	done | sort | uniq
2877c478bd9Sstevel@tonic-gate}
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
2907c478bd9Sstevel@tonic-gate# restoration
291597bd30bSMike Kupferfunction save_binaries {
2927c478bd9Sstevel@tonic-gate	# save off list of binaries
2937c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
2947c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2957c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
2967c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
2977c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
2987c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
2997c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
3007c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
3017c478bd9Sstevel@tonic-gate}
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate# delete files
3041fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
305597bd30bSMike Kupferfunction hybridize_files {
3067c478bd9Sstevel@tonic-gate	DEST=$1
3077c478bd9Sstevel@tonic-gate	MAKETARG=$2
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
3107c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3117c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
3127c478bd9Sstevel@tonic-gate	do
3137c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
3147c478bd9Sstevel@tonic-gate		rm -rf "${i}"
3157c478bd9Sstevel@tonic-gate	done
3167c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
3177c478bd9Sstevel@tonic-gate	do
3187c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
3197c478bd9Sstevel@tonic-gate		rm -f ${i}+
3207c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
3217c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
3227c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
3237c478bd9Sstevel@tonic-gate	done
3247c478bd9Sstevel@tonic-gate}
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
3271fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
328597bd30bSMike Kupferfunction restore_binaries {
3297c478bd9Sstevel@tonic-gate	DEST=$1
3307c478bd9Sstevel@tonic-gate	MAKETARG=$2
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
3337c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3347c478bd9Sstevel@tonic-gate	cd ${DEST}
3357c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
3367c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
3377c478bd9Sstevel@tonic-gate}
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate# rename files we save binaries of
3401fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
341597bd30bSMike Kupferfunction rename_files {
3427c478bd9Sstevel@tonic-gate	DEST=$1
3437c478bd9Sstevel@tonic-gate	MAKETARG=$2
3447c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
3457c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3467c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
3477c478bd9Sstevel@tonic-gate	do
3487c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
3497c478bd9Sstevel@tonic-gate		rm -f ${i}.export
3507c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
3517c478bd9Sstevel@tonic-gate	done
3527c478bd9Sstevel@tonic-gate}
3537c478bd9Sstevel@tonic-gate
3541fe69678Skupfer#
3551fe69678Skupfer# Copy some or all of the source tree.
356cdf0c1d5Smjnelson#
357cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
358cdf0c1d5Smjnelson#
3591fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
3601fe69678Skupfer#
361597bd30bSMike Kupferfunction copy_source {
3627c478bd9Sstevel@tonic-gate	WS=$1
3637c478bd9Sstevel@tonic-gate	DEST=$2
3641fe69678Skupfer	label=$3
3651fe69678Skupfer	srcroot=$4
3667c478bd9Sstevel@tonic-gate
367cdf0c1d5Smjnelson	printf "\n==== Creating %s source from %s (%s) ====\n\n" \
368cdf0c1d5Smjnelson	    "$DEST" "$WS" "$label" | tee -a $mail_msg_file >> $LOGFILE
369cdf0c1d5Smjnelson
370cdf0c1d5Smjnelson	printf "cleaning out %s\n" "$DEST." >> $LOGFILE
371cdf0c1d5Smjnelson	rm -rf "$DEST" >> $LOGFILE 2>&1
372cdf0c1d5Smjnelson
373cdf0c1d5Smjnelson	printf "creating %s\n" "$DEST." >> $LOGFILE
374cdf0c1d5Smjnelson	mkdir -p "$DEST" 2>> $LOGFILE
375cdf0c1d5Smjnelson
376cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
377cdf0c1d5Smjnelson		printf "failed to create %s\n" "$DEST" |
3787c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
379cdf0c1d5Smjnelson		build_ok=n
380cdf0c1d5Smjnelson		return 1
381cdf0c1d5Smjnelson	fi
382cdf0c1d5Smjnelson	cd "$WS"
3837c478bd9Sstevel@tonic-gate
384cdf0c1d5Smjnelson	printf "populating %s\n" "$DEST." >> $LOGFILE
3857c478bd9Sstevel@tonic-gate
386cdf0c1d5Smjnelson	case "$SCM_TYPE" in
387cdf0c1d5Smjnelson	teamware)
3881fe69678Skupfer		find $srcroot -name 's\.*' -a -type f -print | \
3897c478bd9Sstevel@tonic-gate		    sed -e 's,SCCS\/s.,,' | \
3907c478bd9Sstevel@tonic-gate		    grep -v '/\.del-*' | \
391cdf0c1d5Smjnelson		    cpio -pd $DEST >>$LOGFILE 2>&1
392cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
393cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$DEST" |
394cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
395cdf0c1d5Smjnelson		    build_ok=n
396cdf0c1d5Smjnelson		    return 1
397cdf0c1d5Smjnelson		fi
398cdf0c1d5Smjnelson		;;
399cdf0c1d5Smjnelson	mercurial)
400cdf0c1d5Smjnelson		copy_source_mercurial $DEST $srcroot
401cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
402cdf0c1d5Smjnelson		    build_ok=n
403cdf0c1d5Smjnelson		    return 1
404cdf0c1d5Smjnelson		fi
405cdf0c1d5Smjnelson		;;
406cdf0c1d5Smjnelson	*)
407cdf0c1d5Smjnelson		build_ok=n
408cdf0c1d5Smjnelson		echo "Tree copy is not supported for workspace type" \
409cdf0c1d5Smjnelson		    "$SCM_TYPE" | tee -a $mail_msg_file >> $LOGFILE
410cdf0c1d5Smjnelson		return 1
411cdf0c1d5Smjnelson		;;
412cdf0c1d5Smjnelson	esac
413cdf0c1d5Smjnelson
414cdf0c1d5Smjnelson	return 0
415cdf0c1d5Smjnelson}
416cdf0c1d5Smjnelson
417cdf0c1d5Smjnelson#
418cdf0c1d5Smjnelson# Mercurial-specific copy code for copy_source().  Handles the
419cdf0c1d5Smjnelson# combined open and closed trees.
420cdf0c1d5Smjnelson#
421cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
422cdf0c1d5Smjnelson#
423cdf0c1d5Smjnelson# usage: copy_source_mercurial destdir srcroot
424cdf0c1d5Smjnelson#
425cdf0c1d5Smjnelsonfunction copy_source_mercurial {
426cdf0c1d5Smjnelson	typeset dest=$1
427cdf0c1d5Smjnelson	typeset srcroot=$2
428cdf0c1d5Smjnelson	typeset open_top closed_top
429cdf0c1d5Smjnelson
430cdf0c1d5Smjnelson	case $srcroot in
431cdf0c1d5Smjnelson	usr)
432cdf0c1d5Smjnelson		open_top=usr
433cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = yes ]]; then
434cdf0c1d5Smjnelson			closed_top=usr/closed
435cdf0c1d5Smjnelson		fi
436cdf0c1d5Smjnelson		;;
437cdf0c1d5Smjnelson	usr/closed*)
438cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = no ]]; then
439cdf0c1d5Smjnelson			printf "can't copy %s: closed tree not present.\n" \
440cdf0c1d5Smjnelson			    "$srcroot" | tee -a $mail_msg_file >> $LOGFILE
441cdf0c1d5Smjnelson			return 1
442cdf0c1d5Smjnelson		fi
443cdf0c1d5Smjnelson		closed_top="$srcroot"
444cdf0c1d5Smjnelson		;;
445cdf0c1d5Smjnelson	*)
446cdf0c1d5Smjnelson		open_top="$srcroot"
447cdf0c1d5Smjnelson		;;
448cdf0c1d5Smjnelson	esac
449cdf0c1d5Smjnelson
450cdf0c1d5Smjnelson	if [[ -n "$open_top" ]]; then
451cdf0c1d5Smjnelson		hg locate -I "$open_top" | cpio -pd "$dest" >>$LOGFILE 2>&1
452cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
453cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$dest" |
454cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
455cdf0c1d5Smjnelson		    return 1
456cdf0c1d5Smjnelson		fi
457cdf0c1d5Smjnelson	fi
458cdf0c1d5Smjnelson
459cdf0c1d5Smjnelson	if [[ -n "$closed_top" ]]; then
460cdf0c1d5Smjnelson		mkdir -p "$dest/usr/closed" || return 1
461cdf0c1d5Smjnelson		if [[ "$closed_top" = usr/closed ]]; then
462cdf0c1d5Smjnelson			(cd usr/closed; hg locate |
463cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
464cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
465cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed\n" \
466cdf0c1d5Smjnelson				"$dest" | tee -a $mail_msg_file >> $LOGFILE
467cdf0c1d5Smjnelson			    return 1
468cdf0c1d5Smjnelson			fi
469cdf0c1d5Smjnelson		else
470cdf0c1d5Smjnelson			# copy subtree of usr/closed
471cdf0c1d5Smjnelson			closed_top=${closed_top#usr/closed/}
472cdf0c1d5Smjnelson			(cd usr/closed; hg locate -I "$closed_top" |
473cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
474cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
475cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed/%s\n" \
476cdf0c1d5Smjnelson				"$dest" "$closed_top" |
477cdf0c1d5Smjnelson				tee -a $mail_msg_file >> $LOGFILE
478cdf0c1d5Smjnelson			    return 1
479cdf0c1d5Smjnelson			fi
480cdf0c1d5Smjnelson		fi
481cdf0c1d5Smjnelson	fi
482cdf0c1d5Smjnelson
483cdf0c1d5Smjnelson	return 0
4841fe69678Skupfer}
4857c478bd9Sstevel@tonic-gate
4861fe69678Skupfer#
4871fe69678Skupfer# function to create (but not build) the export/crypt source tree.
4881fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
4891fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
4901fe69678Skupfer# builds the tree.
4911fe69678Skupfer#
492597bd30bSMike Kupferfunction set_up_source_build {
4931fe69678Skupfer	WS=$1
4941fe69678Skupfer	DEST=$2
4951fe69678Skupfer	MAKETARG=$3
4961fe69678Skupfer
4971fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
498cdf0c1d5Smjnelson	if (( $? != 0 )); then
499cdf0c1d5Smjnelson	    echo "\nCould not copy source tree for source build." |
500cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
501cdf0c1d5Smjnelson	    build_ok=n
502cdf0c1d5Smjnelson	    return
503cdf0c1d5Smjnelson	fi
504cdf0c1d5Smjnelson
5057c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate	cd $SRC
5087c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
5097c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
5107c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
5117c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
5127c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
5137c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
5147c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
5157c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
5167c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
5197c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate	cd ${DEST}
5227c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
5237c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
5247c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
5257c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
5267c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
5277c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
5287c478bd9Sstevel@tonic-gate		do
5297c478bd9Sstevel@tonic-gate			# make sure the files exist
5307c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
5317c478bd9Sstevel@tonic-gate				continue
5327c478bd9Sstevel@tonic-gate			fi
5337c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
5347c478bd9Sstevel@tonic-gate				continue
5357c478bd9Sstevel@tonic-gate			fi
5367c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
5377c478bd9Sstevel@tonic-gate		done
5387c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
5397c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
5407c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
5417c478bd9Sstevel@tonic-gate	fi
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
5447c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
5457c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
5467c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
5477c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
5487c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
5497c478bd9Sstevel@tonic-gate		fi
5507c478bd9Sstevel@tonic-gate	fi
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate	# save the cleartext
5537c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
5547c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
5557c478bd9Sstevel@tonic-gate	cd ${DEST}
5567c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
557fb23a357Skupfer	find usr -depth -print | \
5587c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
5597c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
5607c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
5617c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
5627c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
5637c478bd9Sstevel@tonic-gate	fi
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
5667c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
5677c478bd9Sstevel@tonic-gate	fi
5687c478bd9Sstevel@tonic-gate
5697c478bd9Sstevel@tonic-gate}
5707c478bd9Sstevel@tonic-gate
5714e5b757fSkupfer# Return library search directive as function of given root.
572597bd30bSMike Kupferfunction myldlibs {
5734e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
5744e5b757fSkupfer}
5757c478bd9Sstevel@tonic-gate
5764e5b757fSkupfer# Return header search directive as function of given root.
577597bd30bSMike Kupferfunction myheaders {
5784e5b757fSkupfer	echo "-I$1/usr/include"
5794e5b757fSkupfer}
5804e5b757fSkupfer
5814e5b757fSkupfer#
58252a52aebSkupfer# Wrapper over commands that generate BFU archives.  The entire
58352a52aebSkupfer# command output gets written to LOGFILE, and any unexpected messages
58452a52aebSkupfer# are written to the mail message.  Returns with the status of the
58552a52aebSkupfer# original command.
58652a52aebSkupfer#
587597bd30bSMike Kupferfunction makebfu_filt {
58852a52aebSkupfer	typeset tmplog
58952a52aebSkupfer	typeset errors
59052a52aebSkupfer	typeset cmd
59152a52aebSkupfer	integer cmd_stat
59252a52aebSkupfer
59352a52aebSkupfer	cmd="$1"
59452a52aebSkupfer	shift
59552a52aebSkupfer	tmplog="$TMPDIR/$cmd.out"
59652a52aebSkupfer	errors="$TMPDIR/$cmd-errors"
59752a52aebSkupfer	$cmd $* > "$tmplog" 2>&1
59852a52aebSkupfer	cmd_stat=$?
59952a52aebSkupfer	cat "$tmplog" >> "$LOGFILE"
60052a52aebSkupfer	grep -v "^Creating .* archive:" "$tmplog" | grep -v "^Making" | \
60152a52aebSkupfer	    grep -v "^$" | sort -u > "$errors"
60252a52aebSkupfer	if [[ -s "$errors" ]]; then
60352a52aebSkupfer		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
60452a52aebSkupfer		    >> "$mail_msg_file"
60552a52aebSkupfer		cat "$errors" >> "$mail_msg_file"
60652a52aebSkupfer	fi
60752a52aebSkupfer	rm -f "$tmplog" "$errors"
60852a52aebSkupfer	return $cmd_stat
60952a52aebSkupfer}
61052a52aebSkupfer
61152a52aebSkupfer#
612597bd30bSMike Kupfer# Unpack the crypto tarball into the proto area.  We first extract the
613ead1f93eSLiane Praza# tarball into a temp directory so that we can handle the non-DEBUG
614597bd30bSMike Kupfer# tarball correctly with MULTI_PROTO=no.
615597bd30bSMike Kupfer# Return 0 on success, non-zero on failure.
616597bd30bSMike Kupfer#
617597bd30bSMike Kupferfunction unpack_crypto {
618597bd30bSMike Kupfer	typeset tarfile=$1
619597bd30bSMike Kupfer	typeset suffix=$2
620597bd30bSMike Kupfer	typeset ctop=$(mktemp -d /tmp/crypto.XXXXXX)
621597bd30bSMike Kupfer	[ -n "$ctop" ] || return 1
622597bd30bSMike Kupfer	typeset croot=$ctop/proto/root_$MACH$suffix
623597bd30bSMike Kupfer	echo "Unpacking crypto ($tarfile)..."
624597bd30bSMike Kupfer	bzcat "$tarfile" | (cd "$ctop"; tar xfBp -)
625597bd30bSMike Kupfer	if [[ $? -ne 0 || ! -d "$croot" ]]; then
626597bd30bSMike Kupfer		return 1
627597bd30bSMike Kupfer	fi
628597bd30bSMike Kupfer	#
629597bd30bSMike Kupfer	# We extract with -p so that we maintain permissions on directories.
630597bd30bSMike Kupfer	#
631597bd30bSMike Kupfer	(cd "$croot"; tar cf - *) | (cd "$ROOT"; tar xfBp -)
632597bd30bSMike Kupfer	typeset -i stat=$?
633597bd30bSMike Kupfer	rm -rf "$ctop"
634597bd30bSMike Kupfer	return $stat
635597bd30bSMike Kupfer}
636597bd30bSMike Kupfer
637597bd30bSMike Kupfer#
6384e5b757fSkupfer# Function to do the build, including cpio archive and package generation.
639597bd30bSMike Kupfer# usage: build LABEL SUFFIX ND MULTIPROTO CRYPTO
6404e5b757fSkupfer# - LABEL is used to tag build output.
641ead1f93eSLiane Praza# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
642597bd30bSMike Kupfer#   open-only vs full tree).
643ead1f93eSLiane Praza# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
6444e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
6454e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
646597bd30bSMike Kupfer# - CRYPTO is the path to the crypto tarball, or null.
6474e5b757fSkupfer#
648597bd30bSMike Kupferfunction build {
6497c478bd9Sstevel@tonic-gate	LABEL=$1
6507c478bd9Sstevel@tonic-gate	SUFFIX=$2
651597bd30bSMike Kupfer	ND=$3
652597bd30bSMike Kupfer	MULTIPROTO=$4
653597bd30bSMike Kupfer	CRYPTOPATH=$5
6547c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
6557c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
6567c478bd9Sstevel@tonic-gate	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
6577c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
6587c478bd9Sstevel@tonic-gate
6594e5b757fSkupfer	ORIGROOT=$ROOT
6604e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
6614e5b757fSkupfer
662b83ec4edSjmcp	if [[ "$O_FLAG" = y ]]; then
663b83ec4edSjmcp		echo "\nSetting CLOSEDROOT= ${ROOT}-closed\n" >> $LOGFILE
664b83ec4edSjmcp		export CLOSEDROOT=${ROOT}-closed
665b83ec4edSjmcp	fi
666b83ec4edSjmcp
6674e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
6684e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
6694e5b757fSkupfer
6707c478bd9Sstevel@tonic-gate	this_build_ok=y
6717c478bd9Sstevel@tonic-gate	#
6727c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
6737c478bd9Sstevel@tonic-gate	#
6747c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
6757c478bd9Sstevel@tonic-gate		>> $LOGFILE
6767c478bd9Sstevel@tonic-gate
6777c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
6787c478bd9Sstevel@tonic-gate	cd $SRC
6797c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
6807c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
68132f1e47bSsommerfe
682cdf0c1d5Smjnelson	if [[ "$SCM_TYPE" = teamware ]]; then
68332f1e47bSsommerfe		echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
684cdf0c1d5Smjnelson		egrep 'sccs(check:| *get)' $SRC/${INSTALLOG}.out >> \
685cdf0c1d5Smjnelson			$mail_msg_file
686cdf0c1d5Smjnelson	fi
68732f1e47bSsommerfe
6887c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
6897c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
6907c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
6917c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
6927c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
6937c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
6947c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
6957c478bd9Sstevel@tonic-gate		build_ok=n
6967c478bd9Sstevel@tonic-gate		this_build_ok=n
6977c478bd9Sstevel@tonic-gate	fi
6987c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
6997c478bd9Sstevel@tonic-gate		>> $mail_msg_file
7007c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
7017c478bd9Sstevel@tonic-gate		build_ok=n
7027c478bd9Sstevel@tonic-gate		this_build_ok=n
7037c478bd9Sstevel@tonic-gate	fi
7047c478bd9Sstevel@tonic-gate
705597bd30bSMike Kupfer	if [ -n "$CRYPTOPATH" ]; then
706597bd30bSMike Kupfer		unpack_crypto "$CRYPTOPATH" "$ND" >> "$LOGFILE" 2>&1
707597bd30bSMike Kupfer		if (( $? != 0 )) ; then
708597bd30bSMike Kupfer			echo "Could not unpack crypto ($CRYPTOPATH)" |
709597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
710597bd30bSMike Kupfer			build_ok=n
711597bd30bSMike Kupfer			this_build_ok=n
712597bd30bSMike Kupfer		fi
713597bd30bSMike Kupfer	fi
714597bd30bSMike Kupfer
7157c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
7167c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
7177c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
7187c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
71920272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
7207c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
7217c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
7227c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
7237c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7247c478bd9Sstevel@tonic-gate	fi
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
7277c478bd9Sstevel@tonic-gate		>> $LOGFILE
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
7307c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
7337c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
7347c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
7357c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
7367c478bd9Sstevel@tonic-gate		fi
7377c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
7387c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
7397c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
7407c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
7417c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
7427c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
7437c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
7447c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
7457c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
7467c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
7477c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
7487c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
7497c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
7507c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
7517c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
7527c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
7537c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
7547c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
75520272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
7567c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
7577c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
7587c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
7597c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
7607c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
7617c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
7627c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
7637c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
7647c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
7657c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
7667c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
7677c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
7687c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
7697c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
7707c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
7717c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
7727c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
7737c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
7747c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
7757c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
7767c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
7777c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
7787c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
7797c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
7807c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
7817c478bd9Sstevel@tonic-gate			| egrep -v '::' \
7827c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
783010b217aSwesolows			| egrep -v '^\+' \
78403eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
785c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
7867c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
7877c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
7887c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
7897c478bd9Sstevel@tonic-gate		fi
7907c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
7917c478bd9Sstevel@tonic-gate			>>$mail_msg_file
7927c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
7937c478bd9Sstevel@tonic-gate	fi
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate	#
79623259b79Srotondo	#	Re-sign selected binaries using signing server
79723259b79Srotondo	#	(gatekeeper builds only)
79823259b79Srotondo	#
7992210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
80023259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
80123259b79Srotondo		signing_file="${TMPDIR}/signing"
80223259b79Srotondo		rm -f ${signing_file}
80323259b79Srotondo		export CODESIGN_USER
80423259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
80523259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
80623259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
80723259b79Srotondo		    >> $LOGFILE
80823259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
80923259b79Srotondo		    >> $mail_msg_file
81023259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
811cdf0c1d5Smjnelson		if (( $? == 0 )) ; then
8122210853dSjohnz			build_ok=n
8132210853dSjohnz			this_build_ok=n
8142210853dSjohnz		fi
81523259b79Srotondo	fi
81623259b79Srotondo
81723259b79Srotondo	#
8187c478bd9Sstevel@tonic-gate	#	Create cpio archives for preintegration testing (PIT)
8197c478bd9Sstevel@tonic-gate	#
8207c478bd9Sstevel@tonic-gate	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
8217c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
8227c478bd9Sstevel@tonic-gate			>> $LOGFILE
82352a52aebSkupfer		makebfu_filt makebfu
8247c478bd9Sstevel@tonic-gate		# hack for test folks
8257c478bd9Sstevel@tonic-gate		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
8267c478bd9Sstevel@tonic-gate			X=/net/`uname -n`${CPIODIR}
8277c478bd9Sstevel@tonic-gate		else
8287c478bd9Sstevel@tonic-gate			X=${CPIODIR}
8297c478bd9Sstevel@tonic-gate		fi
8307c478bd9Sstevel@tonic-gate		echo "Archive_directory: ${X}" >${TMPDIR}/f
8319a6d9a08Sdm120769		cp ${TMPDIR}/f $(dirname $(dirname ${CPIODIR}))/.${MACH}_wgtrun
8327c478bd9Sstevel@tonic-gate		rm -f ${TMPDIR}/f
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate	else
8357c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL cpio archives ====\n" \
8367c478bd9Sstevel@tonic-gate			>> $LOGFILE
8377c478bd9Sstevel@tonic-gate	fi
8387c478bd9Sstevel@tonic-gate
8397c478bd9Sstevel@tonic-gate	#
8407c478bd9Sstevel@tonic-gate	#	Building Packages
8417c478bd9Sstevel@tonic-gate	#
8427c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
843ead1f93eSLiane Praza		if [ -d $SRC/pkg -o -d $SRC/pkgdefs ]; then
8447c478bd9Sstevel@tonic-gate			echo "\n==== Creating $LABEL packages at `date` ====\n" \
8457c478bd9Sstevel@tonic-gate				>> $LOGFILE
846ead1f93eSLiane Praza			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
8476798c3f0SMark J. Nelson			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
8486798c3f0SMark J. Nelson			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
849d8fd4470Sjg
850ead1f93eSLiane Praza			for d in pkg pkgdefs; do
8516798c3f0SMark J. Nelson				if [ ! -f "$SRC/$d/Makefile" ]; then
852ead1f93eSLiane Praza					continue
853ead1f93eSLiane Praza				fi
854ead1f93eSLiane Praza				rm -f $SRC/$d/${INSTALLOG}.out
855ead1f93eSLiane Praza				cd $SRC/$d
856ead1f93eSLiane Praza				/bin/time $MAKE -e install 2>&1 | \
857ead1f93eSLiane Praza					tee -a $SRC/$d/${INSTALLOG}.out >> $LOGFILE
858ead1f93eSLiane Praza			done
859ead1f93eSLiane Praza
860ead1f93eSLiane Praza			echo "\n==== package build errors ($LABEL) ====\n" \
861ead1f93eSLiane Praza				>> $mail_msg_file
862ead1f93eSLiane Praza
863ead1f93eSLiane Praza			for d in pkg pkgdefs; do
8646798c3f0SMark J. Nelson				if [ ! -f "$SRC/$d/Makefile" ]; then
865ead1f93eSLiane Praza					continue
866d8fd4470Sjg				fi
867d8fd4470Sjg
868ead1f93eSLiane Praza				egrep "${MAKE}|ERROR|WARNING" $SRC/$d/${INSTALLOG}.out | \
8697c478bd9Sstevel@tonic-gate					grep ':' | \
8707c478bd9Sstevel@tonic-gate					grep -v PSTAMP | \
8717c478bd9Sstevel@tonic-gate					egrep -v "Ignoring unknown host" \
8727c478bd9Sstevel@tonic-gate					>> $mail_msg_file
873ead1f93eSLiane Praza			done
874ead1f93eSLiane Praza		else
875ead1f93eSLiane Praza			#
876ead1f93eSLiane Praza			# Handle it gracefully if -p was set but there are
877ead1f93eSLiane Praza			# neither pkg nor pkgdefs directories.
878ead1f93eSLiane Praza			#
879ead1f93eSLiane Praza			echo "\n==== No $LABEL packages to build ====\n" \
880ead1f93eSLiane Praza				>> $LOGFILE
881ead1f93eSLiane Praza		fi
8827c478bd9Sstevel@tonic-gate	else
8837c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
8847c478bd9Sstevel@tonic-gate	fi
8854e5b757fSkupfer
8864e5b757fSkupfer	ROOT=$ORIGROOT
8877c478bd9Sstevel@tonic-gate}
8887c478bd9Sstevel@tonic-gate
8891fe69678Skupfer# Usage: dolint /dir y|n
8907c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
891597bd30bSMike Kupferfunction dolint {
8927c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
8931fe69678Skupfer		echo "dolint error: $1 is not a directory"
8947c478bd9Sstevel@tonic-gate		exit 1
8957c478bd9Sstevel@tonic-gate	fi
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
8981fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
8997c478bd9Sstevel@tonic-gate		exit 1
9007c478bd9Sstevel@tonic-gate	fi
9017c478bd9Sstevel@tonic-gate
9027c478bd9Sstevel@tonic-gate	lintdir=$1
9037c478bd9Sstevel@tonic-gate	dodiff=$2
9047c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
9057c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
9067c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
9074e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
9084e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
9097c478bd9Sstevel@tonic-gate
9104e5b757fSkupfer	set_debug_build_flags
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate	#
9137c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
9147c478bd9Sstevel@tonic-gate	#
9157c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate	# remove old lint.out
9187c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
9197c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
9207c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
9217c478bd9Sstevel@tonic-gate	fi
9227c478bd9Sstevel@tonic-gate
9237c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
9247c478bd9Sstevel@tonic-gate	cd $lintdir
9257c478bd9Sstevel@tonic-gate	#
9267c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
9277c478bd9Sstevel@tonic-gate	#
9287c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
929cdf0c1d5Smjnelson	    `find . \( -name SCCS -o -name .hg -o -name .svn \) \
930cdf0c1d5Smjnelson	    	-prune -o -type f -name '*.ln' -print `
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
9337c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
9347c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
9357c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
9367c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
9377c478bd9Sstevel@tonic-gate		>> $mail_msg_file
9387c478bd9Sstevel@tonic-gate
9397c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
9407c478bd9Sstevel@tonic-gate
9417c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
9427c478bd9Sstevel@tonic-gate		>>$mail_msg_file
9437c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
9467c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
9477c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
9487c478bd9Sstevel@tonic-gate	fi
9497c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
9507c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
9517c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
9527c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
9537c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
9547c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
9557c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
9567c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
9577c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
9587c478bd9Sstevel@tonic-gate	fi
9597c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
9607c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
9617c478bd9Sstevel@tonic-gate			>>$mail_msg_file
9627c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
9637c478bd9Sstevel@tonic-gate		# above
9647c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
9657c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
9667c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
9677c478bd9Sstevel@tonic-gate			>> $mail_msg_file
9687c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
9697c478bd9Sstevel@tonic-gate			>> $mail_msg_file
9707c478bd9Sstevel@tonic-gate	fi
9717c478bd9Sstevel@tonic-gate}
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gate# Install proto area from IHV build
9747c478bd9Sstevel@tonic-gate
975597bd30bSMike Kupferfunction copy_ihv_proto {
9767c478bd9Sstevel@tonic-gate
9776fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
9787c478bd9Sstevel@tonic-gate		>> $LOGFILE
9797c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
9807c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
9817c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
9827c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
9837c478bd9Sstevel@tonic-gate		fi
9846fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
9857c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
986b83ec4edSjmcp		tar cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
9877c478bd9Sstevel@tonic-gate	else
9887c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
9897c478bd9Sstevel@tonic-gate	fi
9904e5b757fSkupfer
9914e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
9924e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
9934e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
9944e5b757fSkupfer			mkdir -p $ROOT-nd
9954e5b757fSkupfer		fi
996ead1f93eSLiane Praza		# If there's a non-DEBUG version of the IHV proto area,
9974e5b757fSkupfer		# copy it, but copy something if there's not.
9984e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
9994e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
10004e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
10014e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
10024e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
10034e5b757fSkupfer			cd $IA32_IHV_ROOT
10044e5b757fSkupfer		else
10054e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
10064e5b757fSkupfer			return
10074e5b757fSkupfer		fi
1008b83ec4edSjmcp		tar cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10094e5b757fSkupfer	fi
10107c478bd9Sstevel@tonic-gate}
10117c478bd9Sstevel@tonic-gate
10127c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
10131fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
1014597bd30bSMike Kupferfunction copy_ihv_pkgs {
10157c478bd9Sstevel@tonic-gate	LABEL=$1
10167c478bd9Sstevel@tonic-gate	SUFFIX=$2
10177c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
10187c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
10197c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
10227c478bd9Sstevel@tonic-gate		>> $LOGFILE
10237c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
10247c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
1025b83ec4edSjmcp		tar cf - * | \
10267c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10277c478bd9Sstevel@tonic-gate	else
10287c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
10297c478bd9Sstevel@tonic-gate	fi
10307c478bd9Sstevel@tonic-gate
10317c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
10327c478bd9Sstevel@tonic-gate		>> $LOGFILE
10337c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
10347c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
1035b83ec4edSjmcp		tar cf - * | \
10367c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10377c478bd9Sstevel@tonic-gate	else
10387c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
10397c478bd9Sstevel@tonic-gate	fi
10407c478bd9Sstevel@tonic-gate}
10417c478bd9Sstevel@tonic-gate
10424e5b757fSkupfer#
10434e5b757fSkupfer# Build and install the onbld tools.
10444e5b757fSkupfer#
10451fe69678Skupfer# usage: build_tools DESTROOT
10464e5b757fSkupfer#
10474e5b757fSkupfer# returns non-zero status if the build was successful.
10484e5b757fSkupfer#
1049597bd30bSMike Kupferfunction build_tools {
10507c478bd9Sstevel@tonic-gate	DESTROOT=$1
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
10557c478bd9Sstevel@tonic-gate		>> $LOGFILE
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
10587c478bd9Sstevel@tonic-gate	cd ${TOOLS}
1059ead1f93eSLiane Praza	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
10607c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
10637c478bd9Sstevel@tonic-gate
10647c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
10657c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
10667c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
10677c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
10684e5b757fSkupfer	return $?
10694e5b757fSkupfer}
10704e5b757fSkupfer
10714e5b757fSkupfer#
10724e5b757fSkupfer# Set up to use locally installed tools.
10734e5b757fSkupfer#
10744e5b757fSkupfer# usage: use_tools TOOLSROOT
10754e5b757fSkupfer#
1076597bd30bSMike Kupferfunction use_tools {
10774e5b757fSkupfer	TOOLSROOT=$1
10784e5b757fSkupfer
1079*c168ccb7SMark J. Nelson	#
1080*c168ccb7SMark J. Nelson	# If we're not building ON workspace, then the TOOLSROOT
1081*c168ccb7SMark J. Nelson	# settings here are clearly ignored by the workspace
1082*c168ccb7SMark J. Nelson	# makefiles, prepending nonexistent directories to PATH is
1083*c168ccb7SMark J. Nelson	# harmless, and we clearly do not wish to override
1084*c168ccb7SMark J. Nelson	# ONBLD_TOOLS.
1085*c168ccb7SMark J. Nelson	#
1086*c168ccb7SMark J. Nelson	# If we're building an ON workspace, then the prepended PATH
1087*c168ccb7SMark J. Nelson	# elements should supercede the preexisting ONBLD_TOOLS paths,
1088*c168ccb7SMark J. Nelson	# and we want to override ONBLD_TOOLS to catch the tools that
1089*c168ccb7SMark J. Nelson	# don't have specific path env vars here.
1090*c168ccb7SMark J. Nelson	#
1091*c168ccb7SMark J. Nelson	# So the only conditional behavior is overriding ONBLD_TOOLS,
1092*c168ccb7SMark J. Nelson	# and we check for "an ON workspace" by looking for
1093*c168ccb7SMark J. Nelson	# ${TOOLSROOT}/opt/onbld.
1094*c168ccb7SMark J. Nelson	#
1095*c168ccb7SMark J. Nelson
10964e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
10977c478bd9Sstevel@tonic-gate	export STABS
10984e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
10997c478bd9Sstevel@tonic-gate	export CTFSTABS
11004e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
11017c478bd9Sstevel@tonic-gate	export GENOFFSETS
11027c478bd9Sstevel@tonic-gate
11034e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
11047c478bd9Sstevel@tonic-gate	export CTFCONVERT
11054e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
11067c478bd9Sstevel@tonic-gate	export CTFMERGE
11077c478bd9Sstevel@tonic-gate
11084e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
11097c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
11104e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
11117c478bd9Sstevel@tonic-gate	export CTFFINDMOD
11127c478bd9Sstevel@tonic-gate
11137c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
11144e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
11157c478bd9Sstevel@tonic-gate	else
11164e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
11177c478bd9Sstevel@tonic-gate	fi
11187c478bd9Sstevel@tonic-gate	export ELFSIGN
11197c478bd9Sstevel@tonic-gate
1120*c168ccb7SMark J. Nelson	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
11214e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
11227c478bd9Sstevel@tonic-gate	export PATH
11237c478bd9Sstevel@tonic-gate
1124*c168ccb7SMark J. Nelson	if [ -d "${TOOLSROOT}/opt/onbld" ]; then
1125b06f2c55SMark J. Nelson		ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
11261d9a8b8dSDan Mick		export ONBLD_TOOLS
1127*c168ccb7SMark J. Nelson	fi
11281d9a8b8dSDan Mick
11297c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
11307c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
11317c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
11327c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
11337c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
11347c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
11357c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
11367c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
11377c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
11381d9a8b8dSDan Mick	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
11397c478bd9Sstevel@tonic-gate}
11407c478bd9Sstevel@tonic-gate
1141597bd30bSMike Kupferfunction staffer {
11427c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
11437c478bd9Sstevel@tonic-gate		"$@"
11447c478bd9Sstevel@tonic-gate	else
11457c478bd9Sstevel@tonic-gate		arg="\"$1\""
11467c478bd9Sstevel@tonic-gate		shift
11477c478bd9Sstevel@tonic-gate		for i
11487c478bd9Sstevel@tonic-gate		do
11497c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
11507c478bd9Sstevel@tonic-gate		done
11517c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
11527c478bd9Sstevel@tonic-gate	fi
11537c478bd9Sstevel@tonic-gate}
11547c478bd9Sstevel@tonic-gate
1155085d331dSkupfer#
1156085d331dSkupfer# Verify that the closed tree is present if it needs to be.
1157085d331dSkupfer# Sets CLOSED_IS_PRESENT for future use.
1158085d331dSkupfer#
1159597bd30bSMike Kupferfunction check_closed_tree {
1160085d331dSkupfer	if [ -z "$CLOSED_IS_PRESENT" ]; then
11615c53ea7aSmjnelson		if [ -d $CODEMGR_WS/usr/closed ]; then
1162085d331dSkupfer			CLOSED_IS_PRESENT="yes"
1163085d331dSkupfer		else
1164085d331dSkupfer			CLOSED_IS_PRESENT="no"
1165085d331dSkupfer		fi
1166085d331dSkupfer		export CLOSED_IS_PRESENT
1167085d331dSkupfer	fi
1168085d331dSkupfer	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
1169085d331dSkupfer		#
1170085d331dSkupfer		# If it's an old (pre-split) tree or an empty
1171085d331dSkupfer		# workspace, don't complain.
1172085d331dSkupfer		#
1173085d331dSkupfer		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
1174085d331dSkupfer			echo "If the closed sources are not present," \
1175085d331dSkupfer			    "ON_CLOSED_BINS"
1176085d331dSkupfer			echo "must point to the closed binaries tree."
1177cdf0c1d5Smjnelson			build_ok=n
1178085d331dSkupfer			exit 1
1179085d331dSkupfer		fi
1180085d331dSkupfer	fi
1181085d331dSkupfer}
11827c478bd9Sstevel@tonic-gate
1183597bd30bSMike Kupferfunction obsolete_build {
1184d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
1185d77e7149Ssommerfe}
1186d77e7149Ssommerfe
11874e5b757fSkupfer#
11884e5b757fSkupfer# wrapper over wsdiff.
11894e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
11904e5b757fSkupfer#
1191597bd30bSMike Kupferfunction do_wsdiff {
11924e5b757fSkupfer	label=$1
11934e5b757fSkupfer	oldproto=$2
11944e5b757fSkupfer	newproto=$3
11954e5b757fSkupfer
11964e5b757fSkupfer	echo "\n==== Objects that differ since last build ($label) ====\n" | \
11974e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
11984e5b757fSkupfer
11994e5b757fSkupfer	wsdiff="wsdiff"
12004e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
12014e5b757fSkupfer
12024e5b757fSkupfer	$wsdiff -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
12034e5b757fSkupfer		    tee -a $LOGFILE >> $mail_msg_file
12044e5b757fSkupfer}
12054e5b757fSkupfer
12064e5b757fSkupfer#
1207ead1f93eSLiane Praza# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
12084e5b757fSkupfer# together.
12094e5b757fSkupfer#
12104e5b757fSkupfer
1211597bd30bSMike Kupferfunction set_non_debug_build_flags {
12124e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
12134e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
12144e5b757fSkupfer	unset EXTRA_OPTIONS
12154e5b757fSkupfer	unset EXTRA_CFLAGS
12164e5b757fSkupfer}
12174e5b757fSkupfer
1218597bd30bSMike Kupferfunction set_debug_build_flags {
12194e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
12204e5b757fSkupfer	unset RELEASE_BUILD
12214e5b757fSkupfer	unset EXTRA_OPTIONS
12224e5b757fSkupfer	unset EXTRA_CFLAGS
12234e5b757fSkupfer}
12244e5b757fSkupfer
1225d77e7149Ssommerfe
12267c478bd9Sstevel@tonic-gateMACH=`uname -p`
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
12297c478bd9Sstevel@tonic-gate	OPTHOME=/opt
12307c478bd9Sstevel@tonic-gate	export OPTHOME
12317c478bd9Sstevel@tonic-gatefi
12327c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
12337c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
12347c478bd9Sstevel@tonic-gate	export TEAMWARE
12357c478bd9Sstevel@tonic-gatefi
12367c478bd9Sstevel@tonic-gate
12371fe69678SkupferUSAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H|O ] <env_file>
12387c478bd9Sstevel@tonic-gate
12397c478bd9Sstevel@tonic-gateWhere:
1240d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
12417c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
12427c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
12437c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
12447c478bd9Sstevel@tonic-gate		E - build exportable source
12457c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
12467c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
12471fe69678Skupfer		O - build (only) open source
12487c478bd9Sstevel@tonic-gate
12497c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
12507c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
12517c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
12527c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
12537c478bd9Sstevel@tonic-gate
12547c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
12557c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
12567c478bd9Sstevel@tonic-gate
12577c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
12587c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
12597c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
12607c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
12613c6aa570SMark J. Nelson	-G	gate keeper default group of options (-au)
12627c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
12637c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
12647c478bd9Sstevel@tonic-gate	-N	do not run protocmp
12654e5b757fSkupfer	-O	generate OpenSolaris deliverables
12667c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
12677c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
12687c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
126904a42e3eSszhou	-X	copy x86 IHV proto area
12707c478bd9Sstevel@tonic-gate	-a	create cpio archives
12717c478bd9Sstevel@tonic-gate	-f	find unreferenced files
12727c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
12737c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
12747c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
12757c478bd9Sstevel@tonic-gate	-n      do not do a bringover
12767c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
12777c478bd9Sstevel@tonic-gate	-p	create packages
12787c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
12797c478bd9Sstevel@tonic-gate	-t	build and use the tools in $SRC/tools
12807c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
12817c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
128296ccc8cbSesaxe	-w	report on differences between previous and current proto areas
12837c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
12847c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
12857c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
12867c478bd9Sstevel@tonic-gate		E - build exportable source
12877c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
12887c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
12891fe69678Skupfer		O - build (only) open source
12907c478bd9Sstevel@tonic-gate'
12917c478bd9Sstevel@tonic-gate#
12927c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
12937c478bd9Sstevel@tonic-gate#
12947c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
12951c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
12967c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
12977c478bd9Sstevel@tonic-gate#
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
13007c478bd9Sstevel@tonic-gateA_FLAG=n
13017c478bd9Sstevel@tonic-gatea_FLAG=n
13027c478bd9Sstevel@tonic-gateC_FLAG=n
13036c3c9007SstevelD_FLAG=n
13047c478bd9Sstevel@tonic-gateF_FLAG=n
13057c478bd9Sstevel@tonic-gatef_FLAG=n
13067c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
13077c478bd9Sstevel@tonic-gatel_FLAG=n
13086c3c9007SstevelM_FLAG=n
13097c478bd9Sstevel@tonic-gatem_FLAG=n
13106c3c9007SstevelN_FLAG=n
13116c3c9007Ssteveln_FLAG=n
13124e5b757fSkupferO_FLAG=n
13136c3c9007Sstevelo_FLAG=n
13146c3c9007SstevelP_FLAG=n
13157c478bd9Sstevel@tonic-gatep_FLAG=n
13167c478bd9Sstevel@tonic-gater_FLAG=n
13176c3c9007SstevelT_FLAG=n
1318fd7cef36Ssuhat_FLAG=y
13197c478bd9Sstevel@tonic-gateU_FLAG=n
13206c3c9007Sstevelu_FLAG=n
13217c478bd9Sstevel@tonic-gateV_FLAG=n
13227c478bd9Sstevel@tonic-gateW_FLAG=n
13236c3c9007Sstevelw_FLAG=n
13246c3c9007SstevelX_FLAG=n
13256c3c9007Sstevelz_FLAG=n
13267c478bd9Sstevel@tonic-gateSD_FLAG=n
13276c3c9007SstevelSE_FLAG=n
13287c478bd9Sstevel@tonic-gateSH_FLAG=n
13291fe69678SkupferSO_FLAG=n
13307c478bd9Sstevel@tonic-gate#
13317c478bd9Sstevel@tonic-gateXMOD_OPT=
13327c478bd9Sstevel@tonic-gate#
13337c478bd9Sstevel@tonic-gatebuild_ok=y
13341fe69678Skupfer
1335597bd30bSMike Kupferfunction is_source_build {
13361fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
13371fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
13381fe69678Skupfer	return $?
13391fe69678Skupfer}
13401fe69678Skupfer
13417c478bd9Sstevel@tonic-gate#
13427c478bd9Sstevel@tonic-gate# examine arguments
13437c478bd9Sstevel@tonic-gate#
13447c478bd9Sstevel@tonic-gate
13451fe69678Skupfer#
13461fe69678Skupfer# single function for setting -S flag and doing error checking.
13471fe69678Skupfer# usage: set_S_flag <type>
13481fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
13491fe69678Skupfer#
1350597bd30bSMike Kupferfunction set_S_flag {
13511fe69678Skupfer	if is_source_build; then
13521fe69678Skupfer		echo "Can only build one source variant at a time."
13531fe69678Skupfer		exit 1
13541fe69678Skupfer	fi
13551fe69678Skupfer	if [ "$1" = "E" ]; then
13561fe69678Skupfer		SE_FLAG=y
13571fe69678Skupfer	elif [ "$1" = "D" ]; then
13581fe69678Skupfer		SD_FLAG=y
13591fe69678Skupfer	elif [ "$1" = "H" ]; then
13601fe69678Skupfer		SH_FLAG=y
13611fe69678Skupfer	elif [ "$1" = "O" ]; then
13621fe69678Skupfer		SO_FLAG=y
13631fe69678Skupfer	else
13641fe69678Skupfer		echo "$USAGE"
13651fe69678Skupfer		exit 1
13661fe69678Skupfer	fi
13671fe69678Skupfer}
13681fe69678Skupfer
13697c478bd9Sstevel@tonic-gateOPTIND=1
13706c3c9007Sstevelwhile getopts inS:tV: FLAG
13717c478bd9Sstevel@tonic-gatedo
13727c478bd9Sstevel@tonic-gate	case $FLAG in
13737c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
13747c478bd9Sstevel@tonic-gate		;;
13757c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
13767c478bd9Sstevel@tonic-gate		;;
13777c478bd9Sstevel@tonic-gate	  S )
13781fe69678Skupfer		set_S_flag $OPTARG
13797c478bd9Sstevel@tonic-gate		;;
1380fd7cef36Ssuha	 +t )	t_FLAG=n
13817c478bd9Sstevel@tonic-gate		;;
13826c3c9007Sstevel	  V )	V_FLAG=y
13836c3c9007Sstevel		V_ARG="$OPTARG"
13846c3c9007Sstevel		;;
13857c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
13867c478bd9Sstevel@tonic-gate		exit 1
13877c478bd9Sstevel@tonic-gate		;;
13887c478bd9Sstevel@tonic-gate	esac
13897c478bd9Sstevel@tonic-gatedone
13907c478bd9Sstevel@tonic-gate
13917c478bd9Sstevel@tonic-gate# correct argument count after options
13927c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
13937c478bd9Sstevel@tonic-gate
13947c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
13957c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
13967c478bd9Sstevel@tonic-gate	echo "$USAGE"
13977c478bd9Sstevel@tonic-gate	exit 1
13987c478bd9Sstevel@tonic-gatefi
13997c478bd9Sstevel@tonic-gate
14007c478bd9Sstevel@tonic-gate# check if user is running nightly as root
14017c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
14027c478bd9Sstevel@tonic-gate# when root invokes nightly.
14037c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
14047c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
14057c478bd9Sstevel@tonic-gate
14067c478bd9Sstevel@tonic-gate#
14077c478bd9Sstevel@tonic-gate# force locale to C
14087c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
14097c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
14107c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
14117c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
14127c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
14137c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
14147c478bd9Sstevel@tonic-gate
14157c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
14167c478bd9Sstevel@tonic-gateunset LD_OPTIONS
14177c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
14187c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
14197c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
14207c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
14217c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
14227c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
14237c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
14247c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
14257c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
14267c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
14277c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
14287c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
14297c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
14307c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
14317c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
14327c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
14337c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
14347c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
14357c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
14367c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
14377c478bd9Sstevel@tonic-gate
14387c478bd9Sstevel@tonic-gateunset CONFIG
14397c478bd9Sstevel@tonic-gateunset GROUP
14407c478bd9Sstevel@tonic-gateunset OWNER
14417c478bd9Sstevel@tonic-gateunset REMOTE
14427c478bd9Sstevel@tonic-gateunset ENV
14437c478bd9Sstevel@tonic-gateunset ARCH
14447c478bd9Sstevel@tonic-gateunset CLASSPATH
14457c478bd9Sstevel@tonic-gateunset NAME
14467c478bd9Sstevel@tonic-gate
14477c478bd9Sstevel@tonic-gate#
1448ead1f93eSLiane Praza# To get ONBLD_TOOLS from the environment, it must come from the env file.
1449ead1f93eSLiane Praza# If it comes interactively, it is generally TOOLS_PROTO, which will be
1450ead1f93eSLiane Praza# clobbered before the compiler version checks, which will therefore fail.
1451ead1f93eSLiane Praza#
1452ead1f93eSLiane Prazaunset ONBLD_TOOLS
1453ead1f93eSLiane Praza
1454ead1f93eSLiane Praza#
14557c478bd9Sstevel@tonic-gate#	Setup environmental variables
14567c478bd9Sstevel@tonic-gate#
145747703246Ssommerfeif [ -f /etc/nightly.conf ]; then
145847703246Ssommerfe	. /etc/nightly.conf
145947703246Ssommerfefi
146047703246Ssommerfe
14617c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
14627c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
14637c478bd9Sstevel@tonic-gate		. $1
14647c478bd9Sstevel@tonic-gate	else
14657c478bd9Sstevel@tonic-gate		. ./$1
14667c478bd9Sstevel@tonic-gate	fi
14677c478bd9Sstevel@tonic-gateelse
14687c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
14697c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
14707c478bd9Sstevel@tonic-gate	else
14717c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
14727c478bd9Sstevel@tonic-gate		exit 1
14737c478bd9Sstevel@tonic-gate	fi
14747c478bd9Sstevel@tonic-gatefi
14757c478bd9Sstevel@tonic-gate
14761fe69678Skupfer# contents of stdenv.sh inserted after next line:
14771fe69678Skupfer# STDENV_START
14781fe69678Skupfer# STDENV_END
14791fe69678Skupfer
14807c478bd9Sstevel@tonic-gate#
14817c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
14827c478bd9Sstevel@tonic-gate#
14837c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
14847c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
14857c478bd9Sstevel@tonic-gateelse
14867c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
14877c478bd9Sstevel@tonic-gatefi
14887c478bd9Sstevel@tonic-gate
14897c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
14907c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
14917c478bd9Sstevel@tonic-gate
14927c478bd9Sstevel@tonic-gate#
14937c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
14947c478bd9Sstevel@tonic-gate#
14957c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
14967c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
14977c478bd9Sstevel@tonic-gatefi
14987c478bd9Sstevel@tonic-gate
14997c478bd9Sstevel@tonic-gate#
15007c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
15017c478bd9Sstevel@tonic-gate#
15027c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
15037c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
15047c478bd9Sstevel@tonic-gatefi
15057c478bd9Sstevel@tonic-gate
15067c478bd9Sstevel@tonic-gate#
1507cdf0c1d5Smjnelson# If CLOSED_BRINGOVER_WS was not specified, let it default to CLOSED_CLONE_WS
1508cdf0c1d5Smjnelson#
1509cdf0c1d5Smjnelsonif [ "$CLOSED_BRINGOVER_WS" = "" ]; then
1510cdf0c1d5Smjnelson	CLOSED_BRINGOVER_WS=$CLOSED_CLONE_WS
1511cdf0c1d5Smjnelsonfi
1512cdf0c1d5Smjnelson
1513cdf0c1d5Smjnelson#
1514fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1515a5c06a9eSmike_s#
1516a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1517fb23a357Skupfer	BRINGOVER_FILES="usr"
1518a5c06a9eSmike_sfi
1519a5c06a9eSmike_s
1520fb9f9b97Skupfer#
1521fb9f9b97Skupfer# If the closed sources are not present, the closed binaries must be
1522fb9f9b97Skupfer# present for the build to succeed.  If there's no pointer to the
1523fb9f9b97Skupfer# closed binaries, flag that now, rather than forcing the user to wait
1524fb9f9b97Skupfer# a couple hours (or more) to find out.
1525fb9f9b97Skupfer#
1526085d331dSkupferorig_closed_is_present="$CLOSED_IS_PRESENT"
1527085d331dSkupfercheck_closed_tree
1528fb9f9b97Skupfer
1529a5c06a9eSmike_s#
15307c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1531b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
15327c478bd9Sstevel@tonic-gate#
1533d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
15347c478bd9Sstevel@tonic-gateOPTIND=1
1535ead1f93eSLiane Prazawhile getopts AaBCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
15367c478bd9Sstevel@tonic-gatedo
15377c478bd9Sstevel@tonic-gate	case $FLAG in
15387c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
15397c478bd9Sstevel@tonic-gate		;;
15406c3c9007Sstevel	  a )	a_FLAG=y
15416c3c9007Sstevel		;;
15427c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
15437c478bd9Sstevel@tonic-gate		;; # old version of D
15446c3c9007Sstevel	  C )	C_FLAG=y
15457c478bd9Sstevel@tonic-gate		;;
15467c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
15477c478bd9Sstevel@tonic-gate		;;
15486c3c9007Sstevel	  F )	F_FLAG=y
15497c478bd9Sstevel@tonic-gate		;;
15506c3c9007Sstevel	  f )	f_FLAG=y
15517c478bd9Sstevel@tonic-gate		;;
1552ead1f93eSLiane Praza	  G )   a_FLAG=y
15537c478bd9Sstevel@tonic-gate		u_FLAG=y
15547c478bd9Sstevel@tonic-gate		;;
15557c478bd9Sstevel@tonic-gate	  I )	a_FLAG=y
15567c478bd9Sstevel@tonic-gate		m_FLAG=y
15577c478bd9Sstevel@tonic-gate		p_FLAG=y
15587c478bd9Sstevel@tonic-gate		u_FLAG=y
15597c478bd9Sstevel@tonic-gate		;;
15607c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
15617c478bd9Sstevel@tonic-gate		;;
15626c3c9007Sstevel	  l )	l_FLAG=y
15636c3c9007Sstevel		;;
15646c3c9007Sstevel	  M )	M_FLAG=y
15656c3c9007Sstevel		;;
15666c3c9007Sstevel	  m )	m_FLAG=y
15676c3c9007Sstevel		;;
15686c3c9007Sstevel	  N )	N_FLAG=y
15696c3c9007Sstevel		;;
15707c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
15717c478bd9Sstevel@tonic-gate		;;
15724e5b757fSkupfer	  O )	O_FLAG=y
15734e5b757fSkupfer		;;
15747c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
15757c478bd9Sstevel@tonic-gate		;;
15766c3c9007Sstevel	  P )	P_FLAG=y
15776c3c9007Sstevel		;; # obsolete
15787c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
15797c478bd9Sstevel@tonic-gate		;;
15806c3c9007Sstevel	  R )	m_FLAG=y
15816c3c9007Sstevel		p_FLAG=y
15826c3c9007Sstevel		;;
15837c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
15847c478bd9Sstevel@tonic-gate		;;
15856c3c9007Sstevel	  S )
15866c3c9007Sstevel		set_S_flag $OPTARG
15876c3c9007Sstevel		;;
15886c3c9007Sstevel	  T )	T_FLAG=y
15896c3c9007Sstevel		;; # obsolete
1590fd7cef36Ssuha	 +t )	t_FLAG=n
15917c478bd9Sstevel@tonic-gate		;;
15926798c3f0SMark J. Nelson	  U )   if [ -z "${PARENT_ROOT}" ]; then
15937c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
15947c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
15957c478bd9Sstevel@tonic-gate			exit 1
15967c478bd9Sstevel@tonic-gate		fi
15976798c3f0SMark J. Nelson		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
15986798c3f0SMark J. Nelson		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
15996798c3f0SMark J. Nelson			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
1600ead1f93eSLiane Praza		fi
16017c478bd9Sstevel@tonic-gate		U_FLAG=y
16027c478bd9Sstevel@tonic-gate		;;
16036c3c9007Sstevel	  u )	u_FLAG=y
16047c478bd9Sstevel@tonic-gate		;;
16057c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
16067c478bd9Sstevel@tonic-gate		;;
16076c3c9007Sstevel
16086c3c9007Sstevel	  w )	w_FLAG=y
16097c478bd9Sstevel@tonic-gate		;;
16107c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
16117c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
16127c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
16137c478bd9Sstevel@tonic-gate			X_FLAG=y
16147c478bd9Sstevel@tonic-gate		fi
16157c478bd9Sstevel@tonic-gate		;;
16166c3c9007Sstevel	  x )	XMOD_OPT="-x"
16176c3c9007Sstevel		;;
16186c3c9007Sstevel	  z )	z_FLAG=y
16196c3c9007Sstevel		;;
16207c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
16217c478bd9Sstevel@tonic-gate		exit 1
16227c478bd9Sstevel@tonic-gate		;;
16237c478bd9Sstevel@tonic-gate	esac
16247c478bd9Sstevel@tonic-gatedone
16257c478bd9Sstevel@tonic-gate
16267c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
16277c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
16287c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
16297c478bd9Sstevel@tonic-gate		exit 1
16307c478bd9Sstevel@tonic-gate	fi
16317c478bd9Sstevel@tonic-gate
16327c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
16337c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
16347c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
16357c478bd9Sstevel@tonic-gate		export STAFFER
16367c478bd9Sstevel@tonic-gate	fi
16377c478bd9Sstevel@tonic-gatefi
16387c478bd9Sstevel@tonic-gate
16397c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
16407c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
16417c478bd9Sstevel@tonic-gate	export MAILTO
16427c478bd9Sstevel@tonic-gatefi
16437c478bd9Sstevel@tonic-gate
1644*c168ccb7SMark J. NelsonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
1645*c168ccb7SMark J. NelsonPATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
1646*c168ccb7SMark J. NelsonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
16477c478bd9Sstevel@tonic-gateexport PATH
16487c478bd9Sstevel@tonic-gate
1649fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1650fb23a357Skupferrelsrcdirs="."
16515c53ea7aSmjnelsonif [[ -d $CODEMGR_WS/usr/closed && "$CLOSED_IS_PRESENT" != no ]]; then
1652fb9f9b97Skupfer	relsrcdirs="$relsrcdirs ../closed"
1653fb9f9b97Skupferfi
1654fb23a357Skupferabssrcdirs=""
1655fb23a357Skupferfor d in $relsrcdirs; do
1656fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1657fb23a357Skupferdone
1658fb23a357Skupfer
16597c478bd9Sstevel@tonic-gateunset CH
16607c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
16617c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
16627c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
16637c478bd9Sstevel@tonic-gate# the old ones still do.
16647c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
16657c478bd9Sstevel@tonic-gate	CH=
16667c478bd9Sstevel@tonic-gate	export CH
16677c478bd9Sstevel@tonic-gateelse
16687c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
16697c478bd9Sstevel@tonic-gatefi
16707c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
167148bc00d6Sjmcp# have we set RELEASE_DATE in our env file?
167248bc00d6Sjmcpif [ -z "$RELEASE_DATE" ]; then
167348bc00d6Sjmcp	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
167448bc00d6Sjmcpfi
167548bc00d6SjmcpBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
167648bc00d6SjmcpBASEWSDIR=$(basename $CODEMGR_WS)
167748bc00d6SjmcpDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
16787c478bd9Sstevel@tonic-gate
167948bc00d6Sjmcp# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
168048bc00d6Sjmcp# by avoiding repeated shell invocations to evaluate Makefile.master definitions.
16813c6aa570SMark J. Nelson# we export o_FLAG and X_FLAG for use by makebfu, and by usr/src/pkg/Makefile
168248bc00d6Sjmcpexport o_FLAG X_FLAG POUND_SIGN RELEASE_DATE DEV_CM
16837c478bd9Sstevel@tonic-gate
16847c478bd9Sstevel@tonic-gatemaketype="distributed"
16857c478bd9Sstevel@tonic-gateMAKE=dmake
16867c478bd9Sstevel@tonic-gate# get the dmake version string alone
16877c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
16887c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
16897c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
16907c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
16917c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
16927c478bd9Sstevel@tonic-gate# extract the second (or final) integer
16937c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
16947c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
16957c478bd9Sstevel@tonic-gate# extract the first integer
16967c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
16977c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
16987c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
16997c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
17007c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
17017c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
17027c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
17037c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
17047c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
17057c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
17067c478bd9Sstevel@tonic-gate		exit 1
17077c478bd9Sstevel@tonic-gate	fi
17087c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
17097c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
17107c478bd9Sstevel@tonic-gate	cat <<EOF
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
17137c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
17147c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
17157c478bd9Sstevel@tonic-gate
17167c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
17177c478bd9Sstevel@tonic-gateEOF
17187c478bd9Sstevel@tonic-gate	exit 1
17197c478bd9Sstevel@tonic-gatefi
17207c478bd9Sstevel@tonic-gateexport PATH
17217c478bd9Sstevel@tonic-gateexport MAKE
17227c478bd9Sstevel@tonic-gate
1723597bd30bSMike Kupfer#
1724597bd30bSMike Kupfer# Make sure the crypto tarball is available if it's needed.
1725597bd30bSMike Kupfer#
1726597bd30bSMike Kupfer
1727ead1f93eSLiane Praza# Echo the non-DEBUG name corresponding to the given crypto tarball path.
1728597bd30bSMike Kupferfunction ndcrypto {
1729597bd30bSMike Kupfer	typeset dir file
1730597bd30bSMike Kupfer
1731597bd30bSMike Kupfer	if [ -z "$1" ]; then
1732597bd30bSMike Kupfer		echo ""
1733597bd30bSMike Kupfer		return
1734597bd30bSMike Kupfer	fi
1735597bd30bSMike Kupfer
1736597bd30bSMike Kupfer	dir=$(dirname "$1")
1737597bd30bSMike Kupfer	file=$(basename "$1" ".$MACH.tar.bz2")
1738597bd30bSMike Kupfer
1739597bd30bSMike Kupfer	echo "$dir/$file-nd.$MACH.tar.bz2"
1740597bd30bSMike Kupfer}
1741597bd30bSMike Kupfer
1742597bd30bSMike Kupfer# Return 0 (success) if the required crypto tarball(s) are present.
1743597bd30bSMike Kupferfunction crypto_is_present {
1744597bd30bSMike Kupfer	if [ -z "$ON_CRYPTO_BINS" ]; then
1745597bd30bSMike Kupfer		echo "ON_CRYPTO_BINS is null or not set."
1746597bd30bSMike Kupfer		return 1
1747597bd30bSMike Kupfer	fi
1748597bd30bSMike Kupfer	if [ "$D_FLAG" = y ]; then
1749597bd30bSMike Kupfer		if [ ! -f "$ON_CRYPTO_BINS" ]; then
1750597bd30bSMike Kupfer			echo "DEBUG crypto tarball is unavailable."
1751597bd30bSMike Kupfer			return 1
1752597bd30bSMike Kupfer		fi
1753597bd30bSMike Kupfer	fi
1754597bd30bSMike Kupfer	if [ "$F_FLAG" = n ]; then
1755597bd30bSMike Kupfer		if [ ! -f $(ndcrypto "$ON_CRYPTO_BINS") ]; then
1756597bd30bSMike Kupfer			echo "Non-DEBUG crypto tarball is unavailable."
1757597bd30bSMike Kupfer			return 1
1758597bd30bSMike Kupfer		fi
1759597bd30bSMike Kupfer	fi
1760597bd30bSMike Kupfer
1761597bd30bSMike Kupfer	return 0
1762597bd30bSMike Kupfer}
1763597bd30bSMike Kupfer
1764597bd30bSMike Kupfer#
1765597bd30bSMike Kupfer# Canonicalize ON_CRYPTO_BINS, just in case it was set to the -nd
1766597bd30bSMike Kupfer# tarball.
1767597bd30bSMike Kupfer#
1768597bd30bSMike Kupferif [ -n "$ON_CRYPTO_BINS" ]; then
1769597bd30bSMike Kupfer	export ON_CRYPTO_BINS=$(echo "$ON_CRYPTO_BINS" |
1770597bd30bSMike Kupfer	    sed -e s/-nd.$MACH.tar/.$MACH.tar/)
1771597bd30bSMike Kupferfi
1772597bd30bSMike Kupfer
1773597bd30bSMike Kupferif [[ "$O_FLAG" = y && -z "$CODESIGN_USER" ]]; then
1774597bd30bSMike Kupfer	if ! crypto_is_present; then
1775597bd30bSMike Kupfer		echo "OpenSolaris deliveries need signed crypto."
1776597bd30bSMike Kupfer		exit 1
1777597bd30bSMike Kupfer	fi
1778597bd30bSMike Kupferfi
1779597bd30bSMike Kupfer
1780b83ec4edSjmcpif [[ "$O_FLAG" = y ]]; then
1781b83ec4edSjmcp	export TONICBUILD=""
1782b83ec4edSjmcpelse
1783b83ec4edSjmcp	export TONICBUILD="#"
1784b83ec4edSjmcpfi
1785b83ec4edSjmcp
17867c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
17877c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
17887c478bd9Sstevel@tonic-gate	export PATH
17897c478bd9Sstevel@tonic-gatefi
17907c478bd9Sstevel@tonic-gate
179199e4a37bSWill Fiveashhostname=$(uname -n)
179299e4a37bSWill Fiveashif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
179399e4a37bSWill Fiveashthen
179499e4a37bSWill Fiveash	maxjobs=
179599e4a37bSWill Fiveash	if [[ -f $HOME/.make.machines ]]
179699e4a37bSWill Fiveash	then
179799e4a37bSWill Fiveash		# Note: there is a hard tab and space character in the []s
179899e4a37bSWill Fiveash		# below.
179999e4a37bSWill Fiveash		egrep -i "^[ 	]*$hostname[ 	\.]" \
180099e4a37bSWill Fiveash			$HOME/.make.machines | read host jobs
180199e4a37bSWill Fiveash		maxjobs=${jobs##*=}
18027c478bd9Sstevel@tonic-gate	fi
180399e4a37bSWill Fiveash
180499e4a37bSWill Fiveash	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
180599e4a37bSWill Fiveash	then
180699e4a37bSWill Fiveash		# default
180799e4a37bSWill Fiveash		maxjobs=4
18087c478bd9Sstevel@tonic-gate	fi
180999e4a37bSWill Fiveash
181099e4a37bSWill Fiveash	export DMAKE_MAX_JOBS=$maxjobs
181199e4a37bSWill Fiveashfi
181299e4a37bSWill Fiveash
18137c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
18147c478bd9Sstevel@tonic-gateexport DMAKE_MODE
18157c478bd9Sstevel@tonic-gate
18167c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
18177c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
18187c478bd9Sstevel@tonic-gate	exit 1
18197c478bd9Sstevel@tonic-gatefi
18207c478bd9Sstevel@tonic-gate
18217c478bd9Sstevel@tonic-gate#
18227c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
18237c478bd9Sstevel@tonic-gate#
18247c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
18257c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
18267c478bd9Sstevel@tonic-gatefi
18277c478bd9Sstevel@tonic-gate
182804a42e3eSszhou#
182904a42e3eSszhou# Check for IHV root for copying ihv proto area
183004a42e3eSszhou#
183104a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
183204a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
183304a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
183404a42e3eSszhou		args_ok=n
183504a42e3eSszhou        fi
183604a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
183704a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
183804a42e3eSszhou                args_ok=n
183904a42e3eSszhou        fi
18406fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
18416fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
18426fec3625Sdduvall		args_ok=n
18436fec3625Sdduvall        fi
18446fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
18456fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
18466fec3625Sdduvall                args_ok=n
18476fec3625Sdduvall        fi
184804a42e3eSszhoufi
184904a42e3eSszhou
18507c478bd9Sstevel@tonic-gate# Append source version
18517c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
18527c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
18537c478bd9Sstevel@tonic-gatefi
18547c478bd9Sstevel@tonic-gate
18557c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
18567c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
18577c478bd9Sstevel@tonic-gatefi
18587c478bd9Sstevel@tonic-gate
18597c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
18607c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
18617c478bd9Sstevel@tonic-gatefi
18627c478bd9Sstevel@tonic-gate
18631fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
18641fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
18651fe69678Skupferfi
18661fe69678Skupfer
18677c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
18687c478bd9Sstevel@tonic-gateexport TMPDIR
18697c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
18707c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
187185f46905SMark J. Nelsonchmod 777 $TMPDIR
18727c478bd9Sstevel@tonic-gate
18737c478bd9Sstevel@tonic-gate#
18747c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
18757c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
18767c478bd9Sstevel@tonic-gate# have the fix for 6271754
18777c478bd9Sstevel@tonic-gate#
18787c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
18797c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
18807c478bd9Sstevel@tonic-gate
1881ead1f93eSLiane Praza#
1882ead1f93eSLiane Praza# Tools should only be built non-DEBUG.  Keep track of the tools proto
1883ead1f93eSLiane Praza# area path relative to $TOOLS, because the latter changes in an
1884ead1f93eSLiane Praza# export build.
1885ead1f93eSLiane Praza#
1886ead1f93eSLiane Praza# TOOLS_PROTO is included below for builds other than usr/src/tools
1887ead1f93eSLiane Praza# that look for this location.  For usr/src/tools, this will be
1888ead1f93eSLiane Praza# overridden on the $MAKE command line in build_tools().
1889ead1f93eSLiane Praza#
18907c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
1891ead1f93eSLiane PrazaTOOLS_PROTO_REL=proto/root_${MACH}-nd
1892ead1f93eSLiane PrazaTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
1893ead1f93eSLiane Praza
18947c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
18957c478bd9Sstevel@tonic-gate
18967c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
18977c478bd9Sstevel@tonic-gate# fails to start correctly
1898597bd30bSMike Kupferfunction newdir {
18997c478bd9Sstevel@tonic-gate	dir=$1
19007c478bd9Sstevel@tonic-gate	toadd=
19017c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
19027c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
19037c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
19047c478bd9Sstevel@tonic-gate	done
19057c478bd9Sstevel@tonic-gate	torm=
19067c478bd9Sstevel@tonic-gate	newlist=
19077c478bd9Sstevel@tonic-gate	for dir in $toadd; do
19087c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
19097c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
19107c478bd9Sstevel@tonic-gate			torm="$dir $torm"
19117c478bd9Sstevel@tonic-gate		else
19127c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
19137c478bd9Sstevel@tonic-gate			return 1
19147c478bd9Sstevel@tonic-gate		fi
19157c478bd9Sstevel@tonic-gate	done
19167c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
19177c478bd9Sstevel@tonic-gate	return 0
19187c478bd9Sstevel@tonic-gate}
19197c478bd9Sstevel@tonic-gatenewdirlist=
19207c478bd9Sstevel@tonic-gate
19217c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
19227c478bd9Sstevel@tonic-gate
19237c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
19247c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
19257c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
19267c478bd9Sstevel@tonic-gate# built from this immediate source.
19277c478bd9Sstevel@tonic-gateENVLDLIBS1=
19287c478bd9Sstevel@tonic-gateENVLDLIBS2=
19297c478bd9Sstevel@tonic-gateENVLDLIBS3=
19307c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
19317c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
19327c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
19337c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
19347c478bd9Sstevel@tonic-gatePARENT_ROOT=
19357c478bd9Sstevel@tonic-gate
19367c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
19377c478bd9Sstevel@tonic-gate	PARENT_ROOT
19387c478bd9Sstevel@tonic-gate
19397c478bd9Sstevel@tonic-gateCPIODIR_ORIG=$CPIODIR
19407c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
19417c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
19427c478bd9Sstevel@tonic-gate
19437c478bd9Sstevel@tonic-gate#
19447c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
19457c478bd9Sstevel@tonic-gate#
19467c478bd9Sstevel@tonic-gate
1947597bd30bSMike Kupferfunction logshuffle {
1948fd7cef36Ssuha    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
19497c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
19507c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
19517c478bd9Sstevel@tonic-gate	fi
19527c478bd9Sstevel@tonic-gate	mkdir $LLOG
19534802ef38Srscott	export LLOG
19547c478bd9Sstevel@tonic-gate
19557c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
19567c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
195796ccc8cbSesaxe
19582e02daeeSRainer Orth		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
19592e02daeeSRainer Orth			mv $ATLOG/proto_list_tools_${MACH} $LLOG
19602e02daeeSRainer Orth	        fi
19612e02daeeSRainer Orth
196296ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
196396ccc8cbSesaxe		    	mv $TMPDIR/wsdiff.results $LLOG
196496ccc8cbSesaxe		fi
19654e5b757fSkupfer
19664e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
19674e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
19684e5b757fSkupfer		fi
19697c478bd9Sstevel@tonic-gate	fi
19707c478bd9Sstevel@tonic-gate
19717c478bd9Sstevel@tonic-gate	#
19727c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
19737c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
19747c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
19757c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
19767c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
19777c478bd9Sstevel@tonic-gate	#
19787c478bd9Sstevel@tonic-gate
19797c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
19807c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
19817c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
19827c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
19837c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
19847c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
19857c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
19867c478bd9Sstevel@tonic-gate	fi
19877c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
19887c478bd9Sstevel@tonic-gate
19897c478bd9Sstevel@tonic-gate	case "$build_ok" in
19907c478bd9Sstevel@tonic-gate		y)
19917c478bd9Sstevel@tonic-gate			state=Completed
19927c478bd9Sstevel@tonic-gate			;;
19937c478bd9Sstevel@tonic-gate		i)
19947c478bd9Sstevel@tonic-gate			state=Interrupted
19957c478bd9Sstevel@tonic-gate			;;
19967c478bd9Sstevel@tonic-gate		*)
19977c478bd9Sstevel@tonic-gate	    		state=Failed
19987c478bd9Sstevel@tonic-gate			;;
19997c478bd9Sstevel@tonic-gate	esac
200040bc9153Srscott	NIGHTLY_STATUS=$state
200140bc9153Srscott	export NIGHTLY_STATUS
20027c478bd9Sstevel@tonic-gate
200347703246Ssommerfe	run_hook POST_NIGHTLY $state
200447703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
20054802ef38Srscott
2006cdf0c1d5Smjnelson	cat $build_time_file $build_environ_file $mail_msg_file \
2007cdf0c1d5Smjnelson	    > ${LLOG}/mail_msg
20087c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
2009cdf0c1d5Smjnelson	    	cat ${LLOG}/mail_msg | /usr/bin/mailx -s \
20107c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
20117c478bd9Sstevel@tonic-gate			${MAILTO}
20127c478bd9Sstevel@tonic-gate	fi
20137c478bd9Sstevel@tonic-gate
20147c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
20157c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
20167c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
20177c478bd9Sstevel@tonic-gate	fi
20187c478bd9Sstevel@tonic-gate
20197c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
20207c478bd9Sstevel@tonic-gate}
20217c478bd9Sstevel@tonic-gate
20227c478bd9Sstevel@tonic-gate#
20237c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
20247c478bd9Sstevel@tonic-gate#
2025597bd30bSMike Kupferfunction cleanup {
20267c478bd9Sstevel@tonic-gate    	logshuffle
20277c478bd9Sstevel@tonic-gate
20287c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
20297c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
20307c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
20317c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
20327c478bd9Sstevel@tonic-gate
20337c478bd9Sstevel@tonic-gate	set -- $newdirlist
20347c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
20357c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
20367c478bd9Sstevel@tonic-gate		shift; shift
20377c478bd9Sstevel@tonic-gate	done
20387c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
20397c478bd9Sstevel@tonic-gate}
20407c478bd9Sstevel@tonic-gate
2041597bd30bSMike Kupferfunction cleanup_signal {
20427c478bd9Sstevel@tonic-gate    	build_ok=i
20437c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
20447c478bd9Sstevel@tonic-gate	exit 1
20457c478bd9Sstevel@tonic-gate}
20467c478bd9Sstevel@tonic-gate
20477c478bd9Sstevel@tonic-gatetrap cleanup 0
20487c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
20497c478bd9Sstevel@tonic-gate
20507c478bd9Sstevel@tonic-gate#
20517c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
20527c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
20537c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
20547c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
20557c478bd9Sstevel@tonic-gate# for the workspace).
2056cdf0c1d5Smjnelson#
2057597bd30bSMike Kupferfunction create_lock {
20587c478bd9Sstevel@tonic-gate	lockf=$1
20597c478bd9Sstevel@tonic-gate	lockvar=$2
20608312e758Sdduvall
20617c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
20627c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
20637c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
20648312e758Sdduvall
20658312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
20668312e758Sdduvall		basews=`basename $CODEMGR_WS`
20678312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
20688312e758Sdduvall		if [ "$host" != "$hostname" ]; then
20698312e758Sdduvall			echo "$MACH build of $basews apparently" \
20708312e758Sdduvall			    "already started by $user on $host as $pid."
20718312e758Sdduvall			exit 1
20728312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
20738312e758Sdduvall			echo "$MACH build of $basews already started" \
20748312e758Sdduvall			    "by $user as $pid."
20758312e758Sdduvall			exit 1
20768312e758Sdduvall		else
20778312e758Sdduvall			# stale lock; clear it out and try again
20788312e758Sdduvall			rm -f $lockf
20798312e758Sdduvall		fi
20808312e758Sdduvall	done
20817c478bd9Sstevel@tonic-gate}
20827c478bd9Sstevel@tonic-gate
20834e5b757fSkupfer#
20844e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
20854e5b757fSkupfer# options.
20864e5b757fSkupfer#
2087597bd30bSMike Kupferfunction allprotos {
2088b06f2c55SMark J. Nelson	roots="$ROOT"
2089b83ec4edSjmcp
20904e5b757fSkupfer	if [[ $D_FLAG = y && $F_FLAG = n ]]; then
20914e5b757fSkupfer		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd"
20924e5b757fSkupfer	fi
20934e5b757fSkupfer
2094b83ec4edSjmcp	if [[ $O_FLAG = y ]]; then
2095b83ec4edSjmcp		roots="$roots $ROOT-closed"
2096b83ec4edSjmcp		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd-closed"
2097b83ec4edSjmcp	fi
2098b83ec4edSjmcp
20994e5b757fSkupfer	echo $roots
21004e5b757fSkupfer}
21014e5b757fSkupfer
21027c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
21037c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
21047c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
21057c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
21067c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
21077c478bd9Sstevel@tonic-gatefi
21087c478bd9Sstevel@tonic-gate#
21097c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
21107c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
21117c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
21127c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
21137c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
21147c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
21157c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
21167c478bd9Sstevel@tonic-gate#
21177c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
21187c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
21197c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
21207c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
21217c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
21227c478bd9Sstevel@tonic-gatefi
21237c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
21247c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
21257c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
21267c478bd9Sstevel@tonic-gatefi
21277c478bd9Sstevel@tonic-gate
21287c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
21297c478bd9Sstevel@tonic-gate# the directories we may have created so far.
21307c478bd9Sstevel@tonic-gatenewdirlist=
21317c478bd9Sstevel@tonic-gate
21327c478bd9Sstevel@tonic-gate#
21337c478bd9Sstevel@tonic-gate# Create mail_msg_file
21347c478bd9Sstevel@tonic-gate#
21357c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
21367c478bd9Sstevel@tonic-gatetouch $mail_msg_file
21377c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
2138cdf0c1d5Smjnelsonbuild_environ_file="${TMPDIR}/build_environ"
2139cdf0c1d5Smjnelsontouch $build_environ_file
21407c478bd9Sstevel@tonic-gate#
21417c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
21427c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
21437c478bd9Sstevel@tonic-gate#
21447c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
21457c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
21467c478bd9Sstevel@tonic-gatefi
21477c478bd9Sstevel@tonic-gate#
21487c478bd9Sstevel@tonic-gate#	Build OsNet source
21497c478bd9Sstevel@tonic-gate#
21507c478bd9Sstevel@tonic-gateSTART_DATE=`date`
21517c478bd9Sstevel@tonic-gateSECONDS=0
21527c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
21537c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
21547c478bd9Sstevel@tonic-gate
2155cdf0c1d5Smjnelsonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
2156cdf0c1d5Smjnelson    tee -a $mail_msg_file >> $LOGFILE
2157cdf0c1d5Smjnelson
21587c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
21597c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
21607c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
21617c478bd9Sstevel@tonic-gate
216247703246Ssommerferun_hook SYS_PRE_NIGHTLY
216347703246Ssommerferun_hook PRE_NIGHTLY
216447703246Ssommerfe
21657c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
21667c478bd9Sstevel@tonic-gateenv >> $LOGFILE
21677c478bd9Sstevel@tonic-gate
21687c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
21697c478bd9Sstevel@tonic-gate
2170d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
2171d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
2172d77e7149Ssommerfefi
2173d77e7149Ssommerfe
2174d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
2175d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
2176d77e7149Ssommerfefi
2177d77e7149Ssommerfe
21781fe69678Skupferif is_source_build; then
21797c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
21807c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
21817c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
21827c478bd9Sstevel@tonic-gate		i_FLAG=n
21837c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
21847c478bd9Sstevel@tonic-gate	fi
21857c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
21867c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
21877c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
21887c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
21897c478bd9Sstevel@tonic-gate		N_FLAG=y
21907c478bd9Sstevel@tonic-gate	fi
21917c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
21927c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
21937c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
21947c478bd9Sstevel@tonic-gate		l_FLAG=n
21957c478bd9Sstevel@tonic-gate	fi
21967c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
21977c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
21987c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
21997c478bd9Sstevel@tonic-gate		C_FLAG=n
22007c478bd9Sstevel@tonic-gate	fi
22017c478bd9Sstevel@tonic-gateelse
22027c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
22037c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
22047c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
22057c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
22067c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
22077c478bd9Sstevel@tonic-gateEOF
22087c478bd9Sstevel@tonic-gate		else
22097c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
22107c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
22117c478bd9Sstevel@tonic-gateEOF
22127c478bd9Sstevel@tonic-gate		fi
22137c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
22147c478bd9Sstevel@tonic-gate	fi
22157c478bd9Sstevel@tonic-gatefi
22167c478bd9Sstevel@tonic-gate
22174e5b757fSkupferif [ "$O_FLAG" = "y" -a "$a_FLAG" = "n" ]; then
22184e5b757fSkupfer	echo "WARNING: OpenSolaris deliveries (-O) require archives;" \
22194e5b757fSkupfer	    "enabling the -a flag." | tee -a $mail_msg_file >> $LOGFILE
22204e5b757fSkupfer	a_FLAG=y
22214e5b757fSkupferfi
22224e5b757fSkupfer
22237c478bd9Sstevel@tonic-gateif [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
22247c478bd9Sstevel@tonic-gate	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
22257c478bd9Sstevel@tonic-gate	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
22267c478bd9Sstevel@tonic-gatefi
22277c478bd9Sstevel@tonic-gate
22287c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
22294e5b757fSkupfer	#
22304e5b757fSkupfer	# In the past we just complained but went ahead with the lint
2231ead1f93eSLiane Praza	# pass, even though the proto area was built non-DEBUG.  It's
2232ead1f93eSLiane Praza	# unlikely that non-DEBUG headers will make a difference, but
22334e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
2234ead1f93eSLiane Praza	# to specify a DEBUG build.
22354e5b757fSkupfer	#
22364e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
22377c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
22384e5b757fSkupfer	l_FLAG=n
22397c478bd9Sstevel@tonic-gatefi
22407c478bd9Sstevel@tonic-gate
22417c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
22427c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
22437c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
22447c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
22457c478bd9Sstevel@tonic-gate		f_FLAG=n
22467c478bd9Sstevel@tonic-gate	fi
224711a78ea0SMark J. Nelson	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
224811a78ea0SMark J. Nelson		echo "WARNING: the -f flag requires -l, and -p;" \
224911a78ea0SMark J. Nelson		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
22507c478bd9Sstevel@tonic-gate		f_FLAG=n
22517c478bd9Sstevel@tonic-gate	fi
22527c478bd9Sstevel@tonic-gatefi
22537c478bd9Sstevel@tonic-gate
225496ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
22554e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
225696ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
225796ccc8cbSesaxe	w_FLAG=n
225896ccc8cbSesaxefi
225996ccc8cbSesaxe
22607c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
22617c478bd9Sstevel@tonic-gate	#
22627c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
22637c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
22647c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
22657c478bd9Sstevel@tonic-gate	#
22667c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
22677c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
22687c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
22697c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
22707c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
22717c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
22727c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
22737c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
22747c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
22757c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
22767c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
22777c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
22787c478bd9Sstevel@tonic-gate	fi
22797c478bd9Sstevel@tonic-gatefi
22807c478bd9Sstevel@tonic-gate
22814e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
22824e5b757fSkupfer
22834e5b757fSkupfercase $MULTI_PROTO in
22844e5b757fSkupferyes|no)	;;
22854e5b757fSkupfer*)
22864e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
22874e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
22884e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
22894e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
22904e5b757fSkupfer	export MULTI_PROTO=no
22914e5b757fSkupfer	;;
22924e5b757fSkupferesac
22934e5b757fSkupfer
2294597bd30bSMike Kupfer# If CODESIGN_USER is set, we'll want the crypto that we just built.
2295597bd30bSMike Kupferif [[ -n "$CODESIGN_USER" && -n "$ON_CRYPTO_BINS" ]]; then
2296597bd30bSMike Kupfer	echo "Clearing ON_CRYPTO_BINS for signing build." >> "$LOGFILE"
2297597bd30bSMike Kupfer	unset ON_CRYPTO_BINS
2298597bd30bSMike Kupferfi
2299597bd30bSMike Kupfer
23007c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
23017c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
23027c478bd9Sstevel@tonic-gate
230396ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
230496ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
230596ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
230696ccc8cbSesaxe	rm -rf $ROOT.prev
230796ccc8cbSesaxe    fi
230896ccc8cbSesaxe    mv $ROOT $ROOT.prev
230996ccc8cbSesaxefi
231096ccc8cbSesaxe
23114e5b757fSkupfer# Same for non-DEBUG proto area
23124e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
23134e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
23144e5b757fSkupfer		rm -rf $ROOT-nd.prev
23154e5b757fSkupfer	fi
23164e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
23174e5b757fSkupferfi
23184e5b757fSkupfer
231930635de9SJohn.Zolnowsky@Sun.COM# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
232030635de9SJohn.Zolnowsky@Sun.COMfunction wstypes {
232130635de9SJohn.Zolnowsky@Sun.COM	typeset parent_type child_type junk
232230635de9SJohn.Zolnowsky@Sun.COM
232330635de9SJohn.Zolnowsky@Sun.COM	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
232430635de9SJohn.Zolnowsky@Sun.COM	    | read parent_type junk
232530635de9SJohn.Zolnowsky@Sun.COM	if [[ -z "$parent_type" || "$parent_type" == unknown ]]; then
232630635de9SJohn.Zolnowsky@Sun.COM		# Probe BRINGOVER_WS to determine its type
232730635de9SJohn.Zolnowsky@Sun.COM		if [[ $BRINGOVER_WS == svn*://* ]]; then
232830635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
232930635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == file://* ]] &&
233030635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "This is a Subversion repository" \
233130635de9SJohn.Zolnowsky@Sun.COM		    ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
233230635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
233330635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == ssh://* ]]; then
233430635de9SJohn.Zolnowsky@Sun.COM			parent_type="mercurial"
233530635de9SJohn.Zolnowsky@Sun.COM		elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
233630635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
233730635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == http://* ]] && \
233830635de9SJohn.Zolnowsky@Sun.COM		    http_get "$BRINGOVER_WS/?cmd=heads" | \
233930635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "application/mercurial" 2> /dev/null; then
234030635de9SJohn.Zolnowsky@Sun.COM			parent_type="mercurial"
234130635de9SJohn.Zolnowsky@Sun.COM		else
234230635de9SJohn.Zolnowsky@Sun.COM			parent_type="none"
234330635de9SJohn.Zolnowsky@Sun.COM		fi
234430635de9SJohn.Zolnowsky@Sun.COM	fi
234530635de9SJohn.Zolnowsky@Sun.COM
234630635de9SJohn.Zolnowsky@Sun.COM	# Probe CODEMGR_WS to determine its type
234730635de9SJohn.Zolnowsky@Sun.COM	if [[ -d $CODEMGR_WS ]]; then
234830635de9SJohn.Zolnowsky@Sun.COM		$WHICH_SCM | read child_type junk || exit 1
234930635de9SJohn.Zolnowsky@Sun.COM	fi
235030635de9SJohn.Zolnowsky@Sun.COM
235130635de9SJohn.Zolnowsky@Sun.COM	# fold both unsupported and unrecognized results into "none"
235230635de9SJohn.Zolnowsky@Sun.COM	case "$parent_type" in
235330635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
235430635de9SJohn.Zolnowsky@Sun.COM		;;
235530635de9SJohn.Zolnowsky@Sun.COM	*)	parent_type=none
235630635de9SJohn.Zolnowsky@Sun.COM		;;
235730635de9SJohn.Zolnowsky@Sun.COM	esac
235830635de9SJohn.Zolnowsky@Sun.COM	case "$child_type" in
235930635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
236030635de9SJohn.Zolnowsky@Sun.COM		;;
236130635de9SJohn.Zolnowsky@Sun.COM	*)	child_type=none
236230635de9SJohn.Zolnowsky@Sun.COM		;;
236330635de9SJohn.Zolnowsky@Sun.COM	esac
236430635de9SJohn.Zolnowsky@Sun.COM
236530635de9SJohn.Zolnowsky@Sun.COM	echo $child_type $parent_type
236630635de9SJohn.Zolnowsky@Sun.COM}
236730635de9SJohn.Zolnowsky@Sun.COM
236830635de9SJohn.Zolnowsky@Sun.COMwstypes | read SCM_TYPE PARENT_SCM_TYPE
236930635de9SJohn.Zolnowsky@Sun.COMexport SCM_TYPE PARENT_SCM_TYPE
237030635de9SJohn.Zolnowsky@Sun.COM
23717c478bd9Sstevel@tonic-gate#
23727c478bd9Sstevel@tonic-gate#	Decide whether to clobber
23737c478bd9Sstevel@tonic-gate#
23747c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
23757c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
23767c478bd9Sstevel@tonic-gate
23777c478bd9Sstevel@tonic-gate	cd $SRC
23787c478bd9Sstevel@tonic-gate	# remove old clobber file
23797c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
23807c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
23817c478bd9Sstevel@tonic-gate
23827c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
23837c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
2384cdf0c1d5Smjnelson	find . \( -name SCCS -o -name .hg -o -name .svn \
2385cdf0c1d5Smjnelson		-o -name 'interfaces.*' \) -prune \
23867c478bd9Sstevel@tonic-gate		-o -name '.make.*' -print | xargs rm -f
23877c478bd9Sstevel@tonic-gate
23887c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
23897c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
23907c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
23917c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
23927c478bd9Sstevel@tonic-gate		>> $mail_msg_file
23937c478bd9Sstevel@tonic-gate
23944e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
23957c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
23967c478bd9Sstevel@tonic-gate		cd ${TOOLS}
23977c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
2398ead1f93eSLiane Praza		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
23997c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
24007c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
24017c478bd9Sstevel@tonic-gate			>> $mail_msg_file
24027c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
24037c478bd9Sstevel@tonic-gate			>> $mail_msg_file
24047c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
24057c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
24067c478bd9Sstevel@tonic-gate	fi
240796ccc8cbSesaxe
24084e5b757fSkupfer	rm -rf `allprotos`
24097c478bd9Sstevel@tonic-gate
24107c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
24117c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
24127c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2413fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2414cdf0c1d5Smjnelson	# under source code control, so leave them alone.
24157c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
24167c478bd9Sstevel@tonic-gate	cd $SRC
2417cdf0c1d5Smjnelson	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
2418cdf0c1d5Smjnelson	    -o -name 'interfaces.*' \) -prune -o \
24197c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2420fb23a357Skupfer	       -name '*.o' \) -print | \
2421fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
24227c478bd9Sstevel@tonic-gateelse
24237c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
24247c478bd9Sstevel@tonic-gatefi
24257c478bd9Sstevel@tonic-gate
2426597bd30bSMike Kupfertype bringover_teamware > /dev/null 2>&1 || function bringover_teamware {
24277c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
24287c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
24297c478bd9Sstevel@tonic-gate	do
24307c478bd9Sstevel@tonic-gate		sleep 120
24317c478bd9Sstevel@tonic-gate	done
24327c478bd9Sstevel@tonic-gate
2433fd7cef36Ssuha	if [[ -z $BRINGOVER ]]; then
2434fd7cef36Ssuha		BRINGOVER=$TEAMWARE/bin/bringover
2435fd7cef36Ssuha	fi
243632f1e47bSsommerfe
2437cdf0c1d5Smjnelson	staffer $BRINGOVER -c "nightly update" -p $BRINGOVER_WS \
243832f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
243932f1e47bSsommerfe		touch $TMPDIR/bringover_failed
244032f1e47bSsommerfe
2441d77e7149Ssommerfe        staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2442d77e7149Ssommerfe	if [ -s $TMPDIR/bringovercheck.out ]; then
2443d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2444d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2445d77e7149Ssommerfe	fi
2446cdf0c1d5Smjnelson}
244732f1e47bSsommerfe
2448597bd30bSMike Kupfertype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
2449cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2450cdf0c1d5Smjnelson
2451cdf0c1d5Smjnelson	# If the repository doesn't exist yet, then we want to populate it.
2452cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.hg ]]; then
2453cdf0c1d5Smjnelson		staffer hg init $CODEMGR_WS
24548cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
24558cca05f6SMark J. Nelson		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
2456f457028bSMark J. Nelson		touch $TMPDIR/new_repository
2457cdf0c1d5Smjnelson	fi
24585c53ea7aSmjnelson
24595c53ea7aSmjnelson	#
24605c53ea7aSmjnelson	# If the user set CLOSED_BRINGOVER_WS and didn't set CLOSED_IS_PRESENT
24615c53ea7aSmjnelson	# to "no," then we'll want to initialise the closed repository
24625c53ea7aSmjnelson	#
24635c53ea7aSmjnelson	# We use $orig_closed_is_present instead of $CLOSED_IS_PRESENT,
24645c53ea7aSmjnelson	# because for newly-created source trees, the latter will be "no"
24655c53ea7aSmjnelson	# until after the bringover completes.
24665c53ea7aSmjnelson	#
24675c53ea7aSmjnelson	if [[ "$orig_closed_is_present" != "no" && \
24685c53ea7aSmjnelson	    -n "$CLOSED_BRINGOVER_WS" && \
24695c53ea7aSmjnelson	    ! -d $CODEMGR_WS/usr/closed/.hg ]]; then
24705c53ea7aSmjnelson		staffer mkdir -p $CODEMGR_WS/usr/closed
24715c53ea7aSmjnelson		staffer hg init $CODEMGR_WS/usr/closed
24728cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/usr/closed/.hg/hgrc
24738cca05f6SMark J. Nelson		staffer echo "default=$CLOSED_BRINGOVER_WS" >> $CODEMGR_WS/usr/closed/.hg/hgrc
2474f457028bSMark J. Nelson		touch $TMPDIR/new_closed
24755c53ea7aSmjnelson		export CLOSED_IS_PRESENT=yes
2476cdf0c1d5Smjnelson	fi
2477cdf0c1d5Smjnelson
2478cdf0c1d5Smjnelson	typeset -x HGMERGE="/bin/false"
2479cdf0c1d5Smjnelson
2480cdf0c1d5Smjnelson	#
24815c53ea7aSmjnelson	# If the user has changes, regardless of whether those changes are
24825c53ea7aSmjnelson	# committed, and regardless of whether those changes conflict, then
24835c53ea7aSmjnelson	# we'll attempt to merge them either implicitly (uncommitted) or
24845c53ea7aSmjnelson	# explicitly (committed).
2485cdf0c1d5Smjnelson	#
24865c53ea7aSmjnelson	# These are the messages we'll use to help clarify mercurial output
24875c53ea7aSmjnelson	# in those cases.
24885c53ea7aSmjnelson	#
24895c53ea7aSmjnelson	typeset mergefailmsg="\
24905c53ea7aSmjnelson***\n\
24915c53ea7aSmjnelson*** nightly was unable to automatically merge your changes.  You should\n\
24925c53ea7aSmjnelson*** redo the full merge manually, following the steps outlined by mercurial\n\
24935c53ea7aSmjnelson*** above, then restart nightly.\n\
24945c53ea7aSmjnelson***\n"
24955c53ea7aSmjnelson	typeset mergepassmsg="\
24965c53ea7aSmjnelson***\n\
24975c53ea7aSmjnelson*** nightly successfully merged your changes.  This means that your working\n\
24985c53ea7aSmjnelson*** directory has been updated, but those changes are not yet committed.\n\
24995c53ea7aSmjnelson*** After nightly completes, you should validate the results of the merge,\n\
25005c53ea7aSmjnelson*** then use hg commit manually.\n\
25015c53ea7aSmjnelson***\n"
25025c53ea7aSmjnelson
25035c53ea7aSmjnelson	#
25045c53ea7aSmjnelson	# For each repository in turn:
25055c53ea7aSmjnelson	#
25065c53ea7aSmjnelson	# 1. Do the pull.  If this fails, dump the output and bail out.
25075c53ea7aSmjnelson	#
25085c53ea7aSmjnelson	# 2. If the pull resulted in an extra head, do an explicit merge.
25095c53ea7aSmjnelson	#    If this fails, dump the output and bail out.
25105c53ea7aSmjnelson	#
25115c53ea7aSmjnelson	# Because we can't rely on Mercurial to exit with a failure code
25125c53ea7aSmjnelson	# when a merge fails (Mercurial issue #186), we must grep the
25135c53ea7aSmjnelson	# output of pull/merge to check for attempted and/or failed merges.
25145c53ea7aSmjnelson	#
25155c53ea7aSmjnelson	# 3. If a merge failed, set the message and fail the bringover.
25165c53ea7aSmjnelson	#
25175c53ea7aSmjnelson	# 4. Otherwise, if a merge succeeded, set the message
25185c53ea7aSmjnelson	#
25195c53ea7aSmjnelson	# 5. Dump the output, and any message from step 3 or 4.
25205c53ea7aSmjnelson	#
25215c53ea7aSmjnelson
2522f457028bSMark J. Nelson	typeset HG_SOURCE=$BRINGOVER_WS
2523f457028bSMark J. Nelson	if [ ! -f $TMPDIR/new_repository ]; then
2524f457028bSMark J. Nelson		HG_SOURCE=$TMPDIR/open_bundle.hg
2525f457028bSMark J. Nelson		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
2526f457028bSMark J. Nelson		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
2527f457028bSMark J. Nelson
2528f457028bSMark J. Nelson		#
2529f457028bSMark J. Nelson		# If there are no incoming changesets, then incoming will
2530f457028bSMark J. Nelson		# fail, and there will be no bundle file.  Reset the source,
2531f457028bSMark J. Nelson		# to allow the remaining logic to complete with no false
2532f457028bSMark J. Nelson		# negatives.  (Unlike incoming, pull will return success
2533f457028bSMark J. Nelson		# for the no-change case.)
2534f457028bSMark J. Nelson		#
2535f457028bSMark J. Nelson		if (( $? != 0 )); then
2536f457028bSMark J. Nelson			HG_SOURCE=$BRINGOVER_WS
2537f457028bSMark J. Nelson		fi
2538f457028bSMark J. Nelson	fi
2539f457028bSMark J. Nelson
2540f457028bSMark J. Nelson	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
25415c53ea7aSmjnelson	    > $TMPDIR/pull_open.out 2>&1
25425c53ea7aSmjnelson	if (( $? != 0 )); then
25435c53ea7aSmjnelson		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
25445c53ea7aSmjnelson		cat $TMPDIR/pull_open.out
25455c53ea7aSmjnelson		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
25465c53ea7aSmjnelson			printf "$mergefailmsg"
25475c53ea7aSmjnelson		fi
25485c53ea7aSmjnelson		touch $TMPDIR/bringover_failed
25495c53ea7aSmjnelson		return
25505c53ea7aSmjnelson	fi
25515c53ea7aSmjnelson
2552cdf0c1d5Smjnelson	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
25535c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS merge \
25545c53ea7aSmjnelson		    >> $TMPDIR/pull_open.out 2>&1
25555c53ea7aSmjnelson		if (( $? != 0 )); then
25565c53ea7aSmjnelson			printf "%s: merge failed as follows:\n\n" \
25575c53ea7aSmjnelson			    "$CODEMGR_WS"
25585c53ea7aSmjnelson			cat $TMPDIR/pull_open.out
25595c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_open.out \
25605c53ea7aSmjnelson			    > /dev/null 2>&1; then
25615c53ea7aSmjnelson				printf "$mergefailmsg"
25625c53ea7aSmjnelson			fi
2563cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
25645c53ea7aSmjnelson			return
2565cdf0c1d5Smjnelson		fi
2566cdf0c1d5Smjnelson	fi
25675c53ea7aSmjnelson
25685c53ea7aSmjnelson	printf "updated %s with the following results:\n" "$CODEMGR_WS"
25695c53ea7aSmjnelson	cat $TMPDIR/pull_open.out
25705c53ea7aSmjnelson	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
25715c53ea7aSmjnelson		printf "$mergepassmsg"
25725c53ea7aSmjnelson	fi
25735c53ea7aSmjnelson	printf "\n"
25745c53ea7aSmjnelson
25755c53ea7aSmjnelson	#
25765c53ea7aSmjnelson	# We only want to update usr/closed if it exists, and we haven't been
25775c53ea7aSmjnelson	# told not to via $CLOSED_IS_PRESENT, and we actually know where to
25785c53ea7aSmjnelson	# pull from ($CLOSED_BRINGOVER_WS).
25795c53ea7aSmjnelson	#
25805c53ea7aSmjnelson	if [[ $CLOSED_IS_PRESENT = yes && \
25815c53ea7aSmjnelson	    -d $CODEMGR_WS/usr/closed/.hg && \
25825c53ea7aSmjnelson	    -n $CLOSED_BRINGOVER_WS ]]; then
25835c53ea7aSmjnelson
2584f457028bSMark J. Nelson		HG_SOURCE=$CLOSED_BRINGOVER_WS
2585f457028bSMark J. Nelson		if [ ! -f $TMPDIR/new_closed ]; then
2586f457028bSMark J. Nelson			HG_SOURCE=$TMPDIR/closed_bundle.hg
2587f457028bSMark J. Nelson			staffer hg --cwd $CODEMGR_WS/usr/closed incoming \
2588f457028bSMark J. Nelson			    --bundle $HG_SOURCE -v $CLOSED_BRINGOVER_WS \
2589f457028bSMark J. Nelson			    > $TMPDIR/incoming_closed.out
2590f457028bSMark J. Nelson
2591f457028bSMark J. Nelson			#
2592f457028bSMark J. Nelson			# If there are no incoming changesets, then incoming will
2593f457028bSMark J. Nelson			# fail, and there will be no bundle file.  Reset the source,
2594f457028bSMark J. Nelson			# to allow the remaining logic to complete with no false
2595f457028bSMark J. Nelson			# negatives.  (Unlike incoming, pull will return success
2596f457028bSMark J. Nelson			# for the no-change case.)
2597f457028bSMark J. Nelson			#
2598f457028bSMark J. Nelson			if (( $? != 0 )); then
2599f457028bSMark J. Nelson				HG_SOURCE=$CLOSED_BRINGOVER_WS
2600f457028bSMark J. Nelson			fi
2601f457028bSMark J. Nelson		fi
2602f457028bSMark J. Nelson
26035c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS/usr/closed pull -u \
2604f457028bSMark J. Nelson			$HG_SOURCE > $TMPDIR/pull_closed.out 2>&1
26055c53ea7aSmjnelson		if (( $? != 0 )); then
26065c53ea7aSmjnelson			printf "closed pull failed as follows:\n\n"
26075c53ea7aSmjnelson			cat $TMPDIR/pull_closed.out
26085c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_closed.out \
26095c53ea7aSmjnelson			    > /dev/null 2>&1; then
26105c53ea7aSmjnelson				printf "$mergefailmsg"
26115c53ea7aSmjnelson			fi
26125c53ea7aSmjnelson			touch $TMPDIR/bringover_failed
26135c53ea7aSmjnelson			return
26145c53ea7aSmjnelson		fi
26155c53ea7aSmjnelson
2616cdf0c1d5Smjnelson		if grep "not updating" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
26175c53ea7aSmjnelson			staffer hg --cwd $CODEMGR_WS/usr/closed merge \
26185c53ea7aSmjnelson			    >> $TMPDIR/pull_closed.out 2>&1
26195c53ea7aSmjnelson			if (( $? != 0 )); then
26205c53ea7aSmjnelson				printf "closed merge failed as follows:\n\n"
26215c53ea7aSmjnelson				cat $TMPDIR/pull_closed.out
26225c53ea7aSmjnelson				if grep "^merging.*failed" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
26235c53ea7aSmjnelson					printf "$mergefailmsg"
26245c53ea7aSmjnelson				fi
2625cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
26265c53ea7aSmjnelson				return
26275c53ea7aSmjnelson			fi
26285c53ea7aSmjnelson		fi
26295c53ea7aSmjnelson
26305c53ea7aSmjnelson		printf "updated %s with the following results:\n" \
26315c53ea7aSmjnelson		    "$CODEMGR_WS/usr/closed"
26325c53ea7aSmjnelson		cat $TMPDIR/pull_closed.out
26335c53ea7aSmjnelson		if grep "^merging" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
26345c53ea7aSmjnelson			printf "$mergepassmsg"
2635cdf0c1d5Smjnelson		fi
2636cdf0c1d5Smjnelson	fi
2637f457028bSMark J. Nelson
2638f457028bSMark J. Nelson	#
2639f457028bSMark J. Nelson	# Per-changeset output is neither useful nor manageable for a
2640f457028bSMark J. Nelson	# newly-created repository.
2641f457028bSMark J. Nelson	#
2642f457028bSMark J. Nelson	if [ -f $TMPDIR/new_repository ]; then
2643f457028bSMark J. Nelson		return
2644f457028bSMark J. Nelson	fi
2645f457028bSMark J. Nelson
2646f457028bSMark J. Nelson	printf "\nadded the following changesets to open repository:\n"
2647f457028bSMark J. Nelson	cat $TMPDIR/incoming_open.out
2648f457028bSMark J. Nelson
2649f457028bSMark J. Nelson	#
2650f457028bSMark J. Nelson	# The closed repository could have been newly created, even though
2651f457028bSMark J. Nelson	# the open one previously existed...
2652f457028bSMark J. Nelson	#
2653f457028bSMark J. Nelson	if [ -f $TMPDIR/new_closed ]; then
2654f457028bSMark J. Nelson		return
2655f457028bSMark J. Nelson	fi
2656f457028bSMark J. Nelson
2657f457028bSMark J. Nelson	if [ -f $TMPDIR/incoming_closed.out ]; then
2658f457028bSMark J. Nelson		printf "\nadded the following changesets to closed repository:\n"
2659f457028bSMark J. Nelson		cat $TMPDIR/incoming_closed.out
2660f457028bSMark J. Nelson	fi
2661cdf0c1d5Smjnelson}
2662cdf0c1d5Smjnelson
2663597bd30bSMike Kupfertype bringover_subversion > /dev/null 2>&1 || function bringover_subversion {
2664cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2665cdf0c1d5Smjnelson
2666cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.svn ]]; then
2667cdf0c1d5Smjnelson		staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2668cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2669cdf0c1d5Smjnelson	else
2670cdf0c1d5Smjnelson		typeset root
2671cdf0c1d5Smjnelson		root=$(staffer svn info $CODEMGR_WS |
2672cdf0c1d5Smjnelson			nawk '/^Repository Root:/ {print $NF}')
2673cdf0c1d5Smjnelson		if [[ $root != $BRINGOVER_WS ]]; then
2674cdf0c1d5Smjnelson			# We fail here because there's no way to update
2675cdf0c1d5Smjnelson			# from a named repo.
2676cdf0c1d5Smjnelson			cat <<-EOF
2677cdf0c1d5Smjnelson			\$BRINGOVER_WS doesn't match repository root:
2678cdf0c1d5Smjnelson			  \$BRINGOVER_WS:  $BRINGOVER_WS
2679cdf0c1d5Smjnelson			  Repository root: $root
2680cdf0c1d5Smjnelson			EOF
2681cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2682cdf0c1d5Smjnelson		else
2683cdf0c1d5Smjnelson			# If a conflict happens, svn still exits 0.
2684cdf0c1d5Smjnelson			staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2685cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2686cdf0c1d5Smjnelson			if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2687cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2688cdf0c1d5Smjnelson			fi
2689cdf0c1d5Smjnelson		fi
2690cdf0c1d5Smjnelson	fi
2691cdf0c1d5Smjnelson}
2692cdf0c1d5Smjnelson
2693597bd30bSMike Kupfertype bringover_none > /dev/null 2>&1 || function bringover_none {
2694cdf0c1d5Smjnelson	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2695cdf0c1d5Smjnelson	touch $TMPDIR/bringover_failed
2696cdf0c1d5Smjnelson}
2697cdf0c1d5Smjnelson
2698cdf0c1d5Smjnelson# Parse the URL.
2699cdf0c1d5Smjnelson# The other way to deal with empty components is to echo a string that can
2700cdf0c1d5Smjnelson# be eval'ed by the caller to associate values (possibly empty) with
2701cdf0c1d5Smjnelson# variables.  In that case, passing in a printf string would let the caller
2702cdf0c1d5Smjnelson# choose the variable names.
2703597bd30bSMike Kupferfunction parse_url {
2704cdf0c1d5Smjnelson	typeset url method host port path
2705cdf0c1d5Smjnelson
2706cdf0c1d5Smjnelson	url=$1
2707cdf0c1d5Smjnelson	method=${url%%://*}
2708cdf0c1d5Smjnelson	host=${url#$method://}
2709cdf0c1d5Smjnelson	path=${host#*/}
2710cdf0c1d5Smjnelson	host=${host%%/*}
2711cdf0c1d5Smjnelson	if [[ $host == *:* ]]; then
2712cdf0c1d5Smjnelson		port=${host#*:}
2713cdf0c1d5Smjnelson		host=${host%:*}
2714cdf0c1d5Smjnelson	fi
2715cdf0c1d5Smjnelson
2716cdf0c1d5Smjnelson	# method can never be empty.  host can only be empty if method is
2717cdf0c1d5Smjnelson	# file, and that implies it's localhost.  path can default to / if
2718cdf0c1d5Smjnelson	# it's otherwise empty, leaving port as the only component without
2719cdf0c1d5Smjnelson	# a default, so it has to go last.
2720cdf0c1d5Smjnelson	echo $method ${host:-localhost} ${path:-/} $port
2721cdf0c1d5Smjnelson}
2722cdf0c1d5Smjnelson
2723597bd30bSMike Kupferfunction http_get {
2724cdf0c1d5Smjnelson	typeset url method host port path
2725cdf0c1d5Smjnelson
2726cdf0c1d5Smjnelson	url=$1
2727cdf0c1d5Smjnelson
2728cdf0c1d5Smjnelson	if [[ -n $http_proxy ]]; then
2729cdf0c1d5Smjnelson		parse_url $http_proxy | read method host path port
2730cdf0c1d5Smjnelson		echo "GET $url HTTP/1.0\r\n" |
2731cdf0c1d5Smjnelson			mconnect -p ${port:-8080} $host
2732cdf0c1d5Smjnelson	else
2733cdf0c1d5Smjnelson		parse_url $url | read method host path port
2734cdf0c1d5Smjnelson		echo "GET $path HTTP/1.0\r\n" |
2735cdf0c1d5Smjnelson			mconnect -p ${port:-80} $host
2736cdf0c1d5Smjnelson	fi
2737cdf0c1d5Smjnelson}
2738cdf0c1d5Smjnelson
2739cdf0c1d5Smjnelson#
2740cdf0c1d5Smjnelson#	Decide whether to bringover to the codemgr workspace
2741cdf0c1d5Smjnelson#
2742cdf0c1d5Smjnelsonif [ "$n_FLAG" = "n" ]; then
2743ca0ac982Smjnelson
2744ca0ac982Smjnelson	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2745ca0ac982Smjnelson		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2746ca0ac982Smjnelson		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2747ca0ac982Smjnelson		exit 1
2748ca0ac982Smjnelson	fi
2749ca0ac982Smjnelson
2750cdf0c1d5Smjnelson	run_hook PRE_BRINGOVER
2751cdf0c1d5Smjnelson
2752cdf0c1d5Smjnelson	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2753cdf0c1d5Smjnelson	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2754cdf0c1d5Smjnelson
2755ca0ac982Smjnelson	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2756cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
275732f1e47bSsommerfe
275832f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
275932f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
276032f1e47bSsommerfe		build_ok=n
276132f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
27627c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
27637c478bd9Sstevel@tonic-gate		exit 1
27647c478bd9Sstevel@tonic-gate	fi
2765085d331dSkupfer
2766ca0ac982Smjnelson	#
2767ca0ac982Smjnelson	# It's possible that we used the bringover above to create
2768ca0ac982Smjnelson	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2769ca0ac982Smjnelson	# but should now be the same as $BRINGOVER_WS.
2770ca0ac982Smjnelson	#
2771ca0ac982Smjnelson	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2772ca0ac982Smjnelson
277347703246Ssommerfe	run_hook POST_BRINGOVER
277447703246Ssommerfe
2775085d331dSkupfer	#
2776085d331dSkupfer	# Possible transition from pre-split workspace to split
2777085d331dSkupfer	# workspace.  See if the bringover changed anything.
2778085d331dSkupfer	#
2779085d331dSkupfer	CLOSED_IS_PRESENT="$orig_closed_is_present"
2780085d331dSkupfer	check_closed_tree
2781b83ec4edSjmcp
27827c478bd9Sstevel@tonic-gateelse
27837c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
27847c478bd9Sstevel@tonic-gatefi
27857c478bd9Sstevel@tonic-gate
2786b83ec4edSjmcpif [[ "$O_FLAG" = y && "$CLOSED_IS_PRESENT" != "yes" ]]; then
2787b83ec4edSjmcp	build_ok=n
2788b83ec4edSjmcp	echo "OpenSolaris binary deliverables need usr/closed." \
2789b83ec4edSjmcp	    | tee -a "$mail_msg_file" >> $LOGFILE
2790b83ec4edSjmcp	exit 1
2791b83ec4edSjmcpfi
2792b83ec4edSjmcp
2793597bd30bSMike Kupferif [ "$CLOSED_IS_PRESENT" = no ]; then
2794865a69a7SMike Kupfer	#
2795865a69a7SMike Kupfer	# Not all consolidations have a closed tree, and even if they
2796865a69a7SMike Kupfer	# did, they wouldn't necessarily have signed crypto.  But if
2797865a69a7SMike Kupfer	# the current source base does have signed crypto and it can't
2798865a69a7SMike Kupfer	# be generated, error out, rather than silently building
2799865a69a7SMike Kupfer	# unusable binaries.
2800865a69a7SMike Kupfer	#
2801865a69a7SMike Kupfer	grep -s ELFSIGN_CRYPTO "$SRC/Makefile.master" > /dev/null
2802865a69a7SMike Kupfer	if (( $? == 0 )); then
2803597bd30bSMike Kupfer		crypto_is_present >> "$LOGFILE"
2804597bd30bSMike Kupfer		if (( $? != 0 )); then
2805597bd30bSMike Kupfer			build_ok=n
2806597bd30bSMike Kupfer			echo "A crypto tarball must be provided when" \
2807597bd30bSMike Kupfer			    "there is no closed tree." |
2808597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
2809597bd30bSMike Kupfer			exit 1
2810597bd30bSMike Kupfer		fi
2811597bd30bSMike Kupfer	fi
2812865a69a7SMike Kupferfi
2813597bd30bSMike Kupfer
2814cdf0c1d5Smjnelsonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2815cdf0c1d5Smjnelson
2816cdf0c1d5Smjnelson# System
2817cdf0c1d5Smjnelsonwhence uname | tee -a $build_environ_file >> $LOGFILE
2818cdf0c1d5Smjnelsonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2819cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2820cdf0c1d5Smjnelson
2821cdf0c1d5Smjnelson# nightly
2822cdf0c1d5Smjnelsonecho "$0 $@" | tee -a $build_environ_file >> $LOGFILE
2823cdf0c1d5Smjnelsonif [[ $nightly_path = "/opt/onbld/bin/nightly" ]] &&
2824ead1f93eSLiane Praza    #
2825ead1f93eSLiane Praza    # XXX This should work with ips legacy pkginfo for now, but will
2826ead1f93eSLiane Praza    # fall apart when we stop updating that.
2827ead1f93eSLiane Praza    #
2828cdf0c1d5Smjnelson    pkginfo SUNWonbld > /dev/null 2>&1 ; then
2829cdf0c1d5Smjnelson	pkginfo -l SUNWonbld | egrep "PKGINST:|VERSION:|PSTAMP:"
2830cdf0c1d5Smjnelsonelse
283130635de9SJohn.Zolnowsky@Sun.COM	echo "$nightly_ls"
2832cdf0c1d5Smjnelsonfi | tee -a $build_environ_file >> $LOGFILE
2833cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2834cdf0c1d5Smjnelson
2835cdf0c1d5Smjnelson# make
2836cdf0c1d5Smjnelsonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
2837cdf0c1d5Smjnelson$MAKE -v | tee -a $build_environ_file >> $LOGFILE
2838cdf0c1d5Smjnelsonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2839cdf0c1d5Smjnelson    tee -a $build_environ_file >> $LOGFILE
2840cdf0c1d5Smjnelson
2841cdf0c1d5Smjnelson#
2842cdf0c1d5Smjnelson# Report the compiler versions.
2843cdf0c1d5Smjnelson#
2844cdf0c1d5Smjnelson
2845cdf0c1d5Smjnelsonif [[ ! -f $SRC/Makefile ]]; then
2846cdf0c1d5Smjnelson	build_ok=n
2847cdf0c1d5Smjnelson	echo "\nUnable to find \"Makefile\" in $SRC." | \
2848cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2849cdf0c1d5Smjnelson	exit 1
2850cdf0c1d5Smjnelsonfi
2851cdf0c1d5Smjnelson
2852cdf0c1d5Smjnelson( cd $SRC
2853cdf0c1d5Smjnelson  for target in cc-version cc64-version java-version; do
2854cdf0c1d5Smjnelson	echo
2855cdf0c1d5Smjnelson	#
2856cdf0c1d5Smjnelson	# Put statefile somewhere we know we can write to rather than trip
2857cdf0c1d5Smjnelson	# over a read-only $srcroot.
2858cdf0c1d5Smjnelson	#
2859cdf0c1d5Smjnelson	rm -f $TMPDIR/make-state
2860cdf0c1d5Smjnelson	export SRC
2861cdf0c1d5Smjnelson	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2862cdf0c1d5Smjnelson		continue
2863cdf0c1d5Smjnelson	fi
2864cdf0c1d5Smjnelson	touch $TMPDIR/nocompiler
2865cdf0c1d5Smjnelson  done
2866cdf0c1d5Smjnelson  echo
2867cdf0c1d5Smjnelson) | tee -a $build_environ_file >> $LOGFILE
2868cdf0c1d5Smjnelson
2869cdf0c1d5Smjnelsonif [ -f $TMPDIR/nocompiler ]; then
2870cdf0c1d5Smjnelson	rm -f $TMPDIR/nocompiler
2871cdf0c1d5Smjnelson	build_ok=n
2872cdf0c1d5Smjnelson	echo "Aborting due to missing compiler." |
2873cdf0c1d5Smjnelson		tee -a $build_environ_file >> $LOGFILE
2874cdf0c1d5Smjnelson	exit 1
2875cdf0c1d5Smjnelsonfi
2876cdf0c1d5Smjnelson
2877cdf0c1d5Smjnelson# as
2878cdf0c1d5Smjnelsonwhence as | tee -a $build_environ_file >> $LOGFILE
2879cdf0c1d5Smjnelsonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2880cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2881cdf0c1d5Smjnelson
2882cdf0c1d5Smjnelson# Check that we're running a capable link-editor
2883cdf0c1d5Smjnelsonwhence ld | tee -a $build_environ_file >> $LOGFILE
2884cdf0c1d5SmjnelsonLDVER=`ld -V 2>&1`
2885cdf0c1d5Smjnelsonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
2886cdf0c1d5SmjnelsonLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
2887cdf0c1d5Smjnelsonif [ `expr $LDVER \< 422` -eq 1 ]; then
2888cdf0c1d5Smjnelson	echo "The link-editor needs to be at version 422 or higher to build" | \
2889cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2890cdf0c1d5Smjnelson	echo "the latest stuff.  Hope your build works." | \
2891cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2892cdf0c1d5Smjnelsonfi
2893cdf0c1d5Smjnelson
28947c478bd9Sstevel@tonic-gate#
28954e5b757fSkupfer# Build and use the workspace's tools if requested
28967c478bd9Sstevel@tonic-gate#
28974e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
28984e5b757fSkupfer	set_non_debug_build_flags
28997c478bd9Sstevel@tonic-gate
29007c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
2901ead1f93eSLiane Praza	if [[ $? != 0  && "$t_FLAG" = y ]]; then
29024e5b757fSkupfer		use_tools $TOOLS_PROTO
29034e5b757fSkupfer	fi
29047c478bd9Sstevel@tonic-gatefi
29057c478bd9Sstevel@tonic-gate
29066fec3625Sdduvall#
29076fec3625Sdduvall# copy ihv proto area in addition to the build itself
29086fec3625Sdduvall#
29096fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
29106fec3625Sdduvall	copy_ihv_proto
29116fec3625Sdduvallfi
29126fec3625Sdduvall
29137c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
29147c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
29157c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
29167c478bd9Sstevel@tonic-gateelse
29174e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
29184e5b757fSkupfer	touch $SRC/.build.tstamp
29194e5b757fSkupfer
29207c478bd9Sstevel@tonic-gate	normal_build
29217c478bd9Sstevel@tonic-gatefi
29227c478bd9Sstevel@tonic-gate
29234e5b757fSkupfer#
2924597bd30bSMike Kupfer# Generate the THIRDPARTYLICENSE files if needed.  This is done after
2925597bd30bSMike Kupfer# the build, so that dynamically-created license files are there.
2926597bd30bSMike Kupfer# It's done before findunref to help identify license files that need
2927597bd30bSMike Kupfer# to be added to tools/opensolaris/license-list.
29285d715dd7Skupfer#
29295d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2930597bd30bSMike Kupfer	echo "\n==== Generating THIRDPARTYLICENSE files ====\n" |
2931597bd30bSMike Kupfer	    tee -a "$mail_msg_file" >> "$LOGFILE"
29325d715dd7Skupfer
2933597bd30bSMike Kupfer	mktpl usr/src/tools/opensolaris/license-list >> "$LOGFILE" 2>&1
2934cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
29355d715dd7Skupfer		echo "Couldn't create THIRDPARTYLICENSE files" |
2936597bd30bSMike Kupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
29375d715dd7Skupfer	fi
29385d715dd7Skupferfi
29395d715dd7Skupfer
29407c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
29417c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
29427c478bd9Sstevel@tonic-gate
29437c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
29447c478bd9Sstevel@tonic-gate	save_binaries
29457c478bd9Sstevel@tonic-gatefi
29467c478bd9Sstevel@tonic-gate
29477c478bd9Sstevel@tonic-gate
29487c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
29497c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
2950cdf0c1d5Smjnelson
29517c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2952cdf0c1d5Smjnelson	if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2953cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
29547c478bd9Sstevel@tonic-gate	fi
29557c478bd9Sstevel@tonic-gate
2956cdf0c1d5Smjnelson	if [ $build_ok = y ]; then
2957cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2958cdf0c1d5Smjnelson	fi
2959cdf0c1d5Smjnelsonfi
2960cdf0c1d5Smjnelson
2961cdf0c1d5Smjnelsonif [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
29627c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
29637c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
29647c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
29657c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
29667c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
29677c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
29687c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
29697c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
29707c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
29717c478bd9Sstevel@tonic-gate	else
29727c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
29737c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
29747c478bd9Sstevel@tonic-gate	fi
29757c478bd9Sstevel@tonic-gate
29767c478bd9Sstevel@tonic-gatefi
29777c478bd9Sstevel@tonic-gate
2978cdf0c1d5Smjnelsonif [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
29791fe69678Skupfer	#
29801fe69678Skupfer	# Copy the open sources into their own tree, set up the closed
29814e5b757fSkupfer	# binaries, and set up the environment.  The build looks for
29824e5b757fSkupfer	# the closed binaries in a location that depends on whether
29834e5b757fSkupfer	# it's a DEBUG build, so we might need to make two copies.
29841fe69678Skupfer	#
2985cdf0c1d5Smjnelson	# If copy_source fails, it will have already generated an
2986cdf0c1d5Smjnelson	# error message and set build_ok=n, so we don't need to worry
2987cdf0c1d5Smjnelson	# about that here.
2988cdf0c1d5Smjnelson	#
29891fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2990cdf0c1d5Smjnelsonfi
2991cdf0c1d5Smjnelson
2992cdf0c1d5Smjnelsonif [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
29931fe69678Skupfer
2994b83ec4edSjmcp	echo "\n==== Generating skeleton closed binaries for" \
2995b83ec4edSjmcp	    "open-only build ====\n" | \
2996b83ec4edSjmcp	    tee -a $LOGFILE >> $mail_msg_file
29974e5b757fSkupfer
2998b83ec4edSjmcp	rm -rf $CODEMGR_WS/closed.skel
29994e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
3000b83ec4edSjmcp		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
3001b83ec4edSjmcp		    >>$LOGFILE 2>&1
3002cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
3003b83ec4edSjmcp			echo "Couldn't create skeleton DEBUG closed binaries." |
30041fe69678Skupfer			    tee -a $mail_msg_file >> $LOGFILE
30051fe69678Skupfer		fi
30064e5b757fSkupfer	fi
30074e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
30084e5b757fSkupfer		root=$ROOT
30094e5b757fSkupfer		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
3010b83ec4edSjmcp		mkclosed $MACH $root $CODEMGR_WS/closed.skel/root_$MACH-nd \
30114e5b757fSkupfer		    >>$LOGFILE 2>&1
3012cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
3013b83ec4edSjmcp			echo "Couldn't create skeleton non-DEBUG closed binaries." |
30144e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
30154e5b757fSkupfer		fi
30164e5b757fSkupfer	fi
30174e5b757fSkupfer
3018b83ec4edSjmcp	SRC=$OPEN_SRCDIR/usr/src
3019b83ec4edSjmcp	# Try not to clobber any user-provided closed binaries.
3020b83ec4edSjmcp	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
30214e5b757fSkupfer	export CLOSED_IS_PRESENT=no
30221fe69678Skupferfi
30231fe69678Skupfer
30241fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
30254e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
30264e5b757fSkupfer	rm -rf `allprotos`
30277c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
30284e5b757fSkupfer		set_non_debug_build_flags
3029b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
30301fe69678Skupfer		#
30311fe69678Skupfer		# SRC was set earlier to point to the source build
30321fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
30331fe69678Skupfer		#
30341fe69678Skupfer		TOOLS=${SRC}/tools
3035b06f2c55SMark J. Nelson		TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
3036b06f2c55SMark J. Nelson		build_tools ${TOOLS_PROTO}
3037b06f2c55SMark J. Nelson		if [[ $? != 0 ]]; then
3038b06f2c55SMark J. Nelson			use_tools ${TOOLS_PROTO}
3039b06f2c55SMark J. Nelson		fi
30407c478bd9Sstevel@tonic-gate	fi
30417c478bd9Sstevel@tonic-gate
30427c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
30437c478bd9Sstevel@tonic-gate	normal_build
30447c478bd9Sstevel@tonic-gatefi
30457c478bd9Sstevel@tonic-gate
30461fe69678Skupferif [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
30471fe69678Skupfer	rm -rf $ON_CLOSED_BINS
30481fe69678Skupferfi
30491fe69678Skupfer
30504e5b757fSkupfer#
30514e5b757fSkupfer# There are several checks that need to look at the proto area, but
30524e5b757fSkupfer# they only need to look at one, and they don't care whether it's
30534e5b757fSkupfer# DEBUG or non-DEBUG.
30544e5b757fSkupfer#
30554e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
30564e5b757fSkupfer	checkroot=$ROOT-nd
30574e5b757fSkupferelse
30584e5b757fSkupfer	checkroot=$ROOT
30594e5b757fSkupferfi
30604e5b757fSkupfer
30617c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
30627c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
30637c478bd9Sstevel@tonic-gate		>> $LOGFILE
30644e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
30657c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
30667c478bd9Sstevel@tonic-gate		>> $LOGFILE
30677c478bd9Sstevel@tonic-gate
30687c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
30697c478bd9Sstevel@tonic-gate
3070ead1f93eSLiane Praza		E1=
3071ead1f93eSLiane Praza		f1=
3072ead1f93eSLiane Praza		if [ -d "$SRC/pkgdefs" ]; then
3073ead1f93eSLiane Praza			f1="$SRC/pkgdefs/etc/exception_list_$MACH"
3074ead1f93eSLiane Praza			if [ "$X_FLAG" = "y" ]; then
3075ead1f93eSLiane Praza				f1="$f1 $IA32_IHV_WS/usr/src/pkgdefs/etc/exception_list_$MACH"
30767c478bd9Sstevel@tonic-gate			fi
30776fec3625Sdduvall		fi
30787c478bd9Sstevel@tonic-gate
3079ead1f93eSLiane Praza		for f in $f1; do
3080ead1f93eSLiane Praza			if [ -f "$f" ]; then
3081ead1f93eSLiane Praza				E1="$E1 -e $f"
3082ead1f93eSLiane Praza			fi
3083ead1f93eSLiane Praza		done
3084ead1f93eSLiane Praza
3085ead1f93eSLiane Praza		E2=
3086ead1f93eSLiane Praza		f2=
3087ead1f93eSLiane Praza		if [ -d "$SRC/pkg" ]; then
3088ead1f93eSLiane Praza			f2="$f2 exceptions/packaging"
3089ead1f93eSLiane Praza			if [ "$CLOSED_IS_PRESENT" = "no" ]; then
3090ead1f93eSLiane Praza				f2="$f2 exceptions/packaging.open"
3091ead1f93eSLiane Praza			else
3092ead1f93eSLiane Praza				f2="$f2 exceptions/packaging.closed"
3093ead1f93eSLiane Praza			fi
3094ead1f93eSLiane Praza		fi
3095ead1f93eSLiane Praza
3096ead1f93eSLiane Praza		for f in $f2; do
3097ead1f93eSLiane Praza			if [ -f "$f" ]; then
3098ead1f93eSLiane Praza				E2="$E2 -e $f"
3099ead1f93eSLiane Praza			fi
3100ead1f93eSLiane Praza		done
3101ead1f93eSLiane Praza
31027c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
3103ead1f93eSLiane Praza			#
3104b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
3105b4add148Sdduvall			# IHV proto list to the reference list if the reference
3106b4add148Sdduvall			# was built without -X.
3107b4add148Sdduvall			#
3108b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
3109b4add148Sdduvall			# IHV proto list to the build's proto list if the
3110b4add148Sdduvall			# reference was built with -X.
3111b4add148Sdduvall			#
3112b4add148Sdduvall			# Use the presence of the first file entry of the cached
3113b4add148Sdduvall			# IHV proto list in the reference list to determine
3114ead1f93eSLiane Praza			# whether it was built with -X or not.
3115ead1f93eSLiane Praza			#
3116a51a9b36SMark J. Nelson			IHV_REF_PROTO_LIST=$SRC/pkg/proto_list_ihv_$MACH
3117b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
3118b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
3119b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
3120b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
3121b4add148Sdduvall					grep -w "$grepfor" \
3122b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
3123b4add148Sdduvall					if [ ! "$?" = "0" ]; then
3124b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
3125b4add148Sdduvall					fi
3126b4add148Sdduvall				else
3127b4add148Sdduvall					grep -w "$grepfor" \
3128b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
3129b4add148Sdduvall					if [ "$?" = "0" ]; then
3130b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
3131b4add148Sdduvall					fi
3132b4add148Sdduvall				fi
3133b4add148Sdduvall			fi
3134ead1f93eSLiane Praza		fi
3135ead1f93eSLiane Praza	fi
3136b4add148Sdduvall
313787916a32SMark J. Nelson	if [ "$N_FLAG" != "y" -a -f $SRC/pkgdefs/Makefile ]; then
3138ead1f93eSLiane Praza		echo "\n==== Impact on SVr4 packages ====\n" >> $mail_msg_file
3139ead1f93eSLiane Praza		#
3140ead1f93eSLiane Praza		# Compare the build's proto list with current package
3141ead1f93eSLiane Praza		# definitions to audit the quality of package
3142ead1f93eSLiane Praza		# definitions and makefile install targets. Use the
3143ead1f93eSLiane Praza		# current exception list.
3144ead1f93eSLiane Praza		#
3145ead1f93eSLiane Praza		PKGDEFS_LIST=""
3146ead1f93eSLiane Praza		for d in $abssrcdirs; do
3147ead1f93eSLiane Praza			if [ -d $d/pkgdefs ]; then
3148ead1f93eSLiane Praza				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
3149ead1f93eSLiane Praza			fi
3150ead1f93eSLiane Praza		done
3151ead1f93eSLiane Praza		if [ "$X_FLAG" = "y" -a \
3152ead1f93eSLiane Praza		    -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
3153ead1f93eSLiane Praza			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
3154ead1f93eSLiane Praza		fi
3155ead1f93eSLiane Praza		$PROTOCMPTERSE \
3156ead1f93eSLiane Praza		    "Files missing from the proto area:" \
3157ead1f93eSLiane Praza		    "Files missing from packages:" \
3158ead1f93eSLiane Praza		    "Inconsistencies between pkgdefs and proto area:" \
3159ead1f93eSLiane Praza		    ${E1} \
3160ead1f93eSLiane Praza		    ${PKGDEFS_LIST} \
3161ead1f93eSLiane Praza		    $ATLOG/proto_list_${MACH} \
3162ead1f93eSLiane Praza		    >> $mail_msg_file
3163ead1f93eSLiane Praza	fi
3164ead1f93eSLiane Praza
3165ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
3166ead1f93eSLiane Praza		echo "\n==== Validating manifests against proto area ====\n" \
3167ead1f93eSLiane Praza		    >> $mail_msg_file
3168ead1f93eSLiane Praza		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) \
3169ead1f93eSLiane Praza		    >> $mail_msg_file
3170ead1f93eSLiane Praza
3171ead1f93eSLiane Praza	fi
3172ead1f93eSLiane Praza
3173ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
3174ead1f93eSLiane Praza		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
3175ead1f93eSLiane Praza		if [ -n "$E2" ]; then
3176ead1f93eSLiane Praza			ELIST=$E2
3177ead1f93eSLiane Praza		else
3178ead1f93eSLiane Praza			ELIST=$E1
3179ead1f93eSLiane Praza		fi
31807c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
31817c478bd9Sstevel@tonic-gate			"Files in yesterday's proto area, but not today's:" \
31827c478bd9Sstevel@tonic-gate			"Files in today's proto area, but not yesterday's:" \
31837c478bd9Sstevel@tonic-gate			"Files that changed between yesterday and today:" \
31847c478bd9Sstevel@tonic-gate			${ELIST} \
31857c478bd9Sstevel@tonic-gate			-d $REF_PROTO_LIST \
3186b4add148Sdduvall			$REF_IHV_PROTO \
31877c478bd9Sstevel@tonic-gate			$ATLOG/proto_list_${MACH} \
3188b4add148Sdduvall			$IHV_PROTO_LIST \
31897c478bd9Sstevel@tonic-gate			>> $mail_msg_file
31907c478bd9Sstevel@tonic-gate	fi
31917c478bd9Sstevel@tonic-gatefi
31927c478bd9Sstevel@tonic-gate
31937c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
31947c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
31957c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
31967c478bd9Sstevel@tonic-gatefi
31977c478bd9Sstevel@tonic-gate
31987c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
31997c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
32007c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
32017c478bd9Sstevel@tonic-gate# the variable now.
32027c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
32037c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
32047c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
3205ead1f93eSLiane Praza	rm -rf $NIGHTLY_PARENT_ROOT/*
32067c478bd9Sstevel@tonic-gate	unset Ulockfile
32077c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
32084e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
3209ead1f93eSLiane Praza		( cd $ROOT; tar cf - . |
32104e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
32117c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
32127c478bd9Sstevel@tonic-gate	fi
32134e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
3214ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
32154e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
32164e5b757fSkupfer		cd $ROOT-nd
32174e5b757fSkupfer		( tar cf - . |
32184e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
32194e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
32204e5b757fSkupfer	fi
32216798c3f0SMark J. Nelson	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
3222ead1f93eSLiane Praza		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
3223ead1f93eSLiane Praza		    tee -a $LOGFILE >> $mail_msg_file
3224ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
3225ead1f93eSLiane Praza		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
3226ead1f93eSLiane Praza		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
3227ead1f93eSLiane Praza			( cd $TOOLS_PROTO; tar cf - . |
32286798c3f0SMark J. Nelson			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
32296798c3f0SMark J. Nelson			    umask 0; tar xpf - ) ) 2>&1 |
3230ead1f93eSLiane Praza			    tee -a $mail_msg_file >> $LOGFILE
3231ead1f93eSLiane Praza		fi
32324e5b757fSkupfer	fi
32336798c3f0SMark J. Nelsonfi
32347c478bd9Sstevel@tonic-gate
32357c478bd9Sstevel@tonic-gate#
323675ce41a5SAli Bahrami# ELF verification: ABI (-A) and runtime (-r) checks
32377c478bd9Sstevel@tonic-gate#
323875ce41a5SAli Bahramiif [[ ($build_ok = y) && ( ($A_FLAG = y) || ($r_FLAG = y) ) ]]; then
323975ce41a5SAli Bahrami	# Directory ELF-data.$MACH holds the files produced by these tests.
324075ce41a5SAli Bahrami	elf_ddir=$SRC/ELF-data.$MACH
32417c478bd9Sstevel@tonic-gate
324275ce41a5SAli Bahrami	# If there is a previous ELF-data backup directory, remove it. Then,
324375ce41a5SAli Bahrami	# rotate current ELF-data directory into its place and create a new
324475ce41a5SAli Bahrami	# empty directory
324575ce41a5SAli Bahrami	rm -rf $elf_ddir.ref
324675ce41a5SAli Bahrami	if [[ -d $elf_ddir ]]; then
324775ce41a5SAli Bahrami		mv $elf_ddir $elf_ddir.ref
324875ce41a5SAli Bahrami	fi
324975ce41a5SAli Bahrami	mkdir -p $elf_ddir
325075ce41a5SAli Bahrami
325175ce41a5SAli Bahrami	# Call find_elf to produce a list of the ELF objects in the proto area.
325275ce41a5SAli Bahrami	# This list is passed to check_rtime and interface_check, preventing
325375ce41a5SAli Bahrami	# them from separately calling find_elf to do the same work twice.
325475ce41a5SAli Bahrami	find_elf -fr $checkroot > $elf_ddir/object_list
325575ce41a5SAli Bahrami
325675ce41a5SAli Bahrami	if [[ $A_FLAG = y ]]; then
32577c478bd9Sstevel@tonic-gate	       	echo "\n==== Check versioning and ABI information ====\n"  | \
32587c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
32597c478bd9Sstevel@tonic-gate
326075ce41a5SAli Bahrami		# Produce interface description for the proto. Report errors.
326175ce41a5SAli Bahrami		interface_check -o -w $elf_ddir -f object_list \
326275ce41a5SAli Bahrami			-i interface -E interface.err
326375ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.err ]]; then
326475ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.err \
326575ce41a5SAli Bahrami				>> $mail_msg_file
32667c478bd9Sstevel@tonic-gate		fi
32677c478bd9Sstevel@tonic-gate
326875ce41a5SAli Bahrami	       	echo "\n==== Compare versioning and ABI information to" \
326975ce41a5SAli Bahrami		    "baseline ====\n"  | tee -a $LOGFILE >> $mail_msg_file
32707c478bd9Sstevel@tonic-gate
327175ce41a5SAli Bahrami		# Compare new interface to baseline interface. Report errors.
327275ce41a5SAli Bahrami		interface_cmp -d -o $SRC/tools/abi/interface.$MACH \
327375ce41a5SAli Bahrami			$elf_ddir/interface > $elf_ddir/interface.cmp
327475ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.cmp ]]; then
327575ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.cmp \
327675ce41a5SAli Bahrami				>> $mail_msg_file
32777c478bd9Sstevel@tonic-gate		fi
32787c478bd9Sstevel@tonic-gate	fi
32797c478bd9Sstevel@tonic-gate
328075ce41a5SAli Bahrami	if [[ $r_FLAG = y ]]; then
32817c478bd9Sstevel@tonic-gate		echo "\n==== Check ELF runtime attributes ====\n" | \
32827c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
32837c478bd9Sstevel@tonic-gate
3284ead1f93eSLiane Praza		# If we're doing a DEBUG build the proto area will be left
328575ce41a5SAli Bahrami		# with debuggable objects, thus don't assert -s.
328675ce41a5SAli Bahrami		if [[ $D_FLAG = y ]]; then
32877c478bd9Sstevel@tonic-gate			rtime_sflag=""
32887c478bd9Sstevel@tonic-gate		else
32897c478bd9Sstevel@tonic-gate			rtime_sflag="-s"
32907c478bd9Sstevel@tonic-gate		fi
329175ce41a5SAli Bahrami		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
329275ce41a5SAli Bahrami			-D object_list  -f object_list -E runtime.err \
3293622090e3SAli Bahrami			-I runtime.attr.raw
3294622090e3SAli Bahrami
3295622090e3SAli Bahrami		# check_rtime -I output needs to be sorted in order to
3296622090e3SAli Bahrami		# compare it to that from previous builds.
3297622090e3SAli Bahrami		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
3298622090e3SAli Bahrami		rm $elf_ddir/runtime.attr.raw
32997c478bd9Sstevel@tonic-gate
330075ce41a5SAli Bahrami		# Report errors
330175ce41a5SAli Bahrami		if [[ -s $elf_ddir/runtime.err ]]; then
330275ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/runtime.err \
33037c478bd9Sstevel@tonic-gate				>> $mail_msg_file
330475ce41a5SAli Bahrami		fi
33057c478bd9Sstevel@tonic-gate
330675ce41a5SAli Bahrami		# If there is an ELF-data directory from a previous build,
330775ce41a5SAli Bahrami		# then diff the attr files. These files contain information
330875ce41a5SAli Bahrami		# about dependencies, versioning, and runpaths. There is some
330975ce41a5SAli Bahrami		# overlap with the ABI checking done above, but this also
331075ce41a5SAli Bahrami		# flushes out non-ABI interface differences along with the
331175ce41a5SAli Bahrami		# other information.
331275ce41a5SAli Bahrami		echo "\n==== Diff ELF runtime attributes" \
331375ce41a5SAli Bahrami		    "(since last build) ====\n" | \
331475ce41a5SAli Bahrami		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
331575ce41a5SAli Bahrami
331675ce41a5SAli Bahrami		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
331775ce41a5SAli Bahrami			diff $elf_ddir.ref/runtime.attr \
331875ce41a5SAli Bahrami				$elf_ddir/runtime.attr \
331975ce41a5SAli Bahrami				>> $mail_msg_file
332075ce41a5SAli Bahrami		fi
332175ce41a5SAli Bahrami	fi
33227c478bd9Sstevel@tonic-gatefi
33237c478bd9Sstevel@tonic-gate
33247c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
33257c478bd9Sstevel@tonic-gate
33267c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
33277c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
33287c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
33297c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
33307c478bd9Sstevel@tonic-gate	fi
33317c478bd9Sstevel@tonic-gate	set $LINTDIRS
33327c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
33337c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
33347c478bd9Sstevel@tonic-gate	done
33357c478bd9Sstevel@tonic-gateelse
33367c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
33377c478bd9Sstevel@tonic-gatefi
33387c478bd9Sstevel@tonic-gate
33397c478bd9Sstevel@tonic-gate# "make check" begins
33407c478bd9Sstevel@tonic-gate
33417c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
33427c478bd9Sstevel@tonic-gate	# remove old check.out
33437c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
33447c478bd9Sstevel@tonic-gate
33457c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
33467c478bd9Sstevel@tonic-gate	cd $SRC
33477c478bd9Sstevel@tonic-gate	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
33487c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
33497c478bd9Sstevel@tonic-gate
33507c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
33517c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
33527c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
33537c478bd9Sstevel@tonic-gateelse
33547c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
33557c478bd9Sstevel@tonic-gatefi
33567c478bd9Sstevel@tonic-gate
33577c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
33587c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
33597c478bd9Sstevel@tonic-gate
3360fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
33617c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
33627c478bd9Sstevel@tonic-gate
33637c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
33647c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
33657c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
33667c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
33677c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
33687c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
33697c478bd9Sstevel@tonic-gate	fi
33707c478bd9Sstevel@tonic-gate
33719730304dSmeem	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
3372cdf0c1d5Smjnelson	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
33739730304dSmeem	    sort > $SRC/unref-${MACH}.out
33747c478bd9Sstevel@tonic-gate
33757c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
33767c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
33777c478bd9Sstevel@tonic-gate	fi
33787c478bd9Sstevel@tonic-gate
33797c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
33807c478bd9Sstevel@tonic-gatefi
33817c478bd9Sstevel@tonic-gate
33825d715dd7Skupfer#
33835d715dd7Skupfer# Generate the OpenSolaris deliverables if requested.  Some of these
33845d715dd7Skupfer# steps need to come after findunref and are commented below.
33855d715dd7Skupfer#
3386597bd30bSMike Kupfer
3387597bd30bSMike Kupfer#
3388597bd30bSMike Kupfer# Copy an input crypto tarball to the canonical destination (with
3389597bd30bSMike Kupfer# datestamp), and point the non-stamped symlink at it.
3390597bd30bSMike Kupfer# Usage: copycrypto from_path suffix
3391597bd30bSMike Kupfer# Returns 0 if successful, non-zero if not.
3392597bd30bSMike Kupfer#
3393597bd30bSMike Kupferfunction copycrypto {
3394597bd30bSMike Kupfer	typeset from=$1
3395597bd30bSMike Kupfer	typeset suffix=$2
3396597bd30bSMike Kupfer	typeset to=$(cryptodest "$suffix").bz2
3397597bd30bSMike Kupfer	typeset -i stat
3398597bd30bSMike Kupfer	cp "$from" "$to"
3399597bd30bSMike Kupfer	stat=$?
3400597bd30bSMike Kupfer	if (( $stat == 0 )); then
3401597bd30bSMike Kupfer		cryptolink "$to" "$suffix"
3402597bd30bSMike Kupfer		stat=$?
3403597bd30bSMike Kupfer	fi
3404597bd30bSMike Kupfer	return $stat
3405597bd30bSMike Kupfer}
3406597bd30bSMike Kupfer
3407597bd30bSMike Kupfer#
3408597bd30bSMike Kupfer# Pass through the crypto tarball(s) that we were given, putting it in
3409597bd30bSMike Kupfer# the same place that crypto_from_proto puts things.
3410597bd30bSMike Kupfer#
3411597bd30bSMike Kupferfunction crypto_passthrough {
3412597bd30bSMike Kupfer	echo "Reusing $ON_CRYPTO_BINS for crypto tarball(s)..." >> "$LOGFILE"
3413597bd30bSMike Kupfer	if [ "$D_FLAG" = y ]; then
3414597bd30bSMike Kupfer		copycrypto "$ON_CRYPTO_BINS" "" >> "$LOGFILE" 2>&1
3415597bd30bSMike Kupfer		if (( $? != 0 )) ; then
3416597bd30bSMike Kupfer			echo "Couldn't create DEBUG crypto tarball." |
3417597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
3418597bd30bSMike Kupfer		fi
3419597bd30bSMike Kupfer	fi
3420597bd30bSMike Kupfer	if [ "$F_FLAG" = n ]; then
3421597bd30bSMike Kupfer		copycrypto $(ndcrypto "$ON_CRYPTO_BINS") "-nd" \
3422597bd30bSMike Kupfer		    >> "$LOGFILE" 2>&1
3423597bd30bSMike Kupfer		if (( $? != 0 )) ; then
3424597bd30bSMike Kupfer			echo "Couldn't create non-DEBUG crypto tarball." |
3425597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
3426597bd30bSMike Kupfer		fi
3427597bd30bSMike Kupfer	fi
3428597bd30bSMike Kupfer}
3429597bd30bSMike Kupfer
3430b83ec4edSjmcp# If we are doing an OpenSolaris _source_ build (-S O) then we do
3431b83ec4edSjmcp# not have usr/closed available to us to generate closedbins from,
3432b83ec4edSjmcp# so skip this part.
3433b83ec4edSjmcpif [ "$SO_FLAG" = n -a "$O_FLAG" = y -a "$build_ok" = y ]; then
34345d715dd7Skupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
34355d715dd7Skupfer	    tee -a $mail_msg_file >> $LOGFILE
34365d715dd7Skupfer
34375d715dd7Skupfer	cd $CODEMGR_WS
34385d715dd7Skupfer
34395d715dd7Skupfer	#
3440ead1f93eSLiane Praza	# This step grovels through the package manifests, so it
34415d715dd7Skupfer	# must come after findunref.
34425d715dd7Skupfer	#
3443ead1f93eSLiane Praza	# We assume no DEBUG vs non-DEBUG package content variation
3444ead1f93eSLiane Praza	# here; if that changes, then the "make all" in $SRC/pkg will
3445ead1f93eSLiane Praza	# need to be moved into the conditionals and repeated for each
3446ead1f93eSLiane Praza	# different build.
3447ead1f93eSLiane Praza	#
34485d715dd7Skupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
34495d715dd7Skupfer	closed_basename=on-closed-bins
34505d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
3451b83ec4edSjmcp		bindrop "$closed_basename" >>"$LOGFILE" 2>&1
3452cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
34535d715dd7Skupfer			echo "Couldn't create DEBUG closed binaries." |
34545d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
34555d715dd7Skupfer		fi
34565d715dd7Skupfer	fi
34575d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
3458b83ec4edSjmcp		bindrop -n "$closed_basename-nd" >>"$LOGFILE" 2>&1
3459cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
34605d715dd7Skupfer			echo "Couldn't create non-DEBUG closed binaries." |
34615d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
34625d715dd7Skupfer		fi
34635d715dd7Skupfer	fi
34645d715dd7Skupfer
34655d715dd7Skupfer	echo "Generating README.opensolaris..." >> $LOGFILE
34665d715dd7Skupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
34675d715dd7Skupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
3468cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
34695d715dd7Skupfer		echo "Couldn't create README.opensolaris." |
34705d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
34715d715dd7Skupfer	fi
34725d715dd7Skupfer
3473597bd30bSMike Kupfer	if [ -n "$ON_CRYPTO_BINS" ]; then
3474597bd30bSMike Kupfer		crypto_passthrough
3475597bd30bSMike Kupfer	fi
34765d715dd7Skupferfi
34775d715dd7Skupfer
34787c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
34797c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
34807c478bd9Sstevel@tonic-gate# then don't check the proto area.
34817c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
34827c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
34837c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
34847c478bd9Sstevel@tonic-gate		>>$mail_msg_file
34857c478bd9Sstevel@tonic-gate	arg=-b
34867c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
34874e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
34887c478bd9Sstevel@tonic-gatefi
34897c478bd9Sstevel@tonic-gate
34907c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
34917c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
34927c478bd9Sstevel@tonic-gate		>> $mail_msg_file
3493ead1f93eSLiane Praza
3494ead1f93eSLiane Praza	abspkgdefs=
3495ead1f93eSLiane Praza	abspkg=
3496ead1f93eSLiane Praza	for d in $abssrcdirs; do
3497ead1f93eSLiane Praza		if [ -d "$d/pkgdefs" ]; then
3498ead1f93eSLiane Praza			abspkgdefs="$abspkgdefs $d"
34997c478bd9Sstevel@tonic-gate		fi
3500ead1f93eSLiane Praza		if [ -d "$d/pkg" ]; then
3501ead1f93eSLiane Praza			abspkg="$abspkg $d"
3502ead1f93eSLiane Praza		fi
3503ead1f93eSLiane Praza	done
3504ead1f93eSLiane Praza
3505ead1f93eSLiane Praza	if [ -n "$abspkgdefs" ]; then
3506ead1f93eSLiane Praza		pmodes -qvdP \
3507ead1f93eSLiane Praza		    `find $abspkgdefs -name pkginfo.tmpl -print -o \
3508ead1f93eSLiane Praza		    -name .del\* -prune | sed -e 's:/pkginfo.tmpl$::' | \
3509ead1f93eSLiane Praza		    sort -u` >> $mail_msg_file
3510ead1f93eSLiane Praza	fi
3511ead1f93eSLiane Praza
3512ead1f93eSLiane Praza	if [ -n "$abspkg" ]; then
3513ead1f93eSLiane Praza		for d in "$abspkg"; do
3514ead1f93eSLiane Praza			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
3515ead1f93eSLiane Praza		done
3516ead1f93eSLiane Praza	fi
35177c478bd9Sstevel@tonic-gatefi
35187c478bd9Sstevel@tonic-gate
351996ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
35204e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
35214e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
35224e5b757fSkupfer	fi
352396ccc8cbSesaxe
35244e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
35254e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
352696ccc8cbSesaxe	fi
352796ccc8cbSesaxefi
352896ccc8cbSesaxe
35297c478bd9Sstevel@tonic-gateEND_DATE=`date`
35307c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
35317c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
35327c478bd9Sstevel@tonic-gate
3533c341b28aSDarren Moffattypeset -i10 hours
35347c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
35357c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
35367c478bd9Sstevel@tonic-gate
35377c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
35387c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
35397c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
35407c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
35417c478bd9Sstevel@tonic-gate
35427c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
35437c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
35447c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
35457c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
35467c478bd9Sstevel@tonic-gate
35477c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
35487c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
35497c478bd9Sstevel@tonic-gate
35507c478bd9Sstevel@tonic-gate	#
35517c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
35527c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
35537c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
35547c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
35557c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
35567c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
35577c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
35587c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
35597c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
35607c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
35617c478bd9Sstevel@tonic-gate	# which was already on the parent.
35627c478bd9Sstevel@tonic-gate	#
35637c478bd9Sstevel@tonic-gate
35647c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
35657c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
35667c478bd9Sstevel@tonic-gate	shift
35677c478bd9Sstevel@tonic-gate
35687c478bd9Sstevel@tonic-gate	for unreffile; do
35697c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
35707c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
35717c478bd9Sstevel@tonic-gate	done
35727c478bd9Sstevel@tonic-gate
35737c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
35747c478bd9Sstevel@tonic-gatefi
35757c478bd9Sstevel@tonic-gate
35767c478bd9Sstevel@tonic-gate#
35777c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
35787c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
35797c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
35807c478bd9Sstevel@tonic-gate#
35817c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
35827c478bd9Sstevel@tonic-gate	exit 0
35837c478bd9Sstevel@tonic-gatefi
35847c478bd9Sstevel@tonic-gateexit 1
3585