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.
26 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
28 # Uses supplied "env" file, based on /opt/onbld/etc/env, to set shell variables
29 # before spawning a shell for doing a release-style builds interactively
35 print
-u2 "${progname}: $*"
42 getopts -a "${progname}" "${USAGE}" OPT
'-?'
47 [-?\n@(#)\$Id: bldenv (OS/Net) 2008-04-06 \$\n]
48 [-author?OS/Net community <tools-discuss@opensolaris.org>]
49 [+NAME?bldenv - spawn shell for interactive incremental OS-Net
51 [+DESCRIPTION?bldenv is a useful companion to the nightly(1) script for
52 doing interactive and incremental builds in a workspace
53 already built with nightly(1). bldenv spawns a shell set up
54 with the same environment variables taken from an env_file,
55 as prepared for use with nightly(1).]
56 [+?In addition to running a shell for interactive use, bldenv
57 can optionally run a single command in the given environment,
58 in the vein of sh -c or su -c. This is useful for
59 scripting, when an interactive shell would not be. If the
60 command is composed of multiple shell words or contains
61 other shell metacharacters, it must be quoted appropriately.]
62 [+?bldenv is particularly useful for testing Makefile targets
63 like clobber, install and _msg, which otherwise require digging
64 through large build logs to figure out what is being
66 [+?By default, bldenv will invoke the shell specified in
67 $SHELL. If $SHELL is not set or is invalid, csh will be
69 [c?force the use of csh, regardless of the value of $SHELL.]
70 [f?invoke csh with the -f (fast-start) option. This option is valid
71 only if $SHELL is unset or if it points to csh.]
72 [d?set up environment for doing DEBUG builds (default is non-DEBUG)]
73 [t?set up environment to use the tools in usr/src/tools (this is the
74 default, use +t to use the tools from /opt/onbld)]
79 [+?Example 1: Interactive use]{
80 [+?Use bldenv to spawn a shell to perform a DEBUG build and
81 testing of the Makefile targets clobber and install for
83 [+\n% rlogin wopr-2 -l gk
84 {root::wopr-2::49} bldenv -d /export0/jg/on10-se.env
87 VERSION is wopr-2::on10-se::11/01/2001
88 RELEASE_DATE is May 2004
89 The top-level `setup\' target is available to build headers
91 Using /usr/bin/tcsh as shell.
93 {root::wopr-2::49} cd $SRC/cmd/true
94 {root::wopr-2::50} make
95 {root::wopr-2::51} make clobber
96 /usr/bin/rm -f true true.po
97 {root::wopr-2::52} make
101 {root::wopr-2::53} make install
102 install -s -m 0555 -u root -g bin -f /export0/jg/on10-se/proto/root_sparc/usr/bin true
103 `install\' is up to date.]
105 [+?Example 2: Non-interactive use]{
106 [+?Invoke bldenv to create SUNWonbld with a single command:]
107 [+\nexample% bldenv onnv_06 \'cd $SRC/tools && make pkg\']
110 [+SEE ALSO?\bnightly\b(1)]
116 # boolean flags (true/false)
132 typeset progname
="$(basename -- "${0}")"
137 while getopts -a "${progname}" "${USAGE}" OPT
; do
143 d
) flags.d
=true SUFFIX
="" ;;
144 +d
) flags.d
=false SUFFIX
="-nd" ;;
152 # test that the path to the environment-setting file was given
153 if (( $# < 1 )) ; then
168 # clear environment variables we know to be bad for the build
197 # Setup environment variables
199 if [[ -f /etc
/nightly.conf
]]; then
200 source /etc
/nightly.conf
203 if [[ -f "$1" ]]; then
204 if [[ "$1" == */* ]]; then
210 if [[ -f "/opt/onbld/env/$1" ]]; then
211 source "/opt/onbld/env/$1"
214 'Cannot find env file as either %s or /opt/onbld/env/%s\n' \
221 # contents of stdenv.sh inserted after next line:
225 # Check if we have sufficient data to continue...
226 [[ -v CODEMGR_WS
]] || fatal_error
"Error: Variable CODEMGR_WS not set."
227 [[ -d "${CODEMGR_WS}" ]] || fatal_error
"Error: ${CODEMGR_WS} is not a directory."
228 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error
"Error: ${CODEMGR_WS}/usr/src/Makefile not found."
230 # must match the getopts in nightly.sh
232 NIGHTLY_OPTIONS
="-${NIGHTLY_OPTIONS#-}"
233 while getopts '+0ABCDdFfGIilMmNnpRrtUuwW' FLAG
$NIGHTLY_OPTIONS
243 # have we set RELEASE_DATE in our env file?
244 if [ -z "$RELEASE_DATE" ]; then
245 RELEASE_DATE
=$
(LC_ALL
=C
date +"%B %Y")
247 BUILD_DATE
=$
(LC_ALL
=C
date +%Y-
%b-
%d
)
248 BASEWSDIR
=$
(basename -- "${CODEMGR_WS}")
249 DEV_CM
="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
250 export DEV_CM RELEASE_DATE POUND_SIGN
252 print
'Build type is \c'
259 # default is a non-DEBUG build
261 export RELEASE_BUILD
=
266 # update build-type variables
267 PKGARCHIVE
="${PKGARCHIVE}${SUFFIX}"
269 # Set PATH for a build
270 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:."
271 if [[ "${SUNWSPRO}" != "" ]]; then
272 export PATH
="${SUNWSPRO}/bin:$PATH"
275 if [[ -n "${MAKE}" ]]; then
276 if [[ -x "${MAKE}" ]]; then
277 export PATH
="$(dirname -- "${MAKE}"):$PATH"
279 print
"\$MAKE (${MAKE}) is not a valid executible"
285 TOOLS_PROTO
="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
287 if "${flags.t}" ; then
288 export ONBLD_TOOLS
="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
290 export STABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
291 export CTFSTABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
292 export GENOFFSETS
="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
294 export CTFCONVERT
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert"
295 export CTFMERGE
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge"
297 PATH
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
298 PATH
="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
302 export DMAKE_MODE
=${DMAKE_MODE:-parallel}
328 if [[ "$MULTI_PROTO" != "yes" && "$MULTI_PROTO" != "no" ]]; then
330 'WARNING: invalid value for MULTI_PROTO (%s); setting to "no".\n' \
332 export MULTI_PROTO
="no"
335 [[ "$MULTI_PROTO" == "yes" ]] && export ROOT
="${ROOT}${SUFFIX}"
337 ENVLDLIBS1
="-L$ROOT/lib -L$ROOT/usr/lib"
338 ENVCPPFLAGS1
="-I$ROOT/usr/include"
353 printf 'RELEASE is %s\n' "$RELEASE"
354 printf 'VERSION is %s\n' "$VERSION"
355 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
357 if [[ -f "$SRC/Makefile" ]] && egrep -s '^setup:' "$SRC/Makefile" ; then
358 print
"The top-level 'setup' target is available \c"
359 print
"to build headers and tools."
362 elif "${flags.t}" ; then
364 'The tools can be (re)built with the install target in %s.\n\n' \
369 # place ourselves in a new task, respecting BUILD_PROJECT if set.
371 /usr
/bin
/newtask
-c $$
${BUILD_PROJECT:+-p$BUILD_PROJECT}
373 if [[ "${flags.c}" == "false" && -x "$SHELL" && \
374 "$(basename -- "${SHELL}")" != "csh" ]]; then
375 # $SHELL is set, and it's not csh.
377 if "${flags.f}" ; then
378 print
'WARNING: -f is ignored when $SHELL is not csh'
381 printf 'Using %s as shell.\n' "$SHELL"
382 exec "$SHELL" ${@:+-c "$@"}
384 elif "${flags.f}" ; then
385 print
'Using csh -f as shell.'
386 exec csh
-f ${@:+-c "$@"}
389 print
'Using csh as shell.'
390 exec csh
${@:+-c "$@"}