1#!/bin/ksh -p 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 2007 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# 33USAGE='Usage: bldenv [-fdt] [ -S E|D|H|O ] <env_file> [ command ] 34 35Where: 36 -c Force the use of csh - ignore $SHELL 37 -f Invoke csh with -f 38 -d Setup a DEBUG build (default: non-DEBUG) 39 -t use the tools in $SRC/tools 40 -S Build a variant of the source product 41 E - build exportable source 42 D - build domestic source (exportable + crypt) 43 H - build hybrid source (binaries + deleted source) 44 O - simulate OpenSolaris build 45' 46 47c_FLAG=n 48f_FLAG=n 49d_FLAG=n 50O_FLAG=n 51o_FLAG=n 52t_FLAG=n 53SE_FLAG=n 54SH_FLAG=n 55SD_FLAG=n 56SO_FLAG=n 57 58is_source_build() { 59 [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \ 60 "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ] 61 return $? 62} 63 64# 65# single function for setting -S flag and doing error checking. 66# usage: set_S_flag <type> 67# where <type> is the source build type ("E", "D", ...). 68# 69set_S_flag() { 70 if is_source_build; then 71 echo "Can only build one source variant at a time." 72 exit 1 73 fi 74 if [ "$1" = "E" ]; then 75 SE_FLAG=y 76 elif [ "$1" = "D" ]; then 77 SD_FLAG=y 78 elif [ "$1" = "H" ]; then 79 SH_FLAG=y 80 elif [ "$1" = "O" ]; then 81 SO_FLAG=y 82 else 83 echo "$USAGE" 84 exit 1 85 fi 86} 87 88OPTIND=1 89SUFFIX="-nd" 90while getopts cdfS:t FLAG 91do 92 case $FLAG in 93 c ) c_FLAG=y 94 ;; 95 f ) f_FLAG=y 96 ;; 97 d ) d_FLAG=y 98 SUFFIX="" 99 ;; 100 t ) t_FLAG=y 101 ;; 102 S ) 103 set_S_flag $OPTARG 104 ;; 105 \?) echo "$USAGE" 106 exit 1 107 ;; 108 esac 109done 110 111# correct argument count after options 112shift `expr $OPTIND - 1` 113 114# test that the path to the environment-setting file was given 115if [ $# -lt 1 ] 116then 117 echo "$USAGE" 118 exit 1 119fi 120 121# force locale to C 122LC_COLLATE=C; export LC_COLLATE 123LC_CTYPE=C; export LC_CTYPE 124LC_MESSAGES=C; export LC_MESSAGES 125LC_MONETARY=C; export LC_MONETARY 126LC_NUMERIC=C; export LC_NUMERIC 127LC_TIME=C; export LC_TIME 128 129# clear environment variables we know to be bad for the build 130unset LD_OPTIONS LD_LIBRARY_PATH LD_AUDIT LD_BIND_NOW LD_BREADTH LD_CONFIG 131unset LD_DEBUG LD_FLAGS LD_LIBRARY_PATH_64 LD_NOVERSION LD_ORIGIN 132unset LD_LOADFLTR LD_NOAUXFLTR LD_NOCONFIG LD_NODIRCONFIG LD_NOOBJALTER 133unset LD_PRELOAD LD_PROFILE 134unset CONFIG 135unset GROUP 136unset OWNER 137unset REMOTE 138unset ENV 139unset ARCH 140unset CLASSPATH 141 142# setup environmental variables 143if [ -f $1 ]; then 144 if [[ $1 = */* ]]; then 145 . $1 146 else 147 . ./$1 148 fi 149else 150 if [ -f /opt/onbld/env/$1 ]; then 151 . /opt/onbld/env/$1 152 else 153 echo "Cannot find env file as either $1 or /opt/onbld/env/$1" 154 exit 1 155 fi 156fi 157shift 158 159# contents of stdenv.sh inserted after next line: 160# STDENV_START 161# STDENV_END 162 163#MACH=`uname -p` 164 165# must match the getopts in nightly.sh 166OPTIND=1 167NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-} 168while getopts AaBCDdFfGIilMmNnOopRrS:tUuWwXxz FLAG $NIGHTLY_OPTIONS 169do 170 case $FLAG in 171 O) O_FLAG=y 172 ;; 173 o) o_FLAG=y 174 ;; 175 t ) t_FLAG=y 176 ;; 177 S ) 178 set_S_flag $OPTARG 179 ;; 180 *) ;; 181 esac 182done 183 184echo "Build type is \c" 185if [ ${d_FLAG} = "y" ]; then 186 echo "DEBUG" 187 export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD= 188 unset RELEASE_BUILD 189 unset EXTRA_OPTIONS 190 unset EXTRA_CFLAGS 191else 192 # default is a non-DEBUG build 193 echo "non-DEBUG" 194 export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD= 195 export RELEASE_BUILD ; RELEASE_BUILD= 196 unset EXTRA_OPTIONS 197 unset EXTRA_CFLAGS 198fi 199 200if [ $O_FLAG = "y" ]; then 201 export MULTI_PROTO=yes 202 if [ "$CLOSED_IS_PRESENT" = "yes" ]; then 203 echo "CLOSED_IS_PRESENT is 'no' (because of '-O')" 204 fi 205 export CLOSED_IS_PRESENT=no 206 export ON_CLOSED_BINS=$CODEMGR_WS/closed.skel 207fi 208 209# update build-type variables 210CPIODIR=${CPIODIR}${SUFFIX} 211PKGARCHIVE=${PKGARCHIVE}${SUFFIX} 212 213# Append source version 214if [ "$SE_FLAG" = "y" ]; then 215 VERSION="${VERSION}:EXPORT" 216 SRC=${EXPORT_SRC}/usr/src 217fi 218 219if [ "$SD_FLAG" = "y" ]; then 220 VERSION="${VERSION}:DOMESTIC" 221 SRC=${EXPORT_SRC}/usr/src 222fi 223 224if [ "$SH_FLAG" = "y" ]; then 225 VERSION="${VERSION}:HYBRID" 226 SRC=${EXPORT_SRC}/usr/src 227fi 228 229if [ "$SO_FLAG" = "y" ]; then 230 VERSION="${VERSION}:OPEN_ONLY" 231 SRC=${OPEN_SRCDIR}/usr/src 232fi 233 234# Set PATH for a build 235PATH="/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:." 236if [ "${SUNWSPRO}" != "" ]; then 237 PATH="${SUNWSPRO}/bin:$PATH" 238 export PATH 239fi 240 241if [ -z "$CLOSED_IS_PRESENT" ]; then 242 if [ -d $SRC/../closed ]; then 243 CLOSED_IS_PRESENT="yes" 244 else 245 CLOSED_IS_PRESENT="no" 246 fi 247 export CLOSED_IS_PRESENT 248fi 249 250TOOLS=${SRC}/tools 251TOOLS_PROTO=${TOOLS}/proto 252 253if [ "$t_FLAG" = "y" ]; then 254 export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld} 255 256 STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs 257 export STABS 258 CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs 259 export CTFSTABS 260 GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets 261 export GENOFFSETS 262 263 CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert 264 export CTFCONVERT 265 CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge 266 export CTFMERGE 267 268 CTFCVTPTBL=${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl 269 export CTFCVTPTBL 270 CTFFINDMOD=${TOOLS_PROTO}/opt/onbld/bin/ctffindmod 271 export CTFFINDMOD 272 273 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}" 274 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}" 275 export PATH 276fi 277 278unset CH 279if [ "$o_FLAG" = "y" ]; then 280 CH= 281 export CH 282fi 283POUND_SIGN="#" 284DEF_STRIPFLAG="-s" 285 286TMPDIR="/tmp" 287 288export PATH TMPDIR o_FLAG POUND_SIGN DEF_STRIPFLAG 289unset CFLAGS LD_LIBRARY_PATH 290 291# a la ws 292ENVLDLIBS1= 293ENVLDLIBS2= 294ENVLDLIBS3= 295ENVCPPFLAGS1= 296ENVCPPFLAGS2= 297ENVCPPFLAGS3= 298ENVCPPFLAGS4= 299PARENT_ROOT= 300 301[ "$O_FLAG" = "y" ] && export ROOT=$ROOT-open 302 303if [ "$MULTI_PROTO" != "yes" -a "$MULTI_PROTO" != "no" ]; then 304 echo "WARNING: invalid value for MULTI_PROTO ($MULTI_PROTO);" \ 305 "setting to \"no\"." 306 export MULTI_PROTO=no 307fi 308 309[ "$MULTI_PROTO" = "yes" ] && export ROOT=$ROOT$SUFFIX 310 311ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib" 312ENVCPPFLAGS1="-I$ROOT/usr/include" 313MAKEFLAGS=e 314 315export ENVLDLIBS1 ENVLDLIBS2 ENVLDLIBS3 \ 316 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 \ 317 ENVCPPFLAGS4 MAKEFLAGS PARENT_ROOT 318 319echo "RELEASE is $RELEASE" 320echo "VERSION is $VERSION" 321echo "RELEASE_DATE is $RELEASE_DATE" 322echo "" 323 324if [[ -f $SRC/Makefile ]] && egrep -s '^setup:' $SRC/Makefile; then 325 echo "The top-level 'setup' target is available \c" 326 echo "to build headers and tools." 327 echo "" 328 329elif [[ "$t_FLAG" = "y" ]]; then 330 echo "The tools can be (re)built with the install target in ${TOOLS}." 331 echo "" 332fi 333 334 335if [[ "$c_FLAG" = "n" && -x "$SHELL" && `basename $SHELL` != "csh" ]]; then 336 # $SHELL is set, and it's not csh. 337 338 if [[ "$f_FLAG" != "n" ]]; then 339 echo "WARNING: -f is ignored when \$SHELL is not csh" 340 fi 341 342 echo "Using $SHELL as shell." 343 exec $SHELL ${@:+-c "$@"} 344 345elif [[ "$f_FLAG" = "y" ]]; then 346 echo "Using csh -f as shell." 347 exec csh -f ${@:+-c "$@"} 348 349else 350 echo "Using csh as shell." 351 exec csh ${@:+-c "$@"} 352fi 353