xref: /titanic_52/usr/src/tools/scripts/nightly (revision 8bae33234ba56b4d1ea20393e61e3f2c4949caef)
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.
29b85ab92fSAndy 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)
646b85ab92fSAndy 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
678b85ab92fSAndy 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
859b85ab92fSAndy 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		;;
882b85ab92fSAndy Fiddaman	  L )	L_FLAG=y
883b85ab92fSAndy 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
926*8bae3323SMatt Fiddaman# Skip pkglint if packages aren't being built
927*8bae3323SMatt Fiddaman[ $p_FLAG = n ] && L_FLAG=y
928*8bae3323SMatt Fiddaman
9299e4fd900SJohn Levonif [ $ISUSER -ne 0 ]; then
9309e4fd900SJohn Levon	# Set default value for STAFFER, if needed.
9319e4fd900SJohn Levon	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
9329e4fd900SJohn Levon		STAFFER=`/usr/xpg4/bin/id -un`
9339e4fd900SJohn Levon		export STAFFER
9349e4fd900SJohn Levon	fi
9359e4fd900SJohn Levonfi
9369e4fd900SJohn Levon
9379e4fd900SJohn Levonif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
9389e4fd900SJohn Levon	MAILTO=$STAFFER
9399e4fd900SJohn Levon	export MAILTO
9409e4fd900SJohn Levonfi
9419e4fd900SJohn Levon
9429e4fd900SJohn LevonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
9439e4fd900SJohn LevonPATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
9449e4fd900SJohn LevonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
9459e4fd900SJohn Levonexport PATH
9469e4fd900SJohn Levon
9479e4fd900SJohn Levon# roots of source trees, both relative to $SRC and absolute.
9489e4fd900SJohn Levonrelsrcdirs="."
9499e4fd900SJohn Levonabssrcdirs="$SRC"
9509e4fd900SJohn Levon
9519e4fd900SJohn LevonPROTOCMPTERSE="protocmp.terse -gu"
9529e4fd900SJohn LevonPOUND_SIGN="#"
9539e4fd900SJohn Levon# have we set RELEASE_DATE in our env file?
9549e4fd900SJohn Levonif [ -z "$RELEASE_DATE" ]; then
9559e4fd900SJohn Levon	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
9569e4fd900SJohn Levonfi
9579e4fd900SJohn LevonBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
9589e4fd900SJohn LevonBASEWSDIR=$(basename $CODEMGR_WS)
9599e4fd900SJohn LevonDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
9609e4fd900SJohn Levon
9619e4fd900SJohn Levon# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
9629e4fd900SJohn Levon# by avoiding repeated shell invocations to evaluate Makefile.master
9639e4fd900SJohn Levon# definitions.
9649e4fd900SJohn Levonexport POUND_SIGN RELEASE_DATE DEV_CM
9659e4fd900SJohn Levon
9669e4fd900SJohn Levonmaketype="distributed"
9679e4fd900SJohn Levonif [[ -z "$MAKE" ]]; then
9689e4fd900SJohn Levon	MAKE=dmake
9699e4fd900SJohn Levonelif [[ ! -x "$MAKE" ]]; then
9709e4fd900SJohn Levon	echo "\$MAKE is set to garbage in the environment"
9719e4fd900SJohn Levon	exit 1
9729e4fd900SJohn Levonfi
9739e4fd900SJohn Levonexport PATH
9749e4fd900SJohn Levonexport MAKE
9759e4fd900SJohn Levon
9769e4fd900SJohn Levonif [ "${SUNWSPRO}" != "" ]; then
9779e4fd900SJohn Levon	PATH="${SUNWSPRO}/bin:$PATH"
9789e4fd900SJohn Levon	export PATH
9799e4fd900SJohn Levonfi
9809e4fd900SJohn Levon
9819e4fd900SJohn Levonhostname=$(uname -n)
9829e4fd900SJohn Levonif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
9839e4fd900SJohn Levonthen
9849e4fd900SJohn Levon	maxjobs=
9859e4fd900SJohn Levon	if [[ -f $HOME/.make.machines ]]
9869e4fd900SJohn Levon	then
9879e4fd900SJohn Levon		# Note: there is a hard tab and space character in the []s
9889e4fd900SJohn Levon		# below.
9899e4fd900SJohn Levon		egrep -i "^[ 	]*$hostname[ 	\.]" \
9909e4fd900SJohn Levon			$HOME/.make.machines | read host jobs
9919e4fd900SJohn Levon		maxjobs=${jobs##*=}
9929e4fd900SJohn Levon	fi
9939e4fd900SJohn Levon
9949e4fd900SJohn Levon	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
9959e4fd900SJohn Levon	then
9969e4fd900SJohn Levon		# default
9979e4fd900SJohn Levon		maxjobs=4
9989e4fd900SJohn Levon	fi
9999e4fd900SJohn Levon
10009e4fd900SJohn Levon	export DMAKE_MAX_JOBS=$maxjobs
10019e4fd900SJohn Levonfi
10029e4fd900SJohn Levon
10039e4fd900SJohn LevonDMAKE_MODE=parallel;
10049e4fd900SJohn Levonexport DMAKE_MODE
10059e4fd900SJohn Levon
10069e4fd900SJohn Levonif [ -z "${ROOT}" ]; then
10079e4fd900SJohn Levon	echo "ROOT must be set."
10089e4fd900SJohn Levon	exit 1
10099e4fd900SJohn Levonfi
10109e4fd900SJohn Levon
10119e4fd900SJohn Levon#
10129e4fd900SJohn Levon# if -V flag was given, reset VERSION to V_ARG
10139e4fd900SJohn Levon#
10149e4fd900SJohn Levonif [ "$V_FLAG" = "y" ]; then
10159e4fd900SJohn Levon	VERSION=$V_ARG
10169e4fd900SJohn Levonfi
10179e4fd900SJohn Levon
10189e4fd900SJohn LevonTMPDIR="/tmp/nightly.tmpdir.$$"
10199e4fd900SJohn Levonexport TMPDIR
10209e4fd900SJohn Levonrm -rf ${TMPDIR}
10219e4fd900SJohn Levonmkdir -p $TMPDIR || exit 1
10229e4fd900SJohn Levonchmod 777 $TMPDIR
10239e4fd900SJohn Levon
10249e4fd900SJohn Levon#
10259e4fd900SJohn Levon# Keep elfsign's use of pkcs11_softtoken from looking in the user home
10269e4fd900SJohn Levon# directory, which doesn't always work.   Needed until all build machines
10279e4fd900SJohn Levon# have the fix for 6271754
10289e4fd900SJohn Levon#
10299e4fd900SJohn LevonSOFTTOKEN_DIR=$TMPDIR
10309e4fd900SJohn Levonexport SOFTTOKEN_DIR
10319e4fd900SJohn Levon
10329e4fd900SJohn Levon#
10339e4fd900SJohn Levon# Tools should only be built non-DEBUG.  Keep track of the tools proto
10349e4fd900SJohn Levon# area path relative to $TOOLS, because the latter changes in an
10359e4fd900SJohn Levon# export build.
10369e4fd900SJohn Levon#
10379e4fd900SJohn Levon# TOOLS_PROTO is included below for builds other than usr/src/tools
10389e4fd900SJohn Levon# that look for this location.  For usr/src/tools, this will be
10399e4fd900SJohn Levon# overridden on the $MAKE command line in build_tools().
10409e4fd900SJohn Levon#
10419e4fd900SJohn LevonTOOLS=${SRC}/tools
10429e4fd900SJohn LevonTOOLS_PROTO_REL=proto/root_${MACH}-nd
10439e4fd900SJohn LevonTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
10449e4fd900SJohn Levon
10459e4fd900SJohn Levonunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
10469e4fd900SJohn Levon
10479e4fd900SJohn Levon# create directories that are automatically removed if the nightly script
10489e4fd900SJohn Levon# fails to start correctly
10499e4fd900SJohn Levonfunction newdir {
10509e4fd900SJohn Levon	dir=$1
10519e4fd900SJohn Levon	toadd=
10529e4fd900SJohn Levon	while [ ! -d $dir ]; do
10539e4fd900SJohn Levon		toadd="$dir $toadd"
10549e4fd900SJohn Levon		dir=`dirname $dir`
10559e4fd900SJohn Levon	done
10569e4fd900SJohn Levon	torm=
10579e4fd900SJohn Levon	newlist=
10589e4fd900SJohn Levon	for dir in $toadd; do
10599e4fd900SJohn Levon		if staffer mkdir $dir; then
10609e4fd900SJohn Levon			newlist="$ISUSER $dir $newlist"
10619e4fd900SJohn Levon			torm="$dir $torm"
10629e4fd900SJohn Levon		else
10639e4fd900SJohn Levon			[ -z "$torm" ] || staffer rmdir $torm
10649e4fd900SJohn Levon			return 1
10659e4fd900SJohn Levon		fi
10669e4fd900SJohn Levon	done
10679e4fd900SJohn Levon	newdirlist="$newlist $newdirlist"
10689e4fd900SJohn Levon	return 0
10699e4fd900SJohn Levon}
10709e4fd900SJohn Levonnewdirlist=
10719e4fd900SJohn Levon
10729e4fd900SJohn Levon[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
10739e4fd900SJohn Levon
10749e4fd900SJohn Levon# since this script assumes the build is from full source, it nullifies
10759e4fd900SJohn Levon# variables likely to have been set by a "ws" script; nullification
10769e4fd900SJohn Levon# confines the search space for headers and libraries to the proto area
10779e4fd900SJohn Levon# built from this immediate source.
10789e4fd900SJohn LevonENVLDLIBS1=
10799e4fd900SJohn LevonENVLDLIBS2=
10809e4fd900SJohn LevonENVLDLIBS3=
10819e4fd900SJohn LevonENVCPPFLAGS1=
10829e4fd900SJohn LevonENVCPPFLAGS2=
10839e4fd900SJohn LevonENVCPPFLAGS3=
10849e4fd900SJohn LevonENVCPPFLAGS4=
10859e4fd900SJohn LevonPARENT_ROOT=
10869e4fd900SJohn Levon
10879e4fd900SJohn Levonexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
10889e4fd900SJohn Levon	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
10899e4fd900SJohn Levon
10909e4fd900SJohn LevonPKGARCHIVE_ORIG=$PKGARCHIVE
10919e4fd900SJohn Levon
10929e4fd900SJohn Levon#
10939e4fd900SJohn Levon# Juggle the logs and optionally send mail on completion.
10949e4fd900SJohn Levon#
10959e4fd900SJohn Levon
10969e4fd900SJohn Levonfunction logshuffle {
10979e4fd900SJohn Levon    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
10989e4fd900SJohn Levon	if [ -f $LLOG -o -d $LLOG ]; then
10999e4fd900SJohn Levon	    	LLOG=$LLOG.$$
11009e4fd900SJohn Levon	fi
11019e4fd900SJohn Levon	mkdir $LLOG
11029e4fd900SJohn Levon	export LLOG
11039e4fd900SJohn Levon
11049e4fd900SJohn Levon	if [ "$build_ok" = "y" ]; then
11059e4fd900SJohn Levon		mv $ATLOG/proto_list_${MACH} $LLOG
11069e4fd900SJohn Levon
11079e4fd900SJohn Levon		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
11089e4fd900SJohn Levon			mv $ATLOG/proto_list_tools_${MACH} $LLOG
11099e4fd900SJohn Levon	        fi
11109e4fd900SJohn Levon
11119e4fd900SJohn Levon		if [ -f $TMPDIR/wsdiff.results ]; then
11129e4fd900SJohn Levon		    	mv $TMPDIR/wsdiff.results $LLOG
11139e4fd900SJohn Levon		fi
11149e4fd900SJohn Levon
11159e4fd900SJohn Levon		if [ -f $TMPDIR/wsdiff-nd.results ]; then
11169e4fd900SJohn Levon			mv $TMPDIR/wsdiff-nd.results $LLOG
11179e4fd900SJohn Levon		fi
1118bf16a978SMarcel Telka
1119bf16a978SMarcel Telka		if [ -f $TMPDIR/wsdiff-tools.results ]; then
1120bf16a978SMarcel Telka			mv $TMPDIR/wsdiff-tools.results $LLOG
1121bf16a978SMarcel Telka		fi
11229e4fd900SJohn Levon	fi
11239e4fd900SJohn Levon
11249e4fd900SJohn Levon	#
11259e4fd900SJohn Levon	# Now that we're about to send mail, it's time to check the noise
11269e4fd900SJohn Levon	# file.  In the event that an error occurs beyond this point, it will
11279e4fd900SJohn Levon	# be recorded in the nightly.log file, but nowhere else.  This would
11289e4fd900SJohn Levon	# include only errors that cause the copying of the noise log to fail
11299e4fd900SJohn Levon	# or the mail itself not to be sent.
11309e4fd900SJohn Levon	#
11319e4fd900SJohn Levon
11329e4fd900SJohn Levon	exec >>$LOGFILE 2>&1
11339e4fd900SJohn Levon	if [ -s $build_noise_file ]; then
11349e4fd900SJohn Levon	    	echo "\n==== Nightly build noise ====\n" |
11359e4fd900SJohn Levon		    tee -a $LOGFILE >>$mail_msg_file
11369e4fd900SJohn Levon		cat $build_noise_file >>$LOGFILE
11379e4fd900SJohn Levon		cat $build_noise_file >>$mail_msg_file
11389e4fd900SJohn Levon		echo | tee -a $LOGFILE >>$mail_msg_file
11399e4fd900SJohn Levon	fi
11409e4fd900SJohn Levon	rm -f $build_noise_file
11419e4fd900SJohn Levon
11429e4fd900SJohn Levon	case "$build_ok" in
11439e4fd900SJohn Levon		y)
11449e4fd900SJohn Levon			state=Completed
11459e4fd900SJohn Levon			;;
11469e4fd900SJohn Levon		i)
11479e4fd900SJohn Levon			state=Interrupted
11489e4fd900SJohn Levon			;;
11499e4fd900SJohn Levon		*)
11509e4fd900SJohn Levon	    		state=Failed
11519e4fd900SJohn Levon			;;
11529e4fd900SJohn Levon	esac
11539e4fd900SJohn Levon
11549e4fd900SJohn Levon	if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
11559e4fd900SJohn Levon		state=Failed
11569e4fd900SJohn Levon	fi
11579e4fd900SJohn Levon
11589e4fd900SJohn Levon	NIGHTLY_STATUS=$state
11599e4fd900SJohn Levon	export NIGHTLY_STATUS
11609e4fd900SJohn Levon
11619e4fd900SJohn Levon	run_hook POST_NIGHTLY $state
11629e4fd900SJohn Levon	run_hook SYS_POST_NIGHTLY $state
11639e4fd900SJohn Levon
11649e4fd900SJohn Levon	#
11659e4fd900SJohn Levon	# mailx(1) sets From: based on the -r flag
11669e4fd900SJohn Levon	# if it is given.
11679e4fd900SJohn Levon	#
11689e4fd900SJohn Levon	mailx_r=
11699e4fd900SJohn Levon	if [[ -n "${MAILFROM}" ]]; then
11709e4fd900SJohn Levon		mailx_r="-r ${MAILFROM}"
11719e4fd900SJohn Levon	fi
11729e4fd900SJohn Levon
11739e4fd900SJohn Levon	cat $build_time_file $build_environ_file $mail_msg_file \
11749e4fd900SJohn Levon	    > ${LLOG}/mail_msg
11759e4fd900SJohn Levon	if [ "$m_FLAG" = "y" ]; then
11769e4fd900SJohn Levon	    	cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
11779e4fd900SJohn Levon	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
11789e4fd900SJohn Levon			${MAILTO}
11799e4fd900SJohn Levon	fi
11809e4fd900SJohn Levon
11819e4fd900SJohn Levon	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
11829e4fd900SJohn Levon	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
11839e4fd900SJohn Levon		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
11849e4fd900SJohn Levon	fi
11859e4fd900SJohn Levon
11869e4fd900SJohn Levon	mv $LOGFILE $LLOG
11879e4fd900SJohn Levon}
11889e4fd900SJohn Levon
11899e4fd900SJohn Levon#
11909e4fd900SJohn Levon#	Remove the locks and temporary files on any exit
11919e4fd900SJohn Levon#
11929e4fd900SJohn Levonfunction cleanup {
11939e4fd900SJohn Levon    	logshuffle
11949e4fd900SJohn Levon
11959e4fd900SJohn Levon	[ -z "$lockfile" ] || staffer rm -f $lockfile
11969e4fd900SJohn Levon	[ -z "$atloglockfile" ] || rm -f $atloglockfile
11979e4fd900SJohn Levon	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
11989e4fd900SJohn Levon	[ -z "$Ulockfile" ] || rm -f $Ulockfile
11999e4fd900SJohn Levon
12009e4fd900SJohn Levon	set -- $newdirlist
12019e4fd900SJohn Levon	while [ $# -gt 0 ]; do
12029e4fd900SJohn Levon		ISUSER=$1 staffer rmdir $2
12039e4fd900SJohn Levon		shift; shift
12049e4fd900SJohn Levon	done
12059e4fd900SJohn Levon	rm -rf $TMPDIR
12069e4fd900SJohn Levon}
12079e4fd900SJohn Levon
12089e4fd900SJohn Levonfunction cleanup_signal {
12099e4fd900SJohn Levon    	build_ok=i
12109e4fd900SJohn Levon	# this will trigger cleanup(), above.
12119e4fd900SJohn Levon	exit 1
12129e4fd900SJohn Levon}
12139e4fd900SJohn Levon
12149e4fd900SJohn Levontrap cleanup 0
12159e4fd900SJohn Levontrap cleanup_signal 1 2 3 15
12169e4fd900SJohn Levon
12179e4fd900SJohn Levon#
12189e4fd900SJohn Levon# Generic lock file processing -- make sure that the lock file doesn't
12199e4fd900SJohn Levon# exist.  If it does, it should name the build host and PID.  If it
12209e4fd900SJohn Levon# doesn't, then make sure we can create it.  Clean up locks that are
12219e4fd900SJohn Levon# known to be stale (assumes host name is unique among build systems
12229e4fd900SJohn Levon# for the workspace).
12239e4fd900SJohn Levon#
12249e4fd900SJohn Levonfunction create_lock {
12259e4fd900SJohn Levon	lockf=$1
12269e4fd900SJohn Levon	lockvar=$2
12279e4fd900SJohn Levon
12289e4fd900SJohn Levon	ldir=`dirname $lockf`
12299e4fd900SJohn Levon	[ -d $ldir ] || newdir $ldir || exit 1
12309e4fd900SJohn Levon	eval $lockvar=$lockf
12319e4fd900SJohn Levon
12329e4fd900SJohn Levon	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
12339e4fd900SJohn Levon		basews=`basename $CODEMGR_WS`
12349e4fd900SJohn Levon		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
12359e4fd900SJohn Levon		if [ "$host" != "$hostname" ]; then
12369e4fd900SJohn Levon			echo "$MACH build of $basews apparently" \
12379e4fd900SJohn Levon			    "already started by $user on $host as $pid."
12389e4fd900SJohn Levon			exit 1
12399e4fd900SJohn Levon		elif kill -s 0 $pid 2>/dev/null; then
12409e4fd900SJohn Levon			echo "$MACH build of $basews already started" \
12419e4fd900SJohn Levon			    "by $user as $pid."
12429e4fd900SJohn Levon			exit 1
12439e4fd900SJohn Levon		else
12449e4fd900SJohn Levon			# stale lock; clear it out and try again
12459e4fd900SJohn Levon			rm -f $lockf
12469e4fd900SJohn Levon		fi
12479e4fd900SJohn Levon	done
12489e4fd900SJohn Levon}
12499e4fd900SJohn Levon
12509e4fd900SJohn Levon#
12519e4fd900SJohn Levon# Return the list of interesting proto areas, depending on the current
12529e4fd900SJohn Levon# options.
12539e4fd900SJohn Levon#
12549e4fd900SJohn Levonfunction allprotos {
12559e4fd900SJohn Levon	typeset roots="$ROOT"
12569e4fd900SJohn Levon
12579e4fd900SJohn Levon	if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
12589e4fd900SJohn Levon		roots="$roots $ROOT-nd"
12599e4fd900SJohn Levon	fi
12609e4fd900SJohn Levon
12619e4fd900SJohn Levon	echo $roots
12629e4fd900SJohn Levon}
12639e4fd900SJohn Levon
12649e4fd900SJohn Levon# Ensure no other instance of this script is running on this host.
12659e4fd900SJohn Levon# LOCKNAME can be set in <env_file>, and is by default, but is not
12669e4fd900SJohn Levon# required due to the use of $ATLOG below.
12679e4fd900SJohn Levonif [ -n "$LOCKNAME" ]; then
12689e4fd900SJohn Levon	create_lock /tmp/$LOCKNAME "lockfile"
12699e4fd900SJohn Levonfi
12709e4fd900SJohn Levon#
12719e4fd900SJohn Levon# Create from one, two, or three other locks:
12729e4fd900SJohn Levon#	$ATLOG/nightly.lock
12739e4fd900SJohn Levon#		- protects against multiple builds in same workspace
12749e4fd900SJohn Levon#	$PARENT_WS/usr/src/nightly.$MACH.lock
12759e4fd900SJohn Levon#		- protects against multiple 'u' copy-backs
12769e4fd900SJohn Levon#	$NIGHTLY_PARENT_ROOT/nightly.lock
12779e4fd900SJohn Levon#		- protects against multiple 'U' copy-backs
12789e4fd900SJohn Levon#
12799e4fd900SJohn Levon# Overriding ISUSER to 1 causes the lock to be created as root if the
12809e4fd900SJohn Levon# script is run as root.  The default is to create it as $STAFFER.
12819e4fd900SJohn LevonISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
12829e4fd900SJohn Levonif [ "$u_FLAG" = "y" ]; then
12839e4fd900SJohn Levon	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
12849e4fd900SJohn Levonfi
12859e4fd900SJohn Levonif [ "$U_FLAG" = "y" ]; then
12869e4fd900SJohn Levon	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
12879e4fd900SJohn Levon	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
12889e4fd900SJohn Levonfi
12899e4fd900SJohn Levon
12909e4fd900SJohn Levon# Locks have been taken, so we're doing a build and we're committed to
12919e4fd900SJohn Levon# the directories we may have created so far.
12929e4fd900SJohn Levonnewdirlist=
12939e4fd900SJohn Levon
12949e4fd900SJohn Levon#
12959e4fd900SJohn Levon# Create mail_msg_file
12969e4fd900SJohn Levon#
12979e4fd900SJohn Levonmail_msg_file="${TMPDIR}/mail_msg"
12989e4fd900SJohn Levontouch $mail_msg_file
12999e4fd900SJohn Levonbuild_time_file="${TMPDIR}/build_time"
13009e4fd900SJohn Levonbuild_environ_file="${TMPDIR}/build_environ"
13019e4fd900SJohn Levontouch $build_environ_file
13029e4fd900SJohn Levon#
13039e4fd900SJohn Levon#	Move old LOGFILE aside
13049e4fd900SJohn Levon#	ATLOG directory already made by 'create_lock' above
13059e4fd900SJohn Levon#
13069e4fd900SJohn Levonif [ -f $LOGFILE ]; then
13079e4fd900SJohn Levon	mv -f $LOGFILE ${LOGFILE}-
13089e4fd900SJohn Levonfi
13099e4fd900SJohn Levon#
13109e4fd900SJohn Levon#	Build OsNet source
13119e4fd900SJohn Levon#
13129e4fd900SJohn LevonSTART_DATE=`date`
13139e4fd900SJohn LevonSECONDS=0
13149e4fd900SJohn Levonecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
13159e4fd900SJohn Levon    | tee -a $LOGFILE > $build_time_file
13169e4fd900SJohn Levon
13179e4fd900SJohn Levonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
13189e4fd900SJohn Levon    tee -a $mail_msg_file >> $LOGFILE
13199e4fd900SJohn Levon
13209e4fd900SJohn Levon# make sure we log only to the nightly build file
13219e4fd900SJohn Levonbuild_noise_file="${TMPDIR}/build_noise"
13229e4fd900SJohn Levonexec </dev/null >$build_noise_file 2>&1
13239e4fd900SJohn Levon
13249e4fd900SJohn Levonrun_hook SYS_PRE_NIGHTLY
13259e4fd900SJohn Levonrun_hook PRE_NIGHTLY
13269e4fd900SJohn Levon
13279e4fd900SJohn Levonecho "\n==== list of environment variables ====\n" >> $LOGFILE
13289e4fd900SJohn Levonenv >> $LOGFILE
13299e4fd900SJohn Levon
13309e4fd900SJohn Levonecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
13319e4fd900SJohn Levon
13329e4fd900SJohn Levonif [ "$N_FLAG" = "y" ]; then
13339e4fd900SJohn Levon	if [ "$p_FLAG" = "y" ]; then
13349e4fd900SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
13359e4fd900SJohn LevonWARNING: the p option (create packages) is set, but so is the N option (do
13369e4fd900SJohn Levon         not run protocmp); this is dangerous; you should unset the N option
13379e4fd900SJohn LevonEOF
13389e4fd900SJohn Levon	else
13399e4fd900SJohn Levon		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
13409e4fd900SJohn LevonWarning: the N option (do not run protocmp) is set; it probably shouldn't be
13419e4fd900SJohn LevonEOF
13429e4fd900SJohn Levon	fi
13439e4fd900SJohn Levon	echo "" | tee -a $mail_msg_file >> $LOGFILE
13449e4fd900SJohn Levonfi
13459e4fd900SJohn Levon
13469e4fd900SJohn Levonif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
13479e4fd900SJohn Levon	#
13489e4fd900SJohn Levon	# In the past we just complained but went ahead with the lint
13499e4fd900SJohn Levon	# pass, even though the proto area was built non-DEBUG.  It's
13509e4fd900SJohn Levon	# unlikely that non-DEBUG headers will make a difference, but
13519e4fd900SJohn Levon	# rather than assuming it's a safe combination, force the user
13529e4fd900SJohn Levon	# to specify a DEBUG build.
13539e4fd900SJohn Levon	#
13549e4fd900SJohn Levon	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
13559e4fd900SJohn Levon	    | tee -a $mail_msg_file >> $LOGFILE
13569e4fd900SJohn Levon	l_FLAG=n
13579e4fd900SJohn Levonfi
13589e4fd900SJohn Levon
13599e4fd900SJohn Levonif [ "$f_FLAG" = "y" ]; then
13609e4fd900SJohn Levon	if [ "$i_FLAG" = "y" ]; then
13619e4fd900SJohn Levon		echo "WARNING: the -f flag cannot be used during incremental" \
13629e4fd900SJohn Levon		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13639e4fd900SJohn Levon		f_FLAG=n
13649e4fd900SJohn Levon	fi
13659e4fd900SJohn Levon	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
13669e4fd900SJohn Levon		echo "WARNING: the -f flag requires -l, and -p;" \
13679e4fd900SJohn Levon		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13689e4fd900SJohn Levon		f_FLAG=n
13699e4fd900SJohn Levon	fi
13709e4fd900SJohn Levonfi
13719e4fd900SJohn Levon
13729e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
13739e4fd900SJohn Levon	echo "WARNING: -w specified, but $ROOT does not exist;" \
13749e4fd900SJohn Levon	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
13759e4fd900SJohn Levon	w_FLAG=n
13769e4fd900SJohn Levonfi
13779e4fd900SJohn Levon
13789e4fd900SJohn Levonif [ "$t_FLAG" = "n" ]; then
13799e4fd900SJohn Levon	#
13809e4fd900SJohn Levon	# We're not doing a tools build, so make sure elfsign(1) is
13819e4fd900SJohn Levon	# new enough to safely sign non-crypto binaries.  We test
13829e4fd900SJohn Levon	# debugging output from elfsign to detect the old version.
13839e4fd900SJohn Levon	#
13849e4fd900SJohn Levon	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
13859e4fd900SJohn Levon	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
13869e4fd900SJohn Levon	    | egrep algorithmOID`
13879e4fd900SJohn Levon	if [ -z "$newelfsigntest" ]; then
13889e4fd900SJohn Levon		echo "WARNING: /usr/bin/elfsign out of date;" \
13899e4fd900SJohn Levon		    "will only sign crypto modules\n" | \
13909e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
13919e4fd900SJohn Levon		export ELFSIGN_OBJECT=true
13929e4fd900SJohn Levon	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
13939e4fd900SJohn Levon		echo "WARNING: VERIFY_ELFSIGN=y requires" \
13949e4fd900SJohn Levon		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
13959e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
13969e4fd900SJohn Levon	fi
13979e4fd900SJohn Levonfi
13989e4fd900SJohn Levon
13999e4fd900SJohn Levoncase $MULTI_PROTO in
14009e4fd900SJohn Levonyes|no)	;;
14019e4fd900SJohn Levon*)
14029e4fd900SJohn Levon	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
14039e4fd900SJohn Levon	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
14049e4fd900SJohn Levon	echo "Setting MULTI_PROTO to \"no\".\n" | \
14059e4fd900SJohn Levon	    tee -a $mail_msg_file >> $LOGFILE
14069e4fd900SJohn Levon	export MULTI_PROTO=no
14079e4fd900SJohn Levon	;;
14089e4fd900SJohn Levonesac
14099e4fd900SJohn Levon
14109e4fd900SJohn Levonecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
14119e4fd900SJohn Levonecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
14129e4fd900SJohn Levon
14139e4fd900SJohn Levon# Save the current proto area if we're comparing against the last build
14149e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
14159e4fd900SJohn Levon    if [ -d "$ROOT.prev" ]; then
14169e4fd900SJohn Levon	rm -rf $ROOT.prev
14179e4fd900SJohn Levon    fi
14189e4fd900SJohn Levon    mv $ROOT $ROOT.prev
14199e4fd900SJohn Levonfi
14209e4fd900SJohn Levon
14219e4fd900SJohn Levon# Same for non-DEBUG proto area
14229e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
14239e4fd900SJohn Levon	if [ -d "$ROOT-nd.prev" ]; then
14249e4fd900SJohn Levon		rm -rf $ROOT-nd.prev
14259e4fd900SJohn Levon	fi
14269e4fd900SJohn Levon	mv $ROOT-nd $ROOT-nd.prev
14279e4fd900SJohn Levonfi
14289e4fd900SJohn Levon
1429bf16a978SMarcel Telka# Same for tools proto area
1430bf16a978SMarcel Telkaif [ "$w_FLAG" = "y" -a "$t_FLAG" == "y" -a -d "$TOOLS_PROTO" ]; then
1431bf16a978SMarcel Telka	if [ -d "$TOOLS_PROTO.prev" ]; then
1432bf16a978SMarcel Telka		rm -rf $TOOLS_PROTO.prev
1433bf16a978SMarcel Telka	fi
1434bf16a978SMarcel Telka	mv $TOOLS_PROTO $TOOLS_PROTO.prev
1435bf16a978SMarcel Telkafi
1436bf16a978SMarcel Telka
14379e4fd900SJohn Levon#
14389e4fd900SJohn Levon# Echo the SCM type of the parent workspace, this can't just be which_scm
14399e4fd900SJohn Levon# as that does not know how to identify various network repositories.
14409e4fd900SJohn Levon#
14419e4fd900SJohn Levonfunction parent_wstype {
14429e4fd900SJohn Levon	typeset scm_type junk
14439e4fd900SJohn Levon
14449e4fd900SJohn Levon	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
14459e4fd900SJohn Levon	    | read scm_type junk
14469e4fd900SJohn Levon	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
14479e4fd900SJohn Levon		# Probe BRINGOVER_WS to determine its type
14489e4fd900SJohn Levon		if [[ $BRINGOVER_WS == ssh://* ]]; then
14499e4fd900SJohn Levon			scm_type="mercurial"
14509e4fd900SJohn Levon		elif [[ $BRINGOVER_WS == http://* ]] && \
14519e4fd900SJohn Levon		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
14529e4fd900SJohn Levon		    egrep -s "application/mercurial" 2> /dev/null; then
14539e4fd900SJohn Levon			scm_type="mercurial"
14549e4fd900SJohn Levon		else
14559e4fd900SJohn Levon			scm_type="none"
14569e4fd900SJohn Levon		fi
14579e4fd900SJohn Levon	fi
14589e4fd900SJohn Levon
14599e4fd900SJohn Levon	# fold both unsupported and unrecognized results into "none"
14609e4fd900SJohn Levon	case "$scm_type" in
14619e4fd900SJohn Levon	mercurial)
14629e4fd900SJohn Levon		;;
14639e4fd900SJohn Levon	*)	scm_type=none
14649e4fd900SJohn Levon		;;
14659e4fd900SJohn Levon	esac
14669e4fd900SJohn Levon
14679e4fd900SJohn Levon	echo $scm_type
14689e4fd900SJohn Levon}
14699e4fd900SJohn Levon
14709e4fd900SJohn Levon# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
14719e4fd900SJohn Levonfunction child_wstype {
14729e4fd900SJohn Levon	typeset scm_type junk
14739e4fd900SJohn Levon
14749e4fd900SJohn Levon	# Probe CODEMGR_WS to determine its type
14759e4fd900SJohn Levon	if [[ -d $CODEMGR_WS ]]; then
14769e4fd900SJohn Levon		$WHICH_SCM | read scm_type junk || exit 1
14779e4fd900SJohn Levon	fi
14789e4fd900SJohn Levon
14799e4fd900SJohn Levon	case "$scm_type" in
14809e4fd900SJohn Levon	none|git|mercurial)
14819e4fd900SJohn Levon		;;
14829e4fd900SJohn Levon	*)	scm_type=none
14839e4fd900SJohn Levon		;;
14849e4fd900SJohn Levon	esac
14859e4fd900SJohn Levon
14869e4fd900SJohn Levon	echo $scm_type
14879e4fd900SJohn Levon}
14889e4fd900SJohn Levon
14899e4fd900SJohn LevonSCM_TYPE=$(child_wstype)
14909e4fd900SJohn Levon
14919e4fd900SJohn Levon#
14929e4fd900SJohn Levon#	Decide whether to clobber
14939e4fd900SJohn Levon#
14949e4fd900SJohn Levonif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
14959e4fd900SJohn Levon	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
14969e4fd900SJohn Levon
14979e4fd900SJohn Levon	cd $SRC
14989e4fd900SJohn Levon	# remove old clobber file
14999e4fd900SJohn Levon	rm -f $SRC/clobber.out
15009e4fd900SJohn Levon	rm -f $SRC/clobber-${MACH}.out
15019e4fd900SJohn Levon
15029e4fd900SJohn Levon	# Remove all .make.state* files, just in case we are restarting
15039e4fd900SJohn Levon	# the build after having interrupted a previous 'make clobber'.
15049e4fd900SJohn Levon	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
15059e4fd900SJohn Levon		-o -name 'interfaces.*' \) -prune \
15069e4fd900SJohn Levon		-o -name '.make.*' -print | xargs rm -f
15079e4fd900SJohn Levon
15089e4fd900SJohn Levon	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
15099e4fd900SJohn Levon	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
15109e4fd900SJohn Levon	grep "$MAKE:" $SRC/clobber-${MACH}.out |
15119e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
15129e4fd900SJohn Levon		tee $TMPDIR/clobber_errs >> $mail_msg_file
15139e4fd900SJohn Levon
15149e4fd900SJohn Levon	if [[ -s $TMPDIR/clobber_errs ]]; then
15159e4fd900SJohn Levon		build_extras_ok=n
15169e4fd900SJohn Levon	fi
15179e4fd900SJohn Levon
15189e4fd900SJohn Levon	if [[ "$t_FLAG" = "y" ]]; then
15199e4fd900SJohn Levon		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
15209e4fd900SJohn Levon		cd ${TOOLS}
15219e4fd900SJohn Levon		rm -f ${TOOLS}/clobber-${MACH}.out
15229e4fd900SJohn Levon		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
15239e4fd900SJohn Levon			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
15249e4fd900SJohn Levon		echo "\n==== Make tools clobber ERRORS ====\n" \
15259e4fd900SJohn Levon			>> $mail_msg_file
15269e4fd900SJohn Levon		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
15279e4fd900SJohn Levon			>> $mail_msg_file
15289e4fd900SJohn Levon		if (( $? == 0 )); then
15299e4fd900SJohn Levon			build_extras_ok=n
15309e4fd900SJohn Levon		fi
15319e4fd900SJohn Levon		rm -rf ${TOOLS_PROTO}
15329e4fd900SJohn Levon		mkdir -p ${TOOLS_PROTO}
15339e4fd900SJohn Levon	fi
15349e4fd900SJohn Levon
15359e4fd900SJohn Levon	typeset roots=$(allprotos)
15369e4fd900SJohn Levon	echo "\n\nClearing $roots" >> "$LOGFILE"
15379e4fd900SJohn Levon	rm -rf $roots
15389e4fd900SJohn Levon
15399e4fd900SJohn Levon	# Get back to a clean workspace as much as possible to catch
15409e4fd900SJohn Levon	# problems that only occur on fresh workspaces.
15419e4fd900SJohn Levon	# Remove all .make.state* files, libraries, and .o's that may
15429e4fd900SJohn Levon	# have been omitted from clobber.  A couple of libraries are
15439e4fd900SJohn Levon	# under source code control, so leave them alone.
15449e4fd900SJohn Levon	# We should probably blow away temporary directories too.
15459e4fd900SJohn Levon	cd $SRC
15469e4fd900SJohn Levon	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
15479e4fd900SJohn Levon	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
15489e4fd900SJohn Levon	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
15499e4fd900SJohn Levon	       -name '*.o' \) -print | \
15509e4fd900SJohn Levon	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
15519e4fd900SJohn Levonelse
15529e4fd900SJohn Levon	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
15539e4fd900SJohn Levonfi
15549e4fd900SJohn Levon
15559e4fd900SJohn Levontype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
15569e4fd900SJohn Levon	typeset -x PATH=$PATH
15579e4fd900SJohn Levon
15589e4fd900SJohn Levon	# If the repository doesn't exist yet, then we want to populate it.
15599e4fd900SJohn Levon	if [[ ! -d $CODEMGR_WS/.hg ]]; then
15609e4fd900SJohn Levon		staffer hg init $CODEMGR_WS
15619e4fd900SJohn Levon		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
15629e4fd900SJohn Levon		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
15639e4fd900SJohn Levon		touch $TMPDIR/new_repository
15649e4fd900SJohn Levon	fi
15659e4fd900SJohn Levon
15669e4fd900SJohn Levon	typeset -x HGMERGE="/bin/false"
15679e4fd900SJohn Levon
15689e4fd900SJohn Levon	#
15699e4fd900SJohn Levon	# If the user has changes, regardless of whether those changes are
15709e4fd900SJohn Levon	# committed, and regardless of whether those changes conflict, then
15719e4fd900SJohn Levon	# we'll attempt to merge them either implicitly (uncommitted) or
15729e4fd900SJohn Levon	# explicitly (committed).
15739e4fd900SJohn Levon	#
15749e4fd900SJohn Levon	# These are the messages we'll use to help clarify mercurial output
15759e4fd900SJohn Levon	# in those cases.
15769e4fd900SJohn Levon	#
15779e4fd900SJohn Levon	typeset mergefailmsg="\
15789e4fd900SJohn Levon***\n\
15799e4fd900SJohn Levon*** nightly was unable to automatically merge your changes.  You should\n\
15809e4fd900SJohn Levon*** redo the full merge manually, following the steps outlined by mercurial\n\
15819e4fd900SJohn Levon*** above, then restart nightly.\n\
15829e4fd900SJohn Levon***\n"
15839e4fd900SJohn Levon	typeset mergepassmsg="\
15849e4fd900SJohn Levon***\n\
15859e4fd900SJohn Levon*** nightly successfully merged your changes.  This means that your working\n\
15869e4fd900SJohn Levon*** directory has been updated, but those changes are not yet committed.\n\
15879e4fd900SJohn Levon*** After nightly completes, you should validate the results of the merge,\n\
15889e4fd900SJohn Levon*** then use hg commit manually.\n\
15899e4fd900SJohn Levon***\n"
15909e4fd900SJohn Levon
15919e4fd900SJohn Levon	#
15929e4fd900SJohn Levon	# For each repository in turn:
15939e4fd900SJohn Levon	#
15949e4fd900SJohn Levon	# 1. Do the pull.  If this fails, dump the output and bail out.
15959e4fd900SJohn Levon	#
15969e4fd900SJohn Levon	# 2. If the pull resulted in an extra head, do an explicit merge.
15979e4fd900SJohn Levon	#    If this fails, dump the output and bail out.
15989e4fd900SJohn Levon	#
15999e4fd900SJohn Levon	# Because we can't rely on Mercurial to exit with a failure code
16009e4fd900SJohn Levon	# when a merge fails (Mercurial issue #186), we must grep the
16019e4fd900SJohn Levon	# output of pull/merge to check for attempted and/or failed merges.
16029e4fd900SJohn Levon	#
16039e4fd900SJohn Levon	# 3. If a merge failed, set the message and fail the bringover.
16049e4fd900SJohn Levon	#
16059e4fd900SJohn Levon	# 4. Otherwise, if a merge succeeded, set the message
16069e4fd900SJohn Levon	#
16079e4fd900SJohn Levon	# 5. Dump the output, and any message from step 3 or 4.
16089e4fd900SJohn Levon	#
16099e4fd900SJohn Levon
16109e4fd900SJohn Levon	typeset HG_SOURCE=$BRINGOVER_WS
16119e4fd900SJohn Levon	if [ ! -f $TMPDIR/new_repository ]; then
16129e4fd900SJohn Levon		HG_SOURCE=$TMPDIR/open_bundle.hg
16139e4fd900SJohn Levon		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
16149e4fd900SJohn Levon		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
16159e4fd900SJohn Levon
16169e4fd900SJohn Levon		#
16179e4fd900SJohn Levon		# If there are no incoming changesets, then incoming will
16189e4fd900SJohn Levon		# fail, and there will be no bundle file.  Reset the source,
16199e4fd900SJohn Levon		# to allow the remaining logic to complete with no false
16209e4fd900SJohn Levon		# negatives.  (Unlike incoming, pull will return success
16219e4fd900SJohn Levon		# for the no-change case.)
16229e4fd900SJohn Levon		#
16239e4fd900SJohn Levon		if (( $? != 0 )); then
16249e4fd900SJohn Levon			HG_SOURCE=$BRINGOVER_WS
16259e4fd900SJohn Levon		fi
16269e4fd900SJohn Levon	fi
16279e4fd900SJohn Levon
16289e4fd900SJohn Levon	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
16299e4fd900SJohn Levon	    > $TMPDIR/pull_open.out 2>&1
16309e4fd900SJohn Levon	if (( $? != 0 )); then
16319e4fd900SJohn Levon		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
16329e4fd900SJohn Levon		cat $TMPDIR/pull_open.out
16339e4fd900SJohn Levon		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
16349e4fd900SJohn Levon			printf "$mergefailmsg"
16359e4fd900SJohn Levon		fi
16369e4fd900SJohn Levon		touch $TMPDIR/bringover_failed
16379e4fd900SJohn Levon		return
16389e4fd900SJohn Levon	fi
16399e4fd900SJohn Levon
16409e4fd900SJohn Levon	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
16419e4fd900SJohn Levon		staffer hg --cwd $CODEMGR_WS merge \
16429e4fd900SJohn Levon		    >> $TMPDIR/pull_open.out 2>&1
16439e4fd900SJohn Levon		if (( $? != 0 )); then
16449e4fd900SJohn Levon			printf "%s: merge failed as follows:\n\n" \
16459e4fd900SJohn Levon			    "$CODEMGR_WS"
16469e4fd900SJohn Levon			cat $TMPDIR/pull_open.out
16479e4fd900SJohn Levon			if grep "^merging.*failed" $TMPDIR/pull_open.out \
16489e4fd900SJohn Levon			    > /dev/null 2>&1; then
16499e4fd900SJohn Levon				printf "$mergefailmsg"
16509e4fd900SJohn Levon			fi
16519e4fd900SJohn Levon			touch $TMPDIR/bringover_failed
16529e4fd900SJohn Levon			return
16539e4fd900SJohn Levon		fi
16549e4fd900SJohn Levon	fi
16559e4fd900SJohn Levon
16569e4fd900SJohn Levon	printf "updated %s with the following results:\n" "$CODEMGR_WS"
16579e4fd900SJohn Levon	cat $TMPDIR/pull_open.out
16589e4fd900SJohn Levon	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
16599e4fd900SJohn Levon		printf "$mergepassmsg"
16609e4fd900SJohn Levon	fi
16619e4fd900SJohn Levon	printf "\n"
16629e4fd900SJohn Levon
16639e4fd900SJohn Levon	#
16649e4fd900SJohn Levon	# Per-changeset output is neither useful nor manageable for a
16659e4fd900SJohn Levon	# newly-created repository.
16669e4fd900SJohn Levon	#
16679e4fd900SJohn Levon	if [ -f $TMPDIR/new_repository ]; then
16689e4fd900SJohn Levon		return
16699e4fd900SJohn Levon	fi
16709e4fd900SJohn Levon
16719e4fd900SJohn Levon	printf "\nadded the following changesets to open repository:\n"
16729e4fd900SJohn Levon	cat $TMPDIR/incoming_open.out
16739e4fd900SJohn Levon}
16749e4fd900SJohn Levon
16759e4fd900SJohn Levontype bringover_none > /dev/null 2>&1 || function bringover_none {
16769e4fd900SJohn Levon	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
16779e4fd900SJohn Levon	touch $TMPDIR/bringover_failed
16789e4fd900SJohn Levon}
16799e4fd900SJohn Levon
16809e4fd900SJohn Levon#
16819e4fd900SJohn Levon#	Decide whether to bringover to the codemgr workspace
16829e4fd900SJohn Levon#
16839e4fd900SJohn Levonif [ "$n_FLAG" = "n" ]; then
16849e4fd900SJohn Levon	PARENT_SCM_TYPE=$(parent_wstype)
16859e4fd900SJohn Levon
16869e4fd900SJohn Levon	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
16879e4fd900SJohn Levon		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
16889e4fd900SJohn Levon		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
16899e4fd900SJohn Levon		exit 1
16909e4fd900SJohn Levon	fi
16919e4fd900SJohn Levon
16929e4fd900SJohn Levon	run_hook PRE_BRINGOVER
16939e4fd900SJohn Levon
16949e4fd900SJohn Levon	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
16959e4fd900SJohn Levon	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
16969e4fd900SJohn Levon
16979e4fd900SJohn Levon	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
16989e4fd900SJohn Levon		tee -a $mail_msg_file >> $LOGFILE
16999e4fd900SJohn Levon
17009e4fd900SJohn Levon	if [ -f $TMPDIR/bringover_failed ]; then
17019e4fd900SJohn Levon		rm -f $TMPDIR/bringover_failed
17029e4fd900SJohn Levon		build_ok=n
17039e4fd900SJohn Levon		echo "trouble with bringover, quitting at `date`." |
17049e4fd900SJohn Levon			tee -a $mail_msg_file >> $LOGFILE
17059e4fd900SJohn Levon		exit 1
17069e4fd900SJohn Levon	fi
17079e4fd900SJohn Levon
17089e4fd900SJohn Levon	#
17099e4fd900SJohn Levon	# It's possible that we used the bringover above to create
17109e4fd900SJohn Levon	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
17119e4fd900SJohn Levon	# but should now be the same as $BRINGOVER_WS.
17129e4fd900SJohn Levon	#
17139e4fd900SJohn Levon	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
17149e4fd900SJohn Levon
17159e4fd900SJohn Levon	run_hook POST_BRINGOVER
17169e4fd900SJohn Levon
17179e4fd900SJohn Levon	check_closed_bins
17189e4fd900SJohn Levon
17199e4fd900SJohn Levonelse
17209e4fd900SJohn Levon	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
17219e4fd900SJohn Levonfi
17229e4fd900SJohn Levon
17239e4fd900SJohn Levon# Safeguards
17249e4fd900SJohn Levon[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
17259e4fd900SJohn Levon[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
17269e4fd900SJohn Levon[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
17279e4fd900SJohn Levon
17289e4fd900SJohn Levonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
17299e4fd900SJohn Levon
17309e4fd900SJohn Levon# System
17319e4fd900SJohn Levonwhence uname | tee -a $build_environ_file >> $LOGFILE
17329e4fd900SJohn Levonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
17339e4fd900SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
17349e4fd900SJohn Levon
17359e4fd900SJohn Levon# make
17369e4fd900SJohn Levonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
17379e4fd900SJohn Levon$MAKE -v | tee -a $build_environ_file >> $LOGFILE
17389e4fd900SJohn Levonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
17399e4fd900SJohn Levon    tee -a $build_environ_file >> $LOGFILE
17409e4fd900SJohn Levon
17419e4fd900SJohn Levon#
17429e4fd900SJohn Levon# Report the compiler versions.
17439e4fd900SJohn Levon#
17449e4fd900SJohn Levon
17459e4fd900SJohn Levonif [[ ! -f $SRC/Makefile ]]; then
17469e4fd900SJohn Levon	build_ok=n
17479e4fd900SJohn Levon	echo "\nUnable to find \"Makefile\" in $SRC." | \
17489e4fd900SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17499e4fd900SJohn Levon	exit 1
17509e4fd900SJohn Levonfi
17519e4fd900SJohn Levon
17529e4fd900SJohn Levon( cd $SRC
17539e4fd900SJohn Levon  for target in cc-version cc64-version java-version; do
17549e4fd900SJohn Levon	echo
17559e4fd900SJohn Levon	#
17569e4fd900SJohn Levon	# Put statefile somewhere we know we can write to rather than trip
17579e4fd900SJohn Levon	# over a read-only $srcroot.
17589e4fd900SJohn Levon	#
17599e4fd900SJohn Levon	rm -f $TMPDIR/make-state
17609e4fd900SJohn Levon	export SRC
17619e4fd900SJohn Levon	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
17629e4fd900SJohn Levon		continue
17639e4fd900SJohn Levon	fi
17649e4fd900SJohn Levon	touch $TMPDIR/nocompiler
17659e4fd900SJohn Levon  done
17669e4fd900SJohn Levon  echo
17679e4fd900SJohn Levon) | tee -a $build_environ_file >> $LOGFILE
17689e4fd900SJohn Levon
17699e4fd900SJohn Levonif [ -f $TMPDIR/nocompiler ]; then
17709e4fd900SJohn Levon	rm -f $TMPDIR/nocompiler
17719e4fd900SJohn Levon	build_ok=n
17729e4fd900SJohn Levon	echo "Aborting due to missing compiler." |
17739e4fd900SJohn Levon		tee -a $build_environ_file >> $LOGFILE
17749e4fd900SJohn Levon	exit 1
17759e4fd900SJohn Levonfi
17769e4fd900SJohn Levon
17779e4fd900SJohn Levon# as
17789e4fd900SJohn Levonwhence as | tee -a $build_environ_file >> $LOGFILE
17799e4fd900SJohn Levonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
17809e4fd900SJohn Levonecho | tee -a $build_environ_file >> $LOGFILE
17819e4fd900SJohn Levon
17829e4fd900SJohn Levon# Check that we're running a capable link-editor
17839e4fd900SJohn Levonwhence ld | tee -a $build_environ_file >> $LOGFILE
17849e4fd900SJohn LevonLDVER=`ld -V 2>&1`
17859e4fd900SJohn Levonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
17869e4fd900SJohn LevonLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
17879e4fd900SJohn Levonif [ `expr $LDVER \< 422` -eq 1 ]; then
17889e4fd900SJohn Levon	echo "The link-editor needs to be at version 422 or higher to build" | \
17899e4fd900SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17909e4fd900SJohn Levon	echo "the latest stuff.  Hope your build works." | \
17919e4fd900SJohn Levon	    tee -a $build_environ_file >> $LOGFILE
17929e4fd900SJohn Levonfi
17939e4fd900SJohn Levon
17949e4fd900SJohn Levon#
17959e4fd900SJohn Levon# Build and use the workspace's tools if requested
17969e4fd900SJohn Levon#
17979e4fd900SJohn Levonif [[ "$t_FLAG" = "y" ]]; then
17989e4fd900SJohn Levon	set_non_debug_build_flags
17999e4fd900SJohn Levon
18009e4fd900SJohn Levon	build_tools ${TOOLS_PROTO}
18019e4fd900SJohn Levon	if (( $? != 0 )); then
18029e4fd900SJohn Levon		build_ok=n
18039e4fd900SJohn Levon	else
18049e4fd900SJohn Levon		use_tools $TOOLS_PROTO
18059e4fd900SJohn Levon	fi
18069e4fd900SJohn Levonfi
18079e4fd900SJohn Levon
18089e4fd900SJohn Levon# timestamp the start of the normal build; the findunref tool uses it.
18099e4fd900SJohn Levontouch $SRC/.build.tstamp
18109e4fd900SJohn Levon
18119e4fd900SJohn Levonnormal_build
18129e4fd900SJohn Levon
18139e4fd900SJohn LevonORIG_SRC=$SRC
18149e4fd900SJohn LevonBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
18159e4fd900SJohn Levon
18169e4fd900SJohn Levon
18179e4fd900SJohn Levon#
18189e4fd900SJohn Levon# There are several checks that need to look at the proto area, but
18199e4fd900SJohn Levon# they only need to look at one, and they don't care whether it's
18209e4fd900SJohn Levon# DEBUG or non-DEBUG.
18219e4fd900SJohn Levon#
18229e4fd900SJohn Levonif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
18239e4fd900SJohn Levon	checkroot=$ROOT-nd
18249e4fd900SJohn Levonelse
18259e4fd900SJohn Levon	checkroot=$ROOT
18269e4fd900SJohn Levonfi
18279e4fd900SJohn Levon
18289e4fd900SJohn Levonif [ "$build_ok" = "y" ]; then
18299e4fd900SJohn Levon	echo "\n==== Creating protolist system file at `date` ====" \
18309e4fd900SJohn Levon		>> $LOGFILE
18319e4fd900SJohn Levon	protolist $checkroot > $ATLOG/proto_list_${MACH}
18329e4fd900SJohn Levon	echo "==== protolist system file created at `date` ====\n" \
18339e4fd900SJohn Levon		>> $LOGFILE
18349e4fd900SJohn Levon
18359e4fd900SJohn Levon	if [ "$N_FLAG" != "y" ]; then
18369e4fd900SJohn Levon
18379e4fd900SJohn Levon		E1=
18389e4fd900SJohn Levon		f1=
18399e4fd900SJohn Levon		for f in $f1; do
18409e4fd900SJohn Levon			if [ -f "$f" ]; then
18419e4fd900SJohn Levon				E1="$E1 -e $f"
18429e4fd900SJohn Levon			fi
18439e4fd900SJohn Levon		done
18449e4fd900SJohn Levon
18459e4fd900SJohn Levon		E2=
18469e4fd900SJohn Levon		f2=
18479e4fd900SJohn Levon		if [ -d "$SRC/pkg" ]; then
18489e4fd900SJohn Levon			f2="$f2 exceptions/packaging"
18499e4fd900SJohn Levon		fi
18509e4fd900SJohn Levon
18519e4fd900SJohn Levon		for f in $f2; do
18529e4fd900SJohn Levon			if [ -f "$f" ]; then
18539e4fd900SJohn Levon				E2="$E2 -e $f"
18549e4fd900SJohn Levon			fi
18559e4fd900SJohn Levon		done
18569e4fd900SJohn Levon	fi
18579e4fd900SJohn Levon
18589e4fd900SJohn Levon	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
18599e4fd900SJohn Levon		echo "\n==== Validating manifests against proto area ====\n" \
18609e4fd900SJohn Levon		    >> $mail_msg_file
18619e4fd900SJohn Levon		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
18629e4fd900SJohn Levon		    tee $TMPDIR/protocmp_noise >> $mail_msg_file
18639e4fd900SJohn Levon		if [[ -s $TMPDIR/protocmp_noise ]]; then
18649e4fd900SJohn Levon			build_extras_ok=n
18659e4fd900SJohn Levon		fi
18669e4fd900SJohn Levon	fi
18679e4fd900SJohn Levon
18689e4fd900SJohn Levon	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
18699e4fd900SJohn Levon		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
18709e4fd900SJohn Levon		if [ -n "$E2" ]; then
18719e4fd900SJohn Levon			ELIST=$E2
18729e4fd900SJohn Levon		else
18739e4fd900SJohn Levon			ELIST=$E1
18749e4fd900SJohn Levon		fi
18759e4fd900SJohn Levon		$PROTOCMPTERSE \
18769e4fd900SJohn Levon			"Files in yesterday's proto area, but not today's:" \
18779e4fd900SJohn Levon			"Files in today's proto area, but not yesterday's:" \
18789e4fd900SJohn Levon			"Files that changed between yesterday and today:" \
18799e4fd900SJohn Levon			${ELIST} \
18809e4fd900SJohn Levon			-d $REF_PROTO_LIST \
18819e4fd900SJohn Levon			$ATLOG/proto_list_${MACH} \
18829e4fd900SJohn Levon			>> $mail_msg_file
18839e4fd900SJohn Levon	fi
18849e4fd900SJohn Levonfi
18859e4fd900SJohn Levon
18869e4fd900SJohn Levonif [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
18879e4fd900SJohn Levon    "$build_extras_ok" == "y" ]]; then
18889e4fd900SJohn Levon	staffer cp $ATLOG/proto_list_${MACH} \
18899e4fd900SJohn Levon		$PARENT_WS/usr/src/proto_list_${MACH}
18909e4fd900SJohn Levonfi
18919e4fd900SJohn Levon
18929e4fd900SJohn Levon# Update parent proto area if necessary. This is done now
18939e4fd900SJohn Levon# so that the proto area has either DEBUG or non-DEBUG kernels.
18949e4fd900SJohn Levon# Note that this clears out the lock file, so we can dispense with
18959e4fd900SJohn Levon# the variable now.
18969e4fd900SJohn Levonif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
18979e4fd900SJohn Levon	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
18989e4fd900SJohn Levon	    tee -a $LOGFILE >> $mail_msg_file
18999e4fd900SJohn Levon	rm -rf $NIGHTLY_PARENT_ROOT/*
19009e4fd900SJohn Levon	unset Ulockfile
19019e4fd900SJohn Levon	mkdir -p $NIGHTLY_PARENT_ROOT
19029e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
19039e4fd900SJohn Levon		( cd $ROOT; tar cf - . |
19049e4fd900SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
19059e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
19069e4fd900SJohn Levon	fi
19079e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
19089e4fd900SJohn Levon		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
19099e4fd900SJohn Levon		mkdir -p $NIGHTLY_PARENT_ROOT-nd
19109e4fd900SJohn Levon		cd $ROOT-nd
19119e4fd900SJohn Levon		( tar cf - . |
19129e4fd900SJohn Levon		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
19139e4fd900SJohn Levon		    tee -a $mail_msg_file >> $LOGFILE
19149e4fd900SJohn Levon	fi
19159e4fd900SJohn Levon	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
19169e4fd900SJohn Levon		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
19179e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19189e4fd900SJohn Levon		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
19199e4fd900SJohn Levon		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
19209e4fd900SJohn Levon		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
19219e4fd900SJohn Levon			( cd $TOOLS_PROTO; tar cf - . |
19229e4fd900SJohn Levon			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
19239e4fd900SJohn Levon			    umask 0; tar xpf - ) ) 2>&1 |
19249e4fd900SJohn Levon			    tee -a $mail_msg_file >> $LOGFILE
19259e4fd900SJohn Levon		fi
19269e4fd900SJohn Levon	fi
19279e4fd900SJohn Levonfi
19289e4fd900SJohn Levon
19299e4fd900SJohn Levon#
19309e4fd900SJohn Levon# ELF verification: ABI (-A) and runtime (-r) checks
19319e4fd900SJohn Levon#
19329e4fd900SJohn Levonif [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
19339e4fd900SJohn Levon	# Directory ELF-data.$MACH holds the files produced by these tests.
19349e4fd900SJohn Levon	elf_ddir=$SRC/ELF-data.$MACH
19359e4fd900SJohn Levon
19369e4fd900SJohn Levon	# If there is a previous ELF-data backup directory, remove it. Then,
19379e4fd900SJohn Levon	# rotate current ELF-data directory into its place and create a new
19389e4fd900SJohn Levon	# empty directory
19399e4fd900SJohn Levon	rm -rf $elf_ddir.ref
19409e4fd900SJohn Levon	if [[ -d $elf_ddir ]]; then
19419e4fd900SJohn Levon		mv $elf_ddir $elf_ddir.ref
19429e4fd900SJohn Levon	fi
19439e4fd900SJohn Levon	mkdir -p $elf_ddir
19449e4fd900SJohn Levon
19459e4fd900SJohn Levon	# Call find_elf to produce a list of the ELF objects in the proto area.
19469e4fd900SJohn Levon	# This list is passed to check_rtime and interface_check, preventing
19479e4fd900SJohn Levon	# them from separately calling find_elf to do the same work twice.
19489e4fd900SJohn Levon	find_elf -fr $checkroot > $elf_ddir/object_list
19499e4fd900SJohn Levon
19509e4fd900SJohn Levon	if [[ $A_FLAG = y ]]; then
19519e4fd900SJohn Levon	       	echo "\n==== Check versioning and ABI information ====\n"  | \
19529e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19539e4fd900SJohn Levon
19549e4fd900SJohn Levon		# Produce interface description for the proto. Report errors.
19559e4fd900SJohn Levon		interface_check -o -w $elf_ddir -f object_list \
19569e4fd900SJohn Levon			-i interface -E interface.err
19579e4fd900SJohn Levon		if [[ -s $elf_ddir/interface.err ]]; then
19589e4fd900SJohn Levon			tee -a $LOGFILE < $elf_ddir/interface.err \
19599e4fd900SJohn Levon			    >> $mail_msg_file
19609e4fd900SJohn Levon			build_extras_ok=n
19619e4fd900SJohn Levon		fi
19629e4fd900SJohn Levon
19639e4fd900SJohn Levon		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
19649e4fd900SJohn Levon		# description file to that from the baseline gate. Issue a
19659e4fd900SJohn Levon		# warning if the baseline is not present, and keep going.
19669e4fd900SJohn Levon		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
19679e4fd900SJohn Levon			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
19689e4fd900SJohn Levon
19699e4fd900SJohn Levon		       	echo "\n==== Compare versioning and ABI information" \
19709e4fd900SJohn Levon			    "to baseline ====\n"  | \
19719e4fd900SJohn Levon			    tee -a $LOGFILE >> $mail_msg_file
19729e4fd900SJohn Levon		       	echo "Baseline:  $base_ifile\n" >> $LOGFILE
19739e4fd900SJohn Levon
19749e4fd900SJohn Levon			if [[ -f $base_ifile ]]; then
19759e4fd900SJohn Levon				interface_cmp -d -o $base_ifile \
19769e4fd900SJohn Levon				    $elf_ddir/interface > $elf_ddir/interface.cmp
19779e4fd900SJohn Levon				if [[ -s $elf_ddir/interface.cmp ]]; then
19789e4fd900SJohn Levon					echo | tee -a $LOGFILE >> $mail_msg_file
19799e4fd900SJohn Levon					tee -a $LOGFILE < \
19809e4fd900SJohn Levon					    $elf_ddir/interface.cmp \
19819e4fd900SJohn Levon					    >> $mail_msg_file
19829e4fd900SJohn Levon					build_extras_ok=n
19839e4fd900SJohn Levon				fi
19849e4fd900SJohn Levon			else
19859e4fd900SJohn Levon			       	echo "baseline not available. comparison" \
19869e4fd900SJohn Levon                                    "skipped" | \
19879e4fd900SJohn Levon				    tee -a $LOGFILE >> $mail_msg_file
19889e4fd900SJohn Levon			fi
19899e4fd900SJohn Levon
19909e4fd900SJohn Levon		fi
19919e4fd900SJohn Levon	fi
19929e4fd900SJohn Levon
19939e4fd900SJohn Levon	if [[ $r_FLAG = y ]]; then
19949e4fd900SJohn Levon		echo "\n==== Check ELF runtime attributes ====\n" | \
19959e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file
19969e4fd900SJohn Levon
19979e4fd900SJohn Levon		# If we're doing a DEBUG build the proto area will be left
19989e4fd900SJohn Levon		# with debuggable objects, thus don't assert -s.
19999e4fd900SJohn Levon		if [[ $D_FLAG = y ]]; then
20009e4fd900SJohn Levon			rtime_sflag=""
20019e4fd900SJohn Levon		else
20029e4fd900SJohn Levon			rtime_sflag="-s"
20039e4fd900SJohn Levon		fi
20049e4fd900SJohn Levon		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
20059e4fd900SJohn Levon			-D object_list  -f object_list -E runtime.err \
20069e4fd900SJohn Levon			-I runtime.attr.raw
20079e4fd900SJohn Levon		if (( $? != 0 )); then
20089e4fd900SJohn Levon			build_extras_ok=n
20099e4fd900SJohn Levon		fi
20109e4fd900SJohn Levon
20119e4fd900SJohn Levon		# check_rtime -I output needs to be sorted in order to
20129e4fd900SJohn Levon		# compare it to that from previous builds.
20139e4fd900SJohn Levon		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
20149e4fd900SJohn Levon		rm $elf_ddir/runtime.attr.raw
20159e4fd900SJohn Levon
20169e4fd900SJohn Levon		# Report errors
20179e4fd900SJohn Levon		if [[ -s $elf_ddir/runtime.err ]]; then
20189e4fd900SJohn Levon			tee -a $LOGFILE < $elf_ddir/runtime.err \
20199e4fd900SJohn Levon				>> $mail_msg_file
20209e4fd900SJohn Levon			build_extras_ok=n
20219e4fd900SJohn Levon		fi
20229e4fd900SJohn Levon
20239e4fd900SJohn Levon		# If there is an ELF-data directory from a previous build,
20249e4fd900SJohn Levon		# then diff the attr files. These files contain information
20259e4fd900SJohn Levon		# about dependencies, versioning, and runpaths. There is some
20269e4fd900SJohn Levon		# overlap with the ABI checking done above, but this also
20279e4fd900SJohn Levon		# flushes out non-ABI interface differences along with the
20289e4fd900SJohn Levon		# other information.
20299e4fd900SJohn Levon		echo "\n==== Diff ELF runtime attributes" \
20309e4fd900SJohn Levon		    "(since last build) ====\n" | \
20319e4fd900SJohn Levon		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
20329e4fd900SJohn Levon
20339e4fd900SJohn Levon		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
20349e4fd900SJohn Levon			diff $elf_ddir.ref/runtime.attr \
20359e4fd900SJohn Levon				$elf_ddir/runtime.attr \
20369e4fd900SJohn Levon				>> $mail_msg_file
20379e4fd900SJohn Levon		fi
20389e4fd900SJohn Levon	fi
20399e4fd900SJohn Levon
20409e4fd900SJohn Levon	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
20419e4fd900SJohn Levon	if [[ "$u_FLAG" = "y" ]]; then
20429e4fd900SJohn Levon		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
20439e4fd900SJohn Levon
20449e4fd900SJohn Levon		# If parent lacks the ELF-data.$MACH directory, create it
20459e4fd900SJohn Levon		if [[ ! -d $p_elf_ddir ]]; then
20469e4fd900SJohn Levon			staffer mkdir -p $p_elf_ddir
20479e4fd900SJohn Levon		fi
20489e4fd900SJohn Levon
20499e4fd900SJohn Levon		# These files are used asynchronously by other builds for ABI
20509e4fd900SJohn Levon		# verification, as above for the -A option. As such, we require
20519e4fd900SJohn Levon		# the file replacement to be atomic. Copy the data to a temp
20529e4fd900SJohn Levon		# file in the same filesystem and then rename into place.
20539e4fd900SJohn Levon		(
20549e4fd900SJohn Levon			cd $elf_ddir
20559e4fd900SJohn Levon			for elf_dfile in *; do
20569e4fd900SJohn Levon				staffer cp $elf_dfile \
20579e4fd900SJohn Levon				    ${p_elf_ddir}/${elf_dfile}.new
20589e4fd900SJohn Levon				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
20599e4fd900SJohn Levon				    ${p_elf_ddir}/${elf_dfile}
20609e4fd900SJohn Levon			done
20619e4fd900SJohn Levon		)
20629e4fd900SJohn Levon	fi
20639e4fd900SJohn Levonfi
20649e4fd900SJohn Levon
20659e4fd900SJohn Levon# DEBUG lint of kernel begins
20669e4fd900SJohn Levon
20679e4fd900SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
20689e4fd900SJohn Levon	if [ "$LINTDIRS" = "" ]; then
20699e4fd900SJohn Levon		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
20709e4fd900SJohn Levon		LINTDIRS="$SRC y"
20719e4fd900SJohn Levon	fi
20729e4fd900SJohn Levon	set $LINTDIRS
20739e4fd900SJohn Levon	while [ $# -gt 0 ]; do
20749e4fd900SJohn Levon		dolint $1 $2; shift; shift
20759e4fd900SJohn Levon	done
20769e4fd900SJohn Levonelse
20779e4fd900SJohn Levon	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
20789e4fd900SJohn Levonfi
20799e4fd900SJohn Levon
20809e4fd900SJohn Levon# "make check" begins
20819e4fd900SJohn Levon
20829e4fd900SJohn Levonif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
20839e4fd900SJohn Levon	# remove old check.out
20849e4fd900SJohn Levon	rm -f $SRC/check.out
20859e4fd900SJohn Levon
20869e4fd900SJohn Levon	rm -f $SRC/check-${MACH}.out
20879e4fd900SJohn Levon	cd $SRC
20889e4fd900SJohn Levon	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
20899e4fd900SJohn Levon	    >> $LOGFILE
20909e4fd900SJohn Levon	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
20919e4fd900SJohn Levon
20929e4fd900SJohn Levon	grep ":" $SRC/check-${MACH}.out |
20939e4fd900SJohn Levon		egrep -v "Ignoring unknown host" | \
20949e4fd900SJohn Levon		sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
20959e4fd900SJohn Levon
20969e4fd900SJohn Levon	if [[ -s $TMPDIR/check_errors ]]; then
20979e4fd900SJohn Levon		build_extras_ok=n
20989e4fd900SJohn Levon	fi
20999e4fd900SJohn Levonelse
21009e4fd900SJohn Levon	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
21019e4fd900SJohn Levonfi
21029e4fd900SJohn Levon
21039e4fd900SJohn Levonecho "\n==== Find core files ====\n" | \
21049e4fd900SJohn Levon    tee -a $LOGFILE >> $mail_msg_file
21059e4fd900SJohn Levon
21069e4fd900SJohn Levonfind $abssrcdirs -name core -a -type f -exec file {} \; | \
21079e4fd900SJohn Levon	tee -a $LOGFILE >> $mail_msg_file
21089e4fd900SJohn Levon
21099e4fd900SJohn Levonif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
21109e4fd900SJohn Levon	echo "\n==== Diff unreferenced files (since last build) ====\n" \
21119e4fd900SJohn Levon	    | tee -a $LOGFILE >>$mail_msg_file
21129e4fd900SJohn Levon	rm -f $SRC/unref-${MACH}.ref
21139e4fd900SJohn Levon	if [ -f $SRC/unref-${MACH}.out ]; then
21149e4fd900SJohn Levon		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21159e4fd900SJohn Levon	fi
21169e4fd900SJohn Levon
21179e4fd900SJohn Levon	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
21189e4fd900SJohn Levon	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
21199e4fd900SJohn Levon	    sort > $SRC/unref-${MACH}.out
21209e4fd900SJohn Levon
21219e4fd900SJohn Levon	if [ ! -f $SRC/unref-${MACH}.ref ]; then
21229e4fd900SJohn Levon		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21239e4fd900SJohn Levon	fi
21249e4fd900SJohn Levon
21259e4fd900SJohn Levon	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
21269e4fd900SJohn Levonfi
21279e4fd900SJohn Levon
21289e4fd900SJohn Levon# Verify that the usual lists of files, such as exception lists,
21299e4fd900SJohn Levon# contain only valid references to files.  If the build has failed,
21309e4fd900SJohn Levon# then don't check the proto area.
21319e4fd900SJohn LevonCHECK_PATHS=${CHECK_PATHS:-y}
21329e4fd900SJohn Levonif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
21339e4fd900SJohn Levon	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
21349e4fd900SJohn Levon		>>$mail_msg_file
21359e4fd900SJohn Levon	arg=-b
21369e4fd900SJohn Levon	[ "$build_ok" = y ] && arg=
21379e4fd900SJohn Levon	checkpaths $arg $checkroot > $SRC/check-paths.out 2>&1
21389e4fd900SJohn Levon	if [[ -s $SRC/check-paths.out ]]; then
21399e4fd900SJohn Levon		tee -a $LOGFILE < $SRC/check-paths.out >> $mail_msg_file
21409e4fd900SJohn Levon		build_extras_ok=n
21419e4fd900SJohn Levon	fi
21429e4fd900SJohn Levonfi
21439e4fd900SJohn Levon
21449e4fd900SJohn Levonabspkg=
21459e4fd900SJohn Levonfor d in $abssrcdirs; do
21469e4fd900SJohn Levon	if [ -d "$d/pkg" ]; then
21479e4fd900SJohn Levon		abspkg="$abspkg $d"
21489e4fd900SJohn Levon	fi
21499e4fd900SJohn Levondone
21509e4fd900SJohn Levon
2151b85ab92fSAndy Fiddamanif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
2152b85ab92fSAndy Fiddaman	echo "\n==== Impact on file permissions ====\n" \
2153b85ab92fSAndy Fiddaman		>> $mail_msg_file
2154b85ab92fSAndy Fiddaman
21559e4fd900SJohn Levon	if [ -n "$abspkg" ]; then
21569e4fd900SJohn Levon		for d in "$abspkg"; do
21579e4fd900SJohn Levon			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
21589e4fd900SJohn Levon		done
21599e4fd900SJohn Levon	fi
21609e4fd900SJohn Levonfi
21619e4fd900SJohn Levon
2162b85ab92fSAndy Fiddamanif [ "$L_FLAG" != "y" -a "$build_ok" = y ]; then
2163b85ab92fSAndy Fiddaman	echo "\n==== Linting packages ====\n" | \
2164b85ab92fSAndy Fiddaman	    tee -a $LOGFILE >> $mail_msg_file
2165b85ab92fSAndy Fiddaman
2166b85ab92fSAndy Fiddaman	if [ -n "$abspkg" ]; then
2167b85ab92fSAndy Fiddaman		for d in "$abspkg"; do
2168b85ab92fSAndy Fiddaman			( cd $d/pkg ; $MAKE -e pkglint ) | \
2169b85ab92fSAndy Fiddaman			    tee -a $LOGFILE | \
2170b85ab92fSAndy Fiddaman			    egrep -v 'Lint engine setup|Starting lint run'
2171b85ab92fSAndy Fiddaman		done 2>&1 | tee $TMPDIR/pkglint_noise >> $mail_msg_file
2172b85ab92fSAndy Fiddaman		if [[ -s $TMPDIR/pkglint_noise ]]; then
2173b85ab92fSAndy Fiddaman			build_extras_ok=n
2174b85ab92fSAndy Fiddaman		fi
2175b85ab92fSAndy Fiddaman	fi
2176b85ab92fSAndy Fiddamanfi
2177b85ab92fSAndy Fiddaman
21789e4fd900SJohn Levonif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
21799e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
2180bf16a978SMarcel Telka		do_wsdiff DEBUG $ROOT.prev $ROOT wsdiff.results
21819e4fd900SJohn Levon	fi
21829e4fd900SJohn Levon
21839e4fd900SJohn Levon	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
2184bf16a978SMarcel Telka		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd wsdiff-nd.results
2185bf16a978SMarcel Telka	fi
2186bf16a978SMarcel Telka
2187bf16a978SMarcel Telka	if [[ "$t_FLAG" == "y" ]]; then
2188bf16a978SMarcel Telka		do_wsdiff tools $TOOLS_PROTO.prev $TOOLS_PROTO wsdiff-tools.results
21899e4fd900SJohn Levon	fi
21909e4fd900SJohn Levonfi
21919e4fd900SJohn Levon
21929e4fd900SJohn LevonEND_DATE=`date`
21939e4fd900SJohn Levonecho "==== Nightly $maketype build completed: $END_DATE ====" | \
21949e4fd900SJohn Levon    tee -a $LOGFILE >> $build_time_file
21959e4fd900SJohn Levon
21969e4fd900SJohn Levontypeset -i10 hours
21979e4fd900SJohn Levontypeset -Z2 minutes
21989e4fd900SJohn Levontypeset -Z2 seconds
21999e4fd900SJohn Levon
22009e4fd900SJohn Levonelapsed_time=$SECONDS
22019e4fd900SJohn Levon((hours = elapsed_time / 3600 ))
22029e4fd900SJohn Levon((minutes = elapsed_time / 60  % 60))
22039e4fd900SJohn Levon((seconds = elapsed_time % 60))
22049e4fd900SJohn Levon
22059e4fd900SJohn Levonecho "\n==== Total build time ====" | \
22069e4fd900SJohn Levon    tee -a $LOGFILE >> $build_time_file
22079e4fd900SJohn Levonecho "\nreal    ${hours}:${minutes}:${seconds}" | \
22089e4fd900SJohn Levon    tee -a $LOGFILE >> $build_time_file
22099e4fd900SJohn Levon
22109e4fd900SJohn Levonif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
22119e4fd900SJohn Levon	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
22129e4fd900SJohn Levon
22139e4fd900SJohn Levon	#
22149e4fd900SJohn Levon	# Produce a master list of unreferenced files -- ideally, we'd
22159e4fd900SJohn Levon	# generate the master just once after all of the nightlies
22169e4fd900SJohn Levon	# have finished, but there's no simple way to know when that
22179e4fd900SJohn Levon	# will be.  Instead, we assume that we're the last nightly to
22189e4fd900SJohn Levon	# finish and merge all of the unref-${MACH}.out files in
22199e4fd900SJohn Levon	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
22209e4fd900SJohn Levon	# finish, then this file will be the authoritative master
22219e4fd900SJohn Levon	# list.  Otherwise, another ${MACH}'s nightly will eventually
22229e4fd900SJohn Levon	# overwrite ours with its own master, but in the meantime our
22239e4fd900SJohn Levon	# temporary "master" will be no worse than any older master
22249e4fd900SJohn Levon	# which was already on the parent.
22259e4fd900SJohn Levon	#
22269e4fd900SJohn Levon
22279e4fd900SJohn Levon	set -- $PARENT_WS/usr/src/unref-*.out
22289e4fd900SJohn Levon	cp "$1" ${TMPDIR}/unref.merge
22299e4fd900SJohn Levon	shift
22309e4fd900SJohn Levon
22319e4fd900SJohn Levon	for unreffile; do
22329e4fd900SJohn Levon		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
22339e4fd900SJohn Levon		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
22349e4fd900SJohn Levon	done
22359e4fd900SJohn Levon
22369e4fd900SJohn Levon	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
22379e4fd900SJohn Levonfi
22389e4fd900SJohn Levon
22399e4fd900SJohn Levon#
22409e4fd900SJohn Levon# All done save for the sweeping up.
22419e4fd900SJohn Levon# (whichever exit we hit here will trigger the "cleanup" trap which
22429e4fd900SJohn Levon# optionally sends mail on completion).
22439e4fd900SJohn Levon#
22449e4fd900SJohn Levonif [[ "$build_ok" == "y" ]]; then
22459e4fd900SJohn Levon	if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
22469e4fd900SJohn Levon		exit 0
22479e4fd900SJohn Levon	fi
22489e4fd900SJohn Levonfi
22499e4fd900SJohn Levon
22509e4fd900SJohn Levonexit 1
2251