xref: /titanic_50/usr/src/tools/scripts/bldenv.sh (revision d8260c5137b0926a897a3763eca8997922ad7401)
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
141if [ -z "$CLOSED_IS_PRESENT" ]; then
142	if [ -d $SRC/../closed ]; then
143		CLOSED_IS_PRESENT="yes"
144	else
145		CLOSED_IS_PRESENT="no"
146	fi
147	export CLOSED_IS_PRESENT
148fi
149
150# must match the getopts in nightly.sh
151OPTIND=1
152while getopts ABDFMNPTCGIRafinlmoptuUxdrtzWS:X FLAG $NIGHTLY_OPTIONS
153do
154	case $FLAG in
155	  t )	t_FLAG=y
156		;;
157	  S )
158		if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o "$SH_FLAG" = "y" ]; then
159			echo "Can only build one source variant at a time."
160			exit 1
161		fi
162		if [ "${OPTARG}" = "E" ]; then
163			SE_FLAG=y
164		elif [ "${OPTARG}" = "D" ]; then
165			SD_FLAG=y
166		elif [ "${OPTARG}" = "H" ]; then
167			SH_FLAG=y
168		else
169			echo "$USAGE"
170			exit 1
171		fi
172		;;
173	  o)	o_FLAG=y
174		;;
175	  *)    ;;
176	esac
177done
178
179echo "Build type   is  \c"
180if [ ${d_FLAG} = "y" ]; then
181	echo "DEBUG"
182	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
183	unset RELEASE_BUILD
184	unset EXTRA_OPTIONS
185	unset EXTRA_CFLAGS
186else
187	# default is a non-DEBUG build
188	echo "non-DEBUG"
189	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
190	export RELEASE_BUILD ; RELEASE_BUILD=
191	unset EXTRA_OPTIONS
192	unset EXTRA_CFLAGS
193fi
194
195# update build-type variables
196CPIODIR=${CPIODIR}${SUFFIX}
197PKGARCHIVE=${PKGARCHIVE}${SUFFIX}
198
199if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
200        if [ -z "${EXPORT_SRC}" ]; then
201                echo "EXPORT_SRC must be set for a source build."
202                exit 1
203        fi
204        if [ -z "${CRYPT_SRC}" ]; then
205                echo "CRYPT_SRC must be set for a source build."
206                exit 1
207        fi
208fi
209
210if [ "$SH_FLAG" = "y" ]; then
211        if [ -z "${EXPORT_SRC}" ]; then
212                echo "EXPORT_SRC must be set for a source build."
213                exit 1
214        fi
215fi
216
217# Append source version
218if [ "$SE_FLAG" = "y" ]; then
219        VERSION="${VERSION}:EXPORT"
220	SRC=${EXPORT_SRC}/usr/src
221fi
222
223if [ "$SD_FLAG" = "y" ]; then
224        VERSION="${VERSION}:DOMESTIC"
225	SRC=${EXPORT_SRC}/usr/src
226fi
227
228if [ "$SH_FLAG" = "y" ]; then
229        VERSION="${VERSION}:HYBRID"
230	SRC=${EXPORT_SRC}/usr/src
231fi
232
233# 	Set PATH for a build
234PATH="/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:."
235if [ "${SUNWSPRO}" != "" ]; then
236	PATH="${SUNWSPRO}/bin:$PATH"
237	export PATH
238fi
239
240TOOLS=${SRC}/tools
241TOOLS_PROTO=${TOOLS}/proto
242
243if [ "$t_FLAG" = "y" ]; then
244	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
245
246	STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs
247	export STABS
248	CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs
249	export CTFSTABS
250	GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets
251	export GENOFFSETS
252
253	CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert
254	export CTFCONVERT
255	CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge
256	export CTFMERGE
257
258	CTFCVTPTBL=${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl
259	export CTFCVTPTBL
260	CTFFINDMOD=${TOOLS_PROTO}/opt/onbld/bin/ctffindmod
261	export CTFFINDMOD
262
263	PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
264	PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
265	export PATH
266fi
267
268unset CH
269if [ "$o_FLAG" = "y" ]; then
270	CH=
271	export CH
272fi
273POUND_SIGN="#"
274DEF_STRIPFLAG="-s"
275
276TMPDIR="/tmp"
277
278export	PATH TMPDIR o_FLAG POUND_SIGN DEF_STRIPFLAG
279unset	CFLAGS LD_LIBRARY_PATH
280
281# a la ws
282ENVLDLIBS1=
283ENVLDLIBS2=
284ENVLDLIBS3=
285ENVCPPFLAGS1=
286ENVCPPFLAGS2=
287ENVCPPFLAGS3=
288ENVCPPFLAGS4=
289PARENT_ROOT=
290
291ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
292ENVCPPFLAGS1="-I$ROOT/usr/include"
293MAKEFLAGS=e
294
295export ENVLDLIBS1 ENVLDLIBS2 ENVLDLIBS3 \
296	ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 \
297	ENVCPPFLAGS4 MAKEFLAGS PARENT_ROOT
298
299echo "RELEASE      is  $RELEASE"
300echo "VERSION      is  $VERSION"
301echo "RELEASE_DATE is  $RELEASE_DATE"
302echo ""
303
304if [[ -f $SRC/Makefile ]] && egrep -s '^setup:' $SRC/Makefile; then
305	echo "The top-level 'setup' target is available \c"
306	echo "to build headers and tools."
307	echo ""
308
309elif [[ "$t_FLAG" = "y" ]]; then
310	echo "The tools can be (re)built with the install target in ${TOOLS}."
311	echo ""
312fi
313
314
315if [[ "$c_FLAG" = "n" && -x "$SHELL" && `basename $SHELL` != "csh" ]]; then
316	# $SHELL is set, and it's not csh.
317
318	if [[ "$f_FLAG" != "n" ]]; then
319		echo "WARNING: -f is ignored when \$SHELL is not csh"
320	fi
321
322	echo "Using $SHELL as shell."
323	exec $SHELL ${@:+-c "$@"}
324
325elif [[ "$f_FLAG" = "y" ]]; then
326	echo "Using csh -f as shell."
327	exec csh -f ${@:+-c "$@"}
328
329else
330	echo "Using csh as shell."
331	exec csh ${@:+-c "$@"}
332fi
333