xref: /titanic_51/usr/src/tools/scripts/nightly.sh (revision cb4d1691226e6583657e84c8ca7e3835499528a0)
17c478bd9Sstevel@tonic-gate#!/bin/ksh -p
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6fb23a357Skupfer# Common Development and Distribution License (the "License").
7fb23a357Skupfer# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
224e5b757fSkupfer
237c478bd9Sstevel@tonic-gate#
24b83ec4edSjmcp# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25445b6314SRichard Lowe# Copyright 2008, 2010, Richard Lowe
26d7693b08SRoland Mainz# Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
273cb00cf1SJoshua M. Clulow# Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate# Based on the nightly script from the integration folks,
307c478bd9Sstevel@tonic-gate# Mostly modified and owned by mike_s.
317c478bd9Sstevel@tonic-gate# Changes also by kjc, dmk.
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gate# BRINGOVER_WS may be specified in the env file.
347c478bd9Sstevel@tonic-gate# The default is the old behavior of CLONE_WS
357c478bd9Sstevel@tonic-gate#
367c478bd9Sstevel@tonic-gate# -i on the command line, means fast options, so when it's on the
37d77e7149Ssommerfe# command line (only), lint and check builds are skipped no matter what
38d77e7149Ssommerfe# the setting of their individual flags are in NIGHTLY_OPTIONS.
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate# LINTDIRS can be set in the env file, format is a list of:
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate#	/dirname-to-run-lint-on flag
437c478bd9Sstevel@tonic-gate#
447c478bd9Sstevel@tonic-gate#	Where flag is:	y - enable lint noise diff output
457c478bd9Sstevel@tonic-gate#			n - disable lint noise diff output
467c478bd9Sstevel@tonic-gate#
477c478bd9Sstevel@tonic-gate#	For example: LINTDIRS="$SRC/uts n $SRC/stand y $SRC/psm y"
487c478bd9Sstevel@tonic-gate#
49c3e6cb59SRichard Lowe# OPTHOME  may be set in the environment to override /opt
507c478bd9Sstevel@tonic-gate#
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate#
537c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
547c478bd9Sstevel@tonic-gate# under certain circumstances, which can really screw things up; unset it.
557c478bd9Sstevel@tonic-gate#
567c478bd9Sstevel@tonic-gateunset CDPATH
577c478bd9Sstevel@tonic-gate
58cdf0c1d5Smjnelson# Get the absolute path of the nightly script that the user invoked.  This
59cdf0c1d5Smjnelson# may be a relative path, and we need to do this before changing directory.
60cdf0c1d5Smjnelsonnightly_path=`whence $0`
61cdf0c1d5Smjnelson
62cdf0c1d5Smjnelson#
63cdf0c1d5Smjnelson# Keep track of where we found nightly so we can invoke the matching
64cdf0c1d5Smjnelson# which_scm script.  If that doesn't work, don't go guessing, just rely
65cdf0c1d5Smjnelson# on the $PATH settings, which will generally give us either /opt/onbld
66cdf0c1d5Smjnelson# or the user's workspace.
67cdf0c1d5Smjnelson#
68cdf0c1d5SmjnelsonWHICH_SCM=$(dirname $nightly_path)/which_scm
69cdf0c1d5Smjnelsonif [[ ! -x $WHICH_SCM ]]; then
70cdf0c1d5Smjnelson	WHICH_SCM=which_scm
71cdf0c1d5Smjnelsonfi
72cdf0c1d5Smjnelson
73d7693b08SRoland Mainzfunction fatal_error
74d7693b08SRoland Mainz{
75d7693b08SRoland Mainz	print -u2 "nightly: $*"
76d7693b08SRoland Mainz	exit 1
77d7693b08SRoland Mainz}
78d7693b08SRoland Mainz
794e5b757fSkupfer#
804e5b757fSkupfer# Function to do a DEBUG and non-DEBUG build. Needed because we might
817c478bd9Sstevel@tonic-gate# need to do another for the source build, and since we only deliver DEBUG or
827c478bd9Sstevel@tonic-gate# non-DEBUG packages.
834e5b757fSkupfer#
84b83ec4edSjmcp# usage: normal_build
85ead1f93eSLiane Praza#
86597bd30bSMike Kupferfunction normal_build {
877c478bd9Sstevel@tonic-gate
8852a52aebSkupfer	typeset orig_p_FLAG="$p_FLAG"
89597bd30bSMike Kupfer	typeset crypto_signer="$CODESIGN_USER"
904e5b757fSkupfer
914e5b757fSkupfer	suffix=""
92ead1f93eSLiane Praza
937c478bd9Sstevel@tonic-gate	# non-DEBUG build begins
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate	if [ "$F_FLAG" = "n" ]; then
964e5b757fSkupfer		set_non_debug_build_flags
97597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
986ea3c060SGarrett D'Amore		    build "non-DEBUG" "$suffix-nd" "-nd" "$MULTI_PROTO"
997c478bd9Sstevel@tonic-gate	else
10052a52aebSkupfer		echo "\n==== No non-DEBUG $open_only build ====\n" >> "$LOGFILE"
1017c478bd9Sstevel@tonic-gate	fi
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate	# non-DEBUG build ends
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate	# DEBUG build begins
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate	if [ "$D_FLAG" = "y" ]; then
1084e5b757fSkupfer		set_debug_build_flags
109597bd30bSMike Kupfer		CODESIGN_USER="$crypto_signer" \
1106ea3c060SGarrett D'Amore		    build "DEBUG" "$suffix" "" "$MULTI_PROTO"
1117c478bd9Sstevel@tonic-gate	else
11252a52aebSkupfer		echo "\n==== No DEBUG $open_only build ====\n" >> "$LOGFILE"
1137c478bd9Sstevel@tonic-gate	fi
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate	# DEBUG build ends
1164e5b757fSkupfer
11752a52aebSkupfer	p_FLAG="$orig_p_FLAG"
1187c478bd9Sstevel@tonic-gate}
1197c478bd9Sstevel@tonic-gate
1201fe69678Skupfer#
12147703246Ssommerfe# usage: run_hook HOOKNAME ARGS...
12247703246Ssommerfe#
12347703246Ssommerfe# If variable "$HOOKNAME" is defined, insert a section header into
12447703246Ssommerfe# our logs and then run the command with ARGS
12547703246Ssommerfe#
126597bd30bSMike Kupferfunction run_hook {
12747703246Ssommerfe	HOOKNAME=$1
12847703246Ssommerfe    	eval HOOKCMD=\$$HOOKNAME
12947703246Ssommerfe	shift
13047703246Ssommerfe
13147703246Ssommerfe	if [ -n "$HOOKCMD" ]; then
13247703246Ssommerfe	    	(
13347703246Ssommerfe			echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
13447703246Ssommerfe		    	( $HOOKCMD "$@" 2>&1 )
13547703246Ssommerfe			if [ "$?" -ne 0 ]; then
13647703246Ssommerfe			    	# Let exit status propagate up
13747703246Ssommerfe			    	touch $TMPDIR/abort
13847703246Ssommerfe			fi
13947703246Ssommerfe		) | tee -a $mail_msg_file >> $LOGFILE
14047703246Ssommerfe
14147703246Ssommerfe		if [ -f $TMPDIR/abort ]; then
14247703246Ssommerfe			build_ok=n
14347703246Ssommerfe			echo "\nAborting at request of $HOOKNAME" |
14447703246Ssommerfe				tee -a $mail_msg_file >> $LOGFILE
14547703246Ssommerfe			exit 1
14647703246Ssommerfe		fi
14747703246Ssommerfe	fi
14847703246Ssommerfe}
14947703246Ssommerfe
1504e5b757fSkupfer# Return library search directive as function of given root.
151597bd30bSMike Kupferfunction myldlibs {
1524e5b757fSkupfer	echo "-L$1/lib -L$1/usr/lib"
1534e5b757fSkupfer}
1547c478bd9Sstevel@tonic-gate
1554e5b757fSkupfer# Return header search directive as function of given root.
156597bd30bSMike Kupferfunction myheaders {
1574e5b757fSkupfer	echo "-I$1/usr/include"
1584e5b757fSkupfer}
1594e5b757fSkupfer
1604e5b757fSkupfer#
16178add226Sjmcp# Function to do the build, including package generation.
1626ea3c060SGarrett D'Amore# usage: build LABEL SUFFIX ND MULTIPROTO
1634e5b757fSkupfer# - LABEL is used to tag build output.
164ead1f93eSLiane Praza# - SUFFIX is used to distinguish files (e.g., DEBUG vs non-DEBUG,
165597bd30bSMike Kupfer#   open-only vs full tree).
166ead1f93eSLiane Praza# - ND is "-nd" (non-DEBUG builds) or "" (DEBUG builds).
1674e5b757fSkupfer# - If MULTIPROTO is "yes", it means to name the proto area according to
1684e5b757fSkupfer#   SUFFIX.  Otherwise ("no"), (re)use the standard proto area.
1694e5b757fSkupfer#
170597bd30bSMike Kupferfunction build {
1717c478bd9Sstevel@tonic-gate	LABEL=$1
1727c478bd9Sstevel@tonic-gate	SUFFIX=$2
173597bd30bSMike Kupfer	ND=$3
174597bd30bSMike Kupfer	MULTIPROTO=$4
1757c478bd9Sstevel@tonic-gate	INSTALLOG=install${SUFFIX}-${MACH}
1767c478bd9Sstevel@tonic-gate	NOISE=noise${SUFFIX}-${MACH}
1777c478bd9Sstevel@tonic-gate	PKGARCHIVE=${PKGARCHIVE_ORIG}${SUFFIX}
1787c478bd9Sstevel@tonic-gate
1794e5b757fSkupfer	ORIGROOT=$ROOT
1804e5b757fSkupfer	[ $MULTIPROTO = no ] || export ROOT=$ROOT$SUFFIX
1814e5b757fSkupfer
1824e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
1834e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
1844e5b757fSkupfer
1857c478bd9Sstevel@tonic-gate	this_build_ok=y
1867c478bd9Sstevel@tonic-gate	#
1877c478bd9Sstevel@tonic-gate	#	Build OS-Networking source
1887c478bd9Sstevel@tonic-gate	#
1897c478bd9Sstevel@tonic-gate	echo "\n==== Building OS-Net source at `date` ($LABEL) ====\n" \
1907c478bd9Sstevel@tonic-gate		>> $LOGFILE
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate	rm -f $SRC/${INSTALLOG}.out
1937c478bd9Sstevel@tonic-gate	cd $SRC
1947c478bd9Sstevel@tonic-gate	/bin/time $MAKE -e install 2>&1 | \
1957c478bd9Sstevel@tonic-gate	    tee -a $SRC/${INSTALLOG}.out >> $LOGFILE
19632f1e47bSsommerfe
1977c478bd9Sstevel@tonic-gate	echo "\n==== Build errors ($LABEL) ====\n" >> $mail_msg_file
1987c478bd9Sstevel@tonic-gate	egrep ":" $SRC/${INSTALLOG}.out |
1997c478bd9Sstevel@tonic-gate		egrep -e "(^${MAKE}:|[ 	]error[: 	\n])" | \
2007c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
2017c478bd9Sstevel@tonic-gate		egrep -v "cc .* -o error " | \
202*cb4d1691SRichard Lowe		egrep -v "warning" | tee $TMPDIR/build_errs${SUFFIX} \
203*cb4d1691SRichard Lowe		>> $mail_msg_file
204*cb4d1691SRichard Lowe	if [[ -s $TMPDIR/build_errs${SUFFIX} ]]; then
2057c478bd9Sstevel@tonic-gate		build_ok=n
2067c478bd9Sstevel@tonic-gate		this_build_ok=n
2077c478bd9Sstevel@tonic-gate	fi
2087c478bd9Sstevel@tonic-gate	grep "bootblock image is .* bytes too big" $SRC/${INSTALLOG}.out \
2097c478bd9Sstevel@tonic-gate		>> $mail_msg_file
2107c478bd9Sstevel@tonic-gate	if [ "$?" = "0" ]; then
2117c478bd9Sstevel@tonic-gate		build_ok=n
2127c478bd9Sstevel@tonic-gate		this_build_ok=n
2137c478bd9Sstevel@tonic-gate	fi
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate	echo "\n==== Build warnings ($LABEL) ====\n" >>$mail_msg_file
2167c478bd9Sstevel@tonic-gate	egrep -i warning: $SRC/${INSTALLOG}.out \
2177c478bd9Sstevel@tonic-gate		| egrep -v '^tic:' \
21820272c2eSAli Bahrami		| egrep -v "symbol (\`|')timezone' has differing types:" \
2197c478bd9Sstevel@tonic-gate		| egrep -v "parameter <PSTAMP> set to" \
2207c478bd9Sstevel@tonic-gate		| egrep -v "Ignoring unknown host" \
2217c478bd9Sstevel@tonic-gate		| egrep -v "redefining segment flags attribute for" \
222*cb4d1691SRichard Lowe		| tee $TMPDIR/build_warnings${SUFFIX} >> $mail_msg_file
223*cb4d1691SRichard Lowe	if [[ -s $TMPDIR/build_warnings${SUFFIX} ]]; then
224*cb4d1691SRichard Lowe		build_ok=n
225*cb4d1691SRichard Lowe		this_build_ok=n
226*cb4d1691SRichard Lowe	fi
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate	echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n" \
2297c478bd9Sstevel@tonic-gate		>> $LOGFILE
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed build time ($LABEL) ====\n" >>$mail_msg_file
2327c478bd9Sstevel@tonic-gate	tail -3  $SRC/${INSTALLOG}.out >>$mail_msg_file
2337c478bd9Sstevel@tonic-gate
234c3e6cb59SRichard Lowe	if [ "$i_FLAG" = "n" ]; then
2357c478bd9Sstevel@tonic-gate		rm -f $SRC/${NOISE}.ref
2367c478bd9Sstevel@tonic-gate		if [ -f $SRC/${NOISE}.out ]; then
2377c478bd9Sstevel@tonic-gate			mv $SRC/${NOISE}.out $SRC/${NOISE}.ref
2387c478bd9Sstevel@tonic-gate		fi
2397c478bd9Sstevel@tonic-gate		grep : $SRC/${INSTALLOG}.out \
2407c478bd9Sstevel@tonic-gate			| egrep -v '^/' \
2417c478bd9Sstevel@tonic-gate			| egrep -v '^(Start|Finish|real|user|sys|./bld_awk)' \
2427c478bd9Sstevel@tonic-gate			| egrep -v '^tic:' \
2437c478bd9Sstevel@tonic-gate			| egrep -v '^mcs' \
2447c478bd9Sstevel@tonic-gate			| egrep -v '^LD_LIBRARY_PATH=' \
2457c478bd9Sstevel@tonic-gate			| egrep -v 'ar: creating' \
2467c478bd9Sstevel@tonic-gate			| egrep -v 'ar: writing' \
2477c478bd9Sstevel@tonic-gate			| egrep -v 'conflicts:' \
2487c478bd9Sstevel@tonic-gate			| egrep -v ':saved created' \
2497c478bd9Sstevel@tonic-gate			| egrep -v '^stty.*c:' \
2507c478bd9Sstevel@tonic-gate			| egrep -v '^mfgname.c:' \
2517c478bd9Sstevel@tonic-gate			| egrep -v '^uname-i.c:' \
2527c478bd9Sstevel@tonic-gate			| egrep -v '^volumes.c:' \
2537c478bd9Sstevel@tonic-gate			| egrep -v '^lint library construction:' \
2547c478bd9Sstevel@tonic-gate			| egrep -v 'tsort: INFORM:' \
2557c478bd9Sstevel@tonic-gate			| egrep -v 'stripalign:' \
2567c478bd9Sstevel@tonic-gate			| egrep -v 'chars, width' \
25720272c2eSAli Bahrami			| egrep -v "symbol (\`|')timezone' has differing types:" \
2587c478bd9Sstevel@tonic-gate			| egrep -v 'PSTAMP' \
2597c478bd9Sstevel@tonic-gate			| egrep -v '|%WHOANDWHERE%|' \
2607c478bd9Sstevel@tonic-gate			| egrep -v '^Manifying' \
2617c478bd9Sstevel@tonic-gate			| egrep -v 'Ignoring unknown host' \
2627c478bd9Sstevel@tonic-gate			| egrep -v 'Processing method:' \
2637c478bd9Sstevel@tonic-gate			| egrep -v '^Writing' \
2647c478bd9Sstevel@tonic-gate			| egrep -v 'spellin1:' \
2657c478bd9Sstevel@tonic-gate			| egrep -v '^adding:' \
2667c478bd9Sstevel@tonic-gate			| egrep -v "^echo 'msgid" \
2677c478bd9Sstevel@tonic-gate			| egrep -v '^echo ' \
2687c478bd9Sstevel@tonic-gate			| egrep -v '\.c:$' \
2697c478bd9Sstevel@tonic-gate			| egrep -v '^Adding file:' \
2707c478bd9Sstevel@tonic-gate			| egrep -v 'CLASSPATH=' \
2717c478bd9Sstevel@tonic-gate			| egrep -v '\/var\/mail\/:saved' \
2727c478bd9Sstevel@tonic-gate			| egrep -v -- '-DUTS_VERSION=' \
2737c478bd9Sstevel@tonic-gate			| egrep -v '^Running Mkbootstrap' \
2747c478bd9Sstevel@tonic-gate			| egrep -v '^Applet length read:' \
2757c478bd9Sstevel@tonic-gate			| egrep -v 'bytes written:' \
2767c478bd9Sstevel@tonic-gate			| egrep -v '^File:SolarisAuthApplet.bin' \
2777c478bd9Sstevel@tonic-gate			| egrep -v -i 'jibversion' \
2787c478bd9Sstevel@tonic-gate			| egrep -v '^Output size:' \
2797c478bd9Sstevel@tonic-gate			| egrep -v '^Solo size statistics:' \
2807c478bd9Sstevel@tonic-gate			| egrep -v '^Using ROM API Version' \
2817c478bd9Sstevel@tonic-gate			| egrep -v '^Zero Signature length:' \
2827c478bd9Sstevel@tonic-gate			| egrep -v '^Note \(probably harmless\):' \
2837c478bd9Sstevel@tonic-gate			| egrep -v '::' \
2847c478bd9Sstevel@tonic-gate			| egrep -v -- '-xcache' \
285010b217aSwesolows			| egrep -v '^\+' \
28603eb5f54Swesolows			| egrep -v '^cc1: note: -fwritable-strings' \
287c817a439Sjohnz			| egrep -v 'svccfg-native -s svc:/' \
2887c478bd9Sstevel@tonic-gate			| sort | uniq >$SRC/${NOISE}.out
2897c478bd9Sstevel@tonic-gate		if [ ! -f $SRC/${NOISE}.ref ]; then
2907c478bd9Sstevel@tonic-gate			cp $SRC/${NOISE}.out $SRC/${NOISE}.ref
2917c478bd9Sstevel@tonic-gate		fi
2927c478bd9Sstevel@tonic-gate		echo "\n==== Build noise differences ($LABEL) ====\n" \
2937c478bd9Sstevel@tonic-gate			>>$mail_msg_file
2947c478bd9Sstevel@tonic-gate		diff $SRC/${NOISE}.ref $SRC/${NOISE}.out >>$mail_msg_file
2957c478bd9Sstevel@tonic-gate	fi
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate	#
29823259b79Srotondo	#	Re-sign selected binaries using signing server
29923259b79Srotondo	#	(gatekeeper builds only)
30023259b79Srotondo	#
3012210853dSjohnz	if [ -n "$CODESIGN_USER" -a "$this_build_ok" = "y" ]; then
30223259b79Srotondo		echo "\n==== Signing proto area at `date` ====\n" >> $LOGFILE
30323259b79Srotondo		signing_file="${TMPDIR}/signing"
30423259b79Srotondo		rm -f ${signing_file}
30523259b79Srotondo		export CODESIGN_USER
30623259b79Srotondo		signproto $SRC/tools/codesign/creds 2>&1 | \
30723259b79Srotondo			tee -a ${signing_file} >> $LOGFILE
30823259b79Srotondo		echo "\n==== Finished signing proto area at `date` ====\n" \
30923259b79Srotondo		    >> $LOGFILE
31023259b79Srotondo		echo "\n==== Crypto module signing errors ($LABEL) ====\n" \
31123259b79Srotondo		    >> $mail_msg_file
31223259b79Srotondo		egrep 'WARNING|ERROR' ${signing_file} >> $mail_msg_file
313cdf0c1d5Smjnelson		if (( $? == 0 )) ; then
3142210853dSjohnz			build_ok=n
3152210853dSjohnz			this_build_ok=n
3162210853dSjohnz		fi
31723259b79Srotondo	fi
31823259b79Srotondo
31923259b79Srotondo	#
3207c478bd9Sstevel@tonic-gate	#	Building Packages
3217c478bd9Sstevel@tonic-gate	#
3227c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" -a "$this_build_ok" = "y" ]; then
323c3e6cb59SRichard Lowe		if [ -d $SRC/pkg ]; then
3247c478bd9Sstevel@tonic-gate			echo "\n==== Creating $LABEL packages at `date` ====\n" \
3257c478bd9Sstevel@tonic-gate				>> $LOGFILE
326ead1f93eSLiane Praza			echo "Clearing out $PKGARCHIVE ..." >> $LOGFILE
3276798c3f0SMark J. Nelson			rm -rf $PKGARCHIVE >> "$LOGFILE" 2>&1
3286798c3f0SMark J. Nelson			mkdir -p $PKGARCHIVE >> "$LOGFILE" 2>&1
329d8fd4470Sjg
330c3e6cb59SRichard Lowe			rm -f $SRC/pkg/${INSTALLOG}.out
331c3e6cb59SRichard Lowe			cd $SRC/pkg
332ead1f93eSLiane Praza			/bin/time $MAKE -e install 2>&1 | \
333c3e6cb59SRichard Lowe			    tee -a $SRC/pkg/${INSTALLOG}.out >> $LOGFILE
334ead1f93eSLiane Praza
335ead1f93eSLiane Praza			echo "\n==== package build errors ($LABEL) ====\n" \
336ead1f93eSLiane Praza				>> $mail_msg_file
337ead1f93eSLiane Praza
338c3e6cb59SRichard Lowe			egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/${INSTALLOG}.out | \
3397c478bd9Sstevel@tonic-gate				grep ':' | \
3407c478bd9Sstevel@tonic-gate				grep -v PSTAMP | \
341*cb4d1691SRichard Lowe				egrep -v "Ignoring unknown host" | \
342*cb4d1691SRichard Lowe				tee $TMPDIR/package >> $mail_msg_file
343*cb4d1691SRichard Lowe			if [[ -s $TMPDIR/package ]]; then
344*cb4d1691SRichard Lowe				build_extras_ok=n
345*cb4d1691SRichard Lowe				this_build_ok=n
346*cb4d1691SRichard Lowe			fi
347ead1f93eSLiane Praza		else
348ead1f93eSLiane Praza			#
349c3e6cb59SRichard Lowe			# Handle it gracefully if -p was set but there so
350c3e6cb59SRichard Lowe			# no pkg directory.
351ead1f93eSLiane Praza			#
352ead1f93eSLiane Praza			echo "\n==== No $LABEL packages to build ====\n" \
353ead1f93eSLiane Praza				>> $LOGFILE
354ead1f93eSLiane Praza		fi
3557c478bd9Sstevel@tonic-gate	else
3567c478bd9Sstevel@tonic-gate		echo "\n==== Not creating $LABEL packages ====\n" >> $LOGFILE
3577c478bd9Sstevel@tonic-gate	fi
3584e5b757fSkupfer
3594e5b757fSkupfer	ROOT=$ORIGROOT
3607c478bd9Sstevel@tonic-gate}
3617c478bd9Sstevel@tonic-gate
3621fe69678Skupfer# Usage: dolint /dir y|n
3637c478bd9Sstevel@tonic-gate# Arg. 2 is a flag to turn on/off the lint diff output
364597bd30bSMike Kupferfunction dolint {
3657c478bd9Sstevel@tonic-gate	if [ ! -d "$1" ]; then
3661fe69678Skupfer		echo "dolint error: $1 is not a directory"
3677c478bd9Sstevel@tonic-gate		exit 1
3687c478bd9Sstevel@tonic-gate	fi
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate	if [ "$2" != "y" -a "$2" != "n" ]; then
3711fe69678Skupfer		echo "dolint internal error: $2 should be 'y' or 'n'"
3727c478bd9Sstevel@tonic-gate		exit 1
3737c478bd9Sstevel@tonic-gate	fi
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate	lintdir=$1
3767c478bd9Sstevel@tonic-gate	dodiff=$2
3777c478bd9Sstevel@tonic-gate	base=`basename $lintdir`
3787c478bd9Sstevel@tonic-gate	LINTOUT=$lintdir/lint-${MACH}.out
3797c478bd9Sstevel@tonic-gate	LINTNOISE=$lintdir/lint-noise-${MACH}
3804e5b757fSkupfer	export ENVLDLIBS1=`myldlibs $ROOT`
3814e5b757fSkupfer	export ENVCPPFLAGS1=`myheaders $ROOT`
3827c478bd9Sstevel@tonic-gate
3834e5b757fSkupfer	set_debug_build_flags
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate	#
3867c478bd9Sstevel@tonic-gate	#	'$MAKE lint' in $lintdir
3877c478bd9Sstevel@tonic-gate	#
3887c478bd9Sstevel@tonic-gate	echo "\n==== Begin '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate	# remove old lint.out
3917c478bd9Sstevel@tonic-gate	rm -f $lintdir/lint.out $lintdir/lint-noise.out
3927c478bd9Sstevel@tonic-gate	if [ -f $lintdir/lint-noise.ref ]; then
3937c478bd9Sstevel@tonic-gate		mv $lintdir/lint-noise.ref ${LINTNOISE}.ref
3947c478bd9Sstevel@tonic-gate	fi
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate	rm -f $LINTOUT
3977c478bd9Sstevel@tonic-gate	cd $lintdir
3987c478bd9Sstevel@tonic-gate	#
3997c478bd9Sstevel@tonic-gate	# Remove all .ln files to ensure a full reference file
4007c478bd9Sstevel@tonic-gate	#
4017c478bd9Sstevel@tonic-gate	rm -f Nothing_to_remove \
4028bcea973SRichard Lowe	    `find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \) \
403cdf0c1d5Smjnelson	    	-prune -o -type f -name '*.ln' -print `
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate	/bin/time $MAKE -ek lint 2>&1 | \
4067c478bd9Sstevel@tonic-gate	    tee -a $LINTOUT >> $LOGFILE
407*cb4d1691SRichard Lowe
4087c478bd9Sstevel@tonic-gate	echo "\n==== '$MAKE lint' of $base ERRORS ====\n" >> $mail_msg_file
409*cb4d1691SRichard Lowe
4107c478bd9Sstevel@tonic-gate	grep "$MAKE:" $LINTOUT |
411*cb4d1691SRichard Lowe		egrep -v "Ignoring unknown host" | \
412*cb4d1691SRichard Lowe		tee $TMPDIR/lint_errs >> $mail_msg_file
413*cb4d1691SRichard Lowe	if [[ -s $TMPDIR/lint_errs ]]; then
414*cb4d1691SRichard Lowe		build_extras_ok=n
415*cb4d1691SRichard Lowe	fi
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate	echo "\n==== Ended '$MAKE lint' of $base at `date` ====\n" >> $LOGFILE
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate	echo "\n==== Elapsed time of '$MAKE lint' of $base ====\n" \
4207c478bd9Sstevel@tonic-gate		>>$mail_msg_file
4217c478bd9Sstevel@tonic-gate	tail -3  $LINTOUT >>$mail_msg_file
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate	rm -f ${LINTNOISE}.ref
4247c478bd9Sstevel@tonic-gate	if [ -f ${LINTNOISE}.out ]; then
4257c478bd9Sstevel@tonic-gate		mv ${LINTNOISE}.out ${LINTNOISE}.ref
4267c478bd9Sstevel@tonic-gate	fi
4277c478bd9Sstevel@tonic-gate        grep : $LINTOUT | \
4287c478bd9Sstevel@tonic-gate		egrep -v '^(real|user|sys)' |
4297c478bd9Sstevel@tonic-gate		egrep -v '(library construction)' | \
4307c478bd9Sstevel@tonic-gate		egrep -v ': global crosschecks' | \
4317c478bd9Sstevel@tonic-gate		egrep -v 'Ignoring unknown host' | \
4327c478bd9Sstevel@tonic-gate		egrep -v '\.c:$' | \
4337c478bd9Sstevel@tonic-gate		sort | uniq > ${LINTNOISE}.out
4347c478bd9Sstevel@tonic-gate	if [ ! -f ${LINTNOISE}.ref ]; then
4357c478bd9Sstevel@tonic-gate		cp ${LINTNOISE}.out ${LINTNOISE}.ref
4367c478bd9Sstevel@tonic-gate	fi
437*cb4d1691SRichard Lowe
4387c478bd9Sstevel@tonic-gate	if [ "$dodiff" != "n" ]; then
4397c478bd9Sstevel@tonic-gate		echo "\n==== lint warnings $base ====\n" \
4407c478bd9Sstevel@tonic-gate			>>$mail_msg_file
4417c478bd9Sstevel@tonic-gate		# should be none, though there are a few that were filtered out
4427c478bd9Sstevel@tonic-gate		# above
4437c478bd9Sstevel@tonic-gate		egrep -i '(warning|lint):' ${LINTNOISE}.out \
444*cb4d1691SRichard Lowe			| sort | uniq | tee $TMPDIR/lint_warns >> $mail_msg_file
445*cb4d1691SRichard Lowe		if [[ -s $TMPDIR/lint_warns ]]; then
446*cb4d1691SRichard Lowe			build_extras_ok=n
447*cb4d1691SRichard Lowe		fi
4487c478bd9Sstevel@tonic-gate		echo "\n==== lint noise differences $base ====\n" \
4497c478bd9Sstevel@tonic-gate			>> $mail_msg_file
4507c478bd9Sstevel@tonic-gate		diff ${LINTNOISE}.ref ${LINTNOISE}.out \
4517c478bd9Sstevel@tonic-gate			>> $mail_msg_file
4527c478bd9Sstevel@tonic-gate	fi
4537c478bd9Sstevel@tonic-gate}
4547c478bd9Sstevel@tonic-gate
4554e5b757fSkupfer#
4564e5b757fSkupfer# Build and install the onbld tools.
4574e5b757fSkupfer#
4581fe69678Skupfer# usage: build_tools DESTROOT
4594e5b757fSkupfer#
4604e5b757fSkupfer# returns non-zero status if the build was successful.
4614e5b757fSkupfer#
462597bd30bSMike Kupferfunction build_tools {
4637c478bd9Sstevel@tonic-gate	DESTROOT=$1
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate	INSTALLOG=install-${MACH}
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate	echo "\n==== Building tools at `date` ====\n" \
4687c478bd9Sstevel@tonic-gate		>> $LOGFILE
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gate	rm -f ${TOOLS}/${INSTALLOG}.out
4717c478bd9Sstevel@tonic-gate	cd ${TOOLS}
472ead1f93eSLiane Praza	/bin/time $MAKE TOOLS_PROTO=${DESTROOT} -e install 2>&1 | \
4737c478bd9Sstevel@tonic-gate	    tee -a ${TOOLS}/${INSTALLOG}.out >> $LOGFILE
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate	echo "\n==== Tools build errors ====\n" >> $mail_msg_file
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate	egrep ":" ${TOOLS}/${INSTALLOG}.out |
4787c478bd9Sstevel@tonic-gate		egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
4797c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
480*cb4d1691SRichard Lowe		egrep -v warning | tee $TMPDIR/tools_errors >> $mail_msg_file
481*cb4d1691SRichard Lowe
482*cb4d1691SRichard Lowe	if [[ -s $TMPDIR/tools_errors ]]; then
483*cb4d1691SRichard Lowe		return 1
484*cb4d1691SRichard Lowe	fi
485*cb4d1691SRichard Lowe	return 0
4864e5b757fSkupfer}
4874e5b757fSkupfer
4884e5b757fSkupfer#
4894e5b757fSkupfer# Set up to use locally installed tools.
4904e5b757fSkupfer#
4914e5b757fSkupfer# usage: use_tools TOOLSROOT
4924e5b757fSkupfer#
493597bd30bSMike Kupferfunction use_tools {
4944e5b757fSkupfer	TOOLSROOT=$1
4954e5b757fSkupfer
496c168ccb7SMark J. Nelson	#
497c168ccb7SMark J. Nelson	# If we're not building ON workspace, then the TOOLSROOT
498c168ccb7SMark J. Nelson	# settings here are clearly ignored by the workspace
499c168ccb7SMark J. Nelson	# makefiles, prepending nonexistent directories to PATH is
500c168ccb7SMark J. Nelson	# harmless, and we clearly do not wish to override
501c168ccb7SMark J. Nelson	# ONBLD_TOOLS.
502c168ccb7SMark J. Nelson	#
503c168ccb7SMark J. Nelson	# If we're building an ON workspace, then the prepended PATH
504c168ccb7SMark J. Nelson	# elements should supercede the preexisting ONBLD_TOOLS paths,
505c168ccb7SMark J. Nelson	# and we want to override ONBLD_TOOLS to catch the tools that
506c168ccb7SMark J. Nelson	# don't have specific path env vars here.
507c168ccb7SMark J. Nelson	#
508c168ccb7SMark J. Nelson	# So the only conditional behavior is overriding ONBLD_TOOLS,
509c168ccb7SMark J. Nelson	# and we check for "an ON workspace" by looking for
510c168ccb7SMark J. Nelson	# ${TOOLSROOT}/opt/onbld.
511c168ccb7SMark J. Nelson	#
512c168ccb7SMark J. Nelson
5134e5b757fSkupfer	STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
5147c478bd9Sstevel@tonic-gate	export STABS
5154e5b757fSkupfer	CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
5167c478bd9Sstevel@tonic-gate	export CTFSTABS
5174e5b757fSkupfer	GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
5187c478bd9Sstevel@tonic-gate	export GENOFFSETS
5197c478bd9Sstevel@tonic-gate
5204e5b757fSkupfer	CTFCONVERT=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfconvert
5217c478bd9Sstevel@tonic-gate	export CTFCONVERT
5224e5b757fSkupfer	CTFMERGE=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfmerge
5237c478bd9Sstevel@tonic-gate	export CTFMERGE
5247c478bd9Sstevel@tonic-gate
5254e5b757fSkupfer	CTFCVTPTBL=${TOOLSROOT}/opt/onbld/bin/ctfcvtptbl
5267c478bd9Sstevel@tonic-gate	export CTFCVTPTBL
5274e5b757fSkupfer	CTFFINDMOD=${TOOLSROOT}/opt/onbld/bin/ctffindmod
5287c478bd9Sstevel@tonic-gate	export CTFFINDMOD
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate	if [ "$VERIFY_ELFSIGN" = "y" ]; then
5314e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/elfsigncmp
5327c478bd9Sstevel@tonic-gate	else
5334e5b757fSkupfer		ELFSIGN=${TOOLSROOT}/opt/onbld/bin/${MACH}/elfsign
5347c478bd9Sstevel@tonic-gate	fi
5357c478bd9Sstevel@tonic-gate	export ELFSIGN
5367c478bd9Sstevel@tonic-gate
537c168ccb7SMark J. Nelson	PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
5384e5b757fSkupfer	PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
5397c478bd9Sstevel@tonic-gate	export PATH
5407c478bd9Sstevel@tonic-gate
541c168ccb7SMark J. Nelson	if [ -d "${TOOLSROOT}/opt/onbld" ]; then
542b06f2c55SMark J. Nelson		ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
5431d9a8b8dSDan Mick		export ONBLD_TOOLS
544c168ccb7SMark J. Nelson	fi
5451d9a8b8dSDan Mick
5467c478bd9Sstevel@tonic-gate	echo "\n==== New environment settings. ====\n" >> $LOGFILE
5477c478bd9Sstevel@tonic-gate	echo "STABS=${STABS}" >> $LOGFILE
5487c478bd9Sstevel@tonic-gate	echo "CTFSTABS=${CTFSTABS}" >> $LOGFILE
5497c478bd9Sstevel@tonic-gate	echo "CTFCONVERT=${CTFCONVERT}" >> $LOGFILE
5507c478bd9Sstevel@tonic-gate	echo "CTFMERGE=${CTFMERGE}" >> $LOGFILE
5517c478bd9Sstevel@tonic-gate	echo "CTFCVTPTBL=${CTFCVTPTBL}" >> $LOGFILE
5527c478bd9Sstevel@tonic-gate	echo "CTFFINDMOD=${CTFFINDMOD}" >> $LOGFILE
5537c478bd9Sstevel@tonic-gate	echo "ELFSIGN=${ELFSIGN}" >> $LOGFILE
5547c478bd9Sstevel@tonic-gate	echo "PATH=${PATH}" >> $LOGFILE
5551d9a8b8dSDan Mick	echo "ONBLD_TOOLS=${ONBLD_TOOLS}" >> $LOGFILE
5567c478bd9Sstevel@tonic-gate}
5577c478bd9Sstevel@tonic-gate
558597bd30bSMike Kupferfunction staffer {
5597c478bd9Sstevel@tonic-gate	if [ $ISUSER -ne 0 ]; then
5607c478bd9Sstevel@tonic-gate		"$@"
5617c478bd9Sstevel@tonic-gate	else
5627c478bd9Sstevel@tonic-gate		arg="\"$1\""
5637c478bd9Sstevel@tonic-gate		shift
5647c478bd9Sstevel@tonic-gate		for i
5657c478bd9Sstevel@tonic-gate		do
5667c478bd9Sstevel@tonic-gate			arg="$arg \"$i\""
5677c478bd9Sstevel@tonic-gate		done
5687c478bd9Sstevel@tonic-gate		eval su $STAFFER -c \'$arg\'
5697c478bd9Sstevel@tonic-gate	fi
5707c478bd9Sstevel@tonic-gate}
5717c478bd9Sstevel@tonic-gate
572085d331dSkupfer#
573c3e6cb59SRichard Lowe# Verify that the closed bins are present
574085d331dSkupfer#
575c3e6cb59SRichard Lowefunction check_closed_bins {
576c0e7977aSJosef 'Jeff' Sipek	if [[ ! -d "$ON_CLOSED_BINS" ]]; then
577c0e7977aSJosef 'Jeff' Sipek		echo "ON_CLOSED_BINS must point to the closed binaries tree."
578cdf0c1d5Smjnelson		build_ok=n
579085d331dSkupfer		exit 1
580085d331dSkupfer	fi
581085d331dSkupfer}
5827c478bd9Sstevel@tonic-gate
5834e5b757fSkupfer#
5844e5b757fSkupfer# wrapper over wsdiff.
5854e5b757fSkupfer# usage: do_wsdiff LABEL OLDPROTO NEWPROTO
5864e5b757fSkupfer#
587597bd30bSMike Kupferfunction do_wsdiff {
5884e5b757fSkupfer	label=$1
5894e5b757fSkupfer	oldproto=$2
5904e5b757fSkupfer	newproto=$3
5914e5b757fSkupfer
5924e5b757fSkupfer	wsdiff="wsdiff"
5934e5b757fSkupfer	[ "$t_FLAG" = y ] && wsdiff="wsdiff -t"
5944e5b757fSkupfer
595598cc7dfSVladimir Kotal	echo "\n==== Getting object changes since last build at `date`" \
596598cc7dfSVladimir Kotal	    "($label) ====\n" | tee -a $LOGFILE >> $mail_msg_file
597598cc7dfSVladimir Kotal	$wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto 2>&1 | \
598598cc7dfSVladimir Kotal		    tee -a $LOGFILE >> $mail_msg_file
599598cc7dfSVladimir Kotal	echo "\n==== Object changes determined at `date` ($label) ====\n" | \
6004e5b757fSkupfer	    tee -a $LOGFILE >> $mail_msg_file
6014e5b757fSkupfer}
6024e5b757fSkupfer
6034e5b757fSkupfer#
604ead1f93eSLiane Praza# Functions for setting build flags (DEBUG/non-DEBUG).  Keep them
6054e5b757fSkupfer# together.
6064e5b757fSkupfer#
6074e5b757fSkupfer
608597bd30bSMike Kupferfunction set_non_debug_build_flags {
6094e5b757fSkupfer	export RELEASE_BUILD ; RELEASE_BUILD=
6104e5b757fSkupfer	unset EXTRA_OPTIONS
6114e5b757fSkupfer	unset EXTRA_CFLAGS
6124e5b757fSkupfer}
6134e5b757fSkupfer
614597bd30bSMike Kupferfunction set_debug_build_flags {
6154e5b757fSkupfer	unset RELEASE_BUILD
6164e5b757fSkupfer	unset EXTRA_OPTIONS
6174e5b757fSkupfer	unset EXTRA_CFLAGS
6184e5b757fSkupfer}
6194e5b757fSkupfer
620d77e7149Ssommerfe
6217c478bd9Sstevel@tonic-gateMACH=`uname -p`
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gateif [ "$OPTHOME" = "" ]; then
6247c478bd9Sstevel@tonic-gate	OPTHOME=/opt
6257c478bd9Sstevel@tonic-gate	export OPTHOME
6267c478bd9Sstevel@tonic-gatefi
6277c478bd9Sstevel@tonic-gate
6285110237aSJosef 'Jeff' SipekUSAGE='Usage: nightly [-in] [+t] [-V VERS ] <env_file>
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gateWhere:
631d77e7149Ssommerfe	-i	Fast incremental options (no clobber, lint, check)
6327c478bd9Sstevel@tonic-gate	-n      Do not do a bringover
6335e1b109eSPeter Dennis - Sustaining Engineer	+t	Use the build tools in $ONBLD_TOOLS/bin
6347c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate	<env_file>  file in Bourne shell syntax that sets and exports
6377c478bd9Sstevel@tonic-gate	variables that configure the operation of this script and many of
6387c478bd9Sstevel@tonic-gate	the scripts this one calls. If <env_file> does not exist,
6397c478bd9Sstevel@tonic-gate	it will be looked for in $OPTHOME/onbld/env.
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gatenon-DEBUG is the default build type. Build options can be set in the
6427c478bd9Sstevel@tonic-gateNIGHTLY_OPTIONS variable in the <env_file> as follows:
6437c478bd9Sstevel@tonic-gate
6447c478bd9Sstevel@tonic-gate	-A	check for ABI differences in .so files
6457c478bd9Sstevel@tonic-gate	-C	check for cstyle/hdrchk errors
6467c478bd9Sstevel@tonic-gate	-D	do a build with DEBUG on
6477c478bd9Sstevel@tonic-gate	-F	do _not_ do a non-DEBUG build
6483c6aa570SMark J. Nelson	-G	gate keeper default group of options (-au)
6497c478bd9Sstevel@tonic-gate	-I	integration engineer default group of options (-ampu)
6507c478bd9Sstevel@tonic-gate	-M	do not run pmodes (safe file permission checker)
6517c478bd9Sstevel@tonic-gate	-N	do not run protocmp
6527c478bd9Sstevel@tonic-gate	-R	default group of options for building a release (-mp)
6537c478bd9Sstevel@tonic-gate	-U	update proto area in the parent
6547c478bd9Sstevel@tonic-gate	-V VERS set the build version string to VERS
6557c478bd9Sstevel@tonic-gate	-f	find unreferenced files
6567c478bd9Sstevel@tonic-gate	-i	do an incremental build (no "make clobber")
6577c478bd9Sstevel@tonic-gate	-l	do "make lint" in $LINTDIRS (default: $SRC y)
6587c478bd9Sstevel@tonic-gate	-m	send mail to $MAILTO at end of build
6597c478bd9Sstevel@tonic-gate	-n      do not do a bringover
6607c478bd9Sstevel@tonic-gate	-p	create packages
6617c478bd9Sstevel@tonic-gate	-r	check ELF runtime attributes in the proto area
6625e1b109eSPeter Dennis - Sustaining Engineer	-t	build and use the tools in $SRC/tools (default setting)
6635e1b109eSPeter Dennis - Sustaining Engineer	+t	Use the build tools in $ONBLD_TOOLS/bin
6647c478bd9Sstevel@tonic-gate	-u	update proto_list_$MACH and friends in the parent workspace;
6657c478bd9Sstevel@tonic-gate		when used with -f, also build an unrefmaster.out in the parent
66696ccc8cbSesaxe	-w	report on differences between previous and current proto areas
6677c478bd9Sstevel@tonic-gate'
6687c478bd9Sstevel@tonic-gate#
6697c478bd9Sstevel@tonic-gate#	A log file will be generated under the name $LOGFILE
6701c79753fSdarrenm#	for partially completed build and log.`date '+%F'`
6717c478bd9Sstevel@tonic-gate#	in the same directory for fully completed builds.
6727c478bd9Sstevel@tonic-gate#
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate# default values for low-level FLAGS; G I R are group FLAGS
6757c478bd9Sstevel@tonic-gateA_FLAG=n
6767c478bd9Sstevel@tonic-gateC_FLAG=n
6776c3c9007SstevelD_FLAG=n
6787c478bd9Sstevel@tonic-gateF_FLAG=n
6797c478bd9Sstevel@tonic-gatef_FLAG=n
6807c478bd9Sstevel@tonic-gatei_FLAG=n; i_CMD_LINE_FLAG=n
6817c478bd9Sstevel@tonic-gatel_FLAG=n
6826c3c9007SstevelM_FLAG=n
6837c478bd9Sstevel@tonic-gatem_FLAG=n
6846c3c9007SstevelN_FLAG=n
6856c3c9007Ssteveln_FLAG=n
6867c478bd9Sstevel@tonic-gatep_FLAG=n
6877c478bd9Sstevel@tonic-gater_FLAG=n
688fd7cef36Ssuhat_FLAG=y
6897c478bd9Sstevel@tonic-gateU_FLAG=n
6906c3c9007Sstevelu_FLAG=n
6917c478bd9Sstevel@tonic-gateV_FLAG=n
6926c3c9007Sstevelw_FLAG=n
693*cb4d1691SRichard LoweW_FLAG=n
6947c478bd9Sstevel@tonic-gate#
6957c478bd9Sstevel@tonic-gatebuild_ok=y
696*cb4d1691SRichard Lowebuild_extras_ok=y
6971fe69678Skupfer
6987c478bd9Sstevel@tonic-gate#
6997c478bd9Sstevel@tonic-gate# examine arguments
7007c478bd9Sstevel@tonic-gate#
7017c478bd9Sstevel@tonic-gate
7027c478bd9Sstevel@tonic-gateOPTIND=1
703*cb4d1691SRichard Lowewhile getopts +intV:W FLAG
7047c478bd9Sstevel@tonic-gatedo
7057c478bd9Sstevel@tonic-gate	case $FLAG in
7067c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y; i_CMD_LINE_FLAG=y
7077c478bd9Sstevel@tonic-gate		;;
7087c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
7097c478bd9Sstevel@tonic-gate		;;
710fd7cef36Ssuha	 +t )	t_FLAG=n
7117c478bd9Sstevel@tonic-gate		;;
7126c3c9007Sstevel	  V )	V_FLAG=y
7136c3c9007Sstevel		V_ARG="$OPTARG"
7146c3c9007Sstevel		;;
715*cb4d1691SRichard Lowe	  W )   W_FLAG=y
716*cb4d1691SRichard Lowe		;;
7177c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
7187c478bd9Sstevel@tonic-gate		exit 1
7197c478bd9Sstevel@tonic-gate		;;
7207c478bd9Sstevel@tonic-gate	esac
7217c478bd9Sstevel@tonic-gatedone
7227c478bd9Sstevel@tonic-gate
7237c478bd9Sstevel@tonic-gate# correct argument count after options
7247c478bd9Sstevel@tonic-gateshift `expr $OPTIND - 1`
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate# test that the path to the environment-setting file was given
7277c478bd9Sstevel@tonic-gateif [ $# -ne 1 ]; then
7287c478bd9Sstevel@tonic-gate	echo "$USAGE"
7297c478bd9Sstevel@tonic-gate	exit 1
7307c478bd9Sstevel@tonic-gatefi
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate# check if user is running nightly as root
7337c478bd9Sstevel@tonic-gate# ISUSER is set non-zero if an ordinary user runs nightly, or is zero
7347c478bd9Sstevel@tonic-gate# when root invokes nightly.
7357c478bd9Sstevel@tonic-gate/usr/bin/id | grep '^uid=0(' >/dev/null 2>&1
7367c478bd9Sstevel@tonic-gateISUSER=$?;	export ISUSER
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate#
7397c478bd9Sstevel@tonic-gate# force locale to C
7407c478bd9Sstevel@tonic-gateLC_COLLATE=C;	export LC_COLLATE
7417c478bd9Sstevel@tonic-gateLC_CTYPE=C;	export LC_CTYPE
7427c478bd9Sstevel@tonic-gateLC_MESSAGES=C;	export LC_MESSAGES
7437c478bd9Sstevel@tonic-gateLC_MONETARY=C;	export LC_MONETARY
7447c478bd9Sstevel@tonic-gateLC_NUMERIC=C;	export LC_NUMERIC
7457c478bd9Sstevel@tonic-gateLC_TIME=C;	export LC_TIME
7467c478bd9Sstevel@tonic-gate
7477c478bd9Sstevel@tonic-gate# clear environment variables we know to be bad for the build
7487c478bd9Sstevel@tonic-gateunset LD_OPTIONS
7497c478bd9Sstevel@tonic-gateunset LD_AUDIT		LD_AUDIT_32		LD_AUDIT_64
7507c478bd9Sstevel@tonic-gateunset LD_BIND_NOW	LD_BIND_NOW_32		LD_BIND_NOW_64
7517c478bd9Sstevel@tonic-gateunset LD_BREADTH	LD_BREADTH_32		LD_BREADTH_64
7527c478bd9Sstevel@tonic-gateunset LD_CONFIG		LD_CONFIG_32		LD_CONFIG_64
7537c478bd9Sstevel@tonic-gateunset LD_DEBUG		LD_DEBUG_32		LD_DEBUG_64
7547c478bd9Sstevel@tonic-gateunset LD_DEMANGLE	LD_DEMANGLE_32		LD_DEMANGLE_64
7557c478bd9Sstevel@tonic-gateunset LD_FLAGS		LD_FLAGS_32		LD_FLAGS_64
7567c478bd9Sstevel@tonic-gateunset LD_LIBRARY_PATH	LD_LIBRARY_PATH_32	LD_LIBRARY_PATH_64
7577c478bd9Sstevel@tonic-gateunset LD_LOADFLTR	LD_LOADFLTR_32		LD_LOADFLTR_64
7587c478bd9Sstevel@tonic-gateunset LD_NOAUDIT	LD_NOAUDIT_32		LD_NOAUDIT_64
7597c478bd9Sstevel@tonic-gateunset LD_NOAUXFLTR	LD_NOAUXFLTR_32		LD_NOAUXFLTR_64
7607c478bd9Sstevel@tonic-gateunset LD_NOCONFIG	LD_NOCONFIG_32		LD_NOCONFIG_64
7617c478bd9Sstevel@tonic-gateunset LD_NODIRCONFIG	LD_NODIRCONFIG_32	LD_NODIRCONFIG_64
7627c478bd9Sstevel@tonic-gateunset LD_NODIRECT	LD_NODIRECT_32		LD_NODIRECT_64
7637c478bd9Sstevel@tonic-gateunset LD_NOLAZYLOAD	LD_NOLAZYLOAD_32	LD_NOLAZYLOAD_64
7647c478bd9Sstevel@tonic-gateunset LD_NOOBJALTER	LD_NOOBJALTER_32	LD_NOOBJALTER_64
7657c478bd9Sstevel@tonic-gateunset LD_NOVERSION	LD_NOVERSION_32		LD_NOVERSION_64
7667c478bd9Sstevel@tonic-gateunset LD_ORIGIN		LD_ORIGIN_32		LD_ORIGIN_64
7677c478bd9Sstevel@tonic-gateunset LD_PRELOAD	LD_PRELOAD_32		LD_PRELOAD_64
7687c478bd9Sstevel@tonic-gateunset LD_PROFILE	LD_PROFILE_32		LD_PROFILE_64
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gateunset CONFIG
7717c478bd9Sstevel@tonic-gateunset GROUP
7727c478bd9Sstevel@tonic-gateunset OWNER
7737c478bd9Sstevel@tonic-gateunset REMOTE
7747c478bd9Sstevel@tonic-gateunset ENV
7757c478bd9Sstevel@tonic-gateunset ARCH
7767c478bd9Sstevel@tonic-gateunset CLASSPATH
7777c478bd9Sstevel@tonic-gateunset NAME
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate#
780ead1f93eSLiane Praza# To get ONBLD_TOOLS from the environment, it must come from the env file.
781ead1f93eSLiane Praza# If it comes interactively, it is generally TOOLS_PROTO, which will be
782ead1f93eSLiane Praza# clobbered before the compiler version checks, which will therefore fail.
783ead1f93eSLiane Praza#
784ead1f93eSLiane Prazaunset ONBLD_TOOLS
785ead1f93eSLiane Praza
786ead1f93eSLiane Praza#
7877c478bd9Sstevel@tonic-gate#	Setup environmental variables
7887c478bd9Sstevel@tonic-gate#
78947703246Ssommerfeif [ -f /etc/nightly.conf ]; then
79047703246Ssommerfe	. /etc/nightly.conf
79147703246Ssommerfefi
79247703246Ssommerfe
7937c478bd9Sstevel@tonic-gateif [ -f $1 ]; then
7947c478bd9Sstevel@tonic-gate	if [[ $1 = */* ]]; then
7957c478bd9Sstevel@tonic-gate		. $1
7967c478bd9Sstevel@tonic-gate	else
7977c478bd9Sstevel@tonic-gate		. ./$1
7987c478bd9Sstevel@tonic-gate	fi
7997c478bd9Sstevel@tonic-gateelse
8007c478bd9Sstevel@tonic-gate	if [ -f $OPTHOME/onbld/env/$1 ]; then
8017c478bd9Sstevel@tonic-gate		. $OPTHOME/onbld/env/$1
8027c478bd9Sstevel@tonic-gate	else
8037c478bd9Sstevel@tonic-gate		echo "Cannot find env file as either $1 or $OPTHOME/onbld/env/$1"
8047c478bd9Sstevel@tonic-gate		exit 1
8057c478bd9Sstevel@tonic-gate	fi
8067c478bd9Sstevel@tonic-gatefi
8077c478bd9Sstevel@tonic-gate
8081fe69678Skupfer# contents of stdenv.sh inserted after next line:
8091fe69678Skupfer# STDENV_START
8101fe69678Skupfer# STDENV_END
8111fe69678Skupfer
812d7693b08SRoland Mainz# Check if we have sufficient data to continue...
813d7693b08SRoland Mainz[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
814220399b7SRoland Mainzif  [[ "${NIGHTLY_OPTIONS}" == ~(F)n ]] ; then
815220399b7SRoland Mainz	# Check if the gate data are valid if we don't do a "bringover" below
816220399b7SRoland Mainz	[[ -d "${CODEMGR_WS}" ]] || \
817220399b7SRoland Mainz		fatal_error "Error: ${CODEMGR_WS} is not a directory."
818220399b7SRoland Mainz	[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || \
819220399b7SRoland Mainz		fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
820220399b7SRoland Mainzfi
821d7693b08SRoland Mainz
8227c478bd9Sstevel@tonic-gate#
8237c478bd9Sstevel@tonic-gate# place ourselves in a new task, respecting BUILD_PROJECT if set.
8247c478bd9Sstevel@tonic-gate#
8257c478bd9Sstevel@tonic-gateif [ -z "$BUILD_PROJECT" ]; then
8267c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$
8277c478bd9Sstevel@tonic-gateelse
8287c478bd9Sstevel@tonic-gate	/usr/bin/newtask -c $$ -p $BUILD_PROJECT
8297c478bd9Sstevel@tonic-gatefi
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gateps -o taskid= -p $$ | read build_taskid
8327c478bd9Sstevel@tonic-gateps -o project= -p $$ | read build_project
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate#
8357c478bd9Sstevel@tonic-gate# See if NIGHTLY_OPTIONS is set
8367c478bd9Sstevel@tonic-gate#
8377c478bd9Sstevel@tonic-gateif [ "$NIGHTLY_OPTIONS" = "" ]; then
8387c478bd9Sstevel@tonic-gate	NIGHTLY_OPTIONS="-aBm"
8397c478bd9Sstevel@tonic-gatefi
8407c478bd9Sstevel@tonic-gate
8417c478bd9Sstevel@tonic-gate#
8427c478bd9Sstevel@tonic-gate# If BRINGOVER_WS was not specified, let it default to CLONE_WS
8437c478bd9Sstevel@tonic-gate#
8447c478bd9Sstevel@tonic-gateif [ "$BRINGOVER_WS" = "" ]; then
8457c478bd9Sstevel@tonic-gate	BRINGOVER_WS=$CLONE_WS
8467c478bd9Sstevel@tonic-gatefi
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate#
849fb23a357Skupfer# If BRINGOVER_FILES was not specified, default to usr
850a5c06a9eSmike_s#
851a5c06a9eSmike_sif [ "$BRINGOVER_FILES" = "" ]; then
852fb23a357Skupfer	BRINGOVER_FILES="usr"
853a5c06a9eSmike_sfi
854a5c06a9eSmike_s
855c3e6cb59SRichard Lowecheck_closed_bins
856fb9f9b97Skupfer
857a5c06a9eSmike_s#
8587c478bd9Sstevel@tonic-gate# Note: changes to the option letters here should also be applied to the
859b84bdc30Smeem#	bldenv script.  `d' is listed for backward compatibility.
8607c478bd9Sstevel@tonic-gate#
861d77e7149SsommerfeNIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
8627c478bd9Sstevel@tonic-gateOPTIND=1
863*cb4d1691SRichard Lowewhile getopts +ABCDdFfGIilMmNnpRrtUuwW FLAG $NIGHTLY_OPTIONS
8647c478bd9Sstevel@tonic-gatedo
8657c478bd9Sstevel@tonic-gate	case $FLAG in
8667c478bd9Sstevel@tonic-gate	  A )	A_FLAG=y
8677c478bd9Sstevel@tonic-gate		;;
8687c478bd9Sstevel@tonic-gate	  B )	D_FLAG=y
8697c478bd9Sstevel@tonic-gate		;; # old version of D
8706c3c9007Sstevel	  C )	C_FLAG=y
8717c478bd9Sstevel@tonic-gate		;;
8727c478bd9Sstevel@tonic-gate	  D )	D_FLAG=y
8737c478bd9Sstevel@tonic-gate		;;
8746c3c9007Sstevel	  F )	F_FLAG=y
8757c478bd9Sstevel@tonic-gate		;;
8766c3c9007Sstevel	  f )	f_FLAG=y
8777c478bd9Sstevel@tonic-gate		;;
87878add226Sjmcp	  G )   u_FLAG=y
8797c478bd9Sstevel@tonic-gate		;;
88078add226Sjmcp	  I )	m_FLAG=y
8817c478bd9Sstevel@tonic-gate		p_FLAG=y
8827c478bd9Sstevel@tonic-gate		u_FLAG=y
8837c478bd9Sstevel@tonic-gate		;;
8847c478bd9Sstevel@tonic-gate	  i )	i_FLAG=y
8857c478bd9Sstevel@tonic-gate		;;
8866c3c9007Sstevel	  l )	l_FLAG=y
8876c3c9007Sstevel		;;
8886c3c9007Sstevel	  M )	M_FLAG=y
8896c3c9007Sstevel		;;
8906c3c9007Sstevel	  m )	m_FLAG=y
8916c3c9007Sstevel		;;
8926c3c9007Sstevel	  N )	N_FLAG=y
8936c3c9007Sstevel		;;
8947c478bd9Sstevel@tonic-gate	  n )	n_FLAG=y
8957c478bd9Sstevel@tonic-gate		;;
8967c478bd9Sstevel@tonic-gate	  p )	p_FLAG=y
8977c478bd9Sstevel@tonic-gate		;;
8986c3c9007Sstevel	  R )	m_FLAG=y
8996c3c9007Sstevel		p_FLAG=y
9006c3c9007Sstevel		;;
9017c478bd9Sstevel@tonic-gate	  r )	r_FLAG=y
9027c478bd9Sstevel@tonic-gate		;;
903fd7cef36Ssuha	 +t )	t_FLAG=n
9047c478bd9Sstevel@tonic-gate		;;
9056798c3f0SMark J. Nelson	  U )   if [ -z "${PARENT_ROOT}" ]; then
9067c478bd9Sstevel@tonic-gate			echo "PARENT_ROOT must be set if the U flag is" \
9077c478bd9Sstevel@tonic-gate			    "present in NIGHTLY_OPTIONS."
9087c478bd9Sstevel@tonic-gate			exit 1
9097c478bd9Sstevel@tonic-gate		fi
9106798c3f0SMark J. Nelson		NIGHTLY_PARENT_ROOT=$PARENT_ROOT
9116798c3f0SMark J. Nelson		if [ -n "${PARENT_TOOLS_ROOT}" ]; then
9126798c3f0SMark J. Nelson			NIGHTLY_PARENT_TOOLS_ROOT=$PARENT_TOOLS_ROOT
913ead1f93eSLiane Praza		fi
9147c478bd9Sstevel@tonic-gate		U_FLAG=y
9157c478bd9Sstevel@tonic-gate		;;
9166c3c9007Sstevel	  u )	u_FLAG=y
9177c478bd9Sstevel@tonic-gate		;;
9186c3c9007Sstevel	  w )	w_FLAG=y
9197c478bd9Sstevel@tonic-gate		;;
920*cb4d1691SRichard Lowe	  W )   W_FLAG=y
921*cb4d1691SRichard Lowe		;;
9227c478bd9Sstevel@tonic-gate	 \? )	echo "$USAGE"
9237c478bd9Sstevel@tonic-gate		exit 1
9247c478bd9Sstevel@tonic-gate		;;
9257c478bd9Sstevel@tonic-gate	esac
9267c478bd9Sstevel@tonic-gatedone
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gateif [ $ISUSER -ne 0 ]; then
9297c478bd9Sstevel@tonic-gate	# Set default value for STAFFER, if needed.
9307c478bd9Sstevel@tonic-gate	if [ -z "$STAFFER" -o "$STAFFER" = "nobody" ]; then
9317c478bd9Sstevel@tonic-gate		STAFFER=`/usr/xpg4/bin/id -un`
9327c478bd9Sstevel@tonic-gate		export STAFFER
9337c478bd9Sstevel@tonic-gate	fi
9347c478bd9Sstevel@tonic-gatefi
9357c478bd9Sstevel@tonic-gate
9367c478bd9Sstevel@tonic-gateif [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
9377c478bd9Sstevel@tonic-gate	MAILTO=$STAFFER
9387c478bd9Sstevel@tonic-gate	export MAILTO
9397c478bd9Sstevel@tonic-gatefi
9407c478bd9Sstevel@tonic-gate
941c168ccb7SMark J. NelsonPATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/ccs/bin"
942c3e6cb59SRichard LowePATH="$PATH:$OPTHOME/SUNWspro/bin:/usr/bin:/usr/sbin:/usr/ucb"
943c168ccb7SMark J. NelsonPATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
9447c478bd9Sstevel@tonic-gateexport PATH
9457c478bd9Sstevel@tonic-gate
946fb23a357Skupfer# roots of source trees, both relative to $SRC and absolute.
947fb23a357Skupferrelsrcdirs="."
948c0e7977aSJosef 'Jeff' Sipekabssrcdirs="$SRC"
949fb23a357Skupfer
9507c478bd9Sstevel@tonic-gatePROTOCMPTERSE="protocmp.terse -gu"
9517c478bd9Sstevel@tonic-gatePOUND_SIGN="#"
95248bc00d6Sjmcp# have we set RELEASE_DATE in our env file?
95348bc00d6Sjmcpif [ -z "$RELEASE_DATE" ]; then
95448bc00d6Sjmcp	RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
95548bc00d6Sjmcpfi
95648bc00d6SjmcpBUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
95748bc00d6SjmcpBASEWSDIR=$(basename $CODEMGR_WS)
95848bc00d6SjmcpDEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
9597c478bd9Sstevel@tonic-gate
96048bc00d6Sjmcp# we export POUND_SIGN, RELEASE_DATE and DEV_CM to speed up the build process
961c3e6cb59SRichard Lowe# by avoiding repeated shell invocations to evaluate Makefile.master
962c3e6cb59SRichard Lowe# definitions.
963c3e6cb59SRichard Loweexport POUND_SIGN RELEASE_DATE DEV_CM
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gatemaketype="distributed"
966e119f243SRobert Mustacchiif [[ -z "$MAKE" ]]; then
9677c478bd9Sstevel@tonic-gate	MAKE=dmake
968e119f243SRobert Mustacchielif [[ ! -x "$MAKE" ]]; then
969e119f243SRobert Mustacchi	echo "\$MAKE is set to garbage in the environment"
970e119f243SRobert Mustacchi	exit 1
971e119f243SRobert Mustacchifi
9727c478bd9Sstevel@tonic-gate# get the dmake version string alone
9737c478bd9Sstevel@tonic-gateDMAKE_VERSION=$( $MAKE -v )
9747c478bd9Sstevel@tonic-gateDMAKE_VERSION=${DMAKE_VERSION#*: }
9757c478bd9Sstevel@tonic-gate# focus in on just the dotted version number alone
9767c478bd9Sstevel@tonic-gateDMAKE_MAJOR=$( echo $DMAKE_VERSION | \
9777c478bd9Sstevel@tonic-gate	sed -e 's/.*\<\([^.]*\.[^   ]*\).*$/\1/' )
9787c478bd9Sstevel@tonic-gate# extract the second (or final) integer
9797c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MAJOR#*.}
9807c478bd9Sstevel@tonic-gateDMAKE_MINOR=${DMAKE_MINOR%%.*}
9817c478bd9Sstevel@tonic-gate# extract the first integer
9827c478bd9Sstevel@tonic-gateDMAKE_MAJOR=${DMAKE_MAJOR%%.*}
9837c478bd9Sstevel@tonic-gateCHECK_DMAKE=${CHECK_DMAKE:-y}
9847c478bd9Sstevel@tonic-gate# x86 was built on the 12th, sparc on the 13th.
9857c478bd9Sstevel@tonic-gateif [ "$CHECK_DMAKE" = "y" -a \
9867c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/12" -a \
9877c478bd9Sstevel@tonic-gate     "$DMAKE_VERSION" != "Sun Distributed Make 7.3 2003/03/13" -a \( \
9887c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -lt 7 -o \
9897c478bd9Sstevel@tonic-gate     "$DMAKE_MAJOR" -eq 7 -a "$DMAKE_MINOR" -lt 4 \) ]; then
9907c478bd9Sstevel@tonic-gate	if [ -z "$DMAKE_VERSION" ]; then
9917c478bd9Sstevel@tonic-gate		echo "$MAKE is missing."
9927c478bd9Sstevel@tonic-gate		exit 1
9937c478bd9Sstevel@tonic-gate	fi
9947c478bd9Sstevel@tonic-gate	echo `whence $MAKE`" version is:"
9957c478bd9Sstevel@tonic-gate	echo "  ${DMAKE_VERSION}"
9967c478bd9Sstevel@tonic-gate	cat <<EOF
9977c478bd9Sstevel@tonic-gate
998c3e6cb59SRichard LoweThis version may not be safe for use, if you really want to use this version
999c3e6cb59SRichard Loweanyway add the following to your environment to disable this check:
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate  CHECK_DMAKE=n
10027c478bd9Sstevel@tonic-gateEOF
10037c478bd9Sstevel@tonic-gate	exit 1
10047c478bd9Sstevel@tonic-gatefi
10057c478bd9Sstevel@tonic-gateexport PATH
10067c478bd9Sstevel@tonic-gateexport MAKE
10077c478bd9Sstevel@tonic-gate
10087c478bd9Sstevel@tonic-gateif [ "${SUNWSPRO}" != "" ]; then
10097c478bd9Sstevel@tonic-gate	PATH="${SUNWSPRO}/bin:$PATH"
10107c478bd9Sstevel@tonic-gate	export PATH
10117c478bd9Sstevel@tonic-gatefi
10127c478bd9Sstevel@tonic-gate
101399e4a37bSWill Fiveashhostname=$(uname -n)
101499e4a37bSWill Fiveashif [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
101599e4a37bSWill Fiveashthen
101699e4a37bSWill Fiveash	maxjobs=
101799e4a37bSWill Fiveash	if [[ -f $HOME/.make.machines ]]
101899e4a37bSWill Fiveash	then
101999e4a37bSWill Fiveash		# Note: there is a hard tab and space character in the []s
102099e4a37bSWill Fiveash		# below.
102199e4a37bSWill Fiveash		egrep -i "^[ 	]*$hostname[ 	\.]" \
102299e4a37bSWill Fiveash			$HOME/.make.machines | read host jobs
102399e4a37bSWill Fiveash		maxjobs=${jobs##*=}
10247c478bd9Sstevel@tonic-gate	fi
102599e4a37bSWill Fiveash
102699e4a37bSWill Fiveash	if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
102799e4a37bSWill Fiveash	then
102899e4a37bSWill Fiveash		# default
102999e4a37bSWill Fiveash		maxjobs=4
10307c478bd9Sstevel@tonic-gate	fi
103199e4a37bSWill Fiveash
103299e4a37bSWill Fiveash	export DMAKE_MAX_JOBS=$maxjobs
103399e4a37bSWill Fiveashfi
103499e4a37bSWill Fiveash
10357c478bd9Sstevel@tonic-gateDMAKE_MODE=parallel;
10367c478bd9Sstevel@tonic-gateexport DMAKE_MODE
10377c478bd9Sstevel@tonic-gate
10387c478bd9Sstevel@tonic-gateif [ -z "${ROOT}" ]; then
10397c478bd9Sstevel@tonic-gate	echo "ROOT must be set."
10407c478bd9Sstevel@tonic-gate	exit 1
10417c478bd9Sstevel@tonic-gatefi
10427c478bd9Sstevel@tonic-gate
10437c478bd9Sstevel@tonic-gate#
10447c478bd9Sstevel@tonic-gate# if -V flag was given, reset VERSION to V_ARG
10457c478bd9Sstevel@tonic-gate#
10467c478bd9Sstevel@tonic-gateif [ "$V_FLAG" = "y" ]; then
10477c478bd9Sstevel@tonic-gate	VERSION=$V_ARG
10487c478bd9Sstevel@tonic-gatefi
10497c478bd9Sstevel@tonic-gate
10507c478bd9Sstevel@tonic-gateTMPDIR="/tmp/nightly.tmpdir.$$"
10517c478bd9Sstevel@tonic-gateexport TMPDIR
10527c478bd9Sstevel@tonic-gaterm -rf ${TMPDIR}
10537c478bd9Sstevel@tonic-gatemkdir -p $TMPDIR || exit 1
105485f46905SMark J. Nelsonchmod 777 $TMPDIR
10557c478bd9Sstevel@tonic-gate
10567c478bd9Sstevel@tonic-gate#
10577c478bd9Sstevel@tonic-gate# Keep elfsign's use of pkcs11_softtoken from looking in the user home
10587c478bd9Sstevel@tonic-gate# directory, which doesn't always work.   Needed until all build machines
10597c478bd9Sstevel@tonic-gate# have the fix for 6271754
10607c478bd9Sstevel@tonic-gate#
10617c478bd9Sstevel@tonic-gateSOFTTOKEN_DIR=$TMPDIR
10627c478bd9Sstevel@tonic-gateexport SOFTTOKEN_DIR
10637c478bd9Sstevel@tonic-gate
1064ead1f93eSLiane Praza#
1065ead1f93eSLiane Praza# Tools should only be built non-DEBUG.  Keep track of the tools proto
1066ead1f93eSLiane Praza# area path relative to $TOOLS, because the latter changes in an
1067ead1f93eSLiane Praza# export build.
1068ead1f93eSLiane Praza#
1069ead1f93eSLiane Praza# TOOLS_PROTO is included below for builds other than usr/src/tools
1070ead1f93eSLiane Praza# that look for this location.  For usr/src/tools, this will be
1071ead1f93eSLiane Praza# overridden on the $MAKE command line in build_tools().
1072ead1f93eSLiane Praza#
10737c478bd9Sstevel@tonic-gateTOOLS=${SRC}/tools
1074ead1f93eSLiane PrazaTOOLS_PROTO_REL=proto/root_${MACH}-nd
1075ead1f93eSLiane PrazaTOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL};	export TOOLS_PROTO
1076ead1f93eSLiane Praza
10777c478bd9Sstevel@tonic-gateunset   CFLAGS LD_LIBRARY_PATH LDFLAGS
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gate# create directories that are automatically removed if the nightly script
10807c478bd9Sstevel@tonic-gate# fails to start correctly
1081597bd30bSMike Kupferfunction newdir {
10827c478bd9Sstevel@tonic-gate	dir=$1
10837c478bd9Sstevel@tonic-gate	toadd=
10847c478bd9Sstevel@tonic-gate	while [ ! -d $dir ]; do
10857c478bd9Sstevel@tonic-gate		toadd="$dir $toadd"
10867c478bd9Sstevel@tonic-gate		dir=`dirname $dir`
10877c478bd9Sstevel@tonic-gate	done
10887c478bd9Sstevel@tonic-gate	torm=
10897c478bd9Sstevel@tonic-gate	newlist=
10907c478bd9Sstevel@tonic-gate	for dir in $toadd; do
10917c478bd9Sstevel@tonic-gate		if staffer mkdir $dir; then
10927c478bd9Sstevel@tonic-gate			newlist="$ISUSER $dir $newlist"
10937c478bd9Sstevel@tonic-gate			torm="$dir $torm"
10947c478bd9Sstevel@tonic-gate		else
10957c478bd9Sstevel@tonic-gate			[ -z "$torm" ] || staffer rmdir $torm
10967c478bd9Sstevel@tonic-gate			return 1
10977c478bd9Sstevel@tonic-gate		fi
10987c478bd9Sstevel@tonic-gate	done
10997c478bd9Sstevel@tonic-gate	newdirlist="$newlist $newdirlist"
11007c478bd9Sstevel@tonic-gate	return 0
11017c478bd9Sstevel@tonic-gate}
11027c478bd9Sstevel@tonic-gatenewdirlist=
11037c478bd9Sstevel@tonic-gate
11047c478bd9Sstevel@tonic-gate[ -d $CODEMGR_WS ] || newdir $CODEMGR_WS || exit 1
11057c478bd9Sstevel@tonic-gate
11067c478bd9Sstevel@tonic-gate# since this script assumes the build is from full source, it nullifies
11077c478bd9Sstevel@tonic-gate# variables likely to have been set by a "ws" script; nullification
11087c478bd9Sstevel@tonic-gate# confines the search space for headers and libraries to the proto area
11097c478bd9Sstevel@tonic-gate# built from this immediate source.
11107c478bd9Sstevel@tonic-gateENVLDLIBS1=
11117c478bd9Sstevel@tonic-gateENVLDLIBS2=
11127c478bd9Sstevel@tonic-gateENVLDLIBS3=
11137c478bd9Sstevel@tonic-gateENVCPPFLAGS1=
11147c478bd9Sstevel@tonic-gateENVCPPFLAGS2=
11157c478bd9Sstevel@tonic-gateENVCPPFLAGS3=
11167c478bd9Sstevel@tonic-gateENVCPPFLAGS4=
11177c478bd9Sstevel@tonic-gatePARENT_ROOT=
11187c478bd9Sstevel@tonic-gate
11197c478bd9Sstevel@tonic-gateexport ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
1120494f7e12SKeith M Wesolowski	ENVLDLIBS1 ENVLDLIBS2 PARENT_ROOT
11217c478bd9Sstevel@tonic-gate
11227c478bd9Sstevel@tonic-gatePKGARCHIVE_ORIG=$PKGARCHIVE
11237c478bd9Sstevel@tonic-gate
11247c478bd9Sstevel@tonic-gate#
11257c478bd9Sstevel@tonic-gate# Juggle the logs and optionally send mail on completion.
11267c478bd9Sstevel@tonic-gate#
11277c478bd9Sstevel@tonic-gate
1128597bd30bSMike Kupferfunction logshuffle {
1129fd7cef36Ssuha    	LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
11307c478bd9Sstevel@tonic-gate	if [ -f $LLOG -o -d $LLOG ]; then
11317c478bd9Sstevel@tonic-gate	    	LLOG=$LLOG.$$
11327c478bd9Sstevel@tonic-gate	fi
11337c478bd9Sstevel@tonic-gate	mkdir $LLOG
11344802ef38Srscott	export LLOG
11357c478bd9Sstevel@tonic-gate
11367c478bd9Sstevel@tonic-gate	if [ "$build_ok" = "y" ]; then
11377c478bd9Sstevel@tonic-gate		mv $ATLOG/proto_list_${MACH} $LLOG
113896ccc8cbSesaxe
11392e02daeeSRainer Orth		if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
11402e02daeeSRainer Orth			mv $ATLOG/proto_list_tools_${MACH} $LLOG
11412e02daeeSRainer Orth	        fi
11422e02daeeSRainer Orth
114396ccc8cbSesaxe		if [ -f $TMPDIR/wsdiff.results ]; then
114496ccc8cbSesaxe		    	mv $TMPDIR/wsdiff.results $LLOG
114596ccc8cbSesaxe		fi
11464e5b757fSkupfer
11474e5b757fSkupfer		if [ -f $TMPDIR/wsdiff-nd.results ]; then
11484e5b757fSkupfer			mv $TMPDIR/wsdiff-nd.results $LLOG
11494e5b757fSkupfer		fi
11507c478bd9Sstevel@tonic-gate	fi
11517c478bd9Sstevel@tonic-gate
11527c478bd9Sstevel@tonic-gate	#
11537c478bd9Sstevel@tonic-gate	# Now that we're about to send mail, it's time to check the noise
11547c478bd9Sstevel@tonic-gate	# file.  In the event that an error occurs beyond this point, it will
11557c478bd9Sstevel@tonic-gate	# be recorded in the nightly.log file, but nowhere else.  This would
11567c478bd9Sstevel@tonic-gate	# include only errors that cause the copying of the noise log to fail
11577c478bd9Sstevel@tonic-gate	# or the mail itself not to be sent.
11587c478bd9Sstevel@tonic-gate	#
11597c478bd9Sstevel@tonic-gate
11607c478bd9Sstevel@tonic-gate	exec >>$LOGFILE 2>&1
11617c478bd9Sstevel@tonic-gate	if [ -s $build_noise_file ]; then
11627c478bd9Sstevel@tonic-gate	    	echo "\n==== Nightly build noise ====\n" |
11637c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >>$mail_msg_file
11647c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$LOGFILE
11657c478bd9Sstevel@tonic-gate		cat $build_noise_file >>$mail_msg_file
11667c478bd9Sstevel@tonic-gate		echo | tee -a $LOGFILE >>$mail_msg_file
11677c478bd9Sstevel@tonic-gate	fi
11687c478bd9Sstevel@tonic-gate	rm -f $build_noise_file
11697c478bd9Sstevel@tonic-gate
11707c478bd9Sstevel@tonic-gate	case "$build_ok" in
11717c478bd9Sstevel@tonic-gate		y)
11727c478bd9Sstevel@tonic-gate			state=Completed
11737c478bd9Sstevel@tonic-gate			;;
11747c478bd9Sstevel@tonic-gate		i)
11757c478bd9Sstevel@tonic-gate			state=Interrupted
11767c478bd9Sstevel@tonic-gate			;;
11777c478bd9Sstevel@tonic-gate		*)
11787c478bd9Sstevel@tonic-gate	    		state=Failed
11797c478bd9Sstevel@tonic-gate			;;
11807c478bd9Sstevel@tonic-gate	esac
1181*cb4d1691SRichard Lowe
1182*cb4d1691SRichard Lowe	if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
1183*cb4d1691SRichard Lowe		state=Failed
1184*cb4d1691SRichard Lowe	fi
1185*cb4d1691SRichard Lowe
118640bc9153Srscott	NIGHTLY_STATUS=$state
118740bc9153Srscott	export NIGHTLY_STATUS
11887c478bd9Sstevel@tonic-gate
118947703246Ssommerfe	run_hook POST_NIGHTLY $state
119047703246Ssommerfe	run_hook SYS_POST_NIGHTLY $state
11914802ef38Srscott
11923cb00cf1SJoshua M. Clulow	#
11933cb00cf1SJoshua M. Clulow	# mailx(1) sets From: based on the -r flag
11943cb00cf1SJoshua M. Clulow	# if it is given.
11953cb00cf1SJoshua M. Clulow	#
11963cb00cf1SJoshua M. Clulow	mailx_r=
11973cb00cf1SJoshua M. Clulow	if [[ -n "${MAILFROM}" ]]; then
11983cb00cf1SJoshua M. Clulow		mailx_r="-r ${MAILFROM}"
11993cb00cf1SJoshua M. Clulow	fi
12003cb00cf1SJoshua M. Clulow
1201cdf0c1d5Smjnelson	cat $build_time_file $build_environ_file $mail_msg_file \
1202cdf0c1d5Smjnelson	    > ${LLOG}/mail_msg
12037c478bd9Sstevel@tonic-gate	if [ "$m_FLAG" = "y" ]; then
12043cb00cf1SJoshua M. Clulow	    	cat ${LLOG}/mail_msg | /usr/bin/mailx ${mailx_r} -s \
12057c478bd9Sstevel@tonic-gate	"Nightly ${MACH} Build of `basename ${CODEMGR_WS}` ${state}." \
12067c478bd9Sstevel@tonic-gate			${MAILTO}
12077c478bd9Sstevel@tonic-gate	fi
12087c478bd9Sstevel@tonic-gate
12097c478bd9Sstevel@tonic-gate	if [ "$u_FLAG" = "y" -a "$build_ok" = "y" ]; then
12107c478bd9Sstevel@tonic-gate	    	staffer cp ${LLOG}/mail_msg $PARENT_WS/usr/src/mail_msg-${MACH}
12117c478bd9Sstevel@tonic-gate		staffer cp $LOGFILE $PARENT_WS/usr/src/nightly-${MACH}.log
12127c478bd9Sstevel@tonic-gate	fi
12137c478bd9Sstevel@tonic-gate
12147c478bd9Sstevel@tonic-gate	mv $LOGFILE $LLOG
12157c478bd9Sstevel@tonic-gate}
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate#
12187c478bd9Sstevel@tonic-gate#	Remove the locks and temporary files on any exit
12197c478bd9Sstevel@tonic-gate#
1220597bd30bSMike Kupferfunction cleanup {
12217c478bd9Sstevel@tonic-gate    	logshuffle
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gate	[ -z "$lockfile" ] || staffer rm -f $lockfile
12247c478bd9Sstevel@tonic-gate	[ -z "$atloglockfile" ] || rm -f $atloglockfile
12257c478bd9Sstevel@tonic-gate	[ -z "$ulockfile" ] || staffer rm -f $ulockfile
12267c478bd9Sstevel@tonic-gate	[ -z "$Ulockfile" ] || rm -f $Ulockfile
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gate	set -- $newdirlist
12297c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
12307c478bd9Sstevel@tonic-gate		ISUSER=$1 staffer rmdir $2
12317c478bd9Sstevel@tonic-gate		shift; shift
12327c478bd9Sstevel@tonic-gate	done
12337c478bd9Sstevel@tonic-gate	rm -rf $TMPDIR
12347c478bd9Sstevel@tonic-gate}
12357c478bd9Sstevel@tonic-gate
1236597bd30bSMike Kupferfunction cleanup_signal {
12377c478bd9Sstevel@tonic-gate    	build_ok=i
12387c478bd9Sstevel@tonic-gate	# this will trigger cleanup(), above.
12397c478bd9Sstevel@tonic-gate	exit 1
12407c478bd9Sstevel@tonic-gate}
12417c478bd9Sstevel@tonic-gate
12427c478bd9Sstevel@tonic-gatetrap cleanup 0
12437c478bd9Sstevel@tonic-gatetrap cleanup_signal 1 2 3 15
12447c478bd9Sstevel@tonic-gate
12457c478bd9Sstevel@tonic-gate#
12467c478bd9Sstevel@tonic-gate# Generic lock file processing -- make sure that the lock file doesn't
12477c478bd9Sstevel@tonic-gate# exist.  If it does, it should name the build host and PID.  If it
12487c478bd9Sstevel@tonic-gate# doesn't, then make sure we can create it.  Clean up locks that are
12497c478bd9Sstevel@tonic-gate# known to be stale (assumes host name is unique among build systems
12507c478bd9Sstevel@tonic-gate# for the workspace).
1251cdf0c1d5Smjnelson#
1252597bd30bSMike Kupferfunction create_lock {
12537c478bd9Sstevel@tonic-gate	lockf=$1
12547c478bd9Sstevel@tonic-gate	lockvar=$2
12558312e758Sdduvall
12567c478bd9Sstevel@tonic-gate	ldir=`dirname $lockf`
12577c478bd9Sstevel@tonic-gate	[ -d $ldir ] || newdir $ldir || exit 1
12587c478bd9Sstevel@tonic-gate	eval $lockvar=$lockf
12598312e758Sdduvall
12608312e758Sdduvall	while ! staffer ln -s $hostname.$STAFFER.$$ $lockf 2> /dev/null; do
12618312e758Sdduvall		basews=`basename $CODEMGR_WS`
12628312e758Sdduvall		ls -l $lockf | nawk '{print $NF}' | IFS=. read host user pid
12638312e758Sdduvall		if [ "$host" != "$hostname" ]; then
12648312e758Sdduvall			echo "$MACH build of $basews apparently" \
12658312e758Sdduvall			    "already started by $user on $host as $pid."
12668312e758Sdduvall			exit 1
12678312e758Sdduvall		elif kill -s 0 $pid 2>/dev/null; then
12688312e758Sdduvall			echo "$MACH build of $basews already started" \
12698312e758Sdduvall			    "by $user as $pid."
12708312e758Sdduvall			exit 1
12718312e758Sdduvall		else
12728312e758Sdduvall			# stale lock; clear it out and try again
12738312e758Sdduvall			rm -f $lockf
12748312e758Sdduvall		fi
12758312e758Sdduvall	done
12767c478bd9Sstevel@tonic-gate}
12777c478bd9Sstevel@tonic-gate
12784e5b757fSkupfer#
12794e5b757fSkupfer# Return the list of interesting proto areas, depending on the current
12804e5b757fSkupfer# options.
12814e5b757fSkupfer#
1282597bd30bSMike Kupferfunction allprotos {
1283c7453724SMike Kupfer	typeset roots="$ROOT"
1284b83ec4edSjmcp
1285c7453724SMike Kupfer	if [[ "$F_FLAG" = n && "$MULTI_PROTO" = yes ]]; then
1286c7453724SMike Kupfer		roots="$roots $ROOT-nd"
12874e5b757fSkupfer	fi
12884e5b757fSkupfer
12894e5b757fSkupfer	echo $roots
12904e5b757fSkupfer}
12914e5b757fSkupfer
12927c478bd9Sstevel@tonic-gate# Ensure no other instance of this script is running on this host.
12937c478bd9Sstevel@tonic-gate# LOCKNAME can be set in <env_file>, and is by default, but is not
12947c478bd9Sstevel@tonic-gate# required due to the use of $ATLOG below.
12957c478bd9Sstevel@tonic-gateif [ -n "$LOCKNAME" ]; then
12967c478bd9Sstevel@tonic-gate	create_lock /tmp/$LOCKNAME "lockfile"
12977c478bd9Sstevel@tonic-gatefi
12987c478bd9Sstevel@tonic-gate#
12997c478bd9Sstevel@tonic-gate# Create from one, two, or three other locks:
13007c478bd9Sstevel@tonic-gate#	$ATLOG/nightly.lock
13017c478bd9Sstevel@tonic-gate#		- protects against multiple builds in same workspace
13027c478bd9Sstevel@tonic-gate#	$PARENT_WS/usr/src/nightly.$MACH.lock
13037c478bd9Sstevel@tonic-gate#		- protects against multiple 'u' copy-backs
13047c478bd9Sstevel@tonic-gate#	$NIGHTLY_PARENT_ROOT/nightly.lock
13057c478bd9Sstevel@tonic-gate#		- protects against multiple 'U' copy-backs
13067c478bd9Sstevel@tonic-gate#
13077c478bd9Sstevel@tonic-gate# Overriding ISUSER to 1 causes the lock to be created as root if the
13087c478bd9Sstevel@tonic-gate# script is run as root.  The default is to create it as $STAFFER.
13097c478bd9Sstevel@tonic-gateISUSER=1 create_lock $ATLOG/nightly.lock "atloglockfile"
13107c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" ]; then
13117c478bd9Sstevel@tonic-gate	create_lock $PARENT_WS/usr/src/nightly.$MACH.lock "ulockfile"
13127c478bd9Sstevel@tonic-gatefi
13137c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" ]; then
13147c478bd9Sstevel@tonic-gate	# NIGHTLY_PARENT_ROOT is written as root if script invoked as root.
13157c478bd9Sstevel@tonic-gate	ISUSER=1 create_lock $NIGHTLY_PARENT_ROOT/nightly.lock "Ulockfile"
13167c478bd9Sstevel@tonic-gatefi
13177c478bd9Sstevel@tonic-gate
13187c478bd9Sstevel@tonic-gate# Locks have been taken, so we're doing a build and we're committed to
13197c478bd9Sstevel@tonic-gate# the directories we may have created so far.
13207c478bd9Sstevel@tonic-gatenewdirlist=
13217c478bd9Sstevel@tonic-gate
13227c478bd9Sstevel@tonic-gate#
13237c478bd9Sstevel@tonic-gate# Create mail_msg_file
13247c478bd9Sstevel@tonic-gate#
13257c478bd9Sstevel@tonic-gatemail_msg_file="${TMPDIR}/mail_msg"
13267c478bd9Sstevel@tonic-gatetouch $mail_msg_file
13277c478bd9Sstevel@tonic-gatebuild_time_file="${TMPDIR}/build_time"
1328cdf0c1d5Smjnelsonbuild_environ_file="${TMPDIR}/build_environ"
1329cdf0c1d5Smjnelsontouch $build_environ_file
13307c478bd9Sstevel@tonic-gate#
13317c478bd9Sstevel@tonic-gate#	Move old LOGFILE aside
13327c478bd9Sstevel@tonic-gate#	ATLOG directory already made by 'create_lock' above
13337c478bd9Sstevel@tonic-gate#
13347c478bd9Sstevel@tonic-gateif [ -f $LOGFILE ]; then
13357c478bd9Sstevel@tonic-gate	mv -f $LOGFILE ${LOGFILE}-
13367c478bd9Sstevel@tonic-gatefi
13377c478bd9Sstevel@tonic-gate#
13387c478bd9Sstevel@tonic-gate#	Build OsNet source
13397c478bd9Sstevel@tonic-gate#
13407c478bd9Sstevel@tonic-gateSTART_DATE=`date`
13417c478bd9Sstevel@tonic-gateSECONDS=0
13427c478bd9Sstevel@tonic-gateecho "\n==== Nightly $maketype build started:   $START_DATE ====" \
13437c478bd9Sstevel@tonic-gate    | tee -a $LOGFILE > $build_time_file
13447c478bd9Sstevel@tonic-gate
1345cdf0c1d5Smjnelsonecho "\nBuild project:  $build_project\nBuild taskid:   $build_taskid" | \
1346cdf0c1d5Smjnelson    tee -a $mail_msg_file >> $LOGFILE
1347cdf0c1d5Smjnelson
13487c478bd9Sstevel@tonic-gate# make sure we log only to the nightly build file
13497c478bd9Sstevel@tonic-gatebuild_noise_file="${TMPDIR}/build_noise"
13507c478bd9Sstevel@tonic-gateexec </dev/null >$build_noise_file 2>&1
13517c478bd9Sstevel@tonic-gate
135247703246Ssommerferun_hook SYS_PRE_NIGHTLY
135347703246Ssommerferun_hook PRE_NIGHTLY
135447703246Ssommerfe
13557c478bd9Sstevel@tonic-gateecho "\n==== list of environment variables ====\n" >> $LOGFILE
13567c478bd9Sstevel@tonic-gateenv >> $LOGFILE
13577c478bd9Sstevel@tonic-gate
13587c478bd9Sstevel@tonic-gateecho "\n==== Nightly argument issues ====\n" | tee -a $mail_msg_file >> $LOGFILE
13597c478bd9Sstevel@tonic-gate
13607c478bd9Sstevel@tonic-gateif [ "$N_FLAG" = "y" ]; then
13617c478bd9Sstevel@tonic-gate	if [ "$p_FLAG" = "y" ]; then
13627c478bd9Sstevel@tonic-gate		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
13637c478bd9Sstevel@tonic-gateWARNING: the p option (create packages) is set, but so is the N option (do
13647c478bd9Sstevel@tonic-gate         not run protocmp); this is dangerous; you should unset the N option
13657c478bd9Sstevel@tonic-gateEOF
13667c478bd9Sstevel@tonic-gate	else
13677c478bd9Sstevel@tonic-gate		cat <<EOF | tee -a $mail_msg_file >> $LOGFILE
13687c478bd9Sstevel@tonic-gateWarning: the N option (do not run protocmp) is set; it probably shouldn't be
13697c478bd9Sstevel@tonic-gateEOF
13707c478bd9Sstevel@tonic-gate	fi
13717c478bd9Sstevel@tonic-gate	echo "" | tee -a $mail_msg_file >> $LOGFILE
13727c478bd9Sstevel@tonic-gatefi
13737c478bd9Sstevel@tonic-gate
13747c478bd9Sstevel@tonic-gateif [ "$D_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
13754e5b757fSkupfer	#
13764e5b757fSkupfer	# In the past we just complained but went ahead with the lint
1377ead1f93eSLiane Praza	# pass, even though the proto area was built non-DEBUG.  It's
1378ead1f93eSLiane Praza	# unlikely that non-DEBUG headers will make a difference, but
13794e5b757fSkupfer	# rather than assuming it's a safe combination, force the user
1380ead1f93eSLiane Praza	# to specify a DEBUG build.
13814e5b757fSkupfer	#
13824e5b757fSkupfer	echo "WARNING: DEBUG build not requested; disabling lint.\n" \
13837c478bd9Sstevel@tonic-gate	    | tee -a $mail_msg_file >> $LOGFILE
13844e5b757fSkupfer	l_FLAG=n
13857c478bd9Sstevel@tonic-gatefi
13867c478bd9Sstevel@tonic-gate
13877c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" ]; then
13887c478bd9Sstevel@tonic-gate	if [ "$i_FLAG" = "y" ]; then
13897c478bd9Sstevel@tonic-gate		echo "WARNING: the -f flag cannot be used during incremental" \
13907c478bd9Sstevel@tonic-gate		    "builds; ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13917c478bd9Sstevel@tonic-gate		f_FLAG=n
13927c478bd9Sstevel@tonic-gate	fi
139311a78ea0SMark J. Nelson	if [ "${l_FLAG}${p_FLAG}" != "yy" ]; then
139411a78ea0SMark J. Nelson		echo "WARNING: the -f flag requires -l, and -p;" \
139511a78ea0SMark J. Nelson		    "ignoring -f\n" | tee -a $mail_msg_file >> $LOGFILE
13967c478bd9Sstevel@tonic-gate		f_FLAG=n
13977c478bd9Sstevel@tonic-gate	fi
13987c478bd9Sstevel@tonic-gatefi
13997c478bd9Sstevel@tonic-gate
140096ccc8cbSesaxeif [ "$w_FLAG" = "y" -a ! -d $ROOT ]; then
14014e5b757fSkupfer	echo "WARNING: -w specified, but $ROOT does not exist;" \
140296ccc8cbSesaxe	    "ignoring -w\n" | tee -a $mail_msg_file >> $LOGFILE
140396ccc8cbSesaxe	w_FLAG=n
140496ccc8cbSesaxefi
140596ccc8cbSesaxe
14067c478bd9Sstevel@tonic-gateif [ "$t_FLAG" = "n" ]; then
14077c478bd9Sstevel@tonic-gate	#
14087c478bd9Sstevel@tonic-gate	# We're not doing a tools build, so make sure elfsign(1) is
14097c478bd9Sstevel@tonic-gate	# new enough to safely sign non-crypto binaries.  We test
14107c478bd9Sstevel@tonic-gate	# debugging output from elfsign to detect the old version.
14117c478bd9Sstevel@tonic-gate	#
14127c478bd9Sstevel@tonic-gate	newelfsigntest=`SUNW_CRYPTO_DEBUG=stderr /usr/bin/elfsign verify \
14137c478bd9Sstevel@tonic-gate	    -e /usr/lib/security/pkcs11_softtoken.so.1 2>&1 \
14147c478bd9Sstevel@tonic-gate	    | egrep algorithmOID`
14157c478bd9Sstevel@tonic-gate	if [ -z "$newelfsigntest" ]; then
14167c478bd9Sstevel@tonic-gate		echo "WARNING: /usr/bin/elfsign out of date;" \
14177c478bd9Sstevel@tonic-gate		    "will only sign crypto modules\n" | \
14187c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
14197c478bd9Sstevel@tonic-gate		export ELFSIGN_OBJECT=true
14207c478bd9Sstevel@tonic-gate	elif [ "$VERIFY_ELFSIGN" = "y" ]; then
14217c478bd9Sstevel@tonic-gate		echo "WARNING: VERIFY_ELFSIGN=y requires" \
14227c478bd9Sstevel@tonic-gate		    "the -t flag; ignoring VERIFY_ELFSIGN\n" | \
14237c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
14247c478bd9Sstevel@tonic-gate	fi
14257c478bd9Sstevel@tonic-gatefi
14267c478bd9Sstevel@tonic-gate
14274e5b757fSkupfercase $MULTI_PROTO in
14284e5b757fSkupferyes|no)	;;
14294e5b757fSkupfer*)
14304e5b757fSkupfer	echo "WARNING: MULTI_PROTO is \"$MULTI_PROTO\"; " \
14314e5b757fSkupfer	    "should be \"yes\" or \"no\"." | tee -a $mail_msg_file >> $LOGFILE
14324e5b757fSkupfer	echo "Setting MULTI_PROTO to \"no\".\n" | \
14334e5b757fSkupfer	    tee -a $mail_msg_file >> $LOGFILE
14344e5b757fSkupfer	export MULTI_PROTO=no
14354e5b757fSkupfer	;;
14364e5b757fSkupferesac
14374e5b757fSkupfer
14387c478bd9Sstevel@tonic-gateecho "\n==== Build version ====\n" | tee -a $mail_msg_file >> $LOGFILE
14397c478bd9Sstevel@tonic-gateecho $VERSION | tee -a $mail_msg_file >> $LOGFILE
14407c478bd9Sstevel@tonic-gate
144196ccc8cbSesaxe# Save the current proto area if we're comparing against the last build
144296ccc8cbSesaxeif [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
144396ccc8cbSesaxe    if [ -d "$ROOT.prev" ]; then
144496ccc8cbSesaxe	rm -rf $ROOT.prev
144596ccc8cbSesaxe    fi
144696ccc8cbSesaxe    mv $ROOT $ROOT.prev
144796ccc8cbSesaxefi
144896ccc8cbSesaxe
14494e5b757fSkupfer# Same for non-DEBUG proto area
14504e5b757fSkupferif [ "$w_FLAG" = "y" -a "$MULTI_PROTO" = yes -a -d "$ROOT-nd" ]; then
14514e5b757fSkupfer	if [ -d "$ROOT-nd.prev" ]; then
14524e5b757fSkupfer		rm -rf $ROOT-nd.prev
14534e5b757fSkupfer	fi
14544e5b757fSkupfer	mv $ROOT-nd $ROOT-nd.prev
14554e5b757fSkupferfi
14564e5b757fSkupfer
1457445b6314SRichard Lowe#
1458445b6314SRichard Lowe# Echo the SCM type of the parent workspace, this can't just be which_scm
1459445b6314SRichard Lowe# as that does not know how to identify various network repositories.
1460445b6314SRichard Lowe#
1461445b6314SRichard Lowefunction parent_wstype {
1462445b6314SRichard Lowe	typeset scm_type junk
146330635de9SJohn.Zolnowsky@Sun.COM
146430635de9SJohn.Zolnowsky@Sun.COM	CODEMGR_WS="$BRINGOVER_WS" "$WHICH_SCM" 2>/dev/null \
1465445b6314SRichard Lowe	    | read scm_type junk
1466445b6314SRichard Lowe	if [[ -z "$scm_type" || "$scm_type" == unknown ]]; then
146730635de9SJohn.Zolnowsky@Sun.COM		# Probe BRINGOVER_WS to determine its type
1468c3e6cb59SRichard Lowe		if [[ $BRINGOVER_WS == ssh://* ]]; then
1469445b6314SRichard Lowe			scm_type="mercurial"
147030635de9SJohn.Zolnowsky@Sun.COM		elif [[ $BRINGOVER_WS == http://* ]] && \
1471445b6314SRichard Lowe		    wget -q -O- --save-headers "$BRINGOVER_WS/?cmd=heads" | \
147230635de9SJohn.Zolnowsky@Sun.COM		    egrep -s "application/mercurial" 2> /dev/null; then
1473445b6314SRichard Lowe			scm_type="mercurial"
147430635de9SJohn.Zolnowsky@Sun.COM		else
1475445b6314SRichard Lowe			scm_type="none"
147630635de9SJohn.Zolnowsky@Sun.COM		fi
147730635de9SJohn.Zolnowsky@Sun.COM	fi
147830635de9SJohn.Zolnowsky@Sun.COM
147930635de9SJohn.Zolnowsky@Sun.COM	# fold both unsupported and unrecognized results into "none"
1480445b6314SRichard Lowe	case "$scm_type" in
1481c3e6cb59SRichard Lowe	mercurial)
148230635de9SJohn.Zolnowsky@Sun.COM		;;
1483445b6314SRichard Lowe	*)	scm_type=none
148430635de9SJohn.Zolnowsky@Sun.COM		;;
148530635de9SJohn.Zolnowsky@Sun.COM	esac
148630635de9SJohn.Zolnowsky@Sun.COM
1487445b6314SRichard Lowe	echo $scm_type
148830635de9SJohn.Zolnowsky@Sun.COM}
148930635de9SJohn.Zolnowsky@Sun.COM
1490445b6314SRichard Lowe# Echo the SCM types of $CODEMGR_WS and $BRINGOVER_WS
1491445b6314SRichard Lowefunction child_wstype {
1492445b6314SRichard Lowe	typeset scm_type junk
1493445b6314SRichard Lowe
1494445b6314SRichard Lowe	# Probe CODEMGR_WS to determine its type
1495445b6314SRichard Lowe	if [[ -d $CODEMGR_WS ]]; then
1496445b6314SRichard Lowe		$WHICH_SCM | read scm_type junk || exit 1
1497445b6314SRichard Lowe	fi
1498445b6314SRichard Lowe
1499445b6314SRichard Lowe	case "$scm_type" in
1500c3e6cb59SRichard Lowe	none|git|mercurial)
1501445b6314SRichard Lowe		;;
1502445b6314SRichard Lowe	*)	scm_type=none
1503445b6314SRichard Lowe		;;
1504445b6314SRichard Lowe	esac
1505445b6314SRichard Lowe
1506445b6314SRichard Lowe	echo $scm_type
1507445b6314SRichard Lowe}
1508445b6314SRichard Lowe
15095c70f01eSRichard LoweSCM_TYPE=$(child_wstype)
151030635de9SJohn.Zolnowsky@Sun.COM
15117c478bd9Sstevel@tonic-gate#
15127c478bd9Sstevel@tonic-gate#	Decide whether to clobber
15137c478bd9Sstevel@tonic-gate#
15147c478bd9Sstevel@tonic-gateif [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
15157c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber at `date` ====\n" >> $LOGFILE
15167c478bd9Sstevel@tonic-gate
15177c478bd9Sstevel@tonic-gate	cd $SRC
15187c478bd9Sstevel@tonic-gate	# remove old clobber file
15197c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber.out
15207c478bd9Sstevel@tonic-gate	rm -f $SRC/clobber-${MACH}.out
15217c478bd9Sstevel@tonic-gate
15227c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, just in case we are restarting
15237c478bd9Sstevel@tonic-gate	# the build after having interrupted a previous 'make clobber'.
15248bcea973SRichard Lowe	find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
1525cdf0c1d5Smjnelson		-o -name 'interfaces.*' \) -prune \
15267c478bd9Sstevel@tonic-gate		-o -name '.make.*' -print | xargs rm -f
15277c478bd9Sstevel@tonic-gate
15287c478bd9Sstevel@tonic-gate	$MAKE -ek clobber 2>&1 | tee -a $SRC/clobber-${MACH}.out >> $LOGFILE
15297c478bd9Sstevel@tonic-gate	echo "\n==== Make clobber ERRORS ====\n" >> $mail_msg_file
15307c478bd9Sstevel@tonic-gate	grep "$MAKE:" $SRC/clobber-${MACH}.out |
1531*cb4d1691SRichard Lowe		egrep -v "Ignoring unknown host" | \
1532*cb4d1691SRichard Lowe		tee $TMPDIR/clobber_errs >> $mail_msg_file
1533*cb4d1691SRichard Lowe
1534*cb4d1691SRichard Lowe	if [[ -s $TMPDIR/clobber_errs ]]; then
1535*cb4d1691SRichard Lowe		build_extras_ok=n
1536*cb4d1691SRichard Lowe	fi
15377c478bd9Sstevel@tonic-gate
15385110237aSJosef 'Jeff' Sipek	if [[ "$t_FLAG" = "y" ]]; then
15397c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber at `date` ====\n" >> $LOGFILE
15407c478bd9Sstevel@tonic-gate		cd ${TOOLS}
15417c478bd9Sstevel@tonic-gate		rm -f ${TOOLS}/clobber-${MACH}.out
1542ead1f93eSLiane Praza		$MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber 2>&1 | \
15437c478bd9Sstevel@tonic-gate			tee -a ${TOOLS}/clobber-${MACH}.out >> $LOGFILE
15447c478bd9Sstevel@tonic-gate		echo "\n==== Make tools clobber ERRORS ====\n" \
15457c478bd9Sstevel@tonic-gate			>> $mail_msg_file
15467c478bd9Sstevel@tonic-gate		grep "$MAKE:" ${TOOLS}/clobber-${MACH}.out \
15477c478bd9Sstevel@tonic-gate			>> $mail_msg_file
1548*cb4d1691SRichard Lowe		if (( $? == 0 )); then
1549*cb4d1691SRichard Lowe			build_extras_ok=n
1550*cb4d1691SRichard Lowe		fi
15517c478bd9Sstevel@tonic-gate		rm -rf ${TOOLS_PROTO}
15527c478bd9Sstevel@tonic-gate		mkdir -p ${TOOLS_PROTO}
15537c478bd9Sstevel@tonic-gate	fi
155496ccc8cbSesaxe
1555c7453724SMike Kupfer	typeset roots=$(allprotos)
1556c7453724SMike Kupfer	echo "\n\nClearing $roots" >> "$LOGFILE"
1557c7453724SMike Kupfer	rm -rf $roots
15587c478bd9Sstevel@tonic-gate
15597c478bd9Sstevel@tonic-gate	# Get back to a clean workspace as much as possible to catch
15607c478bd9Sstevel@tonic-gate	# problems that only occur on fresh workspaces.
15617c478bd9Sstevel@tonic-gate	# Remove all .make.state* files, libraries, and .o's that may
1562fb23a357Skupfer	# have been omitted from clobber.  A couple of libraries are
1563cdf0c1d5Smjnelson	# under source code control, so leave them alone.
15647c478bd9Sstevel@tonic-gate	# We should probably blow away temporary directories too.
15657c478bd9Sstevel@tonic-gate	cd $SRC
1566cdf0c1d5Smjnelson	find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
15678bcea973SRichard Lowe	    -o -name .git -o -name 'interfaces.*' \) -prune -o \
15687c478bd9Sstevel@tonic-gate	    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
1569fb23a357Skupfer	       -name '*.o' \) -print | \
1570fb23a357Skupfer	    grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
15717c478bd9Sstevel@tonic-gateelse
15727c478bd9Sstevel@tonic-gate	echo "\n==== No clobber at `date` ====\n" >> $LOGFILE
15737c478bd9Sstevel@tonic-gatefi
15747c478bd9Sstevel@tonic-gate
1575597bd30bSMike Kupfertype bringover_mercurial > /dev/null 2>&1 || function bringover_mercurial {
1576cdf0c1d5Smjnelson	typeset -x PATH=$PATH
1577cdf0c1d5Smjnelson
1578cdf0c1d5Smjnelson	# If the repository doesn't exist yet, then we want to populate it.
1579cdf0c1d5Smjnelson	if [[ ! -d $CODEMGR_WS/.hg ]]; then
1580cdf0c1d5Smjnelson		staffer hg init $CODEMGR_WS
15818cca05f6SMark J. Nelson		staffer echo "[paths]" > $CODEMGR_WS/.hg/hgrc
15828cca05f6SMark J. Nelson		staffer echo "default=$BRINGOVER_WS" >> $CODEMGR_WS/.hg/hgrc
1583f457028bSMark J. Nelson		touch $TMPDIR/new_repository
1584cdf0c1d5Smjnelson	fi
15855c53ea7aSmjnelson
1586cdf0c1d5Smjnelson	typeset -x HGMERGE="/bin/false"
1587cdf0c1d5Smjnelson
1588cdf0c1d5Smjnelson	#
15895c53ea7aSmjnelson	# If the user has changes, regardless of whether those changes are
15905c53ea7aSmjnelson	# committed, and regardless of whether those changes conflict, then
15915c53ea7aSmjnelson	# we'll attempt to merge them either implicitly (uncommitted) or
15925c53ea7aSmjnelson	# explicitly (committed).
1593cdf0c1d5Smjnelson	#
15945c53ea7aSmjnelson	# These are the messages we'll use to help clarify mercurial output
15955c53ea7aSmjnelson	# in those cases.
15965c53ea7aSmjnelson	#
15975c53ea7aSmjnelson	typeset mergefailmsg="\
15985c53ea7aSmjnelson***\n\
15995c53ea7aSmjnelson*** nightly was unable to automatically merge your changes.  You should\n\
16005c53ea7aSmjnelson*** redo the full merge manually, following the steps outlined by mercurial\n\
16015c53ea7aSmjnelson*** above, then restart nightly.\n\
16025c53ea7aSmjnelson***\n"
16035c53ea7aSmjnelson	typeset mergepassmsg="\
16045c53ea7aSmjnelson***\n\
16055c53ea7aSmjnelson*** nightly successfully merged your changes.  This means that your working\n\
16065c53ea7aSmjnelson*** directory has been updated, but those changes are not yet committed.\n\
16075c53ea7aSmjnelson*** After nightly completes, you should validate the results of the merge,\n\
16085c53ea7aSmjnelson*** then use hg commit manually.\n\
16095c53ea7aSmjnelson***\n"
16105c53ea7aSmjnelson
16115c53ea7aSmjnelson	#
16125c53ea7aSmjnelson	# For each repository in turn:
16135c53ea7aSmjnelson	#
16145c53ea7aSmjnelson	# 1. Do the pull.  If this fails, dump the output and bail out.
16155c53ea7aSmjnelson	#
16165c53ea7aSmjnelson	# 2. If the pull resulted in an extra head, do an explicit merge.
16175c53ea7aSmjnelson	#    If this fails, dump the output and bail out.
16185c53ea7aSmjnelson	#
16195c53ea7aSmjnelson	# Because we can't rely on Mercurial to exit with a failure code
16205c53ea7aSmjnelson	# when a merge fails (Mercurial issue #186), we must grep the
16215c53ea7aSmjnelson	# output of pull/merge to check for attempted and/or failed merges.
16225c53ea7aSmjnelson	#
16235c53ea7aSmjnelson	# 3. If a merge failed, set the message and fail the bringover.
16245c53ea7aSmjnelson	#
16255c53ea7aSmjnelson	# 4. Otherwise, if a merge succeeded, set the message
16265c53ea7aSmjnelson	#
16275c53ea7aSmjnelson	# 5. Dump the output, and any message from step 3 or 4.
16285c53ea7aSmjnelson	#
16295c53ea7aSmjnelson
1630f457028bSMark J. Nelson	typeset HG_SOURCE=$BRINGOVER_WS
1631f457028bSMark J. Nelson	if [ ! -f $TMPDIR/new_repository ]; then
1632f457028bSMark J. Nelson		HG_SOURCE=$TMPDIR/open_bundle.hg
1633f457028bSMark J. Nelson		staffer hg --cwd $CODEMGR_WS incoming --bundle $HG_SOURCE \
1634f457028bSMark J. Nelson		    -v $BRINGOVER_WS > $TMPDIR/incoming_open.out
1635f457028bSMark J. Nelson
1636f457028bSMark J. Nelson		#
1637f457028bSMark J. Nelson		# If there are no incoming changesets, then incoming will
1638f457028bSMark J. Nelson		# fail, and there will be no bundle file.  Reset the source,
1639f457028bSMark J. Nelson		# to allow the remaining logic to complete with no false
1640f457028bSMark J. Nelson		# negatives.  (Unlike incoming, pull will return success
1641f457028bSMark J. Nelson		# for the no-change case.)
1642f457028bSMark J. Nelson		#
1643f457028bSMark J. Nelson		if (( $? != 0 )); then
1644f457028bSMark J. Nelson			HG_SOURCE=$BRINGOVER_WS
1645f457028bSMark J. Nelson		fi
1646f457028bSMark J. Nelson	fi
1647f457028bSMark J. Nelson
1648f457028bSMark J. Nelson	staffer hg --cwd $CODEMGR_WS pull -u $HG_SOURCE \
16495c53ea7aSmjnelson	    > $TMPDIR/pull_open.out 2>&1
16505c53ea7aSmjnelson	if (( $? != 0 )); then
16515c53ea7aSmjnelson		printf "%s: pull failed as follows:\n\n" "$CODEMGR_WS"
16525c53ea7aSmjnelson		cat $TMPDIR/pull_open.out
16535c53ea7aSmjnelson		if grep "^merging.*failed" $TMPDIR/pull_open.out > /dev/null 2>&1; then
16545c53ea7aSmjnelson			printf "$mergefailmsg"
16555c53ea7aSmjnelson		fi
16565c53ea7aSmjnelson		touch $TMPDIR/bringover_failed
16575c53ea7aSmjnelson		return
16585c53ea7aSmjnelson	fi
16595c53ea7aSmjnelson
1660cdf0c1d5Smjnelson	if grep "not updating" $TMPDIR/pull_open.out > /dev/null 2>&1; then
16615c53ea7aSmjnelson		staffer hg --cwd $CODEMGR_WS merge \
16625c53ea7aSmjnelson		    >> $TMPDIR/pull_open.out 2>&1
16635c53ea7aSmjnelson		if (( $? != 0 )); then
16645c53ea7aSmjnelson			printf "%s: merge failed as follows:\n\n" \
16655c53ea7aSmjnelson			    "$CODEMGR_WS"
16665c53ea7aSmjnelson			cat $TMPDIR/pull_open.out
16675c53ea7aSmjnelson			if grep "^merging.*failed" $TMPDIR/pull_open.out \
16685c53ea7aSmjnelson			    > /dev/null 2>&1; then
16695c53ea7aSmjnelson				printf "$mergefailmsg"
16705c53ea7aSmjnelson			fi
1671cdf0c1d5Smjnelson			touch $TMPDIR/bringover_failed
16725c53ea7aSmjnelson			return
1673cdf0c1d5Smjnelson		fi
1674cdf0c1d5Smjnelson	fi
16755c53ea7aSmjnelson
16765c53ea7aSmjnelson	printf "updated %s with the following results:\n" "$CODEMGR_WS"
16775c53ea7aSmjnelson	cat $TMPDIR/pull_open.out
16785c53ea7aSmjnelson	if grep "^merging" $TMPDIR/pull_open.out >/dev/null 2>&1; then
16795c53ea7aSmjnelson		printf "$mergepassmsg"
16805c53ea7aSmjnelson	fi
16815c53ea7aSmjnelson	printf "\n"
16825c53ea7aSmjnelson
16835c53ea7aSmjnelson	#
1684f457028bSMark J. Nelson	# Per-changeset output is neither useful nor manageable for a
1685f457028bSMark J. Nelson	# newly-created repository.
1686f457028bSMark J. Nelson	#
1687f457028bSMark J. Nelson	if [ -f $TMPDIR/new_repository ]; then
1688f457028bSMark J. Nelson		return
1689f457028bSMark J. Nelson	fi
1690f457028bSMark J. Nelson
1691f457028bSMark J. Nelson	printf "\nadded the following changesets to open repository:\n"
1692f457028bSMark J. Nelson	cat $TMPDIR/incoming_open.out
1693cdf0c1d5Smjnelson}
1694cdf0c1d5Smjnelson
1695597bd30bSMike Kupfertype bringover_none > /dev/null 2>&1 || function bringover_none {
1696cdf0c1d5Smjnelson	echo "Couldn't figure out what kind of SCM to use for $BRINGOVER_WS."
1697cdf0c1d5Smjnelson	touch $TMPDIR/bringover_failed
1698cdf0c1d5Smjnelson}
1699cdf0c1d5Smjnelson
1700cdf0c1d5Smjnelson#
1701cdf0c1d5Smjnelson#	Decide whether to bringover to the codemgr workspace
1702cdf0c1d5Smjnelson#
1703cdf0c1d5Smjnelsonif [ "$n_FLAG" = "n" ]; then
1704445b6314SRichard Lowe	PARENT_SCM_TYPE=$(parent_wstype)
1705ca0ac982Smjnelson
1706ca0ac982Smjnelson	if [[ $SCM_TYPE != none && $SCM_TYPE != $PARENT_SCM_TYPE ]]; then
1707ca0ac982Smjnelson		echo "cannot bringover from $PARENT_SCM_TYPE to $SCM_TYPE, " \
1708ca0ac982Smjnelson		    "quitting at `date`." | tee -a $mail_msg_file >> $LOGFILE
1709ca0ac982Smjnelson		exit 1
1710ca0ac982Smjnelson	fi
1711ca0ac982Smjnelson
1712cdf0c1d5Smjnelson	run_hook PRE_BRINGOVER
1713cdf0c1d5Smjnelson
1714cdf0c1d5Smjnelson	echo "\n==== bringover to $CODEMGR_WS at `date` ====\n" >> $LOGFILE
1715cdf0c1d5Smjnelson	echo "\n==== BRINGOVER LOG ====\n" >> $mail_msg_file
1716cdf0c1d5Smjnelson
1717ca0ac982Smjnelson	eval "bringover_${PARENT_SCM_TYPE}" 2>&1 |
1718cdf0c1d5Smjnelson		tee -a $mail_msg_file >> $LOGFILE
171932f1e47bSsommerfe
172032f1e47bSsommerfe	if [ -f $TMPDIR/bringover_failed ]; then
172132f1e47bSsommerfe		rm -f $TMPDIR/bringover_failed
172232f1e47bSsommerfe		build_ok=n
172332f1e47bSsommerfe		echo "trouble with bringover, quitting at `date`." |
17247c478bd9Sstevel@tonic-gate			tee -a $mail_msg_file >> $LOGFILE
17257c478bd9Sstevel@tonic-gate		exit 1
17267c478bd9Sstevel@tonic-gate	fi
1727085d331dSkupfer
1728ca0ac982Smjnelson	#
1729ca0ac982Smjnelson	# It's possible that we used the bringover above to create
1730ca0ac982Smjnelson	# $CODEMGR_WS.  If so, then SCM_TYPE was previously "none,"
1731ca0ac982Smjnelson	# but should now be the same as $BRINGOVER_WS.
1732ca0ac982Smjnelson	#
1733ca0ac982Smjnelson	[[ $SCM_TYPE = none ]] && SCM_TYPE=$PARENT_SCM_TYPE
1734ca0ac982Smjnelson
173547703246Ssommerfe	run_hook POST_BRINGOVER
173647703246Ssommerfe
1737c3e6cb59SRichard Lowe	check_closed_bins
1738b83ec4edSjmcp
17397c478bd9Sstevel@tonic-gateelse
17407c478bd9Sstevel@tonic-gate	echo "\n==== No bringover to $CODEMGR_WS ====\n" >> $LOGFILE
17417c478bd9Sstevel@tonic-gatefi
17427c478bd9Sstevel@tonic-gate
1743220399b7SRoland Mainz# Safeguards
1744220399b7SRoland Mainz[[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set."
1745220399b7SRoland Mainz[[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory."
1746220399b7SRoland Mainz[[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found."
1747220399b7SRoland Mainz
1748cdf0c1d5Smjnelsonecho "\n==== Build environment ====\n" | tee -a $build_environ_file >> $LOGFILE
1749cdf0c1d5Smjnelson
1750cdf0c1d5Smjnelson# System
1751cdf0c1d5Smjnelsonwhence uname | tee -a $build_environ_file >> $LOGFILE
1752cdf0c1d5Smjnelsonuname -a 2>&1 | tee -a $build_environ_file >> $LOGFILE
1753cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
1754cdf0c1d5Smjnelson
1755cdf0c1d5Smjnelson# make
1756cdf0c1d5Smjnelsonwhence $MAKE | tee -a $build_environ_file >> $LOGFILE
1757cdf0c1d5Smjnelson$MAKE -v | tee -a $build_environ_file >> $LOGFILE
1758cdf0c1d5Smjnelsonecho "number of concurrent jobs = $DMAKE_MAX_JOBS" |
1759cdf0c1d5Smjnelson    tee -a $build_environ_file >> $LOGFILE
1760cdf0c1d5Smjnelson
1761cdf0c1d5Smjnelson#
1762cdf0c1d5Smjnelson# Report the compiler versions.
1763cdf0c1d5Smjnelson#
1764cdf0c1d5Smjnelson
1765cdf0c1d5Smjnelsonif [[ ! -f $SRC/Makefile ]]; then
1766cdf0c1d5Smjnelson	build_ok=n
1767cdf0c1d5Smjnelson	echo "\nUnable to find \"Makefile\" in $SRC." | \
1768cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
1769cdf0c1d5Smjnelson	exit 1
1770cdf0c1d5Smjnelsonfi
1771cdf0c1d5Smjnelson
1772cdf0c1d5Smjnelson( cd $SRC
1773cdf0c1d5Smjnelson  for target in cc-version cc64-version java-version; do
1774cdf0c1d5Smjnelson	echo
1775cdf0c1d5Smjnelson	#
1776cdf0c1d5Smjnelson	# Put statefile somewhere we know we can write to rather than trip
1777cdf0c1d5Smjnelson	# over a read-only $srcroot.
1778cdf0c1d5Smjnelson	#
1779cdf0c1d5Smjnelson	rm -f $TMPDIR/make-state
1780cdf0c1d5Smjnelson	export SRC
1781cdf0c1d5Smjnelson	if $MAKE -K $TMPDIR/make-state -e $target 2>/dev/null; then
1782cdf0c1d5Smjnelson		continue
1783cdf0c1d5Smjnelson	fi
1784cdf0c1d5Smjnelson	touch $TMPDIR/nocompiler
1785cdf0c1d5Smjnelson  done
1786cdf0c1d5Smjnelson  echo
1787cdf0c1d5Smjnelson) | tee -a $build_environ_file >> $LOGFILE
1788cdf0c1d5Smjnelson
1789cdf0c1d5Smjnelsonif [ -f $TMPDIR/nocompiler ]; then
1790cdf0c1d5Smjnelson	rm -f $TMPDIR/nocompiler
1791cdf0c1d5Smjnelson	build_ok=n
1792cdf0c1d5Smjnelson	echo "Aborting due to missing compiler." |
1793cdf0c1d5Smjnelson		tee -a $build_environ_file >> $LOGFILE
1794cdf0c1d5Smjnelson	exit 1
1795cdf0c1d5Smjnelsonfi
1796cdf0c1d5Smjnelson
1797cdf0c1d5Smjnelson# as
1798cdf0c1d5Smjnelsonwhence as | tee -a $build_environ_file >> $LOGFILE
1799cdf0c1d5Smjnelsonas -V 2>&1 | head -1 | tee -a $build_environ_file >> $LOGFILE
1800cdf0c1d5Smjnelsonecho | tee -a $build_environ_file >> $LOGFILE
1801cdf0c1d5Smjnelson
1802cdf0c1d5Smjnelson# Check that we're running a capable link-editor
1803cdf0c1d5Smjnelsonwhence ld | tee -a $build_environ_file >> $LOGFILE
1804cdf0c1d5SmjnelsonLDVER=`ld -V 2>&1`
1805cdf0c1d5Smjnelsonecho $LDVER | tee -a $build_environ_file >> $LOGFILE
180670087ad3SRichard LoweLDVER=`echo $LDVER | sed -e "s/.*-1\.\([0-9]*\).*/\1/"`
1807cdf0c1d5Smjnelsonif [ `expr $LDVER \< 422` -eq 1 ]; then
1808cdf0c1d5Smjnelson	echo "The link-editor needs to be at version 422 or higher to build" | \
1809cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
1810cdf0c1d5Smjnelson	echo "the latest stuff.  Hope your build works." | \
1811cdf0c1d5Smjnelson	    tee -a $build_environ_file >> $LOGFILE
1812cdf0c1d5Smjnelsonfi
1813cdf0c1d5Smjnelson
18147c478bd9Sstevel@tonic-gate#
18154e5b757fSkupfer# Build and use the workspace's tools if requested
18167c478bd9Sstevel@tonic-gate#
18175110237aSJosef 'Jeff' Sipekif [[ "$t_FLAG" = "y" ]]; then
18184e5b757fSkupfer	set_non_debug_build_flags
18197c478bd9Sstevel@tonic-gate
18207c478bd9Sstevel@tonic-gate	build_tools ${TOOLS_PROTO}
1821*cb4d1691SRichard Lowe	if (( $? != 0 )); then
1822*cb4d1691SRichard Lowe		build_ok=n
1823*cb4d1691SRichard Lowe	else
18244e5b757fSkupfer		use_tools $TOOLS_PROTO
18254e5b757fSkupfer	fi
18267c478bd9Sstevel@tonic-gatefi
18277c478bd9Sstevel@tonic-gate
18284e5b757fSkupfer# timestamp the start of the normal build; the findunref tool uses it.
18294e5b757fSkupfertouch $SRC/.build.tstamp
18304e5b757fSkupfer
18317c478bd9Sstevel@tonic-gatenormal_build
18325d715dd7Skupfer
18337c478bd9Sstevel@tonic-gateORIG_SRC=$SRC
18347c478bd9Sstevel@tonic-gateBINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
18357c478bd9Sstevel@tonic-gate
18367c478bd9Sstevel@tonic-gate
18374e5b757fSkupfer#
18384e5b757fSkupfer# There are several checks that need to look at the proto area, but
18394e5b757fSkupfer# they only need to look at one, and they don't care whether it's
18404e5b757fSkupfer# DEBUG or non-DEBUG.
18414e5b757fSkupfer#
18424e5b757fSkupferif [[ "$MULTI_PROTO" = yes && "$D_FLAG" = n ]]; then
18434e5b757fSkupfer	checkroot=$ROOT-nd
18444e5b757fSkupferelse
18454e5b757fSkupfer	checkroot=$ROOT
18464e5b757fSkupferfi
18474e5b757fSkupfer
18487c478bd9Sstevel@tonic-gateif [ "$build_ok" = "y" ]; then
18497c478bd9Sstevel@tonic-gate	echo "\n==== Creating protolist system file at `date` ====" \
18507c478bd9Sstevel@tonic-gate		>> $LOGFILE
18514e5b757fSkupfer	protolist $checkroot > $ATLOG/proto_list_${MACH}
18527c478bd9Sstevel@tonic-gate	echo "==== protolist system file created at `date` ====\n" \
18537c478bd9Sstevel@tonic-gate		>> $LOGFILE
18547c478bd9Sstevel@tonic-gate
18557c478bd9Sstevel@tonic-gate	if [ "$N_FLAG" != "y" ]; then
18567c478bd9Sstevel@tonic-gate
1857ead1f93eSLiane Praza		E1=
1858ead1f93eSLiane Praza		f1=
1859ead1f93eSLiane Praza		for f in $f1; do
1860ead1f93eSLiane Praza			if [ -f "$f" ]; then
1861ead1f93eSLiane Praza				E1="$E1 -e $f"
1862ead1f93eSLiane Praza			fi
1863ead1f93eSLiane Praza		done
1864ead1f93eSLiane Praza
1865ead1f93eSLiane Praza		E2=
1866ead1f93eSLiane Praza		f2=
1867ead1f93eSLiane Praza		if [ -d "$SRC/pkg" ]; then
1868ead1f93eSLiane Praza			f2="$f2 exceptions/packaging"
1869ead1f93eSLiane Praza		fi
1870ead1f93eSLiane Praza
1871ead1f93eSLiane Praza		for f in $f2; do
1872ead1f93eSLiane Praza			if [ -f "$f" ]; then
1873ead1f93eSLiane Praza				E2="$E2 -e $f"
1874ead1f93eSLiane Praza			fi
1875ead1f93eSLiane Praza		done
1876ead1f93eSLiane Praza	fi
1877ead1f93eSLiane Praza
1878ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -d $SRC/pkg ]; then
1879ead1f93eSLiane Praza		echo "\n==== Validating manifests against proto area ====\n" \
1880ead1f93eSLiane Praza		    >> $mail_msg_file
1881*cb4d1691SRichard Lowe		( cd $SRC/pkg ; $MAKE -e protocmp ROOT="$checkroot" ) | \
1882*cb4d1691SRichard Lowe		    tee $TMPDIR/protocmp_noise >> $mail_msg_file
1883*cb4d1691SRichard Lowe		if [[ -s $TMPDIR/protocmp_noise ]]; then
1884*cb4d1691SRichard Lowe			build_extras_ok=n
1885*cb4d1691SRichard Lowe		fi
1886ead1f93eSLiane Praza	fi
1887ead1f93eSLiane Praza
1888ead1f93eSLiane Praza	if [ "$N_FLAG" != "y" -a -f "$REF_PROTO_LIST" ]; then
1889ead1f93eSLiane Praza		echo "\n==== Impact on proto area ====\n" >> $mail_msg_file
1890ead1f93eSLiane Praza		if [ -n "$E2" ]; then
1891ead1f93eSLiane Praza			ELIST=$E2
1892ead1f93eSLiane Praza		else
1893ead1f93eSLiane Praza			ELIST=$E1
1894ead1f93eSLiane Praza		fi
18957c478bd9Sstevel@tonic-gate		$PROTOCMPTERSE \
18967c478bd9Sstevel@tonic-gate			"Files in yesterday's proto area, but not today's:" \
18977c478bd9Sstevel@tonic-gate			"Files in today's proto area, but not yesterday's:" \
18987c478bd9Sstevel@tonic-gate			"Files that changed between yesterday and today:" \
18997c478bd9Sstevel@tonic-gate			${ELIST} \
19007c478bd9Sstevel@tonic-gate			-d $REF_PROTO_LIST \
19017c478bd9Sstevel@tonic-gate			$ATLOG/proto_list_${MACH} \
19027c478bd9Sstevel@tonic-gate			>> $mail_msg_file
19037c478bd9Sstevel@tonic-gate	fi
19047c478bd9Sstevel@tonic-gatefi
19057c478bd9Sstevel@tonic-gate
1906*cb4d1691SRichard Loweif [[ "$u_FLAG" == "y" && "$build_ok" == "y" && \
1907*cb4d1691SRichard Lowe    "$build_extras_ok" == "y" ]]; then
19087c478bd9Sstevel@tonic-gate	staffer cp $ATLOG/proto_list_${MACH} \
19097c478bd9Sstevel@tonic-gate		$PARENT_WS/usr/src/proto_list_${MACH}
19107c478bd9Sstevel@tonic-gatefi
19117c478bd9Sstevel@tonic-gate
19127c478bd9Sstevel@tonic-gate# Update parent proto area if necessary. This is done now
19137c478bd9Sstevel@tonic-gate# so that the proto area has either DEBUG or non-DEBUG kernels.
19147c478bd9Sstevel@tonic-gate# Note that this clears out the lock file, so we can dispense with
19157c478bd9Sstevel@tonic-gate# the variable now.
19167c478bd9Sstevel@tonic-gateif [ "$U_FLAG" = "y" -a "$build_ok" = "y" ]; then
19177c478bd9Sstevel@tonic-gate	echo "\n==== Copying proto area to $NIGHTLY_PARENT_ROOT ====\n" | \
19187c478bd9Sstevel@tonic-gate	    tee -a $LOGFILE >> $mail_msg_file
1919ead1f93eSLiane Praza	rm -rf $NIGHTLY_PARENT_ROOT/*
19207c478bd9Sstevel@tonic-gate	unset Ulockfile
19217c478bd9Sstevel@tonic-gate	mkdir -p $NIGHTLY_PARENT_ROOT
19224e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
1923ead1f93eSLiane Praza		( cd $ROOT; tar cf - . |
19244e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT;  umask 0; tar xpf - ) ) 2>&1 |
19257c478bd9Sstevel@tonic-gate		    tee -a $mail_msg_file >> $LOGFILE
19267c478bd9Sstevel@tonic-gate	fi
19274e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
1928ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_ROOT-nd/*
19294e5b757fSkupfer		mkdir -p $NIGHTLY_PARENT_ROOT-nd
19304e5b757fSkupfer		cd $ROOT-nd
19314e5b757fSkupfer		( tar cf - . |
19324e5b757fSkupfer		    ( cd $NIGHTLY_PARENT_ROOT-nd; umask 0; tar xpf - ) ) 2>&1 |
19334e5b757fSkupfer		    tee -a $mail_msg_file >> $LOGFILE
19344e5b757fSkupfer	fi
19356798c3f0SMark J. Nelson	if [ -n "${NIGHTLY_PARENT_TOOLS_ROOT}" ]; then
1936ead1f93eSLiane Praza		echo "\n==== Copying tools proto area to $NIGHTLY_PARENT_TOOLS_ROOT ====\n" | \
1937ead1f93eSLiane Praza		    tee -a $LOGFILE >> $mail_msg_file
1938ead1f93eSLiane Praza		rm -rf $NIGHTLY_PARENT_TOOLS_ROOT/*
1939ead1f93eSLiane Praza		mkdir -p $NIGHTLY_PARENT_TOOLS_ROOT
1940ead1f93eSLiane Praza		if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
1941ead1f93eSLiane Praza			( cd $TOOLS_PROTO; tar cf - . |
19426798c3f0SMark J. Nelson			    ( cd $NIGHTLY_PARENT_TOOLS_ROOT;
19436798c3f0SMark J. Nelson			    umask 0; tar xpf - ) ) 2>&1 |
1944ead1f93eSLiane Praza			    tee -a $mail_msg_file >> $LOGFILE
1945ead1f93eSLiane Praza		fi
19464e5b757fSkupfer	fi
19476798c3f0SMark J. Nelsonfi
19487c478bd9Sstevel@tonic-gate
19497c478bd9Sstevel@tonic-gate#
195075ce41a5SAli Bahrami# ELF verification: ABI (-A) and runtime (-r) checks
19517c478bd9Sstevel@tonic-gate#
195275ce41a5SAli Bahramiif [[ ($build_ok = y) && (($A_FLAG = y) || ($r_FLAG = y)) ]]; then
195375ce41a5SAli Bahrami	# Directory ELF-data.$MACH holds the files produced by these tests.
195475ce41a5SAli Bahrami	elf_ddir=$SRC/ELF-data.$MACH
19557c478bd9Sstevel@tonic-gate
195675ce41a5SAli Bahrami	# If there is a previous ELF-data backup directory, remove it. Then,
195775ce41a5SAli Bahrami	# rotate current ELF-data directory into its place and create a new
195875ce41a5SAli Bahrami	# empty directory
195975ce41a5SAli Bahrami	rm -rf $elf_ddir.ref
196075ce41a5SAli Bahrami	if [[ -d $elf_ddir ]]; then
196175ce41a5SAli Bahrami		mv $elf_ddir $elf_ddir.ref
196275ce41a5SAli Bahrami	fi
196375ce41a5SAli Bahrami	mkdir -p $elf_ddir
196475ce41a5SAli Bahrami
196575ce41a5SAli Bahrami	# Call find_elf to produce a list of the ELF objects in the proto area.
196675ce41a5SAli Bahrami	# This list is passed to check_rtime and interface_check, preventing
196775ce41a5SAli Bahrami	# them from separately calling find_elf to do the same work twice.
196875ce41a5SAli Bahrami	find_elf -fr $checkroot > $elf_ddir/object_list
196975ce41a5SAli Bahrami
197075ce41a5SAli Bahrami	if [[ $A_FLAG = y ]]; then
19717c478bd9Sstevel@tonic-gate	       	echo "\n==== Check versioning and ABI information ====\n"  | \
19727c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
19737c478bd9Sstevel@tonic-gate
197475ce41a5SAli Bahrami		# Produce interface description for the proto. Report errors.
197575ce41a5SAli Bahrami		interface_check -o -w $elf_ddir -f object_list \
197675ce41a5SAli Bahrami			-i interface -E interface.err
197775ce41a5SAli Bahrami		if [[ -s $elf_ddir/interface.err ]]; then
197875ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/interface.err \
197975ce41a5SAli Bahrami			    >> $mail_msg_file
1980*cb4d1691SRichard Lowe			build_extras_ok=n
19817c478bd9Sstevel@tonic-gate		fi
19827c478bd9Sstevel@tonic-gate
19835253169eSAli Bahrami		# If ELF_DATA_BASELINE_DIR is defined, compare the new interface
19845253169eSAli Bahrami		# description file to that from the baseline gate. Issue a
19855253169eSAli Bahrami		# warning if the baseline is not present, and keep going.
19865253169eSAli Bahrami		if [[ "$ELF_DATA_BASELINE_DIR" != '' ]]; then
19875253169eSAli Bahrami			base_ifile="$ELF_DATA_BASELINE_DIR/interface"
19887c478bd9Sstevel@tonic-gate
19895253169eSAli Bahrami		       	echo "\n==== Compare versioning and ABI information" \
1990e599109eSAli Bahrami			    "to baseline ====\n"  | \
19915253169eSAli Bahrami			    tee -a $LOGFILE >> $mail_msg_file
1992e599109eSAli Bahrami		       	echo "Baseline:  $base_ifile\n" >> $LOGFILE
19935253169eSAli Bahrami
19945253169eSAli Bahrami			if [[ -f $base_ifile ]]; then
19955253169eSAli Bahrami				interface_cmp -d -o $base_ifile \
199675ce41a5SAli Bahrami				    $elf_ddir/interface > $elf_ddir/interface.cmp
199775ce41a5SAli Bahrami				if [[ -s $elf_ddir/interface.cmp ]]; then
19985253169eSAli Bahrami					echo | tee -a $LOGFILE >> $mail_msg_file
19995253169eSAli Bahrami					tee -a $LOGFILE < \
20005253169eSAli Bahrami					    $elf_ddir/interface.cmp \
200175ce41a5SAli Bahrami					    >> $mail_msg_file
2002*cb4d1691SRichard Lowe					build_extras_ok=n
20037c478bd9Sstevel@tonic-gate				fi
20045253169eSAli Bahrami			else
20055253169eSAli Bahrami			       	echo "baseline not available. comparison" \
20065253169eSAli Bahrami                                    "skipped" | \
20075253169eSAli Bahrami				    tee -a $LOGFILE >> $mail_msg_file
20085253169eSAli Bahrami			fi
20095253169eSAli Bahrami
20105253169eSAli Bahrami		fi
20117c478bd9Sstevel@tonic-gate	fi
20127c478bd9Sstevel@tonic-gate
201375ce41a5SAli Bahrami	if [[ $r_FLAG = y ]]; then
20147c478bd9Sstevel@tonic-gate		echo "\n==== Check ELF runtime attributes ====\n" | \
20157c478bd9Sstevel@tonic-gate		    tee -a $LOGFILE >> $mail_msg_file
20167c478bd9Sstevel@tonic-gate
2017ead1f93eSLiane Praza		# If we're doing a DEBUG build the proto area will be left
201875ce41a5SAli Bahrami		# with debuggable objects, thus don't assert -s.
201975ce41a5SAli Bahrami		if [[ $D_FLAG = y ]]; then
20207c478bd9Sstevel@tonic-gate			rtime_sflag=""
20217c478bd9Sstevel@tonic-gate		else
20227c478bd9Sstevel@tonic-gate			rtime_sflag="-s"
20237c478bd9Sstevel@tonic-gate		fi
202475ce41a5SAli Bahrami		check_rtime -i -m -v $rtime_sflag -o -w $elf_ddir \
202575ce41a5SAli Bahrami			-D object_list  -f object_list -E runtime.err \
2026622090e3SAli Bahrami			-I runtime.attr.raw
2027*cb4d1691SRichard Lowe		if (( $? != 0 )); then
2028*cb4d1691SRichard Lowe			build_extras_ok=n
2029*cb4d1691SRichard Lowe		fi
2030622090e3SAli Bahrami
2031622090e3SAli Bahrami		# check_rtime -I output needs to be sorted in order to
2032622090e3SAli Bahrami		# compare it to that from previous builds.
2033622090e3SAli Bahrami		sort $elf_ddir/runtime.attr.raw > $elf_ddir/runtime.attr
2034622090e3SAli Bahrami		rm $elf_ddir/runtime.attr.raw
20357c478bd9Sstevel@tonic-gate
203675ce41a5SAli Bahrami		# Report errors
203775ce41a5SAli Bahrami		if [[ -s $elf_ddir/runtime.err ]]; then
203875ce41a5SAli Bahrami			tee -a $LOGFILE < $elf_ddir/runtime.err \
20397c478bd9Sstevel@tonic-gate				>> $mail_msg_file
2040*cb4d1691SRichard Lowe			build_extras_ok=n
204175ce41a5SAli Bahrami		fi
20427c478bd9Sstevel@tonic-gate
204375ce41a5SAli Bahrami		# If there is an ELF-data directory from a previous build,
204475ce41a5SAli Bahrami		# then diff the attr files. These files contain information
204575ce41a5SAli Bahrami		# about dependencies, versioning, and runpaths. There is some
204675ce41a5SAli Bahrami		# overlap with the ABI checking done above, but this also
204775ce41a5SAli Bahrami		# flushes out non-ABI interface differences along with the
204875ce41a5SAli Bahrami		# other information.
204975ce41a5SAli Bahrami		echo "\n==== Diff ELF runtime attributes" \
205075ce41a5SAli Bahrami		    "(since last build) ====\n" | \
205175ce41a5SAli Bahrami		    tee -a $LOGFILE >> $mail_msg_file >> $mail_msg_file
205275ce41a5SAli Bahrami
205375ce41a5SAli Bahrami		if [[ -f $elf_ddir.ref/runtime.attr ]]; then
205475ce41a5SAli Bahrami			diff $elf_ddir.ref/runtime.attr \
205575ce41a5SAli Bahrami				$elf_ddir/runtime.attr \
205675ce41a5SAli Bahrami				>> $mail_msg_file
205775ce41a5SAli Bahrami		fi
205875ce41a5SAli Bahrami	fi
20595253169eSAli Bahrami
20605253169eSAli Bahrami	# If -u set, copy contents of ELF-data.$MACH to the parent workspace.
20615253169eSAli Bahrami	if [[ "$u_FLAG" = "y" ]]; then
20625253169eSAli Bahrami		p_elf_ddir=$PARENT_WS/usr/src/ELF-data.$MACH
20635253169eSAli Bahrami
20645253169eSAli Bahrami		# If parent lacks the ELF-data.$MACH directory, create it
20655253169eSAli Bahrami		if [[ ! -d $p_elf_ddir ]]; then
20665253169eSAli Bahrami			staffer mkdir -p $p_elf_ddir
20675253169eSAli Bahrami		fi
20685253169eSAli Bahrami
20695253169eSAli Bahrami		# These files are used asynchronously by other builds for ABI
20705253169eSAli Bahrami		# verification, as above for the -A option. As such, we require
20715253169eSAli Bahrami		# the file replacement to be atomic. Copy the data to a temp
20725253169eSAli Bahrami		# file in the same filesystem and then rename into place.
20735253169eSAli Bahrami		(
20745253169eSAli Bahrami			cd $elf_ddir
20755253169eSAli Bahrami			for elf_dfile in *; do
20765253169eSAli Bahrami				staffer cp $elf_dfile \
20775253169eSAli Bahrami				    ${p_elf_ddir}/${elf_dfile}.new
20785253169eSAli Bahrami				staffer mv -f ${p_elf_ddir}/${elf_dfile}.new \
20795253169eSAli Bahrami				    ${p_elf_ddir}/${elf_dfile}
20805253169eSAli Bahrami			done
20815253169eSAli Bahrami		)
20825253169eSAli Bahrami	fi
20837c478bd9Sstevel@tonic-gatefi
20847c478bd9Sstevel@tonic-gate
20857c478bd9Sstevel@tonic-gate# DEBUG lint of kernel begins
20867c478bd9Sstevel@tonic-gate
20877c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$l_FLAG" = "y" ]; then
20887c478bd9Sstevel@tonic-gate	if [ "$LINTDIRS" = "" ]; then
20897c478bd9Sstevel@tonic-gate		# LINTDIRS="$SRC/uts y $SRC/stand y $SRC/psm y"
20907c478bd9Sstevel@tonic-gate		LINTDIRS="$SRC y"
20917c478bd9Sstevel@tonic-gate	fi
20927c478bd9Sstevel@tonic-gate	set $LINTDIRS
20937c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
20947c478bd9Sstevel@tonic-gate		dolint $1 $2; shift; shift
20957c478bd9Sstevel@tonic-gate	done
20967c478bd9Sstevel@tonic-gateelse
20977c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE lint' ====\n" >> $LOGFILE
20987c478bd9Sstevel@tonic-gatefi
20997c478bd9Sstevel@tonic-gate
21007c478bd9Sstevel@tonic-gate# "make check" begins
21017c478bd9Sstevel@tonic-gate
21027c478bd9Sstevel@tonic-gateif [ "$i_CMD_LINE_FLAG" = "n" -a "$C_FLAG" = "y" ]; then
21037c478bd9Sstevel@tonic-gate	# remove old check.out
21047c478bd9Sstevel@tonic-gate	rm -f $SRC/check.out
21057c478bd9Sstevel@tonic-gate
21067c478bd9Sstevel@tonic-gate	rm -f $SRC/check-${MACH}.out
21077c478bd9Sstevel@tonic-gate	cd $SRC
2108170832d3SAlbert Lee	$MAKE -ek check ROOT="$checkroot" 2>&1 | tee -a $SRC/check-${MACH}.out \
2109170832d3SAlbert Lee	    >> $LOGFILE
21107c478bd9Sstevel@tonic-gate	echo "\n==== cstyle/hdrchk errors ====\n" >> $mail_msg_file
21117c478bd9Sstevel@tonic-gate
21127c478bd9Sstevel@tonic-gate	grep ":" $SRC/check-${MACH}.out |
21137c478bd9Sstevel@tonic-gate		egrep -v "Ignoring unknown host" | \
2114*cb4d1691SRichard Lowe		sort | uniq | tee $TMPDIR/check_errors >> $mail_msg_file
2115*cb4d1691SRichard Lowe
2116*cb4d1691SRichard Lowe	if [[ -s $TMPDIR/check_errors ]]; then
2117*cb4d1691SRichard Lowe		build_extras_ok=n
2118*cb4d1691SRichard Lowe	fi
21197c478bd9Sstevel@tonic-gateelse
21207c478bd9Sstevel@tonic-gate	echo "\n==== No '$MAKE check' ====\n" >> $LOGFILE
21217c478bd9Sstevel@tonic-gatefi
21227c478bd9Sstevel@tonic-gate
21237c478bd9Sstevel@tonic-gateecho "\n==== Find core files ====\n" | \
21247c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $mail_msg_file
21257c478bd9Sstevel@tonic-gate
2126fb23a357Skupferfind $abssrcdirs -name core -a -type f -exec file {} \; | \
21277c478bd9Sstevel@tonic-gate	tee -a $LOGFILE >> $mail_msg_file
21287c478bd9Sstevel@tonic-gate
21297c478bd9Sstevel@tonic-gateif [ "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
21307c478bd9Sstevel@tonic-gate	echo "\n==== Diff unreferenced files (since last build) ====\n" \
21317c478bd9Sstevel@tonic-gate	    | tee -a $LOGFILE >>$mail_msg_file
21327c478bd9Sstevel@tonic-gate	rm -f $SRC/unref-${MACH}.ref
21337c478bd9Sstevel@tonic-gate	if [ -f $SRC/unref-${MACH}.out ]; then
21347c478bd9Sstevel@tonic-gate		mv $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21357c478bd9Sstevel@tonic-gate	fi
21367c478bd9Sstevel@tonic-gate
21379730304dSmeem	findunref -S $SCM_TYPE -t $SRC/.build.tstamp -s usr $CODEMGR_WS \
2138cdf0c1d5Smjnelson	    ${TOOLS}/findunref/exception_list 2>> $mail_msg_file | \
21399730304dSmeem	    sort > $SRC/unref-${MACH}.out
21407c478bd9Sstevel@tonic-gate
21417c478bd9Sstevel@tonic-gate	if [ ! -f $SRC/unref-${MACH}.ref ]; then
21427c478bd9Sstevel@tonic-gate		cp $SRC/unref-${MACH}.out $SRC/unref-${MACH}.ref
21437c478bd9Sstevel@tonic-gate	fi
21447c478bd9Sstevel@tonic-gate
21457c478bd9Sstevel@tonic-gate	diff $SRC/unref-${MACH}.ref $SRC/unref-${MACH}.out >>$mail_msg_file
21467c478bd9Sstevel@tonic-gatefi
21477c478bd9Sstevel@tonic-gate
21487c478bd9Sstevel@tonic-gate# Verify that the usual lists of files, such as exception lists,
21497c478bd9Sstevel@tonic-gate# contain only valid references to files.  If the build has failed,
21507c478bd9Sstevel@tonic-gate# then don't check the proto area.
21517c478bd9Sstevel@tonic-gateCHECK_PATHS=${CHECK_PATHS:-y}
21527c478bd9Sstevel@tonic-gateif [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
21537c478bd9Sstevel@tonic-gate	echo "\n==== Check lists of files ====\n" | tee -a $LOGFILE \
21547c478bd9Sstevel@tonic-gate		>>$mail_msg_file
21557c478bd9Sstevel@tonic-gate	arg=-b
21567c478bd9Sstevel@tonic-gate	[ "$build_ok" = y ] && arg=
2157*cb4d1691SRichard Lowe	checkpaths $arg $checkroot > $SRC/checkpaths.out 2>&1
2158*cb4d1691SRichard Lowe	if [[ -s $SRC/checkpaths.out ]]; then
2159*cb4d1691SRichard Lowe		tee -a $LOGFILE < $SRC/checkpaths.out >> $mail_msg_file
2160*cb4d1691SRichard Lowe		build_extras_ok=n
2161*cb4d1691SRichard Lowe	fi
21627c478bd9Sstevel@tonic-gatefi
21637c478bd9Sstevel@tonic-gate
21647c478bd9Sstevel@tonic-gateif [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
21657c478bd9Sstevel@tonic-gate	echo "\n==== Impact on file permissions ====\n" \
21667c478bd9Sstevel@tonic-gate		>> $mail_msg_file
2167ead1f93eSLiane Praza
2168ead1f93eSLiane Praza	abspkg=
2169ead1f93eSLiane Praza	for d in $abssrcdirs; do
2170ead1f93eSLiane Praza		if [ -d "$d/pkg" ]; then
2171ead1f93eSLiane Praza			abspkg="$abspkg $d"
2172ead1f93eSLiane Praza		fi
2173ead1f93eSLiane Praza	done
2174ead1f93eSLiane Praza
2175ead1f93eSLiane Praza	if [ -n "$abspkg" ]; then
2176ead1f93eSLiane Praza		for d in "$abspkg"; do
2177ead1f93eSLiane Praza			( cd $d/pkg ; $MAKE -e pmodes ) >> $mail_msg_file
2178ead1f93eSLiane Praza		done
2179ead1f93eSLiane Praza	fi
21807c478bd9Sstevel@tonic-gatefi
21817c478bd9Sstevel@tonic-gate
218296ccc8cbSesaxeif [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
21834e5b757fSkupfer	if [[ "$MULTI_PROTO" = no || "$D_FLAG" = y ]]; then
21844e5b757fSkupfer		do_wsdiff DEBUG $ROOT.prev $ROOT
21854e5b757fSkupfer	fi
218696ccc8cbSesaxe
21874e5b757fSkupfer	if [[ "$MULTI_PROTO" = yes && "$F_FLAG" = n ]]; then
21884e5b757fSkupfer		do_wsdiff non-DEBUG $ROOT-nd.prev $ROOT-nd
218996ccc8cbSesaxe	fi
219096ccc8cbSesaxefi
219196ccc8cbSesaxe
21927c478bd9Sstevel@tonic-gateEND_DATE=`date`
21937c478bd9Sstevel@tonic-gateecho "==== Nightly $maketype build completed: $END_DATE ====" | \
21947c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
21957c478bd9Sstevel@tonic-gate
2196c341b28aSDarren Moffattypeset -i10 hours
21977c478bd9Sstevel@tonic-gatetypeset -Z2 minutes
21987c478bd9Sstevel@tonic-gatetypeset -Z2 seconds
21997c478bd9Sstevel@tonic-gate
22007c478bd9Sstevel@tonic-gateelapsed_time=$SECONDS
22017c478bd9Sstevel@tonic-gate((hours = elapsed_time / 3600 ))
22027c478bd9Sstevel@tonic-gate((minutes = elapsed_time / 60  % 60))
22037c478bd9Sstevel@tonic-gate((seconds = elapsed_time % 60))
22047c478bd9Sstevel@tonic-gate
22057c478bd9Sstevel@tonic-gateecho "\n==== Total build time ====" | \
22067c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
22077c478bd9Sstevel@tonic-gateecho "\nreal    ${hours}:${minutes}:${seconds}" | \
22087c478bd9Sstevel@tonic-gate    tee -a $LOGFILE >> $build_time_file
22097c478bd9Sstevel@tonic-gate
22107c478bd9Sstevel@tonic-gateif [ "$u_FLAG" = "y" -a "$f_FLAG" = "y" -a "$build_ok" = "y" ]; then
22117c478bd9Sstevel@tonic-gate	staffer cp ${SRC}/unref-${MACH}.out $PARENT_WS/usr/src/
22127c478bd9Sstevel@tonic-gate
22137c478bd9Sstevel@tonic-gate	#
22147c478bd9Sstevel@tonic-gate	# Produce a master list of unreferenced files -- ideally, we'd
22157c478bd9Sstevel@tonic-gate	# generate the master just once after all of the nightlies
22167c478bd9Sstevel@tonic-gate	# have finished, but there's no simple way to know when that
22177c478bd9Sstevel@tonic-gate	# will be.  Instead, we assume that we're the last nightly to
22187c478bd9Sstevel@tonic-gate	# finish and merge all of the unref-${MACH}.out files in
22197c478bd9Sstevel@tonic-gate	# $PARENT_WS/usr/src/.  If we are in fact the final ${MACH} to
22207c478bd9Sstevel@tonic-gate	# finish, then this file will be the authoritative master
22217c478bd9Sstevel@tonic-gate	# list.  Otherwise, another ${MACH}'s nightly will eventually
22227c478bd9Sstevel@tonic-gate	# overwrite ours with its own master, but in the meantime our
22237c478bd9Sstevel@tonic-gate	# temporary "master" will be no worse than any older master
22247c478bd9Sstevel@tonic-gate	# which was already on the parent.
22257c478bd9Sstevel@tonic-gate	#
22267c478bd9Sstevel@tonic-gate
22277c478bd9Sstevel@tonic-gate	set -- $PARENT_WS/usr/src/unref-*.out
22287c478bd9Sstevel@tonic-gate	cp "$1" ${TMPDIR}/unref.merge
22297c478bd9Sstevel@tonic-gate	shift
22307c478bd9Sstevel@tonic-gate
22317c478bd9Sstevel@tonic-gate	for unreffile; do
22327c478bd9Sstevel@tonic-gate		comm -12 ${TMPDIR}/unref.merge "$unreffile" > ${TMPDIR}/unref.$$
22337c478bd9Sstevel@tonic-gate		mv ${TMPDIR}/unref.$$ ${TMPDIR}/unref.merge
22347c478bd9Sstevel@tonic-gate	done
22357c478bd9Sstevel@tonic-gate
22367c478bd9Sstevel@tonic-gate	staffer cp ${TMPDIR}/unref.merge $PARENT_WS/usr/src/unrefmaster.out
22377c478bd9Sstevel@tonic-gatefi
22387c478bd9Sstevel@tonic-gate
22397c478bd9Sstevel@tonic-gate#
22407c478bd9Sstevel@tonic-gate# All done save for the sweeping up.
22417c478bd9Sstevel@tonic-gate# (whichever exit we hit here will trigger the "cleanup" trap which
22427c478bd9Sstevel@tonic-gate# optionally sends mail on completion).
22437c478bd9Sstevel@tonic-gate#
2244*cb4d1691SRichard Loweif [[ "$build_ok" == "y" ]]; then
2245*cb4d1691SRichard Lowe	if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
22467c478bd9Sstevel@tonic-gate		exit 0
22477c478bd9Sstevel@tonic-gate	fi
2248*cb4d1691SRichard Lowefi
2249*cb4d1691SRichard Lowe
22507c478bd9Sstevel@tonic-gateexit 1
2251