xref: /titanic_51/usr/src/tools/scripts/bldenv.sh (revision 6d98517adc1eff16d9ed42954b8a8b19f7dc44db)
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
193	if [ "$SINGLE_PROTO" = "no" ]; then
194		ROOT=$ROOT-nd
195	fi
196fi
197
198# update build-type variables
199CPIODIR=${CPIODIR}${SUFFIX}
200PKGARCHIVE=${PKGARCHIVE}${SUFFIX}
201
202if [ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" ]; then
203        if [ -z "${EXPORT_SRC}" ]; then
204                echo "EXPORT_SRC must be set for a source build."
205                exit 1
206        fi
207        if [ -z "${CRYPT_SRC}" ]; then
208                echo "CRYPT_SRC must be set for a source build."
209                exit 1
210        fi
211fi
212
213if [ "$SH_FLAG" = "y" ]; then
214        if [ -z "${EXPORT_SRC}" ]; then
215                echo "EXPORT_SRC must be set for a source build."
216                exit 1
217        fi
218fi
219
220# Append source version
221if [ "$SE_FLAG" = "y" ]; then
222        VERSION="${VERSION}:EXPORT"
223	SRC=${EXPORT_SRC}/usr/src
224fi
225
226if [ "$SD_FLAG" = "y" ]; then
227        VERSION="${VERSION}:DOMESTIC"
228	SRC=${EXPORT_SRC}/usr/src
229fi
230
231if [ "$SH_FLAG" = "y" ]; then
232        VERSION="${VERSION}:HYBRID"
233	SRC=${EXPORT_SRC}/usr/src
234fi
235
236# 	Set PATH for a build
237PATH="/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:."
238if [ "${SUNWSPRO}" != "" ]; then
239	PATH="${SUNWSPRO}/bin:$PATH"
240	export PATH
241fi
242
243TOOLS=${SRC}/tools
244TOOLS_PROTO=${TOOLS}/proto
245
246if [ "$t_FLAG" = "y" ]; then
247	export ONBLD_TOOLS=${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}
248
249	STABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs
250	export STABS
251	CTFSTABS=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs
252	export CTFSTABS
253	GENOFFSETS=${TOOLS_PROTO}/opt/onbld/bin/genoffsets
254	export GENOFFSETS
255
256	CTFCONVERT=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfconvert
257	export CTFCONVERT
258	CTFMERGE=${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfmerge
259	export CTFMERGE
260
261	CTFCVTPTBL=${TOOLS_PROTO}/opt/onbld/bin/ctfcvtptbl
262	export CTFCVTPTBL
263	CTFFINDMOD=${TOOLS_PROTO}/opt/onbld/bin/ctffindmod
264	export CTFFINDMOD
265
266	PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
267	PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
268	export PATH
269fi
270
271unset CH
272if [ "$o_FLAG" = "y" ]; then
273	CH=
274	export CH
275fi
276POUND_SIGN="#"
277DEF_STRIPFLAG="-s"
278
279TMPDIR="/tmp"
280
281export	PATH TMPDIR o_FLAG POUND_SIGN DEF_STRIPFLAG
282unset	CFLAGS LD_LIBRARY_PATH
283
284# a la ws
285ENVLDLIBS1=
286ENVLDLIBS2=
287ENVLDLIBS3=
288ENVCPPFLAGS1=
289ENVCPPFLAGS2=
290ENVCPPFLAGS3=
291ENVCPPFLAGS4=
292PARENT_ROOT=
293
294ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
295ENVCPPFLAGS1="-I$ROOT/usr/include"
296MAKEFLAGS=e
297
298export ENVLDLIBS1 ENVLDLIBS2 ENVLDLIBS3 \
299	ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 \
300	ENVCPPFLAGS4 MAKEFLAGS PARENT_ROOT
301
302echo "RELEASE      is  $RELEASE"
303echo "VERSION      is  $VERSION"
304echo "RELEASE_DATE is  $RELEASE_DATE"
305echo ""
306
307if [[ -f $SRC/Makefile ]] && egrep -s '^setup:' $SRC/Makefile; then
308	echo "The top-level 'setup' target is available \c"
309	echo "to build headers and tools."
310	echo ""
311
312elif [[ "$t_FLAG" = "y" ]]; then
313	echo "The tools can be (re)built with the install target in ${TOOLS}."
314	echo ""
315fi
316
317
318if [[ "$c_FLAG" = "n" && -x "$SHELL" && `basename $SHELL` != "csh" ]]; then
319	# $SHELL is set, and it's not csh.
320
321	if [[ "$f_FLAG" != "n" ]]; then
322		echo "WARNING: -f is ignored when \$SHELL is not csh"
323	fi
324
325	echo "Using $SHELL as shell."
326	exec $SHELL ${@:+-c "$@"}
327
328elif [[ "$f_FLAG" = "y" ]]; then
329	echo "Using csh -f as shell."
330	exec csh -f ${@:+-c "$@"}
331
332else
333	echo "Using csh as shell."
334	exec csh ${@:+-c "$@"}
335fi
336