xref: /titanic_51/usr/src/tools/scripts/nightly.sh (revision fb23a357ee0d7777211dcda3cd121f4fa8e36260)
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
6*fb23a357Skupfer# Common Development and Distribution License (the "License").
7*fb23a357Skupfer# 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#
227c478bd9Sstevel@tonic-gate#
237c478bd9Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate#
287c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
297c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
307c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
337c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
347c478bd9Sstevel@tonic-gate#
357c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
367c478bd9Sstevel@tonic-gate# command line (only), lint, check, GPROF and TRACE builds are skipped
377c478bd9Sstevel@tonic-gate# no matter what the setting of their individual flags are in NIGHTLY_OPTIONS.
387c478bd9Sstevel@tonic-gate#
397c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
407c478bd9Sstevel@tonic-gate#
417c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
427c478bd9Sstevel@tonic-gate#
437c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
447c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
457c478bd9Sstevel@tonic-gate#
467c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
477c478bd9Sstevel@tonic-gate#
487c478bd9Sstevel@tonic-gate# -A flag in NIGHTLY_OPTIONS checks ABI diffs in .so files
497c478bd9Sstevel@tonic-gate# This option requires a couple of scripts.
507c478bd9Sstevel@tonic-gate#
517c478bd9Sstevel@tonic-gate# OPTHOME and TEAMWARE may be set in the environment to override /opt
527c478bd9Sstevel@tonic-gate# and /opt/teamware defaults.
537c478bd9Sstevel@tonic-gate#
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate#
567c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
577c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
587c478bd9Sstevel@tonic-gate#
597c478bd9Sstevel@tonic-gateunset CDPATH
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate# function to do a DEBUG and non-DEBUG build. Needed because we might
627c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
637c478bd9Sstevel@tonic-gate# non-DEBUG packages.
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gatenormal_build() {
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate	# timestamp the start of a nightly build; the findunref tool uses it.
687c478bd9Sstevel@tonic-gate	touch $SRC/.build.tstamp
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
737c478bd9Sstevel@tonic-gate		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
747c478bd9Sstevel@tonic-gate		export RELEASE_BUILD ; RELEASE_BUILD=
757c478bd9Sstevel@tonic-gate		unset EXTRA_OPTIONS
767c478bd9Sstevel@tonic-gate		unset EXTRA_CFLAGS
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate		build non-DEBUG -nd
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a "$p_FLAG" = "y" ]; then
817c478bd9Sstevel@tonic-gate			copy_ihv_pkgs non-DEBUG -nd
827c478bd9Sstevel@tonic-gate		fi
837c478bd9Sstevel@tonic-gate	else
847c478bd9Sstevel@tonic-gate		echo "\n==== No non-DEBUG build ====\n" >> $LOGFILE
857c478bd9Sstevel@tonic-gate	fi
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate	# DEBUG build begins
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
947c478bd9Sstevel@tonic-gate		unset RELEASE_BUILD
957c478bd9Sstevel@tonic-gate		unset EXTRA_OPTIONS
967c478bd9Sstevel@tonic-gate		unset EXTRA_CFLAGS
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate		build DEBUG ""
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate		if [ "$build_ok" = "y" -a "$X_FLAG" = "y" -a "$p_FLAG" = "y" ]; then
1017c478bd9Sstevel@tonic-gate			copy_ihv_pkgs DEBUG ""
1027c478bd9Sstevel@tonic-gate		fi
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate	else
1057c478bd9Sstevel@tonic-gate		echo "\n==== No DEBUG build ====\n" >> $LOGFILE
1067c478bd9Sstevel@tonic-gate	fi
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate	# DEBUG build ends
1097c478bd9Sstevel@tonic-gate}
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gatefilelist() {
1127c478bd9Sstevel@tonic-gate	if  [ $# -ne 2 ]; then
1137c478bd9Sstevel@tonic-gate		echo "usage: filelist DESTDIR PATTERN"
1147c478bd9Sstevel@tonic-gate		exit 1;
1157c478bd9Sstevel@tonic-gate	fi
1167c478bd9Sstevel@tonic-gate	DEST=$1
1177c478bd9Sstevel@tonic-gate	PATTERN=$2
1187c478bd9Sstevel@tonic-gate	cd ${DEST}
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate	OBJFILES=${ORIG_SRC}/xmod/obj_files
1217c478bd9Sstevel@tonic-gate	if [ ! -f ${OBJFILES} ]; then
1227c478bd9Sstevel@tonic-gate		return;
1237c478bd9Sstevel@tonic-gate	fi
1247c478bd9Sstevel@tonic-gate	for i in `grep -v '^#' ${ORIG_SRC}/xmod/obj_files | \
1257c478bd9Sstevel@tonic-gate	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
1267c478bd9Sstevel@tonic-gate	do
1277c478bd9Sstevel@tonic-gate		# wildcard expansion
1287c478bd9Sstevel@tonic-gate		for j in $i
1297c478bd9Sstevel@tonic-gate		do
1307c478bd9Sstevel@tonic-gate			if [ -f "$j" ]; then
1317c478bd9Sstevel@tonic-gate				echo $j
1327c478bd9Sstevel@tonic-gate			fi
1337c478bd9Sstevel@tonic-gate			if [ -d "$j" ]; then
1347c478bd9Sstevel@tonic-gate				echo $j
1357c478bd9Sstevel@tonic-gate			fi
1367c478bd9Sstevel@tonic-gate		done
1377c478bd9Sstevel@tonic-gate	done | sort | uniq
1387c478bd9Sstevel@tonic-gate}
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate# function to save off binaries after a full build for later
1417c478bd9Sstevel@tonic-gate# restoration
1427c478bd9Sstevel@tonic-gatesave_binaries() {
1437c478bd9Sstevel@tonic-gate	# save off list of binaries
1447c478bd9Sstevel@tonic-gate	echo "\n==== Saving binaries from build at `date` ====\n" | \
1457c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1467c478bd9Sstevel@tonic-gate	rm -f ${BINARCHIVE}
1477c478bd9Sstevel@tonic-gate	cd ${CODEMGR_WS}
1487c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' >> $LOGFILE
1497c478bd9Sstevel@tonic-gate	filelist ${CODEMGR_WS} '^preserve:' | \
1507c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | compress \
1517c478bd9Sstevel@tonic-gate	    > ${BINARCHIVE}
1527c478bd9Sstevel@tonic-gate}
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate# delete files
1557c478bd9Sstevel@tonic-gatehybridize_files() {
1567c478bd9Sstevel@tonic-gate	if  [ $# -ne 2 ]; then
1577c478bd9Sstevel@tonic-gate		echo "usage: hybridize_files DESTDIR MAKE_TARGET"
1587c478bd9Sstevel@tonic-gate		exit 1;
1597c478bd9Sstevel@tonic-gate	fi
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate	DEST=$1
1627c478bd9Sstevel@tonic-gate	MAKETARG=$2
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate	echo "\n==== Hybridizing files at `date` ====\n" | \
1657c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1667c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^delete:'`
1677c478bd9Sstevel@tonic-gate	do
1687c478bd9Sstevel@tonic-gate		echo "removing ${i}." | tee -a $mail_msg_file >> $LOGFILE
1697c478bd9Sstevel@tonic-gate		rm -rf "${i}"
1707c478bd9Sstevel@tonic-gate	done
1717c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^hybridize:' `
1727c478bd9Sstevel@tonic-gate	do
1737c478bd9Sstevel@tonic-gate		echo "hybridizing ${i}." | tee -a $mail_msg_file >> $LOGFILE
1747c478bd9Sstevel@tonic-gate		rm -f ${i}+
1757c478bd9Sstevel@tonic-gate		sed -e "/^# HYBRID DELETE START/,/^# HYBRID DELETE END/d" \
1767c478bd9Sstevel@tonic-gate		    < ${i} > ${i}+
1777c478bd9Sstevel@tonic-gate		mv ${i}+ ${i}
1787c478bd9Sstevel@tonic-gate	done
1797c478bd9Sstevel@tonic-gate}
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate# restore binaries into the proper source tree.
1827c478bd9Sstevel@tonic-gaterestore_binaries() {
1837c478bd9Sstevel@tonic-gate	if  [ $# -ne 2 ]; then
1847c478bd9Sstevel@tonic-gate		echo "usage: restore_binaries DESTDIR MAKE_TARGET"
1857c478bd9Sstevel@tonic-gate		exit 1;
1867c478bd9Sstevel@tonic-gate	fi
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate	DEST=$1
1897c478bd9Sstevel@tonic-gate	MAKETARG=$2
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate	echo "\n==== Restoring binaries to ${MAKETARG} at `date` ====\n" | \
1927c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
1937c478bd9Sstevel@tonic-gate	cd ${DEST}
1947c478bd9Sstevel@tonic-gate	zcat ${BINARCHIVE} | \
1957c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null | tee -a $mail_msg_file >> ${LOGFILE}
1967c478bd9Sstevel@tonic-gate}
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate# rename files we save binaries of
1997c478bd9Sstevel@tonic-gaterename_files() {
2007c478bd9Sstevel@tonic-gate	if  [ $# -ne 2 ]; then
2017c478bd9Sstevel@tonic-gate		echo "usage: rename_files DESTDIR MAKE_TARGET"
2027c478bd9Sstevel@tonic-gate		exit 1;
2037c478bd9Sstevel@tonic-gate	fi
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate	DEST=$1
2067c478bd9Sstevel@tonic-gate	MAKETARG=$2
2077c478bd9Sstevel@tonic-gate	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
2087c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2097c478bd9Sstevel@tonic-gate	for i in `filelist ${DEST} '^rename:'`
2107c478bd9Sstevel@tonic-gate	do
2117c478bd9Sstevel@tonic-gate		echo ${i} | tee -a $mail_msg_file >> ${LOGFILE}
2127c478bd9Sstevel@tonic-gate		rm -f ${i}.export
2137c478bd9Sstevel@tonic-gate		mv ${i} ${i}.export
2147c478bd9Sstevel@tonic-gate	done
2157c478bd9Sstevel@tonic-gate}
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate# function to create the export/crypt source tree
2187c478bd9Sstevel@tonic-gate# usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gateclone_source() {
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate	if  [ $# -ne 3 ]; then
2237c478bd9Sstevel@tonic-gate		echo "usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET"
2247c478bd9Sstevel@tonic-gate		exit 1;
2257c478bd9Sstevel@tonic-gate	fi
2267c478bd9Sstevel@tonic-gate	WS=$1
2277c478bd9Sstevel@tonic-gate	DEST=$2
2287c478bd9Sstevel@tonic-gate	MAKETARG=$3
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${DEST} source from ${WS} (${MAKETARG}) ====\n" | \
2317c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate	echo "cleaning out ${DEST}." >> $LOGFILE
2347c478bd9Sstevel@tonic-gate	rm -rf "${DEST}" >> $LOGFILE 2>&1
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate	mkdir -p ${DEST}
2377c478bd9Sstevel@tonic-gate	cd ${WS}
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate	echo "creating ${DEST}." >> $LOGFILE
240*fb23a357Skupfer	find usr -name 's\.*' -a -type f -print | \
2417c478bd9Sstevel@tonic-gate	    sed -e 's,SCCS\/s.,,' | \
2427c478bd9Sstevel@tonic-gate	    grep -v '/\.del-*' | \
2437c478bd9Sstevel@tonic-gate	    cpio -pd ${DEST} >>$LOGFILE 2>&1
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate	SRC=${DEST}/usr/src
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate	cd $SRC
2487c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.out
2497c478bd9Sstevel@tonic-gate	echo "making ${MAKETARG} in ${SRC}." >> $LOGFILE
2507c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e ${MAKETARG} 2>&1 | \
2517c478bd9Sstevel@tonic-gate	    tee -a $SRC/${MAKETARG}.out >> $LOGFILE
2527c478bd9Sstevel@tonic-gate	echo "\n==== ${MAKETARG} build errors ====\n" >> $mail_msg_file
2537c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${MAKETARG}.out | \
2547c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
2557c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
2567c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate	echo "clearing state files." >> $LOGFILE
2597c478bd9Sstevel@tonic-gate	find . -name '.make*' -exec rm -f {} \;
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate	cd ${DEST}
2627c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
2637c478bd9Sstevel@tonic-gate		rm -f ${CODEMGR_WS}/crypt_files.cpio.Z
2647c478bd9Sstevel@tonic-gate		echo "\n==== xmod/cry_files that don't exist ====\n" | \
2657c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
2667c478bd9Sstevel@tonic-gate		CRYPT_FILES=${WS}/usr/src/xmod/cry_files
2677c478bd9Sstevel@tonic-gate		for i in `cat ${CRYPT_FILES}`
2687c478bd9Sstevel@tonic-gate		do
2697c478bd9Sstevel@tonic-gate			# make sure the files exist
2707c478bd9Sstevel@tonic-gate			if [ -f "$i" ]; then
2717c478bd9Sstevel@tonic-gate				continue
2727c478bd9Sstevel@tonic-gate			fi
2737c478bd9Sstevel@tonic-gate			if [ -d "$i" ]; then
2747c478bd9Sstevel@tonic-gate				continue
2757c478bd9Sstevel@tonic-gate			fi
2767c478bd9Sstevel@tonic-gate			echo "$i" | tee -a $mail_msg_file >> $LOGFILE
2777c478bd9Sstevel@tonic-gate		done
2787c478bd9Sstevel@tonic-gate		find `cat ${CRYPT_FILES}` -print 2>/dev/null | \
2797c478bd9Sstevel@tonic-gate		    cpio -ocB 2>/dev/null | \
2807c478bd9Sstevel@tonic-gate		    compress > ${CODEMGR_WS}/crypt_files.cpio.Z
2817c478bd9Sstevel@tonic-gate	fi
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
2847c478bd9Sstevel@tonic-gate		# rename first, since we might restore a file
2857c478bd9Sstevel@tonic-gate		# of the same name (mapfiles)
2867c478bd9Sstevel@tonic-gate		rename_files ${EXPORT_SRC} EXPORT_SRC
2877c478bd9Sstevel@tonic-gate		if [ "$SH_FLAG" = "y" ]; then
2887c478bd9Sstevel@tonic-gate			hybridize_files ${EXPORT_SRC} EXPORT_SRC
2897c478bd9Sstevel@tonic-gate		fi
2907c478bd9Sstevel@tonic-gate	fi
2917c478bd9Sstevel@tonic-gate
2927c478bd9Sstevel@tonic-gate	# save the cleartext
2937c478bd9Sstevel@tonic-gate	echo "\n==== Creating ${MAKETARG}.cpio.Z ====\n" | \
2947c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
2957c478bd9Sstevel@tonic-gate	cd ${DEST}
2967c478bd9Sstevel@tonic-gate	rm -f ${MAKETARG}.cpio.Z
297*fb23a357Skupfer	find usr -depth -print | \
2987c478bd9Sstevel@tonic-gate	    grep -v usr/src/${MAKETARG}.out | \
2997c478bd9Sstevel@tonic-gate	    cpio -ocB 2>/dev/null | \
3007c478bd9Sstevel@tonic-gate	    compress > ${CODEMGR_WS}/${MAKETARG}.cpio.Z
3017c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "EXPORT_SRC" ]; then
3027c478bd9Sstevel@tonic-gate		restore_binaries ${EXPORT_SRC} EXPORT_SRC
3037c478bd9Sstevel@tonic-gate	fi
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate	if [ "${MAKETARG}" = "CRYPT_SRC" ]; then
3067c478bd9Sstevel@tonic-gate		restore_binaries ${CRYPT_SRC} CRYPT_SRC
3077c478bd9Sstevel@tonic-gate	fi
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate}
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate# function to do the build.
3127c478bd9Sstevel@tonic-gate# usage: build LABEL SUFFIX
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gatebuild() {
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate	if  [ $# -ne 2 ]; then
3177c478bd9Sstevel@tonic-gate		echo "usage: build LABEL SUFFIX"
3187c478bd9Sstevel@tonic-gate		exit 1;
3197c478bd9Sstevel@tonic-gate	fi
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate	LABEL=$1
3227c478bd9Sstevel@tonic-gate	SUFFIX=$2
3237c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
3247c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
3257c478bd9Sstevel@tonic-gate	CPIODIR=${CPIODIR_ORIG}${SUFFIX}
3267c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
327d8fd4470Sjg	if [ "$SPARC_RM_PKGARCHIVE_ORIG" ]; then
328d8fd4470Sjg		SPARC_RM_PKGARCHIVE=${SPARC_RM_PKGARCHIVE_ORIG}${SUFFIX}
329d8fd4470Sjg	fi
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate	#remove old logs
3327c478bd9Sstevel@tonic-gate	OLDINSTALLOG=install${SUFFIX}
3337c478bd9Sstevel@tonic-gate	OLDNOISE=noise${SUFFIX}
3347c478bd9Sstevel@tonic-gate	rm -f $SRC/${OLDINSTALLOG}.out
3357c478bd9Sstevel@tonic-gate	rm -f $SRC/${OLDNOISE}.ref
3367c478bd9Sstevel@tonic-gate	if [ -f $SRC/${OLDNOISE}.out ]; then
3377c478bd9Sstevel@tonic-gate		mv $SRC/${OLDNOISE}.out $SRC/${NOISE}.ref
3387c478bd9Sstevel@tonic-gate	fi
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate	this_build_ok=y
3417c478bd9Sstevel@tonic-gate	#
3427c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
3437c478bd9Sstevel@tonic-gate	#
3447c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
3457c478bd9Sstevel@tonic-gate		>> $LOGFILE
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
3487c478bd9Sstevel@tonic-gate	cd $SRC
3497c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
3507c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
3517c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
3527c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
3537c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
3547c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
3557c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
3567c478bd9Sstevel@tonic-gate		egrep -v "warning" >> $mail_msg_file
3577c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
3587c478bd9Sstevel@tonic-gate		build_ok=n
3597c478bd9Sstevel@tonic-gate		this_build_ok=n
3607c478bd9Sstevel@tonic-gate	fi
3617c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
3627c478bd9Sstevel@tonic-gate		>> $mail_msg_file
3637c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
3647c478bd9Sstevel@tonic-gate		build_ok=n
3657c478bd9Sstevel@tonic-gate		this_build_ok=n
3667c478bd9Sstevel@tonic-gate	fi
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate	if [ "$W_FLAG" = "n" ]; then
3697c478bd9Sstevel@tonic-gate		echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
3707c478bd9Sstevel@tonic-gate		# should be none, but there are a few that are pmake
3717c478bd9Sstevel@tonic-gate		# related, and a couple of silly ones.
3727c478bd9Sstevel@tonic-gate		egrep -i warning: $SRC/${INSTALLOG}.out \
3737c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
3747c478bd9Sstevel@tonic-gate			| egrep -v '^mcs:' \
3757c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
3767c478bd9Sstevel@tonic-gate			| egrep -v 'multiple use of -K option' \
3777c478bd9Sstevel@tonic-gate			| egrep -v 'option -I appears more than once' \
3787c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
3797c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
3807c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
3817c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
3827c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
3837c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
3847c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
3857c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
3867c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
3877c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
3887c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
3897c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
3907c478bd9Sstevel@tonic-gate			| egrep -v 'option -zdefs/nodefs appears more than' \
3917c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
3927c478bd9Sstevel@tonic-gate			| egrep -v "parameter <PSTAMP> set to" \
3937c478bd9Sstevel@tonic-gate			| egrep -v "^Manifying" \
3947c478bd9Sstevel@tonic-gate			| egrep -v "Ignoring unknown host" \
3957c478bd9Sstevel@tonic-gate			| egrep -v "redefining segment flags attribute for" \
3967c478bd9Sstevel@tonic-gate			>> $mail_msg_file
3977c478bd9Sstevel@tonic-gate	fi
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
4007c478bd9Sstevel@tonic-gate		>> $LOGFILE
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
4037c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "n" -a "$W_FLAG" = "n" ]; then
4067c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
4077c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
4087c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
4097c478bd9Sstevel@tonic-gate		fi
4107c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
4117c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
4127c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
4137c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
4147c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
4157c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
4167c478bd9Sstevel@tonic-gate			| egrep -v 'multiple use of -K option' \
4177c478bd9Sstevel@tonic-gate			| egrep -v 'option -I appears more than once' \
4187c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
4197c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
4207c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
4217c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
4227c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
4237c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
4247c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
4257c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
4267c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
4277c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
4287c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
4297c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
4307c478bd9Sstevel@tonic-gate			| egrep -v 'option -zdefs/nodefs appears more than' \
4317c478bd9Sstevel@tonic-gate			| egrep -v "symbol \`timezone' has differing types:" \
4327c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
4337c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
4347c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
4357c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
4367c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
4377c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
4387c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
4397c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
4407c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
4417c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
4427c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
4437c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
4447c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
4457c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
4467c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
4477c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
4487c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
4497c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
4507c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
4517c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
4527c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
4537c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
4547c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
4557c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
4567c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
4577c478bd9Sstevel@tonic-gate			| egrep -v '::' \
4587c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
459010b217aSwesolows			| egrep -v '^\+' \
4607c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
4617c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
4627c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
4637c478bd9Sstevel@tonic-gate		fi
4647c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
4657c478bd9Sstevel@tonic-gate			>>$mail_msg_file
4667c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
4677c478bd9Sstevel@tonic-gate	fi
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate	#
4707c478bd9Sstevel@tonic-gate	#	Create cpio archives for preintegration testing (PIT)
4717c478bd9Sstevel@tonic-gate	#
4727c478bd9Sstevel@tonic-gate	if [ "$a_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
4737c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL cpio archives at `date` ====\n" \
4747c478bd9Sstevel@tonic-gate			>> $LOGFILE
4757c478bd9Sstevel@tonic-gate		makebfu_file="${TMPDIR}/makebfu"
4767c478bd9Sstevel@tonic-gate		rm -f ${makebfu_file}
4777c478bd9Sstevel@tonic-gate		makebfu 2>&1 | \
4787c478bd9Sstevel@tonic-gate			tee -a ${makebfu_file} >> $LOGFILE
4797c478bd9Sstevel@tonic-gate		echo "\n==== cpio archives build errors ($LABEL) ====\n" \
4807c478bd9Sstevel@tonic-gate			>> $mail_msg_file
4817c478bd9Sstevel@tonic-gate		grep -v "^Creating .* archive:" ${makebfu_file} | \
4827c478bd9Sstevel@tonic-gate			grep -v "^Making" | \
4837c478bd9Sstevel@tonic-gate			grep -v "^$" | \
4847c478bd9Sstevel@tonic-gate			sort | uniq >> $mail_msg_file
4857c478bd9Sstevel@tonic-gate		rm -f ${makebfu_file}
4867c478bd9Sstevel@tonic-gate		# hack for test folks
4877c478bd9Sstevel@tonic-gate		if [ -z "`echo $PARENT_WS|egrep '^\/ws\/'`" ]; then
4887c478bd9Sstevel@tonic-gate			X=/net/`uname -n`${CPIODIR}
4897c478bd9Sstevel@tonic-gate		else
4907c478bd9Sstevel@tonic-gate			X=${CPIODIR}
4917c478bd9Sstevel@tonic-gate		fi
4927c478bd9Sstevel@tonic-gate		echo "Archive_directory: ${X}" >${TMPDIR}/f
4937c478bd9Sstevel@tonic-gate		cp ${TMPDIR}/f ${CPIODIR}/../../.${MACH}_wgtrun
4947c478bd9Sstevel@tonic-gate		rm -f ${TMPDIR}/f
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate	else
4977c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL cpio archives ====\n" \
4987c478bd9Sstevel@tonic-gate			>> $LOGFILE
4997c478bd9Sstevel@tonic-gate	fi
5007c478bd9Sstevel@tonic-gate
5017c478bd9Sstevel@tonic-gate	#
5027c478bd9Sstevel@tonic-gate	#	Building Packages
5037c478bd9Sstevel@tonic-gate	#
5047c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
5057c478bd9Sstevel@tonic-gate		echo "\n==== Creating $LABEL packages at `date` ====\n" \
5067c478bd9Sstevel@tonic-gate			>> $LOGFILE
5077c478bd9Sstevel@tonic-gate		rm -f $SRC/pkgdefs/${INSTALLOG}.out
5087c478bd9Sstevel@tonic-gate		echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
5097c478bd9Sstevel@tonic-gate		rm -rf $PKGARCHIVE
5107c478bd9Sstevel@tonic-gate		mkdir -p $PKGARCHIVE
511d8fd4470Sjg
512d8fd4470Sjg		#
513d8fd4470Sjg		# Optional build of sparc realmode on i386
514d8fd4470Sjg		#
515d8fd4470Sjg		if [ "$MACH" = "i386" ] && [ "${SPARC_RM_PKGARCHIVE}" ]; then
516d8fd4470Sjg			echo "Clearing out ${SPARC_RM_PKGARCHIVE} ..." \
517d8fd4470Sjg				>> $LOGFILE
518d8fd4470Sjg			rm -rf ${SPARC_RM_PKGARCHIVE}
519d8fd4470Sjg			mkdir -p ${SPARC_RM_PKGARCHIVE}
520d8fd4470Sjg		fi
521d8fd4470Sjg
5227c478bd9Sstevel@tonic-gate		cd $SRC/pkgdefs
5237c478bd9Sstevel@tonic-gate		$MAKE -e install 2>&1 | \
5247c478bd9Sstevel@tonic-gate			tee -a $SRC/pkgdefs/${INSTALLOG}.out >> $LOGFILE
5257c478bd9Sstevel@tonic-gate		echo "\n==== Package build errors ($LABEL) ====\n" \
5267c478bd9Sstevel@tonic-gate			>> $mail_msg_file
5277c478bd9Sstevel@tonic-gate		egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/${INSTALLOG}.out | \
5287c478bd9Sstevel@tonic-gate			grep ':' | \
5297c478bd9Sstevel@tonic-gate			grep -v PSTAMP | \
5307c478bd9Sstevel@tonic-gate			egrep -v "Ignoring unknown host" \
5317c478bd9Sstevel@tonic-gate			>> $mail_msg_file
5327c478bd9Sstevel@tonic-gate	else
5337c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
5347c478bd9Sstevel@tonic-gate	fi
5357c478bd9Sstevel@tonic-gate}
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gatedolint() {
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate	#
5407c478bd9Sstevel@tonic-gate	# Arg. 2 is a flag to turn on/off the lint diff output
5417c478bd9Sstevel@tonic-gate	#
5427c478bd9Sstevel@tonic-gate	dl_usage="Usage: dolint /dir y|n"
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate	if [ $# -ne 2 ]; then
5457c478bd9Sstevel@tonic-gate		echo $dl_usage
5467c478bd9Sstevel@tonic-gate		exit 1
5477c478bd9Sstevel@tonic-gate	fi
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
5507c478bd9Sstevel@tonic-gate		echo $dl_usage
5517c478bd9Sstevel@tonic-gate		exit 1
5527c478bd9Sstevel@tonic-gate	fi
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
5557c478bd9Sstevel@tonic-gate		echo $dl_usage
5567c478bd9Sstevel@tonic-gate		exit 1
5577c478bd9Sstevel@tonic-gate	fi
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate	lintdir=$1
5607c478bd9Sstevel@tonic-gate	dodiff=$2
5617c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
5627c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
5637c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
5667c478bd9Sstevel@tonic-gate	unset RELEASE_BUILD
5677c478bd9Sstevel@tonic-gate	unset EXTRA_OPTIONS
5687c478bd9Sstevel@tonic-gate	unset EXTRA_CFLAGS
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate	#
5717c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
5727c478bd9Sstevel@tonic-gate	#
5737c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate	# remove old lint.out
5767c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
5777c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
5787c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
5797c478bd9Sstevel@tonic-gate	fi
5807c478bd9Sstevel@tonic-gate
5817c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
5827c478bd9Sstevel@tonic-gate	cd $lintdir
5837c478bd9Sstevel@tonic-gate	#
5847c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
5857c478bd9Sstevel@tonic-gate	#
5867c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
5877c478bd9Sstevel@tonic-gate	    `find . -name SCCS -prune -o -type f -name '*.ln' -print `
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
5907c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
5917c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
5927c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
5937c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
5947c478bd9Sstevel@tonic-gate		>> $mail_msg_file
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
5997c478bd9Sstevel@tonic-gate		>>$mail_msg_file
6007c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
6037c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
6047c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
6057c478bd9Sstevel@tonic-gate	fi
6067c478bd9Sstevel@tonic-gate        #grep : $LINTOUT |
6077c478bd9Sstevel@tonic-gate		#egrep -v '^(name|function|value|argument|real|user|sys)' |
6087c478bd9Sstevel@tonic-gate		#egrep -v 'warning: (name|function|value|possibly)' |
6097c478bd9Sstevel@tonic-gate		#egrep -v 'warning: argument used' |
6107c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
6117c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
6127c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
6137c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
6147c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
6157c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
6167c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
6177c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
6187c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
6197c478bd9Sstevel@tonic-gate	fi
6207c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
6217c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
6227c478bd9Sstevel@tonic-gate			>>$mail_msg_file
6237c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
6247c478bd9Sstevel@tonic-gate		# above
6257c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
6267c478bd9Sstevel@tonic-gate			| sort | uniq >> $mail_msg_file
6277c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
6287c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6297c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
6307c478bd9Sstevel@tonic-gate			>> $mail_msg_file
6317c478bd9Sstevel@tonic-gate	fi
6327c478bd9Sstevel@tonic-gate}
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate# Install proto area from IHV build
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gatecopy_ihv_proto() {
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate	echo "\n==== Installing $IA32_IHV_ROOT  ====\n" \
6397c478bd9Sstevel@tonic-gate		>> $LOGFILE
6407c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_ROOT" ]; then
6417c478bd9Sstevel@tonic-gate		if [ ! -d "$ROOT" ]; then
6427c478bd9Sstevel@tonic-gate			echo "mkdir -p $ROOT" >> $LOGFILE
6437c478bd9Sstevel@tonic-gate			mkdir -p $ROOT
6447c478bd9Sstevel@tonic-gate		fi
6457c478bd9Sstevel@tonic-gate		echo "cd $IA32_IHV_ROOT\n" >> $LOGFILE
6467c478bd9Sstevel@tonic-gate		cd $IA32_IHV_ROOT
6477c478bd9Sstevel@tonic-gate		tar -cf - . | (cd $ROOT; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
6487c478bd9Sstevel@tonic-gate	else
6497c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_ROOT: not found" >> $LOGFILE
6507c478bd9Sstevel@tonic-gate	fi
6517c478bd9Sstevel@tonic-gate}
6527c478bd9Sstevel@tonic-gate
6537c478bd9Sstevel@tonic-gate# Install IHV packages in PKGARCHIVE
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gatecopy_ihv_pkgs() {
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate	if  [ $# -ne 2 ]; then
6587c478bd9Sstevel@tonic-gate		echo "usage: copy_ihv_pkgs LABEL SUFFIX"
6597c478bd9Sstevel@tonic-gate		exit 1;
6607c478bd9Sstevel@tonic-gate	fi
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate	LABEL=$1
6637c478bd9Sstevel@tonic-gate	SUFFIX=$2
6647c478bd9Sstevel@tonic-gate	# always use non-DEBUG IHV packages
6657c478bd9Sstevel@tonic-gate	IA32_IHV_PKGS=${IA32_IHV_PKGS_ORIG}-nd
6667c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_PKGS ($LABEL) ====\n" \
6697c478bd9Sstevel@tonic-gate		>> $LOGFILE
6707c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_PKGS" ]; then
6717c478bd9Sstevel@tonic-gate		cd $IA32_IHV_PKGS
6727c478bd9Sstevel@tonic-gate		tar -cf - * | \
6737c478bd9Sstevel@tonic-gate		   (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
6747c478bd9Sstevel@tonic-gate	else
6757c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_PKGS: not found" >> $LOGFILE
6767c478bd9Sstevel@tonic-gate	fi
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate	echo "\n==== Installing IHV packages from $IA32_IHV_BINARY_PKGS ($LABEL) ====\n" \
6797c478bd9Sstevel@tonic-gate		>> $LOGFILE
6807c478bd9Sstevel@tonic-gate	if [ -d "$IA32_IHV_BINARY_PKGS" ]; then
6817c478bd9Sstevel@tonic-gate		cd $IA32_IHV_BINARY_PKGS
6827c478bd9Sstevel@tonic-gate		tar -cf - * | \
6837c478bd9Sstevel@tonic-gate		    (cd $PKGARCHIVE; umask 0; tar xpf - ) 2>&1 >> $LOGFILE
6847c478bd9Sstevel@tonic-gate	else
6857c478bd9Sstevel@tonic-gate		echo "$IA32_IHV_BINARY_PKGS: not found" >> $LOGFILE
6867c478bd9Sstevel@tonic-gate	fi
6877c478bd9Sstevel@tonic-gate}
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gatebuild_tools() {
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate	if  [ $# -ne 1 ]; then
6927c478bd9Sstevel@tonic-gate		echo "usage: build_tools DESTROOT"
6937c478bd9Sstevel@tonic-gate		exit 1;
6947c478bd9Sstevel@tonic-gate	fi
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate	DESTROOT=$1
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
7017c478bd9Sstevel@tonic-gate		>> $LOGFILE
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
7047c478bd9Sstevel@tonic-gate	cd ${TOOLS}
7057c478bd9Sstevel@tonic-gate	/bin/time $MAKE ROOT=${DESTROOT} -e install 2>&1 | \
7067c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
7117c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
7127c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
7137c478bd9Sstevel@tonic-gate		egrep -v warning >> $mail_msg_file
7147c478bd9Sstevel@tonic-gate	if [ "$?" != "0" ]; then
7157c478bd9Sstevel@tonic-gate		STABS=${DESTROOT}/opt/onbld/bin/${MACH}/stabs
7167c478bd9Sstevel@tonic-gate		export STABS
7177c478bd9Sstevel@tonic-gate		CTFSTABS=${DESTROOT}/opt/onbld/bin/${MACH}/ctfstabs
7187c478bd9Sstevel@tonic-gate		export CTFSTABS
7197c478bd9Sstevel@tonic-gate		GENOFFSETS=${DESTROOT}/opt/onbld/bin/genoffsets
7207c478bd9Sstevel@tonic-gate		export GENOFFSETS
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate		CTFCONVERT=${DESTROOT}/opt/onbld/bin/${MACH}/ctfconvert
7237c478bd9Sstevel@tonic-gate		export CTFCONVERT
7247c478bd9Sstevel@tonic-gate		CTFMERGE=${DESTROOT}/opt/onbld/bin/${MACH}/ctfmerge
7257c478bd9Sstevel@tonic-gate		export CTFMERGE
7267c478bd9Sstevel@tonic-gate
7277c478bd9Sstevel@tonic-gate		CTFCVTPTBL=${DESTROOT}/opt/onbld/bin/ctfcvtptbl
7287c478bd9Sstevel@tonic-gate		export CTFCVTPTBL
7297c478bd9Sstevel@tonic-gate		CTFFINDMOD=${DESTROOT}/opt/onbld/bin/ctffindmod
7307c478bd9Sstevel@tonic-gate		export CTFFINDMOD
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate		if [ "$VERIFY_ELFSIGN" = "y" ]; then
7337c478bd9Sstevel@tonic-gate			ELFSIGN=${DESTROOT}/opt/onbld/bin/elfsigncmp
7347c478bd9Sstevel@tonic-gate		else
7357c478bd9Sstevel@tonic-gate			ELFSIGN=${DESTROOT}/opt/onbld/bin/${MACH}/elfsign
7367c478bd9Sstevel@tonic-gate		fi
7377c478bd9Sstevel@tonic-gate		export ELFSIGN
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate		PATH="${DESTROOT}/opt/onbld/bin/${MACH}:${PATH}"
7407c478bd9Sstevel@tonic-gate		PATH="${DESTROOT}/opt/onbld/bin:${PATH}"
7417c478bd9Sstevel@tonic-gate		export PATH
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate		echo "\n==== New environment settings. ====\n" >> $LOGFILE
7447c478bd9Sstevel@tonic-gate		echo "STABS=${STABS}" >> $LOGFILE
7457c478bd9Sstevel@tonic-gate		echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
7467c478bd9Sstevel@tonic-gate		echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
7477c478bd9Sstevel@tonic-gate		echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
7487c478bd9Sstevel@tonic-gate		echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
7497c478bd9Sstevel@tonic-gate		echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
7507c478bd9Sstevel@tonic-gate		echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
7517c478bd9Sstevel@tonic-gate		echo "PATH=${PATH}" >> $LOGFILE
7527c478bd9Sstevel@tonic-gate	fi
7537c478bd9Sstevel@tonic-gate}
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gatestaffer() {
7567c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
7577c478bd9Sstevel@tonic-gate		"$@"
7587c478bd9Sstevel@tonic-gate	else
7597c478bd9Sstevel@tonic-gate		arg="\"$1\""
7607c478bd9Sstevel@tonic-gate		shift
7617c478bd9Sstevel@tonic-gate		for i
7627c478bd9Sstevel@tonic-gate		do
7637c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
7647c478bd9Sstevel@tonic-gate		done
7657c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
7667c478bd9Sstevel@tonic-gate	fi
7677c478bd9Sstevel@tonic-gate}
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gateMACH=`uname -p`
7717c478bd9Sstevel@tonic-gate
7727c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
7737c478bd9Sstevel@tonic-gate	OPTHOME=/opt
7747c478bd9Sstevel@tonic-gate	export OPTHOME
7757c478bd9Sstevel@tonic-gatefi
7767c478bd9Sstevel@tonic-gateif [ "$TEAMWARE" = "" ]; then
7777c478bd9Sstevel@tonic-gate	TEAMWARE=$OPTHOME/teamware
7787c478bd9Sstevel@tonic-gate	export TEAMWARE
7797c478bd9Sstevel@tonic-gatefi
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gateUSAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H ] <env_file>
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gateWhere:
7847c478bd9Sstevel@tonic-gate	-i	Fast incremental options (no clobber, lint, check, gprof, trace)
7857c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
7867c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
7877c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
7887c478bd9Sstevel@tonic-gate		E - build exportable source
7897c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
7907c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
7937c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
7947c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
7957c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
7967c478bd9Sstevel@tonic-gate
7977c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
7987c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
8017c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
8027c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
8037c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
8047c478bd9Sstevel@tonic-gate	-G	gate keeper default group of options (-au)
8057c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
8067c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
8077c478bd9Sstevel@tonic-gate	-N	do not run protocmp
8087c478bd9Sstevel@tonic-gate	-P	do a build with GPROF on
8097c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
8107c478bd9Sstevel@tonic-gate	-T	do a build with TRACE on
8117c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
8127c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
81304a42e3eSszhou	-X	copy x86 IHV proto area
8147c478bd9Sstevel@tonic-gate	-a	create cpio archives
8157c478bd9Sstevel@tonic-gate	-d	use Distributed Make (default uses Parallel Make)
8167c478bd9Sstevel@tonic-gate	-f	find unreferenced files
8177c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
8187c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
8197c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
8207c478bd9Sstevel@tonic-gate	-n      do not do a bringover
8217c478bd9Sstevel@tonic-gate	-o	build using root privileges to set OWNER/GROUP (old style)
8227c478bd9Sstevel@tonic-gate	-p	create packages
8237c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
8247c478bd9Sstevel@tonic-gate	-t	build and use the tools in $SRC/tools
8257c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
8267c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
8277c478bd9Sstevel@tonic-gate	-z	compress cpio archives with gzip
8287c478bd9Sstevel@tonic-gate	-W	Do not report warnings (freeware gate ONLY)
8297c478bd9Sstevel@tonic-gate	-S	Build a variant of the source product
8307c478bd9Sstevel@tonic-gate		E - build exportable source
8317c478bd9Sstevel@tonic-gate		D - build domestic source (exportable + crypt)
8327c478bd9Sstevel@tonic-gate		H - build hybrid source (binaries + deleted source)
8337c478bd9Sstevel@tonic-gate'
8347c478bd9Sstevel@tonic-gate#
8357c478bd9Sstevel@tonic-gate#	-x	less public handling of xmod source for the source product
8367c478bd9Sstevel@tonic-gate#
8377c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
8387c478bd9Sstevel@tonic-gate#	for partially completed build and log.`date '+%m%d%y'`
8397c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
8407c478bd9Sstevel@tonic-gate#
8417c478bd9Sstevel@tonic-gate
8427c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
8437c478bd9Sstevel@tonic-gateA_FLAG=n
8447c478bd9Sstevel@tonic-gatea_FLAG=n
8457c478bd9Sstevel@tonic-gated_FLAG=n
8467c478bd9Sstevel@tonic-gateC_FLAG=n
8477c478bd9Sstevel@tonic-gateF_FLAG=n
8487c478bd9Sstevel@tonic-gatef_FLAG=n
8497c478bd9Sstevel@tonic-gateD_FLAG=n
8507c478bd9Sstevel@tonic-gateP_FLAG=n
8517c478bd9Sstevel@tonic-gateT_FLAG=n
8527c478bd9Sstevel@tonic-gaten_FLAG=n
8537c478bd9Sstevel@tonic-gateo_FLAG=n
8547c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
8557c478bd9Sstevel@tonic-gatel_FLAG=n
8567c478bd9Sstevel@tonic-gatem_FLAG=n
8577c478bd9Sstevel@tonic-gatep_FLAG=n
8587c478bd9Sstevel@tonic-gater_FLAG=n
8597c478bd9Sstevel@tonic-gatet_FLAG=n
8607c478bd9Sstevel@tonic-gateu_FLAG=n
8617c478bd9Sstevel@tonic-gateU_FLAG=n
8627c478bd9Sstevel@tonic-gateV_FLAG=n
8637c478bd9Sstevel@tonic-gateM_FLAG=n
8647c478bd9Sstevel@tonic-gateN_FLAG=n
8657c478bd9Sstevel@tonic-gatez_FLAG=n
8667c478bd9Sstevel@tonic-gateW_FLAG=n
8677c478bd9Sstevel@tonic-gateSE_FLAG=n
8687c478bd9Sstevel@tonic-gateSD_FLAG=n
8697c478bd9Sstevel@tonic-gateSH_FLAG=n
8707c478bd9Sstevel@tonic-gateX_FLAG=n
8717c478bd9Sstevel@tonic-gate#
8727c478bd9Sstevel@tonic-gateXMOD_OPT=
8737c478bd9Sstevel@tonic-gate#
8747c478bd9Sstevel@tonic-gatebuild_ok=y
8757c478bd9Sstevel@tonic-gate#
8767c478bd9Sstevel@tonic-gate# examine arguments
8777c478bd9Sstevel@tonic-gate#
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gateOPTIND=1
8807c478bd9Sstevel@tonic-gatewhile getopts inV:S:t FLAG
8817c478bd9Sstevel@tonic-gatedo
8827c478bd9Sstevel@tonic-gate	case $FLAG in
8837c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
8847c478bd9Sstevel@tonic-gate		;;
8857c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
8867c478bd9Sstevel@tonic-gate		;;
8877c478bd9Sstevel@tonic-gate	  V )	V_FLAG=y
8887c478bd9Sstevel@tonic-gate		V_ARG="$OPTARG"
8897c478bd9Sstevel@tonic-gate		;;
8907c478bd9Sstevel@tonic-gate	  S )
8917c478bd9Sstevel@tonic-gate		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
8927c478bd9Sstevel@tonic-gate			echo "Can only build one source variant at a time."
8937c478bd9Sstevel@tonic-gate			exit 1
8947c478bd9Sstevel@tonic-gate		fi
8957c478bd9Sstevel@tonic-gate		if [ "${OPTARG}" = "E" ]; then
8967c478bd9Sstevel@tonic-gate			SE_FLAG=y
8977c478bd9Sstevel@tonic-gate		elif [ "${OPTARG}" = "D" ]; then
8987c478bd9Sstevel@tonic-gate			SD_FLAG=y
8997c478bd9Sstevel@tonic-gate		elif [ "${OPTARG}" = "H" ]; then
9007c478bd9Sstevel@tonic-gate			SH_FLAG=y
9017c478bd9Sstevel@tonic-gate		else
9027c478bd9Sstevel@tonic-gate			echo "$USAGE"
9037c478bd9Sstevel@tonic-gate			exit 1
9047c478bd9Sstevel@tonic-gate		fi
9057c478bd9Sstevel@tonic-gate		;;
9067c478bd9Sstevel@tonic-gate	  t )	t_FLAG=y
9077c478bd9Sstevel@tonic-gate		;;
9087c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
9097c478bd9Sstevel@tonic-gate		exit 1
9107c478bd9Sstevel@tonic-gate		;;
9117c478bd9Sstevel@tonic-gate	esac
9127c478bd9Sstevel@tonic-gatedone
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate# correct argument count after options
9157c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
9167c478bd9Sstevel@tonic-gate
9177c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
9187c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
9197c478bd9Sstevel@tonic-gate	echo "$USAGE"
9207c478bd9Sstevel@tonic-gate	exit 1
9217c478bd9Sstevel@tonic-gatefi
9227c478bd9Sstevel@tonic-gate
9237c478bd9Sstevel@tonic-gate# check if user is running nightly as root
9247c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
9257c478bd9Sstevel@tonic-gate# when root invokes nightly.
9267c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
9277c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate#
9307c478bd9Sstevel@tonic-gate# force locale to C
9317c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
9327c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
9337c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
9347c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
9357c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
9367c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
9377c478bd9Sstevel@tonic-gate
9387c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
9397c478bd9Sstevel@tonic-gateunset LD_OPTIONS
9407c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
9417c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
9427c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
9437c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
9447c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
9457c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
9467c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
9477c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
9487c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
9497c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
9507c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
9517c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
9527c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
9537c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
9547c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
9557c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
9567c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
9577c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
9587c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
9597c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gateunset CONFIG
9627c478bd9Sstevel@tonic-gateunset GROUP
9637c478bd9Sstevel@tonic-gateunset OWNER
9647c478bd9Sstevel@tonic-gateunset REMOTE
9657c478bd9Sstevel@tonic-gateunset ENV
9667c478bd9Sstevel@tonic-gateunset ARCH
9677c478bd9Sstevel@tonic-gateunset CLASSPATH
9687c478bd9Sstevel@tonic-gateunset NAME
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate#
9717c478bd9Sstevel@tonic-gate#	Setup environmental variables
9727c478bd9Sstevel@tonic-gate#
9737c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
9747c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
9757c478bd9Sstevel@tonic-gate		. $1
9767c478bd9Sstevel@tonic-gate	else
9777c478bd9Sstevel@tonic-gate		. ./$1
9787c478bd9Sstevel@tonic-gate	fi
9797c478bd9Sstevel@tonic-gateelse
9807c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
9817c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
9827c478bd9Sstevel@tonic-gate	else
9837c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
9847c478bd9Sstevel@tonic-gate		exit 1
9857c478bd9Sstevel@tonic-gate	fi
9867c478bd9Sstevel@tonic-gatefi
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate#
9897c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
9907c478bd9Sstevel@tonic-gate#
9917c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
9927c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
9937c478bd9Sstevel@tonic-gateelse
9947c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
9957c478bd9Sstevel@tonic-gatefi
9967c478bd9Sstevel@tonic-gate
9977c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
9987c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
9997c478bd9Sstevel@tonic-gate
10007c478bd9Sstevel@tonic-gate#
10017c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
10027c478bd9Sstevel@tonic-gate#
10037c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
10047c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
10057c478bd9Sstevel@tonic-gatefi
10067c478bd9Sstevel@tonic-gate
10077c478bd9Sstevel@tonic-gate#
10087c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
10097c478bd9Sstevel@tonic-gate#
10107c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
10117c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
10127c478bd9Sstevel@tonic-gatefi
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate#
1015*fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
1016a5c06a9eSmike_s#
1017a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
1018*fb23a357Skupfer	BRINGOVER_FILES="usr"
1019a5c06a9eSmike_sfi
1020a5c06a9eSmike_s
1021a5c06a9eSmike_s#
10227c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
10237c478bd9Sstevel@tonic-gate#	bldenv script.
10247c478bd9Sstevel@tonic-gate#
10257c478bd9Sstevel@tonic-gateOPTIND=1
10267c478bd9Sstevel@tonic-gatewhile getopts ABDFNMPTCGIRafinlmoptuUxdrtzWS:X FLAG $NIGHTLY_OPTIONS
10277c478bd9Sstevel@tonic-gatedo
10287c478bd9Sstevel@tonic-gate	case $FLAG in
10297c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
10307c478bd9Sstevel@tonic-gate		;;
10317c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
10327c478bd9Sstevel@tonic-gate		;; # old version of D
10337c478bd9Sstevel@tonic-gate	  F )	F_FLAG=y
10347c478bd9Sstevel@tonic-gate		;;
10357c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
10367c478bd9Sstevel@tonic-gate		;;
10377c478bd9Sstevel@tonic-gate	  P )	P_FLAG=y
10387c478bd9Sstevel@tonic-gate		;;
10397c478bd9Sstevel@tonic-gate	  T )	T_FLAG=y
10407c478bd9Sstevel@tonic-gate		;;
10417c478bd9Sstevel@tonic-gate	  C )	C_FLAG=y
10427c478bd9Sstevel@tonic-gate		;;
10437c478bd9Sstevel@tonic-gate	  M )	M_FLAG=y
10447c478bd9Sstevel@tonic-gate		;;
10457c478bd9Sstevel@tonic-gate	  N )	N_FLAG=y
10467c478bd9Sstevel@tonic-gate		;;
10477c478bd9Sstevel@tonic-gate	  G )	a_FLAG=y
10487c478bd9Sstevel@tonic-gate		u_FLAG=y
10497c478bd9Sstevel@tonic-gate		;;
10507c478bd9Sstevel@tonic-gate	  I )	a_FLAG=y
10517c478bd9Sstevel@tonic-gate		m_FLAG=y
10527c478bd9Sstevel@tonic-gate		p_FLAG=y
10537c478bd9Sstevel@tonic-gate		u_FLAG=y
10547c478bd9Sstevel@tonic-gate		;;
10557c478bd9Sstevel@tonic-gate	  R )	m_FLAG=y
10567c478bd9Sstevel@tonic-gate		p_FLAG=y
10577c478bd9Sstevel@tonic-gate		;;
10587c478bd9Sstevel@tonic-gate	  a )	a_FLAG=y
10597c478bd9Sstevel@tonic-gate		;;
10607c478bd9Sstevel@tonic-gate	  d )	d_FLAG=y
10617c478bd9Sstevel@tonic-gate		;;
10627c478bd9Sstevel@tonic-gate	  f )	f_FLAG=y
10637c478bd9Sstevel@tonic-gate		;;
10647c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
10657c478bd9Sstevel@tonic-gate		;;
10667c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
10677c478bd9Sstevel@tonic-gate		;;
10687c478bd9Sstevel@tonic-gate	  o )	o_FLAG=y
10697c478bd9Sstevel@tonic-gate		;;
10707c478bd9Sstevel@tonic-gate	  l )	l_FLAG=y
10717c478bd9Sstevel@tonic-gate		;;
10727c478bd9Sstevel@tonic-gate	  m )	m_FLAG=y
10737c478bd9Sstevel@tonic-gate		;;
10747c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
10757c478bd9Sstevel@tonic-gate		;;
10767c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
10777c478bd9Sstevel@tonic-gate		;;
10787c478bd9Sstevel@tonic-gate	  t )	t_FLAG=y
10797c478bd9Sstevel@tonic-gate		;;
10807c478bd9Sstevel@tonic-gate	  u )	u_FLAG=y
10817c478bd9Sstevel@tonic-gate		;;
10827c478bd9Sstevel@tonic-gate	  z )	z_FLAG=y
10837c478bd9Sstevel@tonic-gate		;;
10847c478bd9Sstevel@tonic-gate	  U )
10857c478bd9Sstevel@tonic-gate		if [ -z "${PARENT_ROOT}" ]; then
10867c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
10877c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
10887c478bd9Sstevel@tonic-gate			exit 1
10897c478bd9Sstevel@tonic-gate		fi
10907c478bd9Sstevel@tonic-gate		U_FLAG=y
10917c478bd9Sstevel@tonic-gate		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
10927c478bd9Sstevel@tonic-gate		;;
10937c478bd9Sstevel@tonic-gate	  x )	XMOD_OPT="-x"
10947c478bd9Sstevel@tonic-gate		;;
10957c478bd9Sstevel@tonic-gate	  W )	W_FLAG=y
10967c478bd9Sstevel@tonic-gate		;;
10977c478bd9Sstevel@tonic-gate	  S )
10987c478bd9Sstevel@tonic-gate		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
10997c478bd9Sstevel@tonic-gate			echo "Can only build one source variant at a time."
11007c478bd9Sstevel@tonic-gate			exit 1
11017c478bd9Sstevel@tonic-gate		fi
11027c478bd9Sstevel@tonic-gate		if [ "${OPTARG}" = "E" ]; then
11037c478bd9Sstevel@tonic-gate			SE_FLAG=y
11047c478bd9Sstevel@tonic-gate		elif [ "${OPTARG}" = "D" ]; then
11057c478bd9Sstevel@tonic-gate			SD_FLAG=y
11067c478bd9Sstevel@tonic-gate		elif [ "${OPTARG}" = "H" ]; then
11077c478bd9Sstevel@tonic-gate			SH_FLAG=y
11087c478bd9Sstevel@tonic-gate		else
11097c478bd9Sstevel@tonic-gate			echo "$USAGE"
11107c478bd9Sstevel@tonic-gate			exit 1
11117c478bd9Sstevel@tonic-gate		fi
11127c478bd9Sstevel@tonic-gate		;;
11137c478bd9Sstevel@tonic-gate	  X )	# now that we no longer need realmode builds, just
11147c478bd9Sstevel@tonic-gate		# copy IHV packages.  only meaningful on x86.
11157c478bd9Sstevel@tonic-gate		if [ "$MACH" = "i386" ]; then
11167c478bd9Sstevel@tonic-gate			X_FLAG=y
11177c478bd9Sstevel@tonic-gate		fi
11187c478bd9Sstevel@tonic-gate		;;
11197c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
11207c478bd9Sstevel@tonic-gate		exit 1
11217c478bd9Sstevel@tonic-gate		;;
11227c478bd9Sstevel@tonic-gate	esac
11237c478bd9Sstevel@tonic-gatedone
11247c478bd9Sstevel@tonic-gate
11257c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
11267c478bd9Sstevel@tonic-gate	if [ "$o_FLAG" = "y" ]; then
11277c478bd9Sstevel@tonic-gate		echo "Old-style build requires root permission."
11287c478bd9Sstevel@tonic-gate		exit 1
11297c478bd9Sstevel@tonic-gate	fi
11307c478bd9Sstevel@tonic-gate
11317c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
11327c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
11337c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
11347c478bd9Sstevel@tonic-gate		export STAFFER
11357c478bd9Sstevel@tonic-gate	fi
11367c478bd9Sstevel@tonic-gatefi
11377c478bd9Sstevel@tonic-gate
11387c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
11397c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
11407c478bd9Sstevel@tonic-gate	export MAILTO
11417c478bd9Sstevel@tonic-gatefi
11427c478bd9Sstevel@tonic-gate
11437c478bd9Sstevel@tonic-gatePATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
11447c478bd9Sstevel@tonic-gatePATH="$PATH:$OPTHOME/SUNWspro/bin:$TEAMWARE/bin:/usr/bin:/usr/sbin:/usr/ucb"
11457c478bd9Sstevel@tonic-gatePATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
11467c478bd9Sstevel@tonic-gateexport PATH
11477c478bd9Sstevel@tonic-gate
1148*fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
1149*fb23a357Skupferrelsrcdirs="."
1150*fb23a357Skupfer[ -d $SRC/../closed ] && relsrcdirs="$relsrcdirs ../closed"
1151*fb23a357Skupferabssrcdirs=""
1152*fb23a357Skupferfor d in $relsrcdirs; do
1153*fb23a357Skupfer	abssrcdirs="$abssrcdirs $SRC/$d"
1154*fb23a357Skupferdone
1155*fb23a357Skupfer
11567c478bd9Sstevel@tonic-gateunset CH
11577c478bd9Sstevel@tonic-gateif [ "$o_FLAG" = "y" ]; then
11587c478bd9Sstevel@tonic-gate# root invoked old-style build -- make sure it works as it always has
11597c478bd9Sstevel@tonic-gate# by exporting 'CH'.  The current Makefile.master doesn't use this, but
11607c478bd9Sstevel@tonic-gate# the old ones still do.
11617c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse"
11627c478bd9Sstevel@tonic-gate	CH=
11637c478bd9Sstevel@tonic-gate	export CH
11647c478bd9Sstevel@tonic-gateelse
11657c478bd9Sstevel@tonic-gate	PROTOCMPTERSE="protocmp.terse -gu"
11667c478bd9Sstevel@tonic-gatefi
11677c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
11687c478bd9Sstevel@tonic-gate
11697c478bd9Sstevel@tonic-gate# we export POUND_SIGN to speed up the build process -- prevents evaluation of
11707c478bd9Sstevel@tonic-gate# the Makefile.master definitions.
11718ad60789Srieexport o_FLAG POUND_SIGN
11727c478bd9Sstevel@tonic-gate
11737c478bd9Sstevel@tonic-gateif [ "$d_FLAG" = "y" ]; then
11747c478bd9Sstevel@tonic-gate	maketype="distributed"
11757c478bd9Sstevel@tonic-gate	MAKE=dmake
11767c478bd9Sstevel@tonic-gate	# get the dmake version string alone
11777c478bd9Sstevel@tonic-gate	DMAKE_VERSION=$( $MAKE -v )
11787c478bd9Sstevel@tonic-gate	DMAKE_VERSION=${DMAKE_VERSION#*: }
11797c478bd9Sstevel@tonic-gate	# focus in on just the dotted version number alone
11807c478bd9Sstevel@tonic-gate	DMAKE_MAJOR=$( echo $DMAKE_VERSION | \
11817c478bd9Sstevel@tonic-gate		sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
11827c478bd9Sstevel@tonic-gate	# extract the second (or final) integer
11837c478bd9Sstevel@tonic-gate	DMAKE_MINOR=${DMAKE_MAJOR#*.}
11847c478bd9Sstevel@tonic-gate	DMAKE_MINOR=${DMAKE_MINOR%%.*}
11857c478bd9Sstevel@tonic-gate	# extract the first integer
11867c478bd9Sstevel@tonic-gate	DMAKE_MAJOR=${DMAKE_MAJOR%%.*}
11877c478bd9Sstevel@tonic-gate	CHECK_DMAKE=${CHECK_DMAKE:-y}
11887c478bd9Sstevel@tonic-gate	# x86 was built on the 12th, sparc on the 13th.
11897c478bd9Sstevel@tonic-gate	if [ "$CHECK_DMAKE" = "y" -a \
11907c478bd9Sstevel@tonic-gate	     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
11917c478bd9Sstevel@tonic-gate	     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
11927c478bd9Sstevel@tonic-gate	     "$DMAKE_MAJOR" -lt 7 -o \
11937c478bd9Sstevel@tonic-gate	     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
11947c478bd9Sstevel@tonic-gate		if [ -z "$DMAKE_VERSION" ]; then
11957c478bd9Sstevel@tonic-gate			echo "$MAKE is missing."
11967c478bd9Sstevel@tonic-gate			exit 1
11977c478bd9Sstevel@tonic-gate		fi
11987c478bd9Sstevel@tonic-gate		echo `whence $MAKE`" version is:"
11997c478bd9Sstevel@tonic-gate		echo "  ${DMAKE_VERSION}"
12007c478bd9Sstevel@tonic-gate		cat <<EOF
12017c478bd9Sstevel@tonic-gate
12027c478bd9Sstevel@tonic-gateThis version may not be safe for use.  Either set TEAMWARE to a better
12037c478bd9Sstevel@tonic-gatepath or (if you really want to use this version of dmake anyway), add
12047c478bd9Sstevel@tonic-gatethe following to your environment to disable this check:
12057c478bd9Sstevel@tonic-gate
12067c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
12077c478bd9Sstevel@tonic-gateEOF
12087c478bd9Sstevel@tonic-gate		exit 1
12097c478bd9Sstevel@tonic-gate	fi
12107c478bd9Sstevel@tonic-gateelse
12117c478bd9Sstevel@tonic-gate	PATH="$TEAMWARE/ParallelMake/bin:$PATH"
12127c478bd9Sstevel@tonic-gate	maketype="parallel"
12137c478bd9Sstevel@tonic-gate	MAKE=make
12147c478bd9Sstevel@tonic-gatefi
12157c478bd9Sstevel@tonic-gateexport PATH
12167c478bd9Sstevel@tonic-gateexport MAKE
12177c478bd9Sstevel@tonic-gate
12187c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
12197c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
12207c478bd9Sstevel@tonic-gate	export PATH
12217c478bd9Sstevel@tonic-gatefi
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gatehostname=`uname -n`
12247c478bd9Sstevel@tonic-gateif [ ! -f $HOME/.make.machines ]; then
12257c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS=4
12267c478bd9Sstevel@tonic-gateelse
12277c478bd9Sstevel@tonic-gate	DMAKE_MAX_JOBS="`grep $hostname $HOME/.make.machines | \
12287c478bd9Sstevel@tonic-gate	    tail -1 | awk -F= '{print $ 2;}'`"
12297c478bd9Sstevel@tonic-gate	if [ "$DMAKE_MAX_JOBS" = "" ]; then
12307c478bd9Sstevel@tonic-gate		DMAKE_MAX_JOBS=4
12317c478bd9Sstevel@tonic-gate	fi
12327c478bd9Sstevel@tonic-gatefi
12337c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
12347c478bd9Sstevel@tonic-gateexport DMAKE_MODE
12357c478bd9Sstevel@tonic-gateexport DMAKE_MAX_JOBS
12367c478bd9Sstevel@tonic-gate
12377c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
12387c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
12397c478bd9Sstevel@tonic-gate	exit 1
12407c478bd9Sstevel@tonic-gatefi
12417c478bd9Sstevel@tonic-gate
12427c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
12437c478bd9Sstevel@tonic-gate        if [ -z "${EXPORT_SRC}" ]; then
12447c478bd9Sstevel@tonic-gate		echo "EXPORT_SRC must be set for a source build."
12457c478bd9Sstevel@tonic-gate		exit 1
12467c478bd9Sstevel@tonic-gate	fi
12477c478bd9Sstevel@tonic-gate        if [ -z "${CRYPT_SRC}" ]; then
12487c478bd9Sstevel@tonic-gate		echo "CRYPT_SRC must be set for a source build."
12497c478bd9Sstevel@tonic-gate		exit 1
12507c478bd9Sstevel@tonic-gate	fi
12517c478bd9Sstevel@tonic-gatefi
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
12547c478bd9Sstevel@tonic-gate        if [ -z "${EXPORT_SRC}" ]; then
12557c478bd9Sstevel@tonic-gate		echo "EXPORT_SRC must be set for a source build."
12567c478bd9Sstevel@tonic-gate		exit 1
12577c478bd9Sstevel@tonic-gate	fi
12587c478bd9Sstevel@tonic-gatefi
12597c478bd9Sstevel@tonic-gate
12607c478bd9Sstevel@tonic-gate#
12617c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
12627c478bd9Sstevel@tonic-gate#
12637c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
12647c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
12657c478bd9Sstevel@tonic-gatefi
12667c478bd9Sstevel@tonic-gate
126704a42e3eSszhou#
126804a42e3eSszhou# Check for IHV root for copying ihv proto area
126904a42e3eSszhou#
127004a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
127104a42e3eSszhou        if [ "$IA32_IHV_ROOT" = "" ]; then
127204a42e3eSszhou		echo "IA32_IHV_ROOT: must be set for copying ihv proto"
127304a42e3eSszhou		args_ok=n
127404a42e3eSszhou        fi
127504a42e3eSszhou        if [ ! -d "$IA32_IHV_ROOT" ]; then
127604a42e3eSszhou                echo "$IA32_IHV_ROOT: not found"
127704a42e3eSszhou                args_ok=n
127804a42e3eSszhou        fi
127904a42e3eSszhoufi
128004a42e3eSszhou
12817c478bd9Sstevel@tonic-gate# Append source version
12827c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" ]; then
12837c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:EXPORT"
12847c478bd9Sstevel@tonic-gatefi
12857c478bd9Sstevel@tonic-gate
12867c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
12877c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:DOMESTIC"
12887c478bd9Sstevel@tonic-gatefi
12897c478bd9Sstevel@tonic-gate
12907c478bd9Sstevel@tonic-gateif [ "$SH_FLAG" = "y" ]; then
12917c478bd9Sstevel@tonic-gate	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
12927c478bd9Sstevel@tonic-gatefi
12937c478bd9Sstevel@tonic-gate
12947c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
12957c478bd9Sstevel@tonic-gateexport TMPDIR
12967c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
12977c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
12987c478bd9Sstevel@tonic-gate
12997c478bd9Sstevel@tonic-gate#
13007c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
13017c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
13027c478bd9Sstevel@tonic-gate# have the fix for 6271754
13037c478bd9Sstevel@tonic-gate#
13047c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
13057c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
13067c478bd9Sstevel@tonic-gate
13077c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
13087c478bd9Sstevel@tonic-gateTOOLS_PROTO=${TOOLS}/proto
13097c478bd9Sstevel@tonic-gate
13107c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
13117c478bd9Sstevel@tonic-gate
13127c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
13137c478bd9Sstevel@tonic-gate# fails to start correctly
13147c478bd9Sstevel@tonic-gatenewdir() {
13157c478bd9Sstevel@tonic-gate	dir=$1
13167c478bd9Sstevel@tonic-gate	toadd=
13177c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
13187c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
13197c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
13207c478bd9Sstevel@tonic-gate	done
13217c478bd9Sstevel@tonic-gate	torm=
13227c478bd9Sstevel@tonic-gate	newlist=
13237c478bd9Sstevel@tonic-gate	for dir in $toadd; do
13247c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
13257c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
13267c478bd9Sstevel@tonic-gate			torm="$dir $torm"
13277c478bd9Sstevel@tonic-gate		else
13287c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
13297c478bd9Sstevel@tonic-gate			return 1
13307c478bd9Sstevel@tonic-gate		fi
13317c478bd9Sstevel@tonic-gate	done
13327c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
13337c478bd9Sstevel@tonic-gate	return 0
13347c478bd9Sstevel@tonic-gate}
13357c478bd9Sstevel@tonic-gatenewdirlist=
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
13387c478bd9Sstevel@tonic-gate
13397c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
13407c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
13417c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
13427c478bd9Sstevel@tonic-gate# built from this immediate source.
13437c478bd9Sstevel@tonic-gateENVLDLIBS1=
13447c478bd9Sstevel@tonic-gateENVLDLIBS2=
13457c478bd9Sstevel@tonic-gateENVLDLIBS3=
13467c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
13477c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
13487c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
13497c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
13507c478bd9Sstevel@tonic-gatePARENT_ROOT=
13517c478bd9Sstevel@tonic-gate
13527c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
13537c478bd9Sstevel@tonic-gate	PARENT_ROOT
13547c478bd9Sstevel@tonic-gate
13557c478bd9Sstevel@tonic-gateENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
13567c478bd9Sstevel@tonic-gateENVCPPFLAGS1="-I$ROOT/usr/include"
13577c478bd9Sstevel@tonic-gate
13587c478bd9Sstevel@tonic-gateexport ENVLDLIBS1 ENVLDLIBS2
13597c478bd9Sstevel@tonic-gate
13607c478bd9Sstevel@tonic-gateCPIODIR_ORIG=$CPIODIR
13617c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
13627c478bd9Sstevel@tonic-gateIA32_IHV_PKGS_ORIG=$IA32_IHV_PKGS
1363d8fd4470Sjgif [ "$SPARC_RM_PKGARCHIVE" ]; then
13647c478bd9Sstevel@tonic-gate	SPARC_RM_PKGARCHIVE_ORIG=$SPARC_RM_PKGARCHIVE
1365d8fd4470Sjgfi
13667c478bd9Sstevel@tonic-gate
13677c478bd9Sstevel@tonic-gate#
13687c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
13697c478bd9Sstevel@tonic-gate#
13707c478bd9Sstevel@tonic-gate
13717c478bd9Sstevel@tonic-gatelogshuffle() {
13727c478bd9Sstevel@tonic-gate    	LLOG="$ATLOG/log.`date '+%m%d'`"
13737c478bd9Sstevel@tonic-gate	rm -rf $ATLOG/log.??`date '+%d'`
13747c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
13757c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
13767c478bd9Sstevel@tonic-gate	fi
13777c478bd9Sstevel@tonic-gate	mkdir $LLOG
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
13807c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
13817c478bd9Sstevel@tonic-gate	fi
13827c478bd9Sstevel@tonic-gate
13837c478bd9Sstevel@tonic-gate	#
13847c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
13857c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
13867c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
13877c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
13887c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
13897c478bd9Sstevel@tonic-gate	#
13907c478bd9Sstevel@tonic-gate
13917c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
13927c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
13937c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
13947c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
13957c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
13967c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
13977c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
13987c478bd9Sstevel@tonic-gate	fi
13997c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
14007c478bd9Sstevel@tonic-gate
14017c478bd9Sstevel@tonic-gate	case "$build_ok" in
14027c478bd9Sstevel@tonic-gate		y)
14037c478bd9Sstevel@tonic-gate			state=Completed
14047c478bd9Sstevel@tonic-gate			;;
14057c478bd9Sstevel@tonic-gate		i)
14067c478bd9Sstevel@tonic-gate			state=Interrupted
14077c478bd9Sstevel@tonic-gate			;;
14087c478bd9Sstevel@tonic-gate		*)
14097c478bd9Sstevel@tonic-gate	    		state=Failed
14107c478bd9Sstevel@tonic-gate			;;
14117c478bd9Sstevel@tonic-gate	esac
14127c478bd9Sstevel@tonic-gate
14137c478bd9Sstevel@tonic-gate	cat $build_time_file $mail_msg_file > ${LLOG}/mail_msg
14147c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
14157c478bd9Sstevel@tonic-gate	    	cat $build_time_file $mail_msg_file |
14167c478bd9Sstevel@tonic-gate		    /usr/bin/mailx -s \
14177c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
14187c478bd9Sstevel@tonic-gate			${MAILTO}
14197c478bd9Sstevel@tonic-gate	fi
14207c478bd9Sstevel@tonic-gate
14217c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
14227c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
14237c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
14247c478bd9Sstevel@tonic-gate	fi
14257c478bd9Sstevel@tonic-gate
14267c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
14277c478bd9Sstevel@tonic-gate}
14287c478bd9Sstevel@tonic-gate
14297c478bd9Sstevel@tonic-gate#
14307c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
14317c478bd9Sstevel@tonic-gate#
14327c478bd9Sstevel@tonic-gatecleanup() {
14337c478bd9Sstevel@tonic-gate    	logshuffle
14347c478bd9Sstevel@tonic-gate
14357c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
14367c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
14377c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
14387c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
14397c478bd9Sstevel@tonic-gate
14407c478bd9Sstevel@tonic-gate	set -- $newdirlist
14417c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
14427c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
14437c478bd9Sstevel@tonic-gate		shift; shift
14447c478bd9Sstevel@tonic-gate	done
14457c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
14467c478bd9Sstevel@tonic-gate}
14477c478bd9Sstevel@tonic-gate
14487c478bd9Sstevel@tonic-gatecleanup_signal() {
14497c478bd9Sstevel@tonic-gate    	build_ok=i
14507c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
14517c478bd9Sstevel@tonic-gate	exit 1
14527c478bd9Sstevel@tonic-gate}
14537c478bd9Sstevel@tonic-gate
14547c478bd9Sstevel@tonic-gatetrap cleanup 0
14557c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
14567c478bd9Sstevel@tonic-gate
14577c478bd9Sstevel@tonic-gate#
14587c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
14597c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
14607c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
14617c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
14627c478bd9Sstevel@tonic-gate# for the workspace).
14637c478bd9Sstevel@tonic-gatecreate_lock() {
14647c478bd9Sstevel@tonic-gate	lockf=$1
14657c478bd9Sstevel@tonic-gate	lockvar=$2
14667c478bd9Sstevel@tonic-gate	if [ -f $lockf ]; then
14677c478bd9Sstevel@tonic-gate		basews=`basename $CODEMGR_WS`
14687c478bd9Sstevel@tonic-gate		if read host user pid < $lockf; then
14697c478bd9Sstevel@tonic-gate			if [ "$host" != "$hostname" ]; then
14707c478bd9Sstevel@tonic-gate				echo "$MACH build of $basews apparently" \
14717c478bd9Sstevel@tonic-gate				    "already started by $user on $host as $pid."
14727c478bd9Sstevel@tonic-gate			elif kill -s 0 $pid 2>/dev/null; then
14737c478bd9Sstevel@tonic-gate				echo "$MACH build of $basews already started" \
14747c478bd9Sstevel@tonic-gate				    "by $user as $pid."
14757c478bd9Sstevel@tonic-gate			else
14767c478bd9Sstevel@tonic-gate				# stale lock; clear it out and continue
14777c478bd9Sstevel@tonic-gate				rm -f $lockf
14787c478bd9Sstevel@tonic-gate			fi
14797c478bd9Sstevel@tonic-gate		else
14807c478bd9Sstevel@tonic-gate			echo "$MACH build of $basews already running."
14817c478bd9Sstevel@tonic-gate		fi
14827c478bd9Sstevel@tonic-gate	fi
14837c478bd9Sstevel@tonic-gate	if [ -f $lockf ]; then
14847c478bd9Sstevel@tonic-gate		echo "Lock file is $lockf."
14857c478bd9Sstevel@tonic-gate		exit 1
14867c478bd9Sstevel@tonic-gate	fi
14877c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
14887c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
14897c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
14907c478bd9Sstevel@tonic-gate	staffer sh -c "echo $hostname $STAFFER $$ > $lockf" || exit 1
14917c478bd9Sstevel@tonic-gate}
14927c478bd9Sstevel@tonic-gate
14937c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
14947c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
14957c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
14967c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
14977c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
14987c478bd9Sstevel@tonic-gatefi
14997c478bd9Sstevel@tonic-gate#
15007c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
15017c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
15027c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
15037c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
15047c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
15057c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
15067c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
15077c478bd9Sstevel@tonic-gate#
15087c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
15097c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
15107c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
15117c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
15127c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
15137c478bd9Sstevel@tonic-gatefi
15147c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
15157c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
15167c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
15177c478bd9Sstevel@tonic-gatefi
15187c478bd9Sstevel@tonic-gate
15197c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
15207c478bd9Sstevel@tonic-gate# the directories we may have created so far.
15217c478bd9Sstevel@tonic-gatenewdirlist=
15227c478bd9Sstevel@tonic-gate
15237c478bd9Sstevel@tonic-gate#
15247c478bd9Sstevel@tonic-gate# Create mail_msg_file
15257c478bd9Sstevel@tonic-gate#
15267c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
15277c478bd9Sstevel@tonic-gatetouch $mail_msg_file
15287c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
15297c478bd9Sstevel@tonic-gate#
15307c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
15317c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
15327c478bd9Sstevel@tonic-gate#
15337c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
15347c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
15357c478bd9Sstevel@tonic-gatefi
15367c478bd9Sstevel@tonic-gate#
15377c478bd9Sstevel@tonic-gate#	Build OsNet source
15387c478bd9Sstevel@tonic-gate#
15397c478bd9Sstevel@tonic-gateSTART_DATE=`date`
15407c478bd9Sstevel@tonic-gateSECONDS=0
15417c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
15427c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
15437c478bd9Sstevel@tonic-gate
15447c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
15457c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
15467c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
15477c478bd9Sstevel@tonic-gate
15487c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
15497c478bd9Sstevel@tonic-gateenv >> $LOGFILE
15507c478bd9Sstevel@tonic-gate
15517c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
15527c478bd9Sstevel@tonic-gate
15537c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
15547c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
15557c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support incremental" \
15567c478bd9Sstevel@tonic-gate		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
15577c478bd9Sstevel@tonic-gate		i_FLAG=n
15587c478bd9Sstevel@tonic-gate		i_CMD_LINE_FLAG=n
15597c478bd9Sstevel@tonic-gate	fi
15607c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "n" ]; then
15617c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support protocmp;" \
15627c478bd9Sstevel@tonic-gate		    "protocmp disabled\n" | \
15637c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
15647c478bd9Sstevel@tonic-gate		N_FLAG=y
15657c478bd9Sstevel@tonic-gate	fi
15667c478bd9Sstevel@tonic-gate	if [ "$l_FLAG" = "y" ]; then
15677c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support lint;" \
15687c478bd9Sstevel@tonic-gate		    "lint disabled\n" | tee -a $mail_msg_file >> $LOGFILE
15697c478bd9Sstevel@tonic-gate		l_FLAG=n
15707c478bd9Sstevel@tonic-gate	fi
15717c478bd9Sstevel@tonic-gate	if [ "$C_FLAG" = "y" ]; then
15727c478bd9Sstevel@tonic-gate		echo "WARNING: the -S flags do not support cstyle;" \
15737c478bd9Sstevel@tonic-gate		    "cstyle check disabled\n" | tee -a $mail_msg_file >> $LOGFILE
15747c478bd9Sstevel@tonic-gate		C_FLAG=n
15757c478bd9Sstevel@tonic-gate	fi
15767c478bd9Sstevel@tonic-gateelse
15777c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" = "y" ]; then
15787c478bd9Sstevel@tonic-gate		if [ "$p_FLAG" = "y" ]; then
15797c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
15807c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
15817c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
15827c478bd9Sstevel@tonic-gateEOF
15837c478bd9Sstevel@tonic-gate		else
15847c478bd9Sstevel@tonic-gate			cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
15857c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
15867c478bd9Sstevel@tonic-gateEOF
15877c478bd9Sstevel@tonic-gate		fi
15887c478bd9Sstevel@tonic-gate		echo "" | tee -a $mail_msg_file >> $LOGFILE
15897c478bd9Sstevel@tonic-gate	fi
15907c478bd9Sstevel@tonic-gatefi
15917c478bd9Sstevel@tonic-gate
15927c478bd9Sstevel@tonic-gateif [ "$a_FLAG" = "y" -a "$D_FLAG" = "n" -a "$F_FLAG" = "y" ]; then
15937c478bd9Sstevel@tonic-gate	echo "WARNING: Neither DEBUG nor non-DEBUG build requested, but the" \
15947c478bd9Sstevel@tonic-gate	    "'a' option was set." | tee -a $mail_msg_file >> $LOGFILE
15957c478bd9Sstevel@tonic-gatefi
15967c478bd9Sstevel@tonic-gate
15977c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
15987c478bd9Sstevel@tonic-gate	echo "WARNING: DEBUG build not requested, but lint will be with" \
15997c478bd9Sstevel@tonic-gate	    "DEBUG enabled.\n" \
16007c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
16017c478bd9Sstevel@tonic-gatefi
16027c478bd9Sstevel@tonic-gate
16037c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
16047c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
16057c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
16067c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
16077c478bd9Sstevel@tonic-gate		f_FLAG=n
16087c478bd9Sstevel@tonic-gate	fi
16097c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" != "y" -o "$l_FLAG" != "y" ]; then
16107c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag requires -l and -p; ignoring -f\n" | \
16117c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
16127c478bd9Sstevel@tonic-gate		f_FLAG=n
16137c478bd9Sstevel@tonic-gate	fi
16147c478bd9Sstevel@tonic-gatefi
16157c478bd9Sstevel@tonic-gate
16167c478bd9Sstevel@tonic-gateif [ "$T_FLAG" = "y" -a -d $SRC/uts/common/dtrace ]; then
16177c478bd9Sstevel@tonic-gate	echo "WARNING: TRACE build requested but workspace contains DTrace;" \
16187c478bd9Sstevel@tonic-gate	    "-T will have no effect\n" | tee -a $mail_msg_file >> $LOGFILE
16197c478bd9Sstevel@tonic-gatefi
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
16227c478bd9Sstevel@tonic-gate	#
16237c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
16247c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
16257c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
16267c478bd9Sstevel@tonic-gate	#
16277c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
16287c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
16297c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
16307c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
16317c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
16327c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
16337c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
16347c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
16357c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
16367c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
16377c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
16387c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
16397c478bd9Sstevel@tonic-gate	fi
16407c478bd9Sstevel@tonic-gatefi
16417c478bd9Sstevel@tonic-gate
164204a42e3eSszhou# copy ihv proto area in addition to the build itself
164304a42e3eSszhou
164404a42e3eSszhouif [ "$X_FLAG" = "y" ]; then
164504a42e3eSszhou
164604a42e3eSszhou	# Install IA32 IHV proto area
164704a42e3eSszhou	copy_ihv_proto
164804a42e3eSszhoufi
164904a42e3eSszhou
16507c478bd9Sstevel@tonic-gateecho "==== Build environment ====\n" | tee -a $mail_msg_file >> $LOGFILE
16517c478bd9Sstevel@tonic-gate
16527c478bd9Sstevel@tonic-gate# System
16537c478bd9Sstevel@tonic-gatewhence uname | tee -a $mail_msg_file >> $LOGFILE
16547c478bd9Sstevel@tonic-gateuname -a 2>&1 | tee -a $mail_msg_file >> $LOGFILE
16557c478bd9Sstevel@tonic-gateecho | tee -a $mail_msg_file >> $LOGFILE
16567c478bd9Sstevel@tonic-gate
16577c478bd9Sstevel@tonic-gate# nightly (will fail in year 2100 due to SCCS flaw)
16587c478bd9Sstevel@tonic-gateecho "$0 $@" | tee -a $mail_msg_file >> $LOGFILE
16597c478bd9Sstevel@tonic-gateecho "%M% version %I% 20%E%\n" | tee -a $mail_msg_file >> $LOGFILE
16607c478bd9Sstevel@tonic-gate
16617c478bd9Sstevel@tonic-gate# make
16627c478bd9Sstevel@tonic-gatewhence $MAKE | tee -a $mail_msg_file >> $LOGFILE
16637c478bd9Sstevel@tonic-gateif [ "$d_FLAG" = "y" ]; then
16647c478bd9Sstevel@tonic-gate	$MAKE -v | tee -a $mail_msg_file >> $LOGFILE
16657c478bd9Sstevel@tonic-gatefi
16667c478bd9Sstevel@tonic-gateecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
16677c478bd9Sstevel@tonic-gate    tee -a $mail_msg_file >> $LOGFILE
16687c478bd9Sstevel@tonic-gate
16697c478bd9Sstevel@tonic-gate#
16707c478bd9Sstevel@tonic-gate# Report the compiler versions.
16717c478bd9Sstevel@tonic-gate#
16727c478bd9Sstevel@tonic-gateif [ -f $SRC/Makefile ]; then
16737c478bd9Sstevel@tonic-gate	srcroot=$SRC
16747c478bd9Sstevel@tonic-gateelif [ -f $BRINGOVER_WS/usr/src/Makefile ]; then
16757c478bd9Sstevel@tonic-gate	srcroot=$BRINGOVER_WS/usr/src
16767c478bd9Sstevel@tonic-gateelse
16777c478bd9Sstevel@tonic-gate	echo "\nUnable to find \"Makefile\" in $BRINGOVER_WS/usr/src or $SRC." |
16787c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
16797c478bd9Sstevel@tonic-gate	exit 1
16807c478bd9Sstevel@tonic-gatefi
16817c478bd9Sstevel@tonic-gate
16827c478bd9Sstevel@tonic-gate( cd $srcroot
16837c478bd9Sstevel@tonic-gate  for target in cc-version cc64-version java-version; do
16847c478bd9Sstevel@tonic-gate	echo
16857c478bd9Sstevel@tonic-gate	#
16867c478bd9Sstevel@tonic-gate	# Put statefile somewhere we know we can write to rather than trip
16877c478bd9Sstevel@tonic-gate	# over a read-only $srcroot.  Use /usr/ccs/bin/make here because
16887c478bd9Sstevel@tonic-gate	# it supports -K and ParallelMake doesn't.
16897c478bd9Sstevel@tonic-gate	#
16907c478bd9Sstevel@tonic-gate	rm -f $TMPDIR/make-state
16917c478bd9Sstevel@tonic-gate	if /usr/ccs/bin/make -K $TMPDIR/make-state -e $target 2>/dev/null; then
16927c478bd9Sstevel@tonic-gate		continue
16937c478bd9Sstevel@tonic-gate	fi
16947c478bd9Sstevel@tonic-gate	touch $TMPDIR/nocompiler
16957c478bd9Sstevel@tonic-gate  done
16967c478bd9Sstevel@tonic-gate  echo
16977c478bd9Sstevel@tonic-gate) | tee -a $mail_msg_file >> $LOGFILE
16987c478bd9Sstevel@tonic-gate
16997c478bd9Sstevel@tonic-gateif [ -f $TMPDIR/nocompiler ]; then
17007c478bd9Sstevel@tonic-gate	rm -f $TMPDIR/nocompiler
17017c478bd9Sstevel@tonic-gate	build_ok=n
17027c478bd9Sstevel@tonic-gate	echo "Aborting due to missing compiler." |
17037c478bd9Sstevel@tonic-gate		tee -a $mail_msg_file >> $LOGFILE
17047c478bd9Sstevel@tonic-gate	exit 1
17057c478bd9Sstevel@tonic-gatefi
17067c478bd9Sstevel@tonic-gate
17077c478bd9Sstevel@tonic-gate# as
17087c478bd9Sstevel@tonic-gatewhence as | tee -a $mail_msg_file >> $LOGFILE
17097c478bd9Sstevel@tonic-gateas -V 2>&1 | head -1 | tee -a $mail_msg_file >> $LOGFILE
17107c478bd9Sstevel@tonic-gateecho | tee -a $mail_msg_file >> $LOGFILE
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gate# Check that we're running a capable link-editor
17137c478bd9Sstevel@tonic-gatewhence ld | tee -a $mail_msg_file >> $LOGFILE
17147c478bd9Sstevel@tonic-gateLDVER=`ld -V 2>&1`
17157c478bd9Sstevel@tonic-gateecho $LDVER | tee -a $mail_msg_file >> $LOGFILE
17167c478bd9Sstevel@tonic-gateLDVER=`echo $LDVER | sed -e "s/.*-1\.//" -e "s/:.*//"`
17177c478bd9Sstevel@tonic-gateif [ `expr $LDVER \< 422` -eq 1 ]; then
17187c478bd9Sstevel@tonic-gate	echo "The link-editor needs to be at version 422 or higher to build" | \
17197c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
17207c478bd9Sstevel@tonic-gate	echo "the latest stuff, hope your build works." | \
17217c478bd9Sstevel@tonic-gate	    tee -a $mail_msg_file >> $LOGFILE
17227c478bd9Sstevel@tonic-gatefi
17237c478bd9Sstevel@tonic-gate
17247c478bd9Sstevel@tonic-gateecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
17257c478bd9Sstevel@tonic-gate    tee -a $mail_msg_file >> $LOGFILE
17267c478bd9Sstevel@tonic-gate
17277c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
17287c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
17297c478bd9Sstevel@tonic-gate
17307c478bd9Sstevel@tonic-gate#
17317c478bd9Sstevel@tonic-gate#	Decide whether to clobber
17327c478bd9Sstevel@tonic-gate#
17337c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
17347c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
17357c478bd9Sstevel@tonic-gate
17367c478bd9Sstevel@tonic-gate	cd $SRC
17377c478bd9Sstevel@tonic-gate	# remove old clobber file
17387c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
17397c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
17407c478bd9Sstevel@tonic-gate
17417c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
17427c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
17437c478bd9Sstevel@tonic-gate	find . \( -name SCCS -o -name 'interfaces.*' \) -prune \
17447c478bd9Sstevel@tonic-gate	    -o -name '.make.*' -print | xargs rm -f
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
17477c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
17487c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
17497c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" \
17507c478bd9Sstevel@tonic-gate		>> $mail_msg_file
17517c478bd9Sstevel@tonic-gate
17527c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
17537c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
17547c478bd9Sstevel@tonic-gate		cd ${TOOLS}
17557c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
17567c478bd9Sstevel@tonic-gate		$MAKE -ek clobber 2>&1 | \
17577c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
17587c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
17597c478bd9Sstevel@tonic-gate			>> $mail_msg_file
17607c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
17617c478bd9Sstevel@tonic-gate			>> $mail_msg_file
17627c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
17637c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
17647c478bd9Sstevel@tonic-gate	fi
17657c478bd9Sstevel@tonic-gate	rm -rf $ROOT
17667c478bd9Sstevel@tonic-gate
17677c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
17687c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
17697c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
1770*fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
1771*fb23a357Skupfer	# under SCCS, so leave them alone.
17727c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
17737c478bd9Sstevel@tonic-gate	cd $SRC
1774*fb23a357Skupfer	find $relsrcdirs \( -name SCCS -o -name 'interfaces.*' \) -prune -o \
17757c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1776*fb23a357Skupfer	       -name '*.o' \) -print | \
1777*fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
17787c478bd9Sstevel@tonic-gateelse
17797c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
17807c478bd9Sstevel@tonic-gatefi
17817c478bd9Sstevel@tonic-gate
17827c478bd9Sstevel@tonic-gate#
17837c478bd9Sstevel@tonic-gate#	Decide whether to bringover to the codemgr workspace
17847c478bd9Sstevel@tonic-gate#
17857c478bd9Sstevel@tonic-gateif [ "$n_FLAG" = "n" ]; then
17867c478bd9Sstevel@tonic-gate	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
17877c478bd9Sstevel@tonic-gate	# sleep on the parent workspace's lock
17887c478bd9Sstevel@tonic-gate	while egrep -s write $BRINGOVER_WS/Codemgr_wsdata/locks
17897c478bd9Sstevel@tonic-gate	do
17907c478bd9Sstevel@tonic-gate		sleep 120
17917c478bd9Sstevel@tonic-gate	done
17927c478bd9Sstevel@tonic-gate
17937c478bd9Sstevel@tonic-gate	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
17947c478bd9Sstevel@tonic-gate	staffer $TEAMWARE/bin/bringover -c "nightly update" -p $BRINGOVER_WS \
1795a5c06a9eSmike_s	    -w $CODEMGR_WS $BRINGOVER_FILES < /dev/null 2>&1 | \
17967c478bd9Sstevel@tonic-gate		tee -a  $mail_msg_file >> $LOGFILE
17977c478bd9Sstevel@tonic-gate	if [ $? -eq 1 ]
17987c478bd9Sstevel@tonic-gate	then
17997c478bd9Sstevel@tonic-gate		echo "trouble with bringover, quitting at `date`." >> $LOGFILE
18007c478bd9Sstevel@tonic-gate		exit 1
18017c478bd9Sstevel@tonic-gate	fi
18027c478bd9Sstevel@tonic-gateelse
18037c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
18047c478bd9Sstevel@tonic-gatefi
18057c478bd9Sstevel@tonic-gate
18067c478bd9Sstevel@tonic-gate#
18077c478bd9Sstevel@tonic-gate# Build tools if requested
18087c478bd9Sstevel@tonic-gate#
18097c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "y" ]; then
18107c478bd9Sstevel@tonic-gate	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
18117c478bd9Sstevel@tonic-gate	export RELEASE_BUILD ; RELEASE_BUILD=
18127c478bd9Sstevel@tonic-gate	unset EXTRA_OPTIONS
18137c478bd9Sstevel@tonic-gate	unset EXTRA_CFLAGS
18147c478bd9Sstevel@tonic-gate
18157c478bd9Sstevel@tonic-gate	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
18167c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
18177c478bd9Sstevel@tonic-gatefi
18187c478bd9Sstevel@tonic-gate
18197c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "y" -a "$SH_FLAG" = "y" ]; then
18207c478bd9Sstevel@tonic-gate	echo "\n==== NOT Building base OS-Net source ====\n" | \
18217c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
18227c478bd9Sstevel@tonic-gateelse
18237c478bd9Sstevel@tonic-gate	normal_build
18247c478bd9Sstevel@tonic-gatefi
18257c478bd9Sstevel@tonic-gate
18267c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
18277c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
18287c478bd9Sstevel@tonic-gate
18297c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
18307c478bd9Sstevel@tonic-gate	save_binaries
18317c478bd9Sstevel@tonic-gate
18327c478bd9Sstevel@tonic-gate	echo "\n==== Retrieving SCCS files at `date` ====\n" >> $LOGFILE
18337c478bd9Sstevel@tonic-gate	SCCSHELPER=${TMPDIR}/sccs-helper
18347c478bd9Sstevel@tonic-gate	rm -f ${SCCSHELPER}
18357c478bd9Sstevel@tonic-gatecat >${SCCSHELPER} <<EOF
18367c478bd9Sstevel@tonic-gate#!/bin/ksh
18377c478bd9Sstevel@tonic-gatecd \$1
18387c478bd9Sstevel@tonic-gatecd ..
18397c478bd9Sstevel@tonic-gatesccs get SCCS >/dev/null 2>&1
18407c478bd9Sstevel@tonic-gateEOF
18417c478bd9Sstevel@tonic-gate	cd $SRC
18427c478bd9Sstevel@tonic-gate	chmod +x ${SCCSHELPER}
1843*fb23a357Skupfer	find $relsrcdirs -name SCCS | xargs -L 1 ${SCCSHELPER}
18447c478bd9Sstevel@tonic-gate	rm -f ${SCCSHELPER}
18457c478bd9Sstevel@tonic-gatefi
18467c478bd9Sstevel@tonic-gate
18477c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
18487c478bd9Sstevel@tonic-gate	clone_source ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
18497c478bd9Sstevel@tonic-gatefi
18507c478bd9Sstevel@tonic-gate
18517c478bd9Sstevel@tonic-gate# EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
18527c478bd9Sstevel@tonic-gate# $SRC pointing to the export_source usr/src.
18537c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
18547c478bd9Sstevel@tonic-gate	clone_source ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
18557c478bd9Sstevel@tonic-gatefi
18567c478bd9Sstevel@tonic-gate
18577c478bd9Sstevel@tonic-gateif [ "$SD_FLAG" = "y" ]; then
18587c478bd9Sstevel@tonic-gate	# drop the crypt files in place.
18597c478bd9Sstevel@tonic-gate	cd ${EXPORT_SRC}
18607c478bd9Sstevel@tonic-gate	echo "\nextracting crypt_files.cpio.Z onto export_source.\n" \
18617c478bd9Sstevel@tonic-gate	    >> ${LOGFILE}
18627c478bd9Sstevel@tonic-gate	zcat ${CODEMGR_WS}/crypt_files.cpio.Z | \
18637c478bd9Sstevel@tonic-gate	    cpio -idmucvB 2>/dev/null >> ${LOGFILE}
18647c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
18657c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction succeeded ====\n" \
18667c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
18677c478bd9Sstevel@tonic-gate	else
18687c478bd9Sstevel@tonic-gate		echo "\n==== DOMESTIC extraction failed ====\n" \
18697c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
18707c478bd9Sstevel@tonic-gate	fi
18717c478bd9Sstevel@tonic-gate
18727c478bd9Sstevel@tonic-gatefi
18737c478bd9Sstevel@tonic-gate
18747c478bd9Sstevel@tonic-gateif [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
18757c478bd9Sstevel@tonic-gate	# remove proto area here, since we don't clobber
18767c478bd9Sstevel@tonic-gate	rm -rf "$ROOT"
18777c478bd9Sstevel@tonic-gate	if [ "$t_FLAG" = "y" ]; then
18787c478bd9Sstevel@tonic-gate		export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
18797c478bd9Sstevel@tonic-gate		export RELEASE_BUILD ; RELEASE_BUILD=
18807c478bd9Sstevel@tonic-gate		unset EXTRA_OPTIONS
18817c478bd9Sstevel@tonic-gate		unset EXTRA_CFLAGS
18827c478bd9Sstevel@tonic-gate
18837c478bd9Sstevel@tonic-gate		build_tools ${EXPORT_SRC}/usr/src/tools/proto
18847c478bd9Sstevel@tonic-gate	fi
18857c478bd9Sstevel@tonic-gate
18867c478bd9Sstevel@tonic-gate	export EXPORT_RELEASE_BUILD ; EXPORT_RELEASE_BUILD=#
18877c478bd9Sstevel@tonic-gate	normal_build
18887c478bd9Sstevel@tonic-gatefi
18897c478bd9Sstevel@tonic-gate
18907c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
18917c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
18927c478bd9Sstevel@tonic-gate		>> $LOGFILE
18937c478bd9Sstevel@tonic-gate	protolist $ROOT > $ATLOG/proto_list_${MACH}
18947c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
18957c478bd9Sstevel@tonic-gate		>> $LOGFILE
18967c478bd9Sstevel@tonic-gate
18977c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
18987c478bd9Sstevel@tonic-gate		echo "\n==== Impact on packages ====\n" >> $mail_msg_file
18997c478bd9Sstevel@tonic-gate
19007c478bd9Sstevel@tonic-gate		# If there is a reference proto list, compare the build's proto
19017c478bd9Sstevel@tonic-gate		# list with the reference to see changes in proto areas.
19027c478bd9Sstevel@tonic-gate		# Use the current exception list.
19037c478bd9Sstevel@tonic-gate		exc=etc/exception_list_$MACH
19047c478bd9Sstevel@tonic-gate		if [ -f $SRC/pkgdefs/$exc ]; then
19057c478bd9Sstevel@tonic-gate			ELIST="-e $SRC/pkgdefs/$exc"
19067c478bd9Sstevel@tonic-gate		fi
19077c478bd9Sstevel@tonic-gate
19087c478bd9Sstevel@tonic-gate		if [ -f "$REF_PROTO_LIST" ]; then
19097c478bd9Sstevel@tonic-gate			$PROTOCMPTERSE \
19107c478bd9Sstevel@tonic-gate			  "Files in yesterday's proto area, but not today's:" \
19117c478bd9Sstevel@tonic-gate			  "Files in today's proto area, but not yesterday's:" \
19127c478bd9Sstevel@tonic-gate			  "Files that changed between yesterday and today:" \
19137c478bd9Sstevel@tonic-gate			  ${ELIST} \
19147c478bd9Sstevel@tonic-gate			  -d $REF_PROTO_LIST \
19157c478bd9Sstevel@tonic-gate			  $ATLOG/proto_list_${MACH} \
19167c478bd9Sstevel@tonic-gate				>> $mail_msg_file
19177c478bd9Sstevel@tonic-gate		fi
19187c478bd9Sstevel@tonic-gate		# Compare the build's proto list with current package
19197c478bd9Sstevel@tonic-gate		# definitions to audit the quality of package definitions
19207c478bd9Sstevel@tonic-gate		# and makefile install targets. Use the current exception list.
1921*fb23a357Skupfer		PKGDEFS_LIST=""
1922*fb23a357Skupfer		for d in $abssrcdirs; do
1923*fb23a357Skupfer			if [ -d $d/pkgdefs ]; then
1924*fb23a357Skupfer				PKGDEFS_LIST="$PKGDEFS_LIST -d $d/pkgdefs"
1925*fb23a357Skupfer			fi
1926*fb23a357Skupfer		done
19277c478bd9Sstevel@tonic-gate
19287c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
19297c478bd9Sstevel@tonic-gate		    "Files missing from the proto area:" \
19307c478bd9Sstevel@tonic-gate		    "Files missing from packages:" \
19317c478bd9Sstevel@tonic-gate		    "Inconsistencies between pkgdefs and proto area:" \
19327c478bd9Sstevel@tonic-gate		    ${ELIST} \
19337c478bd9Sstevel@tonic-gate		    ${PKGDEFS_LIST} \
19347c478bd9Sstevel@tonic-gate		    $ATLOG/proto_list_${MACH} \
19357c478bd9Sstevel@tonic-gate		    >> $mail_msg_file
19367c478bd9Sstevel@tonic-gate	fi
19377c478bd9Sstevel@tonic-gatefi
19387c478bd9Sstevel@tonic-gate
19397c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y"  -a "$build_ok" = "y" ]; then
19407c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
19417c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
19427c478bd9Sstevel@tonic-gatefi
19437c478bd9Sstevel@tonic-gate
19447c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
19457c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
19467c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
19477c478bd9Sstevel@tonic-gate# the variable now.
19487c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
19497c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
19507c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
19517c478bd9Sstevel@tonic-gate	# The rm -rf command below produces predictable errors if
19527c478bd9Sstevel@tonic-gate	# nightly is invoked from the parent's $ROOT/opt/onbld/bin,
19537c478bd9Sstevel@tonic-gate	# and that directory is accessed via NFS.  This is because
19547c478bd9Sstevel@tonic-gate	# deleted-but-still-open files don't actually disappear as
19557c478bd9Sstevel@tonic-gate	# expected, but rather turn into .nfsXXXX junk files, leaving
19567c478bd9Sstevel@tonic-gate	# the directory non-empty.  Since this is a not-unusual usage
19577c478bd9Sstevel@tonic-gate	# pattern, and we still want to catch other errors here, we
19587c478bd9Sstevel@tonic-gate	# take the unusal step of moving aside 'nightly' from that
19597c478bd9Sstevel@tonic-gate	# directory (if we're using it).
19607c478bd9Sstevel@tonic-gate	mypath=${0##*/root_$MACH/}
19617c478bd9Sstevel@tonic-gate	if [ "$mypath" = $0 ]; then
19627c478bd9Sstevel@tonic-gate		mypath=opt/onbld/bin/${0##*/}
19637c478bd9Sstevel@tonic-gate	fi
19647c478bd9Sstevel@tonic-gate	if [ $0 -ef $PARENT_WS/proto/root_$MACH/$mypath ]; then
19657c478bd9Sstevel@tonic-gate		mv -f $0 $PARENT_WS/proto/root_$MACH
19667c478bd9Sstevel@tonic-gate	fi
19677c478bd9Sstevel@tonic-gate	rm -rf $PARENT_WS/proto/root_$MACH/*
19687c478bd9Sstevel@tonic-gate	unset Ulockfile
19697c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
19707c478bd9Sstevel@tonic-gate	cd $ROOT
19717c478bd9Sstevel@tonic-gate	( tar cf - . | ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
19727c478bd9Sstevel@tonic-gate		tee -a $mail_msg_file >> $LOGFILE
19737c478bd9Sstevel@tonic-gatefi
19747c478bd9Sstevel@tonic-gate
19757c478bd9Sstevel@tonic-gate#
19767c478bd9Sstevel@tonic-gate# do shared library interface verification
19777c478bd9Sstevel@tonic-gate#
19787c478bd9Sstevel@tonic-gate
19797c478bd9Sstevel@tonic-gateif [ "$A_FLAG" = "y" -a "$build_ok" = "y" ]; then
19807c478bd9Sstevel@tonic-gate	echo "\n==== Check versioning and ABI information ====\n"  | \
19817c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
19827c478bd9Sstevel@tonic-gate
19837c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.ref
19847c478bd9Sstevel@tonic-gate	if [ -d $SRC/interfaces.out ]; then
19857c478bd9Sstevel@tonic-gate		mv $SRC/interfaces.out $SRC/interfaces.ref
19867c478bd9Sstevel@tonic-gate	fi
19877c478bd9Sstevel@tonic-gate	rm -rf $SRC/interfaces.out
19887c478bd9Sstevel@tonic-gate	mkdir -p $SRC/interfaces.out
19897c478bd9Sstevel@tonic-gate
19907c478bd9Sstevel@tonic-gate	intf_check -V -m -o -b $SRC/tools/abi/etc \
19917c478bd9Sstevel@tonic-gate		-d $SRC/interfaces.out $ROOT 2>&1 | sort \
19927c478bd9Sstevel@tonic-gate		> $SRC/interfaces.out/log
19937c478bd9Sstevel@tonic-gate
19947c478bd9Sstevel@tonic-gate	# report any ERROR found in log file
19957c478bd9Sstevel@tonic-gate	fgrep 'ERROR' $SRC/interfaces.out/log | sed 's/^ERROR: //' | \
19967c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
19977c478bd9Sstevel@tonic-gate
19987c478bd9Sstevel@tonic-gate	if [ ! -d $SRC/interfaces.ref ] ; then
19997c478bd9Sstevel@tonic-gate		mkdir -p $SRC/interfaces.ref
20007c478bd9Sstevel@tonic-gate		if [ -d  $SRC/interfaces.out ]; then
20017c478bd9Sstevel@tonic-gate			cp -r $SRC/interfaces.out/* $SRC/interfaces.ref
20027c478bd9Sstevel@tonic-gate		fi
20037c478bd9Sstevel@tonic-gate	fi
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gate	echo "\n==== Diff versioning warnings (since last build) ====\n" | \
20067c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
20077c478bd9Sstevel@tonic-gate
20087c478bd9Sstevel@tonic-gate	out_vers=`grep ^VERSION $SRC/interfaces.out/log`;
20097c478bd9Sstevel@tonic-gate	ref_vers=`grep ^VERSION $SRC/interfaces.ref/log`;
20107c478bd9Sstevel@tonic-gate
20117c478bd9Sstevel@tonic-gate	# Report any differences in WARNING messages between last
20127c478bd9Sstevel@tonic-gate	# and current build.
20137c478bd9Sstevel@tonic-gate	if [ "$out_vers" = "$ref_vers" ]; then
20147c478bd9Sstevel@tonic-gate		diff $SRC/interfaces.ref/log $SRC/interfaces.out/log | \
20157c478bd9Sstevel@tonic-gate		    fgrep 'WARNING' | sed 's/WARNING: //' | \
20167c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
20177c478bd9Sstevel@tonic-gate	fi
20187c478bd9Sstevel@tonic-gatefi
20197c478bd9Sstevel@tonic-gate
20207c478bd9Sstevel@tonic-gateif [ "$r_FLAG" = "y" -a "$build_ok" = "y" ]; then
20217c478bd9Sstevel@tonic-gate	echo "\n==== Check ELF runtime attributes ====\n" | \
20227c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
20237c478bd9Sstevel@tonic-gate
20247c478bd9Sstevel@tonic-gate	LDDUSAGE="^ldd: does not support -e"
20257c478bd9Sstevel@tonic-gate	LDDWRONG="wrong class"
20267c478bd9Sstevel@tonic-gate	CRLERROR="^crle:"
20277c478bd9Sstevel@tonic-gate	CRLECONF="^crle: configuration file:"
20287c478bd9Sstevel@tonic-gate
20297c478bd9Sstevel@tonic-gate	rm -f $SRC/runtime.ref
20307c478bd9Sstevel@tonic-gate	if [ -f $SRC/runtime.out ]; then
20317c478bd9Sstevel@tonic-gate		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
20327c478bd9Sstevel@tonic-gate			$SRC/runtime.out > $SRC/runtime.ref
20337c478bd9Sstevel@tonic-gate	fi
20347c478bd9Sstevel@tonic-gate
20357c478bd9Sstevel@tonic-gate	# If we're doing a debug build the proto area will be left with
20367c478bd9Sstevel@tonic-gate	# debuggable objects, thus don't assert -s.
20377c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
20387c478bd9Sstevel@tonic-gate		rtime_sflag=""
20397c478bd9Sstevel@tonic-gate	else
20407c478bd9Sstevel@tonic-gate		rtime_sflag="-s"
20417c478bd9Sstevel@tonic-gate	fi
20427c478bd9Sstevel@tonic-gate	check_rtime -d $ROOT -i -m -o $rtime_sflag $ROOT 2>&1 | \
20437c478bd9Sstevel@tonic-gate	    egrep -v ": unreferenced object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
20447c478bd9Sstevel@tonic-gate	    egrep -v ": unused object=$ROOT/.*/lib(w|intl|thread|pthread).so" | \
20457c478bd9Sstevel@tonic-gate	    sort >$SRC/runtime.out
20467c478bd9Sstevel@tonic-gate
20477c478bd9Sstevel@tonic-gate	# Determine any processing errors that will affect the final output
20487c478bd9Sstevel@tonic-gate	# and display these first.
20497c478bd9Sstevel@tonic-gate	grep -l "$LDDUSAGE" $SRC/runtime.out > /dev/null
20507c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
20517c478bd9Sstevel@tonic-gate	    echo "WARNING: ldd(1) does not support -e.  The version of ldd(1)" | \
20527c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20537c478bd9Sstevel@tonic-gate	    echo "on your system is old - 4390308 (s81_30) is required.\n" | \
20547c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20557c478bd9Sstevel@tonic-gate	fi
20567c478bd9Sstevel@tonic-gate	grep -l "$LDDWRONG" $SRC/runtime.out > /dev/null
20577c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
20587c478bd9Sstevel@tonic-gate	    echo "WARNING: wrong class message detected.  ldd(1) was unable" | \
20597c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20607c478bd9Sstevel@tonic-gate	    echo "to execute an object, thus it could not be checked fully." | \
20617c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20627c478bd9Sstevel@tonic-gate	    echo "Perhaps a 64-bit object was encountered on a 32-bit system," | \
20637c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20647c478bd9Sstevel@tonic-gate	    echo "or an i386 object was encountered on a sparc system?\n" | \
20657c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20667c478bd9Sstevel@tonic-gate	fi
20677c478bd9Sstevel@tonic-gate	grep -l "$CRLECONF" $SRC/runtime.out > /dev/null
20687c478bd9Sstevel@tonic-gate	if [ $? -eq 0 ]; then
20697c478bd9Sstevel@tonic-gate	    echo "WARNING: creation of an alternative dependency cache failed." | \
20707c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20717c478bd9Sstevel@tonic-gate	    echo "Dependencies will bind to the base system libraries.\n" | \
20727c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20737c478bd9Sstevel@tonic-gate	    grep "$CRLECONF" $SRC/runtime.out | \
20747c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20757c478bd9Sstevel@tonic-gate	    grep "$CRLERROR" $SRC/runtime.out | grep -v "$CRLECONF" | \
20767c478bd9Sstevel@tonic-gate		tee -a $LOGFILE >> $mail_msg_file
20777c478bd9Sstevel@tonic-gate	    echo "\n" | tee -a $LOGFILE >> $mail_msg_file
20787c478bd9Sstevel@tonic-gate	fi
20797c478bd9Sstevel@tonic-gate
20807c478bd9Sstevel@tonic-gate	egrep '<dependency no longer necessary>' $SRC/runtime.out | \
20817c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
20827c478bd9Sstevel@tonic-gate
20837c478bd9Sstevel@tonic-gate	# NEEDED= and RPATH= are informational; report anything else that we
20847c478bd9Sstevel@tonic-gate	# haven't already.
20857c478bd9Sstevel@tonic-gate	egrep -v "NEEDED=|RPATH=|$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
20867c478bd9Sstevel@tonic-gate	    $SRC/runtime.out | tee -a $LOGFILE >> $mail_msg_file
20877c478bd9Sstevel@tonic-gate
20887c478bd9Sstevel@tonic-gate	# probably should compare against a 'known ok runpaths' list
20897c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/runtime.ref ]; then
20907c478bd9Sstevel@tonic-gate		egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" \
20917c478bd9Sstevel@tonic-gate			$SRC/runtime.out >  $SRC/runtime.ref
20927c478bd9Sstevel@tonic-gate	fi
20937c478bd9Sstevel@tonic-gate
20947c478bd9Sstevel@tonic-gate	echo "\n==== Diff ELF runtime attributes (since last build) ====\n" \
20957c478bd9Sstevel@tonic-gate	    >> $mail_msg_file
20967c478bd9Sstevel@tonic-gate
20977c478bd9Sstevel@tonic-gate	egrep -v "$LDDUSAGE|$LDDWRONG|$CRLERROR|$CRLECONF" $SRC/runtime.out | \
20987c478bd9Sstevel@tonic-gate	    diff $SRC/runtime.ref - >> $mail_msg_file
20997c478bd9Sstevel@tonic-gatefi
21007c478bd9Sstevel@tonic-gate
21017c478bd9Sstevel@tonic-gate# For now, don't make archives or packages for GPROF/TRACE builds
21027c478bd9Sstevel@tonic-gatea_FLAG=n
21037c478bd9Sstevel@tonic-gatep_FLAG=n
21047c478bd9Sstevel@tonic-gate
21057c478bd9Sstevel@tonic-gate# GPROF build begins
21067c478bd9Sstevel@tonic-gate
21077c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$P_FLAG" = "y" ]; then
21087c478bd9Sstevel@tonic-gate
21097c478bd9Sstevel@tonic-gate	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
21107c478bd9Sstevel@tonic-gate	export RELEASE_BUILD ; RELEASE_BUILD=
21117c478bd9Sstevel@tonic-gate	export EXTRA_OPTIONS ; EXTRA_OPTIONS="-DGPROF"
21127c478bd9Sstevel@tonic-gate	export EXTRA_CFLAGS ; EXTRA_CFLAGS="-xpg"
21137c478bd9Sstevel@tonic-gate
21147c478bd9Sstevel@tonic-gate	build GPROF -prof
21157c478bd9Sstevel@tonic-gate
21167c478bd9Sstevel@tonic-gateelse
21177c478bd9Sstevel@tonic-gate	echo "\n==== No GPROF build ====\n" >> $LOGFILE
21187c478bd9Sstevel@tonic-gatefi
21197c478bd9Sstevel@tonic-gate
21207c478bd9Sstevel@tonic-gate# GPROF build ends
21217c478bd9Sstevel@tonic-gate
21227c478bd9Sstevel@tonic-gate# TRACE build begins
21237c478bd9Sstevel@tonic-gate
21247c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$T_FLAG" = "y" ]; then
21257c478bd9Sstevel@tonic-gate
21267c478bd9Sstevel@tonic-gate	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
21277c478bd9Sstevel@tonic-gate	export RELEASE_BUILD ; RELEASE_BUILD=
21287c478bd9Sstevel@tonic-gate	export EXTRA_OPTIONS ; EXTRA_OPTIONS="-DTRACE"
21297c478bd9Sstevel@tonic-gate	unset EXTRA_CFLAGS
21307c478bd9Sstevel@tonic-gate
21317c478bd9Sstevel@tonic-gate	build TRACE -trace
21327c478bd9Sstevel@tonic-gate
21337c478bd9Sstevel@tonic-gateelse
21347c478bd9Sstevel@tonic-gate	echo "\n==== No TRACE build ====\n" >> $LOGFILE
21357c478bd9Sstevel@tonic-gatefi
21367c478bd9Sstevel@tonic-gate
21377c478bd9Sstevel@tonic-gate# TRACE build ends
21387c478bd9Sstevel@tonic-gate
21397c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
21407c478bd9Sstevel@tonic-gate
21417c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
21427c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
21437c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
21447c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
21457c478bd9Sstevel@tonic-gate	fi
21467c478bd9Sstevel@tonic-gate	set $LINTDIRS
21477c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
21487c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
21497c478bd9Sstevel@tonic-gate	done
21507c478bd9Sstevel@tonic-gateelse
21517c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
21527c478bd9Sstevel@tonic-gatefi
21537c478bd9Sstevel@tonic-gate
21547c478bd9Sstevel@tonic-gate# "make check" begins
21557c478bd9Sstevel@tonic-gate
21567c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
21577c478bd9Sstevel@tonic-gate	# remove old check.out
21587c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
21597c478bd9Sstevel@tonic-gate
21607c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
21617c478bd9Sstevel@tonic-gate	cd $SRC
21627c478bd9Sstevel@tonic-gate	$MAKE -ek check 2>&1 | tee -a $SRC/check-${MACH}.out >> $LOGFILE
21637c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
21647c478bd9Sstevel@tonic-gate
21657c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
21667c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
21677c478bd9Sstevel@tonic-gate		sort | uniq >> $mail_msg_file
21687c478bd9Sstevel@tonic-gateelse
21697c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
21707c478bd9Sstevel@tonic-gatefi
21717c478bd9Sstevel@tonic-gate
21727c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
21737c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
21747c478bd9Sstevel@tonic-gate
2175*fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
21767c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
21777c478bd9Sstevel@tonic-gate
21787c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
21797c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
21807c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
21817c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
21827c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
21837c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21847c478bd9Sstevel@tonic-gate	fi
21857c478bd9Sstevel@tonic-gate
2186*fb23a357Skupfer	findunref -t $SRC/.build.tstamp $SRC/.. \
2187*fb23a357Skupfer	    ${TOOLS}/findunref/exception_list \
2188*fb23a357Skupfer	    2>> $mail_msg_file | sort | \
2189*fb23a357Skupfer	    sed -e s=^./src/=./= -e s=^./closed/=../closed/= \
2190*fb23a357Skupfer	    > $SRC/unref-${MACH}.out
21917c478bd9Sstevel@tonic-gate
21927c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
21937c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21947c478bd9Sstevel@tonic-gate	fi
21957c478bd9Sstevel@tonic-gate
21967c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
21977c478bd9Sstevel@tonic-gatefi
21987c478bd9Sstevel@tonic-gate
21997c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
22007c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
22017c478bd9Sstevel@tonic-gate# then don't check the proto area.
22027c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
22037c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
22047c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
22057c478bd9Sstevel@tonic-gate		>>$mail_msg_file
22067c478bd9Sstevel@tonic-gate	arg=-b
22077c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
22087c478bd9Sstevel@tonic-gate	checkpaths $arg $ROOT 2>&1 | tee -a $LOGFILE >>$mail_msg_file
22097c478bd9Sstevel@tonic-gatefi
22107c478bd9Sstevel@tonic-gate
22117c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
22127c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
22137c478bd9Sstevel@tonic-gate		>> $mail_msg_file
22147c478bd9Sstevel@tonic-gate	#
22157c478bd9Sstevel@tonic-gate	# Get pkginfo files from usr/src/pkgdefs
22167c478bd9Sstevel@tonic-gate	#
22177c478bd9Sstevel@tonic-gate	pmodes -qvdP \
2218*fb23a357Skupfer	`for d in $SRC/pkgdefs $SRC/../closed/pkgdefs; do
22197c478bd9Sstevel@tonic-gate		if [ -d "$d" ]
22207c478bd9Sstevel@tonic-gate		then
22217c478bd9Sstevel@tonic-gate			find $d -name pkginfo.tmpl -print -o -name .del\* -prune
22227c478bd9Sstevel@tonic-gate		fi
22237c478bd9Sstevel@tonic-gate	 done | sed -e 's:/pkginfo.tmpl$::' | sort -u ` >> $mail_msg_file
22247c478bd9Sstevel@tonic-gatefi
22257c478bd9Sstevel@tonic-gate
22267c478bd9Sstevel@tonic-gateEND_DATE=`date`
22277c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
22287c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
22297c478bd9Sstevel@tonic-gate
22307c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
22317c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
22327c478bd9Sstevel@tonic-gate
22337c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
22347c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
22357c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
22367c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
22377c478bd9Sstevel@tonic-gate
22387c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
22397c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
22407c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
22417c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
22427c478bd9Sstevel@tonic-gate
22437c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
22447c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
22457c478bd9Sstevel@tonic-gate
22467c478bd9Sstevel@tonic-gate	#
22477c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
22487c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
22497c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
22507c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
22517c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
22527c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
22537c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
22547c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
22557c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
22567c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
22577c478bd9Sstevel@tonic-gate	# which was already on the parent.
22587c478bd9Sstevel@tonic-gate	#
22597c478bd9Sstevel@tonic-gate
22607c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
22617c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
22627c478bd9Sstevel@tonic-gate	shift
22637c478bd9Sstevel@tonic-gate
22647c478bd9Sstevel@tonic-gate	for unreffile; do
22657c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
22667c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
22677c478bd9Sstevel@tonic-gate	done
22687c478bd9Sstevel@tonic-gate
22697c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
22707c478bd9Sstevel@tonic-gatefi
22717c478bd9Sstevel@tonic-gate
22727c478bd9Sstevel@tonic-gate#
22737c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
22747c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
22757c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
22767c478bd9Sstevel@tonic-gate#
22777c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
22787c478bd9Sstevel@tonic-gate	exit 0
22797c478bd9Sstevel@tonic-gatefi
22807c478bd9Sstevel@tonic-gateexit 1
2281