xref: /titanic_51/usr/src/tools/scripts/bldenv.sh (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2005 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 ] <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'
45
46c_FLAG=n
47f_FLAG=n
48d_FLAG=n
49o_FLAG=n
50t_FLAG=n
51SE_FLAG=n
52SH_FLAG=n
53SD_FLAG=n
54
55OPTIND=1
56SUFFIX="-nd"
57while getopts cdfS:t FLAG
58do
59	case $FLAG in
60	  c )	c_FLAG=y
61		;;
62	  f )	f_FLAG=y
63		;;
64	  d )	d_FLAG=y
65		SUFFIX=""
66		;;
67	  t )	t_FLAG=y
68		;;
69	  S )
70		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
71			echo "Can only build one source variant at a time."
72			exit 1
73		fi
74		if [ "${OPTARG}" = "E" ]; then
75			SE_FLAG=y
76		elif [ "${OPTARG}" = "D" ]; then
77			SD_FLAG=y
78		elif [ "${OPTARG}" = "H" ]; then
79			SH_FLAG=y
80		else
81			echo "$USAGE"
82			exit 1
83		fi
84		;;
85	  \?)	echo "$USAGE"
86		exit 1
87		;;
88	esac
89done
90
91# correct argument count after options
92shift `expr $OPTIND - 1`
93
94# test that the path to the environment-setting file was given
95if [ $# -lt 1 ]
96then
97	echo "$USAGE"
98	exit 1
99fi
100
101# force locale to C
102LC_COLLATE=C;   export LC_COLLATE
103LC_CTYPE=C;     export LC_CTYPE
104LC_MESSAGES=C;  export LC_MESSAGES
105LC_MONETARY=C;  export LC_MONETARY
106LC_NUMERIC=C;   export LC_NUMERIC
107LC_TIME=C;      export LC_TIME
108
109# clear environment variables we know to be bad for the build
110unset LD_OPTIONS LD_LIBRARY_PATH LD_AUDIT LD_BIND_NOW LD_BREADTH LD_CONFIG
111unset LD_DEBUG LD_FLAGS LD_LIBRARY_PATH_64 LD_NOVERSION LD_ORIGIN
112unset LD_LOADFLTR LD_NOAUXFLTR LD_NOCONFIG LD_NODIRCONFIG LD_NOOBJALTER
113unset LD_PRELOAD LD_PROFILE
114unset CONFIG
115unset GROUP
116unset OWNER
117unset REMOTE
118unset ENV
119unset ARCH
120unset CLASSPATH
121
122# setup environmental variables
123if [ -f $1 ]; then
124	if [[ $1 = */* ]]; then
125		. $1
126	else
127		. ./$1
128	fi
129else
130	if [ -f /opt/onbld/env/$1 ]; then
131		. /opt/onbld/env/$1
132	else
133		echo "Cannot find env file as either $1 or /opt/onbld/env/$1"
134		exit 1
135	fi
136fi
137shift
138
139#MACH=`uname -p`
140
141# must match the getopts in nightly.sh
142OPTIND=1
143while getopts ABDFMNPTCGIRafinlmoptuUxdrtzWS:X FLAG $NIGHTLY_OPTIONS
144do
145	case $FLAG in
146	  t )	t_FLAG=y
147		;;
148	  S )
149		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
150			echo "Can only build one source variant at a time."
151			exit 1
152		fi
153		if [ "${OPTARG}" = "E" ]; then
154			SE_FLAG=y
155		elif [ "${OPTARG}" = "D" ]; then
156			SD_FLAG=y
157		elif [ "${OPTARG}" = "H" ]; then
158			SH_FLAG=y
159		else
160			echo "$USAGE"
161			exit 1
162		fi
163		;;
164	  o)	o_FLAG=y
165		;;
166	  *)    ;;
167	esac
168done
169
170echo "Build type   is  \c"
171if [ ${d_FLAG} = "y" ]; then
172	echo "DEBUG"
173	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
174	unset RELEASE_BUILD
175	unset EXTRA_OPTIONS
176	unset EXTRA_CFLAGS
177else
178	# default is a non-DEBUG build
179	echo "non-DEBUG"
180	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
181	export RELEASE_BUILD ; RELEASE_BUILD=
182	unset EXTRA_OPTIONS
183	unset EXTRA_CFLAGS
184fi
185
186# update build-type variables
187CPIODIR=${CPIODIR}${SUFFIX}
188PKGARCHIVE=${PKGARCHIVE}${SUFFIX}
189
190if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
191        if [ -z "${EXPORT_SRC}" ]; then
192                echo "EXPORT_SRC must be set for a source build."
193                exit 1
194        fi
195        if [ -z "${CRYPT_SRC}" ]; then
196                echo "CRYPT_SRC must be set for a source build."
197                exit 1
198        fi
199fi
200
201if [ "$SH_FLAG" = "y" ]; then
202        if [ -z "${EXPORT_SRC}" ]; then
203                echo "EXPORT_SRC must be set for a source build."
204                exit 1
205        fi
206fi
207
208# Append source version
209if [ "$SE_FLAG" = "y" ]; then
210        VERSION="${VERSION}:EXPORT"
211	SRC=${EXPORT_SRC}/usr/src
212fi
213
214if [ "$SD_FLAG" = "y" ]; then
215        VERSION="${VERSION}:DOMESTIC"
216	SRC=${EXPORT_SRC}/usr/src
217fi
218
219if [ "$SH_FLAG" = "y" ]; then
220        VERSION="${VERSION}:HYBRID"
221	SRC=${EXPORT_SRC}/usr/src
222fi
223
224# 	Set PATH for a build
225PATH="/opt/onbld/bin:/opt/onbld/bin/${MACH}:/opt/SUNWspro/bin:/opt/teamware/ParallelMake/bin:/usr/ccs/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/etc:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:."
226if [ "${SUNWSPRO}" != "" ]; then
227	PATH="${SUNWSPRO}/bin:$PATH"
228	export PATH
229fi
230
231TOOLS=${SRC}/tools
232TOOLS_PROTO=${TOOLS}/proto
233
234if [ "$t_FLAG" = "y" ]; then
235	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
236
237	STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs
238	export STABS
239	CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs
240	export CTFSTABS
241	GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets
242	export GENOFFSETS
243
244	CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert
245	export CTFCONVERT
246	CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge
247	export CTFMERGE
248
249	CTFCVTPTBL=${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl
250	export CTFCVTPTBL
251	CTFFINDMOD=${TOOLS_PROTO}/opt/onbld/bin/ctffindmod
252	export CTFFINDMOD
253
254	PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
255	PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
256	export PATH
257fi
258
259unset CH
260if [ "$o_FLAG" = "y" ]; then
261	CH=
262	export CH
263fi
264POUND_SIGN="#"
265DEF_STRIPFLAG="-s"
266
267TMPDIR="/tmp"
268
269export	PATH TMPDIR o_FLAG POUND_SIGN DEF_STRIPFLAG
270unset	CFLAGS LD_LIBRARY_PATH
271
272# a la ws
273ENVLDLIBS1=
274ENVLDLIBS2=
275ENVLDLIBS3=
276ENVCPPFLAGS1=
277ENVCPPFLAGS2=
278ENVCPPFLAGS3=
279ENVCPPFLAGS4=
280PARENT_ROOT=
281
282ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
283ENVCPPFLAGS1="-I$ROOT/usr/include"
284MAKEFLAGS=e
285
286export ENVLDLIBS1 ENVLDLIBS2 ENVLDLIBS3 \
287	ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 \
288	ENVCPPFLAGS4 MAKEFLAGS PARENT_ROOT
289
290echo "RELEASE      is  $RELEASE"
291echo "VERSION      is  $VERSION"
292echo "RELEASE_DATE is  $RELEASE_DATE"
293echo ""
294
295if [[ -f $SRC/Makefile ]] && egrep -s '^setup:' $SRC/Makefile; then
296	echo "The top-level 'setup' target is available \c"
297	echo "to build headers and tools."
298	echo ""
299
300elif [[ "$t_FLAG" = "y" ]]; then
301	echo "The tools can be (re)built with the install target in ${TOOLS}."
302	echo ""
303fi
304
305
306if [[ "$c_FLAG" = "n" && -x "$SHELL" && `basename $SHELL` != "csh" ]]; then
307	# $SHELL is set, and it's not csh.
308
309	if [[ "$f_FLAG" != "n" ]]; then
310		echo "WARNING: -f is ignored when \$SHELL is not csh"
311	fi
312
313	echo "Using $SHELL as shell."
314	exec $SHELL ${@:+-c "$@"}
315
316elif [[ "$f_FLAG" = "y" ]]; then
317	echo "Using csh -f as shell."
318	exec csh -f ${@:+-c "$@"}
319
320else
321	echo "Using csh as shell."
322	exec csh ${@:+-c "$@"}
323fi
324