1 #!/usr/bin/ksh93 2 # 3 # CDDL HEADER START 4 # 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. 8 # 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. 13 # 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] 19 # 20 # CDDL HEADER END 21 # 22 23 # 24 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 25 # Copyright 2011 Nexenta Systems, Inc. All rights reserved. 26 # 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 29 # and incrementally. 30 # 31 32 function fatal_error 33 { 34 print -u2 "${progname}: $*" 35 exit 1 36 } 37 38 function usage 39 { 40 OPTIND=0 41 getopts -a "${progname}" "${USAGE}" OPT '-?' 42 exit 2 43 } 44 45 function is_source_build 46 { 47 "${flags.s.e}" || "${flags.s.d}" || "${flags.s.h}" || "${flags.s.o}" 48 return $? 49 } 50 51 # 52 # single function for setting -S flag and doing error checking. 53 # usage: set_S_flag <type> 54 # where <type> is the source build type ("E", "D", ...). 55 # 56 function set_S_flag 57 { 58 if is_source_build; then 59 print 'Can only build one source variant at a time.' 60 exit 1 61 fi 62 63 case "$1" in 64 "E") flags.s.e=true ;; 65 "D") flags.s.d=true ;; 66 "H") flags.s.h=true ;; 67 "O") flags.s.o=true ;; 68 *) usage ;; 69 esac 70 } 71 72 typeset -r USAGE=$'+ 73 [-?\n@(#)\$Id: bldenv (OS/Net) 2008-04-06 \$\n] 74 [-author?OS/Net community <tools-discuss@opensolaris.org>] 75 [+NAME?bldenv - spawn shell for interactive incremental OS-Net 76 consolidation builds] 77 [+DESCRIPTION?bldenv is a useful companion to the nightly(1) script for 78 doing interactive and incremental builds in a workspace 79 already built with nightly(1). bldenv spawns a shell set up 80 with the same environment variables taken from an env_file, 81 as prepared for use with nightly(1).] 82 [+?In addition to running a shell for interactive use, bldenv 83 can optionally run a single command in the given environment, 84 in the vein of sh -c or su -c. This is useful for 85 scripting, when an interactive shell would not be. If the 86 command is composed of multiple shell words or contains 87 other shell metacharacters, it must be quoted appropriately.] 88 [+?bldenv is particularly useful for testing Makefile targets 89 like clobber, install and _msg, which otherwise require digging 90 through large build logs to figure out what is being 91 done.] 92 [+?bldenv is also useful if you run into build issues with the 93 source product or when generating OpenSolaris deliverables. 94 If a source product build is flagged, the environment is set 95 up for building the indicated source product tree, which is 96 assumed to have already been created. If the OpenSolaris 97 deliverables flag (-O) is set in NIGHTLY_OPTIONS, the 98 environment is set up for building just the open source. 99 This includes using an alternate proto area, as well as 100 using the closed binaries in $CODEMGR_WS/closed.skel (which 101 is assumed to already exist).] 102 [+?By default, bldenv will invoke the shell specified in 103 $SHELL. If $SHELL is not set or is invalid, csh will be 104 used.] 105 [c?force the use of csh, regardless of the value of $SHELL.] 106 [f?invoke csh with the -f (fast-start) option. This option is valid 107 only if $SHELL is unset or if it points to csh.] 108 [d?set up environment for doing DEBUG builds (default is non-DEBUG)] 109 [t?set up environment to use the tools in usr/src/tools (this is the 110 default, use +t to use the tools from /opt/onbld)] 111 [S]:[option?Build a variant of the source product. 112 The value of \aoption\a must be one of the following:]{ 113 [+E?build the exportable source variant of the source product.] 114 [+D?build the domestic source (exportable + crypt) variant of 115 the source product.] 116 [+H?build hybrid source (binaries + deleted source).] 117 [+O?simulate an OpenSolaris (open source only) build.] 118 } 119 120 <env_file> [command] 121 122 [+EXAMPLES]{ 123 [+?Example 1: Interactive use]{ 124 [+?Use bldenv to spawn a shell to perform a DEBUG build and 125 testing of the Makefile targets clobber and install for 126 usr/src/cmd/true.] 127 [+\n% rlogin wopr-2 -l gk 128 {root::wopr-2::49} bldenv -d /export0/jg/on10-se.env 129 Build type is DEBUG 130 RELEASE is 5.10 131 VERSION is wopr-2::on10-se::11/01/2001 132 RELEASE_DATE is May 2004 133 The top-level `setup\' target is available to build headers 134 and tools. 135 Using /usr/bin/tcsh as shell. 136 {root::wopr-2::49} 137 {root::wopr-2::49} cd $SRC/cmd/true 138 {root::wopr-2::50} make 139 {root::wopr-2::51} make clobber 140 /usr/bin/rm -f true true.po 141 {root::wopr-2::52} make 142 /usr/bin/rm -f true 143 cat true.sh > true 144 chmod +x true 145 {root::wopr-2::53} make install 146 install -s -m 0555 -u root -g bin -f /export0/jg/on10-se/proto/root_sparc/usr/bin true 147 `install\' is up to date.] 148 } 149 [+?Example 2: Non-interactive use]{ 150 [+?Invoke bldenv to create SUNWonbld with a single command:] 151 [+\nexample% bldenv onnv_06 \'cd $SRC/tools && make pkg\'] 152 } 153 } 154 [+SEE ALSO?\bnightly\b(1)] 155 ' 156 157 # main 158 builtin basename 159 160 # boolean flags (true/false) 161 typeset flags=( 162 typeset c=false 163 typeset f=false 164 typeset d=false 165 typeset O=false 166 typeset o=false 167 typeset t=true 168 typeset s=( 169 typeset e=false 170 typeset h=false 171 typeset d=false 172 typeset o=false 173 ) 174 ) 175 176 typeset progname="$(basename -- "${0}")" 177 178 OPTIND=1 179 SUFFIX="-nd" 180 181 while getopts -a "${progname}" "${USAGE}" OPT ; do 182 case ${OPT} in 183 c) flags.c=true ;; 184 +c) flags.c=false ;; 185 f) flags.f=true ;; 186 +f) flags.f=false ;; 187 d) flags.d=true SUFFIX="" ;; 188 +d) flags.d=false SUFFIX="-nd" ;; 189 t) flags.t=true ;; 190 +t) flags.t=false ;; 191 S) set_S_flag "$OPTARG" ;; 192 \?) usage ;; 193 esac 194 done 195 shift $((OPTIND-1)) 196 197 # test that the path to the environment-setting file was given 198 if (( $# < 1 )) ; then 199 usage 200 fi 201 202 # force locale to C 203 export \ 204 LC_COLLATE=C \ 205 LC_CTYPE=C \ 206 LC_MESSAGES=C \ 207 LC_MONETARY=C \ 208 LC_NUMERIC=C \ 209 LC_TIME=C 210 211 # clear environment variables we know to be bad for the build 212 unset \ 213 LD_OPTIONS \ 214 LD_LIBRARY_PATH \ 215 LD_AUDIT \ 216 LD_BIND_NOW \ 217 LD_BREADTH \ 218 LD_CONFIG \ 219 LD_DEBUG \ 220 LD_FLAGS \ 221 LD_LIBRARY_PATH_64 \ 222 LD_NOVERSION \ 223 LD_ORIGIN \ 224 LD_LOADFLTR \ 225 LD_NOAUXFLTR \ 226 LD_NOCONFIG \ 227 LD_NODIRCONFIG \ 228 LD_NOOBJALTER \ 229 LD_PRELOAD \ 230 LD_PROFILE \ 231 CONFIG \ 232 GROUP \ 233 OWNER \ 234 REMOTE \ 235 ENV \ 236 ARCH \ 237 CLASSPATH 238 239 # 240 # Setup environment variables 241 # 242 if [[ -f /etc/nightly.conf ]]; then 243 source /etc/nightly.conf 244 fi 245 246 if [[ -f "$1" ]]; then 247 if [[ "$1" == */* ]]; then 248 source "$1" 249 else 250 source "./$1" 251 fi 252 else 253 if [[ -f "/opt/onbld/env/$1" ]]; then 254 source "/opt/onbld/env/$1" 255 else 256 printf \ 257 'Cannot find env file as either %s or /opt/onbld/env/%s\n' \ 258 "$1" "$1" 259 exit 1 260 fi 261 fi 262 shift 263 264 # contents of stdenv.sh inserted after next line: 265 # STDENV_START 266 # STDENV_END 267 268 # Check if we have sufficient data to continue... 269 [[ -v CODEMGR_WS ]] || fatal_error "Error: Variable CODEMGR_WS not set." 270 [[ -d "${CODEMGR_WS}" ]] || fatal_error "Error: ${CODEMGR_WS} is not a directory." 271 [[ -f "${CODEMGR_WS}/usr/src/Makefile" ]] || fatal_error "Error: ${CODEMGR_WS}/usr/src/Makefile not found." 272 273 # must match the getopts in nightly.sh 274 OPTIND=1 275 NIGHTLY_OPTIONS="-${NIGHTLY_OPTIONS#-}" 276 while getopts '+0AaBCDdFfGIilMmNnOopRrS:tUuWwXxz' FLAG "$NIGHTLY_OPTIONS" 277 do 278 case "$FLAG" in 279 O) flags.O=true ;; 280 +O) flags.O=false ;; 281 o) flags.o=true ;; 282 +o) flags.o=false ;; 283 t) flags.t=true ;; 284 +t) flags.t=false ;; 285 S) set_S_flag "$OPTARG" ;; 286 *) ;; 287 esac 288 done 289 290 POUND_SIGN="#" 291 # have we set RELEASE_DATE in our env file? 292 if [ -z "$RELEASE_DATE" ]; then 293 RELEASE_DATE=$(LC_ALL=C date +"%B %Y") 294 fi 295 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d) 296 BASEWSDIR=$(basename -- "${CODEMGR_WS}") 297 DEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\"" 298 export DEV_CM RELEASE_DATE POUND_SIGN 299 300 export INTERNAL_RELEASE_BUILD= 301 302 print 'Build type is \c' 303 if ${flags.d} ; then 304 print 'DEBUG' 305 unset RELEASE_BUILD 306 unset EXTRA_OPTIONS 307 unset EXTRA_CFLAGS 308 else 309 # default is a non-DEBUG build 310 print 'non-DEBUG' 311 export RELEASE_BUILD= 312 unset EXTRA_OPTIONS 313 unset EXTRA_CFLAGS 314 fi 315 316 [[ "${flags.O}" == "true" ]] && export MULTI_PROTO="yes" 317 318 # update build-type variables 319 PKGARCHIVE="${PKGARCHIVE}${SUFFIX}" 320 321 # Append source version 322 if "${flags.s.e}" ; then 323 VERSION+=":EXPORT" 324 SRC="${EXPORT_SRC}/usr/src" 325 fi 326 327 if "${flags.s.d}" ; then 328 VERSION+=":DOMESTIC" 329 SRC="${EXPORT_SRC}/usr/src" 330 fi 331 332 if "${flags.s.h}" ; then 333 VERSION+=":HYBRID" 334 SRC="${EXPORT_SRC}/usr/src" 335 fi 336 337 if "${flags.s.o}" ; then 338 VERSION+=":OPEN_ONLY" 339 SRC="${OPEN_SRCDIR}/usr/src" 340 fi 341 342 # Set PATH for a build 343 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:." 344 if [[ "${SUNWSPRO}" != "" ]]; then 345 export PATH="${SUNWSPRO}/bin:$PATH" 346 fi 347 348 TOOLS="${SRC}/tools" 349 TOOLS_PROTO="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO 350 351 if "${flags.t}" ; then 352 export ONBLD_TOOLS="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}" 353 354 export STABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs" 355 export CTFSTABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs" 356 export GENOFFSETS="${TOOLS_PROTO}/opt/onbld/bin/genoffsets" 357 358 export CTFCONVERT="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert" 359 export CTFMERGE="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge" 360 361 export CTFCVTPTBL="${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl" 362 export CTFFINDMOD="${TOOLS_PROTO}/opt/onbld/bin/ctffindmod" 363 364 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}" 365 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}" 366 export PATH 367 fi 368 369 export DMAKE_MODE=${DMAKE_MODE:-parallel} 370 371 if "${flags.o}" ; then 372 export CH= 373 else 374 unset CH 375 fi 376 DEF_STRIPFLAG="-s" 377 378 TMPDIR="/tmp" 379 380 # "o_FLAG" is used by "nightly.sh" (it may be useful to rename this 381 # variable using a more descriptive name later) 382 export o_FLAG="$(${flags.o} && print 'y' || print 'n')" 383 384 export \ 385 PATH TMPDIR \ 386 POUND_SIGN \ 387 DEF_STRIPFLAG \ 388 RELEASE_DATE 389 unset \ 390 CFLAGS \ 391 LD_LIBRARY_PATH 392 393 # a la ws 394 ENVLDLIBS1= 395 ENVLDLIBS2= 396 ENVLDLIBS3= 397 ENVCPPFLAGS1= 398 ENVCPPFLAGS2= 399 ENVCPPFLAGS3= 400 ENVCPPFLAGS4= 401 PARENT_ROOT= 402 PARENT_TOOLS_ROOT= 403 404 if [[ "$MULTI_PROTO" != "yes" && "$MULTI_PROTO" != "no" ]]; then 405 printf \ 406 'WARNING: invalid value for MULTI_PROTO (%s); setting to "no".\n' \ 407 "$MULTI_PROTO" 408 export MULTI_PROTO="no" 409 fi 410 411 [[ "$MULTI_PROTO" == "yes" ]] && export ROOT="${ROOT}${SUFFIX}" 412 413 export TONICBUILD="#" 414 415 if "${flags.O}" ; then 416 print "OpenSolaris closed binary generation requires " 417 print "closed tree" 418 exit 1 419 fi 420 421 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib" 422 ENVCPPFLAGS1="-I$ROOT/usr/include" 423 MAKEFLAGS=e 424 425 export \ 426 ENVLDLIBS1 \ 427 ENVLDLIBS2 \ 428 ENVLDLIBS3 \ 429 ENVCPPFLAGS1 \ 430 ENVCPPFLAGS2 \ 431 ENVCPPFLAGS3 \ 432 ENVCPPFLAGS4 \ 433 MAKEFLAGS \ 434 PARENT_ROOT \ 435 PARENT_TOOLS_ROOT 436 437 printf 'RELEASE is %s\n' "$RELEASE" 438 printf 'VERSION is %s\n' "$VERSION" 439 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE" 440 441 if [[ -f "$SRC/Makefile" ]] && egrep -s '^setup:' "$SRC/Makefile" ; then 442 print "The top-level 'setup' target is available \c" 443 print "to build headers and tools." 444 print "" 445 446 elif "${flags.t}" ; then 447 printf \ 448 'The tools can be (re)built with the install target in %s.\n\n' \ 449 "${TOOLS}" 450 fi 451 452 # 453 # place ourselves in a new task, respecting BUILD_PROJECT if set. 454 # 455 /usr/bin/newtask -c $$ ${BUILD_PROJECT:+-p$BUILD_PROJECT} 456 457 if [[ "${flags.c}" == "false" && -x "$SHELL" && \ 458 "$(basename -- "${SHELL}")" != "csh" ]]; then 459 # $SHELL is set, and it's not csh. 460 461 if "${flags.f}" ; then 462 print 'WARNING: -f is ignored when $SHELL is not csh' 463 fi 464 465 printf 'Using %s as shell.\n' "$SHELL" 466 exec "$SHELL" ${@:+-c "$@"} 467 468 elif "${flags.f}" ; then 469 print 'Using csh -f as shell.' 470 exec csh -f ${@:+-c "$@"} 471 472 else 473 print 'Using csh as shell.' 474 exec csh ${@:+-c "$@"} 475 fi 476 477 # not reached