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# must match the getopts in nightly.sh 274OPTIND=1 275NIGHTLY_OPTIONS="-${NIGHTLY_OPTIONS#-}" 276while getopts '+0AaBCDdFfGIilMmNnOopRrS:tUuWwXxz' FLAG "$NIGHTLY_OPTIONS" 277do 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 288done 289 290POUND_SIGN="#" 291# have we set RELEASE_DATE in our env file? 292if [ -z "$RELEASE_DATE" ]; then 293 RELEASE_DATE=$(LC_ALL=C date +"%B %Y") 294fi 295BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d) 296BASEWSDIR=$(basename -- "${CODEMGR_WS}") 297DEV_CM="\"@(#)SunOS Internal Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\"" 298export DEV_CM RELEASE_DATE POUND_SIGN 299 300export INTERNAL_RELEASE_BUILD= 301 302print 'Build type is \c' 303if ${flags.d} ; then 304 print 'DEBUG' 305 unset RELEASE_BUILD 306 unset EXTRA_OPTIONS 307 unset EXTRA_CFLAGS 308else 309 # default is a non-DEBUG build 310 print 'non-DEBUG' 311 export RELEASE_BUILD= 312 unset EXTRA_OPTIONS 313 unset EXTRA_CFLAGS 314fi 315 316[[ "${flags.O}" == "true" ]] && export MULTI_PROTO="yes" 317 318# update build-type variables 319PKGARCHIVE="${PKGARCHIVE}${SUFFIX}" 320 321# Append source version 322if "${flags.s.e}" ; then 323 VERSION+=":EXPORT" 324 SRC="${EXPORT_SRC}/usr/src" 325fi 326 327if "${flags.s.d}" ; then 328 VERSION+=":DOMESTIC" 329 SRC="${EXPORT_SRC}/usr/src" 330fi 331 332if "${flags.s.h}" ; then 333 VERSION+=":HYBRID" 334 SRC="${EXPORT_SRC}/usr/src" 335fi 336 337if "${flags.s.o}" ; then 338 VERSION+=":OPEN_ONLY" 339 SRC="${OPEN_SRCDIR}/usr/src" 340fi 341 342# Set PATH for a build 343PATH="/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:." 344if [[ "${SUNWSPRO}" != "" ]]; then 345 export PATH="${SUNWSPRO}/bin:$PATH" 346fi 347 348TOOLS="${SRC}/tools" 349TOOLS_PROTO="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO 350 351if "${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 367fi 368 369export DMAKE_MODE=${DMAKE_MODE:-parallel} 370 371if "${flags.o}" ; then 372 export CH= 373else 374 unset CH 375fi 376DEF_STRIPFLAG="-s" 377 378TMPDIR="/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) 382export o_FLAG="$(${flags.o} && print 'y' || print 'n')" 383 384export \ 385 PATH TMPDIR \ 386 POUND_SIGN \ 387 DEF_STRIPFLAG \ 388 RELEASE_DATE 389unset \ 390 CFLAGS \ 391 LD_LIBRARY_PATH 392 393# a la ws 394ENVLDLIBS1= 395ENVLDLIBS2= 396ENVLDLIBS3= 397ENVCPPFLAGS1= 398ENVCPPFLAGS2= 399ENVCPPFLAGS3= 400ENVCPPFLAGS4= 401PARENT_ROOT= 402PARENT_TOOLS_ROOT= 403 404if [[ "$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" 409fi 410 411[[ "$MULTI_PROTO" == "yes" ]] && export ROOT="${ROOT}${SUFFIX}" 412 413if "${flags.O}" ; then 414 print "OpenSolaris closed binary generation requires " 415 print "closed tree" 416 exit 1 417fi 418 419ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib" 420ENVCPPFLAGS1="-I$ROOT/usr/include" 421MAKEFLAGS=e 422 423export \ 424 ENVLDLIBS1 \ 425 ENVLDLIBS2 \ 426 ENVLDLIBS3 \ 427 ENVCPPFLAGS1 \ 428 ENVCPPFLAGS2 \ 429 ENVCPPFLAGS3 \ 430 ENVCPPFLAGS4 \ 431 MAKEFLAGS \ 432 PARENT_ROOT \ 433 PARENT_TOOLS_ROOT 434 435printf 'RELEASE is %s\n' "$RELEASE" 436printf 'VERSION is %s\n' "$VERSION" 437printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE" 438 439if [[ -f "$SRC/Makefile" ]] && egrep -s '^setup:' "$SRC/Makefile" ; then 440 print "The top-level 'setup' target is available \c" 441 print "to build headers and tools." 442 print "" 443 444elif "${flags.t}" ; then 445 printf \ 446 'The tools can be (re)built with the install target in %s.\n\n' \ 447 "${TOOLS}" 448fi 449 450# 451# place ourselves in a new task, respecting BUILD_PROJECT if set. 452# 453/usr/bin/newtask -c $$ ${BUILD_PROJECT:+-p$BUILD_PROJECT} 454 455if [[ "${flags.c}" == "false" && -x "$SHELL" && \ 456 "$(basename -- "${SHELL}")" != "csh" ]]; then 457 # $SHELL is set, and it's not csh. 458 459 if "${flags.f}" ; then 460 print 'WARNING: -f is ignored when $SHELL is not csh' 461 fi 462 463 printf 'Using %s as shell.\n' "$SHELL" 464 exec "$SHELL" ${@:+-c "$@"} 465 466elif "${flags.f}" ; then 467 print 'Using csh -f as shell.' 468 exec csh -f ${@:+-c "$@"} 469 470else 471 print 'Using csh as shell.' 472 exec csh ${@:+-c "$@"} 473fi 474 475# not reached 476