5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
27 # Uses supplied "env" file, based on /opt/onbld/etc/env, to set shell variables
28 # before spawning a shell for doing a release-style builds interactively
34 print
-u2 "${progname}: $*"
41 getopts -a "${progname}" "${USAGE}" OPT
'-?'
46 [-?\n@(#)\$Id: bldenv (OS/Net) 2008-04-06 \$\n]
47 [-author?OS/Net community <tools-discuss@opensolaris.org>]
48 [+NAME?bldenv - spawn shell for interactive incremental OS-Net
50 [+DESCRIPTION?bldenv is a useful companion to the nightly(1) script for
51 doing interactive and incremental builds in a workspace
52 already built with nightly(1). bldenv spawns a shell set up
53 with the same environment variables taken from an env_file,
54 as prepared for use with nightly(1).]
55 [+?In addition to running a shell for interactive use, bldenv
56 can optionally run a single command in the given environment,
57 in the vein of sh -c or su -c. This is useful for
58 scripting, when an interactive shell would not be. If the
59 command is composed of multiple shell words or contains
60 other shell metacharacters, it must be quoted appropriately.]
61 [+?bldenv is particularly useful for testing Makefile targets
62 like clobber, install and _msg, which otherwise require digging
63 through large build logs to figure out what is being
65 [+?By default, bldenv will invoke the shell specified in
66 $SHELL. If $SHELL is not set or is invalid, csh will be
68 [c?force the use of csh, regardless of the value of $SHELL.]
69 [f?invoke csh with the -f (fast-start) option. This option is valid
70 only if $SHELL is unset or if it points to csh.]
71 [d?set up environment for doing DEBUG builds (default is non-DEBUG)]
72 [t?set up environment to use the tools in usr/src/tools (this is the
73 default, use +t to use the tools from /opt/onbld)]
78 [+?Example 1: Interactive use]{
79 [+?Use bldenv to spawn a shell to perform a DEBUG build and
80 testing of the Makefile targets clobber and install for
82 [+\n% rlogin wopr-2 -l gk
83 {root::wopr-2::49} bldenv -d /export0/jg/on10-se.env
86 VERSION is wopr-2::on10-se::11/01/2001
87 RELEASE_DATE is May 2004
88 The top-level `setup\' target is available to build headers
90 Using /usr/bin/tcsh as shell.
92 {root::wopr-2::49} cd $SRC/cmd/true
93 {root::wopr-2::50} make
94 {root::wopr-2::51} make clobber
95 /usr/bin/rm -f true true.po
96 {root::wopr-2::52} make
100 {root::wopr-2::53} make install
101 install -s -m 0555 -u root -g bin -f /export0/jg/on10-se/proto/root_sparc/usr/bin true
102 `install\' is up to date.]
104 [+?Example 2: Non-interactive use]{
105 [+?Invoke bldenv to create SUNWonbld with a single command:]
106 [+\nexample% bldenv onnv_06 \'cd $SRC/tools && make pkg\']
109 [+SEE ALSO?\bnightly\b(1)]
115 # boolean flags (true/false)
131 typeset progname
="$(basename -- "${0}")"
136 while getopts -a "${progname}" "${USAGE}" OPT
; do
142 d
) flags.d
=true SUFFIX
="" ;;
143 +d
) flags.d
=false SUFFIX
="-nd" ;;
151 # test that the path to the environment-setting file was given
152 if (( $# < 1 )) ; then
167 # clear environment variables we know to be bad for the build
196 # Setup environment variables
198 if [[ -f /etc
/nightly.conf
]]; then
199 source /etc
/nightly.conf
202 if [[ -f "$1" ]]; then
203 if [[ "$1" == */* ]]; then
209 if [[ -f "/opt/onbld/env/$1" ]]; then
210 source "/opt/onbld/env/$1"
213 'Cannot find env file as either %s or /opt/onbld/env/%s\n' \
220 # contents of stdenv.sh inserted after next line:
224 # Check if we have sufficient data to continue...
225 [[ -v CODEMGR_WS
]] || fatal_error
"Error: Variable CODEMGR_WS not set."
226 [[ -d "${CODEMGR_WS}" ]] || fatal_error
"Error: ${CODEMGR_WS} is not a directory."
227 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error
"Error: ${CODEMGR_WS}/usr/src/Makefile not found."
229 # must match the getopts in nightly.sh
231 NIGHTLY_OPTIONS
="-${NIGHTLY_OPTIONS#-}"
232 while getopts '+0ABCDdFfGIilMmNnpRrtUuwW' FLAG
"$NIGHTLY_OPTIONS"
242 # have we set RELEASE_DATE in our env file?
243 if [ -z "$RELEASE_DATE" ]; then
244 RELEASE_DATE
=$
(LC_ALL
=C
date +"%B %Y")
246 BUILD_DATE
=$
(LC_ALL
=C
date +%Y-
%b-
%d
)
247 BASEWSDIR
=$
(basename -- "${CODEMGR_WS}")
248 DEV_CM
="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
249 export DEV_CM RELEASE_DATE POUND_SIGN
251 print
'Build type is \c'
258 # default is a non-DEBUG build
260 export RELEASE_BUILD
=
265 # update build-type variables
266 PKGARCHIVE
="${PKGARCHIVE}${SUFFIX}"
268 # Set PATH for a build
269 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:."
270 if [[ "${SUNWSPRO}" != "" ]]; then
271 export PATH
="${SUNWSPRO}/bin:$PATH"
274 if [[ -n "${MAKE}" ]]; then
275 if [[ -x "${MAKE}" ]]; then
276 export PATH
="$(dirname -- "${MAKE}"):$PATH"
278 print
"\$MAKE (${MAKE}) is not a valid executible"
284 TOOLS_PROTO
="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
286 if "${flags.t}" ; then
287 export ONBLD_TOOLS
="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
289 export STABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
290 export CTFSTABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
291 export GENOFFSETS
="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
293 export CTFCONVERT
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert"
294 export CTFMERGE
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge"
296 export CTFCVTPTBL
="${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl"
297 export CTFFINDMOD
="${TOOLS_PROTO}/opt/onbld/bin/ctffindmod"
299 PATH
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
300 PATH
="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
304 export DMAKE_MODE
=${DMAKE_MODE:-parallel}
330 if [[ "$MULTI_PROTO" != "yes" && "$MULTI_PROTO" != "no" ]]; then
332 'WARNING: invalid value for MULTI_PROTO (%s); setting to "no".\n' \
334 export MULTI_PROTO
="no"
337 [[ "$MULTI_PROTO" == "yes" ]] && export ROOT
="${ROOT}${SUFFIX}"
339 ENVLDLIBS1
="-L$ROOT/lib -L$ROOT/usr/lib"
340 ENVCPPFLAGS1
="-I$ROOT/usr/include"
355 printf 'RELEASE is %s\n' "$RELEASE"
356 printf 'VERSION is %s\n' "$VERSION"
357 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
359 if [[ -f "$SRC/Makefile" ]] && egrep -s '^setup:' "$SRC/Makefile" ; then
360 print
"The top-level 'setup' target is available \c"
361 print
"to build headers and tools."
364 elif "${flags.t}" ; then
366 'The tools can be (re)built with the install target in %s.\n\n' \
371 # place ourselves in a new task, respecting BUILD_PROJECT if set.
373 /usr
/bin
/newtask
-c $$
${BUILD_PROJECT:+-p$BUILD_PROJECT}
375 if [[ "${flags.c}" == "false" && -x "$SHELL" && \
376 "$(basename -- "${SHELL}")" != "csh" ]]; then
377 # $SHELL is set, and it's not csh.
379 if "${flags.f}" ; then
380 print
'WARNING: -f is ignored when $SHELL is not csh'
383 printf 'Using %s as shell.\n' "$SHELL"
384 exec "$SHELL" ${@:+-c "$@"}
386 elif "${flags.f}" ; then
387 print
'Using csh -f as shell.'
388 exec csh
-f ${@:+-c "$@"}
391 print
'Using csh as shell.'
392 exec csh
${@:+-c "$@"}