xref: /titanic_41/usr/src/tools/scripts/bldenv.sh (revision 700c902c445eb3882848aaddc19d13638818cfd6)
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
151NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
152while getopts ABDFMNCGIRafinlmoptuUxdrtzWS: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:/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