xref: /titanic_51/usr/src/tools/scripts/nightly.sh (revision d7693b084fa10f5ce9e9dd8d5032270e175985c3)
17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6fb23a357Skupfer# Common Development and Distribution License (the "License").
7fb23a357Skupfer# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
224e5b757fSkupfer
237c478bd9Sstevel@tonic-gate#
24b83ec4edSjmcp# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25445b6314SRichard Lowe# Copyright 2008, 2010, Richard Lowe
26*d7693b08SRoland Mainz# Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
297c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
307c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
337c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
347c478bd9Sstevel@tonic-gate#
357c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
36d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
37d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
387c478bd9Sstevel@tonic-gate#
397c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
407c478bd9Sstevel@tonic-gate#
417c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
427c478bd9Sstevel@tonic-gate#
437c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
447c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
457c478bd9Sstevel@tonic-gate#
467c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
477c478bd9Sstevel@tonic-gate#
487c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
497c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
507c478bd9Sstevel@tonic-gate#
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate#
537c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
547c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
557c478bd9Sstevel@tonic-gate#
567c478bd9Sstevel@tonic-gateunset CDPATH
577c478bd9Sstevel@tonic-gate
58cdf0c1d5Smjnelson# Get the absolute path of the nightly script that the user invoked.  This
59cdf0c1d5Smjnelson# may be a relative path, and we need to do this before changing directory.
60cdf0c1d5Smjnelsonnightly_path=`whence $0`
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
73*d7693b08SRoland Mainzfunction fatal_error
74*d7693b08SRoland Mainz{
75*d7693b08SRoland Mainz	print -u2 "nightly: $*"
76*d7693b08SRoland Mainz	exit 1
77*d7693b08SRoland Mainz}
78*d7693b08SRoland Mainz
794e5b757fSkupfer#
804e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
817c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
827c478bd9Sstevel@tonic-gate# non-DEBUG packages.
834e5b757fSkupfer#
84b83ec4edSjmcp# usage: normal_build
85ead1f93eSLiane Praza#
86597bd30bSMike Kupferfunction normal_build {
877c478bd9Sstevel@tonic-gate
8852a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
89597bd30bSMike Kupfer	typeset crypto_signer="$CODESIGN_USER"
904e5b757fSkupfer
914e5b757fSkupfer	suffix=""
92ead1f93eSLiane Praza
937c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
964e5b757fSkupfer		set_non_debug_build_flags
97597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
986ea3c060SGarrett D'Amore		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
994e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1004e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1017c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
1027c478bd9Sstevel@tonic-gate		fi
1037c478bd9Sstevel@tonic-gate	else
10452a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1057c478bd9Sstevel@tonic-gate	fi
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate	# DEBUG build begins
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
1124e5b757fSkupfer		set_debug_build_flags
113597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
1146ea3c060SGarrett D'Amore		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
1154e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1164e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1177c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
1187c478bd9Sstevel@tonic-gate		fi
1197c478bd9Sstevel@tonic-gate	else
12052a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1217c478bd9Sstevel@tonic-gate	fi
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate	# DEBUG build ends
1244e5b757fSkupfer
12552a52aebSkupfer	p_FLAG="$orig_p_FLAG"
1267c478bd9Sstevel@tonic-gate}
1277c478bd9Sstevel@tonic-gate
1281fe69678Skupfer#
12947703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
13047703246Ssommerfe#
13147703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
13247703246Ssommerfe# our logs and then run the command with ARGS
13347703246Ssommerfe#
134597bd30bSMike Kupferfunction run_hook {
13547703246Ssommerfe	HOOKNAME=$1
13647703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
13747703246Ssommerfe	shift
13847703246Ssommerfe
13947703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
14047703246Ssommerfe	    	(
14147703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
14247703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
14347703246Ssommerfe			if [ "$?" -ne 0 ]; then
14447703246Ssommerfe			    	# Let exit status propagate up
14547703246Ssommerfe			    	touch $TMPDIR/abort
14647703246Ssommerfe			fi
14747703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
14847703246Ssommerfe
14947703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
15047703246Ssommerfe			build_ok=n
15147703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
15247703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
15347703246Ssommerfe			exit 1
15447703246Ssommerfe		fi
15547703246Ssommerfe	fi
15647703246Ssommerfe}
15747703246Ssommerfe
15847703246Ssommerfe#
1591fe69678Skupfer# usage: filelist DESTDIR PATTERN
1601fe69678Skupfer#
161597bd30bSMike Kupferfunction filelist {
1627c478bd9Sstevel@tonic-gate	DEST=$1
1637c478bd9Sstevel@tonic-gate	PATTERN=$2
1647c478bd9Sstevel@tonic-gate	cd ${DEST}
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
1677c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
1687c478bd9Sstevel@tonic-gate		return;
1697c478bd9Sstevel@tonic-gate	fi
1701fe69678Skupfer	for i in `grep -v '^#' ${OBJFILES} | \
1717c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
1727c478bd9Sstevel@tonic-gate	do
1737c478bd9Sstevel@tonic-gate		# wildcard expansion
1747c478bd9Sstevel@tonic-gate		for j in $i
1757c478bd9Sstevel@tonic-gate		do
1767c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
1777c478bd9Sstevel@tonic-gate				echo $j
1787c478bd9Sstevel@tonic-gate			fi
1797c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
1807c478bd9Sstevel@tonic-gate				echo $j
1817c478bd9Sstevel@tonic-gate			fi
1827c478bd9Sstevel@tonic-gate		done
1837c478bd9Sstevel@tonic-gate	done | sort | uniq
1847c478bd9Sstevel@tonic-gate}
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
1877c478bd9Sstevel@tonic-gate# restoration
188597bd30bSMike Kupferfunction save_binaries {
1897c478bd9Sstevel@tonic-gate	# save off list of binaries
1907c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
1917c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1927c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
1937c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
1947c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
1957c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
1967c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
1977c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
1987c478bd9Sstevel@tonic-gate}
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate# delete files
2011fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
202597bd30bSMike Kupferfunction hybridize_files {
2037c478bd9Sstevel@tonic-gate	DEST=$1
2047c478bd9Sstevel@tonic-gate	MAKETARG=$2
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
2077c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2087c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
2097c478bd9Sstevel@tonic-gate	do
2107c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2117c478bd9Sstevel@tonic-gate		rm -rf "${i}"
2127c478bd9Sstevel@tonic-gate	done
2137c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
2147c478bd9Sstevel@tonic-gate	do
2157c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2167c478bd9Sstevel@tonic-gate		rm -f ${i}+
2177c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
2187c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
2197c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
2207c478bd9Sstevel@tonic-gate	done
2217c478bd9Sstevel@tonic-gate}
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
2241fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
225597bd30bSMike Kupferfunction restore_binaries {
2267c478bd9Sstevel@tonic-gate	DEST=$1
2277c478bd9Sstevel@tonic-gate	MAKETARG=$2
2287c478bd9Sstevel@tonic-gate
2297c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
2307c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2317c478bd9Sstevel@tonic-gate	cd ${DEST}
2327c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
2337c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
2347c478bd9Sstevel@tonic-gate}
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate# rename files we save binaries of
2371fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
238597bd30bSMike Kupferfunction rename_files {
2397c478bd9Sstevel@tonic-gate	DEST=$1
2407c478bd9Sstevel@tonic-gate	MAKETARG=$2
2417c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
2427c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2437c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
2447c478bd9Sstevel@tonic-gate	do
2457c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
2467c478bd9Sstevel@tonic-gate		rm -f ${i}.export
2477c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
2487c478bd9Sstevel@tonic-gate	done
2497c478bd9Sstevel@tonic-gate}
2507c478bd9Sstevel@tonic-gate
2511fe69678Skupfer#
2521fe69678Skupfer# Copy some or all of the source tree.
253cdf0c1d5Smjnelson#
254cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
255cdf0c1d5Smjnelson#
2561fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
2571fe69678Skupfer#
258597bd30bSMike Kupferfunction copy_source {
2597c478bd9Sstevel@tonic-gate	WS=$1
2607c478bd9Sstevel@tonic-gate	DEST=$2
2611fe69678Skupfer	label=$3
2621fe69678Skupfer	srcroot=$4
2637c478bd9Sstevel@tonic-gate
264cdf0c1d5Smjnelson	printf "\n==== Creating %s source from %s (%s) ====\n\n" \
265cdf0c1d5Smjnelson	    "$DEST" "$WS" "$label" | tee -a $mail_msg_file >> $LOGFILE
266cdf0c1d5Smjnelson
267cdf0c1d5Smjnelson	printf "cleaning out %s\n" "$DEST." >> $LOGFILE
268cdf0c1d5Smjnelson	rm -rf "$DEST" >> $LOGFILE 2>&1
269cdf0c1d5Smjnelson
270cdf0c1d5Smjnelson	printf "creating %s\n" "$DEST." >> $LOGFILE
271cdf0c1d5Smjnelson	mkdir -p "$DEST" 2>> $LOGFILE
272cdf0c1d5Smjnelson
273cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
274cdf0c1d5Smjnelson		printf "failed to create %s\n" "$DEST" |
2757c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
276cdf0c1d5Smjnelson		build_ok=n
277cdf0c1d5Smjnelson		return 1
278cdf0c1d5Smjnelson	fi
279cdf0c1d5Smjnelson	cd "$WS"
2807c478bd9Sstevel@tonic-gate
281cdf0c1d5Smjnelson	printf "populating %s\n" "$DEST." >> $LOGFILE
2827c478bd9Sstevel@tonic-gate
283cdf0c1d5Smjnelson	case "$SCM_TYPE" in
284cdf0c1d5Smjnelson	teamware)
2851fe69678Skupfer		find $srcroot -name 's\.*' -a -type f -print | \
2867c478bd9Sstevel@tonic-gate		    sed -e 's,SCCS\/s.,,' | \
2877c478bd9Sstevel@tonic-gate		    grep -v '/\.del-*' | \
288cdf0c1d5Smjnelson		    cpio -pd $DEST >>$LOGFILE 2>&1
289cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
290cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$DEST" |
291cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
292cdf0c1d5Smjnelson		    build_ok=n
293cdf0c1d5Smjnelson		    return 1
294cdf0c1d5Smjnelson		fi
295cdf0c1d5Smjnelson		;;
296cdf0c1d5Smjnelson	mercurial)
297cdf0c1d5Smjnelson		copy_source_mercurial $DEST $srcroot
298cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
299cdf0c1d5Smjnelson		    build_ok=n
300cdf0c1d5Smjnelson		    return 1
301cdf0c1d5Smjnelson		fi
302cdf0c1d5Smjnelson		;;
303cdf0c1d5Smjnelson	*)
304cdf0c1d5Smjnelson		build_ok=n
305cdf0c1d5Smjnelson		echo "Tree copy is not supported for workspace type" \
306cdf0c1d5Smjnelson		    "$SCM_TYPE" | tee -a $mail_msg_file >> $LOGFILE
307cdf0c1d5Smjnelson		return 1
308cdf0c1d5Smjnelson		;;
309cdf0c1d5Smjnelson	esac
310cdf0c1d5Smjnelson
311cdf0c1d5Smjnelson	return 0
312cdf0c1d5Smjnelson}
313cdf0c1d5Smjnelson
314cdf0c1d5Smjnelson#
315cdf0c1d5Smjnelson# Mercurial-specific copy code for copy_source().  Handles the
316cdf0c1d5Smjnelson# combined open and closed trees.
317cdf0c1d5Smjnelson#
318cdf0c1d5Smjnelson# Returns 0 for success, non-zero for failure.
319cdf0c1d5Smjnelson#
320cdf0c1d5Smjnelson# usage: copy_source_mercurial destdir srcroot
321cdf0c1d5Smjnelson#
322cdf0c1d5Smjnelsonfunction copy_source_mercurial {
323cdf0c1d5Smjnelson	typeset dest=$1
324cdf0c1d5Smjnelson	typeset srcroot=$2
325cdf0c1d5Smjnelson	typeset open_top closed_top
326cdf0c1d5Smjnelson
327cdf0c1d5Smjnelson	case $srcroot in
328cdf0c1d5Smjnelson	usr)
329cdf0c1d5Smjnelson		open_top=usr
330cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = yes ]]; then
331cdf0c1d5Smjnelson			closed_top=usr/closed
332cdf0c1d5Smjnelson		fi
333cdf0c1d5Smjnelson		;;
334cdf0c1d5Smjnelson	usr/closed*)
335cdf0c1d5Smjnelson		if [[ "$CLOSED_IS_PRESENT" = no ]]; then
336cdf0c1d5Smjnelson			printf "can't copy %s: closed tree not present.\n" \
337cdf0c1d5Smjnelson			    "$srcroot" | tee -a $mail_msg_file >> $LOGFILE
338cdf0c1d5Smjnelson			return 1
339cdf0c1d5Smjnelson		fi
340cdf0c1d5Smjnelson		closed_top="$srcroot"
341cdf0c1d5Smjnelson		;;
342cdf0c1d5Smjnelson	*)
343cdf0c1d5Smjnelson		open_top="$srcroot"
344cdf0c1d5Smjnelson		;;
345cdf0c1d5Smjnelson	esac
346cdf0c1d5Smjnelson
347cdf0c1d5Smjnelson	if [[ -n "$open_top" ]]; then
348cdf0c1d5Smjnelson		hg locate -I "$open_top" | cpio -pd "$dest" >>$LOGFILE 2>&1
349cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
350cdf0c1d5Smjnelson		    printf "cpio failed for %s\n" "$dest" |
351cdf0c1d5Smjnelson			tee -a $mail_msg_file >> $LOGFILE
352cdf0c1d5Smjnelson		    return 1
353cdf0c1d5Smjnelson		fi
354cdf0c1d5Smjnelson	fi
355cdf0c1d5Smjnelson
356cdf0c1d5Smjnelson	if [[ -n "$closed_top" ]]; then
357cdf0c1d5Smjnelson		mkdir -p "$dest/usr/closed" || return 1
358cdf0c1d5Smjnelson		if [[ "$closed_top" = usr/closed ]]; then
359cdf0c1d5Smjnelson			(cd usr/closed; hg locate |
360cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
361cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
362cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed\n" \
363cdf0c1d5Smjnelson				"$dest" | tee -a $mail_msg_file >> $LOGFILE
364cdf0c1d5Smjnelson			    return 1
365cdf0c1d5Smjnelson			fi
366cdf0c1d5Smjnelson		else
367cdf0c1d5Smjnelson			# copy subtree of usr/closed
368cdf0c1d5Smjnelson			closed_top=${closed_top#usr/closed/}
369cdf0c1d5Smjnelson			(cd usr/closed; hg locate -I "$closed_top" |
370cdf0c1d5Smjnelson			    cpio -pd "$dest/usr/closed") >>$LOGFILE 2>&1
371cdf0c1d5Smjnelson			if (( $? != 0 )) ; then
372cdf0c1d5Smjnelson			    printf "cpio failed for %s/usr/closed/%s\n" \
373cdf0c1d5Smjnelson				"$dest" "$closed_top" |
374cdf0c1d5Smjnelson				tee -a $mail_msg_file >> $LOGFILE
375cdf0c1d5Smjnelson			    return 1
376cdf0c1d5Smjnelson			fi
377cdf0c1d5Smjnelson		fi
378cdf0c1d5Smjnelson	fi
379cdf0c1d5Smjnelson
380cdf0c1d5Smjnelson	return 0
3811fe69678Skupfer}
3827c478bd9Sstevel@tonic-gate
3831fe69678Skupfer#
3841fe69678Skupfer# function to create (but not build) the export/crypt source tree.
3851fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
3861fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
3871fe69678Skupfer# builds the tree.
3881fe69678Skupfer#
389597bd30bSMike Kupferfunction set_up_source_build {
3901fe69678Skupfer	WS=$1
3911fe69678Skupfer	DEST=$2
3921fe69678Skupfer	MAKETARG=$3
3931fe69678Skupfer
3941fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
395cdf0c1d5Smjnelson	if (( $? != 0 )); then
396cdf0c1d5Smjnelson	    echo "\nCould not copy source tree for source build." |
397cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
398cdf0c1d5Smjnelson	    build_ok=n
399cdf0c1d5Smjnelson	    return
400cdf0c1d5Smjnelson	fi
401cdf0c1d5Smjnelson
4027c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate	cd $SRC
4057c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
4067c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
4077c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
4087c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
4097c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
4107c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
4117c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
4127c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
4137c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
4167c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
4177c478bd9Sstevel@tonic-gate
4187c478bd9Sstevel@tonic-gate	cd ${DEST}
4197c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
4207c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
4217c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
4227c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
4237c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
4247c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
4257c478bd9Sstevel@tonic-gate		do
4267c478bd9Sstevel@tonic-gate			# make sure the files exist
4277c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
4287c478bd9Sstevel@tonic-gate				continue
4297c478bd9Sstevel@tonic-gate			fi
4307c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
4317c478bd9Sstevel@tonic-gate				continue
4327c478bd9Sstevel@tonic-gate			fi
4337c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
4347c478bd9Sstevel@tonic-gate		done
4357c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
4367c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
4377c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
4387c478bd9Sstevel@tonic-gate	fi
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
4417c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
4427c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
4437c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
4447c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
4457c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
4467c478bd9Sstevel@tonic-gate		fi
4477c478bd9Sstevel@tonic-gate	fi
4487c478bd9Sstevel@tonic-gate
4497c478bd9Sstevel@tonic-gate	# save the cleartext
4507c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
4517c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
4527c478bd9Sstevel@tonic-gate	cd ${DEST}
4537c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
454fb23a357Skupfer	find usr -depth -print | \
4557c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
4567c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
4577c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
4587c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
4597c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
4607c478bd9Sstevel@tonic-gate	fi
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
4637c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
4647c478bd9Sstevel@tonic-gate	fi
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate}
4677c478bd9Sstevel@tonic-gate
4684e5b757fSkupfer# Return library search directive as function of given root.
469597bd30bSMike Kupferfunction myldlibs {
4704e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
4714e5b757fSkupfer}
4727c478bd9Sstevel@tonic-gate
4734e5b757fSkupfer# Return header search directive as function of given root.
474597bd30bSMike Kupferfunction myheaders {
4754e5b757fSkupfer	echo "-I$1/usr/include"
4764e5b757fSkupfer}
4774e5b757fSkupfer
4784e5b757fSkupfer#
47978add226Sjmcp# Function to do the build, including package generation.
4806ea3c060SGarrett D'Amore# usage: build LABEL SUFFIX ND MULTIPROTO
4814e5b757fSkupfer# - LABEL is used to tag build output.
482ead1f93eSLiane Praza# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
483597bd30bSMike Kupfer#   open-only vs full tree).
484ead1f93eSLiane Praza# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
4854e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
4864e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
4874e5b757fSkupfer#
488597bd30bSMike Kupferfunction build {
4897c478bd9Sstevel@tonic-gate	LABEL=$1
4907c478bd9Sstevel@tonic-gate	SUFFIX=$2
491597bd30bSMike Kupfer	ND=$3
492597bd30bSMike Kupfer	MULTIPROTO=$4
4937c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
4947c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
4957c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
4967c478bd9Sstevel@tonic-gate
4974e5b757fSkupfer	ORIGROOT=$ROOT
4984e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
4994e5b757fSkupfer
500b83ec4edSjmcp	if [[ "$O_FLAG" = y ]]; then
501b83ec4edSjmcp		echo "\nSetting CLOSEDROOT= ${ROOT}-closed\n" >> $LOGFILE
502b83ec4edSjmcp		export CLOSEDROOT=${ROOT}-closed
503b83ec4edSjmcp	fi
504b83ec4edSjmcp
5054e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
5064e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
5074e5b757fSkupfer
5087c478bd9Sstevel@tonic-gate	this_build_ok=y
5097c478bd9Sstevel@tonic-gate	#
5107c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
5117c478bd9Sstevel@tonic-gate	#
5127c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
5137c478bd9Sstevel@tonic-gate		>> $LOGFILE
5147c478bd9Sstevel@tonic-gate
5157c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
5167c478bd9Sstevel@tonic-gate	cd $SRC
5177c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
5187c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
51932f1e47bSsommerfe
520cdf0c1d5Smjnelson	if [[ "$SCM_TYPE" = teamware ]]; then
52132f1e47bSsommerfe		echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
522cdf0c1d5Smjnelson		egrep 'sccs(check:| *get)' $SRC/${INSTALLOG}.out >> \
523cdf0c1d5Smjnelson			$mail_msg_file
524cdf0c1d5Smjnelson	fi
52532f1e47bSsommerfe
5267c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
5277c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
5287c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
5297c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
5307c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
5317c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
5327c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
5337c478bd9Sstevel@tonic-gate		build_ok=n
5347c478bd9Sstevel@tonic-gate		this_build_ok=n
5357c478bd9Sstevel@tonic-gate	fi
5367c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
5377c478bd9Sstevel@tonic-gate		>> $mail_msg_file
5387c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
5397c478bd9Sstevel@tonic-gate		build_ok=n
5407c478bd9Sstevel@tonic-gate		this_build_ok=n
5417c478bd9Sstevel@tonic-gate	fi
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
5447c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
5457c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
5467c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
54720272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
5487c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
5497c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
5507c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
5517c478bd9Sstevel@tonic-gate			>> $mail_msg_file
5527c478bd9Sstevel@tonic-gate	fi
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
5557c478bd9Sstevel@tonic-gate		>> $LOGFILE
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
5587c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
5617c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
5627c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
5637c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
5647c478bd9Sstevel@tonic-gate		fi
5657c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
5667c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
5677c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
5687c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
5697c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
5707c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
5717c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
5727c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
5737c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
5747c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
5757c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
5767c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
5777c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
5787c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
5797c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
5807c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
5817c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
5827c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
58320272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
5847c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
5857c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
5867c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
5877c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
5887c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
5897c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
5907c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
5917c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
5927c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
5937c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
5947c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
5957c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
5967c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
5977c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
5987c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
5997c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
6007c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
6017c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
6027c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
6037c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
6047c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
6057c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
6067c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
6077c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
6087c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
6097c478bd9Sstevel@tonic-gate			| egrep -v '::' \
6107c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
611010b217aSwesolows			| egrep -v '^\+' \
61203eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
613c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
6147c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
6157c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
6167c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
6177c478bd9Sstevel@tonic-gate		fi
6187c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
6197c478bd9Sstevel@tonic-gate			>>$mail_msg_file
6207c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
6217c478bd9Sstevel@tonic-gate	fi
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate	#
62423259b79Srotondo	#	Re-sign selected binaries using signing server
62523259b79Srotondo	#	(gatekeeper builds only)
62623259b79Srotondo	#
6272210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
62823259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
62923259b79Srotondo		signing_file="${TMPDIR}/signing"
63023259b79Srotondo		rm -f ${signing_file}
63123259b79Srotondo		export CODESIGN_USER
63223259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
63323259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
63423259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
63523259b79Srotondo		    >> $LOGFILE
63623259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
63723259b79Srotondo		    >> $mail_msg_file
63823259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
639cdf0c1d5Smjnelson		if (( $? == 0 )) ; then
6402210853dSjohnz			build_ok=n
6412210853dSjohnz			this_build_ok=n
6422210853dSjohnz		fi
64323259b79Srotondo	fi
64423259b79Srotondo
64523259b79Srotondo	#
6467c478bd9Sstevel@tonic-gate	#	Building Packages
6477c478bd9Sstevel@tonic-gate	#
6487c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
649ead1f93eSLiane Praza		if [ -d $SRC/pkg -o -d $SRC/pkgdefs ]; then
6507c478bd9Sstevel@tonic-gate			echo "\n==== Creating $LABEL packages at `date` ====\n" \
6517c478bd9Sstevel@tonic-gate				>> $LOGFILE
652ead1f93eSLiane Praza			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
6536798c3f0SMark J. Nelson			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
6546798c3f0SMark J. Nelson			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
655d8fd4470Sjg
656ead1f93eSLiane Praza			for d in pkg pkgdefs; do
6576798c3f0SMark J. Nelson				if [ ! -f "$SRC/$d/Makefile" ]; then
658ead1f93eSLiane Praza					continue
659ead1f93eSLiane Praza				fi
660ead1f93eSLiane Praza				rm -f $SRC/$d/${INSTALLOG}.out
661ead1f93eSLiane Praza				cd $SRC/$d
662ead1f93eSLiane Praza				/bin/time $MAKE -e install 2>&1 | \
663ead1f93eSLiane Praza					tee -a $SRC/$d/${INSTALLOG}.out >> $LOGFILE
664ead1f93eSLiane Praza			done
665ead1f93eSLiane Praza
666ead1f93eSLiane Praza			echo "\n==== package build errors ($LABEL) ====\n" \
667ead1f93eSLiane Praza				>> $mail_msg_file
668ead1f93eSLiane Praza
669ead1f93eSLiane Praza			for d in pkg pkgdefs; do
6706798c3f0SMark J. Nelson				if [ ! -f "$SRC/$d/Makefile" ]; then
671ead1f93eSLiane Praza					continue
672d8fd4470Sjg				fi
673d8fd4470Sjg
674ead1f93eSLiane Praza				egrep "${MAKE}|ERROR|WARNING" $SRC/$d/${INSTALLOG}.out | \
6757c478bd9Sstevel@tonic-gate					grep ':' | \
6767c478bd9Sstevel@tonic-gate					grep -v PSTAMP | \
6777c478bd9Sstevel@tonic-gate					egrep -v "Ignoring unknown host" \
6787c478bd9Sstevel@tonic-gate					>> $mail_msg_file
679ead1f93eSLiane Praza			done
680ead1f93eSLiane Praza		else
681ead1f93eSLiane Praza			#
682ead1f93eSLiane Praza			# Handle it gracefully if -p was set but there are
683ead1f93eSLiane Praza			# neither pkg nor pkgdefs directories.
684ead1f93eSLiane Praza			#
685ead1f93eSLiane Praza			echo "\n==== No $LABEL packages to build ====\n" \
686ead1f93eSLiane Praza				>> $LOGFILE
687ead1f93eSLiane Praza		fi
6887c478bd9Sstevel@tonic-gate	else
6897c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
6907c478bd9Sstevel@tonic-gate	fi
6914e5b757fSkupfer
6924e5b757fSkupfer	ROOT=$ORIGROOT
6937c478bd9Sstevel@tonic-gate}
6947c478bd9Sstevel@tonic-gate
6951fe69678Skupfer# Usage: dolint /dir y|n
6967c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
697597bd30bSMike Kupferfunction dolint {
6987c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
6991fe69678Skupfer		echo "dolint error: $1 is not a directory"
7007c478bd9Sstevel@tonic-gate		exit 1
7017c478bd9Sstevel@tonic-gate	fi
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
7041fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
7057c478bd9Sstevel@tonic-gate		exit 1
7067c478bd9Sstevel@tonic-gate	fi
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate	lintdir=$1
7097c478bd9Sstevel@tonic-gate	dodiff=$2
7107c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
7117c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
7127c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
7134e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
7144e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
7157c478bd9Sstevel@tonic-gate
7164e5b757fSkupfer	set_debug_build_flags
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate	#
7197c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
7207c478bd9Sstevel@tonic-gate	#
7217c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
7227c478bd9Sstevel@tonic-gate
7237c478bd9Sstevel@tonic-gate	# remove old lint.out
7247c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
7257c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
7267c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
7277c478bd9Sstevel@tonic-gate	fi
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
7307c478bd9Sstevel@tonic-gate	cd $lintdir
7317c478bd9Sstevel@tonic-gate	#
7327c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
7337c478bd9Sstevel@tonic-gate	#
7347c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
735cdf0c1d5Smjnelson	    `find . \( -name SCCS -o -name .hg -o -name .svn \) \
736cdf0c1d5Smjnelson	    	-prune -o -type f -name '*.ln' -print `
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
7397c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
7407c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
7417c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
7427c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
7437c478bd9Sstevel@tonic-gate		>> $mail_msg_file
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
7487c478bd9Sstevel@tonic-gate		>>$mail_msg_file
7497c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
7527c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
7537c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
7547c478bd9Sstevel@tonic-gate	fi
7557c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
7567c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
7577c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
7587c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
7597c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
7607c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
7617c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
7627c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
7637c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
7647c478bd9Sstevel@tonic-gate	fi
7657c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
7667c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
7677c478bd9Sstevel@tonic-gate			>>$mail_msg_file
7687c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
7697c478bd9Sstevel@tonic-gate		# above
7707c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
7717c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
7727c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
7737c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7747c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
7757c478bd9Sstevel@tonic-gate			>> $mail_msg_file
7767c478bd9Sstevel@tonic-gate	fi
7777c478bd9Sstevel@tonic-gate}
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate# Install proto area from IHV build
7807c478bd9Sstevel@tonic-gate
781597bd30bSMike Kupferfunction copy_ihv_proto {
7827c478bd9Sstevel@tonic-gate
7836fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
7847c478bd9Sstevel@tonic-gate		>> $LOGFILE
7857c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
7867c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
7877c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
7887c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
7897c478bd9Sstevel@tonic-gate		fi
7906fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
7917c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
792b83ec4edSjmcp		tar cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7937c478bd9Sstevel@tonic-gate	else
7947c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
7957c478bd9Sstevel@tonic-gate	fi
7964e5b757fSkupfer
7974e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
7984e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
7994e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
8004e5b757fSkupfer			mkdir -p $ROOT-nd
8014e5b757fSkupfer		fi
802ead1f93eSLiane Praza		# If there's a non-DEBUG version of the IHV proto area,
8034e5b757fSkupfer		# copy it, but copy something if there's not.
8044e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
8054e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
8064e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
8074e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
8084e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
8094e5b757fSkupfer			cd $IA32_IHV_ROOT
8104e5b757fSkupfer		else
8114e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
8124e5b757fSkupfer			return
8134e5b757fSkupfer		fi
814b83ec4edSjmcp		tar cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
8154e5b757fSkupfer	fi
8167c478bd9Sstevel@tonic-gate}
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
8191fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
820597bd30bSMike Kupferfunction copy_ihv_pkgs {
8217c478bd9Sstevel@tonic-gate	LABEL=$1
8227c478bd9Sstevel@tonic-gate	SUFFIX=$2
8237c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
8247c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
8257c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
8287c478bd9Sstevel@tonic-gate		>> $LOGFILE
8297c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
8307c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
831b83ec4edSjmcp		tar cf - * | \
8327c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
8337c478bd9Sstevel@tonic-gate	else
8347c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
8357c478bd9Sstevel@tonic-gate	fi
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
8387c478bd9Sstevel@tonic-gate		>> $LOGFILE
8397c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
8407c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
841b83ec4edSjmcp		tar cf - * | \
8427c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
8437c478bd9Sstevel@tonic-gate	else
8447c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
8457c478bd9Sstevel@tonic-gate	fi
8467c478bd9Sstevel@tonic-gate}
8477c478bd9Sstevel@tonic-gate
8484e5b757fSkupfer#
8494e5b757fSkupfer# Build and install the onbld tools.
8504e5b757fSkupfer#
8511fe69678Skupfer# usage: build_tools DESTROOT
8524e5b757fSkupfer#
8534e5b757fSkupfer# returns non-zero status if the build was successful.
8544e5b757fSkupfer#
855597bd30bSMike Kupferfunction build_tools {
8567c478bd9Sstevel@tonic-gate	DESTROOT=$1
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
8617c478bd9Sstevel@tonic-gate		>> $LOGFILE
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
8647c478bd9Sstevel@tonic-gate	cd ${TOOLS}
865ead1f93eSLiane Praza	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
8667c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
8717c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
8727c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
8737c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
8744e5b757fSkupfer	return $?
8754e5b757fSkupfer}
8764e5b757fSkupfer
8774e5b757fSkupfer#
8784e5b757fSkupfer# Set up to use locally installed tools.
8794e5b757fSkupfer#
8804e5b757fSkupfer# usage: use_tools TOOLSROOT
8814e5b757fSkupfer#
882597bd30bSMike Kupferfunction use_tools {
8834e5b757fSkupfer	TOOLSROOT=$1
8844e5b757fSkupfer
885c168ccb7SMark J. Nelson	#
886c168ccb7SMark J. Nelson	# If we're not building ON workspace, then the TOOLSROOT
887c168ccb7SMark J. Nelson	# settings here are clearly ignored by the workspace
888c168ccb7SMark J. Nelson	# makefiles, prepending nonexistent directories to PATH is
889c168ccb7SMark J. Nelson	# harmless, and we clearly do not wish to override
890c168ccb7SMark J. Nelson	# ONBLD_TOOLS.
891c168ccb7SMark J. Nelson	#
892c168ccb7SMark J. Nelson	# If we're building an ON workspace, then the prepended PATH
893c168ccb7SMark J. Nelson	# elements should supercede the preexisting ONBLD_TOOLS paths,
894c168ccb7SMark J. Nelson	# and we want to override ONBLD_TOOLS to catch the tools that
895c168ccb7SMark J. Nelson	# don't have specific path env vars here.
896c168ccb7SMark J. Nelson	#
897c168ccb7SMark J. Nelson	# So the only conditional behavior is overriding ONBLD_TOOLS,
898c168ccb7SMark J. Nelson	# and we check for "an ON workspace" by looking for
899c168ccb7SMark J. Nelson	# ${TOOLSROOT}/opt/onbld.
900c168ccb7SMark J. Nelson	#
901c168ccb7SMark J. Nelson
9024e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
9037c478bd9Sstevel@tonic-gate	export STABS
9044e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
9057c478bd9Sstevel@tonic-gate	export CTFSTABS
9064e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
9077c478bd9Sstevel@tonic-gate	export GENOFFSETS
9087c478bd9Sstevel@tonic-gate
9094e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
9107c478bd9Sstevel@tonic-gate	export CTFCONVERT
9114e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
9127c478bd9Sstevel@tonic-gate	export CTFMERGE
9137c478bd9Sstevel@tonic-gate
9144e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
9157c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
9164e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
9177c478bd9Sstevel@tonic-gate	export CTFFINDMOD
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
9204e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
9217c478bd9Sstevel@tonic-gate	else
9224e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
9237c478bd9Sstevel@tonic-gate	fi
9247c478bd9Sstevel@tonic-gate	export ELFSIGN
9257c478bd9Sstevel@tonic-gate
926c168ccb7SMark J. Nelson	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
9274e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
9287c478bd9Sstevel@tonic-gate	export PATH
9297c478bd9Sstevel@tonic-gate
930c168ccb7SMark J. Nelson	if [ -d "${TOOLSROOT}/opt/onbld" ]; then
931b06f2c55SMark J. Nelson		ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
9321d9a8b8dSDan Mick		export ONBLD_TOOLS
933c168ccb7SMark J. Nelson	fi
9341d9a8b8dSDan Mick
9357c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
9367c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
9377c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
9387c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
9397c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
9407c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
9417c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
9427c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
9437c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
9441d9a8b8dSDan Mick	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
9457c478bd9Sstevel@tonic-gate}
9467c478bd9Sstevel@tonic-gate
947597bd30bSMike Kupferfunction staffer {
9487c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
9497c478bd9Sstevel@tonic-gate		"$@"
9507c478bd9Sstevel@tonic-gate	else
9517c478bd9Sstevel@tonic-gate		arg="\"$1\""
9527c478bd9Sstevel@tonic-gate		shift
9537c478bd9Sstevel@tonic-gate		for i
9547c478bd9Sstevel@tonic-gate		do
9557c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
9567c478bd9Sstevel@tonic-gate		done
9577c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
9587c478bd9Sstevel@tonic-gate	fi
9597c478bd9Sstevel@tonic-gate}
9607c478bd9Sstevel@tonic-gate
961085d331dSkupfer#
962085d331dSkupfer# Verify that the closed tree is present if it needs to be.
963085d331dSkupfer# Sets CLOSED_IS_PRESENT for future use.
964085d331dSkupfer#
965597bd30bSMike Kupferfunction check_closed_tree {
966085d331dSkupfer	if [ -z "$CLOSED_IS_PRESENT" ]; then
9675c53ea7aSmjnelson		if [ -d $CODEMGR_WS/usr/closed ]; then
968085d331dSkupfer			CLOSED_IS_PRESENT="yes"
969085d331dSkupfer		else
970085d331dSkupfer			CLOSED_IS_PRESENT="no"
971085d331dSkupfer		fi
972085d331dSkupfer		export CLOSED_IS_PRESENT
973085d331dSkupfer	fi
974085d331dSkupfer	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
975085d331dSkupfer		#
976085d331dSkupfer		# If it's an old (pre-split) tree or an empty
977085d331dSkupfer		# workspace, don't complain.
978085d331dSkupfer		#
979085d331dSkupfer		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
980085d331dSkupfer			echo "If the closed sources are not present," \
981085d331dSkupfer			    "ON_CLOSED_BINS"
982085d331dSkupfer			echo "must point to the closed binaries tree."
983cdf0c1d5Smjnelson			build_ok=n
984085d331dSkupfer			exit 1
985085d331dSkupfer		fi
986085d331dSkupfer	fi
987085d331dSkupfer}
9887c478bd9Sstevel@tonic-gate
989597bd30bSMike Kupferfunction obsolete_build {
990d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
991d77e7149Ssommerfe}
992d77e7149Ssommerfe
9934e5b757fSkupfer#
9944e5b757fSkupfer# wrapper over wsdiff.
9954e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
9964e5b757fSkupfer#
997597bd30bSMike Kupferfunction do_wsdiff {
9984e5b757fSkupfer	label=$1
9994e5b757fSkupfer	oldproto=$2
10004e5b757fSkupfer	newproto=$3
10014e5b757fSkupfer
10024e5b757fSkupfer	wsdiff="wsdiff"
10034e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
10044e5b757fSkupfer
1005598cc7dfSVladimir Kotal	echo "\n==== Getting object changes since last build at `date`" \
1006598cc7dfSVladimir Kotal	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
1007598cc7dfSVladimir Kotal	$wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
1008598cc7dfSVladimir Kotal		    tee -a $LOGFILE >> $mail_msg_file
1009598cc7dfSVladimir Kotal	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
10104e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
10114e5b757fSkupfer}
10124e5b757fSkupfer
10134e5b757fSkupfer#
1014ead1f93eSLiane Praza# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
10154e5b757fSkupfer# together.
10164e5b757fSkupfer#
10174e5b757fSkupfer
1018597bd30bSMike Kupferfunction set_non_debug_build_flags {
10194e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
10204e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
10214e5b757fSkupfer	unset EXTRA_OPTIONS
10224e5b757fSkupfer	unset EXTRA_CFLAGS
10234e5b757fSkupfer}
10244e5b757fSkupfer
1025597bd30bSMike Kupferfunction set_debug_build_flags {
10264e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
10274e5b757fSkupfer	unset RELEASE_BUILD
10284e5b757fSkupfer	unset EXTRA_OPTIONS
10294e5b757fSkupfer	unset EXTRA_CFLAGS
10304e5b757fSkupfer}
10314e5b757fSkupfer
1032d77e7149Ssommerfe
10337c478bd9Sstevel@tonic-gateMACH=`uname -p`
10347c478bd9Sstevel@tonic-gate
10357c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
10367c478bd9Sstevel@tonic-gate	OPTHOME=/opt
10377c478bd9Sstevel@tonic-gate	export OPTHOME
10387c478bd9Sstevel@tonic-gatefi
10397c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
10407c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
10417c478bd9Sstevel@tonic-gate	export TEAMWARE
10427c478bd9Sstevel@tonic-gatefi
10437c478bd9Sstevel@tonic-gate
10445e1b109eSPeter Dennis - Sustaining EngineerUSAGE='Usage: nightly [-in] [+t] [-V VERS ] [ -S E|D|H|O ] <env_file>
10457c478bd9Sstevel@tonic-gate
10467c478bd9Sstevel@tonic-gateWhere:
1047d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
10487c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
10495e1b109eSPeter Dennis - Sustaining Engineer	+t	Use the build tools in $ONBLD_TOOLS/bin
10507c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
10517c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
10527c478bd9Sstevel@tonic-gate		E - build exportable source
10537c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
10547c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
10551fe69678Skupfer		O - build (only) open source
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
10587c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
10597c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
10607c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
10637c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
10647c478bd9Sstevel@tonic-gate
10657c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
10667c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
10677c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
10687c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
10693c6aa570SMark J. Nelson	-G	gate keeper default group of options (-au)
10707c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
10717c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
10727c478bd9Sstevel@tonic-gate	-N	do not run protocmp
10734e5b757fSkupfer	-O	generate OpenSolaris deliverables
10747c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
10757c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
10767c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
107704a42e3eSszhou	-X	copy x86 IHV proto area
10787c478bd9Sstevel@tonic-gate	-f	find unreferenced files
10797c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
10807c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
10817c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
10827c478bd9Sstevel@tonic-gate	-n      do not do a bringover
10837c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
10847c478bd9Sstevel@tonic-gate	-p	create packages
10857c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
10865e1b109eSPeter Dennis - Sustaining Engineer	-t	build and use the tools in $SRC/tools (default setting)
10875e1b109eSPeter Dennis - Sustaining Engineer	+t	Use the build tools in $ONBLD_TOOLS/bin
10887c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
10897c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
109096ccc8cbSesaxe	-w	report on differences between previous and current proto areas
10917c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
10927c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
10937c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
10947c478bd9Sstevel@tonic-gate		E - build exportable source
10957c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
10967c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
10971fe69678Skupfer		O - build (only) open source
10987c478bd9Sstevel@tonic-gate'
10997c478bd9Sstevel@tonic-gate#
11007c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
11017c478bd9Sstevel@tonic-gate#
11027c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
11031c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
11047c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
11057c478bd9Sstevel@tonic-gate#
11067c478bd9Sstevel@tonic-gate
11077c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
11087c478bd9Sstevel@tonic-gateA_FLAG=n
11097c478bd9Sstevel@tonic-gateC_FLAG=n
11106c3c9007SstevelD_FLAG=n
11117c478bd9Sstevel@tonic-gateF_FLAG=n
11127c478bd9Sstevel@tonic-gatef_FLAG=n
11137c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
11147c478bd9Sstevel@tonic-gatel_FLAG=n
11156c3c9007SstevelM_FLAG=n
11167c478bd9Sstevel@tonic-gatem_FLAG=n
11176c3c9007SstevelN_FLAG=n
11186c3c9007Ssteveln_FLAG=n
11194e5b757fSkupferO_FLAG=n
11206c3c9007Sstevelo_FLAG=n
11216c3c9007SstevelP_FLAG=n
11227c478bd9Sstevel@tonic-gatep_FLAG=n
11237c478bd9Sstevel@tonic-gater_FLAG=n
11246c3c9007SstevelT_FLAG=n
1125fd7cef36Ssuhat_FLAG=y
11267c478bd9Sstevel@tonic-gateU_FLAG=n
11276c3c9007Sstevelu_FLAG=n
11287c478bd9Sstevel@tonic-gateV_FLAG=n
11297c478bd9Sstevel@tonic-gateW_FLAG=n
11306c3c9007Sstevelw_FLAG=n
11316c3c9007SstevelX_FLAG=n
11327c478bd9Sstevel@tonic-gateSD_FLAG=n
11336c3c9007SstevelSE_FLAG=n
11347c478bd9Sstevel@tonic-gateSH_FLAG=n
11351fe69678SkupferSO_FLAG=n
11367c478bd9Sstevel@tonic-gate#
11377c478bd9Sstevel@tonic-gateXMOD_OPT=
11387c478bd9Sstevel@tonic-gate#
11397c478bd9Sstevel@tonic-gatebuild_ok=y
11401fe69678Skupfer
1141597bd30bSMike Kupferfunction is_source_build {
11421fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
11431fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
11441fe69678Skupfer	return $?
11451fe69678Skupfer}
11461fe69678Skupfer
11477c478bd9Sstevel@tonic-gate#
11487c478bd9Sstevel@tonic-gate# examine arguments
11497c478bd9Sstevel@tonic-gate#
11507c478bd9Sstevel@tonic-gate
11511fe69678Skupfer#
11521fe69678Skupfer# single function for setting -S flag and doing error checking.
11531fe69678Skupfer# usage: set_S_flag <type>
11541fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
11551fe69678Skupfer#
1156597bd30bSMike Kupferfunction set_S_flag {
11571fe69678Skupfer	if is_source_build; then
11581fe69678Skupfer		echo "Can only build one source variant at a time."
11591fe69678Skupfer		exit 1
11601fe69678Skupfer	fi
11611fe69678Skupfer	if [ "$1" = "E" ]; then
11621fe69678Skupfer		SE_FLAG=y
11631fe69678Skupfer	elif [ "$1" = "D" ]; then
11641fe69678Skupfer		SD_FLAG=y
11651fe69678Skupfer	elif [ "$1" = "H" ]; then
11661fe69678Skupfer		SH_FLAG=y
11671fe69678Skupfer	elif [ "$1" = "O" ]; then
11681fe69678Skupfer		SO_FLAG=y
11691fe69678Skupfer	else
11701fe69678Skupfer		echo "$USAGE"
11711fe69678Skupfer		exit 1
11721fe69678Skupfer	fi
11731fe69678Skupfer}
11741fe69678Skupfer
11757c478bd9Sstevel@tonic-gateOPTIND=1
11765e1b109eSPeter Dennis - Sustaining Engineerwhile getopts +inS:tV: FLAG
11777c478bd9Sstevel@tonic-gatedo
11787c478bd9Sstevel@tonic-gate	case $FLAG in
11797c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
11807c478bd9Sstevel@tonic-gate		;;
11817c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
11827c478bd9Sstevel@tonic-gate		;;
11837c478bd9Sstevel@tonic-gate	  S )
11841fe69678Skupfer		set_S_flag $OPTARG
11857c478bd9Sstevel@tonic-gate		;;
1186fd7cef36Ssuha	 +t )	t_FLAG=n
11877c478bd9Sstevel@tonic-gate		;;
11886c3c9007Sstevel	  V )	V_FLAG=y
11896c3c9007Sstevel		V_ARG="$OPTARG"
11906c3c9007Sstevel		;;
11917c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
11927c478bd9Sstevel@tonic-gate		exit 1
11937c478bd9Sstevel@tonic-gate		;;
11947c478bd9Sstevel@tonic-gate	esac
11957c478bd9Sstevel@tonic-gatedone
11967c478bd9Sstevel@tonic-gate
11977c478bd9Sstevel@tonic-gate# correct argument count after options
11987c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
11997c478bd9Sstevel@tonic-gate
12007c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
12017c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
12027c478bd9Sstevel@tonic-gate	echo "$USAGE"
12037c478bd9Sstevel@tonic-gate	exit 1
12047c478bd9Sstevel@tonic-gatefi
12057c478bd9Sstevel@tonic-gate
12067c478bd9Sstevel@tonic-gate# check if user is running nightly as root
12077c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
12087c478bd9Sstevel@tonic-gate# when root invokes nightly.
12097c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
12107c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
12117c478bd9Sstevel@tonic-gate
12127c478bd9Sstevel@tonic-gate#
12137c478bd9Sstevel@tonic-gate# force locale to C
12147c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
12157c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
12167c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
12177c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
12187c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
12197c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
12207c478bd9Sstevel@tonic-gate
12217c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
12227c478bd9Sstevel@tonic-gateunset LD_OPTIONS
12237c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
12247c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
12257c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
12267c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
12277c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
12287c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
12297c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
12307c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
12317c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
12327c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
12337c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
12347c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
12357c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
12367c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
12377c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
12387c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
12397c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
12407c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
12417c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
12427c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
12437c478bd9Sstevel@tonic-gate
12447c478bd9Sstevel@tonic-gateunset CONFIG
12457c478bd9Sstevel@tonic-gateunset GROUP
12467c478bd9Sstevel@tonic-gateunset OWNER
12477c478bd9Sstevel@tonic-gateunset REMOTE
12487c478bd9Sstevel@tonic-gateunset ENV
12497c478bd9Sstevel@tonic-gateunset ARCH
12507c478bd9Sstevel@tonic-gateunset CLASSPATH
12517c478bd9Sstevel@tonic-gateunset NAME
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gate#
1254ead1f93eSLiane Praza# To get ONBLD_TOOLS from the environment, it must come from the env file.
1255ead1f93eSLiane Praza# If it comes interactively, it is generally TOOLS_PROTO, which will be
1256ead1f93eSLiane Praza# clobbered before the compiler version checks, which will therefore fail.
1257ead1f93eSLiane Praza#
1258ead1f93eSLiane Prazaunset ONBLD_TOOLS
1259ead1f93eSLiane Praza
1260ead1f93eSLiane Praza#
12617c478bd9Sstevel@tonic-gate#	Setup environmental variables
12627c478bd9Sstevel@tonic-gate#
126347703246Ssommerfeif [ -f /etc/nightly.conf ]; then
126447703246Ssommerfe	. /etc/nightly.conf
126547703246Ssommerfefi
126647703246Ssommerfe
12677c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
12687c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
12697c478bd9Sstevel@tonic-gate		. $1
12707c478bd9Sstevel@tonic-gate	else
12717c478bd9Sstevel@tonic-gate		. ./$1
12727c478bd9Sstevel@tonic-gate	fi
12737c478bd9Sstevel@tonic-gateelse
12747c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
12757c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
12767c478bd9Sstevel@tonic-gate	else
12777c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
12787c478bd9Sstevel@tonic-gate		exit 1
12797c478bd9Sstevel@tonic-gate	fi
12807c478bd9Sstevel@tonic-gatefi
12817c478bd9Sstevel@tonic-gate
12821fe69678Skupfer# contents of stdenv.sh inserted after next line:
12831fe69678Skupfer# STDENV_START
12841fe69678Skupfer# STDENV_END
12851fe69678Skupfer
1286*d7693b08SRoland Mainz# Check if we have sufficient data to continue...
1287*d7693b08SRoland Mainz[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
1288*d7693b08SRoland Mainz[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
1289*d7693b08SRoland Mainz[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
1290*d7693b08SRoland Mainz
12917c478bd9Sstevel@tonic-gate#
12927c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
12937c478bd9Sstevel@tonic-gate#
12947c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
12957c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
12967c478bd9Sstevel@tonic-gateelse
12977c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
12987c478bd9Sstevel@tonic-gatefi
12997c478bd9Sstevel@tonic-gate
13007c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
13017c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
13027c478bd9Sstevel@tonic-gate
13037c478bd9Sstevel@tonic-gate#
13047c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
13057c478bd9Sstevel@tonic-gate#
13067c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
13077c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
13087c478bd9Sstevel@tonic-gatefi
13097c478bd9Sstevel@tonic-gate
13107c478bd9Sstevel@tonic-gate#
13117c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
13127c478bd9Sstevel@tonic-gate#
13137c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
13147c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
13157c478bd9Sstevel@tonic-gatefi
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate#
1318cdf0c1d5Smjnelson# If CLOSED_BRINGOVER_WS was not specified, let it default to CLOSED_CLONE_WS
1319cdf0c1d5Smjnelson#
1320cdf0c1d5Smjnelsonif [ "$CLOSED_BRINGOVER_WS" = "" ]; then
1321cdf0c1d5Smjnelson	CLOSED_BRINGOVER_WS=$CLOSED_CLONE_WS
1322cdf0c1d5Smjnelsonfi
1323cdf0c1d5Smjnelson
1324cdf0c1d5Smjnelson#
1325fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1326a5c06a9eSmike_s#
1327a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1328fb23a357Skupfer	BRINGOVER_FILES="usr"
1329a5c06a9eSmike_sfi
1330a5c06a9eSmike_s
1331fb9f9b97Skupfer#
1332fb9f9b97Skupfer# If the closed sources are not present, the closed binaries must be
1333fb9f9b97Skupfer# present for the build to succeed.  If there's no pointer to the
1334fb9f9b97Skupfer# closed binaries, flag that now, rather than forcing the user to wait
1335fb9f9b97Skupfer# a couple hours (or more) to find out.
1336fb9f9b97Skupfer#
1337085d331dSkupferorig_closed_is_present="$CLOSED_IS_PRESENT"
1338085d331dSkupfercheck_closed_tree
1339fb9f9b97Skupfer
1340a5c06a9eSmike_s#
13417c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1342b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
13437c478bd9Sstevel@tonic-gate#
1344d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
13457c478bd9Sstevel@tonic-gateOPTIND=1
134678add226Sjmcpwhile getopts +ABCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
13477c478bd9Sstevel@tonic-gatedo
13487c478bd9Sstevel@tonic-gate	case $FLAG in
13497c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
13505253169eSAli Bahrami		#
13515253169eSAli Bahrami		# If ELF_DATA_BASELINE_DIR is not defined, and we are on SWAN
13525253169eSAli Bahrami		# (based on CLOSED_IS_PRESENT), then refuse to run. The value
13535253169eSAli Bahrami		# of ELF version checking is greatly enhanced by including
13545253169eSAli Bahrami		# the baseline gate comparison.
13555253169eSAli Bahrami		if [ "$CLOSED_IS_PRESENT" = 'yes' -a \
13565253169eSAli Bahrami		     "$ELF_DATA_BASELINE_DIR" = '' ]; then
13575253169eSAli Bahrami			echo "ELF_DATA_BASELINE_DIR must be set if the A" \
13585253169eSAli Bahrami			    "flag is present in\nNIGHTLY_OPTIONS and closed" \
13595253169eSAli Bahrami			    "sources are present. Update environment file."
13605253169eSAli Bahrami			exit 1;
13615253169eSAli Bahrami		fi
13627c478bd9Sstevel@tonic-gate		;;
13637c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
13647c478bd9Sstevel@tonic-gate		;; # old version of D
13656c3c9007Sstevel	  C )	C_FLAG=y
13667c478bd9Sstevel@tonic-gate		;;
13677c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
13687c478bd9Sstevel@tonic-gate		;;
13696c3c9007Sstevel	  F )	F_FLAG=y
13707c478bd9Sstevel@tonic-gate		;;
13716c3c9007Sstevel	  f )	f_FLAG=y
13727c478bd9Sstevel@tonic-gate		;;
137378add226Sjmcp	  G )   u_FLAG=y
13747c478bd9Sstevel@tonic-gate		;;
137578add226Sjmcp	  I )	m_FLAG=y
13767c478bd9Sstevel@tonic-gate		p_FLAG=y
13777c478bd9Sstevel@tonic-gate		u_FLAG=y
13787c478bd9Sstevel@tonic-gate		;;
13797c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
13807c478bd9Sstevel@tonic-gate		;;
13816c3c9007Sstevel	  l )	l_FLAG=y
13826c3c9007Sstevel		;;
13836c3c9007Sstevel	  M )	M_FLAG=y
13846c3c9007Sstevel		;;
13856c3c9007Sstevel	  m )	m_FLAG=y
13866c3c9007Sstevel		;;
13876c3c9007Sstevel	  N )	N_FLAG=y
13886c3c9007Sstevel		;;
13897c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
13907c478bd9Sstevel@tonic-gate		;;
13914e5b757fSkupfer	  O )	O_FLAG=y
13924e5b757fSkupfer		;;
13937c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
13947c478bd9Sstevel@tonic-gate		;;
13956c3c9007Sstevel	  P )	P_FLAG=y
13966c3c9007Sstevel		;; # obsolete
13977c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
13987c478bd9Sstevel@tonic-gate		;;
13996c3c9007Sstevel	  R )	m_FLAG=y
14006c3c9007Sstevel		p_FLAG=y
14016c3c9007Sstevel		;;
14027c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
14037c478bd9Sstevel@tonic-gate		;;
14046c3c9007Sstevel	  S )
14056c3c9007Sstevel		set_S_flag $OPTARG
14066c3c9007Sstevel		;;
14076c3c9007Sstevel	  T )	T_FLAG=y
14086c3c9007Sstevel		;; # obsolete
1409fd7cef36Ssuha	 +t )	t_FLAG=n
14107c478bd9Sstevel@tonic-gate		;;
14116798c3f0SMark J. Nelson	  U )   if [ -z "${PARENT_ROOT}" ]; then
14127c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
14137c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
14147c478bd9Sstevel@tonic-gate			exit 1
14157c478bd9Sstevel@tonic-gate		fi
14166798c3f0SMark J. Nelson		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
14176798c3f0SMark J. Nelson		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
14186798c3f0SMark J. Nelson			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
1419ead1f93eSLiane Praza		fi
14207c478bd9Sstevel@tonic-gate		U_FLAG=y
14217c478bd9Sstevel@tonic-gate		;;
14226c3c9007Sstevel	  u )	u_FLAG=y
14237c478bd9Sstevel@tonic-gate		;;
14247c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
14257c478bd9Sstevel@tonic-gate		;;
14266c3c9007Sstevel
14276c3c9007Sstevel	  w )	w_FLAG=y
14287c478bd9Sstevel@tonic-gate		;;
14297c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
14307c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
14317c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
14327c478bd9Sstevel@tonic-gate			X_FLAG=y
14337c478bd9Sstevel@tonic-gate		fi
14347c478bd9Sstevel@tonic-gate		;;
14356c3c9007Sstevel	  x )	XMOD_OPT="-x"
14366c3c9007Sstevel		;;
14377c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
14387c478bd9Sstevel@tonic-gate		exit 1
14397c478bd9Sstevel@tonic-gate		;;
14407c478bd9Sstevel@tonic-gate	esac
14417c478bd9Sstevel@tonic-gatedone
14427c478bd9Sstevel@tonic-gate
14437c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
14447c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
14457c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
14467c478bd9Sstevel@tonic-gate		exit 1
14477c478bd9Sstevel@tonic-gate	fi
14487c478bd9Sstevel@tonic-gate
14497c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
14507c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
14517c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
14527c478bd9Sstevel@tonic-gate		export STAFFER
14537c478bd9Sstevel@tonic-gate	fi
14547c478bd9Sstevel@tonic-gatefi
14557c478bd9Sstevel@tonic-gate
14567c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
14577c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
14587c478bd9Sstevel@tonic-gate	export MAILTO
14597c478bd9Sstevel@tonic-gatefi
14607c478bd9Sstevel@tonic-gate
1461c168ccb7SMark J. NelsonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
1462c168ccb7SMark J. NelsonPATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
1463c168ccb7SMark J. NelsonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
14647c478bd9Sstevel@tonic-gateexport PATH
14657c478bd9Sstevel@tonic-gate
1466fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1467fb23a357Skupferrelsrcdirs="."
14685c53ea7aSmjnelsonif [[ -d $CODEMGR_WS/usr/closed && "$CLOSED_IS_PRESENT" != no ]]; then
1469fb9f9b97Skupfer	relsrcdirs="$relsrcdirs ../closed"
1470fb9f9b97Skupferfi
1471fb23a357Skupferabssrcdirs=""
1472fb23a357Skupferfor d in $relsrcdirs; do
1473fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1474fb23a357Skupferdone
1475fb23a357Skupfer
14767c478bd9Sstevel@tonic-gateunset CH
14777c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
14787c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
14797c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
14807c478bd9Sstevel@tonic-gate# the old ones still do.
14817c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
14827c478bd9Sstevel@tonic-gate	CH=
14837c478bd9Sstevel@tonic-gate	export CH
14847c478bd9Sstevel@tonic-gateelse
14857c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
14867c478bd9Sstevel@tonic-gatefi
14877c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
148848bc00d6Sjmcp# have we set RELEASE_DATE in our env file?
148948bc00d6Sjmcpif [ -z "$RELEASE_DATE" ]; then
149048bc00d6Sjmcp	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
149148bc00d6Sjmcpfi
149248bc00d6SjmcpBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
149348bc00d6SjmcpBASEWSDIR=$(basename $CODEMGR_WS)
149448bc00d6SjmcpDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
14957c478bd9Sstevel@tonic-gate
149648bc00d6Sjmcp# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
149748bc00d6Sjmcp# by avoiding repeated shell invocations to evaluate Makefile.master definitions.
14983c6aa570SMark J. Nelson# we export o_FLAG and X_FLAG for use by makebfu, and by usr/src/pkg/Makefile
149948bc00d6Sjmcpexport o_FLAG X_FLAG POUND_SIGN RELEASE_DATE DEV_CM
15007c478bd9Sstevel@tonic-gate
15017c478bd9Sstevel@tonic-gatemaketype="distributed"
15027c478bd9Sstevel@tonic-gateMAKE=dmake
15037c478bd9Sstevel@tonic-gate# get the dmake version string alone
15047c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
15057c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
15067c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
15077c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
15087c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
15097c478bd9Sstevel@tonic-gate# extract the second (or final) integer
15107c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
15117c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
15127c478bd9Sstevel@tonic-gate# extract the first integer
15137c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
15147c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
15157c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
15167c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
15177c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
15187c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
15197c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
15207c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
15217c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
15227c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
15237c478bd9Sstevel@tonic-gate		exit 1
15247c478bd9Sstevel@tonic-gate	fi
15257c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
15267c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
15277c478bd9Sstevel@tonic-gate	cat <<EOF
15287c478bd9Sstevel@tonic-gate
15297c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
15307c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
15317c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
15327c478bd9Sstevel@tonic-gate
15337c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
15347c478bd9Sstevel@tonic-gateEOF
15357c478bd9Sstevel@tonic-gate	exit 1
15367c478bd9Sstevel@tonic-gatefi
15377c478bd9Sstevel@tonic-gateexport PATH
15387c478bd9Sstevel@tonic-gateexport MAKE
15397c478bd9Sstevel@tonic-gate
1540b83ec4edSjmcpif [[ "$O_FLAG" = y ]]; then
1541b83ec4edSjmcp	export TONICBUILD=""
1542b83ec4edSjmcpelse
1543b83ec4edSjmcp	export TONICBUILD="#"
1544b83ec4edSjmcpfi
1545b83ec4edSjmcp
15467c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
15477c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
15487c478bd9Sstevel@tonic-gate	export PATH
15497c478bd9Sstevel@tonic-gatefi
15507c478bd9Sstevel@tonic-gate
155199e4a37bSWill Fiveashhostname=$(uname -n)
155299e4a37bSWill Fiveashif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
155399e4a37bSWill Fiveashthen
155499e4a37bSWill Fiveash	maxjobs=
155599e4a37bSWill Fiveash	if [[ -f $HOME/.make.machines ]]
155699e4a37bSWill Fiveash	then
155799e4a37bSWill Fiveash		# Note: there is a hard tab and space character in the []s
155899e4a37bSWill Fiveash		# below.
155999e4a37bSWill Fiveash		egrep -i "^[ 	]*$hostname[ 	\.]" \
156099e4a37bSWill Fiveash			$HOME/.make.machines | read host jobs
156199e4a37bSWill Fiveash		maxjobs=${jobs##*=}
15627c478bd9Sstevel@tonic-gate	fi
156399e4a37bSWill Fiveash
156499e4a37bSWill Fiveash	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
156599e4a37bSWill Fiveash	then
156699e4a37bSWill Fiveash		# default
156799e4a37bSWill Fiveash		maxjobs=4
15687c478bd9Sstevel@tonic-gate	fi
156999e4a37bSWill Fiveash
157099e4a37bSWill Fiveash	export DMAKE_MAX_JOBS=$maxjobs
157199e4a37bSWill Fiveashfi
157299e4a37bSWill Fiveash
15737c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
15747c478bd9Sstevel@tonic-gateexport DMAKE_MODE
15757c478bd9Sstevel@tonic-gate
15767c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
15777c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
15787c478bd9Sstevel@tonic-gate	exit 1
15797c478bd9Sstevel@tonic-gatefi
15807c478bd9Sstevel@tonic-gate
15817c478bd9Sstevel@tonic-gate#
15827c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
15837c478bd9Sstevel@tonic-gate#
15847c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
15857c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
15867c478bd9Sstevel@tonic-gatefi
15877c478bd9Sstevel@tonic-gate
158804a42e3eSszhou#
158904a42e3eSszhou# Check for IHV root for copying ihv proto area
159004a42e3eSszhou#
159104a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
159204a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
159304a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
159404a42e3eSszhou		args_ok=n
159504a42e3eSszhou        fi
159604a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
159704a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
159804a42e3eSszhou                args_ok=n
159904a42e3eSszhou        fi
16006fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
16016fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
16026fec3625Sdduvall		args_ok=n
16036fec3625Sdduvall        fi
16046fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
16056fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
16066fec3625Sdduvall                args_ok=n
16076fec3625Sdduvall        fi
160804a42e3eSszhoufi
160904a42e3eSszhou
16107c478bd9Sstevel@tonic-gate# Append source version
16117c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
16127c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
16137c478bd9Sstevel@tonic-gatefi
16147c478bd9Sstevel@tonic-gate
16157c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
16167c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
16177c478bd9Sstevel@tonic-gatefi
16187c478bd9Sstevel@tonic-gate
16197c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
16207c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
16217c478bd9Sstevel@tonic-gatefi
16227c478bd9Sstevel@tonic-gate
16231fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
16241fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
16251fe69678Skupferfi
16261fe69678Skupfer
16277c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
16287c478bd9Sstevel@tonic-gateexport TMPDIR
16297c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
16307c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
163185f46905SMark J. Nelsonchmod 777 $TMPDIR
16327c478bd9Sstevel@tonic-gate
16337c478bd9Sstevel@tonic-gate#
16347c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
16357c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
16367c478bd9Sstevel@tonic-gate# have the fix for 6271754
16377c478bd9Sstevel@tonic-gate#
16387c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
16397c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
16407c478bd9Sstevel@tonic-gate
1641ead1f93eSLiane Praza#
1642ead1f93eSLiane Praza# Tools should only be built non-DEBUG.  Keep track of the tools proto
1643ead1f93eSLiane Praza# area path relative to $TOOLS, because the latter changes in an
1644ead1f93eSLiane Praza# export build.
1645ead1f93eSLiane Praza#
1646ead1f93eSLiane Praza# TOOLS_PROTO is included below for builds other than usr/src/tools
1647ead1f93eSLiane Praza# that look for this location.  For usr/src/tools, this will be
1648ead1f93eSLiane Praza# overridden on the $MAKE command line in build_tools().
1649ead1f93eSLiane Praza#
16507c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
1651ead1f93eSLiane PrazaTOOLS_PROTO_REL=proto/root_${MACH}-nd
1652ead1f93eSLiane PrazaTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
1653ead1f93eSLiane Praza
16547c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
16557c478bd9Sstevel@tonic-gate
16567c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
16577c478bd9Sstevel@tonic-gate# fails to start correctly
1658597bd30bSMike Kupferfunction newdir {
16597c478bd9Sstevel@tonic-gate	dir=$1
16607c478bd9Sstevel@tonic-gate	toadd=
16617c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
16627c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
16637c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
16647c478bd9Sstevel@tonic-gate	done
16657c478bd9Sstevel@tonic-gate	torm=
16667c478bd9Sstevel@tonic-gate	newlist=
16677c478bd9Sstevel@tonic-gate	for dir in $toadd; do
16687c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
16697c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
16707c478bd9Sstevel@tonic-gate			torm="$dir $torm"
16717c478bd9Sstevel@tonic-gate		else
16727c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
16737c478bd9Sstevel@tonic-gate			return 1
16747c478bd9Sstevel@tonic-gate		fi
16757c478bd9Sstevel@tonic-gate	done
16767c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
16777c478bd9Sstevel@tonic-gate	return 0
16787c478bd9Sstevel@tonic-gate}
16797c478bd9Sstevel@tonic-gatenewdirlist=
16807c478bd9Sstevel@tonic-gate
16817c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
16827c478bd9Sstevel@tonic-gate
16837c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
16847c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
16857c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
16867c478bd9Sstevel@tonic-gate# built from this immediate source.
16877c478bd9Sstevel@tonic-gateENVLDLIBS1=
16887c478bd9Sstevel@tonic-gateENVLDLIBS2=
16897c478bd9Sstevel@tonic-gateENVLDLIBS3=
16907c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
16917c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
16927c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
16937c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
16947c478bd9Sstevel@tonic-gatePARENT_ROOT=
16957c478bd9Sstevel@tonic-gate
16967c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
16977c478bd9Sstevel@tonic-gate	PARENT_ROOT
16987c478bd9Sstevel@tonic-gate
16997c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
17007c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
17017c478bd9Sstevel@tonic-gate
17027c478bd9Sstevel@tonic-gate#
17037c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
17047c478bd9Sstevel@tonic-gate#
17057c478bd9Sstevel@tonic-gate
1706597bd30bSMike Kupferfunction logshuffle {
1707fd7cef36Ssuha    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
17087c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
17097c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
17107c478bd9Sstevel@tonic-gate	fi
17117c478bd9Sstevel@tonic-gate	mkdir $LLOG
17124802ef38Srscott	export LLOG
17137c478bd9Sstevel@tonic-gate
17147c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
17157c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
171696ccc8cbSesaxe
17172e02daeeSRainer Orth		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
17182e02daeeSRainer Orth			mv $ATLOG/proto_list_tools_${MACH} $LLOG
17192e02daeeSRainer Orth	        fi
17202e02daeeSRainer Orth
172196ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
172296ccc8cbSesaxe		    	mv $TMPDIR/wsdiff.results $LLOG
172396ccc8cbSesaxe		fi
17244e5b757fSkupfer
17254e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
17264e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
17274e5b757fSkupfer		fi
17287c478bd9Sstevel@tonic-gate	fi
17297c478bd9Sstevel@tonic-gate
17307c478bd9Sstevel@tonic-gate	#
17317c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
17327c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
17337c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
17347c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
17357c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
17367c478bd9Sstevel@tonic-gate	#
17377c478bd9Sstevel@tonic-gate
17387c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
17397c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
17407c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
17417c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
17427c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
17437c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
17447c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
17457c478bd9Sstevel@tonic-gate	fi
17467c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
17477c478bd9Sstevel@tonic-gate
17487c478bd9Sstevel@tonic-gate	case "$build_ok" in
17497c478bd9Sstevel@tonic-gate		y)
17507c478bd9Sstevel@tonic-gate			state=Completed
17517c478bd9Sstevel@tonic-gate			;;
17527c478bd9Sstevel@tonic-gate		i)
17537c478bd9Sstevel@tonic-gate			state=Interrupted
17547c478bd9Sstevel@tonic-gate			;;
17557c478bd9Sstevel@tonic-gate		*)
17567c478bd9Sstevel@tonic-gate	    		state=Failed
17577c478bd9Sstevel@tonic-gate			;;
17587c478bd9Sstevel@tonic-gate	esac
175940bc9153Srscott	NIGHTLY_STATUS=$state
176040bc9153Srscott	export NIGHTLY_STATUS
17617c478bd9Sstevel@tonic-gate
176247703246Ssommerfe	run_hook POST_NIGHTLY $state
176347703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
17644802ef38Srscott
1765cdf0c1d5Smjnelson	cat $build_time_file $build_environ_file $mail_msg_file \
1766cdf0c1d5Smjnelson	    > ${LLOG}/mail_msg
17677c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
1768cdf0c1d5Smjnelson	    	cat ${LLOG}/mail_msg | /usr/bin/mailx -s \
17697c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
17707c478bd9Sstevel@tonic-gate			${MAILTO}
17717c478bd9Sstevel@tonic-gate	fi
17727c478bd9Sstevel@tonic-gate
17737c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
17747c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
17757c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
17767c478bd9Sstevel@tonic-gate	fi
17777c478bd9Sstevel@tonic-gate
17787c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
17797c478bd9Sstevel@tonic-gate}
17807c478bd9Sstevel@tonic-gate
17817c478bd9Sstevel@tonic-gate#
17827c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
17837c478bd9Sstevel@tonic-gate#
1784597bd30bSMike Kupferfunction cleanup {
17857c478bd9Sstevel@tonic-gate    	logshuffle
17867c478bd9Sstevel@tonic-gate
17877c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
17887c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
17897c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
17907c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
17917c478bd9Sstevel@tonic-gate
17927c478bd9Sstevel@tonic-gate	set -- $newdirlist
17937c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
17947c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
17957c478bd9Sstevel@tonic-gate		shift; shift
17967c478bd9Sstevel@tonic-gate	done
17977c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
17987c478bd9Sstevel@tonic-gate}
17997c478bd9Sstevel@tonic-gate
1800597bd30bSMike Kupferfunction cleanup_signal {
18017c478bd9Sstevel@tonic-gate    	build_ok=i
18027c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
18037c478bd9Sstevel@tonic-gate	exit 1
18047c478bd9Sstevel@tonic-gate}
18057c478bd9Sstevel@tonic-gate
18067c478bd9Sstevel@tonic-gatetrap cleanup 0
18077c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
18087c478bd9Sstevel@tonic-gate
18097c478bd9Sstevel@tonic-gate#
18107c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
18117c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
18127c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
18137c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
18147c478bd9Sstevel@tonic-gate# for the workspace).
1815cdf0c1d5Smjnelson#
1816597bd30bSMike Kupferfunction create_lock {
18177c478bd9Sstevel@tonic-gate	lockf=$1
18187c478bd9Sstevel@tonic-gate	lockvar=$2
18198312e758Sdduvall
18207c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
18217c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
18227c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
18238312e758Sdduvall
18248312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
18258312e758Sdduvall		basews=`basename $CODEMGR_WS`
18268312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
18278312e758Sdduvall		if [ "$host" != "$hostname" ]; then
18288312e758Sdduvall			echo "$MACH build of $basews apparently" \
18298312e758Sdduvall			    "already started by $user on $host as $pid."
18308312e758Sdduvall			exit 1
18318312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
18328312e758Sdduvall			echo "$MACH build of $basews already started" \
18338312e758Sdduvall			    "by $user as $pid."
18348312e758Sdduvall			exit 1
18358312e758Sdduvall		else
18368312e758Sdduvall			# stale lock; clear it out and try again
18378312e758Sdduvall			rm -f $lockf
18388312e758Sdduvall		fi
18398312e758Sdduvall	done
18407c478bd9Sstevel@tonic-gate}
18417c478bd9Sstevel@tonic-gate
18424e5b757fSkupfer#
18434e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
18444e5b757fSkupfer# options.
18454e5b757fSkupfer#
1846597bd30bSMike Kupferfunction allprotos {
1847c7453724SMike Kupfer	typeset roots="$ROOT"
1848b83ec4edSjmcp
1849c7453724SMike Kupfer	if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
1850c7453724SMike Kupfer		roots="$roots $ROOT-nd"
18514e5b757fSkupfer	fi
18524e5b757fSkupfer
1853b83ec4edSjmcp	if [[ $O_FLAG = y ]]; then
1854b83ec4edSjmcp		roots="$roots $ROOT-closed"
1855b83ec4edSjmcp		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd-closed"
1856b83ec4edSjmcp	fi
1857b83ec4edSjmcp
18584e5b757fSkupfer	echo $roots
18594e5b757fSkupfer}
18604e5b757fSkupfer
18617c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
18627c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
18637c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
18647c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
18657c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
18667c478bd9Sstevel@tonic-gatefi
18677c478bd9Sstevel@tonic-gate#
18687c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
18697c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
18707c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
18717c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
18727c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
18737c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
18747c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
18757c478bd9Sstevel@tonic-gate#
18767c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
18777c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
18787c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
18797c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
18807c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
18817c478bd9Sstevel@tonic-gatefi
18827c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
18837c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
18847c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
18857c478bd9Sstevel@tonic-gatefi
18867c478bd9Sstevel@tonic-gate
18877c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
18887c478bd9Sstevel@tonic-gate# the directories we may have created so far.
18897c478bd9Sstevel@tonic-gatenewdirlist=
18907c478bd9Sstevel@tonic-gate
18917c478bd9Sstevel@tonic-gate#
18927c478bd9Sstevel@tonic-gate# Create mail_msg_file
18937c478bd9Sstevel@tonic-gate#
18947c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
18957c478bd9Sstevel@tonic-gatetouch $mail_msg_file
18967c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
1897cdf0c1d5Smjnelsonbuild_environ_file="${TMPDIR}/build_environ"
1898cdf0c1d5Smjnelsontouch $build_environ_file
18997c478bd9Sstevel@tonic-gate#
19007c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
19017c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
19027c478bd9Sstevel@tonic-gate#
19037c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
19047c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
19057c478bd9Sstevel@tonic-gatefi
19067c478bd9Sstevel@tonic-gate#
19077c478bd9Sstevel@tonic-gate#	Build OsNet source
19087c478bd9Sstevel@tonic-gate#
19097c478bd9Sstevel@tonic-gateSTART_DATE=`date`
19107c478bd9Sstevel@tonic-gateSECONDS=0
19117c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
19127c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
19137c478bd9Sstevel@tonic-gate
1914cdf0c1d5Smjnelsonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1915cdf0c1d5Smjnelson    tee -a $mail_msg_file >> $LOGFILE
1916cdf0c1d5Smjnelson
19177c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
19187c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
19197c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
19207c478bd9Sstevel@tonic-gate
192147703246Ssommerferun_hook SYS_PRE_NIGHTLY
192247703246Ssommerferun_hook PRE_NIGHTLY
192347703246Ssommerfe
19247c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
19257c478bd9Sstevel@tonic-gateenv >> $LOGFILE
19267c478bd9Sstevel@tonic-gate
19277c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
19287c478bd9Sstevel@tonic-gate
1929d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
1930d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1931d77e7149Ssommerfefi
1932d77e7149Ssommerfe
1933d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
1934d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1935d77e7149Ssommerfefi
1936d77e7149Ssommerfe
19371fe69678Skupferif is_source_build; then
19387c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
19397c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
19407c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
19417c478bd9Sstevel@tonic-gate		i_FLAG=n
19427c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
19437c478bd9Sstevel@tonic-gate	fi
19447c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
19457c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
19467c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
19477c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
19487c478bd9Sstevel@tonic-gate		N_FLAG=y
19497c478bd9Sstevel@tonic-gate	fi
19507c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
19517c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
19527c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
19537c478bd9Sstevel@tonic-gate		l_FLAG=n
19547c478bd9Sstevel@tonic-gate	fi
19557c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
19567c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
19577c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
19587c478bd9Sstevel@tonic-gate		C_FLAG=n
19597c478bd9Sstevel@tonic-gate	fi
19607c478bd9Sstevel@tonic-gateelse
19617c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
19627c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
19637c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
19647c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
19657c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
19667c478bd9Sstevel@tonic-gateEOF
19677c478bd9Sstevel@tonic-gate		else
19687c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
19697c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
19707c478bd9Sstevel@tonic-gateEOF
19717c478bd9Sstevel@tonic-gate		fi
19727c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
19737c478bd9Sstevel@tonic-gate	fi
19747c478bd9Sstevel@tonic-gatefi
19757c478bd9Sstevel@tonic-gate
19767c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
19774e5b757fSkupfer	#
19784e5b757fSkupfer	# In the past we just complained but went ahead with the lint
1979ead1f93eSLiane Praza	# pass, even though the proto area was built non-DEBUG.  It's
1980ead1f93eSLiane Praza	# unlikely that non-DEBUG headers will make a difference, but
19814e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
1982ead1f93eSLiane Praza	# to specify a DEBUG build.
19834e5b757fSkupfer	#
19844e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
19857c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
19864e5b757fSkupfer	l_FLAG=n
19877c478bd9Sstevel@tonic-gatefi
19887c478bd9Sstevel@tonic-gate
19897c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
19907c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
19917c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
19927c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
19937c478bd9Sstevel@tonic-gate		f_FLAG=n
19947c478bd9Sstevel@tonic-gate	fi
199511a78ea0SMark J. Nelson	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
199611a78ea0SMark J. Nelson		echo "WARNING: the -f flag requires -l, and -p;" \
199711a78ea0SMark J. Nelson		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
19987c478bd9Sstevel@tonic-gate		f_FLAG=n
19997c478bd9Sstevel@tonic-gate	fi
20007c478bd9Sstevel@tonic-gatefi
20017c478bd9Sstevel@tonic-gate
200296ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
20034e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
200496ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
200596ccc8cbSesaxe	w_FLAG=n
200696ccc8cbSesaxefi
200796ccc8cbSesaxe
20087c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
20097c478bd9Sstevel@tonic-gate	#
20107c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
20117c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
20127c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
20137c478bd9Sstevel@tonic-gate	#
20147c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
20157c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
20167c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
20177c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
20187c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
20197c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
20207c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
20217c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
20227c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
20237c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
20247c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
20257c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
20267c478bd9Sstevel@tonic-gate	fi
20277c478bd9Sstevel@tonic-gatefi
20287c478bd9Sstevel@tonic-gate
20294e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
20304e5b757fSkupfer
20314e5b757fSkupfercase $MULTI_PROTO in
20324e5b757fSkupferyes|no)	;;
20334e5b757fSkupfer*)
20344e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
20354e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
20364e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
20374e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
20384e5b757fSkupfer	export MULTI_PROTO=no
20394e5b757fSkupfer	;;
20404e5b757fSkupferesac
20414e5b757fSkupfer
20427c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
20437c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
20447c478bd9Sstevel@tonic-gate
204596ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
204696ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
204796ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
204896ccc8cbSesaxe	rm -rf $ROOT.prev
204996ccc8cbSesaxe    fi
205096ccc8cbSesaxe    mv $ROOT $ROOT.prev
205196ccc8cbSesaxefi
205296ccc8cbSesaxe
20534e5b757fSkupfer# Same for non-DEBUG proto area
20544e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
20554e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
20564e5b757fSkupfer		rm -rf $ROOT-nd.prev
20574e5b757fSkupfer	fi
20584e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
20594e5b757fSkupferfi
20604e5b757fSkupfer
2061445b6314SRichard Lowe#
2062445b6314SRichard Lowe# Echo the SCM type of the parent workspace, this can't just be which_scm
2063445b6314SRichard Lowe# as that does not know how to identify various network repositories.
2064445b6314SRichard Lowe#
2065445b6314SRichard Lowefunction parent_wstype {
2066445b6314SRichard Lowe	typeset scm_type junk
206730635de9SJohn.Zolnowsky@Sun.COM
206830635de9SJohn.Zolnowsky@Sun.COM	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
2069445b6314SRichard Lowe	    | read scm_type junk
2070445b6314SRichard Lowe	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
207130635de9SJohn.Zolnowsky@Sun.COM		# Probe BRINGOVER_WS to determine its type
207230635de9SJohn.Zolnowsky@Sun.COM		if [[ $BRINGOVER_WS == svn*://* ]]; then
2073445b6314SRichard Lowe			scm_type="subversion"
207430635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == file://* ]] &&
207530635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "This is a Subversion repository" \
207630635de9SJohn.Zolnowsky@Sun.COM		    ${BRINGOVER_WS#file://}/README.txt 2> /dev/null; then
2077445b6314SRichard Lowe			scm_type="subversion"
207830635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == ssh://* ]]; then
2079445b6314SRichard Lowe			scm_type="mercurial"
208030635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == http://* ]] && \
2081445b6314SRichard Lowe		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
208230635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "application/mercurial" 2> /dev/null; then
2083445b6314SRichard Lowe			scm_type="mercurial"
2084445b6314SRichard Lowe		elif svn info $BRINGOVER_WS > /dev/null 2>&1; then
2085445b6314SRichard Lowe			scm_type="subversion"
208630635de9SJohn.Zolnowsky@Sun.COM		else
2087445b6314SRichard Lowe			scm_type="none"
208830635de9SJohn.Zolnowsky@Sun.COM		fi
208930635de9SJohn.Zolnowsky@Sun.COM	fi
209030635de9SJohn.Zolnowsky@Sun.COM
209130635de9SJohn.Zolnowsky@Sun.COM	# fold both unsupported and unrecognized results into "none"
2092445b6314SRichard Lowe	case "$scm_type" in
209330635de9SJohn.Zolnowsky@Sun.COM	none|subversion|teamware|mercurial)
209430635de9SJohn.Zolnowsky@Sun.COM		;;
2095445b6314SRichard Lowe	*)	scm_type=none
209630635de9SJohn.Zolnowsky@Sun.COM		;;
209730635de9SJohn.Zolnowsky@Sun.COM	esac
209830635de9SJohn.Zolnowsky@Sun.COM
2099445b6314SRichard Lowe	echo $scm_type
210030635de9SJohn.Zolnowsky@Sun.COM}
210130635de9SJohn.Zolnowsky@Sun.COM
2102445b6314SRichard Lowe# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
2103445b6314SRichard Lowefunction child_wstype {
2104445b6314SRichard Lowe	typeset scm_type junk
2105445b6314SRichard Lowe
2106445b6314SRichard Lowe	# Probe CODEMGR_WS to determine its type
2107445b6314SRichard Lowe	if [[ -d $CODEMGR_WS ]]; then
2108445b6314SRichard Lowe		$WHICH_SCM | read scm_type junk || exit 1
2109445b6314SRichard Lowe	fi
2110445b6314SRichard Lowe
2111445b6314SRichard Lowe	case "$scm_type" in
2112445b6314SRichard Lowe	none|subversion|teamware|mercurial)
2113445b6314SRichard Lowe		;;
2114445b6314SRichard Lowe	*)	scm_type=none
2115445b6314SRichard Lowe		;;
2116445b6314SRichard Lowe	esac
2117445b6314SRichard Lowe
2118445b6314SRichard Lowe	echo $scm_type
2119445b6314SRichard Lowe}
2120445b6314SRichard Lowe
2121445b6314SRichard Loweexport SCM_TYPE=$(child_wstype)
212230635de9SJohn.Zolnowsky@Sun.COM
21237c478bd9Sstevel@tonic-gate#
21247c478bd9Sstevel@tonic-gate#	Decide whether to clobber
21257c478bd9Sstevel@tonic-gate#
21267c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
21277c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
21287c478bd9Sstevel@tonic-gate
21297c478bd9Sstevel@tonic-gate	cd $SRC
21307c478bd9Sstevel@tonic-gate	# remove old clobber file
21317c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
21327c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
21337c478bd9Sstevel@tonic-gate
21347c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
21357c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
2136cdf0c1d5Smjnelson	find . \( -name SCCS -o -name .hg -o -name .svn \
2137cdf0c1d5Smjnelson		-o -name 'interfaces.*' \) -prune \
21387c478bd9Sstevel@tonic-gate		-o -name '.make.*' -print | xargs rm -f
21397c478bd9Sstevel@tonic-gate
21407c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
21417c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
21427c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
21437c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
21447c478bd9Sstevel@tonic-gate		>> $mail_msg_file
21457c478bd9Sstevel@tonic-gate
21464e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
21477c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
21487c478bd9Sstevel@tonic-gate		cd ${TOOLS}
21497c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
2150ead1f93eSLiane Praza		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
21517c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
21527c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
21537c478bd9Sstevel@tonic-gate			>> $mail_msg_file
21547c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
21557c478bd9Sstevel@tonic-gate			>> $mail_msg_file
21567c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
21577c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
21587c478bd9Sstevel@tonic-gate	fi
215996ccc8cbSesaxe
2160c7453724SMike Kupfer	typeset roots=$(allprotos)
2161c7453724SMike Kupfer	echo "\n\nClearing $roots" >> "$LOGFILE"
2162c7453724SMike Kupfer	rm -rf $roots
21637c478bd9Sstevel@tonic-gate
21647c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
21657c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
21667c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2167fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2168cdf0c1d5Smjnelson	# under source code control, so leave them alone.
21697c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
21707c478bd9Sstevel@tonic-gate	cd $SRC
2171cdf0c1d5Smjnelson	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
2172cdf0c1d5Smjnelson	    -o -name 'interfaces.*' \) -prune -o \
21737c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2174fb23a357Skupfer	       -name '*.o' \) -print | \
2175fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
21767c478bd9Sstevel@tonic-gateelse
21777c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
21787c478bd9Sstevel@tonic-gatefi
21797c478bd9Sstevel@tonic-gate
2180597bd30bSMike Kupfertype bringover_teamware > /dev/null 2>&1 || function bringover_teamware {
21817c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
21827c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
21837c478bd9Sstevel@tonic-gate	do
21847c478bd9Sstevel@tonic-gate		sleep 120
21857c478bd9Sstevel@tonic-gate	done
21867c478bd9Sstevel@tonic-gate
2187fd7cef36Ssuha	if [[ -z $BRINGOVER ]]; then
2188fd7cef36Ssuha		BRINGOVER=$TEAMWARE/bin/bringover
2189fd7cef36Ssuha	fi
219032f1e47bSsommerfe
2191cdf0c1d5Smjnelson	staffer $BRINGOVER -c "nightly update" -p $BRINGOVER_WS \
219232f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
219332f1e47bSsommerfe		touch $TMPDIR/bringover_failed
219432f1e47bSsommerfe
2195d77e7149Ssommerfe        staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2196d77e7149Ssommerfe	if [ -s $TMPDIR/bringovercheck.out ]; then
2197d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2198d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2199d77e7149Ssommerfe	fi
2200cdf0c1d5Smjnelson}
220132f1e47bSsommerfe
2202597bd30bSMike Kupfertype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
2203cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2204cdf0c1d5Smjnelson
2205cdf0c1d5Smjnelson	# If the repository doesn't exist yet, then we want to populate it.
2206cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.hg ]]; then
2207cdf0c1d5Smjnelson		staffer hg init $CODEMGR_WS
22088cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
22098cca05f6SMark J. Nelson		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
2210f457028bSMark J. Nelson		touch $TMPDIR/new_repository
2211cdf0c1d5Smjnelson	fi
22125c53ea7aSmjnelson
22135c53ea7aSmjnelson	#
22145c53ea7aSmjnelson	# If the user set CLOSED_BRINGOVER_WS and didn't set CLOSED_IS_PRESENT
22155c53ea7aSmjnelson	# to "no," then we'll want to initialise the closed repository
22165c53ea7aSmjnelson	#
22175c53ea7aSmjnelson	# We use $orig_closed_is_present instead of $CLOSED_IS_PRESENT,
22185c53ea7aSmjnelson	# because for newly-created source trees, the latter will be "no"
22195c53ea7aSmjnelson	# until after the bringover completes.
22205c53ea7aSmjnelson	#
22215c53ea7aSmjnelson	if [[ "$orig_closed_is_present" != "no" && \
22225c53ea7aSmjnelson	    -n "$CLOSED_BRINGOVER_WS" && \
22235c53ea7aSmjnelson	    ! -d $CODEMGR_WS/usr/closed/.hg ]]; then
22245c53ea7aSmjnelson		staffer mkdir -p $CODEMGR_WS/usr/closed
22255c53ea7aSmjnelson		staffer hg init $CODEMGR_WS/usr/closed
22268cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/usr/closed/.hg/hgrc
22278cca05f6SMark J. Nelson		staffer echo "default=$CLOSED_BRINGOVER_WS" >> $CODEMGR_WS/usr/closed/.hg/hgrc
2228f457028bSMark J. Nelson		touch $TMPDIR/new_closed
22295c53ea7aSmjnelson		export CLOSED_IS_PRESENT=yes
2230cdf0c1d5Smjnelson	fi
2231cdf0c1d5Smjnelson
2232cdf0c1d5Smjnelson	typeset -x HGMERGE="/bin/false"
2233cdf0c1d5Smjnelson
2234cdf0c1d5Smjnelson	#
22355c53ea7aSmjnelson	# If the user has changes, regardless of whether those changes are
22365c53ea7aSmjnelson	# committed, and regardless of whether those changes conflict, then
22375c53ea7aSmjnelson	# we'll attempt to merge them either implicitly (uncommitted) or
22385c53ea7aSmjnelson	# explicitly (committed).
2239cdf0c1d5Smjnelson	#
22405c53ea7aSmjnelson	# These are the messages we'll use to help clarify mercurial output
22415c53ea7aSmjnelson	# in those cases.
22425c53ea7aSmjnelson	#
22435c53ea7aSmjnelson	typeset mergefailmsg="\
22445c53ea7aSmjnelson***\n\
22455c53ea7aSmjnelson*** nightly was unable to automatically merge your changes.  You should\n\
22465c53ea7aSmjnelson*** redo the full merge manually, following the steps outlined by mercurial\n\
22475c53ea7aSmjnelson*** above, then restart nightly.\n\
22485c53ea7aSmjnelson***\n"
22495c53ea7aSmjnelson	typeset mergepassmsg="\
22505c53ea7aSmjnelson***\n\
22515c53ea7aSmjnelson*** nightly successfully merged your changes.  This means that your working\n\
22525c53ea7aSmjnelson*** directory has been updated, but those changes are not yet committed.\n\
22535c53ea7aSmjnelson*** After nightly completes, you should validate the results of the merge,\n\
22545c53ea7aSmjnelson*** then use hg commit manually.\n\
22555c53ea7aSmjnelson***\n"
22565c53ea7aSmjnelson
22575c53ea7aSmjnelson	#
22585c53ea7aSmjnelson	# For each repository in turn:
22595c53ea7aSmjnelson	#
22605c53ea7aSmjnelson	# 1. Do the pull.  If this fails, dump the output and bail out.
22615c53ea7aSmjnelson	#
22625c53ea7aSmjnelson	# 2. If the pull resulted in an extra head, do an explicit merge.
22635c53ea7aSmjnelson	#    If this fails, dump the output and bail out.
22645c53ea7aSmjnelson	#
22655c53ea7aSmjnelson	# Because we can't rely on Mercurial to exit with a failure code
22665c53ea7aSmjnelson	# when a merge fails (Mercurial issue #186), we must grep the
22675c53ea7aSmjnelson	# output of pull/merge to check for attempted and/or failed merges.
22685c53ea7aSmjnelson	#
22695c53ea7aSmjnelson	# 3. If a merge failed, set the message and fail the bringover.
22705c53ea7aSmjnelson	#
22715c53ea7aSmjnelson	# 4. Otherwise, if a merge succeeded, set the message
22725c53ea7aSmjnelson	#
22735c53ea7aSmjnelson	# 5. Dump the output, and any message from step 3 or 4.
22745c53ea7aSmjnelson	#
22755c53ea7aSmjnelson
2276f457028bSMark J. Nelson	typeset HG_SOURCE=$BRINGOVER_WS
2277f457028bSMark J. Nelson	if [ ! -f $TMPDIR/new_repository ]; then
2278f457028bSMark J. Nelson		HG_SOURCE=$TMPDIR/open_bundle.hg
2279f457028bSMark J. Nelson		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
2280f457028bSMark J. Nelson		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
2281f457028bSMark J. Nelson
2282f457028bSMark J. Nelson		#
2283f457028bSMark J. Nelson		# If there are no incoming changesets, then incoming will
2284f457028bSMark J. Nelson		# fail, and there will be no bundle file.  Reset the source,
2285f457028bSMark J. Nelson		# to allow the remaining logic to complete with no false
2286f457028bSMark J. Nelson		# negatives.  (Unlike incoming, pull will return success
2287f457028bSMark J. Nelson		# for the no-change case.)
2288f457028bSMark J. Nelson		#
2289f457028bSMark J. Nelson		if (( $? != 0 )); then
2290f457028bSMark J. Nelson			HG_SOURCE=$BRINGOVER_WS
2291f457028bSMark J. Nelson		fi
2292f457028bSMark J. Nelson	fi
2293f457028bSMark J. Nelson
2294f457028bSMark J. Nelson	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
22955c53ea7aSmjnelson	    > $TMPDIR/pull_open.out 2>&1
22965c53ea7aSmjnelson	if (( $? != 0 )); then
22975c53ea7aSmjnelson		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
22985c53ea7aSmjnelson		cat $TMPDIR/pull_open.out
22995c53ea7aSmjnelson		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
23005c53ea7aSmjnelson			printf "$mergefailmsg"
23015c53ea7aSmjnelson		fi
23025c53ea7aSmjnelson		touch $TMPDIR/bringover_failed
23035c53ea7aSmjnelson		return
23045c53ea7aSmjnelson	fi
23055c53ea7aSmjnelson
2306cdf0c1d5Smjnelson	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
23075c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS merge \
23085c53ea7aSmjnelson		    >> $TMPDIR/pull_open.out 2>&1
23095c53ea7aSmjnelson		if (( $? != 0 )); then
23105c53ea7aSmjnelson			printf "%s: merge failed as follows:\n\n" \
23115c53ea7aSmjnelson			    "$CODEMGR_WS"
23125c53ea7aSmjnelson			cat $TMPDIR/pull_open.out
23135c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_open.out \
23145c53ea7aSmjnelson			    > /dev/null 2>&1; then
23155c53ea7aSmjnelson				printf "$mergefailmsg"
23165c53ea7aSmjnelson			fi
2317cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
23185c53ea7aSmjnelson			return
2319cdf0c1d5Smjnelson		fi
2320cdf0c1d5Smjnelson	fi
23215c53ea7aSmjnelson
23225c53ea7aSmjnelson	printf "updated %s with the following results:\n" "$CODEMGR_WS"
23235c53ea7aSmjnelson	cat $TMPDIR/pull_open.out
23245c53ea7aSmjnelson	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
23255c53ea7aSmjnelson		printf "$mergepassmsg"
23265c53ea7aSmjnelson	fi
23275c53ea7aSmjnelson	printf "\n"
23285c53ea7aSmjnelson
23295c53ea7aSmjnelson	#
23305c53ea7aSmjnelson	# We only want to update usr/closed if it exists, and we haven't been
23315c53ea7aSmjnelson	# told not to via $CLOSED_IS_PRESENT, and we actually know where to
23325c53ea7aSmjnelson	# pull from ($CLOSED_BRINGOVER_WS).
23335c53ea7aSmjnelson	#
23345c53ea7aSmjnelson	if [[ $CLOSED_IS_PRESENT = yes && \
23355c53ea7aSmjnelson	    -d $CODEMGR_WS/usr/closed/.hg && \
23365c53ea7aSmjnelson	    -n $CLOSED_BRINGOVER_WS ]]; then
23375c53ea7aSmjnelson
2338f457028bSMark J. Nelson		HG_SOURCE=$CLOSED_BRINGOVER_WS
2339f457028bSMark J. Nelson		if [ ! -f $TMPDIR/new_closed ]; then
2340f457028bSMark J. Nelson			HG_SOURCE=$TMPDIR/closed_bundle.hg
2341f457028bSMark J. Nelson			staffer hg --cwd $CODEMGR_WS/usr/closed incoming \
2342f457028bSMark J. Nelson			    --bundle $HG_SOURCE -v $CLOSED_BRINGOVER_WS \
2343f457028bSMark J. Nelson			    > $TMPDIR/incoming_closed.out
2344f457028bSMark J. Nelson
2345f457028bSMark J. Nelson			#
2346f457028bSMark J. Nelson			# If there are no incoming changesets, then incoming will
2347f457028bSMark J. Nelson			# fail, and there will be no bundle file.  Reset the source,
2348f457028bSMark J. Nelson			# to allow the remaining logic to complete with no false
2349f457028bSMark J. Nelson			# negatives.  (Unlike incoming, pull will return success
2350f457028bSMark J. Nelson			# for the no-change case.)
2351f457028bSMark J. Nelson			#
2352f457028bSMark J. Nelson			if (( $? != 0 )); then
2353f457028bSMark J. Nelson				HG_SOURCE=$CLOSED_BRINGOVER_WS
2354f457028bSMark J. Nelson			fi
2355f457028bSMark J. Nelson		fi
2356f457028bSMark J. Nelson
23575c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS/usr/closed pull -u \
2358f457028bSMark J. Nelson			$HG_SOURCE > $TMPDIR/pull_closed.out 2>&1
23595c53ea7aSmjnelson		if (( $? != 0 )); then
23605c53ea7aSmjnelson			printf "closed pull failed as follows:\n\n"
23615c53ea7aSmjnelson			cat $TMPDIR/pull_closed.out
23625c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_closed.out \
23635c53ea7aSmjnelson			    > /dev/null 2>&1; then
23645c53ea7aSmjnelson				printf "$mergefailmsg"
23655c53ea7aSmjnelson			fi
23665c53ea7aSmjnelson			touch $TMPDIR/bringover_failed
23675c53ea7aSmjnelson			return
23685c53ea7aSmjnelson		fi
23695c53ea7aSmjnelson
2370cdf0c1d5Smjnelson		if grep "not updating" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
23715c53ea7aSmjnelson			staffer hg --cwd $CODEMGR_WS/usr/closed merge \
23725c53ea7aSmjnelson			    >> $TMPDIR/pull_closed.out 2>&1
23735c53ea7aSmjnelson			if (( $? != 0 )); then
23745c53ea7aSmjnelson				printf "closed merge failed as follows:\n\n"
23755c53ea7aSmjnelson				cat $TMPDIR/pull_closed.out
23765c53ea7aSmjnelson				if grep "^merging.*failed" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
23775c53ea7aSmjnelson					printf "$mergefailmsg"
23785c53ea7aSmjnelson				fi
2379cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
23805c53ea7aSmjnelson				return
23815c53ea7aSmjnelson			fi
23825c53ea7aSmjnelson		fi
23835c53ea7aSmjnelson
23845c53ea7aSmjnelson		printf "updated %s with the following results:\n" \
23855c53ea7aSmjnelson		    "$CODEMGR_WS/usr/closed"
23865c53ea7aSmjnelson		cat $TMPDIR/pull_closed.out
23875c53ea7aSmjnelson		if grep "^merging" $TMPDIR/pull_closed.out > /dev/null 2>&1; then
23885c53ea7aSmjnelson			printf "$mergepassmsg"
2389cdf0c1d5Smjnelson		fi
2390cdf0c1d5Smjnelson	fi
2391f457028bSMark J. Nelson
2392f457028bSMark J. Nelson	#
2393f457028bSMark J. Nelson	# Per-changeset output is neither useful nor manageable for a
2394f457028bSMark J. Nelson	# newly-created repository.
2395f457028bSMark J. Nelson	#
2396f457028bSMark J. Nelson	if [ -f $TMPDIR/new_repository ]; then
2397f457028bSMark J. Nelson		return
2398f457028bSMark J. Nelson	fi
2399f457028bSMark J. Nelson
2400f457028bSMark J. Nelson	printf "\nadded the following changesets to open repository:\n"
2401f457028bSMark J. Nelson	cat $TMPDIR/incoming_open.out
2402f457028bSMark J. Nelson
2403f457028bSMark J. Nelson	#
2404f457028bSMark J. Nelson	# The closed repository could have been newly created, even though
2405f457028bSMark J. Nelson	# the open one previously existed...
2406f457028bSMark J. Nelson	#
2407f457028bSMark J. Nelson	if [ -f $TMPDIR/new_closed ]; then
2408f457028bSMark J. Nelson		return
2409f457028bSMark J. Nelson	fi
2410f457028bSMark J. Nelson
2411f457028bSMark J. Nelson	if [ -f $TMPDIR/incoming_closed.out ]; then
2412f457028bSMark J. Nelson		printf "\nadded the following changesets to closed repository:\n"
2413f457028bSMark J. Nelson		cat $TMPDIR/incoming_closed.out
2414f457028bSMark J. Nelson	fi
2415cdf0c1d5Smjnelson}
2416cdf0c1d5Smjnelson
2417597bd30bSMike Kupfertype bringover_subversion > /dev/null 2>&1 || function bringover_subversion {
2418cdf0c1d5Smjnelson	typeset -x PATH=$PATH
2419cdf0c1d5Smjnelson
2420cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.svn ]]; then
2421cdf0c1d5Smjnelson		staffer svn checkout $BRINGOVER_WS $CODEMGR_WS ||
2422cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2423cdf0c1d5Smjnelson	else
2424cdf0c1d5Smjnelson		typeset root
2425cdf0c1d5Smjnelson		root=$(staffer svn info $CODEMGR_WS |
2426cdf0c1d5Smjnelson			nawk '/^Repository Root:/ {print $NF}')
2427cdf0c1d5Smjnelson		if [[ $root != $BRINGOVER_WS ]]; then
2428cdf0c1d5Smjnelson			# We fail here because there's no way to update
2429cdf0c1d5Smjnelson			# from a named repo.
2430cdf0c1d5Smjnelson			cat <<-EOF
2431cdf0c1d5Smjnelson			\$BRINGOVER_WS doesn't match repository root:
2432cdf0c1d5Smjnelson			  \$BRINGOVER_WS:  $BRINGOVER_WS
2433cdf0c1d5Smjnelson			  Repository root: $root
2434cdf0c1d5Smjnelson			EOF
2435cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
2436cdf0c1d5Smjnelson		else
2437cdf0c1d5Smjnelson			# If a conflict happens, svn still exits 0.
2438cdf0c1d5Smjnelson			staffer svn update $CODEMGR_WS | tee $TMPDIR/pull.out ||
2439cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2440cdf0c1d5Smjnelson			if grep "^C" $TMPDIR/pull.out > /dev/null 2>&1; then
2441cdf0c1d5Smjnelson				touch $TMPDIR/bringover_failed
2442cdf0c1d5Smjnelson			fi
2443cdf0c1d5Smjnelson		fi
2444cdf0c1d5Smjnelson	fi
2445cdf0c1d5Smjnelson}
2446cdf0c1d5Smjnelson
2447597bd30bSMike Kupfertype bringover_none > /dev/null 2>&1 || function bringover_none {
2448cdf0c1d5Smjnelson	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
2449cdf0c1d5Smjnelson	touch $TMPDIR/bringover_failed
2450cdf0c1d5Smjnelson}
2451cdf0c1d5Smjnelson
2452cdf0c1d5Smjnelson#
2453cdf0c1d5Smjnelson#	Decide whether to bringover to the codemgr workspace
2454cdf0c1d5Smjnelson#
2455cdf0c1d5Smjnelsonif [ "$n_FLAG" = "n" ]; then
2456445b6314SRichard Lowe	PARENT_SCM_TYPE=$(parent_wstype)
2457ca0ac982Smjnelson
2458ca0ac982Smjnelson	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
2459ca0ac982Smjnelson		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
2460ca0ac982Smjnelson		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
2461ca0ac982Smjnelson		exit 1
2462ca0ac982Smjnelson	fi
2463ca0ac982Smjnelson
2464cdf0c1d5Smjnelson	run_hook PRE_BRINGOVER
2465cdf0c1d5Smjnelson
2466cdf0c1d5Smjnelson	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
2467cdf0c1d5Smjnelson	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
2468cdf0c1d5Smjnelson
2469ca0ac982Smjnelson	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
2470cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
247132f1e47bSsommerfe
247232f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
247332f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
247432f1e47bSsommerfe		build_ok=n
247532f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
24767c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
24777c478bd9Sstevel@tonic-gate		exit 1
24787c478bd9Sstevel@tonic-gate	fi
2479085d331dSkupfer
2480ca0ac982Smjnelson	#
2481ca0ac982Smjnelson	# It's possible that we used the bringover above to create
2482ca0ac982Smjnelson	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
2483ca0ac982Smjnelson	# but should now be the same as $BRINGOVER_WS.
2484ca0ac982Smjnelson	#
2485ca0ac982Smjnelson	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
2486ca0ac982Smjnelson
248747703246Ssommerfe	run_hook POST_BRINGOVER
248847703246Ssommerfe
2489085d331dSkupfer	#
2490085d331dSkupfer	# Possible transition from pre-split workspace to split
2491085d331dSkupfer	# workspace.  See if the bringover changed anything.
2492085d331dSkupfer	#
2493085d331dSkupfer	CLOSED_IS_PRESENT="$orig_closed_is_present"
2494085d331dSkupfer	check_closed_tree
2495b83ec4edSjmcp
24967c478bd9Sstevel@tonic-gateelse
24977c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
24987c478bd9Sstevel@tonic-gatefi
24997c478bd9Sstevel@tonic-gate
2500b83ec4edSjmcpif [[ "$O_FLAG" = y && "$CLOSED_IS_PRESENT" != "yes" ]]; then
2501b83ec4edSjmcp	build_ok=n
2502b83ec4edSjmcp	echo "OpenSolaris binary deliverables need usr/closed." \
2503b83ec4edSjmcp	    | tee -a "$mail_msg_file" >> $LOGFILE
2504b83ec4edSjmcp	exit 1
2505b83ec4edSjmcpfi
2506b83ec4edSjmcp
2507cdf0c1d5Smjnelsonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
2508cdf0c1d5Smjnelson
2509cdf0c1d5Smjnelson# System
2510cdf0c1d5Smjnelsonwhence uname | tee -a $build_environ_file >> $LOGFILE
2511cdf0c1d5Smjnelsonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
2512cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2513cdf0c1d5Smjnelson
2514cdf0c1d5Smjnelson# make
2515cdf0c1d5Smjnelsonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
2516cdf0c1d5Smjnelson$MAKE -v | tee -a $build_environ_file >> $LOGFILE
2517cdf0c1d5Smjnelsonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
2518cdf0c1d5Smjnelson    tee -a $build_environ_file >> $LOGFILE
2519cdf0c1d5Smjnelson
2520cdf0c1d5Smjnelson#
2521cdf0c1d5Smjnelson# Report the compiler versions.
2522cdf0c1d5Smjnelson#
2523cdf0c1d5Smjnelson
2524cdf0c1d5Smjnelsonif [[ ! -f $SRC/Makefile ]]; then
2525cdf0c1d5Smjnelson	build_ok=n
2526cdf0c1d5Smjnelson	echo "\nUnable to find \"Makefile\" in $SRC." | \
2527cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2528cdf0c1d5Smjnelson	exit 1
2529cdf0c1d5Smjnelsonfi
2530cdf0c1d5Smjnelson
2531cdf0c1d5Smjnelson( cd $SRC
2532cdf0c1d5Smjnelson  for target in cc-version cc64-version java-version; do
2533cdf0c1d5Smjnelson	echo
2534cdf0c1d5Smjnelson	#
2535cdf0c1d5Smjnelson	# Put statefile somewhere we know we can write to rather than trip
2536cdf0c1d5Smjnelson	# over a read-only $srcroot.
2537cdf0c1d5Smjnelson	#
2538cdf0c1d5Smjnelson	rm -f $TMPDIR/make-state
2539cdf0c1d5Smjnelson	export SRC
2540cdf0c1d5Smjnelson	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
2541cdf0c1d5Smjnelson		continue
2542cdf0c1d5Smjnelson	fi
2543cdf0c1d5Smjnelson	touch $TMPDIR/nocompiler
2544cdf0c1d5Smjnelson  done
2545cdf0c1d5Smjnelson  echo
2546cdf0c1d5Smjnelson) | tee -a $build_environ_file >> $LOGFILE
2547cdf0c1d5Smjnelson
2548cdf0c1d5Smjnelsonif [ -f $TMPDIR/nocompiler ]; then
2549cdf0c1d5Smjnelson	rm -f $TMPDIR/nocompiler
2550cdf0c1d5Smjnelson	build_ok=n
2551cdf0c1d5Smjnelson	echo "Aborting due to missing compiler." |
2552cdf0c1d5Smjnelson		tee -a $build_environ_file >> $LOGFILE
2553cdf0c1d5Smjnelson	exit 1
2554cdf0c1d5Smjnelsonfi
2555cdf0c1d5Smjnelson
2556cdf0c1d5Smjnelson# as
2557cdf0c1d5Smjnelsonwhence as | tee -a $build_environ_file >> $LOGFILE
2558cdf0c1d5Smjnelsonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
2559cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
2560cdf0c1d5Smjnelson
2561cdf0c1d5Smjnelson# Check that we're running a capable link-editor
2562cdf0c1d5Smjnelsonwhence ld | tee -a $build_environ_file >> $LOGFILE
2563cdf0c1d5SmjnelsonLDVER=`ld -V 2>&1`
2564cdf0c1d5Smjnelsonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
2565cdf0c1d5SmjnelsonLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
2566cdf0c1d5Smjnelsonif [ `expr $LDVER \< 422` -eq 1 ]; then
2567cdf0c1d5Smjnelson	echo "The link-editor needs to be at version 422 or higher to build" | \
2568cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2569cdf0c1d5Smjnelson	echo "the latest stuff.  Hope your build works." | \
2570cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
2571cdf0c1d5Smjnelsonfi
2572cdf0c1d5Smjnelson
25737c478bd9Sstevel@tonic-gate#
25744e5b757fSkupfer# Build and use the workspace's tools if requested
25757c478bd9Sstevel@tonic-gate#
25764e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
25774e5b757fSkupfer	set_non_debug_build_flags
25787c478bd9Sstevel@tonic-gate
25797c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
2580ead1f93eSLiane Praza	if [[ $? != 0  && "$t_FLAG" = y ]]; then
25814e5b757fSkupfer		use_tools $TOOLS_PROTO
25824e5b757fSkupfer	fi
25837c478bd9Sstevel@tonic-gatefi
25847c478bd9Sstevel@tonic-gate
25856fec3625Sdduvall#
25866fec3625Sdduvall# copy ihv proto area in addition to the build itself
25876fec3625Sdduvall#
25886fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
25896fec3625Sdduvall	copy_ihv_proto
25906fec3625Sdduvallfi
25916fec3625Sdduvall
25927c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
25937c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
25947c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25957c478bd9Sstevel@tonic-gateelse
25964e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
25974e5b757fSkupfer	touch $SRC/.build.tstamp
25984e5b757fSkupfer
25997c478bd9Sstevel@tonic-gate	normal_build
26007c478bd9Sstevel@tonic-gatefi
26017c478bd9Sstevel@tonic-gate
26024e5b757fSkupfer#
2603597bd30bSMike Kupfer# Generate the THIRDPARTYLICENSE files if needed.  This is done after
2604597bd30bSMike Kupfer# the build, so that dynamically-created license files are there.
2605597bd30bSMike Kupfer# It's done before findunref to help identify license files that need
2606597bd30bSMike Kupfer# to be added to tools/opensolaris/license-list.
26075d715dd7Skupfer#
26085d715dd7Skupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
2609597bd30bSMike Kupfer	echo "\n==== Generating THIRDPARTYLICENSE files ====\n" |
2610597bd30bSMike Kupfer	    tee -a "$mail_msg_file" >> "$LOGFILE"
26115d715dd7Skupfer
26125084e753SMark J. Nelson	if [ -d $ROOT/licenses/usr ]; then
26135084e753SMark J. Nelson		( cd $ROOT/licenses ; \
26145084e753SMark J. Nelson		    mktpl $SRC/pkg/license-list ) >> "$LOGFILE" 2>&1
2615cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
26165d715dd7Skupfer			echo "Couldn't create THIRDPARTYLICENSE files" |
2617597bd30bSMike Kupfer			    tee -a "$mail_msg_file" >> "$LOGFILE"
26185d715dd7Skupfer		fi
26195084e753SMark J. Nelson	else
26205084e753SMark J. Nelson		echo "No licenses found under $ROOT/licenses" |
26215084e753SMark J. Nelson		    tee -a "$mail_msg_file" >> "$LOGFILE"
26225084e753SMark J. Nelson	fi
26235d715dd7Skupferfi
26245d715dd7Skupfer
26257c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
26267c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
26277c478bd9Sstevel@tonic-gate
26287c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
26297c478bd9Sstevel@tonic-gate	save_binaries
26307c478bd9Sstevel@tonic-gatefi
26317c478bd9Sstevel@tonic-gate
26327c478bd9Sstevel@tonic-gate
26337c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
26347c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
2635cdf0c1d5Smjnelson
26367c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
2637cdf0c1d5Smjnelson	if [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
2638cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
26397c478bd9Sstevel@tonic-gate	fi
26407c478bd9Sstevel@tonic-gate
2641cdf0c1d5Smjnelson	if [ $build_ok = y ]; then
2642cdf0c1d5Smjnelson	    set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
2643cdf0c1d5Smjnelson	fi
2644cdf0c1d5Smjnelsonfi
2645cdf0c1d5Smjnelson
2646cdf0c1d5Smjnelsonif [ "$SD_FLAG" = "y" -a $build_ok = y ]; then
26477c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
26487c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
26497c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
26507c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
26517c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
26527c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
26537c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
26547c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
26557c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
26567c478bd9Sstevel@tonic-gate	else
26577c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
26587c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
26597c478bd9Sstevel@tonic-gate	fi
26607c478bd9Sstevel@tonic-gate
26617c478bd9Sstevel@tonic-gatefi
26627c478bd9Sstevel@tonic-gate
2663c7453724SMike Kupferif [ "$SO_FLAG" = "y" -a "$build_ok" = y ]; then
26641fe69678Skupfer	#
26651fe69678Skupfer	# Copy the open sources into their own tree, set up the closed
26664e5b757fSkupfer	# binaries, and set up the environment.  The build looks for
26674e5b757fSkupfer	# the closed binaries in a location that depends on whether
26684e5b757fSkupfer	# it's a DEBUG build, so we might need to make two copies.
26691fe69678Skupfer	#
2670cdf0c1d5Smjnelson	# If copy_source fails, it will have already generated an
2671cdf0c1d5Smjnelson	# error message and set build_ok=n, so we don't need to worry
2672cdf0c1d5Smjnelson	# about that here.
2673cdf0c1d5Smjnelson	#
26741fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
2675cdf0c1d5Smjnelsonfi
2676cdf0c1d5Smjnelson
2677c7453724SMike Kupferif [ "$SO_FLAG" = "y" -a "$build_ok" = y ]; then
26781fe69678Skupfer
2679b83ec4edSjmcp	echo "\n==== Generating skeleton closed binaries for" \
2680b83ec4edSjmcp	    "open-only build ====\n" | \
2681b83ec4edSjmcp	    tee -a $LOGFILE >> $mail_msg_file
26824e5b757fSkupfer
2683b83ec4edSjmcp	rm -rf $CODEMGR_WS/closed.skel
26844e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
2685b83ec4edSjmcp		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
2686b83ec4edSjmcp		    >>$LOGFILE 2>&1
2687cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
2688b83ec4edSjmcp			echo "Couldn't create skeleton DEBUG closed binaries." |
26891fe69678Skupfer			    tee -a $mail_msg_file >> $LOGFILE
26901fe69678Skupfer		fi
26914e5b757fSkupfer	fi
26924e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
26934e5b757fSkupfer		root=$ROOT
26944e5b757fSkupfer		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
2695b83ec4edSjmcp		mkclosed $MACH $root $CODEMGR_WS/closed.skel/root_$MACH-nd \
26964e5b757fSkupfer		    >>$LOGFILE 2>&1
2697cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
2698b83ec4edSjmcp			echo "Couldn't create skeleton non-DEBUG closed binaries." |
26994e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
27004e5b757fSkupfer		fi
27014e5b757fSkupfer	fi
27024e5b757fSkupfer
2703b83ec4edSjmcp	SRC=$OPEN_SRCDIR/usr/src
2704b83ec4edSjmcp	# Try not to clobber any user-provided closed binaries.
2705b83ec4edSjmcp	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
27064e5b757fSkupfer	export CLOSED_IS_PRESENT=no
27071fe69678Skupferfi
27081fe69678Skupfer
27091fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
27104e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
27114e5b757fSkupfer	rm -rf `allprotos`
27127c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
27134e5b757fSkupfer		set_non_debug_build_flags
2714b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
27151fe69678Skupfer		#
27161fe69678Skupfer		# SRC was set earlier to point to the source build
27171fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
27181fe69678Skupfer		#
27191fe69678Skupfer		TOOLS=${SRC}/tools
2720b06f2c55SMark J. Nelson		TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
2721b06f2c55SMark J. Nelson		build_tools ${TOOLS_PROTO}
2722b06f2c55SMark J. Nelson		if [[ $? != 0 ]]; then
2723b06f2c55SMark J. Nelson			use_tools ${TOOLS_PROTO}
2724b06f2c55SMark J. Nelson		fi
27257c478bd9Sstevel@tonic-gate	fi
27267c478bd9Sstevel@tonic-gate
27277c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
27287c478bd9Sstevel@tonic-gate	normal_build
27297c478bd9Sstevel@tonic-gatefi
27307c478bd9Sstevel@tonic-gate
27311fe69678Skupferif [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
27321fe69678Skupfer	rm -rf $ON_CLOSED_BINS
27331fe69678Skupferfi
27341fe69678Skupfer
27354e5b757fSkupfer#
27364e5b757fSkupfer# There are several checks that need to look at the proto area, but
27374e5b757fSkupfer# they only need to look at one, and they don't care whether it's
27384e5b757fSkupfer# DEBUG or non-DEBUG.
27394e5b757fSkupfer#
27404e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
27414e5b757fSkupfer	checkroot=$ROOT-nd
27424e5b757fSkupferelse
27434e5b757fSkupfer	checkroot=$ROOT
27444e5b757fSkupferfi
27454e5b757fSkupfer
27467c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
27477c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
27487c478bd9Sstevel@tonic-gate		>> $LOGFILE
27494e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
27507c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
27517c478bd9Sstevel@tonic-gate		>> $LOGFILE
27527c478bd9Sstevel@tonic-gate
27537c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
27547c478bd9Sstevel@tonic-gate
2755ead1f93eSLiane Praza		E1=
2756ead1f93eSLiane Praza		f1=
2757ead1f93eSLiane Praza		if [ -d "$SRC/pkgdefs" ]; then
2758ead1f93eSLiane Praza			f1="$SRC/pkgdefs/etc/exception_list_$MACH"
2759ead1f93eSLiane Praza			if [ "$X_FLAG" = "y" ]; then
2760ead1f93eSLiane Praza				f1="$f1 $IA32_IHV_WS/usr/src/pkgdefs/etc/exception_list_$MACH"
27617c478bd9Sstevel@tonic-gate			fi
27626fec3625Sdduvall		fi
27637c478bd9Sstevel@tonic-gate
2764ead1f93eSLiane Praza		for f in $f1; do
2765ead1f93eSLiane Praza			if [ -f "$f" ]; then
2766ead1f93eSLiane Praza				E1="$E1 -e $f"
2767ead1f93eSLiane Praza			fi
2768ead1f93eSLiane Praza		done
2769ead1f93eSLiane Praza
2770ead1f93eSLiane Praza		E2=
2771ead1f93eSLiane Praza		f2=
2772ead1f93eSLiane Praza		if [ -d "$SRC/pkg" ]; then
2773ead1f93eSLiane Praza			f2="$f2 exceptions/packaging"
2774ead1f93eSLiane Praza		fi
2775ead1f93eSLiane Praza
2776ead1f93eSLiane Praza		for f in $f2; do
2777ead1f93eSLiane Praza			if [ -f "$f" ]; then
2778ead1f93eSLiane Praza				E2="$E2 -e $f"
2779ead1f93eSLiane Praza			fi
2780ead1f93eSLiane Praza		done
2781ead1f93eSLiane Praza
27827c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
2783ead1f93eSLiane Praza			#
2784b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
2785b4add148Sdduvall			# IHV proto list to the reference list if the reference
2786b4add148Sdduvall			# was built without -X.
2787b4add148Sdduvall			#
2788b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
2789b4add148Sdduvall			# IHV proto list to the build's proto list if the
2790b4add148Sdduvall			# reference was built with -X.
2791b4add148Sdduvall			#
2792b4add148Sdduvall			# Use the presence of the first file entry of the cached
2793b4add148Sdduvall			# IHV proto list in the reference list to determine
2794ead1f93eSLiane Praza			# whether it was built with -X or not.
2795ead1f93eSLiane Praza			#
2796a51a9b36SMark J. Nelson			IHV_REF_PROTO_LIST=$SRC/pkg/proto_list_ihv_$MACH
2797b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2798b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
2799b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
2800b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
2801b4add148Sdduvall					grep -w "$grepfor" \
2802b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2803b4add148Sdduvall					if [ ! "$?" = "0" ]; then
2804b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2805b4add148Sdduvall					fi
2806b4add148Sdduvall				else
2807b4add148Sdduvall					grep -w "$grepfor" \
2808b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2809b4add148Sdduvall					if [ "$?" = "0" ]; then
2810b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2811b4add148Sdduvall					fi
2812b4add148Sdduvall				fi
2813b4add148Sdduvall			fi
2814ead1f93eSLiane Praza		fi
2815ead1f93eSLiane Praza	fi
2816b4add148Sdduvall
281787916a32SMark J. Nelson	if [ "$N_FLAG" != "y" -a -f $SRC/pkgdefs/Makefile ]; then
2818ead1f93eSLiane Praza		echo "\n==== Impact on SVr4 packages ====\n" >> $mail_msg_file
2819ead1f93eSLiane Praza		#
2820ead1f93eSLiane Praza		# Compare the build's proto list with current package
2821ead1f93eSLiane Praza		# definitions to audit the quality of package
2822ead1f93eSLiane Praza		# definitions and makefile install targets. Use the
2823ead1f93eSLiane Praza		# current exception list.
2824ead1f93eSLiane Praza		#
2825ead1f93eSLiane Praza		PKGDEFS_LIST=""
2826ead1f93eSLiane Praza		for d in $abssrcdirs; do
2827ead1f93eSLiane Praza			if [ -d $d/pkgdefs ]; then
2828ead1f93eSLiane Praza				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2829ead1f93eSLiane Praza			fi
2830ead1f93eSLiane Praza		done
2831ead1f93eSLiane Praza		if [ "$X_FLAG" = "y" -a \
2832ead1f93eSLiane Praza		    -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
2833ead1f93eSLiane Praza			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
2834ead1f93eSLiane Praza		fi
2835ead1f93eSLiane Praza		$PROTOCMPTERSE \
2836ead1f93eSLiane Praza		    "Files missing from the proto area:" \
2837ead1f93eSLiane Praza		    "Files missing from packages:" \
2838ead1f93eSLiane Praza		    "Inconsistencies between pkgdefs and proto area:" \
2839ead1f93eSLiane Praza		    ${E1} \
2840ead1f93eSLiane Praza		    ${PKGDEFS_LIST} \
2841ead1f93eSLiane Praza		    $ATLOG/proto_list_${MACH} \
2842ead1f93eSLiane Praza		    >> $mail_msg_file
2843ead1f93eSLiane Praza	fi
2844ead1f93eSLiane Praza
2845ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
2846ead1f93eSLiane Praza		echo "\n==== Validating manifests against proto area ====\n" \
2847ead1f93eSLiane Praza		    >> $mail_msg_file
2848ead1f93eSLiane Praza		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) \
2849ead1f93eSLiane Praza		    >> $mail_msg_file
2850ead1f93eSLiane Praza
2851ead1f93eSLiane Praza	fi
2852ead1f93eSLiane Praza
2853ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
2854ead1f93eSLiane Praza		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
2855ead1f93eSLiane Praza		if [ -n "$E2" ]; then
2856ead1f93eSLiane Praza			ELIST=$E2
2857ead1f93eSLiane Praza		else
2858ead1f93eSLiane Praza			ELIST=$E1
2859ead1f93eSLiane Praza		fi
28607c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
28617c478bd9Sstevel@tonic-gate			"Files in yesterday's proto area, but not today's:" \
28627c478bd9Sstevel@tonic-gate			"Files in today's proto area, but not yesterday's:" \
28637c478bd9Sstevel@tonic-gate			"Files that changed between yesterday and today:" \
28647c478bd9Sstevel@tonic-gate			${ELIST} \
28657c478bd9Sstevel@tonic-gate			-d $REF_PROTO_LIST \
2866b4add148Sdduvall			$REF_IHV_PROTO \
28677c478bd9Sstevel@tonic-gate			$ATLOG/proto_list_${MACH} \
2868b4add148Sdduvall			$IHV_PROTO_LIST \
28697c478bd9Sstevel@tonic-gate			>> $mail_msg_file
28707c478bd9Sstevel@tonic-gate	fi
28717c478bd9Sstevel@tonic-gatefi
28727c478bd9Sstevel@tonic-gate
28737c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
28747c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
28757c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
28767c478bd9Sstevel@tonic-gatefi
28777c478bd9Sstevel@tonic-gate
28787c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
28797c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
28807c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
28817c478bd9Sstevel@tonic-gate# the variable now.
28827c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
28837c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
28847c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
2885ead1f93eSLiane Praza	rm -rf $NIGHTLY_PARENT_ROOT/*
28867c478bd9Sstevel@tonic-gate	unset Ulockfile
28877c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
28884e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2889ead1f93eSLiane Praza		( cd $ROOT; tar cf - . |
28904e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
28917c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
28927c478bd9Sstevel@tonic-gate	fi
28934e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2894ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
28954e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
28964e5b757fSkupfer		cd $ROOT-nd
28974e5b757fSkupfer		( tar cf - . |
28984e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
28994e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
29004e5b757fSkupfer	fi
29016798c3f0SMark J. Nelson	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
2902ead1f93eSLiane Praza		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
2903ead1f93eSLiane Praza		    tee -a $LOGFILE >> $mail_msg_file
2904ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
2905ead1f93eSLiane Praza		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
2906ead1f93eSLiane Praza		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2907ead1f93eSLiane Praza			( cd $TOOLS_PROTO; tar cf - . |
29086798c3f0SMark J. Nelson			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
29096798c3f0SMark J. Nelson			    umask 0; tar xpf - ) ) 2>&1 |
2910ead1f93eSLiane Praza			    tee -a $mail_msg_file >> $LOGFILE
2911ead1f93eSLiane Praza		fi
29124e5b757fSkupfer	fi
29136798c3f0SMark J. Nelsonfi
29147c478bd9Sstevel@tonic-gate
29157c478bd9Sstevel@tonic-gate#
291675ce41a5SAli Bahrami# ELF verification: ABI (-A) and runtime (-r) checks
29177c478bd9Sstevel@tonic-gate#
291875ce41a5SAli Bahramiif [[ ($build_ok = y) && ( ($A_FLAG = y) || ($r_FLAG = y) ) ]]; then
291975ce41a5SAli Bahrami	# Directory ELF-data.$MACH holds the files produced by these tests.
292075ce41a5SAli Bahrami	elf_ddir=$SRC/ELF-data.$MACH
29217c478bd9Sstevel@tonic-gate
292275ce41a5SAli Bahrami	# If there is a previous ELF-data backup directory, remove it. Then,
292375ce41a5SAli Bahrami	# rotate current ELF-data directory into its place and create a new
292475ce41a5SAli Bahrami	# empty directory
292575ce41a5SAli Bahrami	rm -rf $elf_ddir.ref
292675ce41a5SAli Bahrami	if [[ -d $elf_ddir ]]; then
292775ce41a5SAli Bahrami		mv $elf_ddir $elf_ddir.ref
292875ce41a5SAli Bahrami	fi
292975ce41a5SAli Bahrami	mkdir -p $elf_ddir
293075ce41a5SAli Bahrami
293175ce41a5SAli Bahrami	# Call find_elf to produce a list of the ELF objects in the proto area.
293275ce41a5SAli Bahrami	# This list is passed to check_rtime and interface_check, preventing
293375ce41a5SAli Bahrami	# them from separately calling find_elf to do the same work twice.
293475ce41a5SAli Bahrami	find_elf -fr $checkroot > $elf_ddir/object_list
293575ce41a5SAli Bahrami
293675ce41a5SAli Bahrami	if [[ $A_FLAG = y ]]; then
29377c478bd9Sstevel@tonic-gate	       	echo "\n==== Check versioning and ABI information ====\n"  | \
29387c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
29397c478bd9Sstevel@tonic-gate
294075ce41a5SAli Bahrami		# Produce interface description for the proto. Report errors.
294175ce41a5SAli Bahrami		interface_check -o -w $elf_ddir -f object_list \
294275ce41a5SAli Bahrami			-i interface -E interface.err
294375ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.err ]]; then
294475ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.err \
294575ce41a5SAli Bahrami				>> $mail_msg_file
29467c478bd9Sstevel@tonic-gate		fi
29477c478bd9Sstevel@tonic-gate
29485253169eSAli Bahrami		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
29495253169eSAli Bahrami		# description file to that from the baseline gate. Issue a
29505253169eSAli Bahrami		# warning if the baseline is not present, and keep going.
29515253169eSAli Bahrami		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
29525253169eSAli Bahrami			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
29537c478bd9Sstevel@tonic-gate
29545253169eSAli Bahrami		       	echo "\n==== Compare versioning and ABI information" \
2955e599109eSAli Bahrami			    "to baseline ====\n"  | \
29565253169eSAli Bahrami			    tee -a $LOGFILE >> $mail_msg_file
2957e599109eSAli Bahrami		       	echo "Baseline:  $base_ifile\n" >> $LOGFILE
29585253169eSAli Bahrami
29595253169eSAli Bahrami			if [[ -f $base_ifile ]]; then
29605253169eSAli Bahrami				interface_cmp -d -o $base_ifile \
296175ce41a5SAli Bahrami				    $elf_ddir/interface > $elf_ddir/interface.cmp
296275ce41a5SAli Bahrami				if [[ -s $elf_ddir/interface.cmp ]]; then
29635253169eSAli Bahrami					echo | tee -a $LOGFILE >> $mail_msg_file
29645253169eSAli Bahrami					tee -a $LOGFILE < \
29655253169eSAli Bahrami					    $elf_ddir/interface.cmp \
296675ce41a5SAli Bahrami					    >> $mail_msg_file
29677c478bd9Sstevel@tonic-gate				fi
29685253169eSAli Bahrami			else
29695253169eSAli Bahrami			       	echo "baseline not available. comparison" \
29705253169eSAli Bahrami                                    "skipped" | \
29715253169eSAli Bahrami				    tee -a $LOGFILE >> $mail_msg_file
29725253169eSAli Bahrami			fi
29735253169eSAli Bahrami
29745253169eSAli Bahrami		fi
29757c478bd9Sstevel@tonic-gate	fi
29767c478bd9Sstevel@tonic-gate
297775ce41a5SAli Bahrami	if [[ $r_FLAG = y ]]; then
29787c478bd9Sstevel@tonic-gate		echo "\n==== Check ELF runtime attributes ====\n" | \
29797c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
29807c478bd9Sstevel@tonic-gate
2981ead1f93eSLiane Praza		# If we're doing a DEBUG build the proto area will be left
298275ce41a5SAli Bahrami		# with debuggable objects, thus don't assert -s.
298375ce41a5SAli Bahrami		if [[ $D_FLAG = y ]]; then
29847c478bd9Sstevel@tonic-gate			rtime_sflag=""
29857c478bd9Sstevel@tonic-gate		else
29867c478bd9Sstevel@tonic-gate			rtime_sflag="-s"
29877c478bd9Sstevel@tonic-gate		fi
298875ce41a5SAli Bahrami		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
298975ce41a5SAli Bahrami			-D object_list  -f object_list -E runtime.err \
2990622090e3SAli Bahrami			-I runtime.attr.raw
2991622090e3SAli Bahrami
2992622090e3SAli Bahrami		# check_rtime -I output needs to be sorted in order to
2993622090e3SAli Bahrami		# compare it to that from previous builds.
2994622090e3SAli Bahrami		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
2995622090e3SAli Bahrami		rm $elf_ddir/runtime.attr.raw
29967c478bd9Sstevel@tonic-gate
299775ce41a5SAli Bahrami		# Report errors
299875ce41a5SAli Bahrami		if [[ -s $elf_ddir/runtime.err ]]; then
299975ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/runtime.err \
30007c478bd9Sstevel@tonic-gate				>> $mail_msg_file
300175ce41a5SAli Bahrami		fi
30027c478bd9Sstevel@tonic-gate
300375ce41a5SAli Bahrami		# If there is an ELF-data directory from a previous build,
300475ce41a5SAli Bahrami		# then diff the attr files. These files contain information
300575ce41a5SAli Bahrami		# about dependencies, versioning, and runpaths. There is some
300675ce41a5SAli Bahrami		# overlap with the ABI checking done above, but this also
300775ce41a5SAli Bahrami		# flushes out non-ABI interface differences along with the
300875ce41a5SAli Bahrami		# other information.
300975ce41a5SAli Bahrami		echo "\n==== Diff ELF runtime attributes" \
301075ce41a5SAli Bahrami		    "(since last build) ====\n" | \
301175ce41a5SAli Bahrami		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
301275ce41a5SAli Bahrami
301375ce41a5SAli Bahrami		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
301475ce41a5SAli Bahrami			diff $elf_ddir.ref/runtime.attr \
301575ce41a5SAli Bahrami				$elf_ddir/runtime.attr \
301675ce41a5SAli Bahrami				>> $mail_msg_file
301775ce41a5SAli Bahrami		fi
301875ce41a5SAli Bahrami	fi
30195253169eSAli Bahrami
30205253169eSAli Bahrami	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
30215253169eSAli Bahrami	if [[ "$u_FLAG" = "y" ]]; then
30225253169eSAli Bahrami		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
30235253169eSAli Bahrami
30245253169eSAli Bahrami		# If parent lacks the ELF-data.$MACH directory, create it
30255253169eSAli Bahrami		if [[ ! -d $p_elf_ddir ]]; then
30265253169eSAli Bahrami			staffer mkdir -p $p_elf_ddir
30275253169eSAli Bahrami		fi
30285253169eSAli Bahrami
30295253169eSAli Bahrami		# These files are used asynchronously by other builds for ABI
30305253169eSAli Bahrami		# verification, as above for the -A option. As such, we require
30315253169eSAli Bahrami		# the file replacement to be atomic. Copy the data to a temp
30325253169eSAli Bahrami		# file in the same filesystem and then rename into place.
30335253169eSAli Bahrami		(
30345253169eSAli Bahrami			cd $elf_ddir
30355253169eSAli Bahrami			for elf_dfile in *; do
30365253169eSAli Bahrami				staffer cp $elf_dfile \
30375253169eSAli Bahrami				    ${p_elf_ddir}/${elf_dfile}.new
30385253169eSAli Bahrami				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
30395253169eSAli Bahrami				    ${p_elf_ddir}/${elf_dfile}
30405253169eSAli Bahrami			done
30415253169eSAli Bahrami		)
30425253169eSAli Bahrami	fi
30437c478bd9Sstevel@tonic-gatefi
30447c478bd9Sstevel@tonic-gate
30457c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
30467c478bd9Sstevel@tonic-gate
30477c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
30487c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
30497c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
30507c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
30517c478bd9Sstevel@tonic-gate	fi
30527c478bd9Sstevel@tonic-gate	set $LINTDIRS
30537c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
30547c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
30557c478bd9Sstevel@tonic-gate	done
30567c478bd9Sstevel@tonic-gateelse
30577c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
30587c478bd9Sstevel@tonic-gatefi
30597c478bd9Sstevel@tonic-gate
30607c478bd9Sstevel@tonic-gate# "make check" begins
30617c478bd9Sstevel@tonic-gate
30627c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
30637c478bd9Sstevel@tonic-gate	# remove old check.out
30647c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
30657c478bd9Sstevel@tonic-gate
30667c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
30677c478bd9Sstevel@tonic-gate	cd $SRC
3068170832d3SAlbert Lee	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
3069170832d3SAlbert Lee	    >> $LOGFILE
30707c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
30717c478bd9Sstevel@tonic-gate
30727c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
30737c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
30747c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
30757c478bd9Sstevel@tonic-gateelse
30767c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
30777c478bd9Sstevel@tonic-gatefi
30787c478bd9Sstevel@tonic-gate
30797c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
30807c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
30817c478bd9Sstevel@tonic-gate
3082fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
30837c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
30847c478bd9Sstevel@tonic-gate
30857c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
30867c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
30877c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
30887c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
30897c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
30907c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
30917c478bd9Sstevel@tonic-gate	fi
30927c478bd9Sstevel@tonic-gate
30939730304dSmeem	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
3094cdf0c1d5Smjnelson	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
30959730304dSmeem	    sort > $SRC/unref-${MACH}.out
30967c478bd9Sstevel@tonic-gate
30977c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
30987c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
30997c478bd9Sstevel@tonic-gate	fi
31007c478bd9Sstevel@tonic-gate
31017c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
31027c478bd9Sstevel@tonic-gatefi
31037c478bd9Sstevel@tonic-gate
31045d715dd7Skupfer#
31055d715dd7Skupfer# Generate the OpenSolaris deliverables if requested.  Some of these
31065d715dd7Skupfer# steps need to come after findunref and are commented below.
31075d715dd7Skupfer#
3108597bd30bSMike Kupfer
3109b83ec4edSjmcp# If we are doing an OpenSolaris _source_ build (-S O) then we do
3110b83ec4edSjmcp# not have usr/closed available to us to generate closedbins from,
3111b83ec4edSjmcp# so skip this part.
3112b83ec4edSjmcpif [ "$SO_FLAG" = n -a "$O_FLAG" = y -a "$build_ok" = y ]; then
31135d715dd7Skupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
31145d715dd7Skupfer	    tee -a $mail_msg_file >> $LOGFILE
31155d715dd7Skupfer
31165d715dd7Skupfer	cd $CODEMGR_WS
31175d715dd7Skupfer
31185d715dd7Skupfer	#
3119ead1f93eSLiane Praza	# This step grovels through the package manifests, so it
31205d715dd7Skupfer	# must come after findunref.
31215d715dd7Skupfer	#
3122ead1f93eSLiane Praza	# We assume no DEBUG vs non-DEBUG package content variation
3123ead1f93eSLiane Praza	# here; if that changes, then the "make all" in $SRC/pkg will
3124ead1f93eSLiane Praza	# need to be moved into the conditionals and repeated for each
3125ead1f93eSLiane Praza	# different build.
3126ead1f93eSLiane Praza	#
31275d715dd7Skupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
31285d715dd7Skupfer	closed_basename=on-closed-bins
31295d715dd7Skupfer	if [ "$D_FLAG" = y ]; then
3130b83ec4edSjmcp		bindrop "$closed_basename" >>"$LOGFILE" 2>&1
3131cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
31325d715dd7Skupfer			echo "Couldn't create DEBUG closed binaries." |
31335d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
3134c7453724SMike Kupfer			build_ok=n
31355d715dd7Skupfer		fi
31365d715dd7Skupfer	fi
31375d715dd7Skupfer	if [ "$F_FLAG" = n ]; then
3138b83ec4edSjmcp		bindrop -n "$closed_basename-nd" >>"$LOGFILE" 2>&1
3139cdf0c1d5Smjnelson		if (( $? != 0 )) ; then
31405d715dd7Skupfer			echo "Couldn't create non-DEBUG closed binaries." |
31415d715dd7Skupfer			    tee -a $mail_msg_file >> $LOGFILE
3142c7453724SMike Kupfer			build_ok=n
31435d715dd7Skupfer		fi
31445d715dd7Skupfer	fi
31455d715dd7Skupfer
31465d715dd7Skupfer	echo "Generating README.opensolaris..." >> $LOGFILE
31475d715dd7Skupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
31485d715dd7Skupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
3149cdf0c1d5Smjnelson	if (( $? != 0 )) ; then
31505d715dd7Skupfer		echo "Couldn't create README.opensolaris." |
31515d715dd7Skupfer		    tee -a $mail_msg_file >> $LOGFILE
3152c7453724SMike Kupfer		build_ok=n
31535d715dd7Skupfer	fi
31545d715dd7Skupferfi
31555d715dd7Skupfer
31567c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
31577c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
31587c478bd9Sstevel@tonic-gate# then don't check the proto area.
31597c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
31607c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
31617c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
31627c478bd9Sstevel@tonic-gate		>>$mail_msg_file
31637c478bd9Sstevel@tonic-gate	arg=-b
31647c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
31654e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
31667c478bd9Sstevel@tonic-gatefi
31677c478bd9Sstevel@tonic-gate
31687c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
31697c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
31707c478bd9Sstevel@tonic-gate		>> $mail_msg_file
3171ead1f93eSLiane Praza
3172ead1f93eSLiane Praza	abspkgdefs=
3173ead1f93eSLiane Praza	abspkg=
3174ead1f93eSLiane Praza	for d in $abssrcdirs; do
3175ead1f93eSLiane Praza		if [ -d "$d/pkgdefs" ]; then
3176ead1f93eSLiane Praza			abspkgdefs="$abspkgdefs $d"
31777c478bd9Sstevel@tonic-gate		fi
3178ead1f93eSLiane Praza		if [ -d "$d/pkg" ]; then
3179ead1f93eSLiane Praza			abspkg="$abspkg $d"
3180ead1f93eSLiane Praza		fi
3181ead1f93eSLiane Praza	done
3182ead1f93eSLiane Praza
3183ead1f93eSLiane Praza	if [ -n "$abspkgdefs" ]; then
3184ead1f93eSLiane Praza		pmodes -qvdP \
3185ead1f93eSLiane Praza		    `find $abspkgdefs -name pkginfo.tmpl -print -o \
3186ead1f93eSLiane Praza		    -name .del\* -prune | sed -e 's:/pkginfo.tmpl$::' | \
3187ead1f93eSLiane Praza		    sort -u` >> $mail_msg_file
3188ead1f93eSLiane Praza	fi
3189ead1f93eSLiane Praza
3190ead1f93eSLiane Praza	if [ -n "$abspkg" ]; then
3191ead1f93eSLiane Praza		for d in "$abspkg"; do
3192ead1f93eSLiane Praza			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
3193ead1f93eSLiane Praza		done
3194ead1f93eSLiane Praza	fi
31957c478bd9Sstevel@tonic-gatefi
31967c478bd9Sstevel@tonic-gate
319796ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
31984e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
31994e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
32004e5b757fSkupfer	fi
320196ccc8cbSesaxe
32024e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
32034e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
320496ccc8cbSesaxe	fi
320596ccc8cbSesaxefi
320696ccc8cbSesaxe
32077c478bd9Sstevel@tonic-gateEND_DATE=`date`
32087c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
32097c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
32107c478bd9Sstevel@tonic-gate
3211c341b28aSDarren Moffattypeset -i10 hours
32127c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
32137c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
32147c478bd9Sstevel@tonic-gate
32157c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
32167c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
32177c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
32187c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
32197c478bd9Sstevel@tonic-gate
32207c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
32217c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
32227c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
32237c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
32247c478bd9Sstevel@tonic-gate
32257c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
32267c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
32277c478bd9Sstevel@tonic-gate
32287c478bd9Sstevel@tonic-gate	#
32297c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
32307c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
32317c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
32327c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
32337c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
32347c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
32357c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
32367c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
32377c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
32387c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
32397c478bd9Sstevel@tonic-gate	# which was already on the parent.
32407c478bd9Sstevel@tonic-gate	#
32417c478bd9Sstevel@tonic-gate
32427c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
32437c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
32447c478bd9Sstevel@tonic-gate	shift
32457c478bd9Sstevel@tonic-gate
32467c478bd9Sstevel@tonic-gate	for unreffile; do
32477c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
32487c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
32497c478bd9Sstevel@tonic-gate	done
32507c478bd9Sstevel@tonic-gate
32517c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
32527c478bd9Sstevel@tonic-gatefi
32537c478bd9Sstevel@tonic-gate
32547c478bd9Sstevel@tonic-gate#
32557c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
32567c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
32577c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
32587c478bd9Sstevel@tonic-gate#
32597c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
32607c478bd9Sstevel@tonic-gate	exit 0
32617c478bd9Sstevel@tonic-gatefi
32627c478bd9Sstevel@tonic-gateexit 1
3263