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