xref: /titanic_44/usr/src/tools/scripts/nightly.sh (revision 52a52aeb5a7fdcd4b40e137fa7498612f87d95f3)
17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6fb23a357Skupfer# Common Development and Distribution License (the "License").
7fb23a357Skupfer# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
224e5b757fSkupfer
237c478bd9Sstevel@tonic-gate#
246c3c9007Sstevel# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
307c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
317c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
347c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
37d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
38d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
437c478bd9Sstevel@tonic-gate#
447c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
457c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
487c478bd9Sstevel@tonic-gate#
497c478bd9Sstevel@tonic-gate# -A flag in NIGHTLY_OPTIONS checks ABI diffs in .so files
507c478bd9Sstevel@tonic-gate# This option requires a couple of scripts.
517c478bd9Sstevel@tonic-gate#
527c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
537c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
547c478bd9Sstevel@tonic-gate#
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate#
577c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
587c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
597c478bd9Sstevel@tonic-gate#
607c478bd9Sstevel@tonic-gateunset CDPATH
617c478bd9Sstevel@tonic-gate
624e5b757fSkupfer#
634e5b757fSkupfer# Print the tag string used to identify a build (e.g., "DEBUG
644e5b757fSkupfer# open-only")
654e5b757fSkupfer# usage: tagstring debug-part open-part
664e5b757fSkupfer#
674e5b757fSkupfertagstring() {
684e5b757fSkupfer	debug_part=$1
694e5b757fSkupfer	open_part=$2
704e5b757fSkupfer
714e5b757fSkupfer	if [ -n "$open_part" ]; then
724e5b757fSkupfer		echo "$debug_part $open_part"
734e5b757fSkupfer	else
744e5b757fSkupfer		echo "$debug_part"
754e5b757fSkupfer	fi
764e5b757fSkupfer}
774e5b757fSkupfer
784e5b757fSkupfer#
794e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
807c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
817c478bd9Sstevel@tonic-gate# non-DEBUG packages.
824e5b757fSkupfer#
834e5b757fSkupfer# usage: normal_build [-O]
84*52a52aebSkupfer# -O	OpenSolaris delivery build.  Put the proto area and
85*52a52aebSkupfer#	(eventually) packages in -open directories.  Use skeleton
86*52a52aebSkupfer#	closed binaries.  Don't generate archives--that needs to be
87*52a52aebSkupfer#	done later, after we've generated the closed binaries.  Also
88*52a52aebSkupfer#	skip the package build (until 6414822 is fixed).
894e5b757fSkupfer#
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gatenormal_build() {
927c478bd9Sstevel@tonic-gate
93*52a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
94*52a52aebSkupfer	typeset orig_a_FLAG="$a_FLAG"
954e5b757fSkupfer
964e5b757fSkupfer	suffix=""
974e5b757fSkupfer	open_only=""
984e5b757fSkupfer	while getopts O FLAG $*; do
994e5b757fSkupfer		case $FLAG in
1004e5b757fSkupfer		O)
1014e5b757fSkupfer			suffix="-open"
1024e5b757fSkupfer			open_only="open-only"
1034e5b757fSkupfer			p_FLAG=n
104*52a52aebSkupfer			a_FLAG=n
1054e5b757fSkupfer			;;
1064e5b757fSkupfer		esac
1074e5b757fSkupfer	done
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
1124e5b757fSkupfer		set_non_debug_build_flags
1134e5b757fSkupfer		mytag=`tagstring "non-DEBUG" "$open_only"`
114*52a52aebSkupfer		build "$mytag" "$suffix-nd" "$MULTI_PROTO"
1154e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1164e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1177c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
1187c478bd9Sstevel@tonic-gate		fi
1197c478bd9Sstevel@tonic-gate	else
120*52a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1217c478bd9Sstevel@tonic-gate	fi
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	# DEBUG build begins
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
1284e5b757fSkupfer		set_debug_build_flags
1294e5b757fSkupfer		mytag=`tagstring "DEBUG" "$open_only"`
130*52a52aebSkupfer		build "$mytag" "$suffix" "$MULTI_PROTO"
1314e5b757fSkupfer		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a \
1324e5b757fSkupfer		    "$p_FLAG" = "y" ]; then
1337c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
1347c478bd9Sstevel@tonic-gate		fi
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate	else
137*52a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1387c478bd9Sstevel@tonic-gate	fi
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate	# DEBUG build ends
1414e5b757fSkupfer
142*52a52aebSkupfer	p_FLAG="$orig_p_FLAG"
143*52a52aebSkupfer	a_FLAG="$orig_a_FLAG"
1447c478bd9Sstevel@tonic-gate}
1457c478bd9Sstevel@tonic-gate
1461fe69678Skupfer#
1471fe69678Skupfer# usage: filelist DESTDIR PATTERN
1481fe69678Skupfer#
1497c478bd9Sstevel@tonic-gatefilelist() {
1507c478bd9Sstevel@tonic-gate	DEST=$1
1517c478bd9Sstevel@tonic-gate	PATTERN=$2
1527c478bd9Sstevel@tonic-gate	cd ${DEST}
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
1557c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
1567c478bd9Sstevel@tonic-gate		return;
1577c478bd9Sstevel@tonic-gate	fi
1581fe69678Skupfer	for i in `grep -v '^#' ${OBJFILES} | \
1597c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
1607c478bd9Sstevel@tonic-gate	do
1617c478bd9Sstevel@tonic-gate		# wildcard expansion
1627c478bd9Sstevel@tonic-gate		for j in $i
1637c478bd9Sstevel@tonic-gate		do
1647c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
1657c478bd9Sstevel@tonic-gate				echo $j
1667c478bd9Sstevel@tonic-gate			fi
1677c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
1687c478bd9Sstevel@tonic-gate				echo $j
1697c478bd9Sstevel@tonic-gate			fi
1707c478bd9Sstevel@tonic-gate		done
1717c478bd9Sstevel@tonic-gate	done | sort | uniq
1727c478bd9Sstevel@tonic-gate}
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
1757c478bd9Sstevel@tonic-gate# restoration
1767c478bd9Sstevel@tonic-gatesave_binaries() {
1777c478bd9Sstevel@tonic-gate	# save off list of binaries
1787c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
1797c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1807c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
1817c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
1827c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
1837c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
1847c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
1857c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
1867c478bd9Sstevel@tonic-gate}
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate# delete files
1891fe69678Skupfer# usage: hybridize_files DESTDIR MAKE_TARGET
1907c478bd9Sstevel@tonic-gatehybridize_files() {
1917c478bd9Sstevel@tonic-gate	DEST=$1
1927c478bd9Sstevel@tonic-gate	MAKETARG=$2
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
1957c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1967c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
1977c478bd9Sstevel@tonic-gate	do
1987c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
1997c478bd9Sstevel@tonic-gate		rm -rf "${i}"
2007c478bd9Sstevel@tonic-gate	done
2017c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
2027c478bd9Sstevel@tonic-gate	do
2037c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
2047c478bd9Sstevel@tonic-gate		rm -f ${i}+
2057c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
2067c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
2077c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
2087c478bd9Sstevel@tonic-gate	done
2097c478bd9Sstevel@tonic-gate}
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
2121fe69678Skupfer# usage: restore_binaries DESTDIR MAKE_TARGET
2137c478bd9Sstevel@tonic-gaterestore_binaries() {
2147c478bd9Sstevel@tonic-gate	DEST=$1
2157c478bd9Sstevel@tonic-gate	MAKETARG=$2
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
2187c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2197c478bd9Sstevel@tonic-gate	cd ${DEST}
2207c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
2217c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
2227c478bd9Sstevel@tonic-gate}
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate# rename files we save binaries of
2251fe69678Skupfer# usage: rename_files DESTDIR MAKE_TARGET
2267c478bd9Sstevel@tonic-gaterename_files() {
2277c478bd9Sstevel@tonic-gate	DEST=$1
2287c478bd9Sstevel@tonic-gate	MAKETARG=$2
2297c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
2307c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2317c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
2327c478bd9Sstevel@tonic-gate	do
2337c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
2347c478bd9Sstevel@tonic-gate		rm -f ${i}.export
2357c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
2367c478bd9Sstevel@tonic-gate	done
2377c478bd9Sstevel@tonic-gate}
2387c478bd9Sstevel@tonic-gate
2391fe69678Skupfer#
2401fe69678Skupfer# Copy some or all of the source tree.
2411fe69678Skupfer# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
2421fe69678Skupfer#
2431fe69678Skupfercopy_source() {
2447c478bd9Sstevel@tonic-gate	WS=$1
2457c478bd9Sstevel@tonic-gate	DEST=$2
2461fe69678Skupfer	label=$3
2471fe69678Skupfer	srcroot=$4
2487c478bd9Sstevel@tonic-gate
2491fe69678Skupfer	echo "\n==== Creating ${DEST} source from ${WS} ($label) ====\n" | \
2507c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate	echo "cleaning out ${DEST}." >> $LOGFILE
2537c478bd9Sstevel@tonic-gate	rm -rf "${DEST}" >> $LOGFILE 2>&1
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate	mkdir -p ${DEST}
2567c478bd9Sstevel@tonic-gate	cd ${WS}
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate	echo "creating ${DEST}." >> $LOGFILE
2591fe69678Skupfer	find $srcroot -name 's\.*' -a -type f -print | \
2607c478bd9Sstevel@tonic-gate	    sed -e 's,SCCS\/s.,,' | \
2617c478bd9Sstevel@tonic-gate	    grep -v '/\.del-*' | \
2627c478bd9Sstevel@tonic-gate	    cpio -pd ${DEST} >>$LOGFILE 2>&1
2631fe69678Skupfer}
2647c478bd9Sstevel@tonic-gate
2651fe69678Skupfer#
2661fe69678Skupfer# function to create (but not build) the export/crypt source tree.
2671fe69678Skupfer# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
2681fe69678Skupfer# Sets SRC to the modified source tree, for use by the caller when it
2691fe69678Skupfer# builds the tree.
2701fe69678Skupfer#
2711fe69678Skupferset_up_source_build() {
2721fe69678Skupfer	WS=$1
2731fe69678Skupfer	DEST=$2
2741fe69678Skupfer	MAKETARG=$3
2751fe69678Skupfer
2761fe69678Skupfer	copy_source $WS $DEST $MAKETARG usr
2777c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate	cd $SRC
2807c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
2817c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
2827c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
2837c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
2847c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
2857c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
2867c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
2877c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
2887c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
2917c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate	cd ${DEST}
2947c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
2957c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
2967c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
2977c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
2987c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
2997c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
3007c478bd9Sstevel@tonic-gate		do
3017c478bd9Sstevel@tonic-gate			# make sure the files exist
3027c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
3037c478bd9Sstevel@tonic-gate				continue
3047c478bd9Sstevel@tonic-gate			fi
3057c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
3067c478bd9Sstevel@tonic-gate				continue
3077c478bd9Sstevel@tonic-gate			fi
3087c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
3097c478bd9Sstevel@tonic-gate		done
3107c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
3117c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
3127c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
3137c478bd9Sstevel@tonic-gate	fi
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
3167c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
3177c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
3187c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
3197c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
3207c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
3217c478bd9Sstevel@tonic-gate		fi
3227c478bd9Sstevel@tonic-gate	fi
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate	# save the cleartext
3257c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
3267c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
3277c478bd9Sstevel@tonic-gate	cd ${DEST}
3287c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
329fb23a357Skupfer	find usr -depth -print | \
3307c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
3317c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
3327c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
3337c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
3347c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
3357c478bd9Sstevel@tonic-gate	fi
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
3387c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
3397c478bd9Sstevel@tonic-gate	fi
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate}
3427c478bd9Sstevel@tonic-gate
3434e5b757fSkupfer# Return library search directive as function of given root.
3444e5b757fSkupfermyldlibs() {
3454e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
3464e5b757fSkupfer}
3477c478bd9Sstevel@tonic-gate
3484e5b757fSkupfer# Return header search directive as function of given root.
3494e5b757fSkupfermyheaders() {
3504e5b757fSkupfer	echo "-I$1/usr/include"
3514e5b757fSkupfer}
3524e5b757fSkupfer
3534e5b757fSkupfer#
354*52a52aebSkupfer# Wrapper over commands that generate BFU archives.  The entire
355*52a52aebSkupfer# command output gets written to LOGFILE, and any unexpected messages
356*52a52aebSkupfer# are written to the mail message.  Returns with the status of the
357*52a52aebSkupfer# original command.
358*52a52aebSkupfer#
359*52a52aebSkupfermakebfu_filt() {
360*52a52aebSkupfer	typeset tmplog
361*52a52aebSkupfer	typeset errors
362*52a52aebSkupfer	typeset cmd
363*52a52aebSkupfer	integer cmd_stat
364*52a52aebSkupfer
365*52a52aebSkupfer	cmd="$1"
366*52a52aebSkupfer	shift
367*52a52aebSkupfer	tmplog="$TMPDIR/$cmd.out"
368*52a52aebSkupfer	errors="$TMPDIR/$cmd-errors"
369*52a52aebSkupfer	$cmd $* > "$tmplog" 2>&1
370*52a52aebSkupfer	cmd_stat=$?
371*52a52aebSkupfer	cat "$tmplog" >> "$LOGFILE"
372*52a52aebSkupfer	grep -v "^Creating .* archive:" "$tmplog" | grep -v "^Making" | \
373*52a52aebSkupfer	    grep -v "^$" | sort -u > "$errors"
374*52a52aebSkupfer	if [[ -s "$errors" ]]; then
375*52a52aebSkupfer		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
376*52a52aebSkupfer		    >> "$mail_msg_file"
377*52a52aebSkupfer		cat "$errors" >> "$mail_msg_file"
378*52a52aebSkupfer	fi
379*52a52aebSkupfer	rm -f "$tmplog" "$errors"
380*52a52aebSkupfer	return $cmd_stat
381*52a52aebSkupfer}
382*52a52aebSkupfer
383*52a52aebSkupfer#
3844e5b757fSkupfer# Function to do the build, including cpio archive and package generation.
3854e5b757fSkupfer# usage: build LABEL SUFFIX MULTIPROTO
3864e5b757fSkupfer# - LABEL is used to tag build output.
3874e5b757fSkupfer# - SUFFIX is used to distinguish files (e.g., debug vs non-debug).
3884e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
3894e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
3904e5b757fSkupfer#
3917c478bd9Sstevel@tonic-gatebuild() {
3927c478bd9Sstevel@tonic-gate	LABEL=$1
3937c478bd9Sstevel@tonic-gate	SUFFIX=$2
3944e5b757fSkupfer	MULTIPROTO=$3
3957c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
3967c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
3977c478bd9Sstevel@tonic-gate	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
3987c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
399d8fd4470Sjg	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
400d8fd4470Sjg		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
401d8fd4470Sjg	fi
4027c478bd9Sstevel@tonic-gate
4034e5b757fSkupfer	ORIGROOT=$ROOT
4044e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
4054e5b757fSkupfer
4064e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
4074e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
4084e5b757fSkupfer
4097c478bd9Sstevel@tonic-gate	this_build_ok=y
4107c478bd9Sstevel@tonic-gate	#
4117c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
4127c478bd9Sstevel@tonic-gate	#
4137c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
4147c478bd9Sstevel@tonic-gate		>> $LOGFILE
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
4177c478bd9Sstevel@tonic-gate	cd $SRC
4187c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
4197c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
42032f1e47bSsommerfe
42132f1e47bSsommerfe	echo "\n==== SCCS Noise ($LABEL) ====\n" >> $mail_msg_file
42232f1e47bSsommerfe
42332f1e47bSsommerfe	egrep 'sccs(check|  get)' $SRC/${INSTALLOG}.out >> $mail_msg_file
42432f1e47bSsommerfe
4257c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
4267c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
4277c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
4287c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
4297c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
4307c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
4317c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
4327c478bd9Sstevel@tonic-gate		build_ok=n
4337c478bd9Sstevel@tonic-gate		this_build_ok=n
4347c478bd9Sstevel@tonic-gate	fi
4357c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
4367c478bd9Sstevel@tonic-gate		>> $mail_msg_file
4377c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
4387c478bd9Sstevel@tonic-gate		build_ok=n
4397c478bd9Sstevel@tonic-gate		this_build_ok=n
4407c478bd9Sstevel@tonic-gate	fi
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
4437c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
4447c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
4457c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
4467c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
4477c478bd9Sstevel@tonic-gate		        | egrep -v "parameter <PSTAMP> set to" \
4487c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
4497c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
4507c478bd9Sstevel@tonic-gate			>> $mail_msg_file
4517c478bd9Sstevel@tonic-gate	fi
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
4547c478bd9Sstevel@tonic-gate		>> $LOGFILE
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
4577c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
4607c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
4617c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
4627c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
4637c478bd9Sstevel@tonic-gate		fi
4647c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
4657c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
4667c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
4677c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
4687c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
4697c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
4707c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
4717c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
4727c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
4737c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
4747c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
4757c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
4767c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
4777c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
4787c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
4797c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
4807c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
4817c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
4827c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
4837c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
4847c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
4857c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
4867c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
4877c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
4887c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
4897c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
4907c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
4917c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
4927c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
4937c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
4947c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
4957c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
4967c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
4977c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
4987c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
4997c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
5007c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
5017c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
5027c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
5037c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
5047c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
5057c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
5067c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
5077c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
5087c478bd9Sstevel@tonic-gate			| egrep -v '::' \
5097c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
510010b217aSwesolows			| egrep -v '^\+' \
51103eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
512c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
5137c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
5147c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
5157c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
5167c478bd9Sstevel@tonic-gate		fi
5177c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
5187c478bd9Sstevel@tonic-gate			>>$mail_msg_file
5197c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
5207c478bd9Sstevel@tonic-gate	fi
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate	#
52323259b79Srotondo	#	Re-sign selected binaries using signing server
52423259b79Srotondo	#	(gatekeeper builds only)
52523259b79Srotondo	#
5262210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
52723259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
52823259b79Srotondo		signing_file="${TMPDIR}/signing"
52923259b79Srotondo		rm -f ${signing_file}
53023259b79Srotondo		export CODESIGN_USER
53123259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
53223259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
53323259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
53423259b79Srotondo		    >> $LOGFILE
53523259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
53623259b79Srotondo		    >> $mail_msg_file
53723259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
5382210853dSjohnz		if [ $? = 0 ]; then
5392210853dSjohnz			build_ok=n
5402210853dSjohnz			this_build_ok=n
5412210853dSjohnz		fi
54223259b79Srotondo	fi
54323259b79Srotondo
54423259b79Srotondo	#
5457c478bd9Sstevel@tonic-gate	#	Create cpio archives for preintegration testing (PIT)
5467c478bd9Sstevel@tonic-gate	#
5477c478bd9Sstevel@tonic-gate	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
5487c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
5497c478bd9Sstevel@tonic-gate			>> $LOGFILE
550*52a52aebSkupfer		makebfu_filt makebfu
5517c478bd9Sstevel@tonic-gate		# hack for test folks
5527c478bd9Sstevel@tonic-gate		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
5537c478bd9Sstevel@tonic-gate			X=/net/`uname -n`${CPIODIR}
5547c478bd9Sstevel@tonic-gate		else
5557c478bd9Sstevel@tonic-gate			X=${CPIODIR}
5567c478bd9Sstevel@tonic-gate		fi
5577c478bd9Sstevel@tonic-gate		echo "Archive_directory: ${X}" >${TMPDIR}/f
5587c478bd9Sstevel@tonic-gate		cp ${TMPDIR}/f ${CPIODIR}/../../.${MACH}_wgtrun
5597c478bd9Sstevel@tonic-gate		rm -f ${TMPDIR}/f
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate	else
5627c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL cpio archives ====\n" \
5637c478bd9Sstevel@tonic-gate			>> $LOGFILE
5647c478bd9Sstevel@tonic-gate	fi
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate	#
5677c478bd9Sstevel@tonic-gate	#	Building Packages
5687c478bd9Sstevel@tonic-gate	#
5697c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
5707c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL packages at `date` ====\n" \
5717c478bd9Sstevel@tonic-gate			>> $LOGFILE
5727c478bd9Sstevel@tonic-gate		rm -f $SRC/pkgdefs/${INSTALLOG}.out
5737c478bd9Sstevel@tonic-gate		echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
5747c478bd9Sstevel@tonic-gate		rm -rf $PKGARCHIVE
5757c478bd9Sstevel@tonic-gate		mkdir -p $PKGARCHIVE
576d8fd4470Sjg
577d8fd4470Sjg		#
578d8fd4470Sjg		# Optional build of sparc realmode on i386
579d8fd4470Sjg		#
580d8fd4470Sjg		if [ "$MACH" = "i386" ] && [ "${SPARC_RM_PKGARCHIVE}" ]; then
581d8fd4470Sjg			echo "Clearing out ${SPARC_RM_PKGARCHIVE} ..." \
582d8fd4470Sjg				>> $LOGFILE
583d8fd4470Sjg			rm -rf ${SPARC_RM_PKGARCHIVE}
584d8fd4470Sjg			mkdir -p ${SPARC_RM_PKGARCHIVE}
585d8fd4470Sjg		fi
586d8fd4470Sjg
5877c478bd9Sstevel@tonic-gate		cd $SRC/pkgdefs
5887c478bd9Sstevel@tonic-gate		$MAKE -e install 2>&1 | \
5897c478bd9Sstevel@tonic-gate			tee -a $SRC/pkgdefs/${INSTALLOG}.out >> $LOGFILE
5907c478bd9Sstevel@tonic-gate		echo "\n==== Package build errors ($LABEL) ====\n" \
5917c478bd9Sstevel@tonic-gate			>> $mail_msg_file
5927c478bd9Sstevel@tonic-gate		egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/${INSTALLOG}.out | \
5937c478bd9Sstevel@tonic-gate			grep ':' | \
5947c478bd9Sstevel@tonic-gate			grep -v PSTAMP | \
5957c478bd9Sstevel@tonic-gate			egrep -v "Ignoring unknown host" \
5967c478bd9Sstevel@tonic-gate			>> $mail_msg_file
5977c478bd9Sstevel@tonic-gate	else
5987c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
5997c478bd9Sstevel@tonic-gate	fi
6004e5b757fSkupfer
6014e5b757fSkupfer	ROOT=$ORIGROOT
6027c478bd9Sstevel@tonic-gate}
6037c478bd9Sstevel@tonic-gate
6041fe69678Skupfer# Usage: dolint /dir y|n
6057c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
6061fe69678Skupferdolint() {
6077c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
6081fe69678Skupfer		echo "dolint error: $1 is not a directory"
6097c478bd9Sstevel@tonic-gate		exit 1
6107c478bd9Sstevel@tonic-gate	fi
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
6131fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
6147c478bd9Sstevel@tonic-gate		exit 1
6157c478bd9Sstevel@tonic-gate	fi
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate	lintdir=$1
6187c478bd9Sstevel@tonic-gate	dodiff=$2
6197c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
6207c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
6217c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
6224e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
6234e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
6247c478bd9Sstevel@tonic-gate
6254e5b757fSkupfer	set_debug_build_flags
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate	#
6287c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
6297c478bd9Sstevel@tonic-gate	#
6307c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
6317c478bd9Sstevel@tonic-gate
6327c478bd9Sstevel@tonic-gate	# remove old lint.out
6337c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
6347c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
6357c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
6367c478bd9Sstevel@tonic-gate	fi
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
6397c478bd9Sstevel@tonic-gate	cd $lintdir
6407c478bd9Sstevel@tonic-gate	#
6417c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
6427c478bd9Sstevel@tonic-gate	#
6437c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
6447c478bd9Sstevel@tonic-gate	    `find . -name SCCS -prune -o -type f -name '*.ln' -print `
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
6477c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
6487c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
6497c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
6507c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
6517c478bd9Sstevel@tonic-gate		>> $mail_msg_file
6527c478bd9Sstevel@tonic-gate
6537c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
6567c478bd9Sstevel@tonic-gate		>>$mail_msg_file
6577c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
6587c478bd9Sstevel@tonic-gate
6597c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
6607c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
6617c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
6627c478bd9Sstevel@tonic-gate	fi
6637c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
6647c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
6657c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
6667c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
6677c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
6687c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
6697c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
6707c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
6717c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
6727c478bd9Sstevel@tonic-gate	fi
6737c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
6747c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
6757c478bd9Sstevel@tonic-gate			>>$mail_msg_file
6767c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
6777c478bd9Sstevel@tonic-gate		# above
6787c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
6797c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
6807c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
6817c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6827c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
6837c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6847c478bd9Sstevel@tonic-gate	fi
6857c478bd9Sstevel@tonic-gate}
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate# Install proto area from IHV build
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gatecopy_ihv_proto() {
6907c478bd9Sstevel@tonic-gate
6916fec3625Sdduvall	echo "\n==== Installing IHV proto area ====\n" \
6927c478bd9Sstevel@tonic-gate		>> $LOGFILE
6937c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
6947c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
6957c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
6967c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
6977c478bd9Sstevel@tonic-gate		fi
6986fec3625Sdduvall		echo "copying $IA32_IHV_ROOT to $ROOT\n" >> $LOGFILE
6997c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
7007c478bd9Sstevel@tonic-gate		tar -cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7017c478bd9Sstevel@tonic-gate	else
7027c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
7037c478bd9Sstevel@tonic-gate	fi
7044e5b757fSkupfer
7054e5b757fSkupfer	if [ "$MULTI_PROTO" = yes ]; then
7064e5b757fSkupfer		if [ ! -d "$ROOT-nd" ]; then
7074e5b757fSkupfer			echo "mkdir -p $ROOT-nd" >> $LOGFILE
7084e5b757fSkupfer			mkdir -p $ROOT-nd
7094e5b757fSkupfer		fi
7104e5b757fSkupfer		# If there's a non-debug version of the IHV proto area,
7114e5b757fSkupfer		# copy it, but copy something if there's not.
7124e5b757fSkupfer		if [ -d "$IA32_IHV_ROOT-nd" ]; then
7134e5b757fSkupfer			echo "copying $IA32_IHV_ROOT-nd to $ROOT-nd\n" >> $LOGFILE
7144e5b757fSkupfer			cd $IA32_IHV_ROOT-nd
7154e5b757fSkupfer		elif [ -d "$IA32_IHV_ROOT" ]; then
7164e5b757fSkupfer			echo "copying $IA32_IHV_ROOT to $ROOT-nd\n" >> $LOGFILE
7174e5b757fSkupfer			cd $IA32_IHV_ROOT
7184e5b757fSkupfer		else
7194e5b757fSkupfer			echo "$IA32_IHV_ROOT{-nd,}: not found" >> $LOGFILE
7204e5b757fSkupfer			return
7214e5b757fSkupfer		fi
7224e5b757fSkupfer		tar -cf - . | (cd $ROOT-nd; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7234e5b757fSkupfer	fi
7247c478bd9Sstevel@tonic-gate}
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
7271fe69678Skupfer# usage: copy_ihv_pkgs LABEL SUFFIX
7287c478bd9Sstevel@tonic-gatecopy_ihv_pkgs() {
7297c478bd9Sstevel@tonic-gate	LABEL=$1
7307c478bd9Sstevel@tonic-gate	SUFFIX=$2
7317c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
7327c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
7337c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
7367c478bd9Sstevel@tonic-gate		>> $LOGFILE
7377c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
7387c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
7397c478bd9Sstevel@tonic-gate		tar -cf - * | \
7407c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7417c478bd9Sstevel@tonic-gate	else
7427c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
7437c478bd9Sstevel@tonic-gate	fi
7447c478bd9Sstevel@tonic-gate
7457c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
7467c478bd9Sstevel@tonic-gate		>> $LOGFILE
7477c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
7487c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
7497c478bd9Sstevel@tonic-gate		tar -cf - * | \
7507c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
7517c478bd9Sstevel@tonic-gate	else
7527c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
7537c478bd9Sstevel@tonic-gate	fi
7547c478bd9Sstevel@tonic-gate}
7557c478bd9Sstevel@tonic-gate
7564e5b757fSkupfer#
7574e5b757fSkupfer# Build and install the onbld tools.
7584e5b757fSkupfer#
7591fe69678Skupfer# usage: build_tools DESTROOT
7604e5b757fSkupfer#
7614e5b757fSkupfer# returns non-zero status if the build was successful.
7624e5b757fSkupfer#
7637c478bd9Sstevel@tonic-gatebuild_tools() {
7647c478bd9Sstevel@tonic-gate	DESTROOT=$1
7657c478bd9Sstevel@tonic-gate
7667c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
7697c478bd9Sstevel@tonic-gate		>> $LOGFILE
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
7727c478bd9Sstevel@tonic-gate	cd ${TOOLS}
7737c478bd9Sstevel@tonic-gate	/bin/time $MAKE ROOT=${DESTROOT} -e install 2>&1 | \
7747c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
7777c478bd9Sstevel@tonic-gate
7787c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
7797c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
7807c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
7817c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
7824e5b757fSkupfer	return $?
7834e5b757fSkupfer}
7844e5b757fSkupfer
7854e5b757fSkupfer#
7864e5b757fSkupfer# Set up to use locally installed tools.
7874e5b757fSkupfer#
7884e5b757fSkupfer# usage: use_tools TOOLSROOT
7894e5b757fSkupfer#
7904e5b757fSkupferuse_tools() {
7914e5b757fSkupfer	TOOLSROOT=$1
7924e5b757fSkupfer
7934e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
7947c478bd9Sstevel@tonic-gate	export STABS
7954e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
7967c478bd9Sstevel@tonic-gate	export CTFSTABS
7974e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
7987c478bd9Sstevel@tonic-gate	export GENOFFSETS
7997c478bd9Sstevel@tonic-gate
8004e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
8017c478bd9Sstevel@tonic-gate	export CTFCONVERT
8024e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
8037c478bd9Sstevel@tonic-gate	export CTFMERGE
8047c478bd9Sstevel@tonic-gate
8054e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
8067c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
8074e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
8087c478bd9Sstevel@tonic-gate	export CTFFINDMOD
8097c478bd9Sstevel@tonic-gate
8107c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
8114e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
8127c478bd9Sstevel@tonic-gate	else
8134e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
8147c478bd9Sstevel@tonic-gate	fi
8157c478bd9Sstevel@tonic-gate	export ELFSIGN
8167c478bd9Sstevel@tonic-gate
8174e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
8184e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
8197c478bd9Sstevel@tonic-gate	export PATH
8207c478bd9Sstevel@tonic-gate
8217c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
8227c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
8237c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
8247c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
8257c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
8267c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
8277c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
8287c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
8297c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
8307c478bd9Sstevel@tonic-gate}
8317c478bd9Sstevel@tonic-gate
8327c478bd9Sstevel@tonic-gatestaffer() {
8337c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
8347c478bd9Sstevel@tonic-gate		"$@"
8357c478bd9Sstevel@tonic-gate	else
8367c478bd9Sstevel@tonic-gate		arg="\"$1\""
8377c478bd9Sstevel@tonic-gate		shift
8387c478bd9Sstevel@tonic-gate		for i
8397c478bd9Sstevel@tonic-gate		do
8407c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
8417c478bd9Sstevel@tonic-gate		done
8427c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
8437c478bd9Sstevel@tonic-gate	fi
8447c478bd9Sstevel@tonic-gate}
8457c478bd9Sstevel@tonic-gate
846085d331dSkupfer#
847085d331dSkupfer# Verify that the closed tree is present if it needs to be.
848085d331dSkupfer# Sets CLOSED_IS_PRESENT for future use.
849085d331dSkupfer#
850085d331dSkupfercheck_closed_tree() {
851085d331dSkupfer	if [ -z "$CLOSED_IS_PRESENT" ]; then
852085d331dSkupfer		if [ -d $SRC/../closed ]; then
853085d331dSkupfer			CLOSED_IS_PRESENT="yes"
854085d331dSkupfer		else
855085d331dSkupfer			CLOSED_IS_PRESENT="no"
856085d331dSkupfer		fi
857085d331dSkupfer		export CLOSED_IS_PRESENT
858085d331dSkupfer	fi
859085d331dSkupfer	if [[ "$CLOSED_IS_PRESENT" = no && ! -d "$ON_CLOSED_BINS" ]]; then
860085d331dSkupfer		#
861085d331dSkupfer		# If it's an old (pre-split) tree or an empty
862085d331dSkupfer		# workspace, don't complain.
863085d331dSkupfer		#
864085d331dSkupfer		if grep -s CLOSED_BUILD $SRC/Makefile.master > /dev/null; then
865085d331dSkupfer			echo "If the closed sources are not present," \
866085d331dSkupfer			    "ON_CLOSED_BINS"
867085d331dSkupfer			echo "must point to the closed binaries tree."
868085d331dSkupfer			exit 1
869085d331dSkupfer		fi
870085d331dSkupfer	fi
871085d331dSkupfer}
8727c478bd9Sstevel@tonic-gate
873d77e7149Ssommerfeobsolete_build() {
874d77e7149Ssommerfe    	echo "WARNING: Obsolete $1 build requested; request will be ignored"
875d77e7149Ssommerfe}
876d77e7149Ssommerfe
8774e5b757fSkupfer#
8784e5b757fSkupfer# wrapper over wsdiff.
8794e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
8804e5b757fSkupfer#
8814e5b757fSkupferdo_wsdiff() {
8824e5b757fSkupfer	label=$1
8834e5b757fSkupfer	oldproto=$2
8844e5b757fSkupfer	newproto=$3
8854e5b757fSkupfer
8864e5b757fSkupfer	echo "\n==== Objects that differ since last build ($label) ====\n" | \
8874e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
8884e5b757fSkupfer
8894e5b757fSkupfer	wsdiff="wsdiff"
8904e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
8914e5b757fSkupfer
8924e5b757fSkupfer	$wsdiff -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
8934e5b757fSkupfer		    tee -a $LOGFILE >> $mail_msg_file
8944e5b757fSkupfer}
8954e5b757fSkupfer
8964e5b757fSkupfer#
8974e5b757fSkupfer# Functions for setting build flags (debug/non-debug).  Keep them
8984e5b757fSkupfer# together.
8994e5b757fSkupfer#
9004e5b757fSkupfer
9014e5b757fSkupferset_non_debug_build_flags() {
9024e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
9034e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
9044e5b757fSkupfer	unset EXTRA_OPTIONS
9054e5b757fSkupfer	unset EXTRA_CFLAGS
9064e5b757fSkupfer}
9074e5b757fSkupfer
9084e5b757fSkupferset_debug_build_flags() {
9094e5b757fSkupfer	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
9104e5b757fSkupfer	unset RELEASE_BUILD
9114e5b757fSkupfer	unset EXTRA_OPTIONS
9124e5b757fSkupfer	unset EXTRA_CFLAGS
9134e5b757fSkupfer}
9144e5b757fSkupfer
915d77e7149Ssommerfe
9167c478bd9Sstevel@tonic-gateMACH=`uname -p`
9177c478bd9Sstevel@tonic-gate
9187c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
9197c478bd9Sstevel@tonic-gate	OPTHOME=/opt
9207c478bd9Sstevel@tonic-gate	export OPTHOME
9217c478bd9Sstevel@tonic-gatefi
9227c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
9237c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
9247c478bd9Sstevel@tonic-gate	export TEAMWARE
9257c478bd9Sstevel@tonic-gatefi
9267c478bd9Sstevel@tonic-gate
9271fe69678SkupferUSAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H|O ] <env_file>
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gateWhere:
930d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
9317c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
9327c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
9337c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
9347c478bd9Sstevel@tonic-gate		E - build exportable source
9357c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
9367c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
9371fe69678Skupfer		O - build (only) open source
9387c478bd9Sstevel@tonic-gate
9397c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
9407c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
9417c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
9427c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
9437c478bd9Sstevel@tonic-gate
9447c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
9457c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
9467c478bd9Sstevel@tonic-gate
9477c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
9487c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
9497c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
9507c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
9517c478bd9Sstevel@tonic-gate	-G	gate keeper default group of options (-au)
9527c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
9537c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
9547c478bd9Sstevel@tonic-gate	-N	do not run protocmp
9554e5b757fSkupfer	-O	generate OpenSolaris deliverables
9567c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
9577c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
9587c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
95904a42e3eSszhou	-X	copy x86 IHV proto area
9607c478bd9Sstevel@tonic-gate	-a	create cpio archives
9617c478bd9Sstevel@tonic-gate	-f	find unreferenced files
9627c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
9637c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
9647c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
9657c478bd9Sstevel@tonic-gate	-n      do not do a bringover
9667c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
9677c478bd9Sstevel@tonic-gate	-p	create packages
9687c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
9697c478bd9Sstevel@tonic-gate	-t	build and use the tools in $SRC/tools
9707c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
9717c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
97296ccc8cbSesaxe	-w	report on differences between previous and current proto areas
9737c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
9747c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
9757c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
9767c478bd9Sstevel@tonic-gate		E - build exportable source
9777c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
9787c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
9791fe69678Skupfer		O - build (only) open source
9807c478bd9Sstevel@tonic-gate'
9817c478bd9Sstevel@tonic-gate#
9827c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
9837c478bd9Sstevel@tonic-gate#
9847c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
9851c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
9867c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
9877c478bd9Sstevel@tonic-gate#
9887c478bd9Sstevel@tonic-gate
9897c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
9907c478bd9Sstevel@tonic-gateA_FLAG=n
9917c478bd9Sstevel@tonic-gatea_FLAG=n
9927c478bd9Sstevel@tonic-gateC_FLAG=n
9936c3c9007SstevelD_FLAG=n
9947c478bd9Sstevel@tonic-gateF_FLAG=n
9957c478bd9Sstevel@tonic-gatef_FLAG=n
9967c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
9977c478bd9Sstevel@tonic-gatel_FLAG=n
9986c3c9007SstevelM_FLAG=n
9997c478bd9Sstevel@tonic-gatem_FLAG=n
10006c3c9007SstevelN_FLAG=n
10016c3c9007Ssteveln_FLAG=n
10024e5b757fSkupferO_FLAG=n
10036c3c9007Sstevelo_FLAG=n
10046c3c9007SstevelP_FLAG=n
10057c478bd9Sstevel@tonic-gatep_FLAG=n
10067c478bd9Sstevel@tonic-gater_FLAG=n
10076c3c9007SstevelT_FLAG=n
10087c478bd9Sstevel@tonic-gatet_FLAG=n
10097c478bd9Sstevel@tonic-gateU_FLAG=n
10106c3c9007Sstevelu_FLAG=n
10117c478bd9Sstevel@tonic-gateV_FLAG=n
10127c478bd9Sstevel@tonic-gateW_FLAG=n
10136c3c9007Sstevelw_FLAG=n
10146c3c9007SstevelX_FLAG=n
10156c3c9007Sstevelz_FLAG=n
10167c478bd9Sstevel@tonic-gateSD_FLAG=n
10176c3c9007SstevelSE_FLAG=n
10187c478bd9Sstevel@tonic-gateSH_FLAG=n
10191fe69678SkupferSO_FLAG=n
10207c478bd9Sstevel@tonic-gate#
10217c478bd9Sstevel@tonic-gateXMOD_OPT=
10227c478bd9Sstevel@tonic-gate#
10237c478bd9Sstevel@tonic-gatebuild_ok=y
10241fe69678Skupfer
10251fe69678Skupferis_source_build() {
10261fe69678Skupfer	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
10271fe69678Skupfer	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
10281fe69678Skupfer	return $?
10291fe69678Skupfer}
10301fe69678Skupfer
10317c478bd9Sstevel@tonic-gate#
10327c478bd9Sstevel@tonic-gate# examine arguments
10337c478bd9Sstevel@tonic-gate#
10347c478bd9Sstevel@tonic-gate
10351fe69678Skupfer#
10361fe69678Skupfer# single function for setting -S flag and doing error checking.
10371fe69678Skupfer# usage: set_S_flag <type>
10381fe69678Skupfer# where <type> is the source build type ("E", "D", ...).
10391fe69678Skupfer#
10401fe69678Skupferset_S_flag() {
10411fe69678Skupfer	if is_source_build; then
10421fe69678Skupfer		echo "Can only build one source variant at a time."
10431fe69678Skupfer		exit 1
10441fe69678Skupfer	fi
10451fe69678Skupfer	if [ "$1" = "E" ]; then
10461fe69678Skupfer		SE_FLAG=y
10471fe69678Skupfer	elif [ "$1" = "D" ]; then
10481fe69678Skupfer		SD_FLAG=y
10491fe69678Skupfer	elif [ "$1" = "H" ]; then
10501fe69678Skupfer		SH_FLAG=y
10511fe69678Skupfer	elif [ "$1" = "O" ]; then
10521fe69678Skupfer		SO_FLAG=y
10531fe69678Skupfer	else
10541fe69678Skupfer		echo "$USAGE"
10551fe69678Skupfer		exit 1
10561fe69678Skupfer	fi
10571fe69678Skupfer}
10581fe69678Skupfer
10597c478bd9Sstevel@tonic-gateOPTIND=1
10606c3c9007Sstevelwhile getopts inS:tV: FLAG
10617c478bd9Sstevel@tonic-gatedo
10627c478bd9Sstevel@tonic-gate	case $FLAG in
10637c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
10647c478bd9Sstevel@tonic-gate		;;
10657c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
10667c478bd9Sstevel@tonic-gate		;;
10677c478bd9Sstevel@tonic-gate	  S )
10681fe69678Skupfer		set_S_flag $OPTARG
10697c478bd9Sstevel@tonic-gate		;;
10707c478bd9Sstevel@tonic-gate	  t )	t_FLAG=y
10717c478bd9Sstevel@tonic-gate		;;
10726c3c9007Sstevel	  V )	V_FLAG=y
10736c3c9007Sstevel		V_ARG="$OPTARG"
10746c3c9007Sstevel		;;
10757c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
10767c478bd9Sstevel@tonic-gate		exit 1
10777c478bd9Sstevel@tonic-gate		;;
10787c478bd9Sstevel@tonic-gate	esac
10797c478bd9Sstevel@tonic-gatedone
10807c478bd9Sstevel@tonic-gate
10817c478bd9Sstevel@tonic-gate# correct argument count after options
10827c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
10837c478bd9Sstevel@tonic-gate
10847c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
10857c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
10867c478bd9Sstevel@tonic-gate	echo "$USAGE"
10877c478bd9Sstevel@tonic-gate	exit 1
10887c478bd9Sstevel@tonic-gatefi
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate# check if user is running nightly as root
10917c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
10927c478bd9Sstevel@tonic-gate# when root invokes nightly.
10937c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
10947c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
10957c478bd9Sstevel@tonic-gate
10967c478bd9Sstevel@tonic-gate#
10977c478bd9Sstevel@tonic-gate# force locale to C
10987c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
10997c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
11007c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
11017c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
11027c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
11037c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
11067c478bd9Sstevel@tonic-gateunset LD_OPTIONS
11077c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
11087c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
11097c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
11107c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
11117c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
11127c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
11137c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
11147c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
11157c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
11167c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
11177c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
11187c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
11197c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
11207c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
11217c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
11227c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
11237c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
11247c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
11257c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
11267c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
11277c478bd9Sstevel@tonic-gate
11287c478bd9Sstevel@tonic-gateunset CONFIG
11297c478bd9Sstevel@tonic-gateunset GROUP
11307c478bd9Sstevel@tonic-gateunset OWNER
11317c478bd9Sstevel@tonic-gateunset REMOTE
11327c478bd9Sstevel@tonic-gateunset ENV
11337c478bd9Sstevel@tonic-gateunset ARCH
11347c478bd9Sstevel@tonic-gateunset CLASSPATH
11357c478bd9Sstevel@tonic-gateunset NAME
11367c478bd9Sstevel@tonic-gate
11377c478bd9Sstevel@tonic-gate#
11387c478bd9Sstevel@tonic-gate#	Setup environmental variables
11397c478bd9Sstevel@tonic-gate#
11407c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
11417c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
11427c478bd9Sstevel@tonic-gate		. $1
11437c478bd9Sstevel@tonic-gate	else
11447c478bd9Sstevel@tonic-gate		. ./$1
11457c478bd9Sstevel@tonic-gate	fi
11467c478bd9Sstevel@tonic-gateelse
11477c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
11487c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
11497c478bd9Sstevel@tonic-gate	else
11507c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
11517c478bd9Sstevel@tonic-gate		exit 1
11527c478bd9Sstevel@tonic-gate	fi
11537c478bd9Sstevel@tonic-gatefi
11547c478bd9Sstevel@tonic-gate
11551fe69678Skupfer# contents of stdenv.sh inserted after next line:
11561fe69678Skupfer# STDENV_START
11571fe69678Skupfer# STDENV_END
11581fe69678Skupfer
11597c478bd9Sstevel@tonic-gate#
11607c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
11617c478bd9Sstevel@tonic-gate#
11627c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
11637c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
11647c478bd9Sstevel@tonic-gateelse
11657c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
11667c478bd9Sstevel@tonic-gatefi
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
11697c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate#
11727c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
11737c478bd9Sstevel@tonic-gate#
11747c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
11757c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
11767c478bd9Sstevel@tonic-gatefi
11777c478bd9Sstevel@tonic-gate
11787c478bd9Sstevel@tonic-gate#
11797c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
11807c478bd9Sstevel@tonic-gate#
11817c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
11827c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
11837c478bd9Sstevel@tonic-gatefi
11847c478bd9Sstevel@tonic-gate
11857c478bd9Sstevel@tonic-gate#
1186fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1187a5c06a9eSmike_s#
1188a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1189fb23a357Skupfer	BRINGOVER_FILES="usr"
1190a5c06a9eSmike_sfi
1191a5c06a9eSmike_s
1192fb9f9b97Skupfer#
1193fb9f9b97Skupfer# If the closed sources are not present, the closed binaries must be
1194fb9f9b97Skupfer# present for the build to succeed.  If there's no pointer to the
1195fb9f9b97Skupfer# closed binaries, flag that now, rather than forcing the user to wait
1196fb9f9b97Skupfer# a couple hours (or more) to find out.
1197fb9f9b97Skupfer#
1198085d331dSkupferorig_closed_is_present="$CLOSED_IS_PRESENT"
1199085d331dSkupfercheck_closed_tree
1200fb9f9b97Skupfer
1201a5c06a9eSmike_s#
12027c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
1203b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
12047c478bd9Sstevel@tonic-gate#
1205d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
12067c478bd9Sstevel@tonic-gateOPTIND=1
12074e5b757fSkupferwhile getopts AaBCDdFfGIilMmNnOoPpRrS:TtUuWwXxz FLAG $NIGHTLY_OPTIONS
12087c478bd9Sstevel@tonic-gatedo
12097c478bd9Sstevel@tonic-gate	case $FLAG in
12107c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
12117c478bd9Sstevel@tonic-gate		;;
12126c3c9007Sstevel	  a )	a_FLAG=y
12136c3c9007Sstevel		;;
12147c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
12157c478bd9Sstevel@tonic-gate		;; # old version of D
12166c3c9007Sstevel	  C )	C_FLAG=y
12177c478bd9Sstevel@tonic-gate		;;
12187c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
12197c478bd9Sstevel@tonic-gate		;;
12206c3c9007Sstevel	  F )	F_FLAG=y
12217c478bd9Sstevel@tonic-gate		;;
12226c3c9007Sstevel	  f )	f_FLAG=y
12237c478bd9Sstevel@tonic-gate		;;
12247c478bd9Sstevel@tonic-gate	  G )	a_FLAG=y
12257c478bd9Sstevel@tonic-gate		u_FLAG=y
12267c478bd9Sstevel@tonic-gate		;;
12277c478bd9Sstevel@tonic-gate	  I )	a_FLAG=y
12287c478bd9Sstevel@tonic-gate		m_FLAG=y
12297c478bd9Sstevel@tonic-gate		p_FLAG=y
12307c478bd9Sstevel@tonic-gate		u_FLAG=y
12317c478bd9Sstevel@tonic-gate		;;
12327c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
12337c478bd9Sstevel@tonic-gate		;;
12346c3c9007Sstevel	  l )	l_FLAG=y
12356c3c9007Sstevel		;;
12366c3c9007Sstevel	  M )	M_FLAG=y
12376c3c9007Sstevel		;;
12386c3c9007Sstevel	  m )	m_FLAG=y
12396c3c9007Sstevel		;;
12406c3c9007Sstevel	  N )	N_FLAG=y
12416c3c9007Sstevel		;;
12427c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
12437c478bd9Sstevel@tonic-gate		;;
12444e5b757fSkupfer	  O )	O_FLAG=y
12454e5b757fSkupfer		;;
12467c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
12477c478bd9Sstevel@tonic-gate		;;
12486c3c9007Sstevel	  P )	P_FLAG=y
12496c3c9007Sstevel		;; # obsolete
12507c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
12517c478bd9Sstevel@tonic-gate		;;
12526c3c9007Sstevel	  R )	m_FLAG=y
12536c3c9007Sstevel		p_FLAG=y
12546c3c9007Sstevel		;;
12557c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
12567c478bd9Sstevel@tonic-gate		;;
12576c3c9007Sstevel	  S )
12586c3c9007Sstevel		set_S_flag $OPTARG
12596c3c9007Sstevel		;;
12606c3c9007Sstevel	  T )	T_FLAG=y
12616c3c9007Sstevel		;; # obsolete
12627c478bd9Sstevel@tonic-gate	  t )	t_FLAG=y
12637c478bd9Sstevel@tonic-gate		;;
12647c478bd9Sstevel@tonic-gate	  U )
12657c478bd9Sstevel@tonic-gate		if [ -z "${PARENT_ROOT}" ]; then
12667c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
12677c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
12687c478bd9Sstevel@tonic-gate			exit 1
12697c478bd9Sstevel@tonic-gate		fi
12707c478bd9Sstevel@tonic-gate		U_FLAG=y
12717c478bd9Sstevel@tonic-gate		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
12727c478bd9Sstevel@tonic-gate		;;
12736c3c9007Sstevel	  u )	u_FLAG=y
12747c478bd9Sstevel@tonic-gate		;;
12757c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
12767c478bd9Sstevel@tonic-gate		;;
12776c3c9007Sstevel
12786c3c9007Sstevel	  w )	w_FLAG=y
12797c478bd9Sstevel@tonic-gate		;;
12807c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
12817c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
12827c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
12837c478bd9Sstevel@tonic-gate			X_FLAG=y
12847c478bd9Sstevel@tonic-gate		fi
12857c478bd9Sstevel@tonic-gate		;;
12866c3c9007Sstevel	  x )	XMOD_OPT="-x"
12876c3c9007Sstevel		;;
12886c3c9007Sstevel	  z )	z_FLAG=y
12896c3c9007Sstevel		;;
12907c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
12917c478bd9Sstevel@tonic-gate		exit 1
12927c478bd9Sstevel@tonic-gate		;;
12937c478bd9Sstevel@tonic-gate	esac
12947c478bd9Sstevel@tonic-gatedone
12957c478bd9Sstevel@tonic-gate
12967c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
12977c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
12987c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
12997c478bd9Sstevel@tonic-gate		exit 1
13007c478bd9Sstevel@tonic-gate	fi
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
13037c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
13047c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
13057c478bd9Sstevel@tonic-gate		export STAFFER
13067c478bd9Sstevel@tonic-gate	fi
13077c478bd9Sstevel@tonic-gatefi
13087c478bd9Sstevel@tonic-gate
13097c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
13107c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
13117c478bd9Sstevel@tonic-gate	export MAILTO
13127c478bd9Sstevel@tonic-gatefi
13137c478bd9Sstevel@tonic-gate
13147c478bd9Sstevel@tonic-gatePATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
13157c478bd9Sstevel@tonic-gatePATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
13167c478bd9Sstevel@tonic-gatePATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
13177c478bd9Sstevel@tonic-gateexport PATH
13187c478bd9Sstevel@tonic-gate
1319fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1320fb23a357Skupferrelsrcdirs="."
1321fb9f9b97Skupferif [[ -d $SRC/../closed && "$CLOSED_IS_PRESENT" != no ]]; then
1322fb9f9b97Skupfer	relsrcdirs="$relsrcdirs ../closed"
1323fb9f9b97Skupferfi
1324fb23a357Skupferabssrcdirs=""
1325fb23a357Skupferfor d in $relsrcdirs; do
1326fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1327fb23a357Skupferdone
1328fb23a357Skupfer
13297c478bd9Sstevel@tonic-gateunset CH
13307c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
13317c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
13327c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
13337c478bd9Sstevel@tonic-gate# the old ones still do.
13347c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
13357c478bd9Sstevel@tonic-gate	CH=
13367c478bd9Sstevel@tonic-gate	export CH
13377c478bd9Sstevel@tonic-gateelse
13387c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
13397c478bd9Sstevel@tonic-gatefi
13407c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
13417c478bd9Sstevel@tonic-gate
13427c478bd9Sstevel@tonic-gate# we export POUND_SIGN to speed up the build process -- prevents evaluation of
13437c478bd9Sstevel@tonic-gate# the Makefile.master definitions.
13446fec3625Sdduvallexport o_FLAG X_FLAG POUND_SIGN
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gatemaketype="distributed"
13477c478bd9Sstevel@tonic-gateMAKE=dmake
13487c478bd9Sstevel@tonic-gate# get the dmake version string alone
13497c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
13507c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
13517c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
13527c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
13537c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
13547c478bd9Sstevel@tonic-gate# extract the second (or final) integer
13557c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
13567c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
13577c478bd9Sstevel@tonic-gate# extract the first integer
13587c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
13597c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
13607c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
13617c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
13627c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
13637c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
13647c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
13657c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
13667c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
13677c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
13687c478bd9Sstevel@tonic-gate		exit 1
13697c478bd9Sstevel@tonic-gate	fi
13707c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
13717c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
13727c478bd9Sstevel@tonic-gate	cat <<EOF
13737c478bd9Sstevel@tonic-gate
13747c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
13757c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
13767c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
13777c478bd9Sstevel@tonic-gate
13787c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
13797c478bd9Sstevel@tonic-gateEOF
13807c478bd9Sstevel@tonic-gate	exit 1
13817c478bd9Sstevel@tonic-gatefi
13827c478bd9Sstevel@tonic-gateexport PATH
13837c478bd9Sstevel@tonic-gateexport MAKE
13847c478bd9Sstevel@tonic-gate
13857c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
13867c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
13877c478bd9Sstevel@tonic-gate	export PATH
13887c478bd9Sstevel@tonic-gatefi
13897c478bd9Sstevel@tonic-gate
13907c478bd9Sstevel@tonic-gatehostname=`uname -n`
13917c478bd9Sstevel@tonic-gateif [ ! -f $HOME/.make.machines ]; then
13927c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS=4
13937c478bd9Sstevel@tonic-gateelse
13947c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
13957c478bd9Sstevel@tonic-gate	    tail -1 | awk -F= '{print $ 2;}'`"
13967c478bd9Sstevel@tonic-gate	if [ "$DMAKE_MAX_JOBS" = "" ]; then
13977c478bd9Sstevel@tonic-gate		DMAKE_MAX_JOBS=4
13987c478bd9Sstevel@tonic-gate	fi
13997c478bd9Sstevel@tonic-gatefi
14007c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
14017c478bd9Sstevel@tonic-gateexport DMAKE_MODE
14027c478bd9Sstevel@tonic-gateexport DMAKE_MAX_JOBS
14037c478bd9Sstevel@tonic-gate
14047c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
14057c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
14067c478bd9Sstevel@tonic-gate	exit 1
14077c478bd9Sstevel@tonic-gatefi
14087c478bd9Sstevel@tonic-gate
14097c478bd9Sstevel@tonic-gate#
14107c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
14117c478bd9Sstevel@tonic-gate#
14127c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
14137c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
14147c478bd9Sstevel@tonic-gatefi
14157c478bd9Sstevel@tonic-gate
141604a42e3eSszhou#
141704a42e3eSszhou# Check for IHV root for copying ihv proto area
141804a42e3eSszhou#
141904a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
142004a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
142104a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
142204a42e3eSszhou		args_ok=n
142304a42e3eSszhou        fi
142404a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
142504a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
142604a42e3eSszhou                args_ok=n
142704a42e3eSszhou        fi
14286fec3625Sdduvall        if [ "$IA32_IHV_WS" = "" ]; then
14296fec3625Sdduvall		echo "IA32_IHV_WS: must be set for copying ihv proto"
14306fec3625Sdduvall		args_ok=n
14316fec3625Sdduvall        fi
14326fec3625Sdduvall        if [ ! -d "$IA32_IHV_WS" ]; then
14336fec3625Sdduvall                echo "$IA32_IHV_WS: not found"
14346fec3625Sdduvall                args_ok=n
14356fec3625Sdduvall        fi
143604a42e3eSszhoufi
143704a42e3eSszhou
14387c478bd9Sstevel@tonic-gate# Append source version
14397c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
14407c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
14417c478bd9Sstevel@tonic-gatefi
14427c478bd9Sstevel@tonic-gate
14437c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
14447c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
14457c478bd9Sstevel@tonic-gatefi
14467c478bd9Sstevel@tonic-gate
14477c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
14487c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
14497c478bd9Sstevel@tonic-gatefi
14507c478bd9Sstevel@tonic-gate
14511fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
14521fe69678Skupfer	VERSION="${VERSION}:OPEN_ONLY"
14531fe69678Skupferfi
14541fe69678Skupfer
14557c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
14567c478bd9Sstevel@tonic-gateexport TMPDIR
14577c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
14587c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
14597c478bd9Sstevel@tonic-gate
14607c478bd9Sstevel@tonic-gate#
14617c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
14627c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
14637c478bd9Sstevel@tonic-gate# have the fix for 6271754
14647c478bd9Sstevel@tonic-gate#
14657c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
14667c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
14677c478bd9Sstevel@tonic-gate
14687c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
14697c478bd9Sstevel@tonic-gateTOOLS_PROTO=${TOOLS}/proto
14707c478bd9Sstevel@tonic-gate
14717c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
14727c478bd9Sstevel@tonic-gate
14737c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
14747c478bd9Sstevel@tonic-gate# fails to start correctly
14757c478bd9Sstevel@tonic-gatenewdir() {
14767c478bd9Sstevel@tonic-gate	dir=$1
14777c478bd9Sstevel@tonic-gate	toadd=
14787c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
14797c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
14807c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
14817c478bd9Sstevel@tonic-gate	done
14827c478bd9Sstevel@tonic-gate	torm=
14837c478bd9Sstevel@tonic-gate	newlist=
14847c478bd9Sstevel@tonic-gate	for dir in $toadd; do
14857c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
14867c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
14877c478bd9Sstevel@tonic-gate			torm="$dir $torm"
14887c478bd9Sstevel@tonic-gate		else
14897c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
14907c478bd9Sstevel@tonic-gate			return 1
14917c478bd9Sstevel@tonic-gate		fi
14927c478bd9Sstevel@tonic-gate	done
14937c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
14947c478bd9Sstevel@tonic-gate	return 0
14957c478bd9Sstevel@tonic-gate}
14967c478bd9Sstevel@tonic-gatenewdirlist=
14977c478bd9Sstevel@tonic-gate
14987c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
14997c478bd9Sstevel@tonic-gate
15007c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
15017c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
15027c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
15037c478bd9Sstevel@tonic-gate# built from this immediate source.
15047c478bd9Sstevel@tonic-gateENVLDLIBS1=
15057c478bd9Sstevel@tonic-gateENVLDLIBS2=
15067c478bd9Sstevel@tonic-gateENVLDLIBS3=
15077c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
15087c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
15097c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
15107c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
15117c478bd9Sstevel@tonic-gatePARENT_ROOT=
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
15147c478bd9Sstevel@tonic-gate	PARENT_ROOT
15157c478bd9Sstevel@tonic-gate
15167c478bd9Sstevel@tonic-gateCPIODIR_ORIG=$CPIODIR
15177c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
15187c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1519d8fd4470Sjgif [ "$SPARC_RM_PKGARCHIVE" ]; then
15207c478bd9Sstevel@tonic-gate	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1521d8fd4470Sjgfi
15227c478bd9Sstevel@tonic-gate
15237c478bd9Sstevel@tonic-gate#
15247c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
15257c478bd9Sstevel@tonic-gate#
15267c478bd9Sstevel@tonic-gate
15277c478bd9Sstevel@tonic-gatelogshuffle() {
15281c79753fSdarrenm    	LLOG="$ATLOG/log.`date '+%F'`"
15297c478bd9Sstevel@tonic-gate	rm -rf $ATLOG/log.??`date '+%d'`
15301c79753fSdarrenm	rm -rf $ATLOG/log.????-??-`date '+%d'`
15317c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
15327c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
15337c478bd9Sstevel@tonic-gate	fi
15347c478bd9Sstevel@tonic-gate	mkdir $LLOG
15354802ef38Srscott	export LLOG
15367c478bd9Sstevel@tonic-gate
15377c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
15387c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
153996ccc8cbSesaxe
154096ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
154196ccc8cbSesaxe		    mv $TMPDIR/wsdiff.results $LLOG
154296ccc8cbSesaxe		fi
15434e5b757fSkupfer
15444e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
15454e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
15464e5b757fSkupfer		fi
15477c478bd9Sstevel@tonic-gate	fi
15487c478bd9Sstevel@tonic-gate
15497c478bd9Sstevel@tonic-gate	#
15507c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
15517c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
15527c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
15537c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
15547c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
15557c478bd9Sstevel@tonic-gate	#
15567c478bd9Sstevel@tonic-gate
15577c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
15587c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
15597c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
15607c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
15617c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
15627c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
15637c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
15647c478bd9Sstevel@tonic-gate	fi
15657c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
15667c478bd9Sstevel@tonic-gate
15677c478bd9Sstevel@tonic-gate	case "$build_ok" in
15687c478bd9Sstevel@tonic-gate		y)
15697c478bd9Sstevel@tonic-gate			state=Completed
15707c478bd9Sstevel@tonic-gate			;;
15717c478bd9Sstevel@tonic-gate		i)
15727c478bd9Sstevel@tonic-gate			state=Interrupted
15737c478bd9Sstevel@tonic-gate			;;
15747c478bd9Sstevel@tonic-gate		*)
15757c478bd9Sstevel@tonic-gate	    		state=Failed
15767c478bd9Sstevel@tonic-gate			;;
15777c478bd9Sstevel@tonic-gate	esac
157840bc9153Srscott	NIGHTLY_STATUS=$state
157940bc9153Srscott	export NIGHTLY_STATUS
15807c478bd9Sstevel@tonic-gate
158140bc9153Srscott	if [ -n "$POST_NIGHTLY" ]; then
158240bc9153Srscott		echo "\n==== Running POST_NIGHTLY command:" \
158340bc9153Srscott		    "$POST_NIGHTLY ====\n" | tee -a $mail_msg_file >> $LOGFILE
158440bc9153Srscott		$POST_NIGHTLY $state 2>&1 | tee -a $mail_msg_file >> $LOGFILE
15854802ef38Srscott	fi
15864802ef38Srscott
15877c478bd9Sstevel@tonic-gate	cat $build_time_file $mail_msg_file > ${LLOG}/mail_msg
15887c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
15897c478bd9Sstevel@tonic-gate	    	cat $build_time_file $mail_msg_file |
15907c478bd9Sstevel@tonic-gate		    /usr/bin/mailx -s \
15917c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
15927c478bd9Sstevel@tonic-gate			${MAILTO}
15937c478bd9Sstevel@tonic-gate	fi
15947c478bd9Sstevel@tonic-gate
15957c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
15967c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
15977c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
15987c478bd9Sstevel@tonic-gate	fi
15997c478bd9Sstevel@tonic-gate
16007c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
16017c478bd9Sstevel@tonic-gate}
16027c478bd9Sstevel@tonic-gate
16037c478bd9Sstevel@tonic-gate#
16047c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
16057c478bd9Sstevel@tonic-gate#
16067c478bd9Sstevel@tonic-gatecleanup() {
16077c478bd9Sstevel@tonic-gate    	logshuffle
16087c478bd9Sstevel@tonic-gate
16097c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
16107c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
16117c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
16127c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
16137c478bd9Sstevel@tonic-gate
16147c478bd9Sstevel@tonic-gate	set -- $newdirlist
16157c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
16167c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
16177c478bd9Sstevel@tonic-gate		shift; shift
16187c478bd9Sstevel@tonic-gate	done
16197c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
16207c478bd9Sstevel@tonic-gate}
16217c478bd9Sstevel@tonic-gate
16227c478bd9Sstevel@tonic-gatecleanup_signal() {
16237c478bd9Sstevel@tonic-gate    	build_ok=i
16247c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
16257c478bd9Sstevel@tonic-gate	exit 1
16267c478bd9Sstevel@tonic-gate}
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gatetrap cleanup 0
16297c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate#
16327c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
16337c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
16347c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
16357c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
16367c478bd9Sstevel@tonic-gate# for the workspace).
16377c478bd9Sstevel@tonic-gatecreate_lock() {
16387c478bd9Sstevel@tonic-gate	lockf=$1
16397c478bd9Sstevel@tonic-gate	lockvar=$2
16407c478bd9Sstevel@tonic-gate	if [ -f $lockf ]; then
16417c478bd9Sstevel@tonic-gate		basews=`basename $CODEMGR_WS`
16427c478bd9Sstevel@tonic-gate		if read host user pid < $lockf; then
16437c478bd9Sstevel@tonic-gate			if [ "$host" != "$hostname" ]; then
16447c478bd9Sstevel@tonic-gate				echo "$MACH build of $basews apparently" \
16457c478bd9Sstevel@tonic-gate				    "already started by $user on $host as $pid."
16467c478bd9Sstevel@tonic-gate			elif kill -s 0 $pid 2>/dev/null; then
16477c478bd9Sstevel@tonic-gate				echo "$MACH build of $basews already started" \
16487c478bd9Sstevel@tonic-gate				    "by $user as $pid."
16497c478bd9Sstevel@tonic-gate			else
16507c478bd9Sstevel@tonic-gate				# stale lock; clear it out and continue
16517c478bd9Sstevel@tonic-gate				rm -f $lockf
16527c478bd9Sstevel@tonic-gate			fi
16537c478bd9Sstevel@tonic-gate		else
16547c478bd9Sstevel@tonic-gate			echo "$MACH build of $basews already running."
16557c478bd9Sstevel@tonic-gate		fi
16567c478bd9Sstevel@tonic-gate	fi
16577c478bd9Sstevel@tonic-gate	if [ -f $lockf ]; then
16587c478bd9Sstevel@tonic-gate		echo "Lock file is $lockf."
16597c478bd9Sstevel@tonic-gate		exit 1
16607c478bd9Sstevel@tonic-gate	fi
16617c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
16627c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
16637c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
16647c478bd9Sstevel@tonic-gate	staffer sh -c "echo $hostname $STAFFER $$ > $lockf" || exit 1
16657c478bd9Sstevel@tonic-gate}
16667c478bd9Sstevel@tonic-gate
16674e5b757fSkupfer#
16684e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
16694e5b757fSkupfer# options.
16704e5b757fSkupfer#
16714e5b757fSkupferallprotos() {
16724e5b757fSkupfer	roots="$ROOT"
16734e5b757fSkupfer	if [ $O_FLAG = y ]; then
16744e5b757fSkupfer		# OpenSolaris deliveries require separate proto areas.
16754e5b757fSkupfer		[ $D_FLAG = y ] && roots="$roots $ROOT-open"
16764e5b757fSkupfer		[ $F_FLAG = n ] && roots="$roots $ROOT-open-nd"
16774e5b757fSkupfer	fi
16784e5b757fSkupfer	if [[ $D_FLAG = y && $F_FLAG = n ]]; then
16794e5b757fSkupfer		[ $MULTI_PROTO = yes ] && roots="$roots $ROOT-nd"
16804e5b757fSkupfer	fi
16814e5b757fSkupfer
16824e5b757fSkupfer	echo $roots
16834e5b757fSkupfer}
16844e5b757fSkupfer
16857c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
16867c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
16877c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
16887c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
16897c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
16907c478bd9Sstevel@tonic-gatefi
16917c478bd9Sstevel@tonic-gate#
16927c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
16937c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
16947c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
16957c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
16967c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
16977c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
16987c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
16997c478bd9Sstevel@tonic-gate#
17007c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
17017c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
17027c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
17037c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
17047c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
17057c478bd9Sstevel@tonic-gatefi
17067c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
17077c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
17087c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
17097c478bd9Sstevel@tonic-gatefi
17107c478bd9Sstevel@tonic-gate
17117c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
17127c478bd9Sstevel@tonic-gate# the directories we may have created so far.
17137c478bd9Sstevel@tonic-gatenewdirlist=
17147c478bd9Sstevel@tonic-gate
17157c478bd9Sstevel@tonic-gate#
17167c478bd9Sstevel@tonic-gate# Create mail_msg_file
17177c478bd9Sstevel@tonic-gate#
17187c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
17197c478bd9Sstevel@tonic-gatetouch $mail_msg_file
17207c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
17217c478bd9Sstevel@tonic-gate#
17227c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
17237c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
17247c478bd9Sstevel@tonic-gate#
17257c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
17267c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
17277c478bd9Sstevel@tonic-gatefi
17287c478bd9Sstevel@tonic-gate#
17297c478bd9Sstevel@tonic-gate#	Build OsNet source
17307c478bd9Sstevel@tonic-gate#
17317c478bd9Sstevel@tonic-gateSTART_DATE=`date`
17327c478bd9Sstevel@tonic-gateSECONDS=0
17337c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
17347c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
17357c478bd9Sstevel@tonic-gate
17367c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
17377c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
17387c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
17397c478bd9Sstevel@tonic-gate
17407c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
17417c478bd9Sstevel@tonic-gateenv >> $LOGFILE
17427c478bd9Sstevel@tonic-gate
17437c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
17447c478bd9Sstevel@tonic-gate
1745d77e7149Ssommerfeif [ "$P_FLAG" = "y" ]; then
1746d77e7149Ssommerfe	obsolete_build GPROF | tee -a $mail_msg_file >> $LOGFILE
1747d77e7149Ssommerfefi
1748d77e7149Ssommerfe
1749d77e7149Ssommerfeif [ "$T_FLAG" = "y" ]; then
1750d77e7149Ssommerfe	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
1751d77e7149Ssommerfefi
1752d77e7149Ssommerfe
17531fe69678Skupferif is_source_build; then
17547c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
17557c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
17567c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
17577c478bd9Sstevel@tonic-gate		i_FLAG=n
17587c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
17597c478bd9Sstevel@tonic-gate	fi
17607c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
17617c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
17627c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
17637c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
17647c478bd9Sstevel@tonic-gate		N_FLAG=y
17657c478bd9Sstevel@tonic-gate	fi
17667c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
17677c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
17687c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
17697c478bd9Sstevel@tonic-gate		l_FLAG=n
17707c478bd9Sstevel@tonic-gate	fi
17717c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
17727c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
17737c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
17747c478bd9Sstevel@tonic-gate		C_FLAG=n
17757c478bd9Sstevel@tonic-gate	fi
17767c478bd9Sstevel@tonic-gateelse
17777c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
17787c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
17797c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
17807c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
17817c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
17827c478bd9Sstevel@tonic-gateEOF
17837c478bd9Sstevel@tonic-gate		else
17847c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
17857c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
17867c478bd9Sstevel@tonic-gateEOF
17877c478bd9Sstevel@tonic-gate		fi
17887c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
17897c478bd9Sstevel@tonic-gate	fi
17907c478bd9Sstevel@tonic-gatefi
17917c478bd9Sstevel@tonic-gate
17924e5b757fSkupferif [ "$O_FLAG" = "y" -a "$a_FLAG" = "n" ]; then
17934e5b757fSkupfer	echo "WARNING: OpenSolaris deliveries (-O) require archives;" \
17944e5b757fSkupfer	    "enabling the -a flag." | tee -a $mail_msg_file >> $LOGFILE
17954e5b757fSkupfer	a_FLAG=y
17964e5b757fSkupferfi
17974e5b757fSkupfer
17987c478bd9Sstevel@tonic-gateif [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
17997c478bd9Sstevel@tonic-gate	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
18007c478bd9Sstevel@tonic-gate	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
18017c478bd9Sstevel@tonic-gatefi
18027c478bd9Sstevel@tonic-gate
18037c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
18044e5b757fSkupfer	#
18054e5b757fSkupfer	# In the past we just complained but went ahead with the lint
18064e5b757fSkupfer	# pass, even though the proto area was built non-debug.  It's
18074e5b757fSkupfer	# unlikely that non-debug headers will make a difference, but
18084e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
18094e5b757fSkupfer	# to specify a debug build.
18104e5b757fSkupfer	#
18114e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
18127c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
18134e5b757fSkupfer	l_FLAG=n
18147c478bd9Sstevel@tonic-gatefi
18157c478bd9Sstevel@tonic-gate
18167c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
18177c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
18187c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
18197c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
18207c478bd9Sstevel@tonic-gate		f_FLAG=n
18217c478bd9Sstevel@tonic-gate	fi
18227c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
18237c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
18247c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18257c478bd9Sstevel@tonic-gate		f_FLAG=n
18267c478bd9Sstevel@tonic-gate	fi
18277c478bd9Sstevel@tonic-gatefi
18287c478bd9Sstevel@tonic-gate
182996ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
18304e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
183196ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
183296ccc8cbSesaxe	w_FLAG=n
183396ccc8cbSesaxefi
183496ccc8cbSesaxe
18357c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
18367c478bd9Sstevel@tonic-gate	#
18377c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
18387c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
18397c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
18407c478bd9Sstevel@tonic-gate	#
18417c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
18427c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
18437c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
18447c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
18457c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
18467c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
18477c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18487c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
18497c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
18507c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
18517c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
18527c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
18537c478bd9Sstevel@tonic-gate	fi
18547c478bd9Sstevel@tonic-gatefi
18557c478bd9Sstevel@tonic-gate
18564e5b757fSkupfer[ "$O_FLAG" = y ] && MULTI_PROTO=yes
18574e5b757fSkupfer
18584e5b757fSkupfercase $MULTI_PROTO in
18594e5b757fSkupferyes|no)	;;
18604e5b757fSkupfer*)
18614e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
18624e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
18634e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
18644e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
18654e5b757fSkupfer	export MULTI_PROTO=no
18664e5b757fSkupfer	;;
18674e5b757fSkupferesac
18684e5b757fSkupfer
18697c478bd9Sstevel@tonic-gateecho "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
18707c478bd9Sstevel@tonic-gate
18717c478bd9Sstevel@tonic-gate# System
18727c478bd9Sstevel@tonic-gatewhence uname | tee -a $mail_msg_file >> $LOGFILE
18737c478bd9Sstevel@tonic-gateuname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
18747c478bd9Sstevel@tonic-gateecho | tee -a $mail_msg_file >> $LOGFILE
18757c478bd9Sstevel@tonic-gate
18767c478bd9Sstevel@tonic-gate# nightly (will fail in year 2100 due to SCCS flaw)
18777c478bd9Sstevel@tonic-gateecho "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
1878964296ffSrotondoecho "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
18797c478bd9Sstevel@tonic-gate
18807c478bd9Sstevel@tonic-gate# make
18817c478bd9Sstevel@tonic-gatewhence $MAKE | tee -a $mail_msg_file >> $LOGFILE
18827c478bd9Sstevel@tonic-gate$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
18837c478bd9Sstevel@tonic-gateecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
18847c478bd9Sstevel@tonic-gate    tee -a $mail_msg_file >> $LOGFILE
18857c478bd9Sstevel@tonic-gate
18867c478bd9Sstevel@tonic-gate#
18877c478bd9Sstevel@tonic-gate# Report the compiler versions.
18887c478bd9Sstevel@tonic-gate#
18897c478bd9Sstevel@tonic-gateif [ -f $SRC/Makefile ]; then
18907c478bd9Sstevel@tonic-gate	srcroot=$SRC
18917c478bd9Sstevel@tonic-gateelif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
18927c478bd9Sstevel@tonic-gate	srcroot=$BRINGOVER_WS/usr/src
18937c478bd9Sstevel@tonic-gateelse
18947c478bd9Sstevel@tonic-gate	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
18957c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
18967c478bd9Sstevel@tonic-gate	exit 1
18977c478bd9Sstevel@tonic-gatefi
18987c478bd9Sstevel@tonic-gate
18997c478bd9Sstevel@tonic-gate( cd $srcroot
19007c478bd9Sstevel@tonic-gate  for target in cc-version cc64-version java-version; do
19017c478bd9Sstevel@tonic-gate	echo
19027c478bd9Sstevel@tonic-gate	#
19037c478bd9Sstevel@tonic-gate	# Put statefile somewhere we know we can write to rather than trip
1904b84bdc30Smeem	# over a read-only $srcroot.
19057c478bd9Sstevel@tonic-gate	#
19067c478bd9Sstevel@tonic-gate	rm -f $TMPDIR/make-state
190732f1e47bSsommerfe	export SRC=$srcroot
1908b84bdc30Smeem	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
19097c478bd9Sstevel@tonic-gate		continue
19107c478bd9Sstevel@tonic-gate	fi
19117c478bd9Sstevel@tonic-gate	touch $TMPDIR/nocompiler
19127c478bd9Sstevel@tonic-gate  done
19137c478bd9Sstevel@tonic-gate  echo
19147c478bd9Sstevel@tonic-gate) | tee -a $mail_msg_file >> $LOGFILE
19157c478bd9Sstevel@tonic-gate
19167c478bd9Sstevel@tonic-gateif [ -f $TMPDIR/nocompiler ]; then
19177c478bd9Sstevel@tonic-gate	rm -f $TMPDIR/nocompiler
19187c478bd9Sstevel@tonic-gate	build_ok=n
19197c478bd9Sstevel@tonic-gate	echo "Aborting due to missing compiler." |
19207c478bd9Sstevel@tonic-gate		tee -a $mail_msg_file >> $LOGFILE
19217c478bd9Sstevel@tonic-gate	exit 1
19227c478bd9Sstevel@tonic-gatefi
19237c478bd9Sstevel@tonic-gate
19247c478bd9Sstevel@tonic-gate# as
19257c478bd9Sstevel@tonic-gatewhence as | tee -a $mail_msg_file >> $LOGFILE
19267c478bd9Sstevel@tonic-gateas -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
19277c478bd9Sstevel@tonic-gateecho | tee -a $mail_msg_file >> $LOGFILE
19287c478bd9Sstevel@tonic-gate
19297c478bd9Sstevel@tonic-gate# Check that we're running a capable link-editor
19307c478bd9Sstevel@tonic-gatewhence ld | tee -a $mail_msg_file >> $LOGFILE
19317c478bd9Sstevel@tonic-gateLDVER=`ld -V 2>&1`
19327c478bd9Sstevel@tonic-gateecho $LDVER | tee -a $mail_msg_file >> $LOGFILE
19337c478bd9Sstevel@tonic-gateLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
19347c478bd9Sstevel@tonic-gateif [ `expr $LDVER \< 422` -eq 1 ]; then
19357c478bd9Sstevel@tonic-gate	echo "The link-editor needs to be at version 422 or higher to build" | \
19367c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
19377c478bd9Sstevel@tonic-gate	echo "the latest stuff, hope your build works." | \
19387c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
19397c478bd9Sstevel@tonic-gatefi
19407c478bd9Sstevel@tonic-gate
19417c478bd9Sstevel@tonic-gateecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
19427c478bd9Sstevel@tonic-gate    tee -a $mail_msg_file >> $LOGFILE
19437c478bd9Sstevel@tonic-gate
19447c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
19457c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
19467c478bd9Sstevel@tonic-gate
194796ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
194896ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
194996ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
195096ccc8cbSesaxe	rm -rf $ROOT.prev
195196ccc8cbSesaxe    fi
195296ccc8cbSesaxe    mv $ROOT $ROOT.prev
195396ccc8cbSesaxefi
195496ccc8cbSesaxe
19554e5b757fSkupfer# Same for non-DEBUG proto area
19564e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
19574e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
19584e5b757fSkupfer		rm -rf $ROOT-nd.prev
19594e5b757fSkupfer	fi
19604e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
19614e5b757fSkupferfi
19624e5b757fSkupfer
19637c478bd9Sstevel@tonic-gate#
19647c478bd9Sstevel@tonic-gate#	Decide whether to clobber
19657c478bd9Sstevel@tonic-gate#
19667c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
19677c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
19687c478bd9Sstevel@tonic-gate
19697c478bd9Sstevel@tonic-gate	cd $SRC
19707c478bd9Sstevel@tonic-gate	# remove old clobber file
19717c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
19727c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
19737c478bd9Sstevel@tonic-gate
19747c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
19757c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
19767c478bd9Sstevel@tonic-gate	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
19777c478bd9Sstevel@tonic-gate	    -o -name '.make.*' -print | xargs rm -f
19787c478bd9Sstevel@tonic-gate
19797c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
19807c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
19817c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
19827c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
19837c478bd9Sstevel@tonic-gate		>> $mail_msg_file
19847c478bd9Sstevel@tonic-gate
19854e5b757fSkupfer	if [[ "$t_FLAG" = "y" || "$O_FLAG" = "y" ]]; then
19867c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
19877c478bd9Sstevel@tonic-gate		cd ${TOOLS}
19887c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
19897c478bd9Sstevel@tonic-gate		$MAKE -ek clobber 2>&1 | \
19907c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
19917c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
19927c478bd9Sstevel@tonic-gate			>> $mail_msg_file
19937c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
19947c478bd9Sstevel@tonic-gate			>> $mail_msg_file
19957c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
19967c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
19977c478bd9Sstevel@tonic-gate	fi
199896ccc8cbSesaxe
19994e5b757fSkupfer	rm -rf `allprotos`
20007c478bd9Sstevel@tonic-gate
20017c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
20027c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
20037c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
2004fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
2005fb23a357Skupfer	# under SCCS, so leave them alone.
20067c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
20077c478bd9Sstevel@tonic-gate	cd $SRC
2008fb23a357Skupfer	find $relsrcdirs \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
20097c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
2010fb23a357Skupfer	       -name '*.o' \) -print | \
2011fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
20127c478bd9Sstevel@tonic-gateelse
20137c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
20147c478bd9Sstevel@tonic-gatefi
20157c478bd9Sstevel@tonic-gate
20167c478bd9Sstevel@tonic-gate#
20177c478bd9Sstevel@tonic-gate#	Decide whether to bringover to the codemgr workspace
20187c478bd9Sstevel@tonic-gate#
20197c478bd9Sstevel@tonic-gateif [ "$n_FLAG" = "n" ]; then
20207c478bd9Sstevel@tonic-gate	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
20217c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
20227c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
20237c478bd9Sstevel@tonic-gate	do
20247c478bd9Sstevel@tonic-gate		sleep 120
20257c478bd9Sstevel@tonic-gate	done
20267c478bd9Sstevel@tonic-gate
20277c478bd9Sstevel@tonic-gate	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
202832f1e47bSsommerfe
202932f1e47bSsommerfe	(staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
203032f1e47bSsommerfe	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 ||
203132f1e47bSsommerfe		touch $TMPDIR/bringover_failed
203232f1e47bSsommerfe
2033d77e7149Ssommerfe         staffer bringovercheck $CODEMGR_WS >$TMPDIR/bringovercheck.out 2>&1
2034d77e7149Ssommerfe
2035d77e7149Ssommerfe	 if [ -s $TMPDIR/bringovercheck.out ]; then
2036d77e7149Ssommerfe		echo "\n==== POST-BRINGOVER CLEANUP NOISE ====\n"
2037d77e7149Ssommerfe		cat $TMPDIR/bringovercheck.out
2038d77e7149Ssommerfe	 fi
203932f1e47bSsommerfe
204032f1e47bSsommerfe	) | tee -a  $mail_msg_file >> $LOGFILE
204132f1e47bSsommerfe
204232f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
204332f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
204432f1e47bSsommerfe		build_ok=n
204532f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
20467c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
20477c478bd9Sstevel@tonic-gate		exit 1
20487c478bd9Sstevel@tonic-gate	fi
2049085d331dSkupfer
2050085d331dSkupfer	#
2051085d331dSkupfer	# Possible transition from pre-split workspace to split
2052085d331dSkupfer	# workspace.  See if the bringover changed anything.
2053085d331dSkupfer	#
2054085d331dSkupfer	CLOSED_IS_PRESENT="$orig_closed_is_present"
2055085d331dSkupfer	check_closed_tree
20567c478bd9Sstevel@tonic-gateelse
20577c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
20587c478bd9Sstevel@tonic-gatefi
20597c478bd9Sstevel@tonic-gate
20607c478bd9Sstevel@tonic-gate#
20614e5b757fSkupfer# Build and use the workspace's tools if requested
20627c478bd9Sstevel@tonic-gate#
20634e5b757fSkupferif [[ "$t_FLAG" = "y" || "$O_FLAG" = y ]]; then
20644e5b757fSkupfer	set_non_debug_build_flags
20657c478bd9Sstevel@tonic-gate
20667c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
20674e5b757fSkupfer
20684e5b757fSkupfer	if [[ $? -ne 0 && "$t_FLAG" = y ]]; then
20694e5b757fSkupfer		use_tools $TOOLS_PROTO
20704e5b757fSkupfer		export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
20714e5b757fSkupfer	fi
20727c478bd9Sstevel@tonic-gatefi
20737c478bd9Sstevel@tonic-gate
20746fec3625Sdduvall#
20756fec3625Sdduvall# copy ihv proto area in addition to the build itself
20766fec3625Sdduvall#
20776fec3625Sdduvallif [ "$X_FLAG" = "y" ]; then
20786fec3625Sdduvall	copy_ihv_proto
20796fec3625Sdduvallfi
20806fec3625Sdduvall
20817c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
20827c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
20837c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
20847c478bd9Sstevel@tonic-gateelse
20854e5b757fSkupfer	# timestamp the start of the normal build; the findunref tool uses it.
20864e5b757fSkupfer	touch $SRC/.build.tstamp
20874e5b757fSkupfer
20887c478bd9Sstevel@tonic-gate	normal_build
20897c478bd9Sstevel@tonic-gatefi
20907c478bd9Sstevel@tonic-gate
20914e5b757fSkupfer#
20924e5b757fSkupfer# Generate OpenSolaris deliverables if requested.
20934e5b757fSkupfer#
20944e5b757fSkupferif [ "$O_FLAG" = y -a "$build_ok" = y ]; then
20954e5b757fSkupfer	#
20964e5b757fSkupfer	# Generate skeleton (minimal) closed binaries for open-only
20974e5b757fSkupfer	# build.  There's no need to distinguish debug from non-debug
20984e5b757fSkupfer	# binaries, but it simplifies file management to have separate
20994e5b757fSkupfer	# trees.
21004e5b757fSkupfer	#
21014e5b757fSkupfer
21024e5b757fSkupfer	echo "\n==== Generating skeleton closed binaries for" \
21034e5b757fSkupfer	    "open-only build ====\n" | \
21044e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
21054e5b757fSkupfer
21064e5b757fSkupfer	rm -rf $CODEMGR_WS/closed.skel
21074e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
21084e5b757fSkupfer		mkclosed $MACH $ROOT $CODEMGR_WS/closed.skel/root_$MACH \
21094e5b757fSkupfer		    >>$LOGFILE 2>&1
21104e5b757fSkupfer		if [ $? -ne 0 ]; then
21114e5b757fSkupfer			echo "Couldn't create skeleton DEBUG closed binaries." |
21124e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21134e5b757fSkupfer		fi
21144e5b757fSkupfer	fi
21154e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
21164e5b757fSkupfer		mkclosed $MACH $ROOT-nd $CODEMGR_WS/closed.skel/root_$MACH-nd \
21174e5b757fSkupfer		    >>$LOGFILE 2>&1
21184e5b757fSkupfer		if [ $? -ne 0 ]; then
21194e5b757fSkupfer			echo "Couldn't create skeleton non-DEBUG closed binaries." |
21204e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21214e5b757fSkupfer		fi
21224e5b757fSkupfer	fi
21234e5b757fSkupfer
21244e5b757fSkupfer	ORIG_CLOSED_IS_PRESENT=$CLOSED_IS_PRESENT
21254e5b757fSkupfer	export CLOSED_IS_PRESENT=no
21264e5b757fSkupfer
21274e5b757fSkupfer	ORIG_ON_CLOSED_BINS="$ON_CLOSED_BINS"
21284e5b757fSkupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel
21294e5b757fSkupfer
21304e5b757fSkupfer	normal_build -O
21314e5b757fSkupfer
21324e5b757fSkupfer	echo "\n==== Generating OpenSolaris tarballs ====\n" | \
21334e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
21344e5b757fSkupfer
21354e5b757fSkupfer	cd $CODEMGR_WS
21364e5b757fSkupfer
21374e5b757fSkupfer	echo "Generating THIRDPARTYLICENSE files..." >> $LOGFILE
21384e5b757fSkupfer
21394e5b757fSkupfer	mktpl usr/src/tools/opensolaris/license-list >>$LOGFILE 2>&1
21404e5b757fSkupfer	if [ $? -ne 0 ]; then
21414e5b757fSkupfer		echo "Couldn't create THIRDPARTYLICENSE files" |
21424e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
21434e5b757fSkupfer	fi
21444e5b757fSkupfer
21454e5b757fSkupfer	echo "Generating closed binaries tarball(s)..." >> $LOGFILE
2146*52a52aebSkupfer	closed_basename=on-closed-bins
21474e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
2148*52a52aebSkupfer		bindrop "$ROOT" "$ROOT-open" "$closed_basename" \
2149*52a52aebSkupfer		    >>"$LOGFILE" 2>&1
21504e5b757fSkupfer		if [ $? -ne 0 ]; then
21514e5b757fSkupfer			echo "Couldn't create DEBUG closed binaries." |
21524e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21534e5b757fSkupfer		fi
21544e5b757fSkupfer	fi
21554e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
2156*52a52aebSkupfer		bindrop -n "$ROOT-nd" "$ROOT-open-nd" "$closed_basename-nd" \
2157*52a52aebSkupfer		    >>"$LOGFILE" 2>&1
21584e5b757fSkupfer		if [ $? -ne 0 ]; then
21594e5b757fSkupfer			echo "Couldn't create non-DEBUG closed binaries." |
21604e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21614e5b757fSkupfer		fi
21624e5b757fSkupfer	fi
21634e5b757fSkupfer
21644e5b757fSkupfer	echo "Generating SUNWonbld tarball..." >> $LOGFILE
21654e5b757fSkupfer	PKGARCHIVE=$PKGARCHIVE_ORIG
21664e5b757fSkupfer	onblddrop >> $LOGFILE 2>&1
21674e5b757fSkupfer	if [ $? -ne 0 ]; then
21684e5b757fSkupfer		echo "Couldn't create SUNWonbld tarball." |
21694e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
21704e5b757fSkupfer	fi
21714e5b757fSkupfer
21724e5b757fSkupfer	echo "Generating README.opensolaris..." >> $LOGFILE
21734e5b757fSkupfer	cat $SRC/tools/opensolaris/README.opensolaris.tmpl | \
21744e5b757fSkupfer	    mkreadme_osol $CODEMGR_WS/README.opensolaris >> $LOGFILE 2>&1
21754e5b757fSkupfer	if [ $? -ne 0 ]; then
21764e5b757fSkupfer		echo "Couldn't create README.opensolaris." |
21774e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
21784e5b757fSkupfer	fi
21794e5b757fSkupfer
21804e5b757fSkupfer	echo "Generating source tarball..." >> $LOGFILE
21814e5b757fSkupfer	sdrop >>$LOGFILE 2>&1
21824e5b757fSkupfer	if [ $? -ne 0 ]; then
21834e5b757fSkupfer		echo "Couldn't create source tarball." |
2184*52a52aebSkupfer		    tee -a "$mail_msg_file" >> "$LOGFILE"
21854e5b757fSkupfer	fi
21864e5b757fSkupfer
21874e5b757fSkupfer	echo "Generating BFU tarball(s)..." >> $LOGFILE
21884e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
2189*52a52aebSkupfer		makebfu_filt bfudrop "$ROOT-open" \
2190*52a52aebSkupfer		    "$closed_basename.$MACH.tar.bz2" nightly-osol
21914e5b757fSkupfer		if [ $? -ne 0 ]; then
21924e5b757fSkupfer			echo "Couldn't create DEBUG archives tarball." |
21934e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
21944e5b757fSkupfer		fi
21954e5b757fSkupfer	fi
21964e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
2197*52a52aebSkupfer		makebfu_filt bfudrop -n "$ROOT-open-nd" \
2198*52a52aebSkupfer		    "$closed_basename-nd.$MACH.tar.bz2" nightly-osol-nd
21994e5b757fSkupfer		if [ $? -ne 0 ]; then
22004e5b757fSkupfer			echo "Couldn't create non-DEBUG archives tarball." |
22014e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
22024e5b757fSkupfer		fi
22034e5b757fSkupfer	fi
22044e5b757fSkupfer
22054e5b757fSkupfer	ON_CLOSED_BINS=$ORIG_ON_CLOSED_BINS
22064e5b757fSkupfer	CLOSED_IS_PRESENT=$ORIG_CLOSED_IS_PRESENT
22074e5b757fSkupferfi
22084e5b757fSkupfer
22097c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
22107c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
22117c478bd9Sstevel@tonic-gate
22121fe69678Skupfer#
22131fe69678Skupfer# For the "open" build, we don't mung any source files, so skip this
22141fe69678Skupfer# step.
22151fe69678Skupfer#
22167c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
22177c478bd9Sstevel@tonic-gate	save_binaries
22187c478bd9Sstevel@tonic-gate
22197c478bd9Sstevel@tonic-gate	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
22207c478bd9Sstevel@tonic-gate	SCCSHELPER=${TMPDIR}/sccs-helper
22217c478bd9Sstevel@tonic-gate	rm -f ${SCCSHELPER}
22227c478bd9Sstevel@tonic-gatecat >${SCCSHELPER} <<EOF
22237c478bd9Sstevel@tonic-gate#!/bin/ksh
22247c478bd9Sstevel@tonic-gatecd \$1
22257c478bd9Sstevel@tonic-gatecd ..
22267c478bd9Sstevel@tonic-gatesccs get SCCS >/dev/null 2>&1
22277c478bd9Sstevel@tonic-gateEOF
22287c478bd9Sstevel@tonic-gate	cd $SRC
22297c478bd9Sstevel@tonic-gate	chmod +x ${SCCSHELPER}
2230fb23a357Skupfer	find $relsrcdirs -name SCCS | xargs -L 1 ${SCCSHELPER}
22317c478bd9Sstevel@tonic-gate	rm -f ${SCCSHELPER}
22327c478bd9Sstevel@tonic-gatefi
22337c478bd9Sstevel@tonic-gate
22347c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
22351fe69678Skupfer	set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
22367c478bd9Sstevel@tonic-gatefi
22377c478bd9Sstevel@tonic-gate
22387c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
22397c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
22407c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
22411fe69678Skupfer	set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
22427c478bd9Sstevel@tonic-gatefi
22437c478bd9Sstevel@tonic-gate
22447c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
22457c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
22467c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
22477c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
22487c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
22497c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
22507c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
22517c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
22527c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
22537c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
22547c478bd9Sstevel@tonic-gate	else
22557c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
22567c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
22577c478bd9Sstevel@tonic-gate	fi
22587c478bd9Sstevel@tonic-gate
22597c478bd9Sstevel@tonic-gatefi
22607c478bd9Sstevel@tonic-gate
22611fe69678Skupferif [ "$SO_FLAG" = "y" ]; then
22621fe69678Skupfer	#
22631fe69678Skupfer	# Copy the open sources into their own tree, set up the closed
22644e5b757fSkupfer	# binaries, and set up the environment.  The build looks for
22654e5b757fSkupfer	# the closed binaries in a location that depends on whether
22664e5b757fSkupfer	# it's a DEBUG build, so we might need to make two copies.
22671fe69678Skupfer	#
22681fe69678Skupfer	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
22691fe69678Skupfer	SRC=$OPEN_SRCDIR/usr/src
22701fe69678Skupfer
22711fe69678Skupfer	# Try not to clobber any user-provided closed binaries.
22721fe69678Skupfer	export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
22734e5b757fSkupfer
22744e5b757fSkupfer	echo "\n==== Copying skeleton closed binaries to" \
22754e5b757fSkupfer	    "$ON_CLOSED_BINS ====\n" | \
22761fe69678Skupfer	    tee -a $mail_msg_file >> $LOGFILE
22774e5b757fSkupfer
22784e5b757fSkupfer	if [ "$D_FLAG" = y ]; then
22794e5b757fSkupfer		mkclosed $MACH $ROOT $ON_CLOSED_BINS/root_$MACH >>$LOGFILE 2>&1
22801fe69678Skupfer		if [ $? -ne 0 ]; then
22811fe69678Skupfer			build_ok=n
22824e5b757fSkupfer			echo "Couldn't create DEBUG closed binaries." |
22831fe69678Skupfer			    tee -a $mail_msg_file >> $LOGFILE
22841fe69678Skupfer		fi
22854e5b757fSkupfer	fi
22864e5b757fSkupfer	if [ "$F_FLAG" = n ]; then
22874e5b757fSkupfer		root=$ROOT
22884e5b757fSkupfer		[ "$MULTI_PROTO" = yes ] && root=$ROOT-nd
22894e5b757fSkupfer		mkclosed $MACH $root $ON_CLOSED_BINS/root_$MACH-nd \
22904e5b757fSkupfer		    >>$LOGFILE 2>&1
22914e5b757fSkupfer		if [ $? -ne 0 ]; then
22924e5b757fSkupfer			build_ok=n
22934e5b757fSkupfer			echo "Couldn't create non-DEBUG closed binaries." |
22944e5b757fSkupfer			    tee -a $mail_msg_file >> $LOGFILE
22954e5b757fSkupfer		fi
22964e5b757fSkupfer	fi
22974e5b757fSkupfer
22984e5b757fSkupfer	export CLOSED_IS_PRESENT=no
22991fe69678Skupferfi
23001fe69678Skupfer
23011fe69678Skupferif is_source_build && [ $build_ok = y ] ; then
23024e5b757fSkupfer	# remove proto area(s) here, since we don't clobber
23034e5b757fSkupfer	rm -rf `allprotos`
23047c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
23054e5b757fSkupfer		set_non_debug_build_flags
2306b91d9e0fSdanmcd		ORIG_TOOLS=$TOOLS
23071fe69678Skupfer		#
23081fe69678Skupfer		# SRC was set earlier to point to the source build
23091fe69678Skupfer		# source tree (e.g., $EXPORT_SRC).
23101fe69678Skupfer		#
23111fe69678Skupfer		TOOLS=${SRC}/tools
23121fe69678Skupfer		build_tools ${SRC}/tools/proto
2313b91d9e0fSdanmcd		TOOLS=$ORIG_TOOLS
23147c478bd9Sstevel@tonic-gate	fi
23157c478bd9Sstevel@tonic-gate
23167c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
23177c478bd9Sstevel@tonic-gate	normal_build
23187c478bd9Sstevel@tonic-gatefi
23197c478bd9Sstevel@tonic-gate
23201fe69678Skupferif [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
23211fe69678Skupfer	rm -rf $ON_CLOSED_BINS
23221fe69678Skupferfi
23231fe69678Skupfer
23244e5b757fSkupfer#
23254e5b757fSkupfer# There are several checks that need to look at the proto area, but
23264e5b757fSkupfer# they only need to look at one, and they don't care whether it's
23274e5b757fSkupfer# DEBUG or non-DEBUG.
23284e5b757fSkupfer#
23294e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
23304e5b757fSkupfer	checkroot=$ROOT-nd
23314e5b757fSkupferelse
23324e5b757fSkupfer	checkroot=$ROOT
23334e5b757fSkupferfi
23344e5b757fSkupfer
23357c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
23367c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
23377c478bd9Sstevel@tonic-gate		>> $LOGFILE
23384e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
23397c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
23407c478bd9Sstevel@tonic-gate		>> $LOGFILE
23417c478bd9Sstevel@tonic-gate
23427c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
23437c478bd9Sstevel@tonic-gate		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
23447c478bd9Sstevel@tonic-gate
23457c478bd9Sstevel@tonic-gate		# If there is a reference proto list, compare the build's proto
23467c478bd9Sstevel@tonic-gate		# list with the reference to see changes in proto areas.
23477c478bd9Sstevel@tonic-gate		# Use the current exception list.
23487c478bd9Sstevel@tonic-gate		exc=etc/exception_list_$MACH
23497c478bd9Sstevel@tonic-gate		if [ -f $SRC/pkgdefs/$exc ]; then
23507c478bd9Sstevel@tonic-gate			ELIST="-e $SRC/pkgdefs/$exc"
23517c478bd9Sstevel@tonic-gate		fi
23526fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -f $IA32_IHV_WS/usr/src/pkgdefs/$exc ]; then
23536fec3625Sdduvall			ELIST="$ELIST -e $IA32_IHV_WS/usr/src/pkgdefs/$exc"
23546fec3625Sdduvall		fi
23557c478bd9Sstevel@tonic-gate
23567c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
2357b4add148Sdduvall			# For builds that copy the IHV proto area (-X), add the
2358b4add148Sdduvall			# IHV proto list to the reference list if the reference
2359b4add148Sdduvall			# was built without -X.
2360b4add148Sdduvall			#
2361b4add148Sdduvall			# For builds that don't copy the IHV proto area, add the
2362b4add148Sdduvall			# IHV proto list to the build's proto list if the
2363b4add148Sdduvall			# reference was built with -X.
2364b4add148Sdduvall			#
2365b4add148Sdduvall			# Use the presence of the first file entry of the cached
2366b4add148Sdduvall			# IHV proto list in the reference list to determine
2367b4add148Sdduvall			# whether it was build with -X or not.
2368b4add148Sdduvall			IHV_REF_PROTO_LIST=$SRC/pkgdefs/etc/proto_list_ihv_$MACH
2369b4add148Sdduvall			grepfor=$(nawk '$1 == "f" { print $2; exit }' \
2370b4add148Sdduvall				$IHV_REF_PROTO_LIST 2> /dev/null)
2371b4add148Sdduvall			if [ $? = 0 -a -n "$grepfor" ]; then
2372b4add148Sdduvall				if [ "$X_FLAG" = "y" ]; then
2373b4add148Sdduvall					grep -w "$grepfor" \
2374b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2375b4add148Sdduvall					if [ ! "$?" = "0" ]; then
2376b4add148Sdduvall						REF_IHV_PROTO="-d $IHV_REF_PROTO_LIST"
2377b4add148Sdduvall					fi
2378b4add148Sdduvall				else
2379b4add148Sdduvall					grep -w "$grepfor" \
2380b4add148Sdduvall						$REF_PROTO_LIST > /dev/null
2381b4add148Sdduvall					if [ "$?" = "0" ]; then
2382b4add148Sdduvall						IHV_PROTO_LIST="$IHV_REF_PROTO_LIST"
2383b4add148Sdduvall					fi
2384b4add148Sdduvall				fi
2385b4add148Sdduvall			fi
2386b4add148Sdduvall
23877c478bd9Sstevel@tonic-gate			$PROTOCMPTERSE \
23887c478bd9Sstevel@tonic-gate			  "Files in yesterday's proto area, but not today's:" \
23897c478bd9Sstevel@tonic-gate			  "Files in today's proto area, but not yesterday's:" \
23907c478bd9Sstevel@tonic-gate			  "Files that changed between yesterday and today:" \
23917c478bd9Sstevel@tonic-gate			  ${ELIST} \
23927c478bd9Sstevel@tonic-gate			  -d $REF_PROTO_LIST \
2393b4add148Sdduvall			  $REF_IHV_PROTO \
23947c478bd9Sstevel@tonic-gate			  $ATLOG/proto_list_${MACH} \
2395b4add148Sdduvall			  $IHV_PROTO_LIST \
23967c478bd9Sstevel@tonic-gate				>> $mail_msg_file
23977c478bd9Sstevel@tonic-gate		fi
23987c478bd9Sstevel@tonic-gate		# Compare the build's proto list with current package
23997c478bd9Sstevel@tonic-gate		# definitions to audit the quality of package definitions
24007c478bd9Sstevel@tonic-gate		# and makefile install targets. Use the current exception list.
2401fb23a357Skupfer		PKGDEFS_LIST=""
2402fb23a357Skupfer		for d in $abssrcdirs; do
2403fb23a357Skupfer			if [ -d $d/pkgdefs ]; then
2404fb23a357Skupfer				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
2405fb23a357Skupfer			fi
2406fb23a357Skupfer		done
24076fec3625Sdduvall		if [ "$X_FLAG" = "y" -a -d $IA32_IHV_WS/usr/src/pkgdefs ]; then
24086fec3625Sdduvall			PKGDEFS_LIST="$PKGDEFS_LIST -d $IA32_IHV_WS/usr/src/pkgdefs"
24096fec3625Sdduvall		fi
24107c478bd9Sstevel@tonic-gate
24117c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
24127c478bd9Sstevel@tonic-gate		    "Files missing from the proto area:" \
24137c478bd9Sstevel@tonic-gate		    "Files missing from packages:" \
24147c478bd9Sstevel@tonic-gate		    "Inconsistencies between pkgdefs and proto area:" \
24157c478bd9Sstevel@tonic-gate		    ${ELIST} \
24167c478bd9Sstevel@tonic-gate		    ${PKGDEFS_LIST} \
24177c478bd9Sstevel@tonic-gate		    $ATLOG/proto_list_${MACH} \
24187c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
24197c478bd9Sstevel@tonic-gate	fi
24207c478bd9Sstevel@tonic-gatefi
24217c478bd9Sstevel@tonic-gate
24227c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
24237c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
24247c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
24257c478bd9Sstevel@tonic-gatefi
24267c478bd9Sstevel@tonic-gate
24277c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
24287c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
24297c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
24307c478bd9Sstevel@tonic-gate# the variable now.
24317c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
24327c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
24337c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
24347c478bd9Sstevel@tonic-gate	# The rm -rf command below produces predictable errors if
24357c478bd9Sstevel@tonic-gate	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
24367c478bd9Sstevel@tonic-gate	# and that directory is accessed via NFS.  This is because
24377c478bd9Sstevel@tonic-gate	# deleted-but-still-open files don't actually disappear as
24387c478bd9Sstevel@tonic-gate	# expected, but rather turn into .nfsXXXX junk files, leaving
24397c478bd9Sstevel@tonic-gate	# the directory non-empty.  Since this is a not-unusual usage
24407c478bd9Sstevel@tonic-gate	# pattern, and we still want to catch other errors here, we
24417c478bd9Sstevel@tonic-gate	# take the unusal step of moving aside 'nightly' from that
24427c478bd9Sstevel@tonic-gate	# directory (if we're using it).
24437c478bd9Sstevel@tonic-gate	mypath=${0##*/root_$MACH/}
24447c478bd9Sstevel@tonic-gate	if [ "$mypath" = $0 ]; then
24457c478bd9Sstevel@tonic-gate		mypath=opt/onbld/bin/${0##*/}
24467c478bd9Sstevel@tonic-gate	fi
24477c478bd9Sstevel@tonic-gate	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
24487c478bd9Sstevel@tonic-gate		mv -f $0 $PARENT_WS/proto/root_$MACH
24497c478bd9Sstevel@tonic-gate	fi
24507c478bd9Sstevel@tonic-gate	rm -rf $PARENT_WS/proto/root_$MACH/*
24517c478bd9Sstevel@tonic-gate	unset Ulockfile
24527c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
24534e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
24547c478bd9Sstevel@tonic-gate		cd $ROOT
24554e5b757fSkupfer		( tar cf - . |
24564e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
24577c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
24587c478bd9Sstevel@tonic-gate	fi
24594e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
24604e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
24614e5b757fSkupfer		cd $ROOT-nd
24624e5b757fSkupfer		( tar cf - . |
24634e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
24644e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
24654e5b757fSkupfer	fi
24664e5b757fSkupferfi
24677c478bd9Sstevel@tonic-gate
24687c478bd9Sstevel@tonic-gate#
24697c478bd9Sstevel@tonic-gate# do shared library interface verification
24707c478bd9Sstevel@tonic-gate#
24717c478bd9Sstevel@tonic-gate
24727c478bd9Sstevel@tonic-gateif [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
24737c478bd9Sstevel@tonic-gate	echo "\n==== Check versioning and ABI information ====\n"  | \
24747c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
24757c478bd9Sstevel@tonic-gate
24767c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.ref
24777c478bd9Sstevel@tonic-gate	if [ -d $SRC/interfaces.out ]; then
24787c478bd9Sstevel@tonic-gate		mv $SRC/interfaces.out $SRC/interfaces.ref
24797c478bd9Sstevel@tonic-gate	fi
24807c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.out
24817c478bd9Sstevel@tonic-gate	mkdir -p $SRC/interfaces.out
24827c478bd9Sstevel@tonic-gate
24837c478bd9Sstevel@tonic-gate	intf_check -V -m -o -b $SRC/tools/abi/etc \
24844e5b757fSkupfer		-d $SRC/interfaces.out $checkroot 2>&1 | sort \
24857c478bd9Sstevel@tonic-gate		> $SRC/interfaces.out/log
24867c478bd9Sstevel@tonic-gate
24877c478bd9Sstevel@tonic-gate	# report any ERROR found in log file
24887c478bd9Sstevel@tonic-gate	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
24897c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
24907c478bd9Sstevel@tonic-gate
24917c478bd9Sstevel@tonic-gate	if [ ! -d $SRC/interfaces.ref ] ; then
24927c478bd9Sstevel@tonic-gate		mkdir -p $SRC/interfaces.ref
24937c478bd9Sstevel@tonic-gate		if [ -d  $SRC/interfaces.out ]; then
24947c478bd9Sstevel@tonic-gate			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
24957c478bd9Sstevel@tonic-gate		fi
24967c478bd9Sstevel@tonic-gate	fi
24977c478bd9Sstevel@tonic-gate
24987c478bd9Sstevel@tonic-gate	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
24997c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25007c478bd9Sstevel@tonic-gate
25017c478bd9Sstevel@tonic-gate	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
25027c478bd9Sstevel@tonic-gate	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
25037c478bd9Sstevel@tonic-gate
25047c478bd9Sstevel@tonic-gate	# Report any differences in WARNING messages between last
25057c478bd9Sstevel@tonic-gate	# and current build.
25067c478bd9Sstevel@tonic-gate	if [ "$out_vers" = "$ref_vers" ]; then
25077c478bd9Sstevel@tonic-gate		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
25087c478bd9Sstevel@tonic-gate		    fgrep 'WARNING' | sed 's/WARNING: //' | \
25097c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
25107c478bd9Sstevel@tonic-gate	fi
25117c478bd9Sstevel@tonic-gatefi
25127c478bd9Sstevel@tonic-gate
25137c478bd9Sstevel@tonic-gateif [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
25147c478bd9Sstevel@tonic-gate	echo "\n==== Check ELF runtime attributes ====\n" | \
25157c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25167c478bd9Sstevel@tonic-gate
25177c478bd9Sstevel@tonic-gate	LDDUSAGE="^ldd: does not support -e"
25187c478bd9Sstevel@tonic-gate	LDDWRONG="wrong class"
25197c478bd9Sstevel@tonic-gate	CRLERROR="^crle:"
25207c478bd9Sstevel@tonic-gate	CRLECONF="^crle: configuration file:"
25217c478bd9Sstevel@tonic-gate
25227c478bd9Sstevel@tonic-gate	rm -f $SRC/runtime.ref
25237c478bd9Sstevel@tonic-gate	if [ -f $SRC/runtime.out ]; then
25247c478bd9Sstevel@tonic-gate		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
25257c478bd9Sstevel@tonic-gate			$SRC/runtime.out > $SRC/runtime.ref
25267c478bd9Sstevel@tonic-gate	fi
25277c478bd9Sstevel@tonic-gate
25287c478bd9Sstevel@tonic-gate	# If we're doing a debug build the proto area will be left with
25297c478bd9Sstevel@tonic-gate	# debuggable objects, thus don't assert -s.
25307c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
25317c478bd9Sstevel@tonic-gate		rtime_sflag=""
25327c478bd9Sstevel@tonic-gate	else
25337c478bd9Sstevel@tonic-gate		rtime_sflag="-s"
25347c478bd9Sstevel@tonic-gate	fi
25354e5b757fSkupfer	check_rtime -d $checkroot -i -m -o $rtime_sflag $checkroot 2>&1 | \
25364e5b757fSkupfer	    egrep -v ": unreferenced object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
25374e5b757fSkupfer	    egrep -v ": unused object=$checkroot/.*/lib(w|intl|thread|pthread).so" | \
25387c478bd9Sstevel@tonic-gate	    sort >$SRC/runtime.out
25397c478bd9Sstevel@tonic-gate
25407c478bd9Sstevel@tonic-gate	# Determine any processing errors that will affect the final output
25417c478bd9Sstevel@tonic-gate	# and display these first.
25427c478bd9Sstevel@tonic-gate	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
25437c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
25447c478bd9Sstevel@tonic-gate	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
25457c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25467c478bd9Sstevel@tonic-gate	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
25477c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25487c478bd9Sstevel@tonic-gate	fi
25497c478bd9Sstevel@tonic-gate	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
25507c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
25517c478bd9Sstevel@tonic-gate	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
25527c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25537c478bd9Sstevel@tonic-gate	    echo "to execute an object, thus it could not be checked fully." | \
25547c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25557c478bd9Sstevel@tonic-gate	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
25567c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25577c478bd9Sstevel@tonic-gate	    echo "or an i386 object was encountered on a sparc system?\n" | \
25587c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25597c478bd9Sstevel@tonic-gate	fi
25607c478bd9Sstevel@tonic-gate	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
25617c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
25627c478bd9Sstevel@tonic-gate	    echo "WARNING: creation of an alternative dependency cache failed." | \
25637c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25647c478bd9Sstevel@tonic-gate	    echo "Dependencies will bind to the base system libraries.\n" | \
25657c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25667c478bd9Sstevel@tonic-gate	    grep "$CRLECONF" $SRC/runtime.out | \
25677c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25687c478bd9Sstevel@tonic-gate	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
25697c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
25707c478bd9Sstevel@tonic-gate	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
25717c478bd9Sstevel@tonic-gate	fi
25727c478bd9Sstevel@tonic-gate
25737c478bd9Sstevel@tonic-gate	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
25747c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
25757c478bd9Sstevel@tonic-gate
25767c478bd9Sstevel@tonic-gate	# NEEDED= and RPATH= are informational; report anything else that we
25777c478bd9Sstevel@tonic-gate	# haven't already.
25787c478bd9Sstevel@tonic-gate	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
25797c478bd9Sstevel@tonic-gate	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
25807c478bd9Sstevel@tonic-gate
25817c478bd9Sstevel@tonic-gate	# probably should compare against a 'known ok runpaths' list
25827c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/runtime.ref ]; then
25837c478bd9Sstevel@tonic-gate		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
25847c478bd9Sstevel@tonic-gate			$SRC/runtime.out >  $SRC/runtime.ref
25857c478bd9Sstevel@tonic-gate	fi
25867c478bd9Sstevel@tonic-gate
25877c478bd9Sstevel@tonic-gate	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
25887c478bd9Sstevel@tonic-gate	    >> $mail_msg_file
25897c478bd9Sstevel@tonic-gate
25907c478bd9Sstevel@tonic-gate	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
25917c478bd9Sstevel@tonic-gate	    diff $SRC/runtime.ref - >> $mail_msg_file
25927c478bd9Sstevel@tonic-gatefi
25937c478bd9Sstevel@tonic-gate
25947c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
25957c478bd9Sstevel@tonic-gate
25967c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
25977c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
25987c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
25997c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
26007c478bd9Sstevel@tonic-gate	fi
26017c478bd9Sstevel@tonic-gate	set $LINTDIRS
26027c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
26037c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
26047c478bd9Sstevel@tonic-gate	done
26057c478bd9Sstevel@tonic-gateelse
26067c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
26077c478bd9Sstevel@tonic-gatefi
26087c478bd9Sstevel@tonic-gate
26097c478bd9Sstevel@tonic-gate# "make check" begins
26107c478bd9Sstevel@tonic-gate
26117c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
26127c478bd9Sstevel@tonic-gate	# remove old check.out
26137c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
26147c478bd9Sstevel@tonic-gate
26157c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
26167c478bd9Sstevel@tonic-gate	cd $SRC
26177c478bd9Sstevel@tonic-gate	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
26187c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
26197c478bd9Sstevel@tonic-gate
26207c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
26217c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
26227c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
26237c478bd9Sstevel@tonic-gateelse
26247c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
26257c478bd9Sstevel@tonic-gatefi
26267c478bd9Sstevel@tonic-gate
26277c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
26287c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
26297c478bd9Sstevel@tonic-gate
2630fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
26317c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
26327c478bd9Sstevel@tonic-gate
26337c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
26347c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
26357c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
26367c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
26377c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
26387c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
26397c478bd9Sstevel@tonic-gate	fi
26407c478bd9Sstevel@tonic-gate
2641fb23a357Skupfer	findunref -t $SRC/.build.tstamp $SRC/.. \
2642fb23a357Skupfer	    ${TOOLS}/findunref/exception_list \
2643fb23a357Skupfer	    2>> $mail_msg_file | sort | \
2644fb23a357Skupfer	    sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
2645fb23a357Skupfer	    > $SRC/unref-${MACH}.out
26467c478bd9Sstevel@tonic-gate
26477c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
26487c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
26497c478bd9Sstevel@tonic-gate	fi
26507c478bd9Sstevel@tonic-gate
26517c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
26527c478bd9Sstevel@tonic-gatefi
26537c478bd9Sstevel@tonic-gate
26547c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
26557c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
26567c478bd9Sstevel@tonic-gate# then don't check the proto area.
26577c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
26587c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
26597c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
26607c478bd9Sstevel@tonic-gate		>>$mail_msg_file
26617c478bd9Sstevel@tonic-gate	arg=-b
26627c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
26634e5b757fSkupfer	checkpaths $arg $checkroot 2>&1 | tee -a $LOGFILE >>$mail_msg_file
26647c478bd9Sstevel@tonic-gatefi
26657c478bd9Sstevel@tonic-gate
26667c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
26677c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
26687c478bd9Sstevel@tonic-gate		>> $mail_msg_file
26697c478bd9Sstevel@tonic-gate	#
26707c478bd9Sstevel@tonic-gate	# Get pkginfo files from usr/src/pkgdefs
26717c478bd9Sstevel@tonic-gate	#
26727c478bd9Sstevel@tonic-gate	pmodes -qvdP \
2673fb9f9b97Skupfer	`for d in $abssrcdirs; do
2674fb9f9b97Skupfer		if [ -d "$d/pkgdefs" ]
26757c478bd9Sstevel@tonic-gate		then
2676fb9f9b97Skupfer			find $d/pkgdefs -name pkginfo.tmpl -print -o -name .del\* -prune
26777c478bd9Sstevel@tonic-gate		fi
26787c478bd9Sstevel@tonic-gate	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
26797c478bd9Sstevel@tonic-gatefi
26807c478bd9Sstevel@tonic-gate
268196ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
26824e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
26834e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
26844e5b757fSkupfer	fi
268596ccc8cbSesaxe
26864e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
26874e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
268896ccc8cbSesaxe	fi
268996ccc8cbSesaxefi
269096ccc8cbSesaxe
26917c478bd9Sstevel@tonic-gateEND_DATE=`date`
26927c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
26937c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
26947c478bd9Sstevel@tonic-gate
26957c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
26967c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
26977c478bd9Sstevel@tonic-gate
26987c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
26997c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
27007c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
27017c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
27027c478bd9Sstevel@tonic-gate
27037c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
27047c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
27057c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
27067c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
27077c478bd9Sstevel@tonic-gate
27087c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
27097c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
27107c478bd9Sstevel@tonic-gate
27117c478bd9Sstevel@tonic-gate	#
27127c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
27137c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
27147c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
27157c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
27167c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
27177c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
27187c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
27197c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
27207c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
27217c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
27227c478bd9Sstevel@tonic-gate	# which was already on the parent.
27237c478bd9Sstevel@tonic-gate	#
27247c478bd9Sstevel@tonic-gate
27257c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
27267c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
27277c478bd9Sstevel@tonic-gate	shift
27287c478bd9Sstevel@tonic-gate
27297c478bd9Sstevel@tonic-gate	for unreffile; do
27307c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
27317c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
27327c478bd9Sstevel@tonic-gate	done
27337c478bd9Sstevel@tonic-gate
27347c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
27357c478bd9Sstevel@tonic-gatefi
27367c478bd9Sstevel@tonic-gate
27377c478bd9Sstevel@tonic-gate#
27387c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
27397c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
27407c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
27417c478bd9Sstevel@tonic-gate#
27427c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
27437c478bd9Sstevel@tonic-gate	exit 0
27447c478bd9Sstevel@tonic-gatefi
27457c478bd9Sstevel@tonic-gateexit 1
2746