8559 Add EFI utility functions to libefi
[unleashed.git] / tools / bldenv.sh
blobf930c8ee02c081c94722e848dcf2604d9a8638cb
1 #!/usr/bin/ksh93
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 OPTIND=0
42 getopts -a "${progname}" "${USAGE}" OPT '-?'
43 exit 2
46 typeset -r USAGE=$'+
47 [-?\n@(#)\$Id: bldenv (OS/Net) 2008-04-06 \$\n]
48 [-author?OS/Net community <tools-discuss@opensolaris.org>]
49 [+NAME?bldenv - spawn shell for interactive incremental OS-Net
50 consolidation builds]
51 [+DESCRIPTION?bldenv is a useful companion to the nightly(1) script for
52 doing interactive and incremental builds in a workspace
53 already built with nightly(1). bldenv spawns a shell set up
54 with the same environment variables taken from an env_file,
55 as prepared for use with nightly(1).]
56 [+?In addition to running a shell for interactive use, bldenv
57 can optionally run a single command in the given environment,
58 in the vein of sh -c or su -c. This is useful for
59 scripting, when an interactive shell would not be. If the
60 command is composed of multiple shell words or contains
61 other shell metacharacters, it must be quoted appropriately.]
62 [+?bldenv is particularly useful for testing Makefile targets
63 like clobber, install and _msg, which otherwise require digging
64 through large build logs to figure out what is being
65 done.]
66 [+?By default, bldenv will invoke the shell specified in
67 $SHELL. If $SHELL is not set or is invalid, csh will be
68 used.]
69 [c?force the use of csh, regardless of the value of $SHELL.]
70 [f?invoke csh with the -f (fast-start) option. This option is valid
71 only if $SHELL is unset or if it points to csh.]
72 [d?set up environment for doing DEBUG builds (default is non-DEBUG)]
74 <env_file> [command]
76 [+EXAMPLES]{
77 [+?Example 1: Interactive use]{
78 [+?Use bldenv to spawn a shell to perform a DEBUG build and
79 testing of the Makefile targets clobber and install for
80 usr/src/cmd/true.]
81 [+\n% rlogin wopr-2 -l gk
82 {root::wopr-2::49} bldenv -d /export0/jg/on10-se.env
83 Build type is DEBUG
84 RELEASE is 5.10
85 VERSION is wopr-2::on10-se::11/01/2001
86 RELEASE_DATE is May 2004
87 Using /usr/bin/tcsh as shell.
88 {root::wopr-2::49}
89 {root::wopr-2::49} cd $SRC/cmd/true
90 {root::wopr-2::50} make
91 {root::wopr-2::51} make clobber
92 /usr/bin/rm -f true true.po
93 {root::wopr-2::52} make
94 /usr/bin/rm -f true
95 cat true.sh > true
96 chmod +x true
97 {root::wopr-2::53} make install
98 install -s -m 0555 -u root -g bin -f /export0/jg/on10-se/proto/root_sparc/usr/bin true
99 `install\' is up to date.]
101 [+?Example 2: Non-interactive use]{
102 [+?Invoke bldenv to create SUNWonbld with a single command:]
103 [+\nexample% bldenv onnv_06 \'cd $SRC/tools && make pkg\']
106 [+SEE ALSO?\bnightly\b(1)]
109 # main
110 builtin basename
112 # boolean flags (true/false)
113 typeset flags=(
114 typeset c=false
115 typeset f=false
116 typeset d=false
117 typeset O=false
118 typeset o=false
119 typeset s=(
120 typeset e=false
121 typeset h=false
122 typeset d=false
123 typeset o=false
127 typeset progname="$(basename -- "${0}")"
129 OPTIND=1
131 while getopts -a "${progname}" "${USAGE}" OPT ; do
132 case ${OPT} in
133 c) flags.c=true ;;
134 +c) flags.c=false ;;
135 f) flags.f=true ;;
136 +f) flags.f=false ;;
137 d) flags.d=true ;;
138 +d) flags.d=false ;;
139 \?) usage ;;
140 esac
141 done
142 shift $((OPTIND-1))
144 # test that the path to the environment-setting file was given
145 if (( $# < 1 )) ; then
146 usage
149 # force locale to C
150 export \
151 LANG=C \
152 LC_ALL=C \
153 LC_COLLATE=C \
154 LC_CTYPE=C \
155 LC_MESSAGES=C \
156 LC_MONETARY=C \
157 LC_NUMERIC=C \
158 LC_TIME=C
160 # clear environment variables we know to be bad for the build
161 unset \
162 LD_OPTIONS \
163 LD_LIBRARY_PATH \
164 LD_AUDIT \
165 LD_BIND_NOW \
166 LD_BREADTH \
167 LD_CONFIG \
168 LD_DEBUG \
169 LD_FLAGS \
170 LD_LIBRARY_PATH_64 \
171 LD_NOVERSION \
172 LD_ORIGIN \
173 LD_LOADFLTR \
174 LD_NOAUXFLTR \
175 LD_NOCONFIG \
176 LD_NODIRCONFIG \
177 LD_NOOBJALTER \
178 LD_PRELOAD \
179 LD_PROFILE \
180 CONFIG \
181 GROUP \
182 OWNER \
183 REMOTE \
184 ENV \
185 ARCH \
186 CLASSPATH
189 # Setup environment variables
192 if [[ -f "$1" ]]; then
193 if [[ "$1" == */* ]]; then
194 source "$1"
195 else
196 source "./$1"
198 else
199 printf \
200 'Cannot find env file as either %s\n' "$1"
201 exit 1
203 shift
205 # Check if we have sufficient data to continue...
206 [[ -v SRCTOP ]] || fatal_error "Error: Variable SRCTOP not set."
207 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
208 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
210 POUND_SIGN="#"
211 # have we set RELEASE_DATE in our env file?
212 if [ -z "$RELEASE_DATE" ]; then
213 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
215 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
216 BASEWSDIR=$(basename -- "${SRCTOP}")
217 DEV_CM="\"@(#)illumos Development: $LOGNAME $BUILD_DATE [$BASEWSDIR]\""
218 export DEV_CM RELEASE_DATE POUND_SIGN
220 # illumos was announced August 3, 2010. We use that as the starting
221 # point.
222 RELEASE_MICRO=$(( ($(date +%Y) * 12 + $(date +%m) - 1) - (2010 * 12 + 8 - 1) ))
223 export RELEASE_MICRO
225 print 'Build type is \c'
226 if ${flags.d} ; then
227 print 'DEBUG'
228 unset RELEASE_BUILD
229 unset EXTRA_OPTIONS
230 unset EXTRA_CFLAGS
231 else
232 # default is a non-DEBUG build
233 print 'non-DEBUG'
234 export RELEASE_BUILD=
235 unset EXTRA_OPTIONS
236 unset EXTRA_CFLAGS
239 # update build-type variables
240 PKGARCHIVE="${PKGARCHIVE}"
242 # Set PATH for a build
243 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"
245 if [[ -n "${MAKE}" ]]; then
246 if [[ -x "${MAKE}" ]]; then
247 export PATH="$(dirname -- "${MAKE}"):$PATH"
248 else
249 print "\$MAKE (${MAKE}) is not a valid executible"
250 exit 1
254 TOOLS="${SRC}/tools"
255 TOOLS_PROTO="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
257 export ONBLD_TOOLS="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
259 export STABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
260 export CTFSTABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
261 export GENOFFSETS="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
263 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
264 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
265 export PATH
267 export DMAKE_MODE=${DMAKE_MODE:-parallel}
269 DEF_STRIPFLAG="-s"
271 TMPDIR="/tmp"
273 export \
274 PATH TMPDIR \
275 POUND_SIGN \
276 DEF_STRIPFLAG \
277 RELEASE_DATE
278 unset \
279 CFLAGS \
280 LD_LIBRARY_PATH
282 # a la ws
283 ENVLDLIBS1=
284 ENVLDLIBS2=
285 ENVLDLIBS3=
286 ENVCPPFLAGS1=
287 ENVCPPFLAGS2=
288 ENVCPPFLAGS3=
289 ENVCPPFLAGS4=
291 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
292 ENVCPPFLAGS1="-I$ROOT/usr/include"
293 MAKEFLAGS=e
295 export \
296 ENVLDLIBS1 \
297 ENVLDLIBS2 \
298 ENVLDLIBS3 \
299 ENVCPPFLAGS1 \
300 ENVCPPFLAGS2 \
301 ENVCPPFLAGS3 \
302 ENVCPPFLAGS4 \
303 MAKEFLAGS
305 printf 'RELEASE is %s\n' "$RELEASE"
306 printf 'VERSION is %s\n' "$VERSION"
307 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
309 print "Use 'bmake gen-config' target to generate config makefiles/headers."
310 print "Use 'dmake setup' target to build legacy headers and tools."
311 print ""
314 # place ourselves in a new task, respecting BUILD_PROJECT if set.
316 /usr/bin/newtask -c $$ ${BUILD_PROJECT:+-p$BUILD_PROJECT}
318 SHELL=/bin/sh
320 if [[ "${flags.c}" == "false" && -x "$SHELL" && \
321 "$(basename -- "${SHELL}")" != "csh" ]]; then
322 # $SHELL is set, and it's not csh.
324 if "${flags.f}" ; then
325 print 'WARNING: -f is ignored when $SHELL is not csh'
328 printf 'Using %s as shell.\n' "$SHELL"
329 exec "$SHELL" ${@:+-c "$@"}
331 elif "${flags.f}" ; then
332 print 'Using csh -f as shell.'
333 exec csh -f ${@:+-c "$@"}
335 else
336 print 'Using csh as shell.'
337 exec csh ${@:+-c "$@"}
340 # not reached