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>
27 # Copyright 2018 Joyent, Inc.
29 # Uses supplied "env" file, based on /opt/onbld/etc/env, to set shell variables
30 # before spawning a shell for doing a release-style builds interactively
36 print
-u2 "${progname}: $*"
43 getopts -a "${progname}" "${USAGE}" OPT
'-?'
48 [-?\n@(#)\$Id: bldenv (OS/Net) 2008-04-06 \$\n]
49 [-author?OS/Net community <tools-discuss@opensolaris.org>]
50 [+NAME?bldenv - spawn shell for interactive incremental OS-Net
52 [+DESCRIPTION?bldenv is a useful companion to the nightly(1) script for
53 doing interactive and incremental builds in a workspace
54 already built with nightly(1). bldenv spawns a shell set up
55 with the same environment variables taken from an env_file,
56 as prepared for use with nightly(1).]
57 [+?In addition to running a shell for interactive use, bldenv
58 can optionally run a single command in the given environment,
59 in the vein of sh -c or su -c. This is useful for
60 scripting, when an interactive shell would not be. If the
61 command is composed of multiple shell words or contains
62 other shell metacharacters, it must be quoted appropriately.]
63 [+?bldenv is particularly useful for testing Makefile targets
64 like clobber, install and _msg, which otherwise require digging
65 through large build logs to figure out what is being
67 [+?By default, bldenv will invoke the shell specified in
68 $SHELL. If $SHELL is not set or is invalid, csh will be
70 [c?force the use of csh, regardless of the value of $SHELL.]
71 [f?invoke csh with the -f (fast-start) option. This option is valid
72 only if $SHELL is unset or if it points to csh.]
73 [d?set up environment for doing DEBUG builds. The default is non-DEBUG,
74 unless the -F flag is specified in the nightly file.]
75 [t?set up environment to use the tools in usr/src/tools (this is the
76 default, use +t to use the tools from /opt/onbld)]
81 [+?Example 1: Interactive use]{
82 [+?Use bldenv to spawn a shell to perform a DEBUG build and
83 testing of the Makefile targets clobber and install for
85 [+\n% rlogin wopr-2 -l gk
86 {root::wopr-2::49} bldenv -d /export0/jg/on10-se.env
89 VERSION is wopr-2::on10-se::11/01/2001
90 RELEASE_DATE is May 2004
91 The top-level `setup\' target is available to build headers
93 Using /usr/bin/tcsh as shell.
95 {root::wopr-2::49} cd $SRC/cmd/true
96 {root::wopr-2::50} make
97 {root::wopr-2::51} make clobber
98 /usr/bin/rm -f true true.po
99 {root::wopr-2::52} make
103 {root::wopr-2::53} make install
104 install -s -m 0555 -u root -g bin -f /export0/jg/on10-se/proto/root_sparc/usr/bin true
105 `install\' is up to date.]
107 [+?Example 2: Non-interactive use]{
108 [+?Invoke bldenv to create SUNWonbld with a single command:]
109 [+\nexample% bldenv onnv_06 \'cd $SRC/tools && make pkg\']
112 [+SEE ALSO?\bnightly\b(1)]
118 # boolean flags (true/false)
133 typeset DF_build
=false
136 typeset progname
="$(basename -- "${0}")"
140 while getopts -a "${progname}" "${USAGE}" OPT
; do
146 d
) flags.d
=true
; flags.d_set
=true
;;
147 +d
) flags.d
=false
; flags.d_set
=true
;;
155 # test that the path to the environment-setting file was given
156 if (( $# < 1 )) ; then
171 # clear environment variables we know to be bad for the build
200 # Setup environment variables
202 if [[ -f /etc
/nightly.conf
]]; then
203 source /etc
/nightly.conf
206 if [[ -f "$1" ]]; then
207 if [[ "$1" == */* ]]; then
213 if [[ -f "/opt/onbld/env/$1" ]]; then
214 source "/opt/onbld/env/$1"
217 'Cannot find env file as either %s or /opt/onbld/env/%s\n' \
224 # contents of stdenv.sh inserted after next line:
228 # Check if we have sufficient data to continue...
229 [[ -v CODEMGR_WS
]] || fatal_error
"Error: Variable CODEMGR_WS not set."
230 [[ -d "${CODEMGR_WS}" ]] || fatal_error
"Error: ${CODEMGR_WS} is not a directory."
231 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error
"Error: ${CODEMGR_WS}/usr/src/Makefile not found."
233 # must match the getopts in nightly.sh
235 NIGHTLY_OPTIONS
="-${NIGHTLY_OPTIONS#-}"
236 while getopts '+0ABCDdFfGIilMmNnpRrtUuwW' FLAG
$NIGHTLY_OPTIONS
241 F
) flags.DF_build
=true
;;
246 # DEBUG is a little bit complicated. First, bldenv -d/+d over-rides
247 # the env file. Otherwise, we'll default to DEBUG iff we are *not*
248 # building non-DEBUG bits at all.
249 if [ "${flags.d_set}" != "true" ] && "${flags.DF_build}"; then
254 # have we set RELEASE_DATE in our env file?
255 if [ -z "$RELEASE_DATE" ]; then
256 RELEASE_DATE
=$
(LC_ALL
=C
date +"%B %Y")
258 BUILD_DATE
=$
(LC_ALL
=C
date +%Y-
%b-
%d
)
259 BASEWSDIR
=$
(basename -- "${CODEMGR_WS}")
260 DEV_CM
="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
261 export DEV_CM RELEASE_DATE POUND_SIGN
263 print
'Build type is \c'
271 # default is a non-DEBUG build
274 export RELEASE_BUILD
=
279 # update build-type variables
280 PKGARCHIVE
="${PKGARCHIVE}${SUFFIX}"
282 # Set PATH for a build
283 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:."
284 if [[ "${SUNWSPRO}" != "" ]]; then
285 export PATH
="${SUNWSPRO}/bin:$PATH"
288 if [[ -n "${MAKE}" ]]; then
289 if [[ -x "${MAKE}" ]]; then
290 export PATH
="$(dirname -- "${MAKE}"):$PATH"
292 print
"\$MAKE (${MAKE}) is not a valid executible"
298 TOOLS_PROTO
="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
300 if "${flags.t}" ; then
301 export ONBLD_TOOLS
="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
303 export STABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
304 export CTFSTABS
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
305 export GENOFFSETS
="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
307 export CTFCONVERT
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert"
308 export CTFMERGE
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge"
309 export NDRGEN
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ndrgen"
311 PATH
="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
312 PATH
="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
316 export DMAKE_MODE
=${DMAKE_MODE:-parallel}
319 # Work around folks who have historically used GCC_ROOT and convert it to
320 # GNUC_ROOT. We leave GCC_ROOT in the environment for now (though this could
321 # mess up the case where multiple different gcc versions are being used to
324 if [[ -n "${GCC_ROOT}" ]]; then
325 export GNUC_ROOT
=${GCC_ROOT}
352 if [[ "$MULTI_PROTO" != "yes" && "$MULTI_PROTO" != "no" ]]; then
354 'WARNING: invalid value for MULTI_PROTO (%s); setting to "no".\n' \
356 export MULTI_PROTO
="no"
359 [[ "$MULTI_PROTO" == "yes" ]] && export ROOT
="${ROOT}${SUFFIX}"
361 ENVLDLIBS1
="-L$ROOT/lib -L$ROOT/usr/lib"
362 ENVCPPFLAGS1
="-I$ROOT/usr/include"
377 printf 'RELEASE is %s\n' "$RELEASE"
378 printf 'VERSION is %s\n' "$VERSION"
379 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
381 if [[ -f "$SRC/Makefile" ]] && egrep -s '^setup:' "$SRC/Makefile" ; then
382 print
"The top-level 'setup' target is available \c"
383 print
"to build headers and tools."
386 elif "${flags.t}" ; then
388 'The tools can be (re)built with the install target in %s.\n\n' \
393 # place ourselves in a new task, respecting BUILD_PROJECT if set.
395 /usr
/bin
/newtask
-c $$
${BUILD_PROJECT:+-p$BUILD_PROJECT}
397 if [[ "${flags.c}" == "false" && -x "$SHELL" && \
398 "$(basename -- "${SHELL}")" != "csh" ]]; then
399 # $SHELL is set, and it's not csh.
401 if "${flags.f}" ; then
402 print
'WARNING: -f is ignored when $SHELL is not csh'
405 printf 'Using %s as shell.\n' "$SHELL"
406 exec "$SHELL" ${@:+-c "$@"}
408 elif "${flags.f}" ; then
409 print
'Using csh -f as shell.'
410 exec csh
-f ${@:+-c "$@"}
413 print
'Using csh as shell.'
414 exec csh
${@:+-c "$@"}