xref: /titanic_50/usr/src/tools/scripts/bldenv.sh (revision 75e454957f9291aa383758b0f444a8ca503c73cf)
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|O ] <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		O - simulate OpenSolaris build
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
54SO_FLAG=n
55
56is_source_build() {
57	[ "$SE_FLAG" = "y" -o "$SD_FLAG" = "y" -o \
58	    "$SH_FLAG" = "y" -o "$SO_FLAG" = "y" ]
59	return $?
60}
61
62#
63# single function for setting -S flag and doing error checking.
64# usage: set_S_flag <type>
65# where <type> is the source build type ("E", "D", ...).
66#
67set_S_flag() {
68	if is_source_build; then
69		echo "Can only build one source variant at a time."
70		exit 1
71	fi
72	if [ "$1" = "E" ]; then
73		SE_FLAG=y
74	elif [ "$1" = "D" ]; then
75		SD_FLAG=y
76	elif [ "$1" = "H" ]; then
77		SH_FLAG=y
78	elif [ "$1" = "O" ]; then
79		SO_FLAG=y
80	else
81		echo "$USAGE"
82		exit 1
83	fi
84}
85
86OPTIND=1
87SUFFIX="-nd"
88while getopts cdfS:t FLAG
89do
90	case $FLAG in
91	  c )	c_FLAG=y
92		;;
93	  f )	f_FLAG=y
94		;;
95	  d )	d_FLAG=y
96		SUFFIX=""
97		;;
98	  t )	t_FLAG=y
99		;;
100	  S )
101		set_S_flag $OPTARG
102		;;
103	  \?)	echo "$USAGE"
104		exit 1
105		;;
106	esac
107done
108
109# correct argument count after options
110shift `expr $OPTIND - 1`
111
112# test that the path to the environment-setting file was given
113if [ $# -lt 1 ]
114then
115	echo "$USAGE"
116	exit 1
117fi
118
119# force locale to C
120LC_COLLATE=C;   export LC_COLLATE
121LC_CTYPE=C;     export LC_CTYPE
122LC_MESSAGES=C;  export LC_MESSAGES
123LC_MONETARY=C;  export LC_MONETARY
124LC_NUMERIC=C;   export LC_NUMERIC
125LC_TIME=C;      export LC_TIME
126
127# clear environment variables we know to be bad for the build
128unset LD_OPTIONS LD_LIBRARY_PATH LD_AUDIT LD_BIND_NOW LD_BREADTH LD_CONFIG
129unset LD_DEBUG LD_FLAGS LD_LIBRARY_PATH_64 LD_NOVERSION LD_ORIGIN
130unset LD_LOADFLTR LD_NOAUXFLTR LD_NOCONFIG LD_NODIRCONFIG LD_NOOBJALTER
131unset LD_PRELOAD LD_PROFILE
132unset CONFIG
133unset GROUP
134unset OWNER
135unset REMOTE
136unset ENV
137unset ARCH
138unset CLASSPATH
139
140# setup environmental variables
141if [ -f $1 ]; then
142	if [[ $1 = */* ]]; then
143		. $1
144	else
145		. ./$1
146	fi
147else
148	if [ -f /opt/onbld/env/$1 ]; then
149		. /opt/onbld/env/$1
150	else
151		echo "Cannot find env file as either $1 or /opt/onbld/env/$1"
152		exit 1
153	fi
154fi
155shift
156
157# contents of stdenv.sh inserted after next line:
158# STDENV_START
159# STDENV_END
160
161#MACH=`uname -p`
162
163# must match the getopts in nightly.sh
164OPTIND=1
165NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
166while getopts ABDFMNCGIRafinlmoptuUxdrtwzWS:X FLAG $NIGHTLY_OPTIONS
167do
168	case $FLAG in
169	  t )	t_FLAG=y
170		;;
171	  S )
172		set_S_flag $OPTARG
173		;;
174	  o)	o_FLAG=y
175		;;
176	  *)    ;;
177	esac
178done
179
180echo "Build type   is  \c"
181if [ ${d_FLAG} = "y" ]; then
182	echo "DEBUG"
183	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
184	unset RELEASE_BUILD
185	unset EXTRA_OPTIONS
186	unset EXTRA_CFLAGS
187else
188	# default is a non-DEBUG build
189	echo "non-DEBUG"
190	export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
191	export RELEASE_BUILD ; RELEASE_BUILD=
192	unset EXTRA_OPTIONS
193	unset EXTRA_CFLAGS
194fi
195
196# update build-type variables
197CPIODIR=${CPIODIR}${SUFFIX}
198PKGARCHIVE=${PKGARCHIVE}${SUFFIX}
199
200# Append source version
201if [ "$SE_FLAG" = "y" ]; then
202        VERSION="${VERSION}:EXPORT"
203	SRC=${EXPORT_SRC}/usr/src
204fi
205
206if [ "$SD_FLAG" = "y" ]; then
207        VERSION="${VERSION}:DOMESTIC"
208	SRC=${EXPORT_SRC}/usr/src
209fi
210
211if [ "$SH_FLAG" = "y" ]; then
212        VERSION="${VERSION}:HYBRID"
213	SRC=${EXPORT_SRC}/usr/src
214fi
215
216if [ "$SO_FLAG" = "y" ]; then
217        VERSION="${VERSION}:OPEN_ONLY"
218	SRC=${OPEN_SRCDIR}/usr/src
219fi
220
221# 	Set PATH for a build
222PATH="/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:."
223if [ "${SUNWSPRO}" != "" ]; then
224	PATH="${SUNWSPRO}/bin:$PATH"
225	export PATH
226fi
227
228if [[ "$SO_FLAG" = "y" && "$CLOSED_IS_PRESENT" = "yes" ]]; then
229	echo "CLOSED_IS_PRESENT is 'no' (because of '-S O')"
230	CLOSED_IS_PRESENT=no
231	export CLOSED_IS_PRESENT
232fi
233
234if [ -z "$CLOSED_IS_PRESENT" ]; then
235	if [ -d $SRC/../closed ]; then
236		CLOSED_IS_PRESENT="yes"
237	else
238		CLOSED_IS_PRESENT="no"
239	fi
240	export CLOSED_IS_PRESENT
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