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