changeset 2947:490e4976e8af

6374716 need way to simulate OpenSolaris build 6472788 nightly(1) list of tasks has malformatted item
author kupfer
date Thu, 19 Oct 2006 19:27:06 -0700
parents 2211d99f898b
children c89bd1dbe6d0
files usr/src/tools/SUNWonbld/prototype_com usr/src/tools/env/developer.sh usr/src/tools/env/gatekeeper.sh usr/src/tools/env/opensolaris.sh usr/src/tools/scripts/Makefile usr/src/tools/scripts/bldenv.1 usr/src/tools/scripts/bldenv.sh usr/src/tools/scripts/mkclosed.sh usr/src/tools/scripts/nightly.1 usr/src/tools/scripts/nightly.sh usr/src/tools/scripts/stdenv.sh
diffstat 11 files changed, 393 insertions(+), 218 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/tools/SUNWonbld/prototype_com	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/SUNWonbld/prototype_com	Thu Oct 19 19:27:06 2006 -0700
@@ -79,6 +79,7 @@
 f none opt/onbld/bin/make_pkg_db 555 root bin
 f none opt/onbld/bin/mkacr 555 root bin
 f none opt/onbld/bin/mkbfu 555 root bin
+f none opt/onbld/bin/mkclosed 555 root bin
 f none opt/onbld/bin/nightly 555 root bin
 f none opt/onbld/bin/protocmp.terse 555 root bin
 f none opt/onbld/bin/sccscheck 555 root bin
--- a/usr/src/tools/env/developer.sh	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/env/developer.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -103,16 +103,6 @@
 SRC="$CODEMGR_WS/usr/src";         	export SRC
 VERSION="$GATE";			export VERSION
 
-# the source product has no SCCS history, and is modified to remove source
-# that cannot be shipped. EXPORT_SRC is where the clear files are copied, then
-# modified with 'make EXPORT_SRC'.
-EXPORT_SRC="$CODEMGR_WS/export_src";    export EXPORT_SRC
-
-# CRYPT_SRC is similar to EXPORT_SRC, but after 'make CRYPT_SRC' the files in
-# xmod/cry_files are saved. They are dropped on the exportable source to create
-# the domestic build.
-CRYPT_SRC="$CODEMGR_WS/crypt_src";      export CRYPT_SRC
-
 #
 # the RELEASE and RELEASE_DATE variables are set in Makefile.master;
 # there might be special reasons to override them here, but that
--- a/usr/src/tools/env/gatekeeper.sh	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/env/gatekeeper.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -113,16 +113,6 @@
 SRC="$CODEMGR_WS/usr/src";         	export SRC
 VERSION="$GATE";			export VERSION
 
-# the source product has no SCCS history, and is modified to remove source
-# that cannot be shipped. EXPORT_SRC is where the clear files are copied, then
-# modified with 'make EXPORT_SRC'.
-EXPORT_SRC="$CODEMGR_WS/export_src";    export EXPORT_SRC
-
-# CRYPT_SRC is similar to EXPORT_SRC, but after 'make CRYPT_SRC' the files in
-# xmod/cry_files are saved. They are dropped on the exportable source to create
-# the domestic build.
-CRYPT_SRC="$CODEMGR_WS/crypt_src";      export CRYPT_SRC
-
 #
 # the RELEASE and RELEASE_DATE variables are set in Makefile.master;
 # there might be special reasons to override them here, but that
--- a/usr/src/tools/env/opensolaris.sh	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/env/opensolaris.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -123,16 +123,6 @@
 SRC="$CODEMGR_WS/usr/src";         	export SRC
 VERSION="$GATE";			export VERSION
 
-# the source product has no SCCS history, and is modified to remove source
-# that cannot be shipped. EXPORT_SRC is where the clear files are copied, then
-# modified with 'make EXPORT_SRC'.
-EXPORT_SRC="$CODEMGR_WS/export_src";    export EXPORT_SRC
-
-# CRYPT_SRC is similar to EXPORT_SRC, but after 'make CRYPT_SRC' the files in
-# xmod/cry_files are saved. They are dropped on the exportable source to create
-# the domestic build.
-CRYPT_SRC="$CODEMGR_WS/crypt_src";      export CRYPT_SRC
-
 #
 # the RELEASE and RELEASE_DATE variables are set in Makefile.master;
 # there might be special reasons to override them here, but that
--- a/usr/src/tools/scripts/Makefile	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/scripts/Makefile	Thu Oct 19 19:27:06 2006 -0700
@@ -44,6 +44,7 @@
 	makebfu \
 	mkacr \
 	mkbfu \
+	mkclosed \
 	nightly \
 	protocmp.terse \
 	sccscheck \
@@ -113,6 +114,16 @@
 clean:
 	$(RM) $(CLEANFILES)
 
+bldenv: bldenv.sh stdenv.sh
+	$(RM) $@
+	sed -e '/# STDENV_START/ r stdenv.sh' bldenv.sh > bldenv
+	$(CHMOD) +x $@ 
+
+nightly: nightly.sh stdenv.sh
+	$(RM) $@
+	sed -e '/# STDENV_START/ r stdenv.sh' nightly.sh > nightly
+	$(CHMOD) +x $@ 
+
 cddlchk.1: cddlchk.pl
 	/usr/perl5/bin/pod2man --center='User Commands' --name=cddlchk \
 	--section=1 --release='SunOS $(RELEASE)' $? > $@
--- a/usr/src/tools/scripts/bldenv.1	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/scripts/bldenv.1	Thu Oct 19 19:27:06 2006 -0700
@@ -1,10 +1,9 @@
 .\" ident	"%Z%%M%	%I%	%E% SMI"
 .\" " CDDL HEADER START
 .\" "
-.\" " The contents of this file are subject to the terms of the
-.\" " Common Development and Distribution License, Version 1.0 only
-.\" " (the "License").  You may not use this file except in compliance
-.\" " with the License.
+.\" The contents of this file are subject to the terms of the
+.\" Common Development and Distribution License (the "License").
+.\" You may not use this file except in compliance with the License.
 .\" "
 .\" " You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 .\" " or http://www.opensolaris.org/os/licensing.
@@ -19,15 +18,15 @@
 .\" "
 .\" " CDDL HEADER END
 .\" "
-.\" "Copyright 2005 Sun Microsystems, Inc."
+.\" "Copyright 2006 Sun Microsystems, Inc."
 .\" "All rights reserved"
 .\" "Use is subject to license terms."
-.TH bldenv 1 "04 Jan 2005"
+.TH bldenv 1 "19 Sep 2006"
 .SH NAME
 .I bldenv
 \- spawn shell for interactive incremental OS-Net consolidation builds
 .SH SYNOPSIS
-\fBbldenv [-fdt] [-S E|C|D] <env_file> [command]\fP
+\fBbldenv [-fdt] [-S E|H|D|O] <env_file> [command]\fP
 .LP
 .SH DESCRIPTION
 .IX "OS-Net build tools" "bldenv" "" "\fBbldenv\fP"
@@ -73,11 +72,14 @@
 .B \-S E
 build the exportable source variant of the source product
 .TP
-.B \-S C
-build the crypt source variant of the source product
-.TP
 .B \-S D
 build the domestic source (exportable + crypt) variant of the source product
+.TP
+.B \-S H
+build hybrid source (binaries + deleted source)
+.TP
+.B \-S O
+simulate an OpenSolaris (open source only) build
 .LP
 .SH EXAMPLES
 .LP
--- a/usr/src/tools/scripts/bldenv.sh	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/scripts/bldenv.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -29,7 +29,7 @@
 # before spawning a shell for doing a release-style builds interactively
 # and incrementally.
 #
-USAGE='Usage: bldenv [-fdt] [ -S E|D|H ] <env_file> [ command ]
+USAGE='Usage: bldenv [-fdt] [ -S E|D|H|O ] <env_file> [ command ]
 
 Where:
 	-c	Force the use of csh - ignore $SHELL
@@ -40,6 +40,7 @@
 		E - build exportable source
 		D - build domestic source (exportable + crypt)
 		H - build hybrid source (binaries + deleted source)
+		O - simulate OpenSolaris build
 '
 
 c_FLAG=n
@@ -50,6 +51,37 @@
 SE_FLAG=n
 SH_FLAG=n
 SD_FLAG=n
+SO_FLAG=n
+
+is_source_build() {
+	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
+	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
+	return $?
+}
+
+#
+# single function for setting -S flag and doing error checking.
+# usage: set_S_flag <type>
+# where <type> is the source build type ("E", "D", ...).
+#
+set_S_flag() {
+	if is_source_build; then
+		echo "Can only build one source variant at a time."
+		exit 1
+	fi
+	if [ "$1" = "E" ]; then
+		SE_FLAG=y
+	elif [ "$1" = "D" ]; then
+		SD_FLAG=y
+	elif [ "$1" = "H" ]; then
+		SH_FLAG=y
+	elif [ "$1" = "O" ]; then
+		SO_FLAG=y
+	else
+		echo "$USAGE"
+		exit 1
+	fi
+}
 
 OPTIND=1
 SUFFIX="-nd"
@@ -66,20 +98,7 @@
 	  t )	t_FLAG=y
 		;;
 	  S )
-		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
-			echo "Can only build one source variant at a time."
-			exit 1
-		fi
-		if [ "${OPTARG}" = "E" ]; then
-			SE_FLAG=y
-		elif [ "${OPTARG}" = "D" ]; then
-			SD_FLAG=y
-		elif [ "${OPTARG}" = "H" ]; then
-			SH_FLAG=y
-		else
-			echo "$USAGE"
-			exit 1
-		fi
+		set_S_flag $OPTARG
 		;;
 	  \?)	echo "$USAGE"
 		exit 1
@@ -135,16 +154,11 @@
 fi
 shift
 
-#MACH=`uname -p`
+# contents of stdenv.sh inserted after next line:
+# STDENV_START
+# STDENV_END
 
-if [ -z "$CLOSED_IS_PRESENT" ]; then
-	if [ -d $SRC/../closed ]; then
-		CLOSED_IS_PRESENT="yes"
-	else
-		CLOSED_IS_PRESENT="no"
-	fi
-	export CLOSED_IS_PRESENT
-fi
+#MACH=`uname -p`
 
 # must match the getopts in nightly.sh
 OPTIND=1
@@ -155,20 +169,7 @@
 	  t )	t_FLAG=y
 		;;
 	  S )
-		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
-			echo "Can only build one source variant at a time."
-			exit 1
-		fi
-		if [ "${OPTARG}" = "E" ]; then
-			SE_FLAG=y
-		elif [ "${OPTARG}" = "D" ]; then
-			SD_FLAG=y
-		elif [ "${OPTARG}" = "H" ]; then
-			SH_FLAG=y
-		else
-			echo "$USAGE"
-			exit 1
-		fi
+		set_S_flag $OPTARG
 		;;
 	  o)	o_FLAG=y
 		;;
@@ -196,24 +197,6 @@
 CPIODIR=${CPIODIR}${SUFFIX}
 PKGARCHIVE=${PKGARCHIVE}${SUFFIX}
 
-if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
-        if [ -z "${EXPORT_SRC}" ]; then
-                echo "EXPORT_SRC must be set for a source build."
-                exit 1
-        fi
-        if [ -z "${CRYPT_SRC}" ]; then
-                echo "CRYPT_SRC must be set for a source build."
-                exit 1
-        fi
-fi
-
-if [ "$SH_FLAG" = "y" ]; then
-        if [ -z "${EXPORT_SRC}" ]; then
-                echo "EXPORT_SRC must be set for a source build."
-                exit 1
-        fi
-fi
- 
 # Append source version
 if [ "$SE_FLAG" = "y" ]; then
         VERSION="${VERSION}:EXPORT"
@@ -230,6 +213,11 @@
 	SRC=${EXPORT_SRC}/usr/src
 fi
  
+if [ "$SO_FLAG" = "y" ]; then
+        VERSION="${VERSION}:OPEN_ONLY"
+	SRC=${OPEN_SRCDIR}/usr/src
+fi
+ 
 # 	Set PATH for a build
 PATH="/opt/onbld/bin:/opt/onbld/bin/${MACH}:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/etc:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
 if [ "${SUNWSPRO}" != "" ]; then 
@@ -237,6 +225,21 @@
 	export PATH 
 fi 
 
+if [[ "$SO_FLAG" = "y" && "$CLOSED_IS_PRESENT" = "yes" ]]; then
+	echo "CLOSED_IS_PRESENT is 'no' (because of '-S O')"
+	CLOSED_IS_PRESENT=no
+	export CLOSED_IS_PRESENT
+fi
+
+if [ -z "$CLOSED_IS_PRESENT" ]; then
+	if [ -d $SRC/../closed ]; then
+		CLOSED_IS_PRESENT="yes"
+	else
+		CLOSED_IS_PRESENT="no"
+	fi
+	export CLOSED_IS_PRESENT
+fi
+
 TOOLS=${SRC}/tools
 TOOLS_PROTO=${TOOLS}/proto
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/tools/scripts/mkclosed.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -0,0 +1,87 @@
+#! /usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# ident	"%Z%%M%	%I%	%E% SMI"
+#
+
+#
+# Generate a minimal set of closed binaries from a proto area.  Useful
+# when building just the open tree.
+#
+
+usage="mkclosed isa proto closed"
+
+if [ $# -ne 3 ]; then
+	print -u2 "usage: $usage"
+	exit 1
+fi
+
+isa=$1
+case "$isa" in
+i386)	plat64=amd64;;
+sparc)	plat64=sparcv9;;
+*)	print -u2 "unknown isa: $isa"
+	exit 1
+	;;
+esac
+
+protoroot=$2/root_$isa
+closedroot=$3/root_$isa
+
+#
+# Make closedroot an absolute path if it isn't already.  This is
+# needed for the cpio invocation below.
+#
+[[ $closedroot = /* ]] || closedroot=`pwd`/$closedroot
+
+# Check arguments before modifying filesystem.
+cd $protoroot || exit 1
+
+mkdir -p $closedroot || exit 1
+
+#
+# Copy files from the proto area to the new closed tree.  We use cpio
+# rather than a tar pipeline to make it easier to detect errors.
+#
+# We need /lib/libc_i18n.a & /lib/{sparcv9,amd64}/libc_i18n.a
+# libdisasm is open on x86, but closed on sparc - how confusing...
+#
+
+(
+	echo lib/libc_i18n.a
+	[ -n "$plat64" ] && echo lib/$plat64/libc_i18n.a
+	if [ "$isa" = "sparc" ]; then
+		echo usr/lib/libdisasm.so.1
+		echo usr/lib/libdisasm.so
+		echo usr/lib/$plat64/libdisasm.so.1
+		echo usr/lib/$plat64/libdisasm.so
+		echo usr/lib/$plat64/libstanddisasm.so
+		echo usr/lib/$plat64/llib-ldisasm.ln
+		echo usr/lib/llib-ldisasm
+		echo usr/lib/mdb/disasm
+		echo usr/lib/llib-ldisasm.ln
+	fi
+) | cpio -dpu $closedroot
--- a/usr/src/tools/scripts/nightly.1	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/scripts/nightly.1	Thu Oct 19 19:27:06 2006 -0700
@@ -20,7 +20,7 @@
 .\" "
 .\" "Copyright 2006 Sun Microsystems, Inc.  All rights reserved."
 .\" "Use is subject to license terms."
-.TH nightly 1 "23 June 2006"
+.TH nightly 1 "12 Oct 2006"
 .SH NAME
 .I nightly
 \- build an OS-Net consolidation overnight
@@ -53,34 +53,49 @@
 .LP
 .RS
 .TP
+\(bu
 perform a "make clobber" to clean up old binaries
 .TP
+\(bu
 bringover from the identified parent gate/clone
 .TP
+\(bu
 perform non-DEBUG and DEBUG builds
 .TP
+\(bu
 list proto area files and compare with previous list
 .TP
+\(bu
 copy updated proto area to parent
 .TP
+\(bu
 list shared lib interface and compare with previous list
 .TP
+\(bu
 perform a "make lint" of the kernel and report errors
 .TP
+\(bu
 perform a "make check" to report hdrchk/cstyle errors
 .TP
+\(bu
 report the presence of any core files
 .TP
+\(bu
 check the ELF runtime attributes of all dynamic objects
 .TP
+\(bu
 check for unreferenced files
 .TP
+\(bu
 report on which proto area objects have changed (since the last build)
 .TP
+\(bu
 report the total build time
 .TP
+\(bu
 save a detailed log file for reference
 .TP
+\(bu
 mail the user a summary of the completed build
 .RE
 .LP
@@ -202,6 +217,22 @@
 Default group of options for building a release (-mp)
 
 .LP
+.B Source Build options
+.TP 10
+.B \-S E | D | H
+Build the Export, Domestic, or Hybrid source product. Only Export and
+Domestic are truly buildable at this time.
+.TP 10
+.B \-S O
+Simulate an OpenSolaris build on a full tree.  This can be used by
+internal developers to ensure that they haven't broken the build for
+external developers.
+.LP
+Source build options only make sense for a full internal tree (open
+and closed source).  Only one source build option can be specified at
+a time.
+
+.LP
 .B Miscellaneous options
 .TP 10
 .B \-V VERS
@@ -214,10 +245,6 @@
 and
 .B BUILDING THE IHV WORKSPACE
 below.
-.TP
-.B \-S E | D | H
-Build the Export, Domestic, or Hybrid source product. Only Export and
-Domestic are truly buildable at this time.
 
 .LP
 .SH ENVIRONMENT VARIABLES
@@ -438,6 +465,22 @@
 the domestic build
 .RE
 .LP
+.B OPEN_SRCDIR
+.RS 5
+The open source tree is copied to this directory when simulating an
+OpenSolaris build (\fB\-S O\fR).  It defaults to $CODEMGR_WS/open_src.
+.RE
+.LP
+.B ON_CLOSED_BINS
+.RS 5
+OpenSolaris builds do not contain the closed source tree.  Instead,
+the developer downloads a closed binaries tree and unpacks it.  
+.B ON_CLOSED_BINS
+tells nightly
+where to find these closed binaries, so that it can add them into the
+build.
+.RE
+.LP
 .B CHECK_PATHS
 .RS 5
 Normally, nightly runs the 'checkpaths' script to check for
--- a/usr/src/tools/scripts/nightly.sh	Thu Oct 19 17:24:48 2006 -0700
+++ b/usr/src/tools/scripts/nightly.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -108,11 +108,10 @@
 	# DEBUG build ends
 }
 
+#
+# usage: filelist DESTDIR PATTERN
+#
 filelist() {
-	if  [ $# -ne 2 ]; then
-		echo "usage: filelist DESTDIR PATTERN"
-		exit 1;
-	fi
 	DEST=$1
 	PATTERN=$2
 	cd ${DEST}
@@ -121,7 +120,7 @@
 	if [ ! -f ${OBJFILES} ]; then
 		return;
 	fi
-	for i in `grep -v '^#' ${ORIG_SRC}/xmod/obj_files | \
+	for i in `grep -v '^#' ${OBJFILES} | \
 	    grep ${PATTERN} | cut -d: -f2 | tr -d ' \t'`
 	do
 		# wildcard expansion
@@ -152,12 +151,8 @@
 }
 
 # delete files
+# usage: hybridize_files DESTDIR MAKE_TARGET
 hybridize_files() {
-	if  [ $# -ne 2 ]; then
-		echo "usage: hybridize_files DESTDIR MAKE_TARGET"
-		exit 1;
-	fi
-
 	DEST=$1
 	MAKETARG=$2
 
@@ -179,12 +174,8 @@
 }
 
 # restore binaries into the proper source tree.
+# usage: restore_binaries DESTDIR MAKE_TARGET
 restore_binaries() {
-	if  [ $# -ne 2 ]; then
-		echo "usage: restore_binaries DESTDIR MAKE_TARGET"
-		exit 1;
-	fi
-
 	DEST=$1
 	MAKETARG=$2
 
@@ -196,12 +187,8 @@
 }
 
 # rename files we save binaries of
+# usage: rename_files DESTDIR MAKE_TARGET
 rename_files() {
-	if  [ $# -ne 2 ]; then
-		echo "usage: rename_files DESTDIR MAKE_TARGET"
-		exit 1;
-	fi
-
 	DEST=$1
 	MAKETARG=$2
 	echo "\n==== Renaming source files in ${MAKETARG} at `date` ====\n" | \
@@ -214,20 +201,17 @@
 	done
 }
 
-# function to create the export/crypt source tree
-# usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET
-
-clone_source() {
-
-	if  [ $# -ne 3 ]; then
-		echo "usage: clone_source CODEMGR_WS DESTDIR MAKE_TARGET"
-		exit 1;
-	fi
+#
+# Copy some or all of the source tree.
+# usage: copy_source CODEMGR_WS DESTDIR LABEL SRCROOT
+#
+copy_source() {
 	WS=$1
 	DEST=$2
-	MAKETARG=$3
+	label=$3
+	srcroot=$4
 
-	echo "\n==== Creating ${DEST} source from ${WS} (${MAKETARG}) ====\n" | \
+	echo "\n==== Creating ${DEST} source from ${WS} ($label) ====\n" | \
 	    tee -a $mail_msg_file >> $LOGFILE
 
 	echo "cleaning out ${DEST}." >> $LOGFILE
@@ -237,11 +221,24 @@
 	cd ${WS}
 
 	echo "creating ${DEST}." >> $LOGFILE
-	find usr -name 's\.*' -a -type f -print | \
+	find $srcroot -name 's\.*' -a -type f -print | \
 	    sed -e 's,SCCS\/s.,,' | \
 	    grep -v '/\.del-*' | \
 	    cpio -pd ${DEST} >>$LOGFILE 2>&1
+}
 
+#
+# function to create (but not build) the export/crypt source tree.
+# usage: set_up_source_build CODEMGR_WS DESTDIR MAKE_TARGET
+# Sets SRC to the modified source tree, for use by the caller when it
+# builds the tree.
+#
+set_up_source_build() {
+	WS=$1
+	DEST=$2
+	MAKETARG=$3
+
+	copy_source $WS $DEST $MAKETARG usr
 	SRC=${DEST}/usr/src
 
 	cd $SRC
@@ -312,12 +309,6 @@
 # usage: build LABEL SUFFIX
 
 build() {
-
-	if  [ $# -ne 2 ]; then
-		echo "usage: build LABEL SUFFIX"
-		exit 1;
-	fi
-
 	LABEL=$1
 	SUFFIX=$2
 	INSTALLOG=install${SUFFIX}-${MACH}
@@ -518,25 +509,16 @@
 	fi
 }
 
+# Usage: dolint /dir y|n
+# Arg. 2 is a flag to turn on/off the lint diff output
 dolint() {
-
-	#
-	# Arg. 2 is a flag to turn on/off the lint diff output
-	#
-	dl_usage="Usage: dolint /dir y|n"
-
-	if [ $# -ne 2 ]; then
-		echo $dl_usage
-		exit 1
-	fi
-
 	if [ ! -d "$1" ]; then
-		echo $dl_usage
+		echo "dolint error: $1 is not a directory"
 		exit 1
 	fi
 
 	if [ "$2" != "y" -a "$2" != "n" ]; then
-		echo $dl_usage
+		echo "dolint internal error: $2 should be 'y' or 'n'"
 		exit 1
 	fi
 
@@ -631,14 +613,8 @@
 }
 
 # Install IHV packages in PKGARCHIVE
-
+# usage: copy_ihv_pkgs LABEL SUFFIX
 copy_ihv_pkgs() {
-
-	if  [ $# -ne 2 ]; then
-		echo "usage: copy_ihv_pkgs LABEL SUFFIX"
-		exit 1;
-	fi
-
 	LABEL=$1
 	SUFFIX=$2
 	# always use non-DEBUG IHV packages
@@ -666,13 +642,8 @@
 	fi
 }
 
+# usage: build_tools DESTROOT
 build_tools() {
-
-	if  [ $# -ne 1 ]; then
-		echo "usage: build_tools DESTROOT"
-		exit 1;
-	fi
-
 	DESTROOT=$1
 
 	INSTALLOG=install-${MACH}
@@ -789,7 +760,7 @@
 	export TEAMWARE
 fi
 
-USAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H ] <env_file>
+USAGE='Usage: nightly [-in] [-V VERS ] [ -S E|D|H|O ] <env_file>
 
 Where:
 	-i	Fast incremental options (no clobber, lint, check)
@@ -799,6 +770,7 @@
 		E - build exportable source
 		D - build domestic source (exportable + crypt)
 		H - build hybrid source (binaries + deleted source)
+		O - build (only) open source
 
 	<env_file>  file in Bourne shell syntax that sets and exports
 	variables that configure the operation of this script and many of
@@ -839,6 +811,7 @@
 		E - build exportable source
 		D - build domestic source (exportable + crypt)
 		H - build hybrid source (binaries + deleted source)
+		O - build (only) open source
 '
 #
 #	-x	less public handling of xmod source for the source product
@@ -876,15 +849,47 @@
 SE_FLAG=n
 SD_FLAG=n
 SH_FLAG=n
+SO_FLAG=n
 X_FLAG=n
 #
 XMOD_OPT=
 #
 build_ok=y
+
+is_source_build() {
+	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
+	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
+	return $?
+}
+
 #
 # examine arguments
 #
 
+#
+# single function for setting -S flag and doing error checking.
+# usage: set_S_flag <type>
+# where <type> is the source build type ("E", "D", ...).
+#
+set_S_flag() {
+	if is_source_build; then
+		echo "Can only build one source variant at a time."
+		exit 1
+	fi
+	if [ "$1" = "E" ]; then
+		SE_FLAG=y
+	elif [ "$1" = "D" ]; then
+		SD_FLAG=y
+	elif [ "$1" = "H" ]; then
+		SH_FLAG=y
+	elif [ "$1" = "O" ]; then
+		SO_FLAG=y
+	else
+		echo "$USAGE"
+		exit 1
+	fi
+}
+
 OPTIND=1
 while getopts inV:S:t FLAG
 do
@@ -897,20 +902,7 @@
 		V_ARG="$OPTARG"
 		;;
 	  S )
-		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
-			echo "Can only build one source variant at a time."
-			exit 1
-		fi
-		if [ "${OPTARG}" = "E" ]; then
-			SE_FLAG=y
-		elif [ "${OPTARG}" = "D" ]; then
-			SD_FLAG=y
-		elif [ "${OPTARG}" = "H" ]; then
-			SH_FLAG=y
-		else
-			echo "$USAGE"
-			exit 1
-		fi
+		set_S_flag $OPTARG
 		;;
 	  t )	t_FLAG=y
 		;;
@@ -994,6 +986,10 @@
 	fi
 fi
 
+# contents of stdenv.sh inserted after next line:
+# STDENV_START
+# STDENV_END
+
 #
 # place ourselves in a new task, respecting BUILD_PROJECT if set.
 #
@@ -1114,20 +1110,7 @@
 	  W )	W_FLAG=y
 		;;
 	  S )
-		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
-			echo "Can only build one source variant at a time."
-			exit 1
-		fi
-		if [ "${OPTARG}" = "E" ]; then
-			SE_FLAG=y
-		elif [ "${OPTARG}" = "D" ]; then
-			SD_FLAG=y
-		elif [ "${OPTARG}" = "H" ]; then
-			SH_FLAG=y
-		else
-			echo "$USAGE"
-			exit 1
-		fi
+		set_S_flag $OPTARG
 		;;
 	  X )	# now that we no longer need realmode builds, just
 		# copy IHV packages.  only meaningful on x86.
@@ -1254,24 +1237,6 @@
 	exit 1
 fi
 
-if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
-        if [ -z "${EXPORT_SRC}" ]; then
-		echo "EXPORT_SRC must be set for a source build."
-		exit 1
-	fi
-        if [ -z "${CRYPT_SRC}" ]; then
-		echo "CRYPT_SRC must be set for a source build."
-		exit 1
-	fi
-fi
-
-if [ "$SH_FLAG" = "y" ]; then
-        if [ -z "${EXPORT_SRC}" ]; then
-		echo "EXPORT_SRC must be set for a source build."
-		exit 1
-	fi
-fi
-
 #
 # if -V flag was given, reset VERSION to V_ARG
 #
@@ -1314,6 +1279,10 @@
 	VERSION="${VERSION}:MODIFIED_SOURCE_PRODUCT"
 fi
 
+if [ "$SO_FLAG" = "y" ]; then
+	VERSION="${VERSION}:OPEN_ONLY"
+fi
+
 TMPDIR="/tmp/nightly.tmpdir.$$"
 export TMPDIR
 rm -rf ${TMPDIR}
@@ -1595,7 +1564,7 @@
 	obsolete_build TRACE | tee -a $mail_msg_file >> $LOGFILE
 fi
 
-if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
+if is_source_build; then
 	if [ "$i_FLAG" = "y" -o "$i_CMD_LINE_FLAG" = "y" ]; then
 		echo "WARNING: the -S flags do not support incremental" \
 		    "builds; forcing clobber\n" | tee -a $mail_msg_file >> $LOGFILE
@@ -1898,6 +1867,10 @@
 ORIG_SRC=$SRC
 BINARCHIVE=${CODEMGR_WS}/bin-${MACH}.cpio.Z
 
+#
+# For the "open" build, we don't mung any source files, so skip this
+# step. 
+#
 if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
 	save_binaries
 
@@ -1917,13 +1890,13 @@
 fi
 
 if [ "$SD_FLAG" = "y" ]; then
-	clone_source ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
+	set_up_source_build ${CODEMGR_WS} ${CRYPT_SRC} CRYPT_SRC
 fi
 
 # EXPORT_SRC comes after CRYPT_SRC since a domestic build will need
 # $SRC pointing to the export_source usr/src.
 if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
-	clone_source ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
+	set_up_source_build ${CODEMGR_WS} ${EXPORT_SRC} EXPORT_SRC
 fi
 
 if [ "$SD_FLAG" = "y" ]; then
@@ -1943,7 +1916,28 @@
 
 fi
 
-if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
+if [ "$SO_FLAG" = "y" ]; then
+	#
+	# Copy the open sources into their own tree, set up the closed
+	# binaries, and set up the environment.
+	#
+	copy_source $CODEMGR_WS $OPEN_SRCDIR OPEN_SOURCE usr/src
+	SRC=$OPEN_SRCDIR/usr/src
+
+	# Try not to clobber any user-provided closed binaries.
+	export ON_CLOSED_BINS=$CODEMGR_WS/closed$$
+	echo "\n==== Copying skeleton closed binaries to $ON_CLOSED_BINS ====\n" | \
+	    tee -a $mail_msg_file >> $LOGFILE
+	mkclosed $MACH $CODEMGR_WS/proto $ON_CLOSED_BINS >>$LOGFILE 2>&1
+	if [ $? -ne 0 ]; then
+		build_ok=n
+		echo "Aborting (couldn't create closed binaries)." |
+			tee -a $mail_msg_file >> $LOGFILE
+	fi
+	CLOSED_IS_PRESENT=no
+fi
+
+if is_source_build && [ $build_ok = y ] ; then
 	# remove proto area here, since we don't clobber
 	rm -rf "$ROOT"
 	if [ "$t_FLAG" = "y" ]; then
@@ -1952,8 +1946,12 @@
 		unset EXTRA_OPTIONS
 		unset EXTRA_CFLAGS
 		ORIG_TOOLS=$TOOLS
-		TOOLS=${EXPORT_SRC}/usr/src/tools
-		build_tools ${EXPORT_SRC}/usr/src/tools/proto
+		#
+		# SRC was set earlier to point to the source build
+		# source tree (e.g., $EXPORT_SRC).
+		#
+		TOOLS=${SRC}/tools
+		build_tools ${SRC}/tools/proto
 		TOOLS=$ORIG_TOOLS
 	fi
 
@@ -1961,6 +1959,10 @@
 	normal_build
 fi
 
+if [[ "$SO_FLAG" = "y" && "$build_ok" = "y" ]]; then
+	rm -rf $ON_CLOSED_BINS
+fi
+
 if [ "$build_ok" = "y" ]; then
 	echo "\n==== Creating protolist system file at `date` ====" \
 		>> $LOGFILE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usr/src/tools/scripts/stdenv.sh	Thu Oct 19 19:27:06 2006 -0700
@@ -0,0 +1,56 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# ident	"%Z%%M%	%I%	%E% SMI"
+#
+
+#
+# Shell script fragment to set standard build environment variables,
+# for use by bldenv(1) and nightly(1).  Can be overridden by the
+# user's environment file.  Because bldenv and nightly are both ksh
+# scripts, we can use ksh syntax here.
+#
+
+#
+# the source product has no SCCS history, and is modified to remove source
+# that cannot be shipped. EXPORT_SRC is where the clear files are copied, then
+# modified with 'make EXPORT_SRC'.
+#
+[ -n "$EXPORT_SRC" ] || export EXPORT_SRC="$CODEMGR_WS/export_src"
+
+#
+# CRYPT_SRC is similar to EXPORT_SRC, but after 'make CRYPT_SRC' the files in
+# xmod/cry_files are saved. They are dropped on the exportable source to create
+# the domestic build.
+#
+[ -n "$CRYPT_SRC" ] || export CRYPT_SRC="$CODEMGR_WS/crypt_src"
+
+#
+# OPEN_SRCDIR is where we copy the open tree to so that we can be sure
+# we don't have a hidden dependency on closed code.  The name ends in
+# "DIR" to avoid confusion with the flags related to open source
+# builds.
+#
+[ -n "$OPEN_SRCDIR" ] || export OPEN_SRCDIR="$CODEMGR_WS/open_src"