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