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 32function fatal_error 33{ 34 print -u2 "${progname}: $*" 35 exit 1 36} 37 38function usage 39{ 40 OPTIND=0 41 getopts -a "${progname}" "${USAGE}" OPT '-?' 42 exit 2 43} 44 45function 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# 56function 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 72typeset -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. 112The 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 129Build type is DEBUG 130RELEASE is 5.10 131VERSION is wopr-2::on10-se::11/01/2001 132RELEASE_DATE is May 2004 133The top-level `setup\' target is available to build headers 134and tools. 135Using /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 143cat true.sh > true 144chmod +x true 145{root::wopr-2::53} make install 146install -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 158builtin basename 159 160# boolean flags (true/false) 161typeset 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 176typeset progname="$(basename -- "${0}")" 177 178OPTIND=1 179SUFFIX="-nd" 180 181while 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 194done 195shift $((OPTIND-1)) 196 197# test that the path to the environment-setting file was given 198if (( $# < 1 )) ; then 199 usage 200fi 201 202# force locale to C 203export \ 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 212unset \ 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# 242if [[ -f /etc/nightly.conf ]]; then 243 source /etc/nightly.conf 244fi 245 246if [[ -f "$1" ]]; then 247 if [[ "$1" == */* ]]; then 248 source "$1" 249 else 250 source "./$1" 251 fi 252else 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 261fi 262shift 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#MACH=$(uname -p) 274 275# must match the getopts in nightly.sh 276OPTIND=1 277NIGHTLY_OPTIONS="-${NIGHTLY_OPTIONS#-}" 278while getopts '+0AaBCDdFfGIilMmNnOopRrS:tUuWwXxz' FLAG "$NIGHTLY_OPTIONS" 279do 280 case "$FLAG" in 281 O) flags.O=true ;; 282 +O) flags.O=false ;; 283 o) flags.o=true ;; 284 +o) flags.o=false ;; 285 t) flags.t=true ;; 286 +t) flags.t=false ;; 287 S) set_S_flag "$OPTARG" ;; 288 *) ;; 289 esac 290done 291 292POUND_SIGN="#" 293# have we set RELEASE_DATE in our env file? 294if [ -z "$RELEASE_DATE" ]; then 295 RELEASE_DATE=$(LC_ALL=C date +"%B %Y") 296fi 297BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d) 298BASEWSDIR=$(basename -- "${CODEMGR_WS}") 299DEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\"" 300export DEV_CM RELEASE_DATE POUND_SIGN 301 302export INTERNAL_RELEASE_BUILD= 303 304print 'Build type is \c' 305if ${flags.d} ; then 306 print 'DEBUG' 307 unset RELEASE_BUILD 308 unset EXTRA_OPTIONS 309 unset EXTRA_CFLAGS 310else 311 # default is a non-DEBUG build 312 print 'non-DEBUG' 313 export RELEASE_BUILD= 314 unset EXTRA_OPTIONS 315 unset EXTRA_CFLAGS 316fi 317 318[[ "${flags.O}" ]] && export MULTI_PROTO="yes" 319 320# update build-type variables 321PKGARCHIVE="${PKGARCHIVE}${SUFFIX}" 322 323# Append source version 324if "${flags.s.e}" ; then 325 VERSION+=":EXPORT" 326 SRC="${EXPORT_SRC}/usr/src" 327fi 328 329if "${flags.s.d}" ; then 330 VERSION+=":DOMESTIC" 331 SRC="${EXPORT_SRC}/usr/src" 332fi 333 334if "${flags.s.h}" ; then 335 VERSION+=":HYBRID" 336 SRC="${EXPORT_SRC}/usr/src" 337fi 338 339if "${flags.s.o}" ; then 340 VERSION+=":OPEN_ONLY" 341 SRC="${OPEN_SRCDIR}/usr/src" 342fi 343 344# 345# Keep track of this now, before we manipulate $PATH 346# 347WHICH_SCM="$(dirname -- "$(whence "$0")")/which_scm" 348if [[ ! -x $WHICH_SCM ]]; then 349 WHICH_SCM=which_scm 350fi 351$WHICH_SCM | read SCM_TYPE junk 352 353 354# Set PATH for a build 355PATH="/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:." 356if [[ "${SUNWSPRO}" != "" ]]; then 357 export PATH="${SUNWSPRO}/bin:$PATH" 358fi 359 360if [[ -z "$CLOSED_IS_PRESENT" ]]; then 361 if [[ -d $SRC/../closed ]]; then 362 export CLOSED_IS_PRESENT="yes" 363 else 364 export CLOSED_IS_PRESENT="no" 365 fi 366fi 367 368TOOLS="${SRC}/tools" 369TOOLS_PROTO="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO 370 371if "${flags.t}" ; then 372 export ONBLD_TOOLS="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}" 373 374 export STABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs" 375 export CTFSTABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs" 376 export GENOFFSETS="${TOOLS_PROTO}/opt/onbld/bin/genoffsets" 377 378 export CTFCONVERT="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert" 379 export CTFMERGE="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge" 380 381 export CTFCVTPTBL="${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl" 382 export CTFFINDMOD="${TOOLS_PROTO}/opt/onbld/bin/ctffindmod" 383 384 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}" 385 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}" 386 export PATH 387fi 388 389export DMAKE_MODE=${DMAKE_MODE:-parallel} 390 391if "${flags.o}" ; then 392 export CH= 393else 394 unset CH 395fi 396DEF_STRIPFLAG="-s" 397 398TMPDIR="/tmp" 399 400# "o_FLAG" is used by "nightly.sh" (it may be useful to rename this 401# variable using a more descriptive name later) 402export o_FLAG="$(${flags.o} && print 'y' || print 'n')" 403 404export \ 405 PATH TMPDIR \ 406 POUND_SIGN \ 407 DEF_STRIPFLAG \ 408 RELEASE_DATE 409unset \ 410 CFLAGS \ 411 LD_LIBRARY_PATH 412 413# a la ws 414ENVLDLIBS1= 415ENVLDLIBS2= 416ENVLDLIBS3= 417ENVCPPFLAGS1= 418ENVCPPFLAGS2= 419ENVCPPFLAGS3= 420ENVCPPFLAGS4= 421PARENT_ROOT= 422PARENT_TOOLS_ROOT= 423 424if [[ "$MULTI_PROTO" != "yes" && "$MULTI_PROTO" != "no" ]]; then 425 printf \ 426 'WARNING: invalid value for MULTI_PROTO (%s); setting to "no".\n' \ 427 "$MULTI_PROTO" 428 export MULTI_PROTO="no" 429fi 430 431[[ "$MULTI_PROTO" == "yes" ]] && export ROOT="${ROOT}${SUFFIX}" 432 433export TONICBUILD="#" 434 435if "${flags.O}" ; then 436 if [[ "$CLOSED_IS_PRESENT" != "yes" ]]; then 437 print "OpenSolaris closed binary generation requires " 438 print "closed tree" 439 exit 1 440 fi 441 print "Generating OpenSolaris deliverables" 442 # We only need CLOSEDROOT in the env for convenience. Makefile.master 443 # figures out what it needs when it matters. 444 export CLOSEDROOT="${ROOT}-closed" 445 export TONICBUILD="" 446fi 447 448ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib" 449ENVCPPFLAGS1="-I$ROOT/usr/include" 450MAKEFLAGS=e 451 452export \ 453 ENVLDLIBS1 \ 454 ENVLDLIBS2 \ 455 ENVLDLIBS3 \ 456 ENVCPPFLAGS1 \ 457 ENVCPPFLAGS2 \ 458 ENVCPPFLAGS3 \ 459 ENVCPPFLAGS4 \ 460 MAKEFLAGS \ 461 PARENT_ROOT \ 462 PARENT_TOOLS_ROOT \ 463 SCM_TYPE 464 465printf 'RELEASE is %s\n' "$RELEASE" 466printf 'VERSION is %s\n' "$VERSION" 467printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE" 468 469if [[ -f "$SRC/Makefile" ]] && egrep -s '^setup:' "$SRC/Makefile" ; then 470 print "The top-level 'setup' target is available \c" 471 print "to build headers and tools." 472 print "" 473 474elif "${flags.t}" ; then 475 printf \ 476 'The tools can be (re)built with the install target in %s.\n\n' \ 477 "${TOOLS}" 478fi 479 480# 481# place ourselves in a new task, respecting BUILD_PROJECT if set. 482# 483/usr/bin/newtask -c $$ ${BUILD_PROJECT:+-p$BUILD_PROJECT} 484 485if [[ "${flags.c}" == "false" && -x "$SHELL" && \ 486 "$(basename -- "${SHELL}")" != "csh" ]]; then 487 # $SHELL is set, and it's not csh. 488 489 if "${flags.f}" ; then 490 print 'WARNING: -f is ignored when $SHELL is not csh' 491 fi 492 493 printf 'Using %s as shell.\n' "$SHELL" 494 exec "$SHELL" ${@:+-c "$@"} 495 496elif "${flags.f}" ; then 497 print 'Using csh -f as shell.' 498 exec csh -f ${@:+-c "$@"} 499 500else 501 print 'Using csh as shell.' 502 exec csh ${@:+-c "$@"} 503fi 504 505# not reached 506