bldenv/nightly: remove unused RELEASE_MICRO/DEV_CM
[unleashed.git] / tools / bldenv.sh
blob4293eddd9e2c57421bef3294ebdb4a47c5d538c5
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 export RELEASE_DATE POUND_SIGN
219 print 'Build type is \c'
220 if ${flags.d} ; then
221 print 'DEBUG'
222 unset RELEASE_BUILD
223 unset EXTRA_OPTIONS
224 unset EXTRA_CFLAGS
225 else
226 # default is a non-DEBUG build
227 print 'non-DEBUG'
228 export RELEASE_BUILD=
229 unset EXTRA_OPTIONS
230 unset EXTRA_CFLAGS
233 # update build-type variables
234 PKGARCHIVE="${PKGARCHIVE}"
236 # Set PATH for a build
237 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"
239 if [[ -n "${MAKE}" ]]; then
240 if [[ -x "${MAKE}" ]]; then
241 export PATH="$(dirname -- "${MAKE}"):$PATH"
242 else
243 print "\$MAKE (${MAKE}) is not a valid executible"
244 exit 1
248 TOOLS="${SRC}/tools"
249 TOOLS_PROTO="${TOOLS}/proto/root_${MACH}-nd" ; export TOOLS_PROTO
251 export ONBLD_TOOLS="${ONBLD_TOOLS:=${TOOLS_PROTO}/opt/onbld}"
253 export STABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/stabs"
254 export CTFSTABS="${TOOLS_PROTO}/opt/onbld/bin/${MACH}/ctfstabs"
255 export GENOFFSETS="${TOOLS_PROTO}/opt/onbld/bin/genoffsets"
257 PATH="${TOOLS_PROTO}/opt/onbld/bin/${MACH}:${PATH}"
258 PATH="${TOOLS_PROTO}/opt/onbld/bin:${PATH}"
259 export PATH
261 export DMAKE_MODE=${DMAKE_MODE:-parallel}
263 DEF_STRIPFLAG="-s"
265 TMPDIR="/tmp"
267 export \
268 PATH TMPDIR \
269 POUND_SIGN \
270 DEF_STRIPFLAG \
271 RELEASE_DATE
272 unset \
273 CFLAGS \
274 LD_LIBRARY_PATH
276 # a la ws
277 ENVLDLIBS1=
278 ENVLDLIBS2=
279 ENVLDLIBS3=
280 ENVCPPFLAGS1=
281 ENVCPPFLAGS2=
282 ENVCPPFLAGS3=
283 ENVCPPFLAGS4=
285 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
286 ENVCPPFLAGS1="-I$ROOT/usr/include"
287 MAKEFLAGS=e
289 export \
290 ENVLDLIBS1 \
291 ENVLDLIBS2 \
292 ENVLDLIBS3 \
293 ENVCPPFLAGS1 \
294 ENVCPPFLAGS2 \
295 ENVCPPFLAGS3 \
296 ENVCPPFLAGS4 \
297 MAKEFLAGS
299 printf 'RELEASE is %s\n' "$RELEASE"
300 printf 'VERSION is %s\n' "$VERSION"
301 printf 'RELEASE_DATE is %s\n\n' "$RELEASE_DATE"
303 print "Use 'bmake gen-config' target to generate config makefiles/headers."
304 print "Use 'dmake setup' target to build legacy headers and tools."
305 print ""
308 # place ourselves in a new task, respecting BUILD_PROJECT if set.
310 /usr/bin/newtask -c $$ ${BUILD_PROJECT:+-p$BUILD_PROJECT}
312 SHELL=/bin/sh
314 if [[ "${flags.c}" == "false" && -x "$SHELL" && \
315 "$(basename -- "${SHELL}")" != "csh" ]]; then
316 # $SHELL is set, and it's not csh.
318 if "${flags.f}" ; then
319 print 'WARNING: -f is ignored when $SHELL is not csh'
322 printf 'Using %s as shell.\n' "$SHELL"
323 exec "$SHELL" ${@:+-c "$@"}
325 elif "${flags.f}" ; then
326 print 'Using csh -f as shell.'
327 exec csh -f ${@:+-c "$@"}
329 else
330 print 'Using csh as shell.'
331 exec csh ${@:+-c "$@"}
334 # not reached