libc: rename struct FTW quit to __quit
[unleashed/lotheac.git] / tools / bldenv.sh
blob4f50d37de181c4e5b7b14ac4db63d9cb78835ead
1 #!/bin/ksh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
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.
33 function fatal_error
35 print -u2 "${progname}: $*"
36 exit 1
39 function usage
41 print -u2 "usage: ${progname} [-cfd] env_file"
42 exit 2
45 # boolean flags (true/false)
46 flags_c=false
47 flags_f=false
48 flags_d=false
50 progname="$(basename -- "${0}")"
52 OPTIND=1
54 while getopts cfd OPT ; do
55 case ${OPT} in
56 c) flags_c=true ;;
57 +c) flags_c=false ;;
58 f) flags_f=true ;;
59 +f) flags_f=false ;;
60 d) flags_d=true ;;
61 +d) flags_d=false ;;
62 \?) usage ;;
63 esac
64 done
65 shift $((OPTIND-1))
67 # test that the path to the environment-setting file was given
68 if [ -z "$1" ] ; then
69 usage
72 # force locale to C
73 export \
74 LANG=C \
75 LC_ALL=C \
76 LC_COLLATE=C \
77 LC_CTYPE=C \
78 LC_MESSAGES=C \
79 LC_MONETARY=C \
80 LC_NUMERIC=C \
81 LC_TIME=C
83 # clear environment variables we know to be bad for the build
84 unset \
85 LD_OPTIONS \
86 LD_LIBRARY_PATH \
87 LD_AUDIT \
88 LD_BIND_NOW \
89 LD_BREADTH \
90 LD_CONFIG \
91 LD_DEBUG \
92 LD_FLAGS \
93 LD_LIBRARY_PATH_64 \
94 LD_NOVERSION \
95 LD_ORIGIN \
96 LD_LOADFLTR \
97 LD_NOAUXFLTR \
98 LD_NOCONFIG \
99 LD_NODIRCONFIG \
100 LD_NOOBJALTER \
101 LD_PRELOAD \
102 LD_PROFILE \
103 CONFIG \
104 GROUP \
105 OWNER \
106 REMOTE \
107 ENV \
108 ARCH \
109 CLASSPATH
112 # Setup environment variables
115 if [[ -f "$1" ]]; then
116 if [[ "$1" == */* ]]; then
117 . "$1"
118 else
119 . "./$1"
121 else
122 printf \
123 'Cannot find env file "%s"\n' "$1"
124 exit 1
126 shift
128 # Check if we have sufficient data to continue...
129 [[ -n "${SRCTOP}" ]] || fatal_error "Error: Variable SRCTOP not set."
130 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
131 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
133 POUND_SIGN="#"
134 # have we set RELEASE_DATE in our env file?
135 if [ -z "$RELEASE_DATE" ]; then
136 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
138 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
139 BASEWSDIR=$(basename -- "${SRCTOP}")
140 export RELEASE_DATE POUND_SIGN
142 print 'Build type is \c'
143 if ${flags_d} ; then
144 print 'DEBUG'
145 unset RELEASE_BUILD
146 unset EXTRA_OPTIONS
147 unset EXTRA_CFLAGS
148 else
149 # default is a non-DEBUG build
150 print 'non-DEBUG'
151 export RELEASE_BUILD=
152 unset EXTRA_OPTIONS
153 unset EXTRA_CFLAGS
156 # update build-type variables
157 PKGARCHIVE="${PKGARCHIVE}"
159 # Set PATH for a build
160 PATH="/opt/onbld/bin:/opt/onbld/bin/${MACH}:/usr/bin:/usr/sbin:/usr/ucb:/usr/etc:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:/opt/SUNWspro/bin"
162 if [[ -n "${MAKE}" ]]; then
163 if [[ -x "${MAKE}" ]]; then
164 export PATH="$(dirname -- "${MAKE}"):$PATH"
165 else
166 print "\$MAKE (${MAKE}) is not a valid executible"
167 exit 1
171 TOOLS="${SRC}/tools"
172 TOOLS_PROTO="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
174 export ONBLD_TOOLS="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
176 export STABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
177 export CTFSTABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
178 export GENOFFSETS="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
180 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
181 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
182 export PATH
184 export DMAKE_MODE=${DMAKE_MODE:-parallel}
186 DEF_STRIPFLAG="-s"
188 TMPDIR="/tmp"
190 export \
191 PATH TMPDIR \
192 POUND_SIGN \
193 DEF_STRIPFLAG \
194 RELEASE_DATE
195 unset \
196 CFLAGS \
197 LD_LIBRARY_PATH
199 # a la ws
200 ENVLDLIBS1=
201 ENVLDLIBS2=
202 ENVLDLIBS3=
203 ENVCPPFLAGS1=
204 ENVCPPFLAGS2=
205 ENVCPPFLAGS3=
206 ENVCPPFLAGS4=
208 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
209 ENVCPPFLAGS1="-I$ROOT/usr/include"
210 MAKEFLAGS=e
212 export \
213 ENVLDLIBS1 \
214 ENVLDLIBS2 \
215 ENVLDLIBS3 \
216 ENVCPPFLAGS1 \
217 ENVCPPFLAGS2 \
218 ENVCPPFLAGS3 \
219 ENVCPPFLAGS4 \
220 MAKEFLAGS
222 printf 'RELEASE is %s\n' "$RELEASE"
223 printf 'VERSION is %s\n' "$VERSION"
224 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
226 print "Use 'bmake gen-config' target to generate config makefiles/headers."
227 print "Use 'dmake setup' target to build legacy headers and tools."
228 print ""
231 # place ourselves in a new task, respecting BUILD_PROJECT if set.
233 /usr/bin/newtask -c $$ ${BUILD_PROJECT:+-p$BUILD_PROJECT}
235 SHELL=/bin/sh
237 if [[ "${flags_c}" == "false" && -x "$SHELL" && \
238 "$(basename -- "${SHELL}")" != "csh" ]]; then
239 # $SHELL is set, and it's not csh.
241 if "${flags_f}" ; then
242 print 'WARNING: -f is ignored when $SHELL is not csh'
245 printf 'Using %s as shell.\n' "$SHELL"
246 exec "$SHELL" ${@:+-c "$@"}
248 elif "${flags_f}" ; then
249 print 'Using csh -f as shell.'
250 exec csh -f ${@:+-c "$@"}
252 else
253 print 'Using csh as shell.'
254 exec csh ${@:+-c "$@"}
257 # not reached