xref: /titanic_53/usr/src/tools/scripts/nightly (revision b85ab92fb289cb50f00b70ad450c8689e3f9f754)
19e4fd900SJohn Levon#!/bin/ksh -p
29e4fd900SJohn Levon#
39e4fd900SJohn Levon# CDDL HEADER START
49e4fd900SJohn Levon#
59e4fd900SJohn Levon# The contents of this file are subject to the terms of the
69e4fd900SJohn Levon# Common Development and Distribution License (the "License").
79e4fd900SJohn Levon# You may not use this file except in compliance with the License.
89e4fd900SJohn Levon#
99e4fd900SJohn Levon# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
109e4fd900SJohn Levon# or http://www.opensolaris.org/os/licensing.
119e4fd900SJohn Levon# See the License for the specific language governing permissions
129e4fd900SJohn Levon# and limitations under the License.
139e4fd900SJohn Levon#
149e4fd900SJohn Levon# When distributing Covered Code, include this CDDL HEADER in each
159e4fd900SJohn Levon# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
169e4fd900SJohn Levon# If applicable, add the following below this CDDL HEADER, with the
179e4fd900SJohn Levon# fields enclosed by brackets "[]" replaced with your own identifying
189e4fd900SJohn Levon# information: Portions Copyright [yyyy] [name of copyright owner]
199e4fd900SJohn Levon#
209e4fd900SJohn Levon# CDDL HEADER END
219e4fd900SJohn Levon#
229e4fd900SJohn Levon
239e4fd900SJohn Levon#
249e4fd900SJohn Levon# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
259e4fd900SJohn Levon# Copyright 2008, 2010, Richard Lowe
269e4fd900SJohn Levon# Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
279e4fd900SJohn Levon# Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
289e4fd900SJohn Levon# Copyright 2020 Joyent, Inc.
29*b85ab92fSAndy Fiddaman# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
309e4fd900SJohn Levon#
319e4fd900SJohn Levon# Based on the nightly script from the integration folks,
329e4fd900SJohn Levon# Mostly modified and owned by mike_s.
339e4fd900SJohn Levon# Changes also by kjc, dmk.
349e4fd900SJohn Levon#
359e4fd900SJohn Levon# BRINGOVER_WS may be specified in the env file.
369e4fd900SJohn Levon# The default is the old behavior of CLONE_WS
379e4fd900SJohn Levon#
389e4fd900SJohn Levon# -i on the command line, means fast options, so when it's on the
399e4fd900SJohn Levon# command line (only), lint and check builds are skipped no matter what
409e4fd900SJohn Levon# the setting of their individual flags are in NIGHTLY_OPTIONS.
419e4fd900SJohn Levon#
429e4fd900SJohn Levon# LINTDIRS can be set in the env file, format is a list of:
439e4fd900SJohn Levon#
449e4fd900SJohn Levon#	/dirname-to-run-lint-on flag
459e4fd900SJohn Levon#
469e4fd900SJohn Levon#	Where flag is:	y - enable lint noise diff output
479e4fd900SJohn Levon#			n - disable lint noise diff output
489e4fd900SJohn Levon#
499e4fd900SJohn Levon#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
509e4fd900SJohn Levon#
519e4fd900SJohn Levon# OPTHOME  may be set in the environment to override /opt
529e4fd900SJohn Levon#
539e4fd900SJohn Levon
549e4fd900SJohn Levon#
559e4fd900SJohn Levon# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
569e4fd900SJohn Levon# under certain circumstances, which can really screw things up; unset it.
579e4fd900SJohn Levon#
589e4fd900SJohn Levonunset CDPATH
599e4fd900SJohn Levon
609e4fd900SJohn Levon# Get the absolute path of the nightly script that the user invoked.  This
619e4fd900SJohn Levon# may be a relative path, and we need to do this before changing directory.
629e4fd900SJohn Levonnightly_path=`whence $0`
639e4fd900SJohn Levon
649e4fd900SJohn Levon#
659e4fd900SJohn Levon# Keep track of where we found nightly so we can invoke the matching
669e4fd900SJohn Levon# which_scm script.  If that doesn't work, don't go guessing, just rely
679e4fd900SJohn Levon# on the $PATH settings, which will generally give us either /opt/onbld
689e4fd900SJohn Levon# or the user's workspace.
699e4fd900SJohn Levon#
709e4fd900SJohn LevonWHICH_SCM=$(dirname $nightly_path)/which_scm
719e4fd900SJohn Levonif [[ ! -x $WHICH_SCM ]]; then
729e4fd900SJohn Levon	WHICH_SCM=which_scm
739e4fd900SJohn Levonfi
749e4fd900SJohn Levon
759e4fd900SJohn Levonfunction fatal_error
769e4fd900SJohn Levon{
779e4fd900SJohn Levon	print -u2 "nightly: $*"
789e4fd900SJohn Levon	exit 1
799e4fd900SJohn Levon}
809e4fd900SJohn Levon
819e4fd900SJohn Levon#
829e4fd900SJohn Levon# Function to do a DEBUG and non-DEBUG build. Needed because we might
839e4fd900SJohn Levon# need to do another for the source build, and since we only deliver DEBUG or
849e4fd900SJohn Levon# non-DEBUG packages.
859e4fd900SJohn Levon#
869e4fd900SJohn Levon# usage: normal_build
879e4fd900SJohn Levon#
889e4fd900SJohn Levonfunction normal_build {
899e4fd900SJohn Levon
909e4fd900SJohn Levon	typeset orig_p_FLAG="$p_FLAG"
919e4fd900SJohn Levon	typeset crypto_signer="$CODESIGN_USER"
929e4fd900SJohn Levon
939e4fd900SJohn Levon	suffix=""
949e4fd900SJohn Levon
959e4fd900SJohn Levon	# non-DEBUG build begins
969e4fd900SJohn Levon
979e4fd900SJohn Levon	if [ "$F_FLAG" = "n" ]; then
989e4fd900SJohn Levon		set_non_debug_build_flags
999e4fd900SJohn Levon		CODESIGN_USER="$crypto_signer" \
1009e4fd900SJohn Levon		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
1019e4fd900SJohn Levon	else
1029e4fd900SJohn Levon		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1039e4fd900SJohn Levon	fi
1049e4fd900SJohn Levon
1059e4fd900SJohn Levon	# non-DEBUG build ends
1069e4fd900SJohn Levon
1079e4fd900SJohn Levon	# DEBUG build begins
1089e4fd900SJohn Levon
1099e4fd900SJohn Levon	if [ "$D_FLAG" = "y" ]; then
1109e4fd900SJohn Levon		set_debug_build_flags
1119e4fd900SJohn Levon		CODESIGN_USER="$crypto_signer" \
1129e4fd900SJohn Levon		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
1139e4fd900SJohn Levon	else
1149e4fd900SJohn Levon		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1159e4fd900SJohn Levon	fi
1169e4fd900SJohn Levon
1179e4fd900SJohn Levon	# DEBUG build ends
1189e4fd900SJohn Levon
1199e4fd900SJohn Levon	p_FLAG="$orig_p_FLAG"
1209e4fd900SJohn Levon}
1219e4fd900SJohn Levon
1229e4fd900SJohn Levon#
1239e4fd900SJohn Levon# usage: run_hook HOOKNAME ARGS...
1249e4fd900SJohn Levon#
1259e4fd900SJohn Levon# If variable "$HOOKNAME" is defined, insert a section header into
1269e4fd900SJohn Levon# our logs and then run the command with ARGS
1279e4fd900SJohn Levon#
1289e4fd900SJohn Levonfunction run_hook {
1299e4fd900SJohn Levon	HOOKNAME=$1
1309e4fd900SJohn Levon    	eval HOOKCMD=\$$HOOKNAME
1319e4fd900SJohn Levon	shift
1329e4fd900SJohn Levon
1339e4fd900SJohn Levon	if [ -n "$HOOKCMD" ]; then
1349e4fd900SJohn Levon	    	(
1359e4fd900SJohn Levon			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
1369e4fd900SJohn Levon		    	( $HOOKCMD "$@" 2>&1 )
1379e4fd900SJohn Levon			if [ "$?" -ne 0 ]; then
1389e4fd900SJohn Levon			    	# Let exit status propagate up
1399e4fd900SJohn Levon			    	touch $TMPDIR/abort
1409e4fd900SJohn Levon			fi
1419e4fd900SJohn Levon		) | tee -a $mail_msg_file >> $LOGFILE
1429e4fd900SJohn Levon
1439e4fd900SJohn Levon		if [ -f $TMPDIR/abort ]; then
1449e4fd900SJohn Levon			build_ok=n
1459e4fd900SJohn Levon			echo "\nAborting at request of $HOOKNAME" |
1469e4fd900SJohn Levon				tee -a $mail_msg_file >> $LOGFILE
1479e4fd900SJohn Levon			exit 1
1489e4fd900SJohn Levon		fi
1499e4fd900SJohn Levon	fi
1509e4fd900SJohn Levon}
1519e4fd900SJohn Levon
1529e4fd900SJohn Levon# Return library search directive as function of given root.
1539e4fd900SJohn Levonfunction myldlibs {
1549e4fd900SJohn Levon	echo "-L$1/lib -L$1/usr/lib"
1559e4fd900SJohn Levon}
1569e4fd900SJohn Levon
1579e4fd900SJohn Levon# Return header search directive as function of given root.
1589e4fd900SJohn Levonfunction myheaders {
1599e4fd900SJohn Levon	echo "-I$1/usr/include"
1609e4fd900SJohn Levon}
1619e4fd900SJohn Levon
1629e4fd900SJohn Levon#
1639e4fd900SJohn Levon# Function to do the build, including package generation.
1649e4fd900SJohn Levon# usage: build LABEL SUFFIX ND MULTIPROTO
1659e4fd900SJohn Levon# - LABEL is used to tag build output.
1669e4fd900SJohn Levon# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
1679e4fd900SJohn Levon#   open-only vs full tree).
1689e4fd900SJohn Levon# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
1699e4fd900SJohn Levon# - If MULTIPROTO is "yes", it means to name the proto area according to
1709e4fd900SJohn Levon#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
1719e4fd900SJohn Levon#
1729e4fd900SJohn Levonfunction build {
1739e4fd900SJohn Levon	LABEL=$1
1749e4fd900SJohn Levon	SUFFIX=$2
1759e4fd900SJohn Levon	ND=$3
1769e4fd900SJohn Levon	MULTIPROTO=$4
1779e4fd900SJohn Levon	INSTALLOG=install${SUFFIX}-${MACH}
1789e4fd900SJohn Levon	NOISE=noise${SUFFIX}-${MACH}
1799e4fd900SJohn Levon	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
1809e4fd900SJohn Levon
1819e4fd900SJohn Levon	ORIGROOT=$ROOT
1829e4fd900SJohn Levon	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
1839e4fd900SJohn Levon
1849e4fd900SJohn Levon	export ENVLDLIBS1=`myldlibs $ROOT`
1859e4fd900SJohn Levon	export ENVCPPFLAGS1=`myheaders $ROOT`
1869e4fd900SJohn Levon
1879e4fd900SJohn Levon	this_build_ok=y
1889e4fd900SJohn Levon	#
1899e4fd900SJohn Levon	#	Build OS-Networking source
1909e4fd900SJohn Levon	#
1919e4fd900SJohn Levon	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
1929e4fd900SJohn Levon		>> $LOGFILE
1939e4fd900SJohn Levon
1949e4fd900SJohn Levon	rm -f $SRC/${INSTALLOG}.out
1959e4fd900SJohn Levon	cd $SRC
1969e4fd900SJohn Levon	/bin/time $MAKE -e install 2>&1 | \
1979e4fd900SJohn Levon	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
1989e4fd900SJohn Levon
1999e4fd900SJohn Levon	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
2009e4fd900SJohn Levon	egrep ":" $SRC/${INSTALLOG}.out |
2019e4fd900SJohn Levon		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
2029e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
2039e4fd900SJohn Levon		egrep -v "cc .* -o error " | \
2049e4fd900SJohn Levon		egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \
2059e4fd900SJohn Levon		>> $mail_msg_file
2069e4fd900SJohn Levon	if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then
2079e4fd900SJohn Levon		build_ok=n
2089e4fd900SJohn Levon		this_build_ok=n
2099e4fd900SJohn Levon	fi
2109e4fd900SJohn Levon	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
2119e4fd900SJohn Levon		>> $mail_msg_file
2129e4fd900SJohn Levon	if [ "$?" = "0" ]; then
2139e4fd900SJohn Levon		build_ok=n
2149e4fd900SJohn Levon		this_build_ok=n
2159e4fd900SJohn Levon	fi
2169e4fd900SJohn Levon
2179e4fd900SJohn Levon	echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
2189e4fd900SJohn Levon	egrep -i warning: $SRC/${INSTALLOG}.out \
2199e4fd900SJohn Levon		| egrep -v '^tic:' \
2209e4fd900SJohn Levon		| egrep -v "symbol (\`|')timezone' has differing types:" \
2219e4fd900SJohn Levon		| egrep -v "parameter <PSTAMP> set to" \
2229e4fd900SJohn Levon		| egrep -v "Ignoring unknown host" \
2239e4fd900SJohn Levon		| egrep -v "redefining segment flags attribute for" \
2249e4fd900SJohn Levon		| tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file
2259e4fd900SJohn Levon	if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then
2269e4fd900SJohn Levon		build_ok=n
2279e4fd900SJohn Levon		this_build_ok=n
2289e4fd900SJohn Levon	fi
2299e4fd900SJohn Levon
2309e4fd900SJohn Levon	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
2319e4fd900SJohn Levon		>> $LOGFILE
2329e4fd900SJohn Levon
2339e4fd900SJohn Levon	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
2349e4fd900SJohn Levon	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
2359e4fd900SJohn Levon
2369e4fd900SJohn Levon	if [ "$i_FLAG" = "n" ]; then
2379e4fd900SJohn Levon		rm -f $SRC/${NOISE}.ref
2389e4fd900SJohn Levon		if [ -f $SRC/${NOISE}.out ]; then
2399e4fd900SJohn Levon			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
2409e4fd900SJohn Levon		fi
2419e4fd900SJohn Levon		grep : $SRC/${INSTALLOG}.out \
2429e4fd900SJohn Levon			| egrep -v '^/' \
2439e4fd900SJohn Levon			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
2449e4fd900SJohn Levon			| egrep -v '^tic:' \
2459e4fd900SJohn Levon			| egrep -v '^mcs' \
2469e4fd900SJohn Levon			| egrep -v '^LD_LIBRARY_PATH=' \
2479e4fd900SJohn Levon			| egrep -v 'ar: creating' \
2489e4fd900SJohn Levon			| egrep -v 'ar: writing' \
2499e4fd900SJohn Levon			| egrep -v 'conflicts:' \
2509e4fd900SJohn Levon			| egrep -v ':saved created' \
2519e4fd900SJohn Levon			| egrep -v '^stty.*c:' \
2529e4fd900SJohn Levon			| egrep -v '^mfgname.c:' \
2539e4fd900SJohn Levon			| egrep -v '^uname-i.c:' \
2549e4fd900SJohn Levon			| egrep -v '^volumes.c:' \
2559e4fd900SJohn Levon			| egrep -v '^lint library construction:' \
2569e4fd900SJohn Levon			| egrep -v 'tsort: INFORM:' \
2579e4fd900SJohn Levon			| egrep -v 'stripalign:' \
2589e4fd900SJohn Levon			| egrep -v 'chars, width' \
2599e4fd900SJohn Levon			| egrep -v "symbol (\`|')timezone' has differing types:" \
2609e4fd900SJohn Levon			| egrep -v 'PSTAMP' \
2619e4fd900SJohn Levon			| egrep -v '|%WHOANDWHERE%|' \
2629e4fd900SJohn Levon			| egrep -v '^Manifying' \
2639e4fd900SJohn Levon			| egrep -v 'Ignoring unknown host' \
2649e4fd900SJohn Levon			| egrep -v 'Processing method:' \
2659e4fd900SJohn Levon			| egrep -v '^Writing' \
2669e4fd900SJohn Levon			| egrep -v 'spellin1:' \
2679e4fd900SJohn Levon			| egrep -v '^adding:' \
2689e4fd900SJohn Levon			| egrep -v "^echo 'msgid" \
2699e4fd900SJohn Levon			| egrep -v '^echo ' \
2709e4fd900SJohn Levon			| egrep -v '\.c:$' \
2719e4fd900SJohn Levon			| egrep -v '^Adding file:' \
2729e4fd900SJohn Levon			| egrep -v 'CLASSPATH=' \
2739e4fd900SJohn Levon			| egrep -v '\/var\/mail\/:saved' \
2749e4fd900SJohn Levon			| egrep -v -- '-DUTS_VERSION=' \
2759e4fd900SJohn Levon			| egrep -v '^Running Mkbootstrap' \
2769e4fd900SJohn Levon			| egrep -v '^Applet length read:' \
2779e4fd900SJohn Levon			| egrep -v 'bytes written:' \
2789e4fd900SJohn Levon			| egrep -v '^File:SolarisAuthApplet.bin' \
2799e4fd900SJohn Levon			| egrep -v -i 'jibversion' \
2809e4fd900SJohn Levon			| egrep -v '^Output size:' \
2819e4fd900SJohn Levon			| egrep -v '^Solo size statistics:' \
2829e4fd900SJohn Levon			| egrep -v '^Using ROM API Version' \
2839e4fd900SJohn Levon			| egrep -v '^Zero Signature length:' \
2849e4fd900SJohn Levon			| egrep -v '^Note \(probably harmless\):' \
2859e4fd900SJohn Levon			| egrep -v '::' \
2869e4fd900SJohn Levon			| egrep -v -- '-xcache' \
2879e4fd900SJohn Levon			| egrep -v '^\+' \
2889e4fd900SJohn Levon			| egrep -v '^cc1: note: -fwritable-strings' \
2899e4fd900SJohn Levon			| egrep -v 'svccfg-native -s svc:/' \
2909e4fd900SJohn Levon			| sort | uniq >$SRC/${NOISE}.out
2919e4fd900SJohn Levon		if [ ! -f $SRC/${NOISE}.ref ]; then
2929e4fd900SJohn Levon			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
2939e4fd900SJohn Levon		fi
2949e4fd900SJohn Levon		echo "\n==== Build noise differences ($LABEL) ====\n" \
2959e4fd900SJohn Levon			>>$mail_msg_file
2969e4fd900SJohn Levon		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
2979e4fd900SJohn Levon	fi
2989e4fd900SJohn Levon
2999e4fd900SJohn Levon	#
3009e4fd900SJohn Levon	#	Re-sign selected binaries using signing server
3019e4fd900SJohn Levon	#	(gatekeeper builds only)
3029e4fd900SJohn Levon	#
3039e4fd900SJohn Levon	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
3049e4fd900SJohn Levon		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
3059e4fd900SJohn Levon		signing_file="${TMPDIR}/signing"
3069e4fd900SJohn Levon		rm -f ${signing_file}
3079e4fd900SJohn Levon		export CODESIGN_USER
3089e4fd900SJohn Levon		signproto $SRC/tools/codesign/creds 2>&1 | \
3099e4fd900SJohn Levon			tee -a ${signing_file} >> $LOGFILE
3109e4fd900SJohn Levon		echo "\n==== Finished signing proto area at `date` ====\n" \
3119e4fd900SJohn Levon		    >> $LOGFILE
3129e4fd900SJohn Levon		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
3139e4fd900SJohn Levon		    >> $mail_msg_file
3149e4fd900SJohn Levon		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
3159e4fd900SJohn Levon		if (( $? == 0 )) ; then
3169e4fd900SJohn Levon			build_ok=n
3179e4fd900SJohn Levon			this_build_ok=n
3189e4fd900SJohn Levon		fi
3199e4fd900SJohn Levon	fi
3209e4fd900SJohn Levon
3219e4fd900SJohn Levon	#
3229e4fd900SJohn Levon	#	Building Packages
3239e4fd900SJohn Levon	#
3249e4fd900SJohn Levon	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
3259e4fd900SJohn Levon		if [ -d $SRC/pkg ]; then
3269e4fd900SJohn Levon			echo "\n==== Creating $LABEL packages at `date` ====\n" \
3279e4fd900SJohn Levon				>> $LOGFILE
3289e4fd900SJohn Levon			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
3299e4fd900SJohn Levon			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
3309e4fd900SJohn Levon			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
3319e4fd900SJohn Levon
3329e4fd900SJohn Levon			rm -f $SRC/pkg/${INSTALLOG}.out
3339e4fd900SJohn Levon			cd $SRC/pkg
3349e4fd900SJohn Levon			/bin/time $MAKE -e install 2>&1 | \
3359e4fd900SJohn Levon			    tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE
3369e4fd900SJohn Levon
3379e4fd900SJohn Levon			echo "\n==== package build errors ($LABEL) ====\n" \
3389e4fd900SJohn Levon				>> $mail_msg_file
3399e4fd900SJohn Levon
3409e4fd900SJohn Levon			egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \
3419e4fd900SJohn Levon				grep ':' | \
3429e4fd900SJohn Levon				grep -v PSTAMP | \
3439e4fd900SJohn Levon				egrep -v "Ignoring unknown host" | \
3449e4fd900SJohn Levon				tee $TMPDIR/package >> $mail_msg_file
3459e4fd900SJohn Levon			if [[ -s $TMPDIR/package ]]; then
3469e4fd900SJohn Levon				build_extras_ok=n
3479e4fd900SJohn Levon				this_build_ok=n
3489e4fd900SJohn Levon			fi
3499e4fd900SJohn Levon		else
3509e4fd900SJohn Levon			#
3519e4fd900SJohn Levon			# Handle it gracefully if -p was set but there so
3529e4fd900SJohn Levon			# no pkg directory.
3539e4fd900SJohn Levon			#
3549e4fd900SJohn Levon			echo "\n==== No $LABEL packages to build ====\n" \
3559e4fd900SJohn Levon				>> $LOGFILE
3569e4fd900SJohn Levon		fi
3579e4fd900SJohn Levon	else
3589e4fd900SJohn Levon		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
3599e4fd900SJohn Levon	fi
3609e4fd900SJohn Levon
3619e4fd900SJohn Levon	ROOT=$ORIGROOT
3629e4fd900SJohn Levon}
3639e4fd900SJohn Levon
3649e4fd900SJohn Levon# Usage: dolint /dir y|n
3659e4fd900SJohn Levon# Arg. 2 is a flag to turn on/off the lint diff output
3669e4fd900SJohn Levonfunction dolint {
3679e4fd900SJohn Levon	if [ ! -d "$1" ]; then
3689e4fd900SJohn Levon		echo "dolint error: $1 is not a directory"
3699e4fd900SJohn Levon		exit 1
3709e4fd900SJohn Levon	fi
3719e4fd900SJohn Levon
3729e4fd900SJohn Levon	if [ "$2" != "y" -a "$2" != "n" ]; then
3739e4fd900SJohn Levon		echo "dolint internal error: $2 should be 'y' or 'n'"
3749e4fd900SJohn Levon		exit 1
3759e4fd900SJohn Levon	fi
3769e4fd900SJohn Levon
3779e4fd900SJohn Levon	lintdir=$1
3789e4fd900SJohn Levon	dodiff=$2
3799e4fd900SJohn Levon	base=`basename $lintdir`
3809e4fd900SJohn Levon	LINTOUT=$lintdir/lint-${MACH}.out
3819e4fd900SJohn Levon	LINTNOISE=$lintdir/lint-noise-${MACH}
3829e4fd900SJohn Levon	export ENVLDLIBS1=`myldlibs $ROOT`
3839e4fd900SJohn Levon	export ENVCPPFLAGS1=`myheaders $ROOT`
3849e4fd900SJohn Levon
3859e4fd900SJohn Levon	set_debug_build_flags
3869e4fd900SJohn Levon
3879e4fd900SJohn Levon	#
3889e4fd900SJohn Levon	#	'$MAKE lint' in $lintdir
3899e4fd900SJohn Levon	#
3909e4fd900SJohn Levon	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
3919e4fd900SJohn Levon
3929e4fd900SJohn Levon	# remove old lint.out
3939e4fd900SJohn Levon	rm -f $lintdir/lint.out $lintdir/lint-noise.out
3949e4fd900SJohn Levon	if [ -f $lintdir/lint-noise.ref ]; then
3959e4fd900SJohn Levon		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
3969e4fd900SJohn Levon	fi
3979e4fd900SJohn Levon
3989e4fd900SJohn Levon	rm -f $LINTOUT
3999e4fd900SJohn Levon	cd $lintdir
4009e4fd900SJohn Levon	#
4019e4fd900SJohn Levon	# Remove all .ln files to ensure a full reference file
4029e4fd900SJohn Levon	#
4039e4fd900SJohn Levon	rm -f Nothing_to_remove \
4049e4fd900SJohn Levon	    `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \
4059e4fd900SJohn Levon	    	-prune -o -type f -name '*.ln' -print `
4069e4fd900SJohn Levon
4079e4fd900SJohn Levon	/bin/time $MAKE -ek lint 2>&1 | \
4089e4fd900SJohn Levon	    tee -a $LINTOUT >> $LOGFILE
4099e4fd900SJohn Levon
4109e4fd900SJohn Levon	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
4119e4fd900SJohn Levon
4129e4fd900SJohn Levon	grep "$MAKE:" $LINTOUT |
4139e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
4149e4fd900SJohn Levon		tee $TMPDIR/lint_errs >> $mail_msg_file
4159e4fd900SJohn Levon	if [[ -s $TMPDIR/lint_errs ]]; then
4169e4fd900SJohn Levon		build_extras_ok=n
4179e4fd900SJohn Levon	fi
4189e4fd900SJohn Levon
4199e4fd900SJohn Levon	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
4209e4fd900SJohn Levon
4219e4fd900SJohn Levon	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
4229e4fd900SJohn Levon		>>$mail_msg_file
4239e4fd900SJohn Levon	tail -3  $LINTOUT >>$mail_msg_file
4249e4fd900SJohn Levon
4259e4fd900SJohn Levon	rm -f ${LINTNOISE}.ref
4269e4fd900SJohn Levon	if [ -f ${LINTNOISE}.out ]; then
4279e4fd900SJohn Levon		mv ${LINTNOISE}.out ${LINTNOISE}.ref
4289e4fd900SJohn Levon	fi
4299e4fd900SJohn Levon        grep : $LINTOUT | \
4309e4fd900SJohn Levon		egrep -v '^(real|user|sys)' |
4319e4fd900SJohn Levon		egrep -v '(library construction)' | \
4329e4fd900SJohn Levon		egrep -v ': global crosschecks' | \
4339e4fd900SJohn Levon		egrep -v 'Ignoring unknown host' | \
4349e4fd900SJohn Levon		egrep -v '\.c:$' | \
4359e4fd900SJohn Levon		sort | uniq > ${LINTNOISE}.out
4369e4fd900SJohn Levon	if [ ! -f ${LINTNOISE}.ref ]; then
4379e4fd900SJohn Levon		cp ${LINTNOISE}.out ${LINTNOISE}.ref
4389e4fd900SJohn Levon	fi
4399e4fd900SJohn Levon
4409e4fd900SJohn Levon	if [ "$dodiff" != "n" ]; then
4419e4fd900SJohn Levon		echo "\n==== lint warnings $base ====\n" \
4429e4fd900SJohn Levon			>>$mail_msg_file
4439e4fd900SJohn Levon		# should be none, though there are a few that were filtered out
4449e4fd900SJohn Levon		# above
4459e4fd900SJohn Levon		egrep -i '(warning|lint):' ${LINTNOISE}.out \
4469e4fd900SJohn Levon			| sort | uniq | tee $TMPDIR/lint_warns >> $mail_msg_file
4479e4fd900SJohn Levon		if [[ -s $TMPDIR/lint_warns ]]; then
4489e4fd900SJohn Levon			build_extras_ok=n
4499e4fd900SJohn Levon		fi
4509e4fd900SJohn Levon		echo "\n==== lint noise differences $base ====\n" \
4519e4fd900SJohn Levon			>> $mail_msg_file
4529e4fd900SJohn Levon		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
4539e4fd900SJohn Levon			>> $mail_msg_file
4549e4fd900SJohn Levon	fi
4559e4fd900SJohn Levon}
4569e4fd900SJohn Levon
4579e4fd900SJohn Levon#
4589e4fd900SJohn Levon# Build and install the onbld tools.
4599e4fd900SJohn Levon#
4609e4fd900SJohn Levon# usage: build_tools DESTROOT
4619e4fd900SJohn Levon#
4629e4fd900SJohn Levon# returns non-zero status if the build was successful.
4639e4fd900SJohn Levon#
4649e4fd900SJohn Levonfunction build_tools {
4659e4fd900SJohn Levon	DESTROOT=$1
4669e4fd900SJohn Levon
4679e4fd900SJohn Levon	INSTALLOG=install-${MACH}
4689e4fd900SJohn Levon
4699e4fd900SJohn Levon	echo "\n==== Building tools at `date` ====\n" \
4709e4fd900SJohn Levon		>> $LOGFILE
4719e4fd900SJohn Levon
4729e4fd900SJohn Levon	rm -f ${TOOLS}/${INSTALLOG}.out
4739e4fd900SJohn Levon	cd ${TOOLS}
4749e4fd900SJohn Levon	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
4759e4fd900SJohn Levon	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
4769e4fd900SJohn Levon
4779e4fd900SJohn Levon	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
4789e4fd900SJohn Levon
4799e4fd900SJohn Levon	egrep ":" ${TOOLS}/${INSTALLOG}.out |
4809e4fd900SJohn Levon		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
4819e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
4829e4fd900SJohn Levon		egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file
4839e4fd900SJohn Levon
4849e4fd900SJohn Levon	if [[ -s $TMPDIR/tools_errors ]]; then
4859e4fd900SJohn Levon		return 1
4869e4fd900SJohn Levon	fi
4879e4fd900SJohn Levon	return 0
4889e4fd900SJohn Levon}
4899e4fd900SJohn Levon
4909e4fd900SJohn Levon#
4919e4fd900SJohn Levon# Set up to use locally installed tools.
4929e4fd900SJohn Levon#
4939e4fd900SJohn Levon# usage: use_tools TOOLSROOT
4949e4fd900SJohn Levon#
4959e4fd900SJohn Levonfunction use_tools {
4969e4fd900SJohn Levon	TOOLSROOT=$1
4979e4fd900SJohn Levon
4989e4fd900SJohn Levon	#
4999e4fd900SJohn Levon	# If we're not building ON workspace, then the TOOLSROOT
5009e4fd900SJohn Levon	# settings here are clearly ignored by the workspace
5019e4fd900SJohn Levon	# makefiles, prepending nonexistent directories to PATH is
5029e4fd900SJohn Levon	# harmless, and we clearly do not wish to override
5039e4fd900SJohn Levon	# ONBLD_TOOLS.
5049e4fd900SJohn Levon	#
5059e4fd900SJohn Levon	# If we're building an ON workspace, then the prepended PATH
5069e4fd900SJohn Levon	# elements should supercede the preexisting ONBLD_TOOLS paths,
5079e4fd900SJohn Levon	# and we want to override ONBLD_TOOLS to catch the tools that
5089e4fd900SJohn Levon	# don't have specific path env vars here.
5099e4fd900SJohn Levon	#
5109e4fd900SJohn Levon	# So the only conditional behavior is overriding ONBLD_TOOLS,
5119e4fd900SJohn Levon	# and we check for "an ON workspace" by looking for
5129e4fd900SJohn Levon	# ${TOOLSROOT}/opt/onbld.
5139e4fd900SJohn Levon	#
5149e4fd900SJohn Levon
5159e4fd900SJohn Levon	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
5169e4fd900SJohn Levon	export STABS
5179e4fd900SJohn Levon	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
5189e4fd900SJohn Levon	export CTFSTABS
5199e4fd900SJohn Levon	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
5209e4fd900SJohn Levon	export GENOFFSETS
5219e4fd900SJohn Levon
5229e4fd900SJohn Levon	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
5239e4fd900SJohn Levon	export CTFCONVERT
5249e4fd900SJohn Levon	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
5259e4fd900SJohn Levon	export CTFMERGE
5269e4fd900SJohn Levon
5279e4fd900SJohn Levon	if [ "$VERIFY_ELFSIGN" = "y" ]; then
5289e4fd900SJohn Levon		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
5299e4fd900SJohn Levon	else
5309e4fd900SJohn Levon		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
5319e4fd900SJohn Levon	fi
5329e4fd900SJohn Levon	export ELFSIGN
5339e4fd900SJohn Levon
5349e4fd900SJohn Levon	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
5359e4fd900SJohn Levon	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
5369e4fd900SJohn Levon	export PATH
5379e4fd900SJohn Levon
5389e4fd900SJohn Levon	if [ -d "${TOOLSROOT}/opt/onbld" ]; then
5399e4fd900SJohn Levon		ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
5409e4fd900SJohn Levon		export ONBLD_TOOLS
5419e4fd900SJohn Levon	fi
5429e4fd900SJohn Levon
5439e4fd900SJohn Levon	echo "\n==== New environment settings. ====\n" >> $LOGFILE
5449e4fd900SJohn Levon	echo "STABS=${STABS}" >> $LOGFILE
5459e4fd900SJohn Levon	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
5469e4fd900SJohn Levon	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
5479e4fd900SJohn Levon	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
5489e4fd900SJohn Levon	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
5499e4fd900SJohn Levon	echo "PATH=${PATH}" >> $LOGFILE
5509e4fd900SJohn Levon	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
5519e4fd900SJohn Levon}
5529e4fd900SJohn Levon
5539e4fd900SJohn Levonfunction staffer {
5549e4fd900SJohn Levon	if [ $ISUSER -ne 0 ]; then
5559e4fd900SJohn Levon		"$@"
5569e4fd900SJohn Levon	else
5579e4fd900SJohn Levon		arg="\"$1\""
5589e4fd900SJohn Levon		shift
5599e4fd900SJohn Levon		for i
5609e4fd900SJohn Levon		do
5619e4fd900SJohn Levon			arg="$arg \"$i\""
5629e4fd900SJohn Levon		done
5639e4fd900SJohn Levon		eval su $STAFFER -c \'$arg\'
5649e4fd900SJohn Levon	fi
5659e4fd900SJohn Levon}
5669e4fd900SJohn Levon
5679e4fd900SJohn Levon#
5689e4fd900SJohn Levon# Verify that the closed bins are present
5699e4fd900SJohn Levon#
5709e4fd900SJohn Levonfunction check_closed_bins {
5719e4fd900SJohn Levon	if [[ ! -d "$ON_CLOSED_BINS" ]]; then
5729e4fd900SJohn Levon		echo "ON_CLOSED_BINS must point to the closed binaries tree."
5739e4fd900SJohn Levon		build_ok=n
5749e4fd900SJohn Levon		exit 1
5759e4fd900SJohn Levon	fi
5769e4fd900SJohn Levon}
5779e4fd900SJohn Levon
5789e4fd900SJohn Levon#
5799e4fd900SJohn Levon# wrapper over wsdiff.
5809e4fd900SJohn Levon# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
5819e4fd900SJohn Levon#
5829e4fd900SJohn Levonfunction do_wsdiff {
5839e4fd900SJohn Levon	label=$1
5849e4fd900SJohn Levon	oldproto=$2
5859e4fd900SJohn Levon	newproto=$3
586bf16a978SMarcel Telka	results=$4
5879e4fd900SJohn Levon
5889e4fd900SJohn Levon	wsdiff="wsdiff"
5899e4fd900SJohn Levon	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
5909e4fd900SJohn Levon
5919e4fd900SJohn Levon	echo "\n==== Getting object changes since last build at `date`" \
5929e4fd900SJohn Levon	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
593bf16a978SMarcel Telka	$wsdiff -s -r ${TMPDIR}/$results $oldproto $newproto 2>&1 | \
5949e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
5959e4fd900SJohn Levon	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
5969e4fd900SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
5979e4fd900SJohn Levon}
5989e4fd900SJohn Levon
5999e4fd900SJohn Levon#
6009e4fd900SJohn Levon# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
6019e4fd900SJohn Levon# together.
6029e4fd900SJohn Levon#
6039e4fd900SJohn Levon
6049e4fd900SJohn Levonfunction set_non_debug_build_flags {
6059e4fd900SJohn Levon	export RELEASE_BUILD ; RELEASE_BUILD=
6069e4fd900SJohn Levon	unset EXTRA_OPTIONS
6079e4fd900SJohn Levon	unset EXTRA_CFLAGS
6089e4fd900SJohn Levon}
6099e4fd900SJohn Levon
6109e4fd900SJohn Levonfunction set_debug_build_flags {
6119e4fd900SJohn Levon	unset RELEASE_BUILD
6129e4fd900SJohn Levon	unset EXTRA_OPTIONS
6139e4fd900SJohn Levon	unset EXTRA_CFLAGS
6149e4fd900SJohn Levon}
6159e4fd900SJohn Levon
6169e4fd900SJohn Levon
6179e4fd900SJohn LevonMACH=`uname -p`
6189e4fd900SJohn Levon
6199e4fd900SJohn Levonif [ "$OPTHOME" = "" ]; then
6209e4fd900SJohn Levon	OPTHOME=/opt
6219e4fd900SJohn Levon	export OPTHOME
6229e4fd900SJohn Levonfi
6239e4fd900SJohn Levon
6249e4fd900SJohn LevonUSAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file>
6259e4fd900SJohn Levon
6269e4fd900SJohn LevonWhere:
6279e4fd900SJohn Levon	-i	Fast incremental options (no clobber, lint, check)
6289e4fd900SJohn Levon	-n      Do not do a bringover
6299e4fd900SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
6309e4fd900SJohn Levon	-V VERS set the build version string to VERS
6319e4fd900SJohn Levon
6329e4fd900SJohn Levon	<env_file>  file in Bourne shell syntax that sets and exports
6339e4fd900SJohn Levon	variables that configure the operation of this script and many of
6349e4fd900SJohn Levon	the scripts this one calls. If <env_file> does not exist,
6359e4fd900SJohn Levon	it will be looked for in $OPTHOME/onbld/env.
6369e4fd900SJohn Levon
6379e4fd900SJohn Levonnon-DEBUG is the default build type. Build options can be set in the
6389e4fd900SJohn LevonNIGHTLY_OPTIONS variable in the <env_file> as follows:
6399e4fd900SJohn Levon
6409e4fd900SJohn Levon	-A	check for ABI differences in .so files
6419e4fd900SJohn Levon	-C	check for cstyle/hdrchk errors
6429e4fd900SJohn Levon	-D	do a build with DEBUG on
6439e4fd900SJohn Levon	-F	do _not_ do a non-DEBUG build
6449e4fd900SJohn Levon	-G	gate keeper default group of options (-au)
6459e4fd900SJohn Levon	-I	integration engineer default group of options (-ampu)
646*b85ab92fSAndy Fiddaman	-L	do not run pkglint
6479e4fd900SJohn Levon	-M	do not run pmodes (safe file permission checker)
6489e4fd900SJohn Levon	-N	do not run protocmp
6499e4fd900SJohn Levon	-R	default group of options for building a release (-mp)
6509e4fd900SJohn Levon	-U	update proto area in the parent
6519e4fd900SJohn Levon	-V VERS set the build version string to VERS
6529e4fd900SJohn Levon	-f	find unreferenced files
6539e4fd900SJohn Levon	-i	do an incremental build (no "make clobber")
6549e4fd900SJohn Levon	-l	do "make lint" in $LINTDIRS (default: $SRC y)
6559e4fd900SJohn Levon	-m	send mail to $MAILTO at end of build
6569e4fd900SJohn Levon	-n      do not do a bringover
6579e4fd900SJohn Levon	-p	create packages
6589e4fd900SJohn Levon	-r	check ELF runtime attributes in the proto area
6599e4fd900SJohn Levon	-t	build and use the tools in $SRC/tools (default setting)
6609e4fd900SJohn Levon	+t	Use the build tools in $ONBLD_TOOLS/bin
6619e4fd900SJohn Levon	-u	update proto_list_$MACH and friends in the parent workspace;
6629e4fd900SJohn Levon		when used with -f, also build an unrefmaster.out in the parent
6639e4fd900SJohn Levon	-w	report on differences between previous and current proto areas
6649e4fd900SJohn Levon'
6659e4fd900SJohn Levon#
6669e4fd900SJohn Levon#	A log file will be generated under the name $LOGFILE
6679e4fd900SJohn Levon#	for partially completed build and log.`date '+%F'`
6689e4fd900SJohn Levon#	in the same directory for fully completed builds.
6699e4fd900SJohn Levon#
6709e4fd900SJohn Levon
6719e4fd900SJohn Levon# default values for low-level FLAGS; G I R are group FLAGS
6729e4fd900SJohn LevonA_FLAG=n
6739e4fd900SJohn LevonC_FLAG=n
6749e4fd900SJohn LevonD_FLAG=n
6759e4fd900SJohn LevonF_FLAG=n
6769e4fd900SJohn Levonf_FLAG=n
6779e4fd900SJohn Levoni_FLAG=n; i_CMD_LINE_FLAG=n
678*b85ab92fSAndy FiddamanL_FLAG=n
6799e4fd900SJohn Levonl_FLAG=n
6809e4fd900SJohn LevonM_FLAG=n
6819e4fd900SJohn Levonm_FLAG=n
6829e4fd900SJohn LevonN_FLAG=n
6839e4fd900SJohn Levonn_FLAG=n
6849e4fd900SJohn Levonp_FLAG=n
6859e4fd900SJohn Levonr_FLAG=n
6869e4fd900SJohn Levont_FLAG=y
6879e4fd900SJohn LevonU_FLAG=n
6889e4fd900SJohn Levonu_FLAG=n
6899e4fd900SJohn LevonV_FLAG=n
6909e4fd900SJohn Levonw_FLAG=n
6919e4fd900SJohn LevonW_FLAG=n
6929e4fd900SJohn Levon#
6939e4fd900SJohn Levonbuild_ok=y
6949e4fd900SJohn Levonbuild_extras_ok=y
6959e4fd900SJohn Levon
6969e4fd900SJohn Levon#
6979e4fd900SJohn Levon# examine arguments
6989e4fd900SJohn Levon#
6999e4fd900SJohn Levon
7009e4fd900SJohn LevonOPTIND=1
7019e4fd900SJohn Levonwhile getopts +intV:W FLAG
7029e4fd900SJohn Levondo
7039e4fd900SJohn Levon	case $FLAG in
7049e4fd900SJohn Levon	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
7059e4fd900SJohn Levon		;;
7069e4fd900SJohn Levon	  n )	n_FLAG=y
7079e4fd900SJohn Levon		;;
7089e4fd900SJohn Levon	 +t )	t_FLAG=n
7099e4fd900SJohn Levon		;;
7109e4fd900SJohn Levon	  V )	V_FLAG=y
7119e4fd900SJohn Levon		V_ARG="$OPTARG"
7129e4fd900SJohn Levon		;;
7139e4fd900SJohn Levon	  W )   W_FLAG=y
7149e4fd900SJohn Levon		;;
7159e4fd900SJohn Levon	 \? )	echo "$USAGE"
7169e4fd900SJohn Levon		exit 1
7179e4fd900SJohn Levon		;;
7189e4fd900SJohn Levon	esac
7199e4fd900SJohn Levondone
7209e4fd900SJohn Levon
7219e4fd900SJohn Levon# correct argument count after options
7229e4fd900SJohn Levonshift `expr $OPTIND - 1`
7239e4fd900SJohn Levon
7249e4fd900SJohn Levon# test that the path to the environment-setting file was given
7259e4fd900SJohn Levonif [ $# -ne 1 ]; then
7269e4fd900SJohn Levon	echo "$USAGE"
7279e4fd900SJohn Levon	exit 1
7289e4fd900SJohn Levonfi
7299e4fd900SJohn Levon
7309e4fd900SJohn Levon# check if user is running nightly as root
7319e4fd900SJohn Levon# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
7329e4fd900SJohn Levon# when root invokes nightly.
7339e4fd900SJohn Levon/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
7349e4fd900SJohn LevonISUSER=$?;	export ISUSER
7359e4fd900SJohn Levon
7369e4fd900SJohn Levon#
7379e4fd900SJohn Levon# force locale to C
7389e4fd900SJohn LevonLANG=C;		export LANG
7399e4fd900SJohn LevonLC_ALL=C;	export LC_ALL
7409e4fd900SJohn LevonLC_COLLATE=C;	export LC_COLLATE
7419e4fd900SJohn LevonLC_CTYPE=C;	export LC_CTYPE
7429e4fd900SJohn LevonLC_MESSAGES=C;	export LC_MESSAGES
7439e4fd900SJohn LevonLC_MONETARY=C;	export LC_MONETARY
7449e4fd900SJohn LevonLC_NUMERIC=C;	export LC_NUMERIC
7459e4fd900SJohn LevonLC_TIME=C;	export LC_TIME
7469e4fd900SJohn Levon
7479e4fd900SJohn Levon# clear environment variables we know to be bad for the build
7489e4fd900SJohn Levonunset LD_OPTIONS
7499e4fd900SJohn Levonunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
7509e4fd900SJohn Levonunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
7519e4fd900SJohn Levonunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
7529e4fd900SJohn Levonunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
7539e4fd900SJohn Levonunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
7549e4fd900SJohn Levonunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
7559e4fd900SJohn Levonunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
7569e4fd900SJohn Levonunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
7579e4fd900SJohn Levonunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
7589e4fd900SJohn Levonunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
7599e4fd900SJohn Levonunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
7609e4fd900SJohn Levonunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
7619e4fd900SJohn Levonunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
7629e4fd900SJohn Levonunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
7639e4fd900SJohn Levonunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
7649e4fd900SJohn Levonunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
7659e4fd900SJohn Levonunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
7669e4fd900SJohn Levonunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
7679e4fd900SJohn Levonunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
7689e4fd900SJohn Levonunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
7699e4fd900SJohn Levon
7709e4fd900SJohn Levonunset CONFIG
7719e4fd900SJohn Levonunset GROUP
7729e4fd900SJohn Levonunset OWNER
7739e4fd900SJohn Levonunset REMOTE
7749e4fd900SJohn Levonunset ENV
7759e4fd900SJohn Levonunset ARCH
7769e4fd900SJohn Levonunset CLASSPATH
7779e4fd900SJohn Levonunset NAME
7789e4fd900SJohn Levon
7799e4fd900SJohn Levon#
7809e4fd900SJohn Levon# To get ONBLD_TOOLS from the environment, it must come from the env file.
7819e4fd900SJohn Levon# If it comes interactively, it is generally TOOLS_PROTO, which will be
7829e4fd900SJohn Levon# clobbered before the compiler version checks, which will therefore fail.
7839e4fd900SJohn Levon#
7849e4fd900SJohn Levonunset ONBLD_TOOLS
7859e4fd900SJohn Levon
7869e4fd900SJohn Levon#
7879e4fd900SJohn Levon#	Setup environmental variables
7889e4fd900SJohn Levon#
7899e4fd900SJohn Levonif [ -f /etc/nightly.conf ]; then
7909e4fd900SJohn Levon	. /etc/nightly.conf
7919e4fd900SJohn Levonfi
7929e4fd900SJohn Levon
7939e4fd900SJohn Levonif [ -f $1 ]; then
7949e4fd900SJohn Levon	if [[ $1 = */* ]]; then
7959e4fd900SJohn Levon		. $1
7969e4fd900SJohn Levon	else
7979e4fd900SJohn Levon		. ./$1
7989e4fd900SJohn Levon	fi
7999e4fd900SJohn Levonelse
8009e4fd900SJohn Levon	if [ -f $OPTHOME/onbld/env/$1 ]; then
8019e4fd900SJohn Levon		. $OPTHOME/onbld/env/$1
8029e4fd900SJohn Levon	else
8039e4fd900SJohn Levon		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
8049e4fd900SJohn Levon		exit 1
8059e4fd900SJohn Levon	fi
8069e4fd900SJohn Levonfi
8079e4fd900SJohn Levon
8089e4fd900SJohn Levon# Check if we have sufficient data to continue...
8099e4fd900SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
8109e4fd900SJohn Levonif  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
8119e4fd900SJohn Levon	# Check if the gate data are valid if we don't do a "bringover" below
8129e4fd900SJohn Levon	[[ -d "${CODEMGR_WS}" ]] || \
8139e4fd900SJohn Levon		fatal_error "Error: ${CODEMGR_WS} is not a directory."
8149e4fd900SJohn Levon	[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
8159e4fd900SJohn Levon		fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
8169e4fd900SJohn Levonfi
8179e4fd900SJohn Levon
8189e4fd900SJohn Levon#
8199e4fd900SJohn Levon# place ourselves in a new task, respecting BUILD_PROJECT if set.
8209e4fd900SJohn Levon#
8219e4fd900SJohn Levonif [ -z "$BUILD_PROJECT" ]; then
8229e4fd900SJohn Levon	/usr/bin/newtask -c $$
8239e4fd900SJohn Levonelse
8249e4fd900SJohn Levon	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
8259e4fd900SJohn Levonfi
8269e4fd900SJohn Levon
8279e4fd900SJohn Levonps -o taskid= -p $$ | read build_taskid
8289e4fd900SJohn Levonps -o project= -p $$ | read build_project
8299e4fd900SJohn Levon
8309e4fd900SJohn Levon#
8319e4fd900SJohn Levon# See if NIGHTLY_OPTIONS is set
8329e4fd900SJohn Levon#
8339e4fd900SJohn Levonif [ "$NIGHTLY_OPTIONS" = "" ]; then
8349e4fd900SJohn Levon	NIGHTLY_OPTIONS="-aBm"
8359e4fd900SJohn Levonfi
8369e4fd900SJohn Levon
8379e4fd900SJohn Levon#
8389e4fd900SJohn Levon# If BRINGOVER_WS was not specified, let it default to CLONE_WS
8399e4fd900SJohn Levon#
8409e4fd900SJohn Levonif [ "$BRINGOVER_WS" = "" ]; then
8419e4fd900SJohn Levon	BRINGOVER_WS=$CLONE_WS
8429e4fd900SJohn Levonfi
8439e4fd900SJohn Levon
8449e4fd900SJohn Levon#
8459e4fd900SJohn Levon# If BRINGOVER_FILES was not specified, default to usr
8469e4fd900SJohn Levon#
8479e4fd900SJohn Levonif [ "$BRINGOVER_FILES" = "" ]; then
8489e4fd900SJohn Levon	BRINGOVER_FILES="usr"
8499e4fd900SJohn Levonfi
8509e4fd900SJohn Levon
8519e4fd900SJohn Levoncheck_closed_bins
8529e4fd900SJohn Levon
8539e4fd900SJohn Levon#
8549e4fd900SJohn Levon# Note: changes to the option letters here should also be applied to the
8559e4fd900SJohn Levon#	bldenv script.  `d' is listed for backward compatibility.
8569e4fd900SJohn Levon#
8579e4fd900SJohn LevonNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
8589e4fd900SJohn LevonOPTIND=1
859*b85ab92fSAndy Fiddamanwhile getopts +ABCDdFfGIiLlMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS
8609e4fd900SJohn Levondo
8619e4fd900SJohn Levon	case $FLAG in
8629e4fd900SJohn Levon	  A )	A_FLAG=y
8639e4fd900SJohn Levon		;;
8649e4fd900SJohn Levon	  B )	D_FLAG=y
8659e4fd900SJohn Levon		;; # old version of D
8669e4fd900SJohn Levon	  C )	C_FLAG=y
8679e4fd900SJohn Levon		;;
8689e4fd900SJohn Levon	  D )	D_FLAG=y
8699e4fd900SJohn Levon		;;
8709e4fd900SJohn Levon	  F )	F_FLAG=y
8719e4fd900SJohn Levon		;;
8729e4fd900SJohn Levon	  f )	f_FLAG=y
8739e4fd900SJohn Levon		;;
8749e4fd900SJohn Levon	  G )   u_FLAG=y
8759e4fd900SJohn Levon		;;
8769e4fd900SJohn Levon	  I )	m_FLAG=y
8779e4fd900SJohn Levon		p_FLAG=y
8789e4fd900SJohn Levon		u_FLAG=y
8799e4fd900SJohn Levon		;;
8809e4fd900SJohn Levon	  i )	i_FLAG=y
8819e4fd900SJohn Levon		;;
882*b85ab92fSAndy Fiddaman	  L )	L_FLAG=y
883*b85ab92fSAndy Fiddaman		;;
8849e4fd900SJohn Levon	  l )	l_FLAG=y
8859e4fd900SJohn Levon		;;
8869e4fd900SJohn Levon	  M )	M_FLAG=y
8879e4fd900SJohn Levon		;;
8889e4fd900SJohn Levon	  m )	m_FLAG=y
8899e4fd900SJohn Levon		;;
8909e4fd900SJohn Levon	  N )	N_FLAG=y
8919e4fd900SJohn Levon		;;
8929e4fd900SJohn Levon	  n )	n_FLAG=y
8939e4fd900SJohn Levon		;;
8949e4fd900SJohn Levon	  p )	p_FLAG=y
8959e4fd900SJohn Levon		;;
8969e4fd900SJohn Levon	  R )	m_FLAG=y
8979e4fd900SJohn Levon		p_FLAG=y
8989e4fd900SJohn Levon		;;
8999e4fd900SJohn Levon	  r )	r_FLAG=y
9009e4fd900SJohn Levon		;;
9019e4fd900SJohn Levon	 +t )	t_FLAG=n
9029e4fd900SJohn Levon		;;
9039e4fd900SJohn Levon	  U )   if [ -z "${PARENT_ROOT}" ]; then
9049e4fd900SJohn Levon			echo "PARENT_ROOT must be set if the U flag is" \
9059e4fd900SJohn Levon			    "present in NIGHTLY_OPTIONS."
9069e4fd900SJohn Levon			exit 1
9079e4fd900SJohn Levon		fi
9089e4fd900SJohn Levon		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
9099e4fd900SJohn Levon		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
9109e4fd900SJohn Levon			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
9119e4fd900SJohn Levon		fi
9129e4fd900SJohn Levon		U_FLAG=y
9139e4fd900SJohn Levon		;;
9149e4fd900SJohn Levon	  u )	u_FLAG=y
9159e4fd900SJohn Levon		;;
9169e4fd900SJohn Levon	  w )	w_FLAG=y
9179e4fd900SJohn Levon		;;
9189e4fd900SJohn Levon	  W )   W_FLAG=y
9199e4fd900SJohn Levon		;;
9209e4fd900SJohn Levon	 \? )	echo "$USAGE"
9219e4fd900SJohn Levon		exit 1
9229e4fd900SJohn Levon		;;
9239e4fd900SJohn Levon	esac
9249e4fd900SJohn Levondone
9259e4fd900SJohn Levon
9269e4fd900SJohn Levonif [ $ISUSER -ne 0 ]; then
9279e4fd900SJohn Levon	# Set default value for STAFFER, if needed.
9289e4fd900SJohn Levon	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
9299e4fd900SJohn Levon		STAFFER=`/usr/xpg4/bin/id -un`
9309e4fd900SJohn Levon		export STAFFER
9319e4fd900SJohn Levon	fi
9329e4fd900SJohn Levonfi
9339e4fd900SJohn Levon
9349e4fd900SJohn Levonif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
9359e4fd900SJohn Levon	MAILTO=$STAFFER
9369e4fd900SJohn Levon	export MAILTO
9379e4fd900SJohn Levonfi
9389e4fd900SJohn Levon
9399e4fd900SJohn LevonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
9409e4fd900SJohn LevonPATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
9419e4fd900SJohn LevonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
9429e4fd900SJohn Levonexport PATH
9439e4fd900SJohn Levon
9449e4fd900SJohn Levon# roots of source trees, both relative to $SRC and absolute.
9459e4fd900SJohn Levonrelsrcdirs="."
9469e4fd900SJohn Levonabssrcdirs="$SRC"
9479e4fd900SJohn Levon
9489e4fd900SJohn LevonPROTOCMPTERSE="protocmp.terse -gu"
9499e4fd900SJohn LevonPOUND_SIGN="#"
9509e4fd900SJohn Levon# have we set RELEASE_DATE in our env file?
9519e4fd900SJohn Levonif [ -z "$RELEASE_DATE" ]; then
9529e4fd900SJohn Levon	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
9539e4fd900SJohn Levonfi
9549e4fd900SJohn LevonBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
9559e4fd900SJohn LevonBASEWSDIR=$(basename $CODEMGR_WS)
9569e4fd900SJohn LevonDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
9579e4fd900SJohn Levon
9589e4fd900SJohn Levon# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
9599e4fd900SJohn Levon# by avoiding repeated shell invocations to evaluate Makefile.master
9609e4fd900SJohn Levon# definitions.
9619e4fd900SJohn Levonexport POUND_SIGN RELEASE_DATE DEV_CM
9629e4fd900SJohn Levon
9639e4fd900SJohn Levonmaketype="distributed"
9649e4fd900SJohn Levonif [[ -z "$MAKE" ]]; then
9659e4fd900SJohn Levon	MAKE=dmake
9669e4fd900SJohn Levonelif [[ ! -x "$MAKE" ]]; then
9679e4fd900SJohn Levon	echo "\$MAKE is set to garbage in the environment"
9689e4fd900SJohn Levon	exit 1
9699e4fd900SJohn Levonfi
9709e4fd900SJohn Levonexport PATH
9719e4fd900SJohn Levonexport MAKE
9729e4fd900SJohn Levon
9739e4fd900SJohn Levonif [ "${SUNWSPRO}" != "" ]; then
9749e4fd900SJohn Levon	PATH="${SUNWSPRO}/bin:$PATH"
9759e4fd900SJohn Levon	export PATH
9769e4fd900SJohn Levonfi
9779e4fd900SJohn Levon
9789e4fd900SJohn Levonhostname=$(uname -n)
9799e4fd900SJohn Levonif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
9809e4fd900SJohn Levonthen
9819e4fd900SJohn Levon	maxjobs=
9829e4fd900SJohn Levon	if [[ -f $HOME/.make.machines ]]
9839e4fd900SJohn Levon	then
9849e4fd900SJohn Levon		# Note: there is a hard tab and space character in the []s
9859e4fd900SJohn Levon		# below.
9869e4fd900SJohn Levon		egrep -i "^[ 	]*$hostname[ 	\.]" \
9879e4fd900SJohn Levon			$HOME/.make.machines | read host jobs
9889e4fd900SJohn Levon		maxjobs=${jobs##*=}
9899e4fd900SJohn Levon	fi
9909e4fd900SJohn Levon
9919e4fd900SJohn Levon	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
9929e4fd900SJohn Levon	then
9939e4fd900SJohn Levon		# default
9949e4fd900SJohn Levon		maxjobs=4
9959e4fd900SJohn Levon	fi
9969e4fd900SJohn Levon
9979e4fd900SJohn Levon	export DMAKE_MAX_JOBS=$maxjobs
9989e4fd900SJohn Levonfi
9999e4fd900SJohn Levon
10009e4fd900SJohn LevonDMAKE_MODE=parallel;
10019e4fd900SJohn Levonexport DMAKE_MODE
10029e4fd900SJohn Levon
10039e4fd900SJohn Levonif [ -z "${ROOT}" ]; then
10049e4fd900SJohn Levon	echo "ROOT must be set."
10059e4fd900SJohn Levon	exit 1
10069e4fd900SJohn Levonfi
10079e4fd900SJohn Levon
10089e4fd900SJohn Levon#
10099e4fd900SJohn Levon# if -V flag was given, reset VERSION to V_ARG
10109e4fd900SJohn Levon#
10119e4fd900SJohn Levonif [ "$V_FLAG" = "y" ]; then
10129e4fd900SJohn Levon	VERSION=$V_ARG
10139e4fd900SJohn Levonfi
10149e4fd900SJohn Levon
10159e4fd900SJohn LevonTMPDIR="/tmp/nightly.tmpdir.$$"
10169e4fd900SJohn Levonexport TMPDIR
10179e4fd900SJohn Levonrm -rf ${TMPDIR}
10189e4fd900SJohn Levonmkdir -p $TMPDIR || exit 1
10199e4fd900SJohn Levonchmod 777 $TMPDIR
10209e4fd900SJohn Levon
10219e4fd900SJohn Levon#
10229e4fd900SJohn Levon# Keep elfsign's use of pkcs11_softtoken from looking in the user home
10239e4fd900SJohn Levon# directory, which doesn't always work.   Needed until all build machines
10249e4fd900SJohn Levon# have the fix for 6271754
10259e4fd900SJohn Levon#
10269e4fd900SJohn LevonSOFTTOKEN_DIR=$TMPDIR
10279e4fd900SJohn Levonexport SOFTTOKEN_DIR
10289e4fd900SJohn Levon
10299e4fd900SJohn Levon#
10309e4fd900SJohn Levon# Tools should only be built non-DEBUG.  Keep track of the tools proto
10319e4fd900SJohn Levon# area path relative to $TOOLS, because the latter changes in an
10329e4fd900SJohn Levon# export build.
10339e4fd900SJohn Levon#
10349e4fd900SJohn Levon# TOOLS_PROTO is included below for builds other than usr/src/tools
10359e4fd900SJohn Levon# that look for this location.  For usr/src/tools, this will be
10369e4fd900SJohn Levon# overridden on the $MAKE command line in build_tools().
10379e4fd900SJohn Levon#
10389e4fd900SJohn LevonTOOLS=${SRC}/tools
10399e4fd900SJohn LevonTOOLS_PROTO_REL=proto/root_${MACH}-nd
10409e4fd900SJohn LevonTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
10419e4fd900SJohn Levon
10429e4fd900SJohn Levonunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
10439e4fd900SJohn Levon
10449e4fd900SJohn Levon# create directories that are automatically removed if the nightly script
10459e4fd900SJohn Levon# fails to start correctly
10469e4fd900SJohn Levonfunction newdir {
10479e4fd900SJohn Levon	dir=$1
10489e4fd900SJohn Levon	toadd=
10499e4fd900SJohn Levon	while [ ! -d $dir ]; do
10509e4fd900SJohn Levon		toadd="$dir $toadd"
10519e4fd900SJohn Levon		dir=`dirname $dir`
10529e4fd900SJohn Levon	done
10539e4fd900SJohn Levon	torm=
10549e4fd900SJohn Levon	newlist=
10559e4fd900SJohn Levon	for dir in $toadd; do
10569e4fd900SJohn Levon		if staffer mkdir $dir; then
10579e4fd900SJohn Levon			newlist="$ISUSER $dir $newlist"
10589e4fd900SJohn Levon			torm="$dir $torm"
10599e4fd900SJohn Levon		else
10609e4fd900SJohn Levon			[ -z "$torm" ] || staffer rmdir $torm
10619e4fd900SJohn Levon			return 1
10629e4fd900SJohn Levon		fi
10639e4fd900SJohn Levon	done
10649e4fd900SJohn Levon	newdirlist="$newlist $newdirlist"
10659e4fd900SJohn Levon	return 0
10669e4fd900SJohn Levon}
10679e4fd900SJohn Levonnewdirlist=
10689e4fd900SJohn Levon
10699e4fd900SJohn Levon[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
10709e4fd900SJohn Levon
10719e4fd900SJohn Levon# since this script assumes the build is from full source, it nullifies
10729e4fd900SJohn Levon# variables likely to have been set by a "ws" script; nullification
10739e4fd900SJohn Levon# confines the search space for headers and libraries to the proto area
10749e4fd900SJohn Levon# built from this immediate source.
10759e4fd900SJohn LevonENVLDLIBS1=
10769e4fd900SJohn LevonENVLDLIBS2=
10779e4fd900SJohn LevonENVLDLIBS3=
10789e4fd900SJohn LevonENVCPPFLAGS1=
10799e4fd900SJohn LevonENVCPPFLAGS2=
10809e4fd900SJohn LevonENVCPPFLAGS3=
10819e4fd900SJohn LevonENVCPPFLAGS4=
10829e4fd900SJohn LevonPARENT_ROOT=
10839e4fd900SJohn Levon
10849e4fd900SJohn Levonexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
10859e4fd900SJohn Levon	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
10869e4fd900SJohn Levon
10879e4fd900SJohn LevonPKGARCHIVE_ORIG=$PKGARCHIVE
10889e4fd900SJohn Levon
10899e4fd900SJohn Levon#
10909e4fd900SJohn Levon# Juggle the logs and optionally send mail on completion.
10919e4fd900SJohn Levon#
10929e4fd900SJohn Levon
10939e4fd900SJohn Levonfunction logshuffle {
10949e4fd900SJohn Levon    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
10959e4fd900SJohn Levon	if [ -f $LLOG -o -d $LLOG ]; then
10969e4fd900SJohn Levon	    	LLOG=$LLOG.$$
10979e4fd900SJohn Levon	fi
10989e4fd900SJohn Levon	mkdir $LLOG
10999e4fd900SJohn Levon	export LLOG
11009e4fd900SJohn Levon
11019e4fd900SJohn Levon	if [ "$build_ok" = "y" ]; then
11029e4fd900SJohn Levon		mv $ATLOG/proto_list_${MACH} $LLOG
11039e4fd900SJohn Levon
11049e4fd900SJohn Levon		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
11059e4fd900SJohn Levon			mv $ATLOG/proto_list_tools_${MACH} $LLOG
11069e4fd900SJohn Levon	        fi
11079e4fd900SJohn Levon
11089e4fd900SJohn Levon		if [ -f $TMPDIR/wsdiff.results ]; then
11099e4fd900SJohn Levon		    	mv $TMPDIR/wsdiff.results $LLOG
11109e4fd900SJohn Levon		fi
11119e4fd900SJohn Levon
11129e4fd900SJohn Levon		if [ -f $TMPDIR/wsdiff-nd.results ]; then
11139e4fd900SJohn Levon			mv $TMPDIR/wsdiff-nd.results $LLOG
11149e4fd900SJohn Levon		fi
1115bf16a978SMarcel Telka
1116bf16a978SMarcel Telka		if [ -f $TMPDIR/wsdiff-tools.results ]; then
1117bf16a978SMarcel Telka			mv $TMPDIR/wsdiff-tools.results $LLOG
1118bf16a978SMarcel Telka		fi
11199e4fd900SJohn Levon	fi
11209e4fd900SJohn Levon
11219e4fd900SJohn Levon	#
11229e4fd900SJohn Levon	# Now that we're about to send mail, it's time to check the noise
11239e4fd900SJohn Levon	# file.  In the event that an error occurs beyond this point, it will
11249e4fd900SJohn Levon	# be recorded in the nightly.log file, but nowhere else.  This would
11259e4fd900SJohn Levon	# include only errors that cause the copying of the noise log to fail
11269e4fd900SJohn Levon	# or the mail itself not to be sent.
11279e4fd900SJohn Levon	#
11289e4fd900SJohn Levon
11299e4fd900SJohn Levon	exec >>$LOGFILE 2>&1
11309e4fd900SJohn Levon	if [ -s $build_noise_file ]; then
11319e4fd900SJohn Levon	    	echo "\n==== Nightly build noise ====\n" |
11329e4fd900SJohn Levon		    tee -a $LOGFILE >>$mail_msg_file
11339e4fd900SJohn Levon		cat $build_noise_file >>$LOGFILE
11349e4fd900SJohn Levon		cat $build_noise_file >>$mail_msg_file
11359e4fd900SJohn Levon		echo | tee -a $LOGFILE >>$mail_msg_file
11369e4fd900SJohn Levon	fi
11379e4fd900SJohn Levon	rm -f $build_noise_file
11389e4fd900SJohn Levon
11399e4fd900SJohn Levon	case "$build_ok" in
11409e4fd900SJohn Levon		y)
11419e4fd900SJohn Levon			state=Completed
11429e4fd900SJohn Levon			;;
11439e4fd900SJohn Levon		i)
11449e4fd900SJohn Levon			state=Interrupted
11459e4fd900SJohn Levon			;;
11469e4fd900SJohn Levon		*)
11479e4fd900SJohn Levon	    		state=Failed
11489e4fd900SJohn Levon			;;
11499e4fd900SJohn Levon	esac
11509e4fd900SJohn Levon
11519e4fd900SJohn Levon	if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
11529e4fd900SJohn Levon		state=Failed
11539e4fd900SJohn Levon	fi
11549e4fd900SJohn Levon
11559e4fd900SJohn Levon	NIGHTLY_STATUS=$state
11569e4fd900SJohn Levon	export NIGHTLY_STATUS
11579e4fd900SJohn Levon
11589e4fd900SJohn Levon	run_hook POST_NIGHTLY $state
11599e4fd900SJohn Levon	run_hook SYS_POST_NIGHTLY $state
11609e4fd900SJohn Levon
11619e4fd900SJohn Levon	#
11629e4fd900SJohn Levon	# mailx(1) sets From: based on the -r flag
11639e4fd900SJohn Levon	# if it is given.
11649e4fd900SJohn Levon	#
11659e4fd900SJohn Levon	mailx_r=
11669e4fd900SJohn Levon	if [[ -n "${MAILFROM}" ]]; then
11679e4fd900SJohn Levon		mailx_r="-r ${MAILFROM}"
11689e4fd900SJohn Levon	fi
11699e4fd900SJohn Levon
11709e4fd900SJohn Levon	cat $build_time_file $build_environ_file $mail_msg_file \
11719e4fd900SJohn Levon	    > ${LLOG}/mail_msg
11729e4fd900SJohn Levon	if [ "$m_FLAG" = "y" ]; then
11739e4fd900SJohn Levon	    	cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
11749e4fd900SJohn Levon	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
11759e4fd900SJohn Levon			${MAILTO}
11769e4fd900SJohn Levon	fi
11779e4fd900SJohn Levon
11789e4fd900SJohn Levon	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
11799e4fd900SJohn Levon	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
11809e4fd900SJohn Levon		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
11819e4fd900SJohn Levon	fi
11829e4fd900SJohn Levon
11839e4fd900SJohn Levon	mv $LOGFILE $LLOG
11849e4fd900SJohn Levon}
11859e4fd900SJohn Levon
11869e4fd900SJohn Levon#
11879e4fd900SJohn Levon#	Remove the locks and temporary files on any exit
11889e4fd900SJohn Levon#
11899e4fd900SJohn Levonfunction cleanup {
11909e4fd900SJohn Levon    	logshuffle
11919e4fd900SJohn Levon
11929e4fd900SJohn Levon	[ -z "$lockfile" ] || staffer rm -f $lockfile
11939e4fd900SJohn Levon	[ -z "$atloglockfile" ] || rm -f $atloglockfile
11949e4fd900SJohn Levon	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
11959e4fd900SJohn Levon	[ -z "$Ulockfile" ] || rm -f $Ulockfile
11969e4fd900SJohn Levon
11979e4fd900SJohn Levon	set -- $newdirlist
11989e4fd900SJohn Levon	while [ $# -gt 0 ]; do
11999e4fd900SJohn Levon		ISUSER=$1 staffer rmdir $2
12009e4fd900SJohn Levon		shift; shift
12019e4fd900SJohn Levon	done
12029e4fd900SJohn Levon	rm -rf $TMPDIR
12039e4fd900SJohn Levon}
12049e4fd900SJohn Levon
12059e4fd900SJohn Levonfunction cleanup_signal {
12069e4fd900SJohn Levon    	build_ok=i
12079e4fd900SJohn Levon	# this will trigger cleanup(), above.
12089e4fd900SJohn Levon	exit 1
12099e4fd900SJohn Levon}
12109e4fd900SJohn Levon
12119e4fd900SJohn Levontrap cleanup 0
12129e4fd900SJohn Levontrap cleanup_signal 1 2 3 15
12139e4fd900SJohn Levon
12149e4fd900SJohn Levon#
12159e4fd900SJohn Levon# Generic lock file processing -- make sure that the lock file doesn't
12169e4fd900SJohn Levon# exist.  If it does, it should name the build host and PID.  If it
12179e4fd900SJohn Levon# doesn't, then make sure we can create it.  Clean up locks that are
12189e4fd900SJohn Levon# known to be stale (assumes host name is unique among build systems
12199e4fd900SJohn Levon# for the workspace).
12209e4fd900SJohn Levon#
12219e4fd900SJohn Levonfunction create_lock {
12229e4fd900SJohn Levon	lockf=$1
12239e4fd900SJohn Levon	lockvar=$2
12249e4fd900SJohn Levon
12259e4fd900SJohn Levon	ldir=`dirname $lockf`
12269e4fd900SJohn Levon	[ -d $ldir ] || newdir $ldir || exit 1
12279e4fd900SJohn Levon	eval $lockvar=$lockf
12289e4fd900SJohn Levon
12299e4fd900SJohn Levon	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
12309e4fd900SJohn Levon		basews=`basename $CODEMGR_WS`
12319e4fd900SJohn Levon		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
12329e4fd900SJohn Levon		if [ "$host" != "$hostname" ]; then
12339e4fd900SJohn Levon			echo "$MACH build of $basews apparently" \
12349e4fd900SJohn Levon			    "already started by $user on $host as $pid."
12359e4fd900SJohn Levon			exit 1
12369e4fd900SJohn Levon		elif kill -s 0 $pid 2>/dev/null; then
12379e4fd900SJohn Levon			echo "$MACH build of $basews already started" \
12389e4fd900SJohn Levon			    "by $user as $pid."
12399e4fd900SJohn Levon			exit 1
12409e4fd900SJohn Levon		else
12419e4fd900SJohn Levon			# stale lock; clear it out and try again
12429e4fd900SJohn Levon			rm -f $lockf
12439e4fd900SJohn Levon		fi
12449e4fd900SJohn Levon	done
12459e4fd900SJohn Levon}
12469e4fd900SJohn Levon
12479e4fd900SJohn Levon#
12489e4fd900SJohn Levon# Return the list of interesting proto areas, depending on the current
12499e4fd900SJohn Levon# options.
12509e4fd900SJohn Levon#
12519e4fd900SJohn Levonfunction allprotos {
12529e4fd900SJohn Levon	typeset roots="$ROOT"
12539e4fd900SJohn Levon
12549e4fd900SJohn Levon	if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
12559e4fd900SJohn Levon		roots="$roots $ROOT-nd"
12569e4fd900SJohn Levon	fi
12579e4fd900SJohn Levon
12589e4fd900SJohn Levon	echo $roots
12599e4fd900SJohn Levon}
12609e4fd900SJohn Levon
12619e4fd900SJohn Levon# Ensure no other instance of this script is running on this host.
12629e4fd900SJohn Levon# LOCKNAME can be set in <env_file>, and is by default, but is not
12639e4fd900SJohn Levon# required due to the use of $ATLOG below.
12649e4fd900SJohn Levonif [ -n "$LOCKNAME" ]; then
12659e4fd900SJohn Levon	create_lock /tmp/$LOCKNAME "lockfile"
12669e4fd900SJohn Levonfi
12679e4fd900SJohn Levon#
12689e4fd900SJohn Levon# Create from one, two, or three other locks:
12699e4fd900SJohn Levon#	$ATLOG/nightly.lock
12709e4fd900SJohn Levon#		- protects against multiple builds in same workspace
12719e4fd900SJohn Levon#	$PARENT_WS/usr/src/nightly.$MACH.lock
12729e4fd900SJohn Levon#		- protects against multiple 'u' copy-backs
12739e4fd900SJohn Levon#	$NIGHTLY_PARENT_ROOT/nightly.lock
12749e4fd900SJohn Levon#		- protects against multiple 'U' copy-backs
12759e4fd900SJohn Levon#
12769e4fd900SJohn Levon# Overriding ISUSER to 1 causes the lock to be created as root if the
12779e4fd900SJohn Levon# script is run as root.  The default is to create it as $STAFFER.
12789e4fd900SJohn LevonISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
12799e4fd900SJohn Levonif [ "$u_FLAG" = "y" ]; then
12809e4fd900SJohn Levon	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
12819e4fd900SJohn Levonfi
12829e4fd900SJohn Levonif [ "$U_FLAG" = "y" ]; then
12839e4fd900SJohn Levon	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
12849e4fd900SJohn Levon	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
12859e4fd900SJohn Levonfi
12869e4fd900SJohn Levon
12879e4fd900SJohn Levon# Locks have been taken, so we're doing a build and we're committed to
12889e4fd900SJohn Levon# the directories we may have created so far.
12899e4fd900SJohn Levonnewdirlist=
12909e4fd900SJohn Levon
12919e4fd900SJohn Levon#
12929e4fd900SJohn Levon# Create mail_msg_file
12939e4fd900SJohn Levon#
12949e4fd900SJohn Levonmail_msg_file="${TMPDIR}/mail_msg"
12959e4fd900SJohn Levontouch $mail_msg_file
12969e4fd900SJohn Levonbuild_time_file="${TMPDIR}/build_time"
12979e4fd900SJohn Levonbuild_environ_file="${TMPDIR}/build_environ"
12989e4fd900SJohn Levontouch $build_environ_file
12999e4fd900SJohn Levon#
13009e4fd900SJohn Levon#	Move old LOGFILE aside
13019e4fd900SJohn Levon#	ATLOG directory already made by 'create_lock' above
13029e4fd900SJohn Levon#
13039e4fd900SJohn Levonif [ -f $LOGFILE ]; then
13049e4fd900SJohn Levon	mv -f $LOGFILE ${LOGFILE}-
13059e4fd900SJohn Levonfi
13069e4fd900SJohn Levon#
13079e4fd900SJohn Levon#	Build OsNet source
13089e4fd900SJohn Levon#
13099e4fd900SJohn LevonSTART_DATE=`date`
13109e4fd900SJohn LevonSECONDS=0
13119e4fd900SJohn Levonecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
13129e4fd900SJohn Levon    | tee -a $LOGFILE > $build_time_file
13139e4fd900SJohn Levon
13149e4fd900SJohn Levonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
13159e4fd900SJohn Levon    tee -a $mail_msg_file >> $LOGFILE
13169e4fd900SJohn Levon
13179e4fd900SJohn Levon# make sure we log only to the nightly build file
13189e4fd900SJohn Levonbuild_noise_file="${TMPDIR}/build_noise"
13199e4fd900SJohn Levonexec </dev/null >$build_noise_file 2>&1
13209e4fd900SJohn Levon
13219e4fd900SJohn Levonrun_hook SYS_PRE_NIGHTLY
13229e4fd900SJohn Levonrun_hook PRE_NIGHTLY
13239e4fd900SJohn Levon
13249e4fd900SJohn Levonecho "\n==== list of environment variables ====\n" >> $LOGFILE
13259e4fd900SJohn Levonenv >> $LOGFILE
13269e4fd900SJohn Levon
13279e4fd900SJohn Levonecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
13289e4fd900SJohn Levon
13299e4fd900SJohn Levonif [ "$N_FLAG" = "y" ]; then
13309e4fd900SJohn Levon	if [ "$p_FLAG" = "y" ]; then
13319e4fd900SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
13329e4fd900SJohn LevonWARNING: the p option (create packages) is set, but so is the N option (do
13339e4fd900SJohn Levon         not run protocmp); this is dangerous; you should unset the N option
13349e4fd900SJohn LevonEOF
13359e4fd900SJohn Levon	else
13369e4fd900SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
13379e4fd900SJohn LevonWarning: the N option (do not run protocmp) is set; it probably shouldn't be
13389e4fd900SJohn LevonEOF
13399e4fd900SJohn Levon	fi
13409e4fd900SJohn Levon	echo "" | tee -a $mail_msg_file >> $LOGFILE
13419e4fd900SJohn Levonfi
13429e4fd900SJohn Levon
13439e4fd900SJohn Levonif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
13449e4fd900SJohn Levon	#
13459e4fd900SJohn Levon	# In the past we just complained but went ahead with the lint
13469e4fd900SJohn Levon	# pass, even though the proto area was built non-DEBUG.  It's
13479e4fd900SJohn Levon	# unlikely that non-DEBUG headers will make a difference, but
13489e4fd900SJohn Levon	# rather than assuming it's a safe combination, force the user
13499e4fd900SJohn Levon	# to specify a DEBUG build.
13509e4fd900SJohn Levon	#
13519e4fd900SJohn Levon	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
13529e4fd900SJohn Levon	    | tee -a $mail_msg_file >> $LOGFILE
13539e4fd900SJohn Levon	l_FLAG=n
13549e4fd900SJohn Levonfi
13559e4fd900SJohn Levon
13569e4fd900SJohn Levonif [ "$f_FLAG" = "y" ]; then
13579e4fd900SJohn Levon	if [ "$i_FLAG" = "y" ]; then
13589e4fd900SJohn Levon		echo "WARNING: the -f flag cannot be used during incremental" \
13599e4fd900SJohn Levon		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13609e4fd900SJohn Levon		f_FLAG=n
13619e4fd900SJohn Levon	fi
13629e4fd900SJohn Levon	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
13639e4fd900SJohn Levon		echo "WARNING: the -f flag requires -l, and -p;" \
13649e4fd900SJohn Levon		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13659e4fd900SJohn Levon		f_FLAG=n
13669e4fd900SJohn Levon	fi
13679e4fd900SJohn Levonfi
13689e4fd900SJohn Levon
13699e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
13709e4fd900SJohn Levon	echo "WARNING: -w specified, but $ROOT does not exist;" \
13719e4fd900SJohn Levon	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
13729e4fd900SJohn Levon	w_FLAG=n
13739e4fd900SJohn Levonfi
13749e4fd900SJohn Levon
13759e4fd900SJohn Levonif [ "$t_FLAG" = "n" ]; then
13769e4fd900SJohn Levon	#
13779e4fd900SJohn Levon	# We're not doing a tools build, so make sure elfsign(1) is
13789e4fd900SJohn Levon	# new enough to safely sign non-crypto binaries.  We test
13799e4fd900SJohn Levon	# debugging output from elfsign to detect the old version.
13809e4fd900SJohn Levon	#
13819e4fd900SJohn Levon	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
13829e4fd900SJohn Levon	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
13839e4fd900SJohn Levon	    | egrep algorithmOID`
13849e4fd900SJohn Levon	if [ -z "$newelfsigntest" ]; then
13859e4fd900SJohn Levon		echo "WARNING: /usr/bin/elfsign out of date;" \
13869e4fd900SJohn Levon		    "will only sign crypto modules\n" | \
13879e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
13889e4fd900SJohn Levon		export ELFSIGN_OBJECT=true
13899e4fd900SJohn Levon	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
13909e4fd900SJohn Levon		echo "WARNING: VERIFY_ELFSIGN=y requires" \
13919e4fd900SJohn Levon		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
13929e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
13939e4fd900SJohn Levon	fi
13949e4fd900SJohn Levonfi
13959e4fd900SJohn Levon
13969e4fd900SJohn Levoncase $MULTI_PROTO in
13979e4fd900SJohn Levonyes|no)	;;
13989e4fd900SJohn Levon*)
13999e4fd900SJohn Levon	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
14009e4fd900SJohn Levon	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
14019e4fd900SJohn Levon	echo "Setting MULTI_PROTO to \"no\".\n" | \
14029e4fd900SJohn Levon	    tee -a $mail_msg_file >> $LOGFILE
14039e4fd900SJohn Levon	export MULTI_PROTO=no
14049e4fd900SJohn Levon	;;
14059e4fd900SJohn Levonesac
14069e4fd900SJohn Levon
14079e4fd900SJohn Levonecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
14089e4fd900SJohn Levonecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
14099e4fd900SJohn Levon
14109e4fd900SJohn Levon# Save the current proto area if we're comparing against the last build
14119e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
14129e4fd900SJohn Levon    if [ -d "$ROOT.prev" ]; then
14139e4fd900SJohn Levon	rm -rf $ROOT.prev
14149e4fd900SJohn Levon    fi
14159e4fd900SJohn Levon    mv $ROOT $ROOT.prev
14169e4fd900SJohn Levonfi
14179e4fd900SJohn Levon
14189e4fd900SJohn Levon# Same for non-DEBUG proto area
14199e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
14209e4fd900SJohn Levon	if [ -d "$ROOT-nd.prev" ]; then
14219e4fd900SJohn Levon		rm -rf $ROOT-nd.prev
14229e4fd900SJohn Levon	fi
14239e4fd900SJohn Levon	mv $ROOT-nd $ROOT-nd.prev
14249e4fd900SJohn Levonfi
14259e4fd900SJohn Levon
1426bf16a978SMarcel Telka# Same for tools proto area
1427bf16a978SMarcel Telkaif [ "$w_FLAG" = "y" -a "$t_FLAG" == "y" -a -d "$TOOLS_PROTO" ]; then
1428bf16a978SMarcel Telka	if [ -d "$TOOLS_PROTO.prev" ]; then
1429bf16a978SMarcel Telka		rm -rf $TOOLS_PROTO.prev
1430bf16a978SMarcel Telka	fi
1431bf16a978SMarcel Telka	mv $TOOLS_PROTO $TOOLS_PROTO.prev
1432bf16a978SMarcel Telkafi
1433bf16a978SMarcel Telka
14349e4fd900SJohn Levon#
14359e4fd900SJohn Levon# Echo the SCM type of the parent workspace, this can't just be which_scm
14369e4fd900SJohn Levon# as that does not know how to identify various network repositories.
14379e4fd900SJohn Levon#
14389e4fd900SJohn Levonfunction parent_wstype {
14399e4fd900SJohn Levon	typeset scm_type junk
14409e4fd900SJohn Levon
14419e4fd900SJohn Levon	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
14429e4fd900SJohn Levon	    | read scm_type junk
14439e4fd900SJohn Levon	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
14449e4fd900SJohn Levon		# Probe BRINGOVER_WS to determine its type
14459e4fd900SJohn Levon		if [[ $BRINGOVER_WS == ssh://* ]]; then
14469e4fd900SJohn Levon			scm_type="mercurial"
14479e4fd900SJohn Levon		elif [[ $BRINGOVER_WS == http://* ]] && \
14489e4fd900SJohn Levon		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
14499e4fd900SJohn Levon		    egrep -s "application/mercurial" 2> /dev/null; then
14509e4fd900SJohn Levon			scm_type="mercurial"
14519e4fd900SJohn Levon		else
14529e4fd900SJohn Levon			scm_type="none"
14539e4fd900SJohn Levon		fi
14549e4fd900SJohn Levon	fi
14559e4fd900SJohn Levon
14569e4fd900SJohn Levon	# fold both unsupported and unrecognized results into "none"
14579e4fd900SJohn Levon	case "$scm_type" in
14589e4fd900SJohn Levon	mercurial)
14599e4fd900SJohn Levon		;;
14609e4fd900SJohn Levon	*)	scm_type=none
14619e4fd900SJohn Levon		;;
14629e4fd900SJohn Levon	esac
14639e4fd900SJohn Levon
14649e4fd900SJohn Levon	echo $scm_type
14659e4fd900SJohn Levon}
14669e4fd900SJohn Levon
14679e4fd900SJohn Levon# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
14689e4fd900SJohn Levonfunction child_wstype {
14699e4fd900SJohn Levon	typeset scm_type junk
14709e4fd900SJohn Levon
14719e4fd900SJohn Levon	# Probe CODEMGR_WS to determine its type
14729e4fd900SJohn Levon	if [[ -d $CODEMGR_WS ]]; then
14739e4fd900SJohn Levon		$WHICH_SCM | read scm_type junk || exit 1
14749e4fd900SJohn Levon	fi
14759e4fd900SJohn Levon
14769e4fd900SJohn Levon	case "$scm_type" in
14779e4fd900SJohn Levon	none|git|mercurial)
14789e4fd900SJohn Levon		;;
14799e4fd900SJohn Levon	*)	scm_type=none
14809e4fd900SJohn Levon		;;
14819e4fd900SJohn Levon	esac
14829e4fd900SJohn Levon
14839e4fd900SJohn Levon	echo $scm_type
14849e4fd900SJohn Levon}
14859e4fd900SJohn Levon
14869e4fd900SJohn LevonSCM_TYPE=$(child_wstype)
14879e4fd900SJohn Levon
14889e4fd900SJohn Levon#
14899e4fd900SJohn Levon#	Decide whether to clobber
14909e4fd900SJohn Levon#
14919e4fd900SJohn Levonif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
14929e4fd900SJohn Levon	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
14939e4fd900SJohn Levon
14949e4fd900SJohn Levon	cd $SRC
14959e4fd900SJohn Levon	# remove old clobber file
14969e4fd900SJohn Levon	rm -f $SRC/clobber.out
14979e4fd900SJohn Levon	rm -f $SRC/clobber-${MACH}.out
14989e4fd900SJohn Levon
14999e4fd900SJohn Levon	# Remove all .make.state* files, just in case we are restarting
15009e4fd900SJohn Levon	# the build after having interrupted a previous 'make clobber'.
15019e4fd900SJohn Levon	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
15029e4fd900SJohn Levon		-o -name 'interfaces.*' \) -prune \
15039e4fd900SJohn Levon		-o -name '.make.*' -print | xargs rm -f
15049e4fd900SJohn Levon
15059e4fd900SJohn Levon	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
15069e4fd900SJohn Levon	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
15079e4fd900SJohn Levon	grep "$MAKE:" $SRC/clobber-${MACH}.out |
15089e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
15099e4fd900SJohn Levon		tee $TMPDIR/clobber_errs >> $mail_msg_file
15109e4fd900SJohn Levon
15119e4fd900SJohn Levon	if [[ -s $TMPDIR/clobber_errs ]]; then
15129e4fd900SJohn Levon		build_extras_ok=n
15139e4fd900SJohn Levon	fi
15149e4fd900SJohn Levon
15159e4fd900SJohn Levon	if [[ "$t_FLAG" = "y" ]]; then
15169e4fd900SJohn Levon		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
15179e4fd900SJohn Levon		cd ${TOOLS}
15189e4fd900SJohn Levon		rm -f ${TOOLS}/clobber-${MACH}.out
15199e4fd900SJohn Levon		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
15209e4fd900SJohn Levon			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
15219e4fd900SJohn Levon		echo "\n==== Make tools clobber ERRORS ====\n" \
15229e4fd900SJohn Levon			>> $mail_msg_file
15239e4fd900SJohn Levon		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
15249e4fd900SJohn Levon			>> $mail_msg_file
15259e4fd900SJohn Levon		if (( $? == 0 )); then
15269e4fd900SJohn Levon			build_extras_ok=n
15279e4fd900SJohn Levon		fi
15289e4fd900SJohn Levon		rm -rf ${TOOLS_PROTO}
15299e4fd900SJohn Levon		mkdir -p ${TOOLS_PROTO}
15309e4fd900SJohn Levon	fi
15319e4fd900SJohn Levon
15329e4fd900SJohn Levon	typeset roots=$(allprotos)
15339e4fd900SJohn Levon	echo "\n\nClearing $roots" >> "$LOGFILE"
15349e4fd900SJohn Levon	rm -rf $roots
15359e4fd900SJohn Levon
15369e4fd900SJohn Levon	# Get back to a clean workspace as much as possible to catch
15379e4fd900SJohn Levon	# problems that only occur on fresh workspaces.
15389e4fd900SJohn Levon	# Remove all .make.state* files, libraries, and .o's that may
15399e4fd900SJohn Levon	# have been omitted from clobber.  A couple of libraries are
15409e4fd900SJohn Levon	# under source code control, so leave them alone.
15419e4fd900SJohn Levon	# We should probably blow away temporary directories too.
15429e4fd900SJohn Levon	cd $SRC
15439e4fd900SJohn Levon	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
15449e4fd900SJohn Levon	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
15459e4fd900SJohn Levon	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
15469e4fd900SJohn Levon	       -name '*.o' \) -print | \
15479e4fd900SJohn Levon	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
15489e4fd900SJohn Levonelse
15499e4fd900SJohn Levon	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
15509e4fd900SJohn Levonfi
15519e4fd900SJohn Levon
15529e4fd900SJohn Levontype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
15539e4fd900SJohn Levon	typeset -x PATH=$PATH
15549e4fd900SJohn Levon
15559e4fd900SJohn Levon	# If the repository doesn't exist yet, then we want to populate it.
15569e4fd900SJohn Levon	if [[ ! -d $CODEMGR_WS/.hg ]]; then
15579e4fd900SJohn Levon		staffer hg init $CODEMGR_WS
15589e4fd900SJohn Levon		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
15599e4fd900SJohn Levon		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
15609e4fd900SJohn Levon		touch $TMPDIR/new_repository
15619e4fd900SJohn Levon	fi
15629e4fd900SJohn Levon
15639e4fd900SJohn Levon	typeset -x HGMERGE="/bin/false"
15649e4fd900SJohn Levon
15659e4fd900SJohn Levon	#
15669e4fd900SJohn Levon	# If the user has changes, regardless of whether those changes are
15679e4fd900SJohn Levon	# committed, and regardless of whether those changes conflict, then
15689e4fd900SJohn Levon	# we'll attempt to merge them either implicitly (uncommitted) or
15699e4fd900SJohn Levon	# explicitly (committed).
15709e4fd900SJohn Levon	#
15719e4fd900SJohn Levon	# These are the messages we'll use to help clarify mercurial output
15729e4fd900SJohn Levon	# in those cases.
15739e4fd900SJohn Levon	#
15749e4fd900SJohn Levon	typeset mergefailmsg="\
15759e4fd900SJohn Levon***\n\
15769e4fd900SJohn Levon*** nightly was unable to automatically merge your changes.  You should\n\
15779e4fd900SJohn Levon*** redo the full merge manually, following the steps outlined by mercurial\n\
15789e4fd900SJohn Levon*** above, then restart nightly.\n\
15799e4fd900SJohn Levon***\n"
15809e4fd900SJohn Levon	typeset mergepassmsg="\
15819e4fd900SJohn Levon***\n\
15829e4fd900SJohn Levon*** nightly successfully merged your changes.  This means that your working\n\
15839e4fd900SJohn Levon*** directory has been updated, but those changes are not yet committed.\n\
15849e4fd900SJohn Levon*** After nightly completes, you should validate the results of the merge,\n\
15859e4fd900SJohn Levon*** then use hg commit manually.\n\
15869e4fd900SJohn Levon***\n"
15879e4fd900SJohn Levon
15889e4fd900SJohn Levon	#
15899e4fd900SJohn Levon	# For each repository in turn:
15909e4fd900SJohn Levon	#
15919e4fd900SJohn Levon	# 1. Do the pull.  If this fails, dump the output and bail out.
15929e4fd900SJohn Levon	#
15939e4fd900SJohn Levon	# 2. If the pull resulted in an extra head, do an explicit merge.
15949e4fd900SJohn Levon	#    If this fails, dump the output and bail out.
15959e4fd900SJohn Levon	#
15969e4fd900SJohn Levon	# Because we can't rely on Mercurial to exit with a failure code
15979e4fd900SJohn Levon	# when a merge fails (Mercurial issue #186), we must grep the
15989e4fd900SJohn Levon	# output of pull/merge to check for attempted and/or failed merges.
15999e4fd900SJohn Levon	#
16009e4fd900SJohn Levon	# 3. If a merge failed, set the message and fail the bringover.
16019e4fd900SJohn Levon	#
16029e4fd900SJohn Levon	# 4. Otherwise, if a merge succeeded, set the message
16039e4fd900SJohn Levon	#
16049e4fd900SJohn Levon	# 5. Dump the output, and any message from step 3 or 4.
16059e4fd900SJohn Levon	#
16069e4fd900SJohn Levon
16079e4fd900SJohn Levon	typeset HG_SOURCE=$BRINGOVER_WS
16089e4fd900SJohn Levon	if [ ! -f $TMPDIR/new_repository ]; then
16099e4fd900SJohn Levon		HG_SOURCE=$TMPDIR/open_bundle.hg
16109e4fd900SJohn Levon		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
16119e4fd900SJohn Levon		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
16129e4fd900SJohn Levon
16139e4fd900SJohn Levon		#
16149e4fd900SJohn Levon		# If there are no incoming changesets, then incoming will
16159e4fd900SJohn Levon		# fail, and there will be no bundle file.  Reset the source,
16169e4fd900SJohn Levon		# to allow the remaining logic to complete with no false
16179e4fd900SJohn Levon		# negatives.  (Unlike incoming, pull will return success
16189e4fd900SJohn Levon		# for the no-change case.)
16199e4fd900SJohn Levon		#
16209e4fd900SJohn Levon		if (( $? != 0 )); then
16219e4fd900SJohn Levon			HG_SOURCE=$BRINGOVER_WS
16229e4fd900SJohn Levon		fi
16239e4fd900SJohn Levon	fi
16249e4fd900SJohn Levon
16259e4fd900SJohn Levon	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
16269e4fd900SJohn Levon	    > $TMPDIR/pull_open.out 2>&1
16279e4fd900SJohn Levon	if (( $? != 0 )); then
16289e4fd900SJohn Levon		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
16299e4fd900SJohn Levon		cat $TMPDIR/pull_open.out
16309e4fd900SJohn Levon		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
16319e4fd900SJohn Levon			printf "$mergefailmsg"
16329e4fd900SJohn Levon		fi
16339e4fd900SJohn Levon		touch $TMPDIR/bringover_failed
16349e4fd900SJohn Levon		return
16359e4fd900SJohn Levon	fi
16369e4fd900SJohn Levon
16379e4fd900SJohn Levon	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
16389e4fd900SJohn Levon		staffer hg --cwd $CODEMGR_WS merge \
16399e4fd900SJohn Levon		    >> $TMPDIR/pull_open.out 2>&1
16409e4fd900SJohn Levon		if (( $? != 0 )); then
16419e4fd900SJohn Levon			printf "%s: merge failed as follows:\n\n" \
16429e4fd900SJohn Levon			    "$CODEMGR_WS"
16439e4fd900SJohn Levon			cat $TMPDIR/pull_open.out
16449e4fd900SJohn Levon			if grep "^merging.*failed" $TMPDIR/pull_open.out \
16459e4fd900SJohn Levon			    > /dev/null 2>&1; then
16469e4fd900SJohn Levon				printf "$mergefailmsg"
16479e4fd900SJohn Levon			fi
16489e4fd900SJohn Levon			touch $TMPDIR/bringover_failed
16499e4fd900SJohn Levon			return
16509e4fd900SJohn Levon		fi
16519e4fd900SJohn Levon	fi
16529e4fd900SJohn Levon
16539e4fd900SJohn Levon	printf "updated %s with the following results:\n" "$CODEMGR_WS"
16549e4fd900SJohn Levon	cat $TMPDIR/pull_open.out
16559e4fd900SJohn Levon	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
16569e4fd900SJohn Levon		printf "$mergepassmsg"
16579e4fd900SJohn Levon	fi
16589e4fd900SJohn Levon	printf "\n"
16599e4fd900SJohn Levon
16609e4fd900SJohn Levon	#
16619e4fd900SJohn Levon	# Per-changeset output is neither useful nor manageable for a
16629e4fd900SJohn Levon	# newly-created repository.
16639e4fd900SJohn Levon	#
16649e4fd900SJohn Levon	if [ -f $TMPDIR/new_repository ]; then
16659e4fd900SJohn Levon		return
16669e4fd900SJohn Levon	fi
16679e4fd900SJohn Levon
16689e4fd900SJohn Levon	printf "\nadded the following changesets to open repository:\n"
16699e4fd900SJohn Levon	cat $TMPDIR/incoming_open.out
16709e4fd900SJohn Levon}
16719e4fd900SJohn Levon
16729e4fd900SJohn Levontype bringover_none > /dev/null 2>&1 || function bringover_none {
16739e4fd900SJohn Levon	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
16749e4fd900SJohn Levon	touch $TMPDIR/bringover_failed
16759e4fd900SJohn Levon}
16769e4fd900SJohn Levon
16779e4fd900SJohn Levon#
16789e4fd900SJohn Levon#	Decide whether to bringover to the codemgr workspace
16799e4fd900SJohn Levon#
16809e4fd900SJohn Levonif [ "$n_FLAG" = "n" ]; then
16819e4fd900SJohn Levon	PARENT_SCM_TYPE=$(parent_wstype)
16829e4fd900SJohn Levon
16839e4fd900SJohn Levon	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
16849e4fd900SJohn Levon		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
16859e4fd900SJohn Levon		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
16869e4fd900SJohn Levon		exit 1
16879e4fd900SJohn Levon	fi
16889e4fd900SJohn Levon
16899e4fd900SJohn Levon	run_hook PRE_BRINGOVER
16909e4fd900SJohn Levon
16919e4fd900SJohn Levon	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
16929e4fd900SJohn Levon	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
16939e4fd900SJohn Levon
16949e4fd900SJohn Levon	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
16959e4fd900SJohn Levon		tee -a $mail_msg_file >> $LOGFILE
16969e4fd900SJohn Levon
16979e4fd900SJohn Levon	if [ -f $TMPDIR/bringover_failed ]; then
16989e4fd900SJohn Levon		rm -f $TMPDIR/bringover_failed
16999e4fd900SJohn Levon		build_ok=n
17009e4fd900SJohn Levon		echo "trouble with bringover, quitting at `date`." |
17019e4fd900SJohn Levon			tee -a $mail_msg_file >> $LOGFILE
17029e4fd900SJohn Levon		exit 1
17039e4fd900SJohn Levon	fi
17049e4fd900SJohn Levon
17059e4fd900SJohn Levon	#
17069e4fd900SJohn Levon	# It's possible that we used the bringover above to create
17079e4fd900SJohn Levon	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
17089e4fd900SJohn Levon	# but should now be the same as $BRINGOVER_WS.
17099e4fd900SJohn Levon	#
17109e4fd900SJohn Levon	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
17119e4fd900SJohn Levon
17129e4fd900SJohn Levon	run_hook POST_BRINGOVER
17139e4fd900SJohn Levon
17149e4fd900SJohn Levon	check_closed_bins
17159e4fd900SJohn Levon
17169e4fd900SJohn Levonelse
17179e4fd900SJohn Levon	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
17189e4fd900SJohn Levonfi
17199e4fd900SJohn Levon
17209e4fd900SJohn Levon# Safeguards
17219e4fd900SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
17229e4fd900SJohn Levon[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
17239e4fd900SJohn Levon[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
17249e4fd900SJohn Levon
17259e4fd900SJohn Levonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
17269e4fd900SJohn Levon
17279e4fd900SJohn Levon# System
17289e4fd900SJohn Levonwhence uname | tee -a $build_environ_file >> $LOGFILE
17299e4fd900SJohn Levonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
17309e4fd900SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
17319e4fd900SJohn Levon
17329e4fd900SJohn Levon# make
17339e4fd900SJohn Levonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
17349e4fd900SJohn Levon$MAKE -v | tee -a $build_environ_file >> $LOGFILE
17359e4fd900SJohn Levonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
17369e4fd900SJohn Levon    tee -a $build_environ_file >> $LOGFILE
17379e4fd900SJohn Levon
17389e4fd900SJohn Levon#
17399e4fd900SJohn Levon# Report the compiler versions.
17409e4fd900SJohn Levon#
17419e4fd900SJohn Levon
17429e4fd900SJohn Levonif [[ ! -f $SRC/Makefile ]]; then
17439e4fd900SJohn Levon	build_ok=n
17449e4fd900SJohn Levon	echo "\nUnable to find \"Makefile\" in $SRC." | \
17459e4fd900SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17469e4fd900SJohn Levon	exit 1
17479e4fd900SJohn Levonfi
17489e4fd900SJohn Levon
17499e4fd900SJohn Levon( cd $SRC
17509e4fd900SJohn Levon  for target in cc-version cc64-version java-version; do
17519e4fd900SJohn Levon	echo
17529e4fd900SJohn Levon	#
17539e4fd900SJohn Levon	# Put statefile somewhere we know we can write to rather than trip
17549e4fd900SJohn Levon	# over a read-only $srcroot.
17559e4fd900SJohn Levon	#
17569e4fd900SJohn Levon	rm -f $TMPDIR/make-state
17579e4fd900SJohn Levon	export SRC
17589e4fd900SJohn Levon	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
17599e4fd900SJohn Levon		continue
17609e4fd900SJohn Levon	fi
17619e4fd900SJohn Levon	touch $TMPDIR/nocompiler
17629e4fd900SJohn Levon  done
17639e4fd900SJohn Levon  echo
17649e4fd900SJohn Levon) | tee -a $build_environ_file >> $LOGFILE
17659e4fd900SJohn Levon
17669e4fd900SJohn Levonif [ -f $TMPDIR/nocompiler ]; then
17679e4fd900SJohn Levon	rm -f $TMPDIR/nocompiler
17689e4fd900SJohn Levon	build_ok=n
17699e4fd900SJohn Levon	echo "Aborting due to missing compiler." |
17709e4fd900SJohn Levon		tee -a $build_environ_file >> $LOGFILE
17719e4fd900SJohn Levon	exit 1
17729e4fd900SJohn Levonfi
17739e4fd900SJohn Levon
17749e4fd900SJohn Levon# as
17759e4fd900SJohn Levonwhence as | tee -a $build_environ_file >> $LOGFILE
17769e4fd900SJohn Levonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
17779e4fd900SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
17789e4fd900SJohn Levon
17799e4fd900SJohn Levon# Check that we're running a capable link-editor
17809e4fd900SJohn Levonwhence ld | tee -a $build_environ_file >> $LOGFILE
17819e4fd900SJohn LevonLDVER=`ld -V 2>&1`
17829e4fd900SJohn Levonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
17839e4fd900SJohn LevonLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
17849e4fd900SJohn Levonif [ `expr $LDVER \< 422` -eq 1 ]; then
17859e4fd900SJohn Levon	echo "The link-editor needs to be at version 422 or higher to build" | \
17869e4fd900SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17879e4fd900SJohn Levon	echo "the latest stuff.  Hope your build works." | \
17889e4fd900SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17899e4fd900SJohn Levonfi
17909e4fd900SJohn Levon
17919e4fd900SJohn Levon#
17929e4fd900SJohn Levon# Build and use the workspace's tools if requested
17939e4fd900SJohn Levon#
17949e4fd900SJohn Levonif [[ "$t_FLAG" = "y" ]]; then
17959e4fd900SJohn Levon	set_non_debug_build_flags
17969e4fd900SJohn Levon
17979e4fd900SJohn Levon	build_tools ${TOOLS_PROTO}
17989e4fd900SJohn Levon	if (( $? != 0 )); then
17999e4fd900SJohn Levon		build_ok=n
18009e4fd900SJohn Levon	else
18019e4fd900SJohn Levon		use_tools $TOOLS_PROTO
18029e4fd900SJohn Levon	fi
18039e4fd900SJohn Levonfi
18049e4fd900SJohn Levon
18059e4fd900SJohn Levon# timestamp the start of the normal build; the findunref tool uses it.
18069e4fd900SJohn Levontouch $SRC/.build.tstamp
18079e4fd900SJohn Levon
18089e4fd900SJohn Levonnormal_build
18099e4fd900SJohn Levon
18109e4fd900SJohn LevonORIG_SRC=$SRC
18119e4fd900SJohn LevonBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
18129e4fd900SJohn Levon
18139e4fd900SJohn Levon
18149e4fd900SJohn Levon#
18159e4fd900SJohn Levon# There are several checks that need to look at the proto area, but
18169e4fd900SJohn Levon# they only need to look at one, and they don't care whether it's
18179e4fd900SJohn Levon# DEBUG or non-DEBUG.
18189e4fd900SJohn Levon#
18199e4fd900SJohn Levonif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
18209e4fd900SJohn Levon	checkroot=$ROOT-nd
18219e4fd900SJohn Levonelse
18229e4fd900SJohn Levon	checkroot=$ROOT
18239e4fd900SJohn Levonfi
18249e4fd900SJohn Levon
18259e4fd900SJohn Levonif [ "$build_ok" = "y" ]; then
18269e4fd900SJohn Levon	echo "\n==== Creating protolist system file at `date` ====" \
18279e4fd900SJohn Levon		>> $LOGFILE
18289e4fd900SJohn Levon	protolist $checkroot > $ATLOG/proto_list_${MACH}
18299e4fd900SJohn Levon	echo "==== protolist system file created at `date` ====\n" \
18309e4fd900SJohn Levon		>> $LOGFILE
18319e4fd900SJohn Levon
18329e4fd900SJohn Levon	if [ "$N_FLAG" != "y" ]; then
18339e4fd900SJohn Levon
18349e4fd900SJohn Levon		E1=
18359e4fd900SJohn Levon		f1=
18369e4fd900SJohn Levon		for f in $f1; do
18379e4fd900SJohn Levon			if [ -f "$f" ]; then
18389e4fd900SJohn Levon				E1="$E1 -e $f"
18399e4fd900SJohn Levon			fi
18409e4fd900SJohn Levon		done
18419e4fd900SJohn Levon
18429e4fd900SJohn Levon		E2=
18439e4fd900SJohn Levon		f2=
18449e4fd900SJohn Levon		if [ -d "$SRC/pkg" ]; then
18459e4fd900SJohn Levon			f2="$f2 exceptions/packaging"
18469e4fd900SJohn Levon		fi
18479e4fd900SJohn Levon
18489e4fd900SJohn Levon		for f in $f2; do
18499e4fd900SJohn Levon			if [ -f "$f" ]; then
18509e4fd900SJohn Levon				E2="$E2 -e $f"
18519e4fd900SJohn Levon			fi
18529e4fd900SJohn Levon		done
18539e4fd900SJohn Levon	fi
18549e4fd900SJohn Levon
18559e4fd900SJohn Levon	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
18569e4fd900SJohn Levon		echo "\n==== Validating manifests against proto area ====\n" \
18579e4fd900SJohn Levon		    >> $mail_msg_file
18589e4fd900SJohn Levon		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
18599e4fd900SJohn Levon		    tee $TMPDIR/protocmp_noise >> $mail_msg_file
18609e4fd900SJohn Levon		if [[ -s $TMPDIR/protocmp_noise ]]; then
18619e4fd900SJohn Levon			build_extras_ok=n
18629e4fd900SJohn Levon		fi
18639e4fd900SJohn Levon	fi
18649e4fd900SJohn Levon
18659e4fd900SJohn Levon	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
18669e4fd900SJohn Levon		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
18679e4fd900SJohn Levon		if [ -n "$E2" ]; then
18689e4fd900SJohn Levon			ELIST=$E2
18699e4fd900SJohn Levon		else
18709e4fd900SJohn Levon			ELIST=$E1
18719e4fd900SJohn Levon		fi
18729e4fd900SJohn Levon		$PROTOCMPTERSE \
18739e4fd900SJohn Levon			"Files in yesterday's proto area, but not today's:" \
18749e4fd900SJohn Levon			"Files in today's proto area, but not yesterday's:" \
18759e4fd900SJohn Levon			"Files that changed between yesterday and today:" \
18769e4fd900SJohn Levon			${ELIST} \
18779e4fd900SJohn Levon			-d $REF_PROTO_LIST \
18789e4fd900SJohn Levon			$ATLOG/proto_list_${MACH} \
18799e4fd900SJohn Levon			>> $mail_msg_file
18809e4fd900SJohn Levon	fi
18819e4fd900SJohn Levonfi
18829e4fd900SJohn Levon
18839e4fd900SJohn Levonif [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
18849e4fd900SJohn Levon    "$build_extras_ok" == "y" ]]; then
18859e4fd900SJohn Levon	staffer cp $ATLOG/proto_list_${MACH} \
18869e4fd900SJohn Levon		$PARENT_WS/usr/src/proto_list_${MACH}
18879e4fd900SJohn Levonfi
18889e4fd900SJohn Levon
18899e4fd900SJohn Levon# Update parent proto area if necessary. This is done now
18909e4fd900SJohn Levon# so that the proto area has either DEBUG or non-DEBUG kernels.
18919e4fd900SJohn Levon# Note that this clears out the lock file, so we can dispense with
18929e4fd900SJohn Levon# the variable now.
18939e4fd900SJohn Levonif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
18949e4fd900SJohn Levon	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
18959e4fd900SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
18969e4fd900SJohn Levon	rm -rf $NIGHTLY_PARENT_ROOT/*
18979e4fd900SJohn Levon	unset Ulockfile
18989e4fd900SJohn Levon	mkdir -p $NIGHTLY_PARENT_ROOT
18999e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
19009e4fd900SJohn Levon		( cd $ROOT; tar cf - . |
19019e4fd900SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
19029e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
19039e4fd900SJohn Levon	fi
19049e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
19059e4fd900SJohn Levon		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
19069e4fd900SJohn Levon		mkdir -p $NIGHTLY_PARENT_ROOT-nd
19079e4fd900SJohn Levon		cd $ROOT-nd
19089e4fd900SJohn Levon		( tar cf - . |
19099e4fd900SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
19109e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
19119e4fd900SJohn Levon	fi
19129e4fd900SJohn Levon	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
19139e4fd900SJohn Levon		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
19149e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19159e4fd900SJohn Levon		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
19169e4fd900SJohn Levon		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
19179e4fd900SJohn Levon		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
19189e4fd900SJohn Levon			( cd $TOOLS_PROTO; tar cf - . |
19199e4fd900SJohn Levon			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
19209e4fd900SJohn Levon			    umask 0; tar xpf - ) ) 2>&1 |
19219e4fd900SJohn Levon			    tee -a $mail_msg_file >> $LOGFILE
19229e4fd900SJohn Levon		fi
19239e4fd900SJohn Levon	fi
19249e4fd900SJohn Levonfi
19259e4fd900SJohn Levon
19269e4fd900SJohn Levon#
19279e4fd900SJohn Levon# ELF verification: ABI (-A) and runtime (-r) checks
19289e4fd900SJohn Levon#
19299e4fd900SJohn Levonif [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
19309e4fd900SJohn Levon	# Directory ELF-data.$MACH holds the files produced by these tests.
19319e4fd900SJohn Levon	elf_ddir=$SRC/ELF-data.$MACH
19329e4fd900SJohn Levon
19339e4fd900SJohn Levon	# If there is a previous ELF-data backup directory, remove it. Then,
19349e4fd900SJohn Levon	# rotate current ELF-data directory into its place and create a new
19359e4fd900SJohn Levon	# empty directory
19369e4fd900SJohn Levon	rm -rf $elf_ddir.ref
19379e4fd900SJohn Levon	if [[ -d $elf_ddir ]]; then
19389e4fd900SJohn Levon		mv $elf_ddir $elf_ddir.ref
19399e4fd900SJohn Levon	fi
19409e4fd900SJohn Levon	mkdir -p $elf_ddir
19419e4fd900SJohn Levon
19429e4fd900SJohn Levon	# Call find_elf to produce a list of the ELF objects in the proto area.
19439e4fd900SJohn Levon	# This list is passed to check_rtime and interface_check, preventing
19449e4fd900SJohn Levon	# them from separately calling find_elf to do the same work twice.
19459e4fd900SJohn Levon	find_elf -fr $checkroot > $elf_ddir/object_list
19469e4fd900SJohn Levon
19479e4fd900SJohn Levon	if [[ $A_FLAG = y ]]; then
19489e4fd900SJohn Levon	       	echo "\n==== Check versioning and ABI information ====\n"  | \
19499e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19509e4fd900SJohn Levon
19519e4fd900SJohn Levon		# Produce interface description for the proto. Report errors.
19529e4fd900SJohn Levon		interface_check -o -w $elf_ddir -f object_list \
19539e4fd900SJohn Levon			-i interface -E interface.err
19549e4fd900SJohn Levon		if [[ -s $elf_ddir/interface.err ]]; then
19559e4fd900SJohn Levon			tee -a $LOGFILE < $elf_ddir/interface.err \
19569e4fd900SJohn Levon			    >> $mail_msg_file
19579e4fd900SJohn Levon			build_extras_ok=n
19589e4fd900SJohn Levon		fi
19599e4fd900SJohn Levon
19609e4fd900SJohn Levon		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
19619e4fd900SJohn Levon		# description file to that from the baseline gate. Issue a
19629e4fd900SJohn Levon		# warning if the baseline is not present, and keep going.
19639e4fd900SJohn Levon		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
19649e4fd900SJohn Levon			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
19659e4fd900SJohn Levon
19669e4fd900SJohn Levon		       	echo "\n==== Compare versioning and ABI information" \
19679e4fd900SJohn Levon			    "to baseline ====\n"  | \
19689e4fd900SJohn Levon			    tee -a $LOGFILE >> $mail_msg_file
19699e4fd900SJohn Levon		       	echo "Baseline:  $base_ifile\n" >> $LOGFILE
19709e4fd900SJohn Levon
19719e4fd900SJohn Levon			if [[ -f $base_ifile ]]; then
19729e4fd900SJohn Levon				interface_cmp -d -o $base_ifile \
19739e4fd900SJohn Levon				    $elf_ddir/interface > $elf_ddir/interface.cmp
19749e4fd900SJohn Levon				if [[ -s $elf_ddir/interface.cmp ]]; then
19759e4fd900SJohn Levon					echo | tee -a $LOGFILE >> $mail_msg_file
19769e4fd900SJohn Levon					tee -a $LOGFILE < \
19779e4fd900SJohn Levon					    $elf_ddir/interface.cmp \
19789e4fd900SJohn Levon					    >> $mail_msg_file
19799e4fd900SJohn Levon					build_extras_ok=n
19809e4fd900SJohn Levon				fi
19819e4fd900SJohn Levon			else
19829e4fd900SJohn Levon			       	echo "baseline not available. comparison" \
19839e4fd900SJohn Levon                                    "skipped" | \
19849e4fd900SJohn Levon				    tee -a $LOGFILE >> $mail_msg_file
19859e4fd900SJohn Levon			fi
19869e4fd900SJohn Levon
19879e4fd900SJohn Levon		fi
19889e4fd900SJohn Levon	fi
19899e4fd900SJohn Levon
19909e4fd900SJohn Levon	if [[ $r_FLAG = y ]]; then
19919e4fd900SJohn Levon		echo "\n==== Check ELF runtime attributes ====\n" | \
19929e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19939e4fd900SJohn Levon
19949e4fd900SJohn Levon		# If we're doing a DEBUG build the proto area will be left
19959e4fd900SJohn Levon		# with debuggable objects, thus don't assert -s.
19969e4fd900SJohn Levon		if [[ $D_FLAG = y ]]; then
19979e4fd900SJohn Levon			rtime_sflag=""
19989e4fd900SJohn Levon		else
19999e4fd900SJohn Levon			rtime_sflag="-s"
20009e4fd900SJohn Levon		fi
20019e4fd900SJohn Levon		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
20029e4fd900SJohn Levon			-D object_list  -f object_list -E runtime.err \
20039e4fd900SJohn Levon			-I runtime.attr.raw
20049e4fd900SJohn Levon		if (( $? != 0 )); then
20059e4fd900SJohn Levon			build_extras_ok=n
20069e4fd900SJohn Levon		fi
20079e4fd900SJohn Levon
20089e4fd900SJohn Levon		# check_rtime -I output needs to be sorted in order to
20099e4fd900SJohn Levon		# compare it to that from previous builds.
20109e4fd900SJohn Levon		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
20119e4fd900SJohn Levon		rm $elf_ddir/runtime.attr.raw
20129e4fd900SJohn Levon
20139e4fd900SJohn Levon		# Report errors
20149e4fd900SJohn Levon		if [[ -s $elf_ddir/runtime.err ]]; then
20159e4fd900SJohn Levon			tee -a $LOGFILE < $elf_ddir/runtime.err \
20169e4fd900SJohn Levon				>> $mail_msg_file
20179e4fd900SJohn Levon			build_extras_ok=n
20189e4fd900SJohn Levon		fi
20199e4fd900SJohn Levon
20209e4fd900SJohn Levon		# If there is an ELF-data directory from a previous build,
20219e4fd900SJohn Levon		# then diff the attr files. These files contain information
20229e4fd900SJohn Levon		# about dependencies, versioning, and runpaths. There is some
20239e4fd900SJohn Levon		# overlap with the ABI checking done above, but this also
20249e4fd900SJohn Levon		# flushes out non-ABI interface differences along with the
20259e4fd900SJohn Levon		# other information.
20269e4fd900SJohn Levon		echo "\n==== Diff ELF runtime attributes" \
20279e4fd900SJohn Levon		    "(since last build) ====\n" | \
20289e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
20299e4fd900SJohn Levon
20309e4fd900SJohn Levon		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
20319e4fd900SJohn Levon			diff $elf_ddir.ref/runtime.attr \
20329e4fd900SJohn Levon				$elf_ddir/runtime.attr \
20339e4fd900SJohn Levon				>> $mail_msg_file
20349e4fd900SJohn Levon		fi
20359e4fd900SJohn Levon	fi
20369e4fd900SJohn Levon
20379e4fd900SJohn Levon	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
20389e4fd900SJohn Levon	if [[ "$u_FLAG" = "y" ]]; then
20399e4fd900SJohn Levon		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
20409e4fd900SJohn Levon
20419e4fd900SJohn Levon		# If parent lacks the ELF-data.$MACH directory, create it
20429e4fd900SJohn Levon		if [[ ! -d $p_elf_ddir ]]; then
20439e4fd900SJohn Levon			staffer mkdir -p $p_elf_ddir
20449e4fd900SJohn Levon		fi
20459e4fd900SJohn Levon
20469e4fd900SJohn Levon		# These files are used asynchronously by other builds for ABI
20479e4fd900SJohn Levon		# verification, as above for the -A option. As such, we require
20489e4fd900SJohn Levon		# the file replacement to be atomic. Copy the data to a temp
20499e4fd900SJohn Levon		# file in the same filesystem and then rename into place.
20509e4fd900SJohn Levon		(
20519e4fd900SJohn Levon			cd $elf_ddir
20529e4fd900SJohn Levon			for elf_dfile in *; do
20539e4fd900SJohn Levon				staffer cp $elf_dfile \
20549e4fd900SJohn Levon				    ${p_elf_ddir}/${elf_dfile}.new
20559e4fd900SJohn Levon				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
20569e4fd900SJohn Levon				    ${p_elf_ddir}/${elf_dfile}
20579e4fd900SJohn Levon			done
20589e4fd900SJohn Levon		)
20599e4fd900SJohn Levon	fi
20609e4fd900SJohn Levonfi
20619e4fd900SJohn Levon
20629e4fd900SJohn Levon# DEBUG lint of kernel begins
20639e4fd900SJohn Levon
20649e4fd900SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
20659e4fd900SJohn Levon	if [ "$LINTDIRS" = "" ]; then
20669e4fd900SJohn Levon		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
20679e4fd900SJohn Levon		LINTDIRS="$SRC y"
20689e4fd900SJohn Levon	fi
20699e4fd900SJohn Levon	set $LINTDIRS
20709e4fd900SJohn Levon	while [ $# -gt 0 ]; do
20719e4fd900SJohn Levon		dolint $1 $2; shift; shift
20729e4fd900SJohn Levon	done
20739e4fd900SJohn Levonelse
20749e4fd900SJohn Levon	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
20759e4fd900SJohn Levonfi
20769e4fd900SJohn Levon
20779e4fd900SJohn Levon# "make check" begins
20789e4fd900SJohn Levon
20799e4fd900SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
20809e4fd900SJohn Levon	# remove old check.out
20819e4fd900SJohn Levon	rm -f $SRC/check.out
20829e4fd900SJohn Levon
20839e4fd900SJohn Levon	rm -f $SRC/check-${MACH}.out
20849e4fd900SJohn Levon	cd $SRC
20859e4fd900SJohn Levon	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
20869e4fd900SJohn Levon	    >> $LOGFILE
20879e4fd900SJohn Levon	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
20889e4fd900SJohn Levon
20899e4fd900SJohn Levon	grep ":" $SRC/check-${MACH}.out |
20909e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
20919e4fd900SJohn Levon		sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
20929e4fd900SJohn Levon
20939e4fd900SJohn Levon	if [[ -s $TMPDIR/check_errors ]]; then
20949e4fd900SJohn Levon		build_extras_ok=n
20959e4fd900SJohn Levon	fi
20969e4fd900SJohn Levonelse
20979e4fd900SJohn Levon	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
20989e4fd900SJohn Levonfi
20999e4fd900SJohn Levon
21009e4fd900SJohn Levonecho "\n==== Find core files ====\n" | \
21019e4fd900SJohn Levon    tee -a $LOGFILE >> $mail_msg_file
21029e4fd900SJohn Levon
21039e4fd900SJohn Levonfind $abssrcdirs -name core -a -type f -exec file {} \; | \
21049e4fd900SJohn Levon	tee -a $LOGFILE >> $mail_msg_file
21059e4fd900SJohn Levon
21069e4fd900SJohn Levonif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
21079e4fd900SJohn Levon	echo "\n==== Diff unreferenced files (since last build) ====\n" \
21089e4fd900SJohn Levon	    | tee -a $LOGFILE >>$mail_msg_file
21099e4fd900SJohn Levon	rm -f $SRC/unref-${MACH}.ref
21109e4fd900SJohn Levon	if [ -f $SRC/unref-${MACH}.out ]; then
21119e4fd900SJohn Levon		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21129e4fd900SJohn Levon	fi
21139e4fd900SJohn Levon
21149e4fd900SJohn Levon	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
21159e4fd900SJohn Levon	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
21169e4fd900SJohn Levon	    sort > $SRC/unref-${MACH}.out
21179e4fd900SJohn Levon
21189e4fd900SJohn Levon	if [ ! -f $SRC/unref-${MACH}.ref ]; then
21199e4fd900SJohn Levon		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21209e4fd900SJohn Levon	fi
21219e4fd900SJohn Levon
21229e4fd900SJohn Levon	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
21239e4fd900SJohn Levonfi
21249e4fd900SJohn Levon
21259e4fd900SJohn Levon# Verify that the usual lists of files, such as exception lists,
21269e4fd900SJohn Levon# contain only valid references to files.  If the build has failed,
21279e4fd900SJohn Levon# then don't check the proto area.
21289e4fd900SJohn LevonCHECK_PATHS=${CHECK_PATHS:-y}
21299e4fd900SJohn Levonif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
21309e4fd900SJohn Levon	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
21319e4fd900SJohn Levon		>>$mail_msg_file
21329e4fd900SJohn Levon	arg=-b
21339e4fd900SJohn Levon	[ "$build_ok" = y ] && arg=
21349e4fd900SJohn Levon	checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1
21359e4fd900SJohn Levon	if [[ -s $SRC/check-paths.out ]]; then
21369e4fd900SJohn Levon		tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file
21379e4fd900SJohn Levon		build_extras_ok=n
21389e4fd900SJohn Levon	fi
21399e4fd900SJohn Levonfi
21409e4fd900SJohn Levon
21419e4fd900SJohn Levonabspkg=
21429e4fd900SJohn Levonfor d in $abssrcdirs; do
21439e4fd900SJohn Levon	if [ -d "$d/pkg" ]; then
21449e4fd900SJohn Levon		abspkg="$abspkg $d"
21459e4fd900SJohn Levon	fi
21469e4fd900SJohn Levondone
21479e4fd900SJohn Levon
2148*b85ab92fSAndy Fiddamanif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2149*b85ab92fSAndy Fiddaman	echo "\n==== Impact on file permissions ====\n" \
2150*b85ab92fSAndy Fiddaman		>> $mail_msg_file
2151*b85ab92fSAndy Fiddaman
21529e4fd900SJohn Levon	if [ -n "$abspkg" ]; then
21539e4fd900SJohn Levon		for d in "$abspkg"; do
21549e4fd900SJohn Levon			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
21559e4fd900SJohn Levon		done
21569e4fd900SJohn Levon	fi
21579e4fd900SJohn Levonfi
21589e4fd900SJohn Levon
2159*b85ab92fSAndy Fiddamanif [ "$L_FLAG" != "y" -a "$build_ok" = y ]; then
2160*b85ab92fSAndy Fiddaman	echo "\n==== Linting packages ====\n" | \
2161*b85ab92fSAndy Fiddaman	    tee -a $LOGFILE >> $mail_msg_file
2162*b85ab92fSAndy Fiddaman
2163*b85ab92fSAndy Fiddaman	if [ -n "$abspkg" ]; then
2164*b85ab92fSAndy Fiddaman		for d in "$abspkg"; do
2165*b85ab92fSAndy Fiddaman			( cd $d/pkg ; $MAKE -e pkglint ) | \
2166*b85ab92fSAndy Fiddaman			    tee -a $LOGFILE | \
2167*b85ab92fSAndy Fiddaman			    egrep -v 'Lint engine setup|Starting lint run'
2168*b85ab92fSAndy Fiddaman		done 2>&1 | tee $TMPDIR/pkglint_noise >> $mail_msg_file
2169*b85ab92fSAndy Fiddaman		if [[ -s $TMPDIR/pkglint_noise ]]; then
2170*b85ab92fSAndy Fiddaman			build_extras_ok=n
2171*b85ab92fSAndy Fiddaman		fi
2172*b85ab92fSAndy Fiddaman	fi
2173*b85ab92fSAndy Fiddamanfi
2174*b85ab92fSAndy Fiddaman
21759e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
21769e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2177bf16a978SMarcel Telka		do_wsdiff DEBUG $ROOT.prev $ROOT wsdiff.results
21789e4fd900SJohn Levon	fi
21799e4fd900SJohn Levon
21809e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2181bf16a978SMarcel Telka		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd wsdiff-nd.results
2182bf16a978SMarcel Telka	fi
2183bf16a978SMarcel Telka
2184bf16a978SMarcel Telka	if [[ "$t_FLAG" == "y" ]]; then
2185bf16a978SMarcel Telka		do_wsdiff tools $TOOLS_PROTO.prev $TOOLS_PROTO wsdiff-tools.results
21869e4fd900SJohn Levon	fi
21879e4fd900SJohn Levonfi
21889e4fd900SJohn Levon
21899e4fd900SJohn LevonEND_DATE=`date`
21909e4fd900SJohn Levonecho "==== Nightly $maketype build completed: $END_DATE ====" | \
21919e4fd900SJohn Levon    tee -a $LOGFILE >> $build_time_file
21929e4fd900SJohn Levon
21939e4fd900SJohn Levontypeset -i10 hours
21949e4fd900SJohn Levontypeset -Z2 minutes
21959e4fd900SJohn Levontypeset -Z2 seconds
21969e4fd900SJohn Levon
21979e4fd900SJohn Levonelapsed_time=$SECONDS
21989e4fd900SJohn Levon((hours = elapsed_time / 3600 ))
21999e4fd900SJohn Levon((minutes = elapsed_time / 60  % 60))
22009e4fd900SJohn Levon((seconds = elapsed_time % 60))
22019e4fd900SJohn Levon
22029e4fd900SJohn Levonecho "\n==== Total build time ====" | \
22039e4fd900SJohn Levon    tee -a $LOGFILE >> $build_time_file
22049e4fd900SJohn Levonecho "\nreal    ${hours}:${minutes}:${seconds}" | \
22059e4fd900SJohn Levon    tee -a $LOGFILE >> $build_time_file
22069e4fd900SJohn Levon
22079e4fd900SJohn Levonif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
22089e4fd900SJohn Levon	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
22099e4fd900SJohn Levon
22109e4fd900SJohn Levon	#
22119e4fd900SJohn Levon	# Produce a master list of unreferenced files -- ideally, we'd
22129e4fd900SJohn Levon	# generate the master just once after all of the nightlies
22139e4fd900SJohn Levon	# have finished, but there's no simple way to know when that
22149e4fd900SJohn Levon	# will be.  Instead, we assume that we're the last nightly to
22159e4fd900SJohn Levon	# finish and merge all of the unref-${MACH}.out files in
22169e4fd900SJohn Levon	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
22179e4fd900SJohn Levon	# finish, then this file will be the authoritative master
22189e4fd900SJohn Levon	# list.  Otherwise, another ${MACH}'s nightly will eventually
22199e4fd900SJohn Levon	# overwrite ours with its own master, but in the meantime our
22209e4fd900SJohn Levon	# temporary "master" will be no worse than any older master
22219e4fd900SJohn Levon	# which was already on the parent.
22229e4fd900SJohn Levon	#
22239e4fd900SJohn Levon
22249e4fd900SJohn Levon	set -- $PARENT_WS/usr/src/unref-*.out
22259e4fd900SJohn Levon	cp "$1" ${TMPDIR}/unref.merge
22269e4fd900SJohn Levon	shift
22279e4fd900SJohn Levon
22289e4fd900SJohn Levon	for unreffile; do
22299e4fd900SJohn Levon		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
22309e4fd900SJohn Levon		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
22319e4fd900SJohn Levon	done
22329e4fd900SJohn Levon
22339e4fd900SJohn Levon	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
22349e4fd900SJohn Levonfi
22359e4fd900SJohn Levon
22369e4fd900SJohn Levon#
22379e4fd900SJohn Levon# All done save for the sweeping up.
22389e4fd900SJohn Levon# (whichever exit we hit here will trigger the "cleanup" trap which
22399e4fd900SJohn Levon# optionally sends mail on completion).
22409e4fd900SJohn Levon#
22419e4fd900SJohn Levonif [[ "$build_ok" == "y" ]]; then
22429e4fd900SJohn Levon	if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
22439e4fd900SJohn Levon		exit 0
22449e4fd900SJohn Levon	fi
22459e4fd900SJohn Levonfi
22469e4fd900SJohn Levon
22479e4fd900SJohn Levonexit 1
2248