xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision 597bd30ba830d1e11c8efdb9a1b9de28e0599f5e)
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#
24*597bd30bSMike Kupfer# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
287c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
297c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
327c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
337c478bd9Sstevel@tonic-gate#
347c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
35d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
36d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
377c478bd9Sstevel@tonic-gate#
387c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
437c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
447c478bd9Sstevel@tonic-gate#
457c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
487c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
497c478bd9Sstevel@tonic-gate#
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate#
527c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
537c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
547c478bd9Sstevel@tonic-gate#
557c478bd9Sstevel@tonic-gateunset CDPATH
567c478bd9Sstevel@tonic-gate
57cdf0c1d5Smjnelson# Get the absolute path of the nightly script that the user invoked.  This
58cdf0c1d5Smjnelson# may be a relative path, and we need to do this before changing directory.
59cdf0c1d5Smjnelsonnightly_path=`whence $0`
6030635de9SJohn.Zolnowsky@Sun.COMnightly_ls="`ls -l $nightly_path`"
61cdf0c1d5Smjnelson
62cdf0c1d5Smjnelson#
63cdf0c1d5Smjnelson# Keep track of where we found nightly so we can invoke the matching
64cdf0c1d5Smjnelson# which_scm script.  If that doesn't work, don't go guessing, just rely
65cdf0c1d5Smjnelson# on the $PATH settings, which will generally give us either /opt/onbld
66cdf0c1d5Smjnelson# or the user's workspace.
67cdf0c1d5Smjnelson#
68cdf0c1d5SmjnelsonWHICH_SCM=$(dirname $nightly_path)/which_scm
69cdf0c1d5Smjnelsonif [[ ! -x $WHICH_SCM ]]; then
70cdf0c1d5Smjnelson	WHICH_SCM=which_scm
71cdf0c1d5Smjnelsonfi
72cdf0c1d5Smjnelson
734e5b757fSkupfer#
74*597bd30bSMike Kupfer# Datestamp for crypto tarballs.  We don't use BUILD_DATE because it
75*597bd30bSMike Kupfer# doesn't sort right and it uses English abbreviations for the month.
76*597bd30bSMike Kupfer# We want to guarantee a consistent string, so just invoke date(1)
77*597bd30bSMike Kupfer# once and save the result in a global variable.  YYYY-MM-DD is easier
78*597bd30bSMike Kupfer# to parse visually than YYYYMMDD.
79*597bd30bSMike Kupfer#
80*597bd30bSMike Kupfercryptostamp=$(date +%Y-%m-%d)
81*597bd30bSMike Kupfer
82*597bd30bSMike Kupfer#
83*597bd30bSMike Kupfer# Echo the path for depositing a crypto tarball, creating the target
84*597bd30bSMike Kupfer# directory if it doesn't already exist.
85*597bd30bSMike Kupfer# usage: cryptodest suffix
86*597bd30bSMike Kupfer# where "suffix" is "" or "-nd".
87*597bd30bSMike Kupfer#
88*597bd30bSMike Kupferfunction cryptodest {
89*597bd30bSMike Kupfer	typeset suffix=$1
90*597bd30bSMike Kupfer	#
91*597bd30bSMike Kupfer	# $PKGARCHIVE gets wiped out with each build, so put the
92*597bd30bSMike Kupfer	# tarball one level up.
93*597bd30bSMike Kupfer	#
94*597bd30bSMike Kupfer	typeset dir=$(dirname "$PKGARCHIVE")
95*597bd30bSMike Kupfer	[ -d "$dir" ] || mkdir -p "$dir" >> "$LOGFILE" 2>&1
96*597bd30bSMike Kupfer	#
97*597bd30bSMike Kupfer	# Put the suffix after the datestamp to make it easier for
98*597bd30bSMike Kupfer	# gatelings to use crypto from a specific date (no need to
99*597bd30bSMike Kupfer	# copy and rename the gate tarball).
100*597bd30bSMike Kupfer	#
101*597bd30bSMike Kupfer	echo "$dir/on-crypto-$cryptostamp$suffix.$MACH.tar"
102*597bd30bSMike Kupfer}
103*597bd30bSMike Kupfer
104*597bd30bSMike Kupfer#
105*597bd30bSMike Kupfer# Create a non-stamped symlink to the given crypto tarball.
106*597bd30bSMike Kupfer# Return 0 on success, non-zero on failure.
107*597bd30bSMike Kupfer#
108*597bd30bSMike Kupferfunction cryptolink {
109*597bd30bSMike Kupfer	typeset targpath=$1
110*597bd30bSMike Kupfer	typeset suffix=$2
111*597bd30bSMike Kupfer	if [ ! -f "$targpath" ]; then
112*597bd30bSMike Kupfer		echo "no crypto at $targpath"
113*597bd30bSMike Kupfer		return 1
114*597bd30bSMike Kupfer	fi
115*597bd30bSMike Kupfer	typeset dir=$(dirname "$targpath")
116*597bd30bSMike Kupfer	typeset targfile=$(basename "$targpath")
117*597bd30bSMike Kupfer	typeset link=on-crypto$suffix.$MACH.tar.bz2
118*597bd30bSMike Kupfer	(cd "$dir"; rm -f "$link")
119*597bd30bSMike Kupfer	(cd "$dir"; ln -s "$targfile" "$link")
120*597bd30bSMike Kupfer	return $?
121*597bd30bSMike Kupfer}
122*597bd30bSMike Kupfer
123*597bd30bSMike Kupfer#
124*597bd30bSMike Kupfer# Generate a crypto tarball from the proto area and put it in the
125*597bd30bSMike Kupfer# canonical location, along with the datestamp-free symlink.
126*597bd30bSMike Kupfer# Sets build_ok to "n" if there is a problem.
127*597bd30bSMike Kupfer#
128*597bd30bSMike Kupferfunction crypto_from_proto {
129*597bd30bSMike Kupfer	typeset label=$1
130*597bd30bSMike Kupfer	typeset suffix=$2
131*597bd30bSMike Kupfer	typeset -i stat
132*597bd30bSMike Kupfer	typeset to
133*597bd30bSMike Kupfer
134*597bd30bSMike Kupfer	echo "Creating $label crypto tarball..." >> "$LOGFILE"
135*597bd30bSMike Kupfer
136*597bd30bSMike Kupfer	#
137*597bd30bSMike Kupfer	# Generate the crypto THIRDPARTYLICENSE file.  This needs to
138*597bd30bSMike Kupfer	# be done after the build has finished and before we run
139*597bd30bSMike Kupfer	# cryptodrop.  We'll generate the file twice if we're building
140*597bd30bSMike Kupfer	# both debug and non-debug, but it's a cheap operation and not
141*597bd30bSMike Kupfer	# worth the complexity to only do once.
142*597bd30bSMike Kupfer	#
143*597bd30bSMike Kupfer	mktpl -c usr/src/tools/opensolaris/license-list >> "$LOGFILE" 2>&1
144*597bd30bSMike Kupfer	if (( $? != 0 )) ; then
145*597bd30bSMike Kupfer		echo "Couldn't create crypto THIRDPARTYLICENSE file." |
146*597bd30bSMike Kupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
147*597bd30bSMike Kupfer		build_ok=n
148*597bd30bSMike Kupfer		return
149*597bd30bSMike Kupfer	fi
150*597bd30bSMike Kupfer
151*597bd30bSMike Kupfer	to=$(cryptodest "$suffix")
152*597bd30bSMike Kupfer	if [ "$suffix" = "-nd" ]; then
153*597bd30bSMike Kupfer		cryptodrop -n "$to" >> "$LOGFILE" 2>&1
154*597bd30bSMike Kupfer	else
155*597bd30bSMike Kupfer		cryptodrop "$to" >> "$LOGFILE" 2>&1
156*597bd30bSMike Kupfer	fi
157*597bd30bSMike Kupfer	if (( $? != 0 )) ; then
158*597bd30bSMike Kupfer		echo "\nCould not create $label crypto tarball." |
159*597bd30bSMike Kupfer		   tee -a "$mail_msg_file" >> "$LOGFILE"
160*597bd30bSMike Kupfer		build_ok=n
161*597bd30bSMike Kupfer	else
162*597bd30bSMike Kupfer		cryptolink "$to.bz2" "$suffix" >> "$LOGFILE" 2>&1
163*597bd30bSMike Kupfer		if (( $? != 0 )) ; then
164*597bd30bSMike Kupfer			build_ok=n
165*597bd30bSMike Kupfer		fi
166*597bd30bSMike Kupfer	fi
167*597bd30bSMike Kupfer}
168*597bd30bSMike Kupfer
169*597bd30bSMike Kupfer#
1704e5b757fSkupfer# Print the tag string used to identify a build (e.g., "DEBUG
1714e5b757fSkupfer# open-only")
1724e5b757fSkupfer# usage: tagstring debug-part open-part
1734e5b757fSkupfer#
174*597bd30bSMike Kupferfunction tagstring {
1754e5b757fSkupfer	debug_part=$1
1764e5b757fSkupfer	open_part=$2
1774e5b757fSkupfer
1784e5b757fSkupfer	if [ -n "$open_part" ]; then
1794e5b757fSkupfer		echo "$debug_part $open_part"
1804e5b757fSkupfer	else
1814e5b757fSkupfer		echo "$debug_part"
1824e5b757fSkupfer	fi
1834e5b757fSkupfer}
1844e5b757fSkupfer
1854e5b757fSkupfer#
1864e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
1877c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
1887c478bd9Sstevel@tonic-gate# non-DEBUG packages.
1894e5b757fSkupfer#
1904e5b757fSkupfer# usage: normal_build [-O]
19152a52aebSkupfer# -O	OpenSolaris delivery build.  Put the proto area and
19252a52aebSkupfer#	(eventually) packages in -open directories.  Use skeleton
19352a52aebSkupfer#	closed binaries.  Don't generate archives--that needs to be
194*597bd30bSMike Kupfer#	done later, after we've generated the closed binaries.  Use
195*597bd30bSMike Kupfer#	the signed binaries from the earlier full build.  Skip the
196*597bd30bSMike Kupfer#	package build (until 6414822 is fixed).
1974e5b757fSkupfer#
1987c478bd9Sstevel@tonic-gate
199*597bd30bSMike Kupferfunction normal_build {
2007c478bd9Sstevel@tonic-gate
20152a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
20252a52aebSkupfer	typeset orig_a_FLAG="$a_FLAG"
20311a78ea0SMark J. Nelson	typeset orig_zero_FLAG="$zero_FLAG"
204*597bd30bSMike Kupfer	typeset crypto_in="$ON_CRYPTO_BINS"
205*597bd30bSMike Kupfer	typeset crypto_signer="$CODESIGN_USER"
206*597bd30bSMike Kupfer	typeset gencrypto=no
2074e5b757fSkupfer
2084e5b757fSkupfer	suffix=""
2094e5b757fSkupfer	open_only=""
210*597bd30bSMike Kupfer	[ -n "$CODESIGN_USER" ] && gencrypto=yes
2114e5b757fSkupfer	while getopts O FLAG $*; do
2124e5b757fSkupfer		case $FLAG in
2134e5b757fSkupfer		O)
2144e5b757fSkupfer			suffix="-open"
2154e5b757fSkupfer			open_only="open-only"
2164e5b757fSkupfer			p_FLAG=n
21752a52aebSkupfer			a_FLAG=n
21811a78ea0SMark J. Nelson			zero_FLAG=n
219*597bd30bSMike Kupfer			gencrypto=no
220*597bd30bSMike Kupfer			if [ -n "$CODESIGN_USER" ]; then
221*597bd30bSMike Kupfer				#
222*597bd30bSMike Kupfer				# Crypto doesn't get signed in the
223*597bd30bSMike Kupfer				# open-only build (no closed tree ->
224*597bd30bSMike Kupfer				# no internal signing -> no signing
225*597bd30bSMike Kupfer				# for off-SWAN).  So use the earlier
226*597bd30bSMike Kupfer				# signed crypto.
227*597bd30bSMike Kupfer				#
228*597bd30bSMike Kupfer				crypto_in=$PKGARCHIVE/../on-crypto.$MACH.tar.bz2
229*597bd30bSMike Kupfer				crypto_signer=""
230*597bd30bSMike Kupfer			fi
2314e5b757fSkupfer			;;
2324e5b757fSkupfer		esac
2334e5b757fSkupfer	done
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
2384e5b757fSkupfer		set_non_debug_build_flags
2394e5b757fSkupfer		mytag=`tagstring "non-DEBUG" "$open_only"`
240*597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
241*597bd30bSMike Kupfer		    build "$mytag" "$suffix-nd" "-nd" "$MULTI_PROTO" \
242*597bd30bSMike Kupfer		    $(ndcrypto "$crypto_in")
2434e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
2444e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
2457c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
2467c478bd9Sstevel@tonic-gate		fi
247*597bd30bSMike Kupfer
248*597bd30bSMike Kupfer		if [[ "$gencrypto" = yes && "$build_ok" = y ]]; then
249*597bd30bSMike Kupfer			crypto_from_proto non-DEBUG -nd
250*597bd30bSMike Kupfer		fi
251*597bd30bSMike Kupfer
2527c478bd9Sstevel@tonic-gate	else
25352a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
2547c478bd9Sstevel@tonic-gate	fi
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate	# DEBUG build begins
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
2614e5b757fSkupfer		set_debug_build_flags
2624e5b757fSkupfer		mytag=`tagstring "DEBUG" "$open_only"`
263*597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
264*597bd30bSMike Kupfer		    build "$mytag" "$suffix" "" "$MULTI_PROTO" "$crypto_in"
2654e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
2664e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
2677c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
2687c478bd9Sstevel@tonic-gate		fi
2697c478bd9Sstevel@tonic-gate
270*597bd30bSMike Kupfer		if [[ "$gencrypto" = yes && "$build_ok" = y ]]; then
271*597bd30bSMike Kupfer			crypto_from_proto DEBUG ""
272*597bd30bSMike Kupfer		fi
273*597bd30bSMike Kupfer
2747c478bd9Sstevel@tonic-gate	else
27552a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
2767c478bd9Sstevel@tonic-gate	fi
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate	# DEBUG build ends
2794e5b757fSkupfer
28052a52aebSkupfer	p_FLAG="$orig_p_FLAG"
28152a52aebSkupfer	a_FLAG="$orig_a_FLAG"
28211a78ea0SMark J. Nelson	zero_FLAG="$orig_zero_FLAG"
2837c478bd9Sstevel@tonic-gate}
2847c478bd9Sstevel@tonic-gate
2851fe69678Skupfer#
28647703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
28747703246Ssommerfe#
28847703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
28947703246Ssommerfe# our logs and then run the command with ARGS
29047703246Ssommerfe#
291*597bd30bSMike Kupferfunction run_hook {
29247703246Ssommerfe	HOOKNAME=$1
29347703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
29447703246Ssommerfe	shift
29547703246Ssommerfe
29647703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
29747703246Ssommerfe	    	(
29847703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
29947703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
30047703246Ssommerfe			if [ "$?" -ne 0 ]; then
30147703246Ssommerfe			    	# Let exit status propagate up
30247703246Ssommerfe			    	touch $TMPDIR/abort
30347703246Ssommerfe			fi
30447703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
30547703246Ssommerfe
30647703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
30747703246Ssommerfe			build_ok=n
30847703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
30947703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
31047703246Ssommerfe			exit 1
31147703246Ssommerfe		fi
31247703246Ssommerfe	fi
31347703246Ssommerfe}
31447703246Ssommerfe
31547703246Ssommerfe#
3161fe69678Skupfer# usage: filelist DESTDIR PATTERN
3171fe69678Skupfer#
318*597bd30bSMike Kupferfunction filelist {
3197c478bd9Sstevel@tonic-gate	DEST=$1
3207c478bd9Sstevel@tonic-gate	PATTERN=$2
3217c478bd9Sstevel@tonic-gate	cd ${DEST}
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
3247c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
3257c478bd9Sstevel@tonic-gate		return;
3267c478bd9Sstevel@tonic-gate	fi
3271fe69678Skupfer	for i in `grep -v '^#' ${OBJFILES} | \
3287c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
3297c478bd9Sstevel@tonic-gate	do
3307c478bd9Sstevel@tonic-gate		# wildcard expansion
3317c478bd9Sstevel@tonic-gate		for j in $i
3327c478bd9Sstevel@tonic-gate		do
3337c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
3347c478bd9Sstevel@tonic-gate				echo $j
3357c478bd9Sstevel@tonic-gate			fi
3367c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
3377c478bd9Sstevel@tonic-gate				echo $j
3387c478bd9Sstevel@tonic-gate			fi
3397c478bd9Sstevel@tonic-gate		done
3407c478bd9Sstevel@tonic-gate	done | sort | uniq
3417c478bd9Sstevel@tonic-gate}
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
3447c478bd9Sstevel@tonic-gate# restoration
345*597bd30bSMike Kupferfunction save_binaries {
3467c478bd9Sstevel@tonic-gate	# save off list of binaries
3477c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
3487c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3497c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
3507c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
3517c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
3527c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
3537c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
3547c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
3557c478bd9Sstevel@tonic-gate}
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate# delete files
3581fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
359*597bd30bSMike Kupferfunction hybridize_files {
3607c478bd9Sstevel@tonic-gate	DEST=$1
3617c478bd9Sstevel@tonic-gate	MAKETARG=$2
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
3647c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3657c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
3667c478bd9Sstevel@tonic-gate	do
3677c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
3687c478bd9Sstevel@tonic-gate		rm -rf "${i}"
3697c478bd9Sstevel@tonic-gate	done
3707c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
3717c478bd9Sstevel@tonic-gate	do
3727c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
3737c478bd9Sstevel@tonic-gate		rm -f ${i}+
3747c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
3757c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
3767c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
3777c478bd9Sstevel@tonic-gate	done
3787c478bd9Sstevel@tonic-gate}
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
3811fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
382*597bd30bSMike Kupferfunction restore_binaries {
3837c478bd9Sstevel@tonic-gate	DEST=$1
3847c478bd9Sstevel@tonic-gate	MAKETARG=$2
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
3877c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3887c478bd9Sstevel@tonic-gate	cd ${DEST}
3897c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
3907c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
3917c478bd9Sstevel@tonic-gate}
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate# rename files we save binaries of
3941fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
395*597bd30bSMike Kupferfunction rename_files {
3967c478bd9Sstevel@tonic-gate	DEST=$1
3977c478bd9Sstevel@tonic-gate	MAKETARG=$2
3987c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
3997c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
4007c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
4017c478bd9Sstevel@tonic-gate	do
4027c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
4037c478bd9Sstevel@tonic-gate		rm -f ${i}.export
4047c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
4057c478bd9Sstevel@tonic-gate	done
4067c478bd9Sstevel@tonic-gate}
4077c478bd9Sstevel@tonic-gate
4081fe69678Skupfer#
4091fe69678Skupfer# Copy some or all of the source tree.
410cdf0c1d5Smjnelson#
411cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
412cdf0c1d5Smjnelson#
4131fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
4141fe69678Skupfer#
415*597bd30bSMike Kupferfunction copy_source {
4167c478bd9Sstevel@tonic-gate	WS=$1
4177c478bd9Sstevel@tonic-gate	DEST=$2
4181fe69678Skupfer	label=$3
4191fe69678Skupfer	srcroot=$4
4207c478bd9Sstevel@tonic-gate
421cdf0c1d5Smjnelson	printf "\n==== Creating %s source from %s (%s) ====\n\n" \
422cdf0c1d5Smjnelson	    "$DEST" "$WS" "$label" | tee -a $mail_msg_file >> $LOGFILE
423cdf0c1d5Smjnelson
424cdf0c1d5Smjnelson	printf "cleaning out %s\n" "$DEST." >> $LOGFILE
425cdf0c1d5Smjnelson	rm -rf "$DEST" >> $LOGFILE 2>&1
426cdf0c1d5Smjnelson
427cdf0c1d5Smjnelson	printf "creating %s\n" "$DEST." >> $LOGFILE
428cdf0c1d5Smjnelson	mkdir -p "$DEST" 2>> $LOGFILE
429cdf0c1d5Smjnelson
430cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
431cdf0c1d5Smjnelson		printf "failed to create %s\n" "$DEST" |
4327c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
433cdf0c1d5Smjnelson		build_ok=n
434cdf0c1d5Smjnelson		return 1
435cdf0c1d5Smjnelson	fi
436cdf0c1d5Smjnelson	cd "$WS"
4377c478bd9Sstevel@tonic-gate
438cdf0c1d5Smjnelson	printf "populating %s\n" "$DEST." >> $LOGFILE
4397c478bd9Sstevel@tonic-gate
440cdf0c1d5Smjnelson	case "$SCM_TYPE" in
441cdf0c1d5Smjnelson	teamware)
4421fe69678Skupfer		find $srcroot -name 's\.*' -a -type f -print | \
4437c478bd9Sstevel@tonic-gate		    sed -e 's,SCCS\/s.,,' | \
4447c478bd9Sstevel@tonic-gate		    grep -v '/\.del-*' | \
445cdf0c1d5Smjnelson		    cpio -pd $DEST >>$LOGFILE 2>&1
446cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
447cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$DEST" |
448cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
449cdf0c1d5Smjnelson		    build_ok=n
450cdf0c1d5Smjnelson		    return 1
451cdf0c1d5Smjnelson		fi
452cdf0c1d5Smjnelson		;;
453cdf0c1d5Smjnelson	mercurial)
454cdf0c1d5Smjnelson		copy_source_mercurial $DEST $srcroot
455cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
456cdf0c1d5Smjnelson		    build_ok=n
457cdf0c1d5Smjnelson		    return 1
458cdf0c1d5Smjnelson		fi
459cdf0c1d5Smjnelson		;;
460cdf0c1d5Smjnelson	*)
461cdf0c1d5Smjnelson		build_ok=n
462cdf0c1d5Smjnelson		echo "Tree copy is not supported for workspace type" \
463cdf0c1d5Smjnelson		    "$SCM_TYPE" | tee -a $mail_msg_file >> $LOGFILE
464cdf0c1d5Smjnelson		return 1
465cdf0c1d5Smjnelson		;;
466cdf0c1d5Smjnelson	esac
467cdf0c1d5Smjnelson
468cdf0c1d5Smjnelson	return 0
469cdf0c1d5Smjnelson}
470cdf0c1d5Smjnelson
471cdf0c1d5Smjnelson#
472cdf0c1d5Smjnelson# Mercurial-specific copy code for copy_source().  Handles the
473cdf0c1d5Smjnelson# combined open and closed trees.
474cdf0c1d5Smjnelson#
475cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
476cdf0c1d5Smjnelson#
477cdf0c1d5Smjnelson# usage: copy_source_mercurial destdir srcroot
478cdf0c1d5Smjnelson#
479cdf0c1d5Smjnelsonfunction copy_source_mercurial {
480cdf0c1d5Smjnelson	typeset dest=$1
481cdf0c1d5Smjnelson	typeset srcroot=$2
482cdf0c1d5Smjnelson	typeset open_top closed_top
483cdf0c1d5Smjnelson
484cdf0c1d5Smjnelson	case $srcroot in
485cdf0c1d5Smjnelson	usr)
486cdf0c1d5Smjnelson		open_top=usr
487cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = yes ]]; then
488cdf0c1d5Smjnelson			closed_top=usr/closed
489cdf0c1d5Smjnelson		fi
490cdf0c1d5Smjnelson		;;
491cdf0c1d5Smjnelson	usr/closed*)
492cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = no ]]; then
493cdf0c1d5Smjnelson			printf "can't copy %s: closed tree not present.\n" \
494cdf0c1d5Smjnelson			    "$srcroot" | tee -a $mail_msg_file >> $LOGFILE
495cdf0c1d5Smjnelson			return 1
496cdf0c1d5Smjnelson		fi
497cdf0c1d5Smjnelson		closed_top="$srcroot"
498cdf0c1d5Smjnelson		;;
499cdf0c1d5Smjnelson	*)
500cdf0c1d5Smjnelson		open_top="$srcroot"
501cdf0c1d5Smjnelson		;;
502cdf0c1d5Smjnelson	esac
503cdf0c1d5Smjnelson
504cdf0c1d5Smjnelson	if [[ -n "$open_top" ]]; then
505cdf0c1d5Smjnelson		hg locate -I "$open_top" | cpio -pd "$dest" >>$LOGFILE 2>&1
506cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
507cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$dest" |
508cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
509cdf0c1d5Smjnelson		    return 1
510cdf0c1d5Smjnelson		fi
511cdf0c1d5Smjnelson	fi
512cdf0c1d5Smjnelson
513cdf0c1d5Smjnelson	if [[ -n "$closed_top" ]]; then
514cdf0c1d5Smjnelson		mkdir -p "$dest/usr/closed" || return 1
515cdf0c1d5Smjnelson		if [[ "$closed_top" = usr/closed ]]; then
516cdf0c1d5Smjnelson			(cd usr/closed; hg locate |
517cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
518cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
519cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed\n" \
520cdf0c1d5Smjnelson				"$dest" | tee -a $mail_msg_file >> $LOGFILE
521cdf0c1d5Smjnelson			    return 1
522cdf0c1d5Smjnelson			fi
523cdf0c1d5Smjnelson		else
524cdf0c1d5Smjnelson			# copy subtree of usr/closed
525cdf0c1d5Smjnelson			closed_top=${closed_top#usr/closed/}
526cdf0c1d5Smjnelson			(cd usr/closed; hg locate -I "$closed_top" |
527cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
528cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
529cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed/%s\n" \
530cdf0c1d5Smjnelson				"$dest" "$closed_top" |
531cdf0c1d5Smjnelson				tee -a $mail_msg_file >> $LOGFILE
532cdf0c1d5Smjnelson			    return 1
533cdf0c1d5Smjnelson			fi
534cdf0c1d5Smjnelson		fi
535cdf0c1d5Smjnelson	fi
536cdf0c1d5Smjnelson
537cdf0c1d5Smjnelson	return 0
5381fe69678Skupfer}
5397c478bd9Sstevel@tonic-gate
5401fe69678Skupfer#
5411fe69678Skupfer# function to create (but not build) the export/crypt source tree.
5421fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
5431fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
5441fe69678Skupfer# builds the tree.
5451fe69678Skupfer#
546*597bd30bSMike Kupferfunction set_up_source_build {
5471fe69678Skupfer	WS=$1
5481fe69678Skupfer	DEST=$2
5491fe69678Skupfer	MAKETARG=$3
5501fe69678Skupfer
5511fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
552cdf0c1d5Smjnelson	if (( $? != 0 )); then
553cdf0c1d5Smjnelson	    echo "\nCould not copy source tree for source build." |
554cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
555cdf0c1d5Smjnelson	    build_ok=n
556cdf0c1d5Smjnelson	    return
557cdf0c1d5Smjnelson	fi
558cdf0c1d5Smjnelson
5597c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate	cd $SRC
5627c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
5637c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
5647c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
5657c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
5667c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
5677c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
5687c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
5697c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
5707c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
5737c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate	cd ${DEST}
5767c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
5777c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
5787c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
5797c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
5807c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
5817c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
5827c478bd9Sstevel@tonic-gate		do
5837c478bd9Sstevel@tonic-gate			# make sure the files exist
5847c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
5857c478bd9Sstevel@tonic-gate				continue
5867c478bd9Sstevel@tonic-gate			fi
5877c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
5887c478bd9Sstevel@tonic-gate				continue
5897c478bd9Sstevel@tonic-gate			fi
5907c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
5917c478bd9Sstevel@tonic-gate		done
5927c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
5937c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
5947c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
5957c478bd9Sstevel@tonic-gate	fi
5967c478bd9Sstevel@tonic-gate
5977c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
5987c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
5997c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
6007c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
6017c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
6027c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
6037c478bd9Sstevel@tonic-gate		fi
6047c478bd9Sstevel@tonic-gate	fi
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate	# save the cleartext
6077c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
6087c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
6097c478bd9Sstevel@tonic-gate	cd ${DEST}
6107c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
611fb23a357Skupfer	find usr -depth -print | \
6127c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
6137c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
6147c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
6157c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
6167c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
6177c478bd9Sstevel@tonic-gate	fi
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
6207c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
6217c478bd9Sstevel@tonic-gate	fi
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate}
6247c478bd9Sstevel@tonic-gate
6254e5b757fSkupfer# Return library search directive as function of given root.
626*597bd30bSMike Kupferfunction myldlibs {
6274e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
6284e5b757fSkupfer}
6297c478bd9Sstevel@tonic-gate
6304e5b757fSkupfer# Return header search directive as function of given root.
631*597bd30bSMike Kupferfunction myheaders {
6324e5b757fSkupfer	echo "-I$1/usr/include"
6334e5b757fSkupfer}
6344e5b757fSkupfer
6354e5b757fSkupfer#
63652a52aebSkupfer# Wrapper over commands that generate BFU archives.  The entire
63752a52aebSkupfer# command output gets written to LOGFILE, and any unexpected messages
63852a52aebSkupfer# are written to the mail message.  Returns with the status of the
63952a52aebSkupfer# original command.
64052a52aebSkupfer#
641*597bd30bSMike Kupferfunction makebfu_filt {
64252a52aebSkupfer	typeset tmplog
64352a52aebSkupfer	typeset errors
64452a52aebSkupfer	typeset cmd
64552a52aebSkupfer	integer cmd_stat
64652a52aebSkupfer
64752a52aebSkupfer	cmd="$1"
64852a52aebSkupfer	shift
64952a52aebSkupfer	tmplog="$TMPDIR/$cmd.out"
65052a52aebSkupfer	errors="$TMPDIR/$cmd-errors"
65152a52aebSkupfer	$cmd $* > "$tmplog" 2>&1
65252a52aebSkupfer	cmd_stat=$?
65352a52aebSkupfer	cat "$tmplog" >> "$LOGFILE"
65452a52aebSkupfer	grep -v "^Creating .* archive:" "$tmplog" | grep -v "^Making" | \
65552a52aebSkupfer	    grep -v "^$" | sort -u > "$errors"
65652a52aebSkupfer	if [[ -s "$errors" ]]; then
65752a52aebSkupfer		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
65852a52aebSkupfer		    >> "$mail_msg_file"
65952a52aebSkupfer		cat "$errors" >> "$mail_msg_file"
66052a52aebSkupfer	fi
66152a52aebSkupfer	rm -f "$tmplog" "$errors"
66252a52aebSkupfer	return $cmd_stat
66352a52aebSkupfer}
66452a52aebSkupfer
66552a52aebSkupfer#
666*597bd30bSMike Kupfer# Unpack the crypto tarball into the proto area.  We first extract the
667*597bd30bSMike Kupfer# tarball into a temp directory so that we can handle the non-debug
668*597bd30bSMike Kupfer# tarball correctly with MULTI_PROTO=no.
669*597bd30bSMike Kupfer# Return 0 on success, non-zero on failure.
670*597bd30bSMike Kupfer#
671*597bd30bSMike Kupferfunction unpack_crypto {
672*597bd30bSMike Kupfer	typeset tarfile=$1
673*597bd30bSMike Kupfer	typeset suffix=$2
674*597bd30bSMike Kupfer	typeset ctop=$(mktemp -d /tmp/crypto.XXXXXX)
675*597bd30bSMike Kupfer	[ -n "$ctop" ] || return 1
676*597bd30bSMike Kupfer	typeset croot=$ctop/proto/root_$MACH$suffix
677*597bd30bSMike Kupfer	echo "Unpacking crypto ($tarfile)..."
678*597bd30bSMike Kupfer	bzcat "$tarfile" | (cd "$ctop"; tar xfBp -)
679*597bd30bSMike Kupfer	if [[ $? -ne 0 || ! -d "$croot" ]]; then
680*597bd30bSMike Kupfer		return 1
681*597bd30bSMike Kupfer	fi
682*597bd30bSMike Kupfer	#
683*597bd30bSMike Kupfer	# We extract with -p so that we maintain permissions on directories.
684*597bd30bSMike Kupfer	#
685*597bd30bSMike Kupfer	(cd "$croot"; tar cf - *) | (cd "$ROOT"; tar xfBp -)
686*597bd30bSMike Kupfer	typeset -i stat=$?
687*597bd30bSMike Kupfer	rm -rf "$ctop"
688*597bd30bSMike Kupfer	return $stat
689*597bd30bSMike Kupfer}
690*597bd30bSMike Kupfer
691*597bd30bSMike Kupfer#
6924e5b757fSkupfer# Function to do the build, including cpio archive and package generation.
693*597bd30bSMike Kupfer# usage: build LABEL SUFFIX ND MULTIPROTO CRYPTO
6944e5b757fSkupfer# - LABEL is used to tag build output.
695*597bd30bSMike Kupfer# - SUFFIX is used to distinguish files (e.g., debug vs non-debug,
696*597bd30bSMike Kupfer#   open-only vs full tree).
697*597bd30bSMike Kupfer# - ND is "-nd" (non-debug builds) or "" (debug builds).
6984e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
6994e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
700*597bd30bSMike Kupfer# - CRYPTO is the path to the crypto tarball, or null.
7014e5b757fSkupfer#
702*597bd30bSMike Kupferfunction build {
7037c478bd9Sstevel@tonic-gate	LABEL=$1
7047c478bd9Sstevel@tonic-gate	SUFFIX=$2
705*597bd30bSMike Kupfer	ND=$3
706*597bd30bSMike Kupfer	MULTIPROTO=$4
707*597bd30bSMike Kupfer	CRYPTOPATH=$5
7087c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
7097c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
7107c478bd9Sstevel@tonic-gate	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
7117c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
712d8fd4470Sjg	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
713d8fd4470Sjg		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
714d8fd4470Sjg	fi
7157c478bd9Sstevel@tonic-gate
7164e5b757fSkupfer	ORIGROOT=$ROOT
7174e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
7184e5b757fSkupfer
7194e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
7204e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
7214e5b757fSkupfer
7227c478bd9Sstevel@tonic-gate	this_build_ok=y
7237c478bd9Sstevel@tonic-gate	#
7247c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
7257c478bd9Sstevel@tonic-gate	#
7267c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
7277c478bd9Sstevel@tonic-gate		>> $LOGFILE
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
7307c478bd9Sstevel@tonic-gate	cd $SRC
7317c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
7327c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
73332f1e47bSsommerfe
734cdf0c1d5Smjnelson	if [[ "$SCM_TYPE" = teamware ]]; then
73532f1e47bSsommerfe		echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
736cdf0c1d5Smjnelson		egrep 'sccs(check:| *get)' $SRC/${INSTALLOG}.out >> \
737cdf0c1d5Smjnelson			$mail_msg_file
738cdf0c1d5Smjnelson	fi
73932f1e47bSsommerfe
7407c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
7417c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
7427c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
7437c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
7447c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
7457c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
7467c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
7477c478bd9Sstevel@tonic-gate		build_ok=n
7487c478bd9Sstevel@tonic-gate		this_build_ok=n
7497c478bd9Sstevel@tonic-gate	fi
7507c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
7517c478bd9Sstevel@tonic-gate		>> $mail_msg_file
7527c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
7537c478bd9Sstevel@tonic-gate		build_ok=n
7547c478bd9Sstevel@tonic-gate		this_build_ok=n
7557c478bd9Sstevel@tonic-gate	fi
7567c478bd9Sstevel@tonic-gate
757*597bd30bSMike Kupfer	if [ -n "$CRYPTOPATH" ]; then
758*597bd30bSMike Kupfer		unpack_crypto "$CRYPTOPATH" "$ND" >> "$LOGFILE" 2>&1
759*597bd30bSMike Kupfer		if (( $? != 0 )) ; then
760*597bd30bSMike Kupfer			echo "Could not unpack crypto ($CRYPTOPATH)" |
761*597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
762*597bd30bSMike Kupfer			build_ok=n
763*597bd30bSMike Kupfer			this_build_ok=n
764*597bd30bSMike Kupfer		fi
765*597bd30bSMike Kupfer	fi
766*597bd30bSMike Kupfer
7677c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
7687c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
7697c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
7707c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
7717c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
7727c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
7737c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
7747c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
7757c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7767c478bd9Sstevel@tonic-gate	fi
7777c478bd9Sstevel@tonic-gate
7787c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
7797c478bd9Sstevel@tonic-gate		>> $LOGFILE
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
7827c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
7837c478bd9Sstevel@tonic-gate
7847c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
7857c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
7867c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
7877c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
7887c478bd9Sstevel@tonic-gate		fi
7897c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
7907c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
7917c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
7927c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
7937c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
7947c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
7957c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
7967c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
7977c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
7987c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
7997c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
8007c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
8017c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
8027c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
8037c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
8047c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
8057c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
8067c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
8077c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
8087c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
8097c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
8107c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
8117c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
8127c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
8137c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
8147c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
8157c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
8167c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
8177c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
8187c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
8197c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
8207c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
8217c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
8227c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
8237c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
8247c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
8257c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
8267c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
8277c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
8287c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
8297c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
8307c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
8317c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
8327c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
8337c478bd9Sstevel@tonic-gate			| egrep -v '::' \
8347c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
835010b217aSwesolows			| egrep -v '^\+' \
83603eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
837c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
8387c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
8397c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
8407c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
8417c478bd9Sstevel@tonic-gate		fi
8427c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
8437c478bd9Sstevel@tonic-gate			>>$mail_msg_file
8447c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
8457c478bd9Sstevel@tonic-gate	fi
8467c478bd9Sstevel@tonic-gate
8477c478bd9Sstevel@tonic-gate	#
84823259b79Srotondo	#	Re-sign selected binaries using signing server
84923259b79Srotondo	#	(gatekeeper builds only)
85023259b79Srotondo	#
8512210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
85223259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
85323259b79Srotondo		signing_file="${TMPDIR}/signing"
85423259b79Srotondo		rm -f ${signing_file}
85523259b79Srotondo		export CODESIGN_USER
85623259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
85723259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
85823259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
85923259b79Srotondo		    >> $LOGFILE
86023259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
86123259b79Srotondo		    >> $mail_msg_file
86223259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
863cdf0c1d5Smjnelson		if (( $? == 0 )) ; then
8642210853dSjohnz			build_ok=n
8652210853dSjohnz			this_build_ok=n
8662210853dSjohnz		fi
86723259b79Srotondo	fi
86823259b79Srotondo
86923259b79Srotondo	#
8707c478bd9Sstevel@tonic-gate	#	Create cpio archives for preintegration testing (PIT)
8717c478bd9Sstevel@tonic-gate	#
8727c478bd9Sstevel@tonic-gate	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
8737c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
8747c478bd9Sstevel@tonic-gate			>> $LOGFILE
87552a52aebSkupfer		makebfu_filt makebfu
8767c478bd9Sstevel@tonic-gate		# hack for test folks
8777c478bd9Sstevel@tonic-gate		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
8787c478bd9Sstevel@tonic-gate			X=/net/`uname -n`${CPIODIR}
8797c478bd9Sstevel@tonic-gate		else
8807c478bd9Sstevel@tonic-gate			X=${CPIODIR}
8817c478bd9Sstevel@tonic-gate		fi
8827c478bd9Sstevel@tonic-gate		echo "Archive_directory: ${X}" >${TMPDIR}/f
8839a6d9a08Sdm120769		cp ${TMPDIR}/f $(dirname $(dirname ${CPIODIR}))/.${MACH}_wgtrun
8847c478bd9Sstevel@tonic-gate		rm -f ${TMPDIR}/f
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate	else
8877c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL cpio archives ====\n" \
8887c478bd9Sstevel@tonic-gate			>> $LOGFILE
8897c478bd9Sstevel@tonic-gate	fi
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate	#
8927c478bd9Sstevel@tonic-gate	#	Building Packages
8937c478bd9Sstevel@tonic-gate	#
8947c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
8957c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL packages at `date` ====\n" \
8967c478bd9Sstevel@tonic-gate			>> $LOGFILE
8977c478bd9Sstevel@tonic-gate		rm -f $SRC/pkgdefs/${INSTALLOG}.out
898*597bd30bSMike Kupfer		echo "Clearing out $PKGARCHIVE ..." >> "$LOGFILE"
899*597bd30bSMike Kupfer		rm -rf "$PKGARCHIVE" >> "$LOGFILE" 2>&1
900*597bd30bSMike Kupfer		mkdir -p "$PKGARCHIVE" >> "$LOGFILE" 2>&1
901d8fd4470Sjg
902d8fd4470Sjg		#
903d8fd4470Sjg		# Optional build of sparc realmode on i386
904d8fd4470Sjg		#
905d8fd4470Sjg		if [ "$MACH" = "i386" ] && [ "${SPARC_RM_PKGARCHIVE}" ]; then
906d8fd4470Sjg			echo "Clearing out ${SPARC_RM_PKGARCHIVE} ..." \
907d8fd4470Sjg				>> $LOGFILE
908*597bd30bSMike Kupfer			rm -rf ${SPARC_RM_PKGARCHIVE} >> "$LOGFILE" 2>&1
909*597bd30bSMike Kupfer			mkdir -p ${SPARC_RM_PKGARCHIVE} >> "$LOGFILE" 2>&1
910d8fd4470Sjg		fi
911d8fd4470Sjg
9127c478bd9Sstevel@tonic-gate		cd $SRC/pkgdefs
9137c478bd9Sstevel@tonic-gate		$MAKE -e install 2>&1 | \
9147c478bd9Sstevel@tonic-gate			tee -a $SRC/pkgdefs/${INSTALLOG}.out >> $LOGFILE
9157c478bd9Sstevel@tonic-gate		echo "\n==== Package build errors ($LABEL) ====\n" \
9167c478bd9Sstevel@tonic-gate			>> $mail_msg_file
9177c478bd9Sstevel@tonic-gate		egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/${INSTALLOG}.out | \
9187c478bd9Sstevel@tonic-gate			grep ':' | \
9197c478bd9Sstevel@tonic-gate			grep -v PSTAMP | \
9207c478bd9Sstevel@tonic-gate			egrep -v "Ignoring unknown host" \
9217c478bd9Sstevel@tonic-gate			>> $mail_msg_file
9227c478bd9Sstevel@tonic-gate	else
9237c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
9247c478bd9Sstevel@tonic-gate	fi
9254e5b757fSkupfer
9265d3b8cb7SBill Sommerfeld	if [[ "$zero_FLAG" = "y" ]]; then
9275d3b8cb7SBill Sommerfeld		if [[ -d "${G11N_PKGDIR}" ]]; then
9285d3b8cb7SBill Sommerfeld			echo "\n==== Building globalization package" \
9295d3b8cb7SBill Sommerfeld			    "$(basename ${G11N_PKGDIR}) ($LABEL) ====\n" \
9305d3b8cb7SBill Sommerfeld			    >> $LOGFILE
9315d3b8cb7SBill Sommerfeld			cd $G11N_PKGDIR
9325d3b8cb7SBill Sommerfeld			/bin/time $MAKE -e install 2>&1 | \
9335d3b8cb7SBill Sommerfeld			    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
9345d3b8cb7SBill Sommerfeld			cd $SRC
9355d3b8cb7SBill Sommerfeld		else
9365d3b8cb7SBill Sommerfeld			echo "\n==== Skipping nonexistent globalization" \
9375d3b8cb7SBill Sommerfeld			    "package $(basename ${G11N_PKGDIR})" \
9385d3b8cb7SBill Sommerfeld			    "($LABEL) ====\n" >> $LOGFILE
9395d3b8cb7SBill Sommerfeld		fi
9405d3b8cb7SBill Sommerfeld	fi
9415d3b8cb7SBill Sommerfeld
9424e5b757fSkupfer	ROOT=$ORIGROOT
9437c478bd9Sstevel@tonic-gate}
9447c478bd9Sstevel@tonic-gate
9451fe69678Skupfer# Usage: dolint /dir y|n
9467c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
947*597bd30bSMike Kupferfunction dolint {
9487c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
9491fe69678Skupfer		echo "dolint error: $1 is not a directory"
9507c478bd9Sstevel@tonic-gate		exit 1
9517c478bd9Sstevel@tonic-gate	fi
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
9541fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
9557c478bd9Sstevel@tonic-gate		exit 1
9567c478bd9Sstevel@tonic-gate	fi
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate	lintdir=$1
9597c478bd9Sstevel@tonic-gate	dodiff=$2
9607c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
9617c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
9627c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
9634e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
9644e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
9657c478bd9Sstevel@tonic-gate
9664e5b757fSkupfer	set_debug_build_flags
9677c478bd9Sstevel@tonic-gate
9687c478bd9Sstevel@tonic-gate	#
9697c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
9707c478bd9Sstevel@tonic-gate	#
9717c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gate	# remove old lint.out
9747c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
9757c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
9767c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
9777c478bd9Sstevel@tonic-gate	fi
9787c478bd9Sstevel@tonic-gate
9797c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
9807c478bd9Sstevel@tonic-gate	cd $lintdir
9817c478bd9Sstevel@tonic-gate	#
9827c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
9837c478bd9Sstevel@tonic-gate	#
9847c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
985cdf0c1d5Smjnelson	    `find . \( -name SCCS -o -name .hg -o -name .svn \) \
986cdf0c1d5Smjnelson	    	-prune -o -type f -name '*.ln' -print `
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
9897c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
9907c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
9917c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
9927c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
9937c478bd9Sstevel@tonic-gate		>> $mail_msg_file
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
9967c478bd9Sstevel@tonic-gate
9977c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
9987c478bd9Sstevel@tonic-gate		>>$mail_msg_file
9997c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
10027c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
10037c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
10047c478bd9Sstevel@tonic-gate	fi
10057c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
10067c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
10077c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
10087c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
10097c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
10107c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
10117c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
10127c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
10137c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
10147c478bd9Sstevel@tonic-gate	fi
10157c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
10167c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
10177c478bd9Sstevel@tonic-gate			>>$mail_msg_file
10187c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
10197c478bd9Sstevel@tonic-gate		# above
10207c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
10217c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
10227c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
10237c478bd9Sstevel@tonic-gate			>> $mail_msg_file
10247c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
10257c478bd9Sstevel@tonic-gate			>> $mail_msg_file
10267c478bd9Sstevel@tonic-gate	fi
10277c478bd9Sstevel@tonic-gate}
10287c478bd9Sstevel@tonic-gate
10297c478bd9Sstevel@tonic-gate# Install proto area from IHV build
10307c478bd9Sstevel@tonic-gate
1031*597bd30bSMike Kupferfunction copy_ihv_proto {
10327c478bd9Sstevel@tonic-gate
10336fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
10347c478bd9Sstevel@tonic-gate		>> $LOGFILE
10357c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
10367c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
10377c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
10387c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
10397c478bd9Sstevel@tonic-gate		fi
10406fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
10417c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
10427c478bd9Sstevel@tonic-gate		tar -cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10437c478bd9Sstevel@tonic-gate	else
10447c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
10457c478bd9Sstevel@tonic-gate	fi
10464e5b757fSkupfer
10474e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
10484e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
10494e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
10504e5b757fSkupfer			mkdir -p $ROOT-nd
10514e5b757fSkupfer		fi
10524e5b757fSkupfer		# If there's a non-debug version of the IHV proto area,
10534e5b757fSkupfer		# copy it, but copy something if there's not.
10544e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
10554e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
10564e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
10574e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
10584e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
10594e5b757fSkupfer			cd $IA32_IHV_ROOT
10604e5b757fSkupfer		else
10614e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
10624e5b757fSkupfer			return
10634e5b757fSkupfer		fi
10644e5b757fSkupfer		tar -cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10654e5b757fSkupfer	fi
10667c478bd9Sstevel@tonic-gate}
10677c478bd9Sstevel@tonic-gate
10687c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
10691fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
1070*597bd30bSMike Kupferfunction copy_ihv_pkgs {
10717c478bd9Sstevel@tonic-gate	LABEL=$1
10727c478bd9Sstevel@tonic-gate	SUFFIX=$2
10737c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
10747c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
10757c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
10767c478bd9Sstevel@tonic-gate
10777c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
10787c478bd9Sstevel@tonic-gate		>> $LOGFILE
10797c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
10807c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
10817c478bd9Sstevel@tonic-gate		tar -cf - * | \
10827c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10837c478bd9Sstevel@tonic-gate	else
10847c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
10857c478bd9Sstevel@tonic-gate	fi
10867c478bd9Sstevel@tonic-gate
10877c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
10887c478bd9Sstevel@tonic-gate		>> $LOGFILE
10897c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
10907c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
10917c478bd9Sstevel@tonic-gate		tar -cf - * | \
10927c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
10937c478bd9Sstevel@tonic-gate	else
10947c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
10957c478bd9Sstevel@tonic-gate	fi
10967c478bd9Sstevel@tonic-gate}
10977c478bd9Sstevel@tonic-gate
10984e5b757fSkupfer#
10994e5b757fSkupfer# Build and install the onbld tools.
11004e5b757fSkupfer#
11011fe69678Skupfer# usage: build_tools DESTROOT
11024e5b757fSkupfer#
11034e5b757fSkupfer# returns non-zero status if the build was successful.
11044e5b757fSkupfer#
1105*597bd30bSMike Kupferfunction build_tools {
11067c478bd9Sstevel@tonic-gate	DESTROOT=$1
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
11097c478bd9Sstevel@tonic-gate
11107c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
11117c478bd9Sstevel@tonic-gate		>> $LOGFILE
11127c478bd9Sstevel@tonic-gate
11137c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
11147c478bd9Sstevel@tonic-gate	cd ${TOOLS}
11157c478bd9Sstevel@tonic-gate	/bin/time $MAKE ROOT=${DESTROOT} -e install 2>&1 | \
11167c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
11177c478bd9Sstevel@tonic-gate
11187c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
11197c478bd9Sstevel@tonic-gate
11207c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
11217c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
11227c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
11237c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
11244e5b757fSkupfer	return $?
11254e5b757fSkupfer}
11264e5b757fSkupfer
11274e5b757fSkupfer#
11284e5b757fSkupfer# Set up to use locally installed tools.
11294e5b757fSkupfer#
11304e5b757fSkupfer# usage: use_tools TOOLSROOT
11314e5b757fSkupfer#
1132*597bd30bSMike Kupferfunction use_tools {
11334e5b757fSkupfer	TOOLSROOT=$1
11344e5b757fSkupfer
11354e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
11367c478bd9Sstevel@tonic-gate	export STABS
11374e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
11387c478bd9Sstevel@tonic-gate	export CTFSTABS
11394e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
11407c478bd9Sstevel@tonic-gate	export GENOFFSETS
11417c478bd9Sstevel@tonic-gate
11424e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
11437c478bd9Sstevel@tonic-gate	export CTFCONVERT
11444e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
11457c478bd9Sstevel@tonic-gate	export CTFMERGE
11467c478bd9Sstevel@tonic-gate
11474e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
11487c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
11494e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
11507c478bd9Sstevel@tonic-gate	export CTFFINDMOD
11517c478bd9Sstevel@tonic-gate
11527c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
11534e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
11547c478bd9Sstevel@tonic-gate	else
11554e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
11567c478bd9Sstevel@tonic-gate	fi
11577c478bd9Sstevel@tonic-gate	export ELFSIGN
11587c478bd9Sstevel@tonic-gate
11594e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
11604e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
11617c478bd9Sstevel@tonic-gate	export PATH
11627c478bd9Sstevel@tonic-gate
11631d9a8b8dSDan Mick	ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
11641d9a8b8dSDan Mick	export ONBLD_TOOLS
11651d9a8b8dSDan Mick
11667c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
11677c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
11687c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
11697c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
11707c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
11717c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
11727c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
11737c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
11747c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
11751d9a8b8dSDan Mick	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
11767c478bd9Sstevel@tonic-gate}
11777c478bd9Sstevel@tonic-gate
1178*597bd30bSMike Kupferfunction staffer {
11797c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
11807c478bd9Sstevel@tonic-gate		"$@"
11817c478bd9Sstevel@tonic-gate	else
11827c478bd9Sstevel@tonic-gate		arg="\"$1\""
11837c478bd9Sstevel@tonic-gate		shift
11847c478bd9Sstevel@tonic-gate		for i
11857c478bd9Sstevel@tonic-gate		do
11867c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
11877c478bd9Sstevel@tonic-gate		done
11887c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
11897c478bd9Sstevel@tonic-gate	fi
11907c478bd9Sstevel@tonic-gate}
11917c478bd9Sstevel@tonic-gate
1192085d331dSkupfer#
1193085d331dSkupfer# Verify that the closed tree is present if it needs to be.
1194085d331dSkupfer# Sets CLOSED_IS_PRESENT for future use.
1195085d331dSkupfer#
1196*597bd30bSMike Kupferfunction check_closed_tree {
1197085d331dSkupfer	if [ -z "$CLOSED_IS_PRESENT" ]; then
11985c53ea7aSmjnelson		if [ -d $CODEMGR_WS/usr/closed ]; then
1199085d331dSkupfer			CLOSED_IS_PRESENT="yes"
1200085d331dSkupfer		else
1201085d331dSkupfer			CLOSED_IS_PRESENT="no"
1202085d331dSkupfer		fi
1203085d331dSkupfer		export CLOSED_IS_PRESENT
1204085d331dSkupfer	fi
1205085d331dSkupfer	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
1206085d331dSkupfer		#
1207085d331dSkupfer		# If it's an old (pre-split) tree or an empty
1208085d331dSkupfer		# workspace, don't complain.
1209085d331dSkupfer		#
1210085d331dSkupfer		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
1211085d331dSkupfer			echo "If the closed sources are not present," \
1212085d331dSkupfer			    "ON_CLOSED_BINS"
1213085d331dSkupfer			echo "must point to the closed binaries tree."
1214cdf0c1d5Smjnelson			build_ok=n
1215085d331dSkupfer			exit 1
1216085d331dSkupfer		fi
1217085d331dSkupfer	fi
1218085d331dSkupfer}
12197c478bd9Sstevel@tonic-gate
1220*597bd30bSMike Kupferfunction obsolete_build {
1221d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
1222d77e7149Ssommerfe}
1223d77e7149Ssommerfe
12244e5b757fSkupfer#
12254e5b757fSkupfer# wrapper over wsdiff.
12264e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
12274e5b757fSkupfer#
1228*597bd30bSMike Kupferfunction do_wsdiff {
12294e5b757fSkupfer	label=$1
12304e5b757fSkupfer	oldproto=$2
12314e5b757fSkupfer	newproto=$3
12324e5b757fSkupfer
12334e5b757fSkupfer	echo "\n==== Objects that differ since last build ($label) ====\n" | \
12344e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
12354e5b757fSkupfer
12364e5b757fSkupfer	wsdiff="wsdiff"
12374e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
12384e5b757fSkupfer
12394e5b757fSkupfer	$wsdiff -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
12404e5b757fSkupfer		    tee -a $LOGFILE >> $mail_msg_file
12414e5b757fSkupfer}
12424e5b757fSkupfer
12434e5b757fSkupfer#
12444e5b757fSkupfer# Functions for setting build flags (debug/non-debug).  Keep them
12454e5b757fSkupfer# together.
12464e5b757fSkupfer#
12474e5b757fSkupfer
1248*597bd30bSMike Kupferfunction set_non_debug_build_flags {
12494e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
12504e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
12514e5b757fSkupfer	unset EXTRA_OPTIONS
12524e5b757fSkupfer	unset EXTRA_CFLAGS
12534e5b757fSkupfer}
12544e5b757fSkupfer
1255*597bd30bSMike Kupferfunction set_debug_build_flags {
12564e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
12574e5b757fSkupfer	unset RELEASE_BUILD
12584e5b757fSkupfer	unset EXTRA_OPTIONS
12594e5b757fSkupfer	unset EXTRA_CFLAGS
12604e5b757fSkupfer}
12614e5b757fSkupfer
1262d77e7149Ssommerfe
12637c478bd9Sstevel@tonic-gateMACH=`uname -p`
12647c478bd9Sstevel@tonic-gate
12657c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
12667c478bd9Sstevel@tonic-gate	OPTHOME=/opt
12677c478bd9Sstevel@tonic-gate	export OPTHOME
12687c478bd9Sstevel@tonic-gatefi
12697c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
12707c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
12717c478bd9Sstevel@tonic-gate	export TEAMWARE
12727c478bd9Sstevel@tonic-gatefi
12737c478bd9Sstevel@tonic-gate
12741fe69678SkupferUSAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H|O ] <env_file>
12757c478bd9Sstevel@tonic-gate
12767c478bd9Sstevel@tonic-gateWhere:
1277d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
12787c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
12797c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
12807c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
12817c478bd9Sstevel@tonic-gate		E - build exportable source
12827c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
12837c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
12841fe69678Skupfer		O - build (only) open source
12857c478bd9Sstevel@tonic-gate
12867c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
12877c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
12887c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
12897c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
12907c478bd9Sstevel@tonic-gate
12917c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
12927c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
12937c478bd9Sstevel@tonic-gate
129411a78ea0SMark J. Nelson	-0	build the globalization package
12957c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
12967c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
12977c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
12987c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
129911a78ea0SMark J. Nelson	-G	gate keeper default group of options (-0au)
13007c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
13017c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
13027c478bd9Sstevel@tonic-gate	-N	do not run protocmp
13034e5b757fSkupfer	-O	generate OpenSolaris deliverables
13047c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
13057c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
13067c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
130704a42e3eSszhou	-X	copy x86 IHV proto area
13087c478bd9Sstevel@tonic-gate	-a	create cpio archives
13097c478bd9Sstevel@tonic-gate	-f	find unreferenced files
13107c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
13117c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
13127c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
13137c478bd9Sstevel@tonic-gate	-n      do not do a bringover
13147c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
13157c478bd9Sstevel@tonic-gate	-p	create packages
13167c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
13177c478bd9Sstevel@tonic-gate	-t	build and use the tools in $SRC/tools
13187c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
13197c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
132096ccc8cbSesaxe	-w	report on differences between previous and current proto areas
13217c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
13227c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
13237c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
13247c478bd9Sstevel@tonic-gate		E - build exportable source
13257c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
13267c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
13271fe69678Skupfer		O - build (only) open source
13287c478bd9Sstevel@tonic-gate'
13297c478bd9Sstevel@tonic-gate#
13307c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
13317c478bd9Sstevel@tonic-gate#
13327c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
13331c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
13347c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
13357c478bd9Sstevel@tonic-gate#
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
133811a78ea0SMark J. Nelsonzero_FLAG=n
13397c478bd9Sstevel@tonic-gateA_FLAG=n
13407c478bd9Sstevel@tonic-gatea_FLAG=n
13417c478bd9Sstevel@tonic-gateC_FLAG=n
13426c3c9007SstevelD_FLAG=n
13437c478bd9Sstevel@tonic-gateF_FLAG=n
13447c478bd9Sstevel@tonic-gatef_FLAG=n
13457c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
13467c478bd9Sstevel@tonic-gatel_FLAG=n
13476c3c9007SstevelM_FLAG=n
13487c478bd9Sstevel@tonic-gatem_FLAG=n
13496c3c9007SstevelN_FLAG=n
13506c3c9007Ssteveln_FLAG=n
13514e5b757fSkupferO_FLAG=n
13526c3c9007Sstevelo_FLAG=n
13536c3c9007SstevelP_FLAG=n
13547c478bd9Sstevel@tonic-gatep_FLAG=n
13557c478bd9Sstevel@tonic-gater_FLAG=n
13566c3c9007SstevelT_FLAG=n
1357fd7cef36Ssuhat_FLAG=y
13587c478bd9Sstevel@tonic-gateU_FLAG=n
13596c3c9007Sstevelu_FLAG=n
13607c478bd9Sstevel@tonic-gateV_FLAG=n
13617c478bd9Sstevel@tonic-gateW_FLAG=n
13626c3c9007Sstevelw_FLAG=n
13636c3c9007SstevelX_FLAG=n
13646c3c9007Sstevelz_FLAG=n
13657c478bd9Sstevel@tonic-gateSD_FLAG=n
13666c3c9007SstevelSE_FLAG=n
13677c478bd9Sstevel@tonic-gateSH_FLAG=n
13681fe69678SkupferSO_FLAG=n
13697c478bd9Sstevel@tonic-gate#
13707c478bd9Sstevel@tonic-gateXMOD_OPT=
13717c478bd9Sstevel@tonic-gate#
13727c478bd9Sstevel@tonic-gatebuild_ok=y
13732e02daeeSRainer Orthtools_build_ok=y
13741fe69678Skupfer
1375*597bd30bSMike Kupferfunction is_source_build {
13761fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
13771fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
13781fe69678Skupfer	return $?
13791fe69678Skupfer}
13801fe69678Skupfer
13817c478bd9Sstevel@tonic-gate#
13827c478bd9Sstevel@tonic-gate# examine arguments
13837c478bd9Sstevel@tonic-gate#
13847c478bd9Sstevel@tonic-gate
13851fe69678Skupfer#
13861fe69678Skupfer# single function for setting -S flag and doing error checking.
13871fe69678Skupfer# usage: set_S_flag <type>
13881fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
13891fe69678Skupfer#
1390*597bd30bSMike Kupferfunction set_S_flag {
13911fe69678Skupfer	if is_source_build; then
13921fe69678Skupfer		echo "Can only build one source variant at a time."
13931fe69678Skupfer		exit 1
13941fe69678Skupfer	fi
13951fe69678Skupfer	if [ "$1" = "E" ]; then
13961fe69678Skupfer		SE_FLAG=y
13971fe69678Skupfer	elif [ "$1" = "D" ]; then
13981fe69678Skupfer		SD_FLAG=y
13991fe69678Skupfer	elif [ "$1" = "H" ]; then
14001fe69678Skupfer		SH_FLAG=y
14011fe69678Skupfer	elif [ "$1" = "O" ]; then
14021fe69678Skupfer		SO_FLAG=y
14031fe69678Skupfer	else
14041fe69678Skupfer		echo "$USAGE"
14051fe69678Skupfer		exit 1
14061fe69678Skupfer	fi
14071fe69678Skupfer}
14081fe69678Skupfer
14097c478bd9Sstevel@tonic-gateOPTIND=1
14106c3c9007Sstevelwhile getopts inS:tV: FLAG
14117c478bd9Sstevel@tonic-gatedo
14127c478bd9Sstevel@tonic-gate	case $FLAG in
14137c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
14147c478bd9Sstevel@tonic-gate		;;
14157c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
14167c478bd9Sstevel@tonic-gate		;;
14177c478bd9Sstevel@tonic-gate	  S )
14181fe69678Skupfer		set_S_flag $OPTARG
14197c478bd9Sstevel@tonic-gate		;;
1420fd7cef36Ssuha	 +t )	t_FLAG=n
14217c478bd9Sstevel@tonic-gate		;;
14226c3c9007Sstevel	  V )	V_FLAG=y
14236c3c9007Sstevel		V_ARG="$OPTARG"
14246c3c9007Sstevel		;;
14257c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
14267c478bd9Sstevel@tonic-gate		exit 1
14277c478bd9Sstevel@tonic-gate		;;
14287c478bd9Sstevel@tonic-gate	esac
14297c478bd9Sstevel@tonic-gatedone
14307c478bd9Sstevel@tonic-gate
14317c478bd9Sstevel@tonic-gate# correct argument count after options
14327c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
14337c478bd9Sstevel@tonic-gate
14347c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
14357c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
14367c478bd9Sstevel@tonic-gate	echo "$USAGE"
14377c478bd9Sstevel@tonic-gate	exit 1
14387c478bd9Sstevel@tonic-gatefi
14397c478bd9Sstevel@tonic-gate
14407c478bd9Sstevel@tonic-gate# check if user is running nightly as root
14417c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
14427c478bd9Sstevel@tonic-gate# when root invokes nightly.
14437c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
14447c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate#
14477c478bd9Sstevel@tonic-gate# force locale to C
14487c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
14497c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
14507c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
14517c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
14527c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
14537c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
14547c478bd9Sstevel@tonic-gate
14557c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
14567c478bd9Sstevel@tonic-gateunset LD_OPTIONS
14577c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
14587c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
14597c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
14607c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
14617c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
14627c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
14637c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
14647c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
14657c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
14667c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
14677c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
14687c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
14697c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
14707c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
14717c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
14727c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
14737c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
14747c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
14757c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
14767c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
14777c478bd9Sstevel@tonic-gate
14787c478bd9Sstevel@tonic-gateunset CONFIG
14797c478bd9Sstevel@tonic-gateunset GROUP
14807c478bd9Sstevel@tonic-gateunset OWNER
14817c478bd9Sstevel@tonic-gateunset REMOTE
14827c478bd9Sstevel@tonic-gateunset ENV
14837c478bd9Sstevel@tonic-gateunset ARCH
14847c478bd9Sstevel@tonic-gateunset CLASSPATH
14857c478bd9Sstevel@tonic-gateunset NAME
14867c478bd9Sstevel@tonic-gate
14877c478bd9Sstevel@tonic-gate#
14887c478bd9Sstevel@tonic-gate#	Setup environmental variables
14897c478bd9Sstevel@tonic-gate#
149047703246Ssommerfeif [ -f /etc/nightly.conf ]; then
149147703246Ssommerfe	. /etc/nightly.conf
149247703246Ssommerfefi
149347703246Ssommerfe
14947c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
14957c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
14967c478bd9Sstevel@tonic-gate		. $1
14977c478bd9Sstevel@tonic-gate	else
14987c478bd9Sstevel@tonic-gate		. ./$1
14997c478bd9Sstevel@tonic-gate	fi
15007c478bd9Sstevel@tonic-gateelse
15017c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
15027c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
15037c478bd9Sstevel@tonic-gate	else
15047c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
15057c478bd9Sstevel@tonic-gate		exit 1
15067c478bd9Sstevel@tonic-gate	fi
15077c478bd9Sstevel@tonic-gatefi
15087c478bd9Sstevel@tonic-gate
15091fe69678Skupfer# contents of stdenv.sh inserted after next line:
15101fe69678Skupfer# STDENV_START
15111fe69678Skupfer# STDENV_END
15121fe69678Skupfer
15137c478bd9Sstevel@tonic-gate#
15147c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
15157c478bd9Sstevel@tonic-gate#
15167c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
15177c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
15187c478bd9Sstevel@tonic-gateelse
15197c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
15207c478bd9Sstevel@tonic-gatefi
15217c478bd9Sstevel@tonic-gate
15227c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
15237c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
15247c478bd9Sstevel@tonic-gate
15257c478bd9Sstevel@tonic-gate#
15267c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
15277c478bd9Sstevel@tonic-gate#
15287c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
15297c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
15307c478bd9Sstevel@tonic-gatefi
15317c478bd9Sstevel@tonic-gate
15327c478bd9Sstevel@tonic-gate#
15337c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
15347c478bd9Sstevel@tonic-gate#
15357c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
15367c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
15377c478bd9Sstevel@tonic-gatefi
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gate#
1540cdf0c1d5Smjnelson# If CLOSED_BRINGOVER_WS was not specified, let it default to CLOSED_CLONE_WS
1541cdf0c1d5Smjnelson#
1542cdf0c1d5Smjnelsonif [ "$CLOSED_BRINGOVER_WS" = "" ]; then
1543cdf0c1d5Smjnelson	CLOSED_BRINGOVER_WS=$CLOSED_CLONE_WS
1544cdf0c1d5Smjnelsonfi
1545cdf0c1d5Smjnelson
1546cdf0c1d5Smjnelson#
1547fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1548a5c06a9eSmike_s#
1549a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1550fb23a357Skupfer	BRINGOVER_FILES="usr"
1551a5c06a9eSmike_sfi
1552a5c06a9eSmike_s
1553fb9f9b97Skupfer#
1554fb9f9b97Skupfer# If the closed sources are not present, the closed binaries must be
1555fb9f9b97Skupfer# present for the build to succeed.  If there's no pointer to the
1556fb9f9b97Skupfer# closed binaries, flag that now, rather than forcing the user to wait
1557fb9f9b97Skupfer# a couple hours (or more) to find out.
1558fb9f9b97Skupfer#
1559085d331dSkupferorig_closed_is_present="$CLOSED_IS_PRESENT"
1560085d331dSkupfercheck_closed_tree
1561fb9f9b97Skupfer
1562a5c06a9eSmike_s#
15637c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1564b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
15657c478bd9Sstevel@tonic-gate#
1566d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
15677c478bd9Sstevel@tonic-gateOPTIND=1
156811a78ea0SMark J. Nelsonwhile getopts 0AaBCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
15697c478bd9Sstevel@tonic-gatedo
15707c478bd9Sstevel@tonic-gate	case $FLAG in
157111a78ea0SMark J. Nelson	  0 )   zero_FLAG=y
157211a78ea0SMark J. Nelson	  	;;
15737c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
15747c478bd9Sstevel@tonic-gate		;;
15756c3c9007Sstevel	  a )	a_FLAG=y
15766c3c9007Sstevel		;;
15777c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
15787c478bd9Sstevel@tonic-gate		;; # old version of D
15796c3c9007Sstevel	  C )	C_FLAG=y
15807c478bd9Sstevel@tonic-gate		;;
15817c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
15827c478bd9Sstevel@tonic-gate		;;
15836c3c9007Sstevel	  F )	F_FLAG=y
15847c478bd9Sstevel@tonic-gate		;;
15856c3c9007Sstevel	  f )	f_FLAG=y
15867c478bd9Sstevel@tonic-gate		;;
158711a78ea0SMark J. Nelson	  G )   zero_FLAG=y
158811a78ea0SMark J. Nelson	  	a_FLAG=y
15897c478bd9Sstevel@tonic-gate		u_FLAG=y
15907c478bd9Sstevel@tonic-gate		;;
15917c478bd9Sstevel@tonic-gate	  I )	a_FLAG=y
15927c478bd9Sstevel@tonic-gate		m_FLAG=y
15937c478bd9Sstevel@tonic-gate		p_FLAG=y
15947c478bd9Sstevel@tonic-gate		u_FLAG=y
15957c478bd9Sstevel@tonic-gate		;;
15967c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
15977c478bd9Sstevel@tonic-gate		;;
15986c3c9007Sstevel	  l )	l_FLAG=y
15996c3c9007Sstevel		;;
16006c3c9007Sstevel	  M )	M_FLAG=y
16016c3c9007Sstevel		;;
16026c3c9007Sstevel	  m )	m_FLAG=y
16036c3c9007Sstevel		;;
16046c3c9007Sstevel	  N )	N_FLAG=y
16056c3c9007Sstevel		;;
16067c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
16077c478bd9Sstevel@tonic-gate		;;
16084e5b757fSkupfer	  O )	O_FLAG=y
16094e5b757fSkupfer		;;
16107c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
16117c478bd9Sstevel@tonic-gate		;;
16126c3c9007Sstevel	  P )	P_FLAG=y
16136c3c9007Sstevel		;; # obsolete
16147c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
16157c478bd9Sstevel@tonic-gate		;;
16166c3c9007Sstevel	  R )	m_FLAG=y
16176c3c9007Sstevel		p_FLAG=y
16186c3c9007Sstevel		;;
16197c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
16207c478bd9Sstevel@tonic-gate		;;
16216c3c9007Sstevel	  S )
16226c3c9007Sstevel		set_S_flag $OPTARG
16236c3c9007Sstevel		;;
16246c3c9007Sstevel	  T )	T_FLAG=y
16256c3c9007Sstevel		;; # obsolete
1626fd7cef36Ssuha	 +t )	t_FLAG=n
16277c478bd9Sstevel@tonic-gate		;;
16287c478bd9Sstevel@tonic-gate	  U )
16297c478bd9Sstevel@tonic-gate		if [ -z "${PARENT_ROOT}" ]; then
16307c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
16317c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
16327c478bd9Sstevel@tonic-gate			exit 1
16337c478bd9Sstevel@tonic-gate		fi
16347c478bd9Sstevel@tonic-gate		U_FLAG=y
16357c478bd9Sstevel@tonic-gate		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
16367c478bd9Sstevel@tonic-gate		;;
16376c3c9007Sstevel	  u )	u_FLAG=y
16387c478bd9Sstevel@tonic-gate		;;
16397c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
16407c478bd9Sstevel@tonic-gate		;;
16416c3c9007Sstevel
16426c3c9007Sstevel	  w )	w_FLAG=y
16437c478bd9Sstevel@tonic-gate		;;
16447c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
16457c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
16467c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
16477c478bd9Sstevel@tonic-gate			X_FLAG=y
16487c478bd9Sstevel@tonic-gate		fi
16497c478bd9Sstevel@tonic-gate		;;
16506c3c9007Sstevel	  x )	XMOD_OPT="-x"
16516c3c9007Sstevel		;;
16526c3c9007Sstevel	  z )	z_FLAG=y
16536c3c9007Sstevel		;;
16547c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
16557c478bd9Sstevel@tonic-gate		exit 1
16567c478bd9Sstevel@tonic-gate		;;
16577c478bd9Sstevel@tonic-gate	esac
16587c478bd9Sstevel@tonic-gatedone
16597c478bd9Sstevel@tonic-gate
16607c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
16617c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
16627c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
16637c478bd9Sstevel@tonic-gate		exit 1
16647c478bd9Sstevel@tonic-gate	fi
16657c478bd9Sstevel@tonic-gate
16667c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
16677c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
16687c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
16697c478bd9Sstevel@tonic-gate		export STAFFER
16707c478bd9Sstevel@tonic-gate	fi
16717c478bd9Sstevel@tonic-gatefi
16727c478bd9Sstevel@tonic-gate
16737c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
16747c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
16757c478bd9Sstevel@tonic-gate	export MAILTO
16767c478bd9Sstevel@tonic-gatefi
16777c478bd9Sstevel@tonic-gate
16787c478bd9Sstevel@tonic-gatePATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
16797c478bd9Sstevel@tonic-gatePATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
16807c478bd9Sstevel@tonic-gatePATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
16817c478bd9Sstevel@tonic-gateexport PATH
16827c478bd9Sstevel@tonic-gate
1683fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1684fb23a357Skupferrelsrcdirs="."
16855c53ea7aSmjnelsonif [[ -d $CODEMGR_WS/usr/closed && "$CLOSED_IS_PRESENT" != no ]]; then
1686fb9f9b97Skupfer	relsrcdirs="$relsrcdirs ../closed"
1687fb9f9b97Skupferfi
1688fb23a357Skupferabssrcdirs=""
1689fb23a357Skupferfor d in $relsrcdirs; do
1690fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1691fb23a357Skupferdone
1692fb23a357Skupfer
16937c478bd9Sstevel@tonic-gateunset CH
16947c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
16957c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
16967c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
16977c478bd9Sstevel@tonic-gate# the old ones still do.
16987c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
16997c478bd9Sstevel@tonic-gate	CH=
17007c478bd9Sstevel@tonic-gate	export CH
17017c478bd9Sstevel@tonic-gateelse
17027c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
17037c478bd9Sstevel@tonic-gatefi
17047c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
170548bc00d6Sjmcp# have we set RELEASE_DATE in our env file?
170648bc00d6Sjmcpif [ -z "$RELEASE_DATE" ]; then
170748bc00d6Sjmcp	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
170848bc00d6Sjmcpfi
170948bc00d6SjmcpBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
171048bc00d6SjmcpBASEWSDIR=$(basename $CODEMGR_WS)
171148bc00d6SjmcpDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
17127c478bd9Sstevel@tonic-gate
171348bc00d6Sjmcp# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
171448bc00d6Sjmcp# by avoiding repeated shell invocations to evaluate Makefile.master definitions.
171548bc00d6Sjmcpexport o_FLAG X_FLAG POUND_SIGN RELEASE_DATE DEV_CM
17167c478bd9Sstevel@tonic-gate
17177c478bd9Sstevel@tonic-gatemaketype="distributed"
17187c478bd9Sstevel@tonic-gateMAKE=dmake
17197c478bd9Sstevel@tonic-gate# get the dmake version string alone
17207c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
17217c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
17227c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
17237c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
17247c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
17257c478bd9Sstevel@tonic-gate# extract the second (or final) integer
17267c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
17277c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
17287c478bd9Sstevel@tonic-gate# extract the first integer
17297c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
17307c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
17317c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
17327c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
17337c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
17347c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
17357c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
17367c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
17377c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
17387c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
17397c478bd9Sstevel@tonic-gate		exit 1
17407c478bd9Sstevel@tonic-gate	fi
17417c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
17427c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
17437c478bd9Sstevel@tonic-gate	cat <<EOF
17447c478bd9Sstevel@tonic-gate
17457c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
17467c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
17477c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
17507c478bd9Sstevel@tonic-gateEOF
17517c478bd9Sstevel@tonic-gate	exit 1
17527c478bd9Sstevel@tonic-gatefi
17537c478bd9Sstevel@tonic-gateexport PATH
17547c478bd9Sstevel@tonic-gateexport MAKE
17557c478bd9Sstevel@tonic-gate
1756*597bd30bSMike Kupfer#
1757*597bd30bSMike Kupfer# Make sure the crypto tarball is available if it's needed.
1758*597bd30bSMike Kupfer#
1759*597bd30bSMike Kupfer
1760*597bd30bSMike Kupfer# Echo the non-debug name corresponding to the given crypto tarball path.
1761*597bd30bSMike Kupferfunction ndcrypto {
1762*597bd30bSMike Kupfer	typeset dir file
1763*597bd30bSMike Kupfer
1764*597bd30bSMike Kupfer	if [ -z "$1" ]; then
1765*597bd30bSMike Kupfer		echo ""
1766*597bd30bSMike Kupfer		return
1767*597bd30bSMike Kupfer	fi
1768*597bd30bSMike Kupfer
1769*597bd30bSMike Kupfer	dir=$(dirname "$1")
1770*597bd30bSMike Kupfer	file=$(basename "$1" ".$MACH.tar.bz2")
1771*597bd30bSMike Kupfer
1772*597bd30bSMike Kupfer	echo "$dir/$file-nd.$MACH.tar.bz2"
1773*597bd30bSMike Kupfer}
1774*597bd30bSMike Kupfer
1775*597bd30bSMike Kupfer# Return 0 (success) if the required crypto tarball(s) are present.
1776*597bd30bSMike Kupferfunction crypto_is_present {
1777*597bd30bSMike Kupfer	if [ -z "$ON_CRYPTO_BINS" ]; then
1778*597bd30bSMike Kupfer		echo "ON_CRYPTO_BINS is null or not set."
1779*597bd30bSMike Kupfer		return 1
1780*597bd30bSMike Kupfer	fi
1781*597bd30bSMike Kupfer	if [ "$D_FLAG" = y ]; then
1782*597bd30bSMike Kupfer		if [ ! -f "$ON_CRYPTO_BINS" ]; then
1783*597bd30bSMike Kupfer			echo "DEBUG crypto tarball is unavailable."
1784*597bd30bSMike Kupfer			return 1
1785*597bd30bSMike Kupfer		fi
1786*597bd30bSMike Kupfer	fi
1787*597bd30bSMike Kupfer	if [ "$F_FLAG" = n ]; then
1788*597bd30bSMike Kupfer		if [ ! -f $(ndcrypto "$ON_CRYPTO_BINS") ]; then
1789*597bd30bSMike Kupfer			echo "Non-DEBUG crypto tarball is unavailable."
1790*597bd30bSMike Kupfer			return 1
1791*597bd30bSMike Kupfer		fi
1792*597bd30bSMike Kupfer	fi
1793*597bd30bSMike Kupfer
1794*597bd30bSMike Kupfer	return 0
1795*597bd30bSMike Kupfer}
1796*597bd30bSMike Kupfer
1797*597bd30bSMike Kupfer#
1798*597bd30bSMike Kupfer# Canonicalize ON_CRYPTO_BINS, just in case it was set to the -nd
1799*597bd30bSMike Kupfer# tarball.
1800*597bd30bSMike Kupfer#
1801*597bd30bSMike Kupferif [ -n "$ON_CRYPTO_BINS" ]; then
1802*597bd30bSMike Kupfer	export ON_CRYPTO_BINS=$(echo "$ON_CRYPTO_BINS" |
1803*597bd30bSMike Kupfer	    sed -e s/-nd.$MACH.tar/.$MACH.tar/)
1804*597bd30bSMike Kupferfi
1805*597bd30bSMike Kupfer
1806*597bd30bSMike Kupferif [[ "$O_FLAG" = y && -z "$CODESIGN_USER" ]]; then
1807*597bd30bSMike Kupfer	if ! crypto_is_present; then
1808*597bd30bSMike Kupfer		echo "OpenSolaris deliveries need signed crypto."
1809*597bd30bSMike Kupfer		exit 1
1810*597bd30bSMike Kupfer	fi
1811*597bd30bSMike Kupferfi
1812*597bd30bSMike Kupfer
18137c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
18147c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
18157c478bd9Sstevel@tonic-gate	export PATH
18167c478bd9Sstevel@tonic-gatefi
18177c478bd9Sstevel@tonic-gate
18187c478bd9Sstevel@tonic-gatehostname=`uname -n`
18197c478bd9Sstevel@tonic-gateif [ ! -f $HOME/.make.machines ]; then
18207c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS=4
18217c478bd9Sstevel@tonic-gateelse
18227c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
18237c478bd9Sstevel@tonic-gate	    tail -1 | awk -F= '{print $ 2;}'`"
18247c478bd9Sstevel@tonic-gate	if [ "$DMAKE_MAX_JOBS" = "" ]; then
18257c478bd9Sstevel@tonic-gate		DMAKE_MAX_JOBS=4
18267c478bd9Sstevel@tonic-gate	fi
18277c478bd9Sstevel@tonic-gatefi
18287c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
18297c478bd9Sstevel@tonic-gateexport DMAKE_MODE
18307c478bd9Sstevel@tonic-gateexport DMAKE_MAX_JOBS
18317c478bd9Sstevel@tonic-gate
18327c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
18337c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
18347c478bd9Sstevel@tonic-gate	exit 1
18357c478bd9Sstevel@tonic-gatefi
18367c478bd9Sstevel@tonic-gate
18377c478bd9Sstevel@tonic-gate#
18387c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
18397c478bd9Sstevel@tonic-gate#
18407c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
18417c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
18427c478bd9Sstevel@tonic-gatefi
18437c478bd9Sstevel@tonic-gate
184404a42e3eSszhou#
184504a42e3eSszhou# Check for IHV root for copying ihv proto area
184604a42e3eSszhou#
184704a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
184804a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
184904a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
185004a42e3eSszhou		args_ok=n
185104a42e3eSszhou        fi
185204a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
185304a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
185404a42e3eSszhou                args_ok=n
185504a42e3eSszhou        fi
18566fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
18576fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
18586fec3625Sdduvall		args_ok=n
18596fec3625Sdduvall        fi
18606fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
18616fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
18626fec3625Sdduvall                args_ok=n
18636fec3625Sdduvall        fi
186404a42e3eSszhoufi
186504a42e3eSszhou
18667c478bd9Sstevel@tonic-gate# Append source version
18677c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
18687c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
18697c478bd9Sstevel@tonic-gatefi
18707c478bd9Sstevel@tonic-gate
18717c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
18727c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
18737c478bd9Sstevel@tonic-gatefi
18747c478bd9Sstevel@tonic-gate
18757c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
18767c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
18777c478bd9Sstevel@tonic-gatefi
18787c478bd9Sstevel@tonic-gate
18791fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
18801fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
18811fe69678Skupferfi
18821fe69678Skupfer
18837c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
18847c478bd9Sstevel@tonic-gateexport TMPDIR
18857c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
18867c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
188785f46905SMark J. Nelsonchmod 777 $TMPDIR
18887c478bd9Sstevel@tonic-gate
18897c478bd9Sstevel@tonic-gate#
18907c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
18917c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
18927c478bd9Sstevel@tonic-gate# have the fix for 6271754
18937c478bd9Sstevel@tonic-gate#
18947c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
18957c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
18967c478bd9Sstevel@tonic-gate
18977c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
18987c478bd9Sstevel@tonic-gateTOOLS_PROTO=${TOOLS}/proto
18997c478bd9Sstevel@tonic-gate
19007c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
19017c478bd9Sstevel@tonic-gate
19027c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
19037c478bd9Sstevel@tonic-gate# fails to start correctly
1904*597bd30bSMike Kupferfunction newdir {
19057c478bd9Sstevel@tonic-gate	dir=$1
19067c478bd9Sstevel@tonic-gate	toadd=
19077c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
19087c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
19097c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
19107c478bd9Sstevel@tonic-gate	done
19117c478bd9Sstevel@tonic-gate	torm=
19127c478bd9Sstevel@tonic-gate	newlist=
19137c478bd9Sstevel@tonic-gate	for dir in $toadd; do
19147c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
19157c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
19167c478bd9Sstevel@tonic-gate			torm="$dir $torm"
19177c478bd9Sstevel@tonic-gate		else
19187c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
19197c478bd9Sstevel@tonic-gate			return 1
19207c478bd9Sstevel@tonic-gate		fi
19217c478bd9Sstevel@tonic-gate	done
19227c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
19237c478bd9Sstevel@tonic-gate	return 0
19247c478bd9Sstevel@tonic-gate}
19257c478bd9Sstevel@tonic-gatenewdirlist=
19267c478bd9Sstevel@tonic-gate
19277c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
19287c478bd9Sstevel@tonic-gate
19297c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
19307c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
19317c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
19327c478bd9Sstevel@tonic-gate# built from this immediate source.
19337c478bd9Sstevel@tonic-gateENVLDLIBS1=
19347c478bd9Sstevel@tonic-gateENVLDLIBS2=
19357c478bd9Sstevel@tonic-gateENVLDLIBS3=
19367c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
19377c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
19387c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
19397c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
19407c478bd9Sstevel@tonic-gatePARENT_ROOT=
19417c478bd9Sstevel@tonic-gate
19427c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
19437c478bd9Sstevel@tonic-gate	PARENT_ROOT
19447c478bd9Sstevel@tonic-gate
19457c478bd9Sstevel@tonic-gateCPIODIR_ORIG=$CPIODIR
19467c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
19477c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1948d8fd4470Sjgif [ "$SPARC_RM_PKGARCHIVE" ]; then
19497c478bd9Sstevel@tonic-gate	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1950d8fd4470Sjgfi
19517c478bd9Sstevel@tonic-gate
19527c478bd9Sstevel@tonic-gate#
19537c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
19547c478bd9Sstevel@tonic-gate#
19557c478bd9Sstevel@tonic-gate
1956*597bd30bSMike Kupferfunction logshuffle {
1957fd7cef36Ssuha    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
19587c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
19597c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
19607c478bd9Sstevel@tonic-gate	fi
19617c478bd9Sstevel@tonic-gate	mkdir $LLOG
19624802ef38Srscott	export LLOG
19637c478bd9Sstevel@tonic-gate
19647c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
19657c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
196696ccc8cbSesaxe
19672e02daeeSRainer Orth		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
19682e02daeeSRainer Orth			mv $ATLOG/proto_list_tools_${MACH} $LLOG
19692e02daeeSRainer Orth	        fi
19702e02daeeSRainer Orth
197196ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
197296ccc8cbSesaxe		    	mv $TMPDIR/wsdiff.results $LLOG
197396ccc8cbSesaxe		fi
19744e5b757fSkupfer
19754e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
19764e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
19774e5b757fSkupfer		fi
19787c478bd9Sstevel@tonic-gate	fi
19797c478bd9Sstevel@tonic-gate
19807c478bd9Sstevel@tonic-gate	#
19817c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
19827c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
19837c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
19847c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
19857c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
19867c478bd9Sstevel@tonic-gate	#
19877c478bd9Sstevel@tonic-gate
19887c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
19897c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
19907c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
19917c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
19927c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
19937c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
19947c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
19957c478bd9Sstevel@tonic-gate	fi
19967c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
19977c478bd9Sstevel@tonic-gate
19987c478bd9Sstevel@tonic-gate	case "$build_ok" in
19997c478bd9Sstevel@tonic-gate		y)
20007c478bd9Sstevel@tonic-gate			state=Completed
20017c478bd9Sstevel@tonic-gate			;;
20027c478bd9Sstevel@tonic-gate		i)
20037c478bd9Sstevel@tonic-gate			state=Interrupted
20047c478bd9Sstevel@tonic-gate			;;
20057c478bd9Sstevel@tonic-gate		*)
20067c478bd9Sstevel@tonic-gate	    		state=Failed
20077c478bd9Sstevel@tonic-gate			;;
20087c478bd9Sstevel@tonic-gate	esac
200940bc9153Srscott	NIGHTLY_STATUS=$state
201040bc9153Srscott	export NIGHTLY_STATUS
20117c478bd9Sstevel@tonic-gate
201247703246Ssommerfe	run_hook POST_NIGHTLY $state
201347703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
20144802ef38Srscott
2015cdf0c1d5Smjnelson	cat $build_time_file $build_environ_file $mail_msg_file \
2016cdf0c1d5Smjnelson	    > ${LLOG}/mail_msg
20177c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
2018cdf0c1d5Smjnelson	    	cat ${LLOG}/mail_msg | /usr/bin/mailx -s \
20197c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
20207c478bd9Sstevel@tonic-gate			${MAILTO}
20217c478bd9Sstevel@tonic-gate	fi
20227c478bd9Sstevel@tonic-gate
20237c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
20247c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
20257c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
20267c478bd9Sstevel@tonic-gate	fi
20277c478bd9Sstevel@tonic-gate
20287c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
20297c478bd9Sstevel@tonic-gate}
20307c478bd9Sstevel@tonic-gate
20317c478bd9Sstevel@tonic-gate#
20327c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
20337c478bd9Sstevel@tonic-gate#
2034*597bd30bSMike Kupferfunction cleanup {
20357c478bd9Sstevel@tonic-gate    	logshuffle
20367c478bd9Sstevel@tonic-gate
20377c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
20387c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
20397c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
20407c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
20417c478bd9Sstevel@tonic-gate
20427c478bd9Sstevel@tonic-gate	set -- $newdirlist
20437c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
20447c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
20457c478bd9Sstevel@tonic-gate		shift; shift
20467c478bd9Sstevel@tonic-gate	done
20477c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
20487c478bd9Sstevel@tonic-gate}
20497c478bd9Sstevel@tonic-gate
2050*597bd30bSMike Kupferfunction cleanup_signal {
20517c478bd9Sstevel@tonic-gate    	build_ok=i
20527c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
20537c478bd9Sstevel@tonic-gate	exit 1
20547c478bd9Sstevel@tonic-gate}
20557c478bd9Sstevel@tonic-gate
20567c478bd9Sstevel@tonic-gatetrap cleanup 0
20577c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
20587c478bd9Sstevel@tonic-gate
20597c478bd9Sstevel@tonic-gate#
20607c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
20617c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
20627c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
20637c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
20647c478bd9Sstevel@tonic-gate# for the workspace).
2065cdf0c1d5Smjnelson#
2066*597bd30bSMike Kupferfunction create_lock {
20677c478bd9Sstevel@tonic-gate	lockf=$1
20687c478bd9Sstevel@tonic-gate	lockvar=$2
20698312e758Sdduvall
20707c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
20717c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
20727c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
20738312e758Sdduvall
20748312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
20758312e758Sdduvall		basews=`basename $CODEMGR_WS`
20768312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
20778312e758Sdduvall		if [ "$host" != "$hostname" ]; then
20788312e758Sdduvall			echo "$MACH build of $basews apparently" \
20798312e758Sdduvall			    "already started by $user on $host as $pid."
20808312e758Sdduvall			exit 1
20818312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
20828312e758Sdduvall			echo "$MACH build of $basews already started" \
20838312e758Sdduvall			    "by $user as $pid."
20848312e758Sdduvall			exit 1
20858312e758Sdduvall		else
20868312e758Sdduvall			# stale lock; clear it out and try again
20878312e758Sdduvall			rm -f $lockf
20888312e758Sdduvall		fi
20898312e758Sdduvall	done
20907c478bd9Sstevel@tonic-gate}
20917c478bd9Sstevel@tonic-gate
20924e5b757fSkupfer#
20934e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
20944e5b757fSkupfer# options.
20954e5b757fSkupfer#
2096*597bd30bSMike Kupferfunction allprotos {
20974e5b757fSkupfer	roots="$ROOT"
20984e5b757fSkupfer	if [ $O_FLAG = y ]; then
20994e5b757fSkupfer		# OpenSolaris deliveries require separate proto areas.
21004e5b757fSkupfer		[ $D_FLAG = y ] && roots="$roots $ROOT-open"
21014e5b757fSkupfer		[ $F_FLAG = n ] && roots="$roots $ROOT-open-nd"
21024e5b757fSkupfer	fi
21034e5b757fSkupfer	if [[ $D_FLAG = y && $F_FLAG = n ]]; then
21044e5b757fSkupfer		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd"
21054e5b757fSkupfer	fi
21064e5b757fSkupfer
21074e5b757fSkupfer	echo $roots
21084e5b757fSkupfer}
21094e5b757fSkupfer
21107c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
21117c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
21127c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
21137c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
21147c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
21157c478bd9Sstevel@tonic-gatefi
21167c478bd9Sstevel@tonic-gate#
21177c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
21187c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
21197c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
21207c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
21217c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
21227c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
21237c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
21247c478bd9Sstevel@tonic-gate#
21257c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
21267c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
21277c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
21287c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
21297c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
21307c478bd9Sstevel@tonic-gatefi
21317c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
21327c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
21337c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
21347c478bd9Sstevel@tonic-gatefi
21357c478bd9Sstevel@tonic-gate
21367c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
21377c478bd9Sstevel@tonic-gate# the directories we may have created so far.
21387c478bd9Sstevel@tonic-gatenewdirlist=
21397c478bd9Sstevel@tonic-gate
21407c478bd9Sstevel@tonic-gate#
21417c478bd9Sstevel@tonic-gate# Create mail_msg_file
21427c478bd9Sstevel@tonic-gate#
21437c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
21447c478bd9Sstevel@tonic-gatetouch $mail_msg_file
21457c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
2146cdf0c1d5Smjnelsonbuild_environ_file="${TMPDIR}/build_environ"
2147cdf0c1d5Smjnelsontouch $build_environ_file
21487c478bd9Sstevel@tonic-gate#
21497c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
21507c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
21517c478bd9Sstevel@tonic-gate#
21527c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
21537c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
21547c478bd9Sstevel@tonic-gatefi
21557c478bd9Sstevel@tonic-gate#
21567c478bd9Sstevel@tonic-gate#	Build OsNet source
21577c478bd9Sstevel@tonic-gate#
21587c478bd9Sstevel@tonic-gateSTART_DATE=`date`
21597c478bd9Sstevel@tonic-gateSECONDS=0
21607c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
21617c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
21627c478bd9Sstevel@tonic-gate
2163cdf0c1d5Smjnelsonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
2164cdf0c1d5Smjnelson    tee -a $mail_msg_file >> $LOGFILE
2165cdf0c1d5Smjnelson
21667c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
21677c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
21687c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
21697c478bd9Sstevel@tonic-gate
217047703246Ssommerferun_hook SYS_PRE_NIGHTLY
217147703246Ssommerferun_hook PRE_NIGHTLY
217247703246Ssommerfe
21737c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
21747c478bd9Sstevel@tonic-gateenv >> $LOGFILE
21757c478bd9Sstevel@tonic-gate
21767c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
21777c478bd9Sstevel@tonic-gate
2178d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
2179d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
2180d77e7149Ssommerfefi
2181d77e7149Ssommerfe
2182d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
2183d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
2184d77e7149Ssommerfefi
2185d77e7149Ssommerfe
21861fe69678Skupferif is_source_build; then
21877c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
21887c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
21897c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
21907c478bd9Sstevel@tonic-gate		i_FLAG=n
21917c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
21927c478bd9Sstevel@tonic-gate	fi
21937c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
21947c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
21957c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
21967c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
21977c478bd9Sstevel@tonic-gate		N_FLAG=y
21987c478bd9Sstevel@tonic-gate	fi
21997c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
22007c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
22017c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
22027c478bd9Sstevel@tonic-gate		l_FLAG=n
22037c478bd9Sstevel@tonic-gate	fi
22047c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
22057c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
22067c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
22077c478bd9Sstevel@tonic-gate		C_FLAG=n
22087c478bd9Sstevel@tonic-gate	fi
22097c478bd9Sstevel@tonic-gateelse
22107c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
22117c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
22127c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
22137c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
22147c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
22157c478bd9Sstevel@tonic-gateEOF
22167c478bd9Sstevel@tonic-gate		else
22177c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
22187c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
22197c478bd9Sstevel@tonic-gateEOF
22207c478bd9Sstevel@tonic-gate		fi
22217c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
22227c478bd9Sstevel@tonic-gate	fi
22237c478bd9Sstevel@tonic-gatefi
22247c478bd9Sstevel@tonic-gate
22254e5b757fSkupferif [ "$O_FLAG" = "y" -a "$a_FLAG" = "n" ]; then
22264e5b757fSkupfer	echo "WARNING: OpenSolaris deliveries (-O) require archives;" \
22274e5b757fSkupfer	    "enabling the -a flag." | tee -a $mail_msg_file >> $LOGFILE
22284e5b757fSkupfer	a_FLAG=y
22294e5b757fSkupferfi
22304e5b757fSkupfer
22317c478bd9Sstevel@tonic-gateif [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
22327c478bd9Sstevel@tonic-gate	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
22337c478bd9Sstevel@tonic-gate	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
22347c478bd9Sstevel@tonic-gatefi
22357c478bd9Sstevel@tonic-gate
22367c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
22374e5b757fSkupfer	#
22384e5b757fSkupfer	# In the past we just complained but went ahead with the lint
22394e5b757fSkupfer	# pass, even though the proto area was built non-debug.  It's
22404e5b757fSkupfer	# unlikely that non-debug headers will make a difference, but
22414e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
22424e5b757fSkupfer	# to specify a debug build.
22434e5b757fSkupfer	#
22444e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
22457c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
22464e5b757fSkupfer	l_FLAG=n
22477c478bd9Sstevel@tonic-gatefi
22487c478bd9Sstevel@tonic-gate
22497c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
22507c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
22517c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
22527c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
22537c478bd9Sstevel@tonic-gate		f_FLAG=n
22547c478bd9Sstevel@tonic-gate	fi
225511a78ea0SMark J. Nelson	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
225611a78ea0SMark J. Nelson		echo "WARNING: the -f flag requires -l, and -p;" \
225711a78ea0SMark J. Nelson		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
22587c478bd9Sstevel@tonic-gate		f_FLAG=n
22597c478bd9Sstevel@tonic-gate	fi
226011a78ea0SMark J. Nelson	if [ "${f_FLAG}${zero_FLAG}" = "yn" ]; then
226111a78ea0SMark J. Nelson		echo "WARNING: the -f flag implies -0; enabling -0\n" \
226211a78ea0SMark J. Nelson		    | tee -a $mail_msg_file >> $LOGFILE
226311a78ea0SMark J. Nelson		zero_FLAG=y
226411a78ea0SMark J. Nelson	fi
226511a78ea0SMark J. Nelsonfi
226611a78ea0SMark J. Nelson
226711a78ea0SMark J. Nelsonif [ "$zero_FLAG" = "y" -a -z "$G11N_PKGDIR" ]; then
226811a78ea0SMark J. Nelson	echo "WARNING: the -0 flag requires that G11N_PKGDIR be set" \
226911a78ea0SMark J. Nelson	    "in the environment; ignoring -0\n" \
227011a78ea0SMark J. Nelson	    | tee -a $mail_msg_file >> $LOGFILE
227111a78ea0SMark J. Nelson	zero_FLAG=n
22727c478bd9Sstevel@tonic-gatefi
22737c478bd9Sstevel@tonic-gate
227496ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
22754e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
227696ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
227796ccc8cbSesaxe	w_FLAG=n
227896ccc8cbSesaxefi
227996ccc8cbSesaxe
22807c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
22817c478bd9Sstevel@tonic-gate	#
22827c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
22837c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
22847c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
22857c478bd9Sstevel@tonic-gate	#
22867c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
22877c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
22887c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
22897c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
22907c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
22917c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
22927c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
22937c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
22947c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
22957c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
22967c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
22977c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
22987c478bd9Sstevel@tonic-gate	fi
22997c478bd9Sstevel@tonic-gatefi
23007c478bd9Sstevel@tonic-gate
23014e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
23024e5b757fSkupfer
23034e5b757fSkupfercase $MULTI_PROTO in
23044e5b757fSkupferyes|no)	;;
23054e5b757fSkupfer*)
23064e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
23074e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
23084e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
23094e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
23104e5b757fSkupfer	export MULTI_PROTO=no
23114e5b757fSkupfer	;;
23124e5b757fSkupferesac
23134e5b757fSkupfer
2314*597bd30bSMike Kupfer# If CODESIGN_USER is set, we'll want the crypto that we just built.
2315*597bd30bSMike Kupferif [[ -n "$CODESIGN_USER" && -n "$ON_CRYPTO_BINS" ]]; then
2316*597bd30bSMike Kupfer	echo "Clearing ON_CRYPTO_BINS for signing build." >> "$LOGFILE"
2317*597bd30bSMike Kupfer	unset ON_CRYPTO_BINS
2318*597bd30bSMike Kupferfi
2319*597bd30bSMike Kupfer
23207c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
23217c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
23227c478bd9Sstevel@tonic-gate
232396ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
232496ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
232596ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
232696ccc8cbSesaxe	rm -rf $ROOT.prev
232796ccc8cbSesaxe    fi
232896ccc8cbSesaxe    mv $ROOT $ROOT.prev
232996ccc8cbSesaxefi
233096ccc8cbSesaxe
23314e5b757fSkupfer# Same for non-DEBUG proto area
23324e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
23334e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
23344e5b757fSkupfer		rm -rf $ROOT-nd.prev
23354e5b757fSkupfer	fi
23364e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
23374e5b757fSkupferfi
23384e5b757fSkupfer
233930635de9SJohn.Zolnowsky@Sun.COM# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
234030635de9SJohn.Zolnowsky@Sun.COMfunction wstypes {
234130635de9SJohn.Zolnowsky@Sun.COM	typeset parent_type child_type junk
234230635de9SJohn.Zolnowsky@Sun.COM
234330635de9SJohn.Zolnowsky@Sun.COM	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
234430635de9SJohn.Zolnowsky@Sun.COM	    | read parent_type junk
234530635de9SJohn.Zolnowsky@Sun.COM	if [[ -z "$parent_type" || "$parent_type" == unknown ]]; then
234630635de9SJohn.Zolnowsky@Sun.COM		# Probe BRINGOVER_WS to determine its type
234730635de9SJohn.Zolnowsky@Sun.COM		if [[ $BRINGOVER_WS == svn*://* ]]; then
234830635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
234930635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == file://* ]] &&
235030635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "This is a Subversion repository" \
235130635de9SJohn.Zolnowsky@Sun.COM		    ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
235230635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
235330635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == ssh://* ]]; then
235430635de9SJohn.Zolnowsky@Sun.COM			parent_type="mercurial"
235530635de9SJohn.Zolnowsky@Sun.COM		elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
235630635de9SJohn.Zolnowsky@Sun.COM			parent_type="subversion"
235730635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == http://* ]] && \
235830635de9SJohn.Zolnowsky@Sun.COM		    http_get "$BRINGOVER_WS/?cmd=heads" | \
235930635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "application/mercurial" 2> /dev/null; then
236030635de9SJohn.Zolnowsky@Sun.COM			parent_type="mercurial"
236130635de9SJohn.Zolnowsky@Sun.COM		else
236230635de9SJohn.Zolnowsky@Sun.COM			parent_type="none"
236330635de9SJohn.Zolnowsky@Sun.COM		fi
236430635de9SJohn.Zolnowsky@Sun.COM	fi
236530635de9SJohn.Zolnowsky@Sun.COM
236630635de9SJohn.Zolnowsky@Sun.COM	# Probe CODEMGR_WS to determine its type
236730635de9SJohn.Zolnowsky@Sun.COM	if [[ -d $CODEMGR_WS ]]; then
236830635de9SJohn.Zolnowsky@Sun.COM		$WHICH_SCM | read child_type junk || exit 1
236930635de9SJohn.Zolnowsky@Sun.COM	fi
237030635de9SJohn.Zolnowsky@Sun.COM
237130635de9SJohn.Zolnowsky@Sun.COM	# fold both unsupported and unrecognized results into "none"
237230635de9SJohn.Zolnowsky@Sun.COM	case "$parent_type" in
237330635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
237430635de9SJohn.Zolnowsky@Sun.COM		;;
237530635de9SJohn.Zolnowsky@Sun.COM	*)	parent_type=none
237630635de9SJohn.Zolnowsky@Sun.COM		;;
237730635de9SJohn.Zolnowsky@Sun.COM	esac
237830635de9SJohn.Zolnowsky@Sun.COM	case "$child_type" in
237930635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
238030635de9SJohn.Zolnowsky@Sun.COM		;;
238130635de9SJohn.Zolnowsky@Sun.COM	*)	child_type=none
238230635de9SJohn.Zolnowsky@Sun.COM		;;
238330635de9SJohn.Zolnowsky@Sun.COM	esac
238430635de9SJohn.Zolnowsky@Sun.COM
238530635de9SJohn.Zolnowsky@Sun.COM	echo $child_type $parent_type
238630635de9SJohn.Zolnowsky@Sun.COM}
238730635de9SJohn.Zolnowsky@Sun.COM
238830635de9SJohn.Zolnowsky@Sun.COMwstypes | read SCM_TYPE PARENT_SCM_TYPE
238930635de9SJohn.Zolnowsky@Sun.COMexport SCM_TYPE PARENT_SCM_TYPE
239030635de9SJohn.Zolnowsky@Sun.COM
23917c478bd9Sstevel@tonic-gate#
23927c478bd9Sstevel@tonic-gate#	Decide whether to clobber
23937c478bd9Sstevel@tonic-gate#
23947c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
23957c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
23967c478bd9Sstevel@tonic-gate
23977c478bd9Sstevel@tonic-gate	cd $SRC
23987c478bd9Sstevel@tonic-gate	# remove old clobber file
23997c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
24007c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
24017c478bd9Sstevel@tonic-gate
24027c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
24037c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
2404cdf0c1d5Smjnelson	find . \( -name SCCS -o -name .hg -o -name .svn \
2405cdf0c1d5Smjnelson		-o -name 'interfaces.*' \) -prune \
24067c478bd9Sstevel@tonic-gate		-o -name '.make.*' -print | xargs rm -f
24077c478bd9Sstevel@tonic-gate
24087c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
24097c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
24107c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
24117c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
24127c478bd9Sstevel@tonic-gate		>> $mail_msg_file
24137c478bd9Sstevel@tonic-gate
24144e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
24157c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
24167c478bd9Sstevel@tonic-gate		cd ${TOOLS}
24177c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
24187c478bd9Sstevel@tonic-gate		$MAKE -ek clobber 2>&1 | \
24197c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
24207c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
24217c478bd9Sstevel@tonic-gate			>> $mail_msg_file
24227c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
24237c478bd9Sstevel@tonic-gate			>> $mail_msg_file
24247c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
24257c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
24267c478bd9Sstevel@tonic-gate	fi
242796ccc8cbSesaxe
24284e5b757fSkupfer	rm -rf `allprotos`
24297c478bd9Sstevel@tonic-gate
24307c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
24317c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
24327c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2433fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2434cdf0c1d5Smjnelson	# under source code control, so leave them alone.
24357c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
24367c478bd9Sstevel@tonic-gate	cd $SRC
2437cdf0c1d5Smjnelson	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
2438cdf0c1d5Smjnelson	    -o -name 'interfaces.*' \) -prune -o \
24397c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2440fb23a357Skupfer	       -name '*.o' \) -print | \
2441fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
24427c478bd9Sstevel@tonic-gateelse
24437c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
24447c478bd9Sstevel@tonic-gatefi
24457c478bd9Sstevel@tonic-gate
2446*597bd30bSMike Kupfertype bringover_teamware > /dev/null 2>&1 || function bringover_teamware {
24477c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
24487c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
24497c478bd9Sstevel@tonic-gate	do
24507c478bd9Sstevel@tonic-gate		sleep 120
24517c478bd9Sstevel@tonic-gate	done
24527c478bd9Sstevel@tonic-gate
2453fd7cef36Ssuha	if [[ -z $BRINGOVER ]]; then
2454fd7cef36Ssuha		BRINGOVER=$TEAMWARE/bin/bringover
2455fd7cef36Ssuha	fi
245632f1e47bSsommerfe
2457cdf0c1d5Smjnelson	staffer $BRINGOVER -c "nightly update" -p $BRINGOVER_WS \
245832f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
245932f1e47bSsommerfe		touch $TMPDIR/bringover_failed
246032f1e47bSsommerfe
2461d77e7149Ssommerfe        staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2462d77e7149Ssommerfe	if [ -s $TMPDIR/bringovercheck.out ]; then
2463d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2464d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2465d77e7149Ssommerfe	fi
2466cdf0c1d5Smjnelson}
246732f1e47bSsommerfe
2468*597bd30bSMike Kupfertype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
2469cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2470cdf0c1d5Smjnelson
2471cdf0c1d5Smjnelson	# If the repository doesn't exist yet, then we want to populate it.
2472cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.hg ]]; then
2473cdf0c1d5Smjnelson		staffer hg init $CODEMGR_WS
24748cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
24758cca05f6SMark J. Nelson		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
2476f457028bSMark J. Nelson		touch $TMPDIR/new_repository
2477cdf0c1d5Smjnelson	fi
24785c53ea7aSmjnelson
24795c53ea7aSmjnelson	#
24805c53ea7aSmjnelson	# If the user set CLOSED_BRINGOVER_WS and didn't set CLOSED_IS_PRESENT
24815c53ea7aSmjnelson	# to "no," then we'll want to initialise the closed repository
24825c53ea7aSmjnelson	#
24835c53ea7aSmjnelson	# We use $orig_closed_is_present instead of $CLOSED_IS_PRESENT,
24845c53ea7aSmjnelson	# because for newly-created source trees, the latter will be "no"
24855c53ea7aSmjnelson	# until after the bringover completes.
24865c53ea7aSmjnelson	#
24875c53ea7aSmjnelson	if [[ "$orig_closed_is_present" != "no" && \
24885c53ea7aSmjnelson	    -n "$CLOSED_BRINGOVER_WS" && \
24895c53ea7aSmjnelson	    ! -d $CODEMGR_WS/usr/closed/.hg ]]; then
24905c53ea7aSmjnelson		staffer mkdir -p $CODEMGR_WS/usr/closed
24915c53ea7aSmjnelson		staffer hg init $CODEMGR_WS/usr/closed
24928cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/usr/closed/.hg/hgrc
24938cca05f6SMark J. Nelson		staffer echo "default=$CLOSED_BRINGOVER_WS" >> $CODEMGR_WS/usr/closed/.hg/hgrc
2494f457028bSMark J. Nelson		touch $TMPDIR/new_closed
24955c53ea7aSmjnelson		export CLOSED_IS_PRESENT=yes
2496cdf0c1d5Smjnelson	fi
2497cdf0c1d5Smjnelson
2498cdf0c1d5Smjnelson	typeset -x HGMERGE="/bin/false"
2499cdf0c1d5Smjnelson
2500cdf0c1d5Smjnelson	#
25015c53ea7aSmjnelson	# If the user has changes, regardless of whether those changes are
25025c53ea7aSmjnelson	# committed, and regardless of whether those changes conflict, then
25035c53ea7aSmjnelson	# we'll attempt to merge them either implicitly (uncommitted) or
25045c53ea7aSmjnelson	# explicitly (committed).
2505cdf0c1d5Smjnelson	#
25065c53ea7aSmjnelson	# These are the messages we'll use to help clarify mercurial output
25075c53ea7aSmjnelson	# in those cases.
25085c53ea7aSmjnelson	#
25095c53ea7aSmjnelson	typeset mergefailmsg="\
25105c53ea7aSmjnelson***\n\
25115c53ea7aSmjnelson*** nightly was unable to automatically merge your changes.  You should\n\
25125c53ea7aSmjnelson*** redo the full merge manually, following the steps outlined by mercurial\n\
25135c53ea7aSmjnelson*** above, then restart nightly.\n\
25145c53ea7aSmjnelson***\n"
25155c53ea7aSmjnelson	typeset mergepassmsg="\
25165c53ea7aSmjnelson***\n\
25175c53ea7aSmjnelson*** nightly successfully merged your changes.  This means that your working\n\
25185c53ea7aSmjnelson*** directory has been updated, but those changes are not yet committed.\n\
25195c53ea7aSmjnelson*** After nightly completes, you should validate the results of the merge,\n\
25205c53ea7aSmjnelson*** then use hg commit manually.\n\
25215c53ea7aSmjnelson***\n"
25225c53ea7aSmjnelson
25235c53ea7aSmjnelson	#
25245c53ea7aSmjnelson	# For each repository in turn:
25255c53ea7aSmjnelson	#
25265c53ea7aSmjnelson	# 1. Do the pull.  If this fails, dump the output and bail out.
25275c53ea7aSmjnelson	#
25285c53ea7aSmjnelson	# 2. If the pull resulted in an extra head, do an explicit merge.
25295c53ea7aSmjnelson	#    If this fails, dump the output and bail out.
25305c53ea7aSmjnelson	#
25315c53ea7aSmjnelson	# Because we can't rely on Mercurial to exit with a failure code
25325c53ea7aSmjnelson	# when a merge fails (Mercurial issue #186), we must grep the
25335c53ea7aSmjnelson	# output of pull/merge to check for attempted and/or failed merges.
25345c53ea7aSmjnelson	#
25355c53ea7aSmjnelson	# 3. If a merge failed, set the message and fail the bringover.
25365c53ea7aSmjnelson	#
25375c53ea7aSmjnelson	# 4. Otherwise, if a merge succeeded, set the message
25385c53ea7aSmjnelson	#
25395c53ea7aSmjnelson	# 5. Dump the output, and any message from step 3 or 4.
25405c53ea7aSmjnelson	#
25415c53ea7aSmjnelson
2542f457028bSMark J. Nelson	typeset HG_SOURCE=$BRINGOVER_WS
2543f457028bSMark J. Nelson	if [ ! -f $TMPDIR/new_repository ]; then
2544f457028bSMark J. Nelson		HG_SOURCE=$TMPDIR/open_bundle.hg
2545f457028bSMark J. Nelson		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
2546f457028bSMark J. Nelson		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
2547f457028bSMark J. Nelson
2548f457028bSMark J. Nelson		#
2549f457028bSMark J. Nelson		# If there are no incoming changesets, then incoming will
2550f457028bSMark J. Nelson		# fail, and there will be no bundle file.  Reset the source,
2551f457028bSMark J. Nelson		# to allow the remaining logic to complete with no false
2552f457028bSMark J. Nelson		# negatives.  (Unlike incoming, pull will return success
2553f457028bSMark J. Nelson		# for the no-change case.)
2554f457028bSMark J. Nelson		#
2555f457028bSMark J. Nelson		if (( $? != 0 )); then
2556f457028bSMark J. Nelson			HG_SOURCE=$BRINGOVER_WS
2557f457028bSMark J. Nelson		fi
2558f457028bSMark J. Nelson	fi
2559f457028bSMark J. Nelson
2560f457028bSMark J. Nelson	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
25615c53ea7aSmjnelson	    > $TMPDIR/pull_open.out 2>&1
25625c53ea7aSmjnelson	if (( $? != 0 )); then
25635c53ea7aSmjnelson		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
25645c53ea7aSmjnelson		cat $TMPDIR/pull_open.out
25655c53ea7aSmjnelson		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
25665c53ea7aSmjnelson			printf "$mergefailmsg"
25675c53ea7aSmjnelson		fi
25685c53ea7aSmjnelson		touch $TMPDIR/bringover_failed
25695c53ea7aSmjnelson		return
25705c53ea7aSmjnelson	fi
25715c53ea7aSmjnelson
2572cdf0c1d5Smjnelson	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
25735c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS merge \
25745c53ea7aSmjnelson		    >> $TMPDIR/pull_open.out 2>&1
25755c53ea7aSmjnelson		if (( $? != 0 )); then
25765c53ea7aSmjnelson			printf "%s: merge failed as follows:\n\n" \
25775c53ea7aSmjnelson			    "$CODEMGR_WS"
25785c53ea7aSmjnelson			cat $TMPDIR/pull_open.out
25795c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_open.out \
25805c53ea7aSmjnelson			    > /dev/null 2>&1; then
25815c53ea7aSmjnelson				printf "$mergefailmsg"
25825c53ea7aSmjnelson			fi
2583cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
25845c53ea7aSmjnelson			return
2585cdf0c1d5Smjnelson		fi
2586cdf0c1d5Smjnelson	fi
25875c53ea7aSmjnelson
25885c53ea7aSmjnelson	printf "updated %s with the following results:\n" "$CODEMGR_WS"
25895c53ea7aSmjnelson	cat $TMPDIR/pull_open.out
25905c53ea7aSmjnelson	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
25915c53ea7aSmjnelson		printf "$mergepassmsg"
25925c53ea7aSmjnelson	fi
25935c53ea7aSmjnelson	printf "\n"
25945c53ea7aSmjnelson
25955c53ea7aSmjnelson	#
25965c53ea7aSmjnelson	# We only want to update usr/closed if it exists, and we haven't been
25975c53ea7aSmjnelson	# told not to via $CLOSED_IS_PRESENT, and we actually know where to
25985c53ea7aSmjnelson	# pull from ($CLOSED_BRINGOVER_WS).
25995c53ea7aSmjnelson	#
26005c53ea7aSmjnelson	if [[ $CLOSED_IS_PRESENT = yes && \
26015c53ea7aSmjnelson	    -d $CODEMGR_WS/usr/closed/.hg && \
26025c53ea7aSmjnelson	    -n $CLOSED_BRINGOVER_WS ]]; then
26035c53ea7aSmjnelson
2604f457028bSMark J. Nelson		HG_SOURCE=$CLOSED_BRINGOVER_WS
2605f457028bSMark J. Nelson		if [ ! -f $TMPDIR/new_closed ]; then
2606f457028bSMark J. Nelson			HG_SOURCE=$TMPDIR/closed_bundle.hg
2607f457028bSMark J. Nelson			staffer hg --cwd $CODEMGR_WS/usr/closed incoming \
2608f457028bSMark J. Nelson			    --bundle $HG_SOURCE -v $CLOSED_BRINGOVER_WS \
2609f457028bSMark J. Nelson			    > $TMPDIR/incoming_closed.out
2610f457028bSMark J. Nelson
2611f457028bSMark J. Nelson			#
2612f457028bSMark J. Nelson			# If there are no incoming changesets, then incoming will
2613f457028bSMark J. Nelson			# fail, and there will be no bundle file.  Reset the source,
2614f457028bSMark J. Nelson			# to allow the remaining logic to complete with no false
2615f457028bSMark J. Nelson			# negatives.  (Unlike incoming, pull will return success
2616f457028bSMark J. Nelson			# for the no-change case.)
2617f457028bSMark J. Nelson			#
2618f457028bSMark J. Nelson			if (( $? != 0 )); then
2619f457028bSMark J. Nelson				HG_SOURCE=$CLOSED_BRINGOVER_WS
2620f457028bSMark J. Nelson			fi
2621f457028bSMark J. Nelson		fi
2622f457028bSMark J. Nelson
26235c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS/usr/closed pull -u \
2624f457028bSMark J. Nelson			$HG_SOURCE > $TMPDIR/pull_closed.out 2>&1
26255c53ea7aSmjnelson		if (( $? != 0 )); then
26265c53ea7aSmjnelson			printf "closed pull failed as follows:\n\n"
26275c53ea7aSmjnelson			cat $TMPDIR/pull_closed.out
26285c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_closed.out \
26295c53ea7aSmjnelson			    > /dev/null 2>&1; then
26305c53ea7aSmjnelson				printf "$mergefailmsg"
26315c53ea7aSmjnelson			fi
26325c53ea7aSmjnelson			touch $TMPDIR/bringover_failed
26335c53ea7aSmjnelson			return
26345c53ea7aSmjnelson		fi
26355c53ea7aSmjnelson
2636cdf0c1d5Smjnelson		if grep "not updating" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
26375c53ea7aSmjnelson			staffer hg --cwd $CODEMGR_WS/usr/closed merge \
26385c53ea7aSmjnelson			    >> $TMPDIR/pull_closed.out 2>&1
26395c53ea7aSmjnelson			if (( $? != 0 )); then
26405c53ea7aSmjnelson				printf "closed merge failed as follows:\n\n"
26415c53ea7aSmjnelson				cat $TMPDIR/pull_closed.out
26425c53ea7aSmjnelson				if grep "^merging.*failed" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
26435c53ea7aSmjnelson					printf "$mergefailmsg"
26445c53ea7aSmjnelson				fi
2645cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
26465c53ea7aSmjnelson				return
26475c53ea7aSmjnelson			fi
26485c53ea7aSmjnelson		fi
26495c53ea7aSmjnelson
26505c53ea7aSmjnelson		printf "updated %s with the following results:\n" \
26515c53ea7aSmjnelson		    "$CODEMGR_WS/usr/closed"
26525c53ea7aSmjnelson		cat $TMPDIR/pull_closed.out
26535c53ea7aSmjnelson		if grep "^merging" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
26545c53ea7aSmjnelson			printf "$mergepassmsg"
2655cdf0c1d5Smjnelson		fi
2656cdf0c1d5Smjnelson	fi
2657f457028bSMark J. Nelson
2658f457028bSMark J. Nelson	#
2659f457028bSMark J. Nelson	# Per-changeset output is neither useful nor manageable for a
2660f457028bSMark J. Nelson	# newly-created repository.
2661f457028bSMark J. Nelson	#
2662f457028bSMark J. Nelson	if [ -f $TMPDIR/new_repository ]; then
2663f457028bSMark J. Nelson		return
2664f457028bSMark J. Nelson	fi
2665f457028bSMark J. Nelson
2666f457028bSMark J. Nelson	printf "\nadded the following changesets to open repository:\n"
2667f457028bSMark J. Nelson	cat $TMPDIR/incoming_open.out
2668f457028bSMark J. Nelson
2669f457028bSMark J. Nelson	#
2670f457028bSMark J. Nelson	# The closed repository could have been newly created, even though
2671f457028bSMark J. Nelson	# the open one previously existed...
2672f457028bSMark J. Nelson	#
2673f457028bSMark J. Nelson	if [ -f $TMPDIR/new_closed ]; then
2674f457028bSMark J. Nelson		return
2675f457028bSMark J. Nelson	fi
2676f457028bSMark J. Nelson
2677f457028bSMark J. Nelson	if [ -f $TMPDIR/incoming_closed.out ]; then
2678f457028bSMark J. Nelson		printf "\nadded the following changesets to closed repository:\n"
2679f457028bSMark J. Nelson		cat $TMPDIR/incoming_closed.out
2680f457028bSMark J. Nelson	fi
2681cdf0c1d5Smjnelson}
2682cdf0c1d5Smjnelson
2683*597bd30bSMike Kupfertype bringover_subversion > /dev/null 2>&1 || function bringover_subversion {
2684cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2685cdf0c1d5Smjnelson
2686cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.svn ]]; then
2687cdf0c1d5Smjnelson		staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2688cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2689cdf0c1d5Smjnelson	else
2690cdf0c1d5Smjnelson		typeset root
2691cdf0c1d5Smjnelson		root=$(staffer svn info $CODEMGR_WS |
2692cdf0c1d5Smjnelson			nawk '/^Repository Root:/ {print $NF}')
2693cdf0c1d5Smjnelson		if [[ $root != $BRINGOVER_WS ]]; then
2694cdf0c1d5Smjnelson			# We fail here because there's no way to update
2695cdf0c1d5Smjnelson			# from a named repo.
2696cdf0c1d5Smjnelson			cat <<-EOF
2697cdf0c1d5Smjnelson			\$BRINGOVER_WS doesn't match repository root:
2698cdf0c1d5Smjnelson			  \$BRINGOVER_WS:  $BRINGOVER_WS
2699cdf0c1d5Smjnelson			  Repository root: $root
2700cdf0c1d5Smjnelson			EOF
2701cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2702cdf0c1d5Smjnelson		else
2703cdf0c1d5Smjnelson			# If a conflict happens, svn still exits 0.
2704cdf0c1d5Smjnelson			staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2705cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2706cdf0c1d5Smjnelson			if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2707cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2708cdf0c1d5Smjnelson			fi
2709cdf0c1d5Smjnelson		fi
2710cdf0c1d5Smjnelson	fi
2711cdf0c1d5Smjnelson}
2712cdf0c1d5Smjnelson
2713*597bd30bSMike Kupfertype bringover_none > /dev/null 2>&1 || function bringover_none {
2714cdf0c1d5Smjnelson	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2715cdf0c1d5Smjnelson	touch $TMPDIR/bringover_failed
2716cdf0c1d5Smjnelson}
2717cdf0c1d5Smjnelson
2718cdf0c1d5Smjnelson# Parse the URL.
2719cdf0c1d5Smjnelson# The other way to deal with empty components is to echo a string that can
2720cdf0c1d5Smjnelson# be eval'ed by the caller to associate values (possibly empty) with
2721cdf0c1d5Smjnelson# variables.  In that case, passing in a printf string would let the caller
2722cdf0c1d5Smjnelson# choose the variable names.
2723*597bd30bSMike Kupferfunction parse_url {
2724cdf0c1d5Smjnelson	typeset url method host port path
2725cdf0c1d5Smjnelson
2726cdf0c1d5Smjnelson	url=$1
2727cdf0c1d5Smjnelson	method=${url%%://*}
2728cdf0c1d5Smjnelson	host=${url#$method://}
2729cdf0c1d5Smjnelson	path=${host#*/}
2730cdf0c1d5Smjnelson	host=${host%%/*}
2731cdf0c1d5Smjnelson	if [[ $host == *:* ]]; then
2732cdf0c1d5Smjnelson		port=${host#*:}
2733cdf0c1d5Smjnelson		host=${host%:*}
2734cdf0c1d5Smjnelson	fi
2735cdf0c1d5Smjnelson
2736cdf0c1d5Smjnelson	# method can never be empty.  host can only be empty if method is
2737cdf0c1d5Smjnelson	# file, and that implies it's localhost.  path can default to / if
2738cdf0c1d5Smjnelson	# it's otherwise empty, leaving port as the only component without
2739cdf0c1d5Smjnelson	# a default, so it has to go last.
2740cdf0c1d5Smjnelson	echo $method ${host:-localhost} ${path:-/} $port
2741cdf0c1d5Smjnelson}
2742cdf0c1d5Smjnelson
2743*597bd30bSMike Kupferfunction http_get {
2744cdf0c1d5Smjnelson	typeset url method host port path
2745cdf0c1d5Smjnelson
2746cdf0c1d5Smjnelson	url=$1
2747cdf0c1d5Smjnelson
2748cdf0c1d5Smjnelson	if [[ -n $http_proxy ]]; then
2749cdf0c1d5Smjnelson		parse_url $http_proxy | read method host path port
2750cdf0c1d5Smjnelson		echo "GET $url HTTP/1.0\r\n" |
2751cdf0c1d5Smjnelson			mconnect -p ${port:-8080} $host
2752cdf0c1d5Smjnelson	else
2753cdf0c1d5Smjnelson		parse_url $url | read method host path port
2754cdf0c1d5Smjnelson		echo "GET $path HTTP/1.0\r\n" |
2755cdf0c1d5Smjnelson			mconnect -p ${port:-80} $host
2756cdf0c1d5Smjnelson	fi
2757cdf0c1d5Smjnelson}
2758cdf0c1d5Smjnelson
2759cdf0c1d5Smjnelson#
2760cdf0c1d5Smjnelson#	Decide whether to bringover to the codemgr workspace
2761cdf0c1d5Smjnelson#
2762cdf0c1d5Smjnelsonif [ "$n_FLAG" = "n" ]; then
2763ca0ac982Smjnelson
2764ca0ac982Smjnelson	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2765ca0ac982Smjnelson		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2766ca0ac982Smjnelson		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2767ca0ac982Smjnelson		exit 1
2768ca0ac982Smjnelson	fi
2769ca0ac982Smjnelson
2770cdf0c1d5Smjnelson	run_hook PRE_BRINGOVER
2771cdf0c1d5Smjnelson
2772cdf0c1d5Smjnelson	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2773cdf0c1d5Smjnelson	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2774cdf0c1d5Smjnelson
2775ca0ac982Smjnelson	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2776cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
277732f1e47bSsommerfe
277832f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
277932f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
278032f1e47bSsommerfe		build_ok=n
278132f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
27827c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
27837c478bd9Sstevel@tonic-gate		exit 1
27847c478bd9Sstevel@tonic-gate	fi
2785085d331dSkupfer
2786ca0ac982Smjnelson	#
2787ca0ac982Smjnelson	# It's possible that we used the bringover above to create
2788ca0ac982Smjnelson	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2789ca0ac982Smjnelson	# but should now be the same as $BRINGOVER_WS.
2790ca0ac982Smjnelson	#
2791ca0ac982Smjnelson	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2792ca0ac982Smjnelson
279347703246Ssommerfe	run_hook POST_BRINGOVER
279447703246Ssommerfe
2795085d331dSkupfer	#
2796085d331dSkupfer	# Possible transition from pre-split workspace to split
2797085d331dSkupfer	# workspace.  See if the bringover changed anything.
2798085d331dSkupfer	#
2799085d331dSkupfer	CLOSED_IS_PRESENT="$orig_closed_is_present"
2800085d331dSkupfer	check_closed_tree
28017c478bd9Sstevel@tonic-gateelse
28027c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
28037c478bd9Sstevel@tonic-gatefi
28047c478bd9Sstevel@tonic-gate
2805*597bd30bSMike Kupferif [ "$CLOSED_IS_PRESENT" = no ]; then
2806*597bd30bSMike Kupfer	crypto_is_present >> "$LOGFILE"
2807*597bd30bSMike Kupfer	if (( $? != 0 )); then
2808*597bd30bSMike Kupfer		build_ok=n
2809*597bd30bSMike Kupfer		echo "A crypto tarball must be provided when" \
2810*597bd30bSMike Kupfer		    "there is no closed tree." |
2811*597bd30bSMike Kupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
2812*597bd30bSMike Kupfer		exit 1
2813*597bd30bSMike Kupfer	fi
2814*597bd30bSMike Kupferfi
2815*597bd30bSMike Kupfer
2816cdf0c1d5Smjnelsonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2817cdf0c1d5Smjnelson
2818cdf0c1d5Smjnelson# System
2819cdf0c1d5Smjnelsonwhence uname | tee -a $build_environ_file >> $LOGFILE
2820cdf0c1d5Smjnelsonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2821cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2822cdf0c1d5Smjnelson
2823cdf0c1d5Smjnelson# nightly
2824cdf0c1d5Smjnelsonecho "$0 $@" | tee -a $build_environ_file >> $LOGFILE
2825cdf0c1d5Smjnelsonif [[ $nightly_path = "/opt/onbld/bin/nightly" ]] &&
2826cdf0c1d5Smjnelson    pkginfo SUNWonbld > /dev/null 2>&1 ; then
2827cdf0c1d5Smjnelson	pkginfo -l SUNWonbld | egrep "PKGINST:|VERSION:|PSTAMP:"
2828cdf0c1d5Smjnelsonelse
282930635de9SJohn.Zolnowsky@Sun.COM	echo "$nightly_ls"
2830cdf0c1d5Smjnelsonfi | tee -a $build_environ_file >> $LOGFILE
2831cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2832cdf0c1d5Smjnelson
2833cdf0c1d5Smjnelson# make
2834cdf0c1d5Smjnelsonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
2835cdf0c1d5Smjnelson$MAKE -v | tee -a $build_environ_file >> $LOGFILE
2836cdf0c1d5Smjnelsonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2837cdf0c1d5Smjnelson    tee -a $build_environ_file >> $LOGFILE
2838cdf0c1d5Smjnelson
2839cdf0c1d5Smjnelson#
2840cdf0c1d5Smjnelson# Report the compiler versions.
2841cdf0c1d5Smjnelson#
2842cdf0c1d5Smjnelson
2843cdf0c1d5Smjnelsonif [[ ! -f $SRC/Makefile ]]; then
2844cdf0c1d5Smjnelson	build_ok=n
2845cdf0c1d5Smjnelson	echo "\nUnable to find \"Makefile\" in $SRC." | \
2846cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2847cdf0c1d5Smjnelson	exit 1
2848cdf0c1d5Smjnelsonfi
2849cdf0c1d5Smjnelson
2850cdf0c1d5Smjnelson( cd $SRC
2851cdf0c1d5Smjnelson  for target in cc-version cc64-version java-version; do
2852cdf0c1d5Smjnelson	echo
2853cdf0c1d5Smjnelson	#
2854cdf0c1d5Smjnelson	# Put statefile somewhere we know we can write to rather than trip
2855cdf0c1d5Smjnelson	# over a read-only $srcroot.
2856cdf0c1d5Smjnelson	#
2857cdf0c1d5Smjnelson	rm -f $TMPDIR/make-state
2858cdf0c1d5Smjnelson	export SRC
2859cdf0c1d5Smjnelson	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2860cdf0c1d5Smjnelson		continue
2861cdf0c1d5Smjnelson	fi
2862cdf0c1d5Smjnelson	touch $TMPDIR/nocompiler
2863cdf0c1d5Smjnelson  done
2864cdf0c1d5Smjnelson  echo
2865cdf0c1d5Smjnelson) | tee -a $build_environ_file >> $LOGFILE
2866cdf0c1d5Smjnelson
2867cdf0c1d5Smjnelsonif [ -f $TMPDIR/nocompiler ]; then
2868cdf0c1d5Smjnelson	rm -f $TMPDIR/nocompiler
2869cdf0c1d5Smjnelson	build_ok=n
2870cdf0c1d5Smjnelson	echo "Aborting due to missing compiler." |
2871cdf0c1d5Smjnelson		tee -a $build_environ_file >> $LOGFILE
2872cdf0c1d5Smjnelson	exit 1
2873cdf0c1d5Smjnelsonfi
2874cdf0c1d5Smjnelson
2875cdf0c1d5Smjnelson# as
2876cdf0c1d5Smjnelsonwhence as | tee -a $build_environ_file >> $LOGFILE
2877cdf0c1d5Smjnelsonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2878cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2879cdf0c1d5Smjnelson
2880cdf0c1d5Smjnelson# Check that we're running a capable link-editor
2881cdf0c1d5Smjnelsonwhence ld | tee -a $build_environ_file >> $LOGFILE
2882cdf0c1d5SmjnelsonLDVER=`ld -V 2>&1`
2883cdf0c1d5Smjnelsonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
2884cdf0c1d5SmjnelsonLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
2885cdf0c1d5Smjnelsonif [ `expr $LDVER \< 422` -eq 1 ]; then
2886cdf0c1d5Smjnelson	echo "The link-editor needs to be at version 422 or higher to build" | \
2887cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2888cdf0c1d5Smjnelson	echo "the latest stuff.  Hope your build works." | \
2889cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2890cdf0c1d5Smjnelsonfi
2891cdf0c1d5Smjnelson
28927c478bd9Sstevel@tonic-gate#
28934e5b757fSkupfer# Build and use the workspace's tools if requested
28947c478bd9Sstevel@tonic-gate#
28954e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
28964e5b757fSkupfer	set_non_debug_build_flags
28977c478bd9Sstevel@tonic-gate
28987c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
28992e02daeeSRainer Orth	if [[ $? = 0 ]]; then
29002e02daeeSRainer Orth		tools_build_ok=n
29012e02daeeSRainer Orth	fi
29024e5b757fSkupfer
29032e02daeeSRainer Orth	if [[ $tools_build_ok = y ]]; then
29042e02daeeSRainer Orth		echo "\n==== Creating protolist tools file at `date` ====" \
29052e02daeeSRainer Orth			>> $LOGFILE
29062e02daeeSRainer Orth		protolist $TOOLS_PROTO > $ATLOG/proto_list_tools_${MACH}
29072e02daeeSRainer Orth		echo "==== protolist tools file created at `date` ====\n" \
29082e02daeeSRainer Orth			>> $LOGFILE
29092e02daeeSRainer Orth
29102e02daeeSRainer Orth		if [ "$N_FLAG" != "y" ]; then
29112e02daeeSRainer Orth			echo "\n==== Impact on tools packages ====\n" \
29122e02daeeSRainer Orth				>> $mail_msg_file
29132e02daeeSRainer Orth
29142e02daeeSRainer Orth			# Use the current tools exception list.
29152e02daeeSRainer Orth			exc=etc/exception_list_$MACH
29162e02daeeSRainer Orth			if [ -f $SRC/tools/$exc ]; then
29172e02daeeSRainer Orth				TOOLS_ELIST="-e $SRC/tools/$exc"
29182e02daeeSRainer Orth			fi
29192e02daeeSRainer Orth			# Compare the build's proto list with current package
29202e02daeeSRainer Orth			# definitions to audit the quality of package
29212e02daeeSRainer Orth			# definitions and makefile install targets.
29222e02daeeSRainer Orth			$PROTOCMPTERSE \
29232e02daeeSRainer Orth			    "Files missing from the proto area:" \
29242e02daeeSRainer Orth			    "Files missing from packages:" \
29252e02daeeSRainer Orth			    "Inconsistencies between pkgdefs and proto area:" \
29262e02daeeSRainer Orth			    ${TOOLS_ELIST} \
29272e02daeeSRainer Orth			    -d $SRC/tools \
29282e02daeeSRainer Orth			    $ATLOG/proto_list_tools_${MACH} \
29292e02daeeSRainer Orth			    >> $mail_msg_file
29302e02daeeSRainer Orth		fi
29312e02daeeSRainer Orth	fi
29322e02daeeSRainer Orth
29332e02daeeSRainer Orth	if [[ $tools_build_ok = y && "$t_FLAG" = y ]]; then
29344e5b757fSkupfer		use_tools $TOOLS_PROTO
29354e5b757fSkupfer	fi
29367c478bd9Sstevel@tonic-gatefi
29377c478bd9Sstevel@tonic-gate
29386fec3625Sdduvall#
29396fec3625Sdduvall# copy ihv proto area in addition to the build itself
29406fec3625Sdduvall#
29416fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
29426fec3625Sdduvall	copy_ihv_proto
29436fec3625Sdduvallfi
29446fec3625Sdduvall
29457c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
29467c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
29477c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
29487c478bd9Sstevel@tonic-gateelse
29494e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
29504e5b757fSkupfer	touch $SRC/.build.tstamp
29514e5b757fSkupfer
29527c478bd9Sstevel@tonic-gate	normal_build
29537c478bd9Sstevel@tonic-gatefi
29547c478bd9Sstevel@tonic-gate
29554e5b757fSkupfer#
2956*597bd30bSMike Kupfer# Generate the THIRDPARTYLICENSE files if needed.  This is done after
2957*597bd30bSMike Kupfer# the build, so that dynamically-created license files are there.
2958*597bd30bSMike Kupfer# It's done before findunref to help identify license files that need
2959*597bd30bSMike Kupfer# to be added to tools/opensolaris/license-list.
29605d715dd7Skupfer#
29615d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2962*597bd30bSMike Kupfer	echo "\n==== Generating THIRDPARTYLICENSE files ====\n" |
2963*597bd30bSMike Kupfer	    tee -a "$mail_msg_file" >> "$LOGFILE"
29645d715dd7Skupfer
2965*597bd30bSMike Kupfer	mktpl usr/src/tools/opensolaris/license-list >> "$LOGFILE" 2>&1
2966cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
29675d715dd7Skupfer		echo "Couldn't create THIRDPARTYLICENSE files" |
2968*597bd30bSMike Kupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
29695d715dd7Skupfer	fi
29705d715dd7Skupferfi
29715d715dd7Skupfer
29725d715dd7Skupfer#
29735d715dd7Skupfer# If OpenSolaris deliverables were requested, do the open-only build
29745d715dd7Skupfer# now, so that it happens at roughly the same point as the source
29755d715dd7Skupfer# product builds.  This lets us take advantage of checks that come
29765d715dd7Skupfer# later (e.g., the core file check).
29774e5b757fSkupfer#
29784e5b757fSkupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
29794e5b757fSkupfer	#
29804e5b757fSkupfer	# Generate skeleton (minimal) closed binaries for open-only
29814e5b757fSkupfer	# build.  There's no need to distinguish debug from non-debug
29824e5b757fSkupfer	# binaries, but it simplifies file management to have separate
29834e5b757fSkupfer	# trees.
29844e5b757fSkupfer	#
29854e5b757fSkupfer
29864e5b757fSkupfer	echo "\n==== Generating skeleton closed binaries for" \
29874e5b757fSkupfer	    "open-only build ====\n" | \
29884e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
29894e5b757fSkupfer
29904e5b757fSkupfer	rm -rf $CODEMGR_WS/closed.skel
29914e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
29924e5b757fSkupfer		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
29934e5b757fSkupfer		    >>$LOGFILE 2>&1
2994cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
29954e5b757fSkupfer			echo "Couldn't create skeleton DEBUG closed binaries." |
29964e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
29974e5b757fSkupfer		fi
29984e5b757fSkupfer	fi
29994e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
30004e5b757fSkupfer		mkclosed $MACH $ROOT-nd $CODEMGR_WS/closed.skel/root_$MACH-nd \
30014e5b757fSkupfer		    >>$LOGFILE 2>&1
3002cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
30034e5b757fSkupfer			echo "Couldn't create skeleton non-DEBUG closed binaries." |
30044e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
30054e5b757fSkupfer		fi
30064e5b757fSkupfer	fi
30074e5b757fSkupfer
30084e5b757fSkupfer	ORIG_CLOSED_IS_PRESENT=$CLOSED_IS_PRESENT
30094e5b757fSkupfer	export CLOSED_IS_PRESENT=no
30104e5b757fSkupfer
30114e5b757fSkupfer	ORIG_ON_CLOSED_BINS="$ON_CLOSED_BINS"
30124e5b757fSkupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
30134e5b757fSkupfer
30144e5b757fSkupfer	normal_build -O
30154e5b757fSkupfer
30164e5b757fSkupfer	ON_CLOSED_BINS=$ORIG_ON_CLOSED_BINS
30174e5b757fSkupfer	CLOSED_IS_PRESENT=$ORIG_CLOSED_IS_PRESENT
30184e5b757fSkupferfi
30194e5b757fSkupfer
30207c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
30217c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
30227c478bd9Sstevel@tonic-gate
30237c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
30247c478bd9Sstevel@tonic-gate	save_binaries
30257c478bd9Sstevel@tonic-gatefi
30267c478bd9Sstevel@tonic-gate
30277c478bd9Sstevel@tonic-gate
30287c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
30297c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
3030cdf0c1d5Smjnelson
30317c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
3032cdf0c1d5Smjnelson	if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
3033cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
30347c478bd9Sstevel@tonic-gate	fi
30357c478bd9Sstevel@tonic-gate
3036cdf0c1d5Smjnelson	if [ $build_ok = y ]; then
3037cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
3038cdf0c1d5Smjnelson	fi
3039cdf0c1d5Smjnelsonfi
3040cdf0c1d5Smjnelson
3041cdf0c1d5Smjnelsonif [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
30427c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
30437c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
30447c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
30457c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
30467c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
30477c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
30487c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
30497c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
30507c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
30517c478bd9Sstevel@tonic-gate	else
30527c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
30537c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
30547c478bd9Sstevel@tonic-gate	fi
30557c478bd9Sstevel@tonic-gate
30567c478bd9Sstevel@tonic-gatefi
30577c478bd9Sstevel@tonic-gate
3058cdf0c1d5Smjnelsonif [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
30591fe69678Skupfer	#
30601fe69678Skupfer	# Copy the open sources into their own tree, set up the closed
30614e5b757fSkupfer	# binaries, and set up the environment.  The build looks for
30624e5b757fSkupfer	# the closed binaries in a location that depends on whether
30634e5b757fSkupfer	# it's a DEBUG build, so we might need to make two copies.
30641fe69678Skupfer	#
3065cdf0c1d5Smjnelson	# If copy_source fails, it will have already generated an
3066cdf0c1d5Smjnelson	# error message and set build_ok=n, so we don't need to worry
3067cdf0c1d5Smjnelson	# about that here.
3068cdf0c1d5Smjnelson	#
30691fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
3070cdf0c1d5Smjnelsonfi
3071cdf0c1d5Smjnelson
3072cdf0c1d5Smjnelsonif [ "$SO_FLAG" = "y" -a $build_ok = y ]; then
30731fe69678Skupfer	SRC=$OPEN_SRCDIR/usr/src
30741fe69678Skupfer
30751fe69678Skupfer	# Try not to clobber any user-provided closed binaries.
30761fe69678Skupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
30774e5b757fSkupfer
30784e5b757fSkupfer	echo "\n==== Copying skeleton closed binaries to" \
30794e5b757fSkupfer	    "$ON_CLOSED_BINS ====\n" | \
30801fe69678Skupfer	    tee -a $mail_msg_file >> $LOGFILE
30814e5b757fSkupfer
30824e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
30834e5b757fSkupfer		mkclosed $MACH $ROOT $ON_CLOSED_BINS/root_$MACH >>$LOGFILE 2>&1
3084cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
30851fe69678Skupfer			build_ok=n
30864e5b757fSkupfer			echo "Couldn't create DEBUG closed binaries." |
30871fe69678Skupfer			    tee -a $mail_msg_file >> $LOGFILE
30881fe69678Skupfer		fi
30894e5b757fSkupfer	fi
30904e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
30914e5b757fSkupfer		root=$ROOT
30924e5b757fSkupfer		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
30934e5b757fSkupfer		mkclosed $MACH $root $ON_CLOSED_BINS/root_$MACH-nd \
30944e5b757fSkupfer		    >>$LOGFILE 2>&1
3095cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
30964e5b757fSkupfer			build_ok=n
30974e5b757fSkupfer			echo "Couldn't create non-DEBUG closed binaries." |
30984e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
30994e5b757fSkupfer		fi
31004e5b757fSkupfer	fi
31014e5b757fSkupfer
31024e5b757fSkupfer	export CLOSED_IS_PRESENT=no
31031fe69678Skupferfi
31041fe69678Skupfer
31051fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
31064e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
31074e5b757fSkupfer	rm -rf `allprotos`
31087c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
31094e5b757fSkupfer		set_non_debug_build_flags
3110b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
31111fe69678Skupfer		#
31121fe69678Skupfer		# SRC was set earlier to point to the source build
31131fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
31141fe69678Skupfer		#
31151fe69678Skupfer		TOOLS=${SRC}/tools
31161fe69678Skupfer		build_tools ${SRC}/tools/proto
3117b91d9e0fSdanmcd		TOOLS=$ORIG_TOOLS
31187c478bd9Sstevel@tonic-gate	fi
31197c478bd9Sstevel@tonic-gate
31207c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
31217c478bd9Sstevel@tonic-gate	normal_build
31227c478bd9Sstevel@tonic-gatefi
31237c478bd9Sstevel@tonic-gate
31241fe69678Skupferif [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
31251fe69678Skupfer	rm -rf $ON_CLOSED_BINS
31261fe69678Skupferfi
31271fe69678Skupfer
31284e5b757fSkupfer#
31294e5b757fSkupfer# There are several checks that need to look at the proto area, but
31304e5b757fSkupfer# they only need to look at one, and they don't care whether it's
31314e5b757fSkupfer# DEBUG or non-DEBUG.
31324e5b757fSkupfer#
31334e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
31344e5b757fSkupfer	checkroot=$ROOT-nd
31354e5b757fSkupferelse
31364e5b757fSkupfer	checkroot=$ROOT
31374e5b757fSkupferfi
31384e5b757fSkupfer
31397c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
31407c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
31417c478bd9Sstevel@tonic-gate		>> $LOGFILE
31424e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
31437c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
31447c478bd9Sstevel@tonic-gate		>> $LOGFILE
31457c478bd9Sstevel@tonic-gate
31467c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
31477c478bd9Sstevel@tonic-gate		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
31487c478bd9Sstevel@tonic-gate
31497c478bd9Sstevel@tonic-gate		# If there is a reference proto list, compare the build's proto
31507c478bd9Sstevel@tonic-gate		# list with the reference to see changes in proto areas.
31517c478bd9Sstevel@tonic-gate		# Use the current exception list.
31527c478bd9Sstevel@tonic-gate		exc=etc/exception_list_$MACH
31537c478bd9Sstevel@tonic-gate		if [ -f $SRC/pkgdefs/$exc ]; then
31547c478bd9Sstevel@tonic-gate			ELIST="-e $SRC/pkgdefs/$exc"
31557c478bd9Sstevel@tonic-gate		fi
31566fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
31576fec3625Sdduvall			ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
31586fec3625Sdduvall		fi
31597c478bd9Sstevel@tonic-gate
31607c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
3161b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
3162b4add148Sdduvall			# IHV proto list to the reference list if the reference
3163b4add148Sdduvall			# was built without -X.
3164b4add148Sdduvall			#
3165b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
3166b4add148Sdduvall			# IHV proto list to the build's proto list if the
3167b4add148Sdduvall			# reference was built with -X.
3168b4add148Sdduvall			#
3169b4add148Sdduvall			# Use the presence of the first file entry of the cached
3170b4add148Sdduvall			# IHV proto list in the reference list to determine
3171b4add148Sdduvall			# whether it was build with -X or not.
3172b4add148Sdduvall			IHV_REF_PROTO_LIST=$SRC/pkgdefs/etc/proto_list_ihv_$MACH
3173b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
3174b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
3175b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
3176b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
3177b4add148Sdduvall					grep -w "$grepfor" \
3178b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
3179b4add148Sdduvall					if [ ! "$?" = "0" ]; then
3180b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
3181b4add148Sdduvall					fi
3182b4add148Sdduvall				else
3183b4add148Sdduvall					grep -w "$grepfor" \
3184b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
3185b4add148Sdduvall					if [ "$?" = "0" ]; then
3186b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
3187b4add148Sdduvall					fi
3188b4add148Sdduvall				fi
3189b4add148Sdduvall			fi
3190b4add148Sdduvall
31917c478bd9Sstevel@tonic-gate			$PROTOCMPTERSE \
31927c478bd9Sstevel@tonic-gate			  "Files in yesterday's proto area, but not today's:" \
31937c478bd9Sstevel@tonic-gate			  "Files in today's proto area, but not yesterday's:" \
31947c478bd9Sstevel@tonic-gate			  "Files that changed between yesterday and today:" \
31957c478bd9Sstevel@tonic-gate			  ${ELIST} \
31967c478bd9Sstevel@tonic-gate			  -d $REF_PROTO_LIST \
3197b4add148Sdduvall			  $REF_IHV_PROTO \
31987c478bd9Sstevel@tonic-gate			  $ATLOG/proto_list_${MACH} \
3199b4add148Sdduvall			  $IHV_PROTO_LIST \
32007c478bd9Sstevel@tonic-gate				>> $mail_msg_file
32017c478bd9Sstevel@tonic-gate		fi
32027c478bd9Sstevel@tonic-gate		# Compare the build's proto list with current package
32037c478bd9Sstevel@tonic-gate		# definitions to audit the quality of package definitions
32047c478bd9Sstevel@tonic-gate		# and makefile install targets. Use the current exception list.
3205fb23a357Skupfer		PKGDEFS_LIST=""
3206fb23a357Skupfer		for d in $abssrcdirs; do
3207fb23a357Skupfer			if [ -d $d/pkgdefs ]; then
3208fb23a357Skupfer				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
3209fb23a357Skupfer			fi
3210fb23a357Skupfer		done
32116fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
32126fec3625Sdduvall			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
32136fec3625Sdduvall		fi
32147c478bd9Sstevel@tonic-gate
32157c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
32167c478bd9Sstevel@tonic-gate		    "Files missing from the proto area:" \
32177c478bd9Sstevel@tonic-gate		    "Files missing from packages:" \
32187c478bd9Sstevel@tonic-gate		    "Inconsistencies between pkgdefs and proto area:" \
32197c478bd9Sstevel@tonic-gate		    ${ELIST} \
32207c478bd9Sstevel@tonic-gate		    ${PKGDEFS_LIST} \
32217c478bd9Sstevel@tonic-gate		    $ATLOG/proto_list_${MACH} \
32227c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
32237c478bd9Sstevel@tonic-gate	fi
32247c478bd9Sstevel@tonic-gatefi
32257c478bd9Sstevel@tonic-gate
32267c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
32277c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
32287c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
32297c478bd9Sstevel@tonic-gatefi
32307c478bd9Sstevel@tonic-gate
32317c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
32327c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
32337c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
32347c478bd9Sstevel@tonic-gate# the variable now.
32357c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
32367c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
32377c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
32387c478bd9Sstevel@tonic-gate	# The rm -rf command below produces predictable errors if
32397c478bd9Sstevel@tonic-gate	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
32407c478bd9Sstevel@tonic-gate	# and that directory is accessed via NFS.  This is because
32417c478bd9Sstevel@tonic-gate	# deleted-but-still-open files don't actually disappear as
32427c478bd9Sstevel@tonic-gate	# expected, but rather turn into .nfsXXXX junk files, leaving
32437c478bd9Sstevel@tonic-gate	# the directory non-empty.  Since this is a not-unusual usage
32447c478bd9Sstevel@tonic-gate	# pattern, and we still want to catch other errors here, we
32457c478bd9Sstevel@tonic-gate	# take the unusal step of moving aside 'nightly' from that
32467c478bd9Sstevel@tonic-gate	# directory (if we're using it).
3247cdf0c1d5Smjnelson	mypath=${nightly_path##*/root_$MACH/}
3248cdf0c1d5Smjnelson	if [ "$mypath" = $nightly_path ]; then
3249cdf0c1d5Smjnelson		mypath=opt/onbld/bin/${nightly_path##*/}
32507c478bd9Sstevel@tonic-gate	fi
3251cdf0c1d5Smjnelson	if [ $nightly_path -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
3252cdf0c1d5Smjnelson		mv -f $nightly_path $PARENT_WS/proto/root_$MACH
32537c478bd9Sstevel@tonic-gate	fi
32547c478bd9Sstevel@tonic-gate	rm -rf $PARENT_WS/proto/root_$MACH/*
32557c478bd9Sstevel@tonic-gate	unset Ulockfile
32567c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
32574e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
32587c478bd9Sstevel@tonic-gate		cd $ROOT
32594e5b757fSkupfer		( tar cf - . |
32604e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
32617c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
32627c478bd9Sstevel@tonic-gate	fi
32634e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
32644e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
32654e5b757fSkupfer		cd $ROOT-nd
32664e5b757fSkupfer		( tar cf - . |
32674e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
32684e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
32694e5b757fSkupfer	fi
32704e5b757fSkupferfi
32717c478bd9Sstevel@tonic-gate
32727c478bd9Sstevel@tonic-gate#
327375ce41a5SAli Bahrami# ELF verification: ABI (-A) and runtime (-r) checks
32747c478bd9Sstevel@tonic-gate#
327575ce41a5SAli Bahramiif [[ ($build_ok = y) && ( ($A_FLAG = y) || ($r_FLAG = y) ) ]]; then
327675ce41a5SAli Bahrami	# Directory ELF-data.$MACH holds the files produced by these tests.
327775ce41a5SAli Bahrami	elf_ddir=$SRC/ELF-data.$MACH
32787c478bd9Sstevel@tonic-gate
327975ce41a5SAli Bahrami	# If there is a previous ELF-data backup directory, remove it. Then,
328075ce41a5SAli Bahrami	# rotate current ELF-data directory into its place and create a new
328175ce41a5SAli Bahrami	# empty directory
328275ce41a5SAli Bahrami	rm -rf $elf_ddir.ref
328375ce41a5SAli Bahrami	if [[ -d $elf_ddir ]]; then
328475ce41a5SAli Bahrami		mv $elf_ddir $elf_ddir.ref
328575ce41a5SAli Bahrami	fi
328675ce41a5SAli Bahrami	mkdir -p $elf_ddir
328775ce41a5SAli Bahrami
328875ce41a5SAli Bahrami	# Call find_elf to produce a list of the ELF objects in the proto area.
328975ce41a5SAli Bahrami	# This list is passed to check_rtime and interface_check, preventing
329075ce41a5SAli Bahrami	# them from separately calling find_elf to do the same work twice.
329175ce41a5SAli Bahrami	find_elf -fr $checkroot > $elf_ddir/object_list
329275ce41a5SAli Bahrami
329375ce41a5SAli Bahrami	if [[ $A_FLAG = y ]]; then
32947c478bd9Sstevel@tonic-gate	       	echo "\n==== Check versioning and ABI information ====\n"  | \
32957c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
32967c478bd9Sstevel@tonic-gate
329775ce41a5SAli Bahrami		# Produce interface description for the proto. Report errors.
329875ce41a5SAli Bahrami		interface_check -o -w $elf_ddir -f object_list \
329975ce41a5SAli Bahrami			-i interface -E interface.err
330075ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.err ]]; then
330175ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.err \
330275ce41a5SAli Bahrami				>> $mail_msg_file
33037c478bd9Sstevel@tonic-gate		fi
33047c478bd9Sstevel@tonic-gate
330575ce41a5SAli Bahrami	       	echo "\n==== Compare versioning and ABI information to" \
330675ce41a5SAli Bahrami		    "baseline ====\n"  | tee -a $LOGFILE >> $mail_msg_file
33077c478bd9Sstevel@tonic-gate
330875ce41a5SAli Bahrami		# Compare new interface to baseline interface. Report errors.
330975ce41a5SAli Bahrami		interface_cmp -d -o $SRC/tools/abi/interface.$MACH \
331075ce41a5SAli Bahrami			$elf_ddir/interface > $elf_ddir/interface.cmp
331175ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.cmp ]]; then
331275ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.cmp \
331375ce41a5SAli Bahrami				>> $mail_msg_file
33147c478bd9Sstevel@tonic-gate		fi
33157c478bd9Sstevel@tonic-gate	fi
33167c478bd9Sstevel@tonic-gate
331775ce41a5SAli Bahrami	if [[ $r_FLAG = y ]]; then
33187c478bd9Sstevel@tonic-gate		echo "\n==== Check ELF runtime attributes ====\n" | \
33197c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
33207c478bd9Sstevel@tonic-gate
332175ce41a5SAli Bahrami		# If we're doing a debug build the proto area will be left
332275ce41a5SAli Bahrami		# with debuggable objects, thus don't assert -s.
332375ce41a5SAli Bahrami		if [[ $D_FLAG = y ]]; then
33247c478bd9Sstevel@tonic-gate			rtime_sflag=""
33257c478bd9Sstevel@tonic-gate		else
33267c478bd9Sstevel@tonic-gate			rtime_sflag="-s"
33277c478bd9Sstevel@tonic-gate		fi
332875ce41a5SAli Bahrami		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
332975ce41a5SAli Bahrami			-D object_list  -f object_list -E runtime.err \
3330622090e3SAli Bahrami			-I runtime.attr.raw
3331622090e3SAli Bahrami
3332622090e3SAli Bahrami		# check_rtime -I output needs to be sorted in order to
3333622090e3SAli Bahrami		# compare it to that from previous builds.
3334622090e3SAli Bahrami		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
3335622090e3SAli Bahrami		rm $elf_ddir/runtime.attr.raw
33367c478bd9Sstevel@tonic-gate
333775ce41a5SAli Bahrami		# Report errors
333875ce41a5SAli Bahrami		if [[ -s $elf_ddir/runtime.err ]]; then
333975ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/runtime.err \
33407c478bd9Sstevel@tonic-gate				>> $mail_msg_file
334175ce41a5SAli Bahrami		fi
33427c478bd9Sstevel@tonic-gate
334375ce41a5SAli Bahrami		# If there is an ELF-data directory from a previous build,
334475ce41a5SAli Bahrami		# then diff the attr files. These files contain information
334575ce41a5SAli Bahrami		# about dependencies, versioning, and runpaths. There is some
334675ce41a5SAli Bahrami		# overlap with the ABI checking done above, but this also
334775ce41a5SAli Bahrami		# flushes out non-ABI interface differences along with the
334875ce41a5SAli Bahrami		# other information.
334975ce41a5SAli Bahrami		echo "\n==== Diff ELF runtime attributes" \
335075ce41a5SAli Bahrami		    "(since last build) ====\n" | \
335175ce41a5SAli Bahrami		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
335275ce41a5SAli Bahrami
335375ce41a5SAli Bahrami		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
335475ce41a5SAli Bahrami			diff $elf_ddir.ref/runtime.attr \
335575ce41a5SAli Bahrami				$elf_ddir/runtime.attr \
335675ce41a5SAli Bahrami				>> $mail_msg_file
335775ce41a5SAli Bahrami		fi
335875ce41a5SAli Bahrami	fi
33597c478bd9Sstevel@tonic-gatefi
33607c478bd9Sstevel@tonic-gate
33617c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
33627c478bd9Sstevel@tonic-gate
33637c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
33647c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
33657c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
33667c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
33677c478bd9Sstevel@tonic-gate	fi
33687c478bd9Sstevel@tonic-gate	set $LINTDIRS
33697c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
33707c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
33717c478bd9Sstevel@tonic-gate	done
33727c478bd9Sstevel@tonic-gateelse
33737c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
33747c478bd9Sstevel@tonic-gatefi
33757c478bd9Sstevel@tonic-gate
33767c478bd9Sstevel@tonic-gate# "make check" begins
33777c478bd9Sstevel@tonic-gate
33787c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
33797c478bd9Sstevel@tonic-gate	# remove old check.out
33807c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
33817c478bd9Sstevel@tonic-gate
33827c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
33837c478bd9Sstevel@tonic-gate	cd $SRC
33847c478bd9Sstevel@tonic-gate	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
33857c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
33867c478bd9Sstevel@tonic-gate
33877c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
33887c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
33897c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
33907c478bd9Sstevel@tonic-gateelse
33917c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
33927c478bd9Sstevel@tonic-gatefi
33937c478bd9Sstevel@tonic-gate
33947c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
33957c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
33967c478bd9Sstevel@tonic-gate
3397fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
33987c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
33997c478bd9Sstevel@tonic-gate
34007c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
34017c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
34027c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
34037c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
34047c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
34057c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
34067c478bd9Sstevel@tonic-gate	fi
34077c478bd9Sstevel@tonic-gate
34089730304dSmeem	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
3409cdf0c1d5Smjnelson	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
34109730304dSmeem	    sort > $SRC/unref-${MACH}.out
34117c478bd9Sstevel@tonic-gate
34127c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
34137c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
34147c478bd9Sstevel@tonic-gate	fi
34157c478bd9Sstevel@tonic-gate
34167c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
34177c478bd9Sstevel@tonic-gatefi
34187c478bd9Sstevel@tonic-gate
34195d715dd7Skupfer#
34205d715dd7Skupfer# Generate the OpenSolaris deliverables if requested.  Some of these
34215d715dd7Skupfer# steps need to come after findunref and are commented below.
34225d715dd7Skupfer#
3423*597bd30bSMike Kupfer
3424*597bd30bSMike Kupfer#
3425*597bd30bSMike Kupfer# Copy an input crypto tarball to the canonical destination (with
3426*597bd30bSMike Kupfer# datestamp), and point the non-stamped symlink at it.
3427*597bd30bSMike Kupfer# Usage: copycrypto from_path suffix
3428*597bd30bSMike Kupfer# Returns 0 if successful, non-zero if not.
3429*597bd30bSMike Kupfer#
3430*597bd30bSMike Kupferfunction copycrypto {
3431*597bd30bSMike Kupfer	typeset from=$1
3432*597bd30bSMike Kupfer	typeset suffix=$2
3433*597bd30bSMike Kupfer	typeset to=$(cryptodest "$suffix").bz2
3434*597bd30bSMike Kupfer	typeset -i stat
3435*597bd30bSMike Kupfer	cp "$from" "$to"
3436*597bd30bSMike Kupfer	stat=$?
3437*597bd30bSMike Kupfer	if (( $stat == 0 )); then
3438*597bd30bSMike Kupfer		cryptolink "$to" "$suffix"
3439*597bd30bSMike Kupfer		stat=$?
3440*597bd30bSMike Kupfer	fi
3441*597bd30bSMike Kupfer	return $stat
3442*597bd30bSMike Kupfer}
3443*597bd30bSMike Kupfer
3444*597bd30bSMike Kupfer#
3445*597bd30bSMike Kupfer# Pass through the crypto tarball(s) that we were given, putting it in
3446*597bd30bSMike Kupfer# the same place that crypto_from_proto puts things.
3447*597bd30bSMike Kupfer#
3448*597bd30bSMike Kupferfunction crypto_passthrough {
3449*597bd30bSMike Kupfer	echo "Reusing $ON_CRYPTO_BINS for crypto tarball(s)..." >> "$LOGFILE"
3450*597bd30bSMike Kupfer	if [ "$D_FLAG" = y ]; then
3451*597bd30bSMike Kupfer		copycrypto "$ON_CRYPTO_BINS" "" >> "$LOGFILE" 2>&1
3452*597bd30bSMike Kupfer		if (( $? != 0 )) ; then
3453*597bd30bSMike Kupfer			echo "Couldn't create DEBUG crypto tarball." |
3454*597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
3455*597bd30bSMike Kupfer		fi
3456*597bd30bSMike Kupfer	fi
3457*597bd30bSMike Kupfer	if [ "$F_FLAG" = n ]; then
3458*597bd30bSMike Kupfer		copycrypto $(ndcrypto "$ON_CRYPTO_BINS") "-nd" \
3459*597bd30bSMike Kupfer		    >> "$LOGFILE" 2>&1
3460*597bd30bSMike Kupfer		if (( $? != 0 )) ; then
3461*597bd30bSMike Kupfer			echo "Couldn't create non-DEBUG crypto tarball." |
3462*597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
3463*597bd30bSMike Kupfer		fi
3464*597bd30bSMike Kupfer	fi
3465*597bd30bSMike Kupfer}
3466*597bd30bSMike Kupfer
34675d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
34685d715dd7Skupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
34695d715dd7Skupfer	    tee -a $mail_msg_file >> $LOGFILE
34705d715dd7Skupfer
34715d715dd7Skupfer	cd $CODEMGR_WS
34725d715dd7Skupfer
34735d715dd7Skupfer	#
34745d715dd7Skupfer	# This step grovels through the pkgdefs proto* files, so it
34755d715dd7Skupfer	# must come after findunref.
34765d715dd7Skupfer	#
34775d715dd7Skupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
34785d715dd7Skupfer	closed_basename=on-closed-bins
34795d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
34805d715dd7Skupfer		bindrop "$ROOT" "$ROOT-open" "$closed_basename" \
34815d715dd7Skupfer		    >>"$LOGFILE" 2>&1
3482cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
34835d715dd7Skupfer			echo "Couldn't create DEBUG closed binaries." |
34845d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
34855d715dd7Skupfer		fi
34865d715dd7Skupfer	fi
34875d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
34885d715dd7Skupfer		bindrop -n "$ROOT-nd" "$ROOT-open-nd" "$closed_basename-nd" \
34895d715dd7Skupfer		    >>"$LOGFILE" 2>&1
3490cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
34915d715dd7Skupfer			echo "Couldn't create non-DEBUG closed binaries." |
34925d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
34935d715dd7Skupfer		fi
34945d715dd7Skupfer	fi
34955d715dd7Skupfer
34965d715dd7Skupfer	echo "Generating SUNWonbld tarball..." >> $LOGFILE
34975d715dd7Skupfer	PKGARCHIVE=$PKGARCHIVE_ORIG
34985d715dd7Skupfer	onblddrop >> $LOGFILE 2>&1
3499cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
35005d715dd7Skupfer		echo "Couldn't create SUNWonbld tarball." |
35015d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
35025d715dd7Skupfer	fi
35035d715dd7Skupfer
35045d715dd7Skupfer	echo "Generating README.opensolaris..." >> $LOGFILE
35055d715dd7Skupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
35065d715dd7Skupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
3507cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
35085d715dd7Skupfer		echo "Couldn't create README.opensolaris." |
35095d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
35105d715dd7Skupfer	fi
35115d715dd7Skupfer
35125d715dd7Skupfer	# This step walks the source tree, so it must come after
35135d715dd7Skupfer	# findunref.  It depends on README.opensolaris.
35145d715dd7Skupfer	echo "Generating source tarball..." >> $LOGFILE
35155d715dd7Skupfer	sdrop >>$LOGFILE 2>&1
3516cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
35175d715dd7Skupfer		echo "Couldn't create source tarball." |
35185d715dd7Skupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
35195d715dd7Skupfer	fi
35205d715dd7Skupfer
35215d715dd7Skupfer	# This step depends on the closed binaries tarballs.
35225d715dd7Skupfer	echo "Generating BFU tarball(s)..." >> $LOGFILE
35235d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
35245d715dd7Skupfer		makebfu_filt bfudrop "$ROOT-open" \
35255d715dd7Skupfer		    "$closed_basename.$MACH.tar.bz2" nightly-osol
3526cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
35275d715dd7Skupfer			echo "Couldn't create DEBUG archives tarball." |
35285d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
35295d715dd7Skupfer		fi
35305d715dd7Skupfer	fi
35315d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
35325d715dd7Skupfer		makebfu_filt bfudrop -n "$ROOT-open-nd" \
35335d715dd7Skupfer		    "$closed_basename-nd.$MACH.tar.bz2" nightly-osol-nd
3534cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
35355d715dd7Skupfer			echo "Couldn't create non-DEBUG archives tarball." |
35365d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
35375d715dd7Skupfer		fi
35385d715dd7Skupfer	fi
3539*597bd30bSMike Kupfer
3540*597bd30bSMike Kupfer	if [ -n "$ON_CRYPTO_BINS" ]; then
3541*597bd30bSMike Kupfer		crypto_passthrough
3542*597bd30bSMike Kupfer	fi
35435d715dd7Skupferfi
35445d715dd7Skupfer
35457c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
35467c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
35477c478bd9Sstevel@tonic-gate# then don't check the proto area.
35487c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
35497c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
35507c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
35517c478bd9Sstevel@tonic-gate		>>$mail_msg_file
35527c478bd9Sstevel@tonic-gate	arg=-b
35537c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
35544e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
35557c478bd9Sstevel@tonic-gatefi
35567c478bd9Sstevel@tonic-gate
35577c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
35587c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
35597c478bd9Sstevel@tonic-gate		>> $mail_msg_file
35607c478bd9Sstevel@tonic-gate	#
35617c478bd9Sstevel@tonic-gate	# Get pkginfo files from usr/src/pkgdefs
35627c478bd9Sstevel@tonic-gate	#
35637c478bd9Sstevel@tonic-gate	pmodes -qvdP \
3564fb9f9b97Skupfer	`for d in $abssrcdirs; do
3565fb9f9b97Skupfer		if [ -d "$d/pkgdefs" ]
35667c478bd9Sstevel@tonic-gate		then
3567fb9f9b97Skupfer			find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
35687c478bd9Sstevel@tonic-gate		fi
35697c478bd9Sstevel@tonic-gate	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
35707c478bd9Sstevel@tonic-gatefi
35717c478bd9Sstevel@tonic-gate
357296ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
35734e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
35744e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
35754e5b757fSkupfer	fi
357696ccc8cbSesaxe
35774e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
35784e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
357996ccc8cbSesaxe	fi
358096ccc8cbSesaxefi
358196ccc8cbSesaxe
35827c478bd9Sstevel@tonic-gateEND_DATE=`date`
35837c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
35847c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
35857c478bd9Sstevel@tonic-gate
3586c341b28aSDarren Moffattypeset -i10 hours
35877c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
35887c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
35897c478bd9Sstevel@tonic-gate
35907c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
35917c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
35927c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
35937c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
35947c478bd9Sstevel@tonic-gate
35957c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
35967c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
35977c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
35987c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
35997c478bd9Sstevel@tonic-gate
36007c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
36017c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
36027c478bd9Sstevel@tonic-gate
36037c478bd9Sstevel@tonic-gate	#
36047c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
36057c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
36067c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
36077c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
36087c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
36097c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
36107c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
36117c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
36127c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
36137c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
36147c478bd9Sstevel@tonic-gate	# which was already on the parent.
36157c478bd9Sstevel@tonic-gate	#
36167c478bd9Sstevel@tonic-gate
36177c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
36187c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
36197c478bd9Sstevel@tonic-gate	shift
36207c478bd9Sstevel@tonic-gate
36217c478bd9Sstevel@tonic-gate	for unreffile; do
36227c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
36237c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
36247c478bd9Sstevel@tonic-gate	done
36257c478bd9Sstevel@tonic-gate
36267c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
36277c478bd9Sstevel@tonic-gatefi
36287c478bd9Sstevel@tonic-gate
36297c478bd9Sstevel@tonic-gate#
36307c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
36317c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
36327c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
36337c478bd9Sstevel@tonic-gate#
36347c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
36357c478bd9Sstevel@tonic-gate	exit 0
36367c478bd9Sstevel@tonic-gatefi
36377c478bd9Sstevel@tonic-gateexit 1
3638