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)]
77 [+?Example 1: Interactive use]{
78 [+?Use bldenv to spawn a shell to perform a DEBUG build and
79 testing of the Makefile targets clobber and install for
81 [+\n% rlogin wopr-2 -l gk
82 {root::wopr-2::49} bldenv -d /export0/jg/on10-se.env
85 VERSION is wopr-2::on10-se::11/01/2001
86 RELEASE_DATE is May 2004
87 Using /usr/bin/tcsh as shell.
89 {root::wopr-2::49} cd $SRC/cmd/true
90 {root::wopr-2::50} make
91 {root::wopr-2::51} make clobber
92 /usr/bin/rm -f true true.po
93 {root::wopr-2::52} make
97 {root::wopr-2::53} make install
98 install -s -m 0555 -u root -g bin -f /export0/jg/on10-se/proto/root_sparc/usr/bin true
99 `install\' is up to date.]
101 [+?Example 2: Non-interactive use]{
102 [+?Invoke bldenv to create SUNWonbld with a single command:]
103 [+\nexample% bldenv onnv_06 \'cd $SRC/tools && make pkg\']
106 [+SEE ALSO?\bnightly\b(1)]
112 # boolean flags (true/false)
127 typeset progname
="$(basename -- "${0}")"
131 while getopts -a "${progname}" "${USAGE}" OPT
; do
144 # test that the path to the environment-setting file was given
145 if (( $# < 1 )) ; then
160 # clear environment variables we know to be bad for the build
189 # Setup environment variables
192 if [[ -f "$1" ]]; then
193 if [[ "$1" == */* ]]; then
200 'Cannot find env file as either %s\n' "$1"
205 # Check if we have sufficient data to continue...
206 [[ -v SRCTOP
]] || fatal_error
"Error: Variable SRCTOP not set."
207 [[ -d "${SRCTOP}" ]] || fatal_error
"Error: ${SRCTOP} is not a directory."
208 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error
"Error: ${SRCTOP}/usr/src/Makefile not found."
211 # have we set RELEASE_DATE in our env file?
212 if [ -z "$RELEASE_DATE" ]; then
213 RELEASE_DATE
=$
(LC_ALL
=C
date +"%B %Y")
215 BUILD_DATE
=$
(LC_ALL
=C
date +%Y-
%b-
%d
)
216 BASEWSDIR
=$
(basename -- "${SRCTOP}")
217 export RELEASE_DATE POUND_SIGN
219 print
'Build type is \c'
226 # default is a non-DEBUG build
228 export RELEASE_BUILD
=
233 # update build-type variables
234 PKGARCHIVE
="${PKGARCHIVE}"
236 # Set PATH for a build
237 PATH
="/opt/onbld/bin:/opt/onbld/bin/${MACH}:/usr/bin:/usr/sbin:/usr/ucb:/usr/etc:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:/opt/SUNWspro/bin"
239 if [[ -n "${MAKE}" ]]; then
240 if [[ -x "${MAKE}" ]]; then
241 export PATH
="$(dirname -- "${MAKE}"):$PATH"
243 print
"\$MAKE (${MAKE}) is not a valid executible"
249 TOOLS_PROTO
="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
251 export ONBLD_TOOLS
="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
253 export STABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
254 export CTFSTABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
255 export GENOFFSETS
="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
257 PATH
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
258 PATH
="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
261 export DMAKE_MODE
=${DMAKE_MODE:-parallel}
285 ENVLDLIBS1
="-L$ROOT/lib -L$ROOT/usr/lib"
286 ENVCPPFLAGS1
="-I$ROOT/usr/include"
299 printf 'RELEASE is %s\n' "$RELEASE"
300 printf 'VERSION is %s\n' "$VERSION"
301 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
303 print
"Use 'bmake gen-config' target to generate config makefiles/headers."
304 print
"Use 'dmake setup' target to build legacy headers and tools."
308 # place ourselves in a new task, respecting BUILD_PROJECT if set.
310 /usr
/bin
/newtask
-c $$
${BUILD_PROJECT:+-p$BUILD_PROJECT}
314 if [[ "${flags.c}" == "false" && -x "$SHELL" && \
315 "$(basename -- "${SHELL}")" != "csh" ]]; then
316 # $SHELL is set, and it's not csh.
318 if "${flags.f}" ; then
319 print
'WARNING: -f is ignored when $SHELL is not csh'
322 printf 'Using %s as shell.\n' "$SHELL"
323 exec "$SHELL" ${@:+-c "$@"}
325 elif "${flags.f}" ; then
326 print
'Using csh -f as shell.'
327 exec csh
-f ${@:+-c "$@"}
330 print
'Using csh as shell.'
331 exec csh
${@:+-c "$@"}