build.sh revision 1.260 1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.260 2012/12/02 19:19:36 apb Exp $
3 #
4 # Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Todd Vierling and Luke Mewburn.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 #
31 #
32 # Top level build wrapper, to build or cross-build NetBSD.
33 #
34
35 #
36 # {{{ Begin shell feature tests.
37 #
38 # We try to determine whether or not this script is being run under
39 # a shell that supports the features that we use. If not, we try to
40 # re-exec the script under another shell. If we can't find another
41 # suitable shell, then we print a message and exit.
42 #
43
44 errmsg='' # error message, if not empty
45 shelltest=false # if true, exit after testing the shell
46 re_exec_allowed=true # if true, we may exec under another shell
47
48 # Parse special command line options in $1. These special options are
49 # for internal use only, are not documented, and are not valid anywhere
50 # other than $1.
51 case "$1" in
52 "--shelltest")
53 shelltest=true
54 re_exec_allowed=false
55 shift
56 ;;
57 "--no-re-exec")
58 re_exec_allowed=false
59 shift
60 ;;
61 esac
62
63 # Solaris /bin/sh, and other SVR4 shells, do not support "!".
64 # This is the first feature that we test, because subsequent
65 # tests use "!".
66 #
67 if test -z "$errmsg"; then
68 if ( eval '! false' ) >/dev/null 2>&1 ; then
69 :
70 else
71 errmsg='Shell does not support "!".'
72 fi
73 fi
74
75 # Does the shell support functions?
76 #
77 if test -z "$errmsg"; then
78 if ! (
79 eval 'somefunction() { : ; }'
80 ) >/dev/null 2>&1
81 then
82 errmsg='Shell does not support functions.'
83 fi
84 fi
85
86 # Does the shell support the "local" keyword for variables in functions?
87 #
88 # Local variables are not required by SUSv3, but some scripts run during
89 # the NetBSD build use them.
90 #
91 # ksh93 fails this test; it uses an incompatible syntax involving the
92 # keywords 'function' and 'typeset'.
93 #
94 if test -z "$errmsg"; then
95 if ! (
96 eval 'f() { local v=2; }; v=1; f && test x"$v" = x"1"'
97 ) >/dev/null 2>&1
98 then
99 errmsg='Shell does not support the "local" keyword in functions.'
100 fi
101 fi
102
103 # Does the shell support ${var%suffix}, ${var#prefix}, and their variants?
104 #
105 # We don't bother testing for ${var+value}, ${var-value}, or their variants,
106 # since shells without those are sure to fail other tests too.
107 #
108 if test -z "$errmsg"; then
109 if ! (
110 eval 'var=a/b/c ;
111 test x"${var#*/};${var##*/};${var%/*};${var%%/*}" = \
112 x"b/c;c;a/b;a" ;'
113 ) >/dev/null 2>&1
114 then
115 errmsg='Shell does not support "${var%suffix}" or "${var#prefix}".'
116 fi
117 fi
118
119 # Does the shell support IFS?
120 #
121 # zsh in normal mode (as opposed to "emulate sh" mode) fails this test.
122 #
123 if test -z "$errmsg"; then
124 if ! (
125 eval 'IFS=: ; v=":a b::c" ; set -- $v ; IFS=+ ;
126 test x"$#;$1,$2,$3,$4;$*" = x"4;,a b,,c;+a b++c"'
127 ) >/dev/null 2>&1
128 then
129 errmsg='Shell does not support IFS word splitting.'
130 fi
131 fi
132
133 # Does the shell support ${1+"$@"}?
134 #
135 # Some versions of zsh fail this test, even in "emulate sh" mode.
136 #
137 if test -z "$errmsg"; then
138 if ! (
139 eval 'set -- "a a a" "b b b"; set -- ${1+"$@"};
140 test x"$#;$1;$2" = x"2;a a a;b b b";'
141 ) >/dev/null 2>&1
142 then
143 errmsg='Shell does not support ${1+"$@"}.'
144 fi
145 fi
146
147 # Does the shell support $(...) command substitution?
148 #
149 if test -z "$errmsg"; then
150 if ! (
151 eval 'var=$(echo abc); test x"$var" = x"abc"'
152 ) >/dev/null 2>&1
153 then
154 errmsg='Shell does not support "$(...)" command substitution.'
155 fi
156 fi
157
158 # Does the shell support $(...) command substitution with
159 # unbalanced parentheses?
160 #
161 # Some shells known to fail this test are: NetBSD /bin/ksh (as of 2009-12),
162 # bash-3.1, pdksh-5.2.14, zsh-4.2.7 in "emulate sh" mode.
163 #
164 if test -z "$errmsg"; then
165 if ! (
166 eval 'var=$(case x in x) echo abc;; esac); test x"$var" = x"abc"'
167 ) >/dev/null 2>&1
168 then
169 # XXX: This test is ignored because so many shells fail it; instead,
170 # the NetBSD build avoids using the problematic construct.
171 : ignore 'Shell does not support "$(...)" with unbalanced ")".'
172 fi
173 fi
174
175 # Does the shell support getopts or getopt?
176 #
177 if test -z "$errmsg"; then
178 if ! (
179 eval 'type getopts || type getopt'
180 ) >/dev/null 2>&1
181 then
182 errmsg='Shell does not support getopts or getopt.'
183 fi
184 fi
185
186 #
187 # If shelltest is true, exit now, reporting whether or not the shell is good.
188 #
189 if $shelltest; then
190 if test -n "$errmsg"; then
191 echo >&2 "$0: $errmsg"
192 exit 1
193 else
194 exit 0
195 fi
196 fi
197
198 #
199 # If the shell was bad, try to exec a better shell, or report an error.
200 #
201 # Loops are broken by passing an extra "--no-re-exec" flag to the new
202 # instance of this script.
203 #
204 if test -n "$errmsg"; then
205 if $re_exec_allowed; then
206 for othershell in \
207 "${HOST_SH}" /usr/xpg4/bin/sh ksh ksh88 mksh pdksh bash dash
208 # NOTE: some shells known not to work are:
209 # any shell using csh syntax;
210 # Solaris /bin/sh (missing many modern features);
211 # ksh93 (incompatible syntax for local variables);
212 # zsh (many differences, unless run in compatibility mode).
213 do
214 test -n "$othershell" || continue
215 if eval 'type "$othershell"' >/dev/null 2>&1 \
216 && "$othershell" "$0" --shelltest >/dev/null 2>&1
217 then
218 cat <<EOF
219 $0: $errmsg
220 $0: Retrying under $othershell
221 EOF
222 HOST_SH="$othershell"
223 export HOST_SH
224 exec $othershell "$0" --no-re-exec "$@" # avoid ${1+"$@"}
225 fi
226 # If HOST_SH was set, but failed the test above,
227 # then give up without trying any other shells.
228 test x"${othershell}" = x"${HOST_SH}" && break
229 done
230 fi
231
232 #
233 # If we get here, then the shell is bad, and we either could not
234 # find a replacement, or were not allowed to try a replacement.
235 #
236 cat <<EOF
237 $0: $errmsg
238
239 The NetBSD build system requires a shell that supports modern POSIX
240 features, as well as the "local" keyword in functions (which is a
241 widely-implemented but non-standardised feature).
242
243 Please re-run this script under a suitable shell. For example:
244
245 /path/to/suitable/shell $0 ...
246
247 The above command will usually enable build.sh to automatically set
248 HOST_SH=/path/to/suitable/shell, but if that fails, then you may also
249 need to explicitly set the HOST_SH environment variable, as follows:
250
251 HOST_SH=/path/to/suitable/shell
252 export HOST_SH
253 \${HOST_SH} $0 ...
254 EOF
255 exit 1
256 fi
257
258 #
259 # }}} End shell feature tests.
260 #
261
262 progname=${0##*/}
263 toppid=$$
264 results=/dev/null
265 tab=' '
266 nl='
267 '
268 trap "exit 1" 1 2 3 15
269
270 bomb()
271 {
272 cat >&2 <<ERRORMESSAGE
273
274 ERROR: $@
275 *** BUILD ABORTED ***
276 ERRORMESSAGE
277 kill ${toppid} # in case we were invoked from a subshell
278 exit 1
279 }
280
281
282 statusmsg()
283 {
284 ${runcmd} echo "===> $@" | tee -a "${results}"
285 }
286
287 statusmsg2()
288 {
289 local msg
290
291 msg="${1}"
292 shift
293 case "${msg}" in
294 ????????????????*) ;;
295 ??????????*) msg="${msg} ";;
296 ?????*) msg="${msg} ";;
297 *) msg="${msg} ";;
298 esac
299 case "${msg}" in
300 ?????????????????????*) ;;
301 ????????????????????) msg="${msg} ";;
302 ???????????????????) msg="${msg} ";;
303 ??????????????????) msg="${msg} ";;
304 ?????????????????) msg="${msg} ";;
305 ????????????????) msg="${msg} ";;
306 esac
307 statusmsg "${msg}$*"
308 }
309
310 warning()
311 {
312 statusmsg "Warning: $@"
313 }
314
315 # Find a program in the PATH, and print the result. If not found,
316 # print a default. If $2 is defined (even if it is an empty string),
317 # then that is the default; otherwise, $1 is used as the default.
318 find_in_PATH()
319 {
320 local prog="$1"
321 local result="${2-"$1"}"
322 local oldIFS="${IFS}"
323 local dir
324 IFS=":"
325 for dir in ${PATH}; do
326 if [ -x "${dir}/${prog}" ]; then
327 result="${dir}/${prog}"
328 break
329 fi
330 done
331 IFS="${oldIFS}"
332 echo "${result}"
333 }
334
335 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
336 # Assumes that uname_s, uname_m, and PWD have been set.
337 set_HOST_SH()
338 {
339 # Even if ${HOST_SH} is already defined, we still do the
340 # sanity checks at the end.
341
342 # Solaris has /usr/xpg4/bin/sh.
343 #
344 [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
345 [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
346
347 # Try to get the name of the shell that's running this script,
348 # by parsing the output from "ps". We assume that, if the host
349 # system's ps command supports -o comm at all, it will do so
350 # in the usual way: a one-line header followed by a one-line
351 # result, possibly including trailing white space. And if the
352 # host system's ps command doesn't support -o comm, we assume
353 # that we'll get an error message on stderr and nothing on
354 # stdout. (We don't try to use ps -o 'comm=' to suppress the
355 # header line, because that is less widely supported.)
356 #
357 # If we get the wrong result here, the user can override it by
358 # specifying HOST_SH in the environment.
359 #
360 [ -z "${HOST_SH}" ] && HOST_SH="$(
361 (ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )"
362
363 # If nothing above worked, use "sh". We will later find the
364 # first directory in the PATH that has a "sh" program.
365 #
366 [ -z "${HOST_SH}" ] && HOST_SH="sh"
367
368 # If the result so far is not an absolute path, try to prepend
369 # PWD or search the PATH.
370 #
371 case "${HOST_SH}" in
372 /*) :
373 ;;
374 */*) HOST_SH="${PWD}/${HOST_SH}"
375 ;;
376 *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
377 ;;
378 esac
379
380 # If we don't have an absolute path by now, bomb.
381 #
382 case "${HOST_SH}" in
383 /*) :
384 ;;
385 *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path."
386 ;;
387 esac
388
389 # If HOST_SH is not executable, bomb.
390 #
391 [ -x "${HOST_SH}" ] ||
392 bomb "HOST_SH=\"${HOST_SH}\" is not executable."
393
394 # If HOST_SH fails tests, bomb.
395 # ("$0" may be a path that is no longer valid, because we have
396 # performed "cd $(dirname $0)", so don't use $0 here.)
397 #
398 "${HOST_SH}" build.sh --shelltest ||
399 bomb "HOST_SH=\"${HOST_SH}\" failed functionality tests."
400 }
401
402 # initdefaults --
403 # Set defaults before parsing command line options.
404 #
405 initdefaults()
406 {
407 makeenv=
408 makewrapper=
409 makewrappermachine=
410 runcmd=
411 operations=
412 removedirs=
413
414 [ -d usr.bin/make ] || cd "$(dirname $0)"
415 [ -d usr.bin/make ] ||
416 bomb "build.sh must be run from the top source level"
417 [ -f share/mk/bsd.own.mk ] ||
418 bomb "src/share/mk is missing; please re-fetch the source tree"
419
420 # Set various environment variables to known defaults,
421 # to minimize (cross-)build problems observed "in the field".
422 #
423 # LC_ALL=C must be set before we try to parse the output from
424 # any command. Other variables are set (or unset) here, before
425 # we parse command line arguments.
426 #
427 # These variables can be overridden via "-V var=value" if
428 # you know what you are doing.
429 #
430 unsetmakeenv INFODIR
431 unsetmakeenv LESSCHARSET
432 unsetmakeenv MAKEFLAGS
433 setmakeenv LC_ALL C
434
435 # Find information about the build platform. This should be
436 # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
437 # variables in share/mk/bsd.sys.mk.
438 #
439 # Note that "uname -p" is not part of POSIX, but we want uname_p
440 # to be set to the host MACHINE_ARCH, if possible. On systems
441 # where "uname -p" fails, prints "unknown", or prints a string
442 # that does not look like an identifier, fall back to using the
443 # output from "uname -m" instead.
444 #
445 uname_s=$(uname -s 2>/dev/null)
446 uname_r=$(uname -r 2>/dev/null)
447 uname_m=$(uname -m 2>/dev/null)
448 uname_p=$(uname -p 2>/dev/null || echo "unknown")
449 case "${uname_p}" in
450 ''|unknown|*[^-_A-Za-z0-9]*) uname_p="${uname_m}" ;;
451 esac
452
453 id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null)
454
455 # If $PWD is a valid name of the current directory, POSIX mandates
456 # that pwd return it by default which causes problems in the
457 # presence of symlinks. Unsetting PWD is simpler than changing
458 # every occurrence of pwd to use -P.
459 #
460 # XXX Except that doesn't work on Solaris. Or many Linuces.
461 #
462 unset PWD
463 TOP=$(/bin/pwd -P 2>/dev/null || /bin/pwd 2>/dev/null)
464
465 # The user can set HOST_SH in the environment, or we try to
466 # guess an appropriate value. Then we set several other
467 # variables from HOST_SH.
468 #
469 set_HOST_SH
470 setmakeenv HOST_SH "${HOST_SH}"
471 setmakeenv BSHELL "${HOST_SH}"
472 setmakeenv CONFIG_SHELL "${HOST_SH}"
473
474 # Set defaults.
475 #
476 toolprefix=nb
477
478 # Some systems have a small ARG_MAX. -X prevents make(1) from
479 # exporting variables in the environment redundantly.
480 #
481 case "${uname_s}" in
482 Darwin | FreeBSD | CYGWIN*)
483 MAKEFLAGS="-X ${MAKEFLAGS}"
484 ;;
485 esac
486
487 # do_{operation}=true if given operation is requested.
488 #
489 do_expertmode=false
490 do_rebuildmake=false
491 do_removedirs=false
492 do_tools=false
493 do_cleandir=false
494 do_obj=false
495 do_build=false
496 do_distribution=false
497 do_release=false
498 do_kernel=false
499 do_releasekernel=false
500 do_modules=false
501 do_installmodules=false
502 do_install=false
503 do_sets=false
504 do_sourcesets=false
505 do_syspkgs=false
506 do_iso_image=false
507 do_iso_image_source=false
508 do_live_image=false
509 do_install_image=false
510 do_params=false
511 do_rump=false
512
513 # done_{operation}=true if given operation has been done.
514 #
515 done_rebuildmake=false
516
517 # Create scratch directory
518 #
519 tmpdir="${TMPDIR-/tmp}/nbbuild$$"
520 mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
521 trap "cd /; rm -r -f \"${tmpdir}\"" 0
522 results="${tmpdir}/build.sh.results"
523
524 # Set source directories
525 #
526 setmakeenv NETBSDSRCDIR "${TOP}"
527
528 # Make sure KERNOBJDIR is an absolute path if defined
529 #
530 case "${KERNOBJDIR}" in
531 ''|/*) ;;
532 *) KERNOBJDIR="${TOP}/${KERNOBJDIR}"
533 setmakeenv KERNOBJDIR "${KERNOBJDIR}"
534 ;;
535 esac
536
537 # Find the version of NetBSD
538 #
539 DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
540
541 # Set the BUILDSEED to NetBSD-"N"
542 #
543 setmakeenv BUILDSEED "NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
544
545 # Set MKARZERO to "yes"
546 #
547 setmakeenv MKARZERO "yes"
548
549 }
550
551 # valid_MACHINE_ARCH -- A multi-line string, listing all valid
552 # MACHINE/MACHINE_ARCH pairs.
553 #
554 # Each line contains a MACHINE and MACHINE_ARCH value, an optional ALIAS
555 # which may be used to refer to the MACHINE/MACHINE_ARCH pair, and an
556 # optional DEFAULT or NO_DEFAULT keyword.
557 #
558 # When a MACHINE corresponds to multiple possible values of
559 # MACHINE_ARCH, then this table should list all allowed combinations.
560 # If the MACHINE is associated with a default MACHINE_ARCH (to be
561 # used when the user specifies the MACHINE but fails to specify the
562 # MACHINE_ARCH), then one of the lines should have the "DEFAULT"
563 # keyword. If there is no default MACHINE_ARCH for a particular
564 # MACHINE, then there should be a line with the "NO_DEFAULT" keyword,
565 # and with a blank MACHINE_ARCH.
566 #
567 valid_MACHINE_ARCH='
568 MACHINE=acorn26 MACHINE_ARCH=arm
569 MACHINE=acorn32 MACHINE_ARCH=arm
570 MACHINE=algor MACHINE_ARCH=mips64el ALIAS=algor64
571 MACHINE=algor MACHINE_ARCH=mipsel DEFAULT
572 MACHINE=alpha MACHINE_ARCH=alpha
573 MACHINE=amd64 MACHINE_ARCH=x86_64
574 MACHINE=amiga MACHINE_ARCH=m68k
575 MACHINE=amigappc MACHINE_ARCH=powerpc
576 MACHINE=arc MACHINE_ARCH=mips64el ALIAS=arc64
577 MACHINE=arc MACHINE_ARCH=mipsel DEFAULT
578 MACHINE=atari MACHINE_ARCH=m68k
579 MACHINE=bebox MACHINE_ARCH=powerpc
580 MACHINE=cats MACHINE_ARCH=arm DEFAULT
581 MACHINE=cats MACHINE_ARCH=earm
582 MACHINE=cesfic MACHINE_ARCH=m68k
583 MACHINE=cobalt MACHINE_ARCH=mips64el ALIAS=cobalt64
584 MACHINE=cobalt MACHINE_ARCH=mipsel DEFAULT
585 MACHINE=dreamcast MACHINE_ARCH=sh3el
586 MACHINE=emips MACHINE_ARCH=mipseb
587 MACHINE=evbarm MACHINE_ARCH=arm ALIAS=evbarm-el DEFAULT
588 MACHINE=evbarm MACHINE_ARCH=armeb ALIAS=evbarm-eb
589 MACHINE=evbarm MACHINE_ARCH=earm ALIAS=evbearm-el
590 MACHINE=evbarm MACHINE_ARCH=earmeb ALIAS=evbearm-eb
591 MACHINE=evbmips MACHINE_ARCH= NO_DEFAULT
592 MACHINE=evbmips MACHINE_ARCH=mips64eb ALIAS=evbmips64-eb
593 MACHINE=evbmips MACHINE_ARCH=mips64el ALIAS=evbmips64-el
594 MACHINE=evbmips MACHINE_ARCH=mipseb ALIAS=evbmips-eb
595 MACHINE=evbmips MACHINE_ARCH=mipsel ALIAS=evbmips-el
596 MACHINE=evbppc MACHINE_ARCH=powerpc DEFAULT
597 MACHINE=evbppc MACHINE_ARCH=powerpc64 ALIAS=evbppc64
598 MACHINE=evbsh3 MACHINE_ARCH= NO_DEFAULT
599 MACHINE=evbsh3 MACHINE_ARCH=sh3eb ALIAS=evbsh3-eb
600 MACHINE=evbsh3 MACHINE_ARCH=sh3el ALIAS=evbsh3-el
601 MACHINE=ews4800mips MACHINE_ARCH=mipseb
602 MACHINE=hp300 MACHINE_ARCH=m68k
603 MACHINE=hp700 MACHINE_ARCH=hppa
604 MACHINE=hpcarm MACHINE_ARCH=arm
605 MACHINE=hpcmips MACHINE_ARCH=mipsel
606 MACHINE=hpcsh MACHINE_ARCH=sh3el
607 MACHINE=i386 MACHINE_ARCH=i386
608 MACHINE=ia64 MACHINE_ARCH=ia64
609 MACHINE=ibmnws MACHINE_ARCH=powerpc
610 MACHINE=iyonix MACHINE_ARCH=arm DEFAULT
611 MACHINE=iyonix MACHINE_ARCH=earm
612 MACHINE=landisk MACHINE_ARCH=sh3el
613 MACHINE=luna68k MACHINE_ARCH=m68k
614 MACHINE=mac68k MACHINE_ARCH=m68k
615 MACHINE=macppc MACHINE_ARCH=powerpc DEFAULT
616 MACHINE=macppc MACHINE_ARCH=powerpc64 ALIAS=macppc64
617 MACHINE=mipsco MACHINE_ARCH=mipseb
618 MACHINE=mmeye MACHINE_ARCH=sh3eb
619 MACHINE=mvme68k MACHINE_ARCH=m68k
620 MACHINE=mvmeppc MACHINE_ARCH=powerpc
621 MACHINE=netwinder MACHINE_ARCH=arm DEFAULT
622 MACHINE=netwinder MACHINE_ARCH=earm
623 MACHINE=news68k MACHINE_ARCH=m68k
624 MACHINE=newsmips MACHINE_ARCH=mipseb
625 MACHINE=next68k MACHINE_ARCH=m68k
626 MACHINE=ofppc MACHINE_ARCH=powerpc DEFAULT
627 MACHINE=ofppc MACHINE_ARCH=powerpc64 ALIAS=ofppc64
628 MACHINE=pmax MACHINE_ARCH=mips64el ALIAS=pmax64
629 MACHINE=pmax MACHINE_ARCH=mipsel DEFAULT
630 MACHINE=prep MACHINE_ARCH=powerpc
631 MACHINE=rs6000 MACHINE_ARCH=powerpc
632 MACHINE=sandpoint MACHINE_ARCH=powerpc
633 MACHINE=sbmips MACHINE_ARCH= NO_DEFAULT
634 MACHINE=sbmips MACHINE_ARCH=mips64eb ALIAS=sbmips64-eb
635 MACHINE=sbmips MACHINE_ARCH=mips64el ALIAS=sbmips64-el
636 MACHINE=sbmips MACHINE_ARCH=mipseb ALIAS=sbmips-eb
637 MACHINE=sbmips MACHINE_ARCH=mipsel ALIAS=sbmips-el
638 MACHINE=sgimips MACHINE_ARCH=mips64eb ALIAS=sgimips64
639 MACHINE=sgimips MACHINE_ARCH=mipseb DEFAULT
640 MACHINE=shark MACHINE_ARCH=arm DEFAULT
641 MACHINE=shark MACHINE_ARCH=earm
642 MACHINE=sparc MACHINE_ARCH=sparc
643 MACHINE=sparc64 MACHINE_ARCH=sparc64
644 MACHINE=sun2 MACHINE_ARCH=m68000
645 MACHINE=sun3 MACHINE_ARCH=m68k
646 MACHINE=vax MACHINE_ARCH=vax
647 MACHINE=x68k MACHINE_ARCH=m68k
648 MACHINE=zaurus MACHINE_ARCH=arm DEFAULT
649 MACHINE=zaurus MACHINE_ARCH=earm
650 '
651
652 # getarch -- find the default MACHINE_ARCH for a MACHINE,
653 # or convert an alias to a MACHINE/MACHINE_ARCH pair.
654 #
655 # Saves MACHINE in makewrappermachine before possibly modifying MACHINE.
656 #
657 # Sets MACHINE and MACHINE_ARCH if the input MACHINE value is
658 # recognised as an alias, or recognised as a machine that has a default
659 # MACHINE_ARCH (or that has only one possible MACHINE_ARCH).
660 #
661 # Leaves MACHINE and MACHINE_ARCH unchanged if MACHINE is recognised
662 # as being associated with multiple MACHINE_ARCH values with no default.
663 #
664 # Bombs if MACHINE is not recognised.
665 #
666 getarch()
667 {
668 local IFS
669 local found=""
670 local line
671
672 IFS="${nl}"
673 makewrappermachine="${MACHINE}"
674 for line in ${valid_MACHINE_ARCH}; do
675 line="${line%%#*}" # ignore comments
676 line="$( IFS=" ${tab}" ; echo $line )" # normalise white space
677 case "${line} " in
678 "")
679 # skip blank lines or comment lines
680 continue
681 ;;
682 *" ALIAS=${MACHINE} "*)
683 # Found a line with a matching ALIAS=<alias>.
684 found="$line"
685 break
686 ;;
687 "MACHINE=${MACHINE} "*" NO_DEFAULT"*)
688 # Found an explicit "NO_DEFAULT" for this MACHINE.
689 found="$line"
690 break
691 ;;
692 "MACHINE=${MACHINE} "*" DEFAULT"*)
693 # Found an explicit "DEFAULT" for this MACHINE.
694 found="$line"
695 break
696 ;;
697 "MACHINE=${MACHINE} "*)
698 # Found a line for this MACHINE. If it's the
699 # first such line, then tentatively accept it.
700 # If it's not the first matching line, then
701 # remember that there was more than one match.
702 case "$found" in
703 '') found="$line" ;;
704 *) found="MULTIPLE_MATCHES" ; break ;;
705 esac
706 ;;
707 esac
708 done
709
710 case "$found" in
711 *NO_DEFAULT*|*MULTIPLE_MATCHES*)
712 # MACHINE is OK, but MACHINE_ARCH is still unknown
713 return
714 ;;
715 "MACHINE="*" MACHINE_ARCH="*)
716 # Obey the MACHINE= and MACHINE_ARCH= parts of the line.
717 IFS=" "
718 for frag in ${found}; do
719 case "$frag" in
720 MACHINE=*|MACHINE_ARCH=*)
721 eval "$frag"
722 ;;
723 esac
724 done
725 ;;
726 *)
727 bomb "Unknown target MACHINE: ${MACHINE}"
728 ;;
729 esac
730 }
731
732 # validatearch -- check that the MACHINE/MACHINE_ARCH pair is supported.
733 #
734 # Bombs if the pair is not supported.
735 #
736 validatearch()
737 {
738 local IFS
739 local line
740 local foundpair=false foundmachine=false foundarch=false
741
742 case "${MACHINE_ARCH}" in
743 "")
744 bomb "No MACHINE_ARCH provided"
745 ;;
746 esac
747
748 IFS="${nl}"
749 for line in ${valid_MACHINE_ARCH}; do
750 line="${line%%#*}" # ignore comments
751 line="$( IFS=" ${tab}" ; echo $line )" # normalise white space
752 case "${line} " in
753 "")
754 # skip blank lines or comment lines
755 continue
756 ;;
757 "MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} "*)
758 foundpair=true
759 ;;
760 "MACHINE=${MACHINE} "*)
761 foundmachine=true
762 ;;
763 *"MACHINE_ARCH=${MACHINE_ARCH} "*)
764 foundarch=true
765 ;;
766 esac
767 done
768
769 case "${foundpair}:${foundmachine}:${foundarch}" in
770 true:*)
771 : OK
772 ;;
773 *:false:*)
774 bomb "Unknown target MACHINE: ${MACHINE}"
775 ;;
776 *:*:false)
777 bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
778 ;;
779 *)
780 bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
781 ;;
782 esac
783 }
784
785 # nobomb_getmakevar --
786 # Given the name of a make variable in $1, print make's idea of the
787 # value of that variable, or return 1 if there's an error.
788 #
789 nobomb_getmakevar()
790 {
791 [ -x "${make}" ] || return 1
792 "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
793 _x_:
794 echo \${$1}
795 .include <bsd.prog.mk>
796 .include <bsd.kernobj.mk>
797 EOF
798 }
799
800 # bomb_getmakevar --
801 # Given the name of a make variable in $1, print make's idea of the
802 # value of that variable, or bomb if there's an error.
803 #
804 bomb_getmakevar()
805 {
806 [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable"
807 nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed"
808 }
809
810 # getmakevar --
811 # Given the name of a make variable in $1, print make's idea of the
812 # value of that variable, or print a literal '$' followed by the
813 # variable name if ${make} is not executable. This is intended for use in
814 # messages that need to be readable even if $make hasn't been built,
815 # such as when build.sh is run with the "-n" option.
816 #
817 getmakevar()
818 {
819 if [ -x "${make}" ]; then
820 bomb_getmakevar "$1"
821 else
822 echo "\$$1"
823 fi
824 }
825
826 setmakeenv()
827 {
828 eval "$1='$2'; export $1"
829 makeenv="${makeenv} $1"
830 }
831
832 unsetmakeenv()
833 {
834 eval "unset $1"
835 makeenv="${makeenv} $1"
836 }
837
838 # Given a variable name in $1, modify the variable in place as follows:
839 # For each space-separated word in the variable, call resolvepath.
840 resolvepaths()
841 {
842 local var="$1"
843 local val
844 eval val=\"\${${var}}\"
845 local newval=''
846 local word
847 for word in ${val}; do
848 resolvepath word
849 newval="${newval}${newval:+ }${word}"
850 done
851 eval ${var}=\"\${newval}\"
852 }
853
854 # Given a variable name in $1, modify the variable in place as follows:
855 # Convert possibly-relative path to absolute path by prepending
856 # ${TOP} if necessary. Also delete trailing "/", if any.
857 resolvepath()
858 {
859 local var="$1"
860 local val
861 eval val=\"\${${var}}\"
862 case "${val}" in
863 /)
864 ;;
865 /*)
866 val="${val%/}"
867 ;;
868 *)
869 val="${TOP}/${val%/}"
870 ;;
871 esac
872 eval ${var}=\"\${val}\"
873 }
874
875 usage()
876 {
877 if [ -n "$*" ]; then
878 echo ""
879 echo "${progname}: $*"
880 fi
881 cat <<_usage_
882
883 Usage: ${progname} [-EhnorUuxy] [-a arch] [-B buildid] [-C cdextras]
884 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
885 [-O obj] [-R release] [-S seed] [-T tools]
886 [-V var=[value]] [-w wrapper] [-X x11src] [-Y extsrcsrc]
887 [-Z var]
888 operation [...]
889
890 Build operations (all imply "obj" and "tools"):
891 build Run "make build".
892 distribution Run "make distribution" (includes DESTDIR/etc/ files).
893 release Run "make release" (includes kernels & distrib media).
894
895 Other operations:
896 help Show this message and exit.
897 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
898 Always performed.
899 cleandir Run "make cleandir". [Default unless -u is used]
900 obj Run "make obj". [Default unless -o is used]
901 tools Build and install tools.
902 install=idir Run "make installworld" to \`idir' to install all sets
903 except \`etc'. Useful after "distribution" or "release"
904 kernel=conf Build kernel with config file \`conf'
905 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
906 installmodules=idir Run "make installmodules" to \`idir' to install all
907 kernel modules.
908 modules Build kernel modules.
909 rumptest Do a linktest for rump (for developers).
910 sets Create binary sets in
911 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
912 DESTDIR should be populated beforehand.
913 sourcesets Create source sets in RELEASEDIR/source/sets.
914 syspkgs Create syspkgs in
915 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
916 iso-image Create CD-ROM image in RELEASEDIR/iso.
917 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
918 live-image Create bootable live image in
919 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage.
920 install-image Create bootable installation image in
921 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage.
922 params Display various make(1) parameters.
923
924 Options:
925 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
926 -B buildid Set BUILDID to buildid.
927 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM.
928 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
929 -E Set "expert" mode; disables various safety checks.
930 Should not be used without expert knowledge of the build system.
931 -h Print this help message.
932 -j njob Run up to njob jobs in parallel; see make(1) -j.
933 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
934 Unsets MAKEOBJDIR.
935 -m mach Set MACHINE to mach; not required if NetBSD native.
936 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
937 0 Minimal output ("quiet")
938 1 Describe what is occurring
939 2 Describe what is occurring and echo the actual command
940 3 Ignore the effect of the "@" prefix in make commands
941 4 Trace shell commands using the shell's -x flag
942 [Default: 2]
943 -n Show commands that would be executed, but do not execute them.
944 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
945 Unsets MAKEOBJDIRPREFIX.
946 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
947 -R release Set RELEASEDIR to release. [Default: releasedir]
948 -r Remove contents of TOOLDIR and DESTDIR before building.
949 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
950 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
951 the environment, ${toolprefix}make will be (re)built
952 unconditionally.
953 -U Set MKUNPRIVED=yes; build without requiring root privileges,
954 install from an UNPRIVED build with proper file permissions.
955 -u Set MKUPDATE=yes; do not run "make cleandir" first.
956 Without this, everything is rebuilt, including the tools.
957 -V var=[value] Set variable \`var' to \`value'.
958 -w wrapper Create ${toolprefix}make script as wrapper.
959 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
960 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
961 -x Set MKX11=yes; build X11 from X11SRCDIR
962 -Y extsrcsrc Set EXTSRCSRCDIR to extsrcsrc. [Default: /usr/extsrc]
963 -y Set MKEXTSRC=yes; build extsrc from EXTSRCSRCDIR
964 -Z var Unset ("zap") variable \`var'.
965
966 _usage_
967 exit 1
968 }
969
970 parseoptions()
971 {
972 opts='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:X:xY:yZ:'
973 opt_a=no
974
975 if type getopts >/dev/null 2>&1; then
976 # Use POSIX getopts.
977 #
978 getoptcmd='getopts ${opts} opt && opt=-${opt}'
979 optargcmd=':'
980 optremcmd='shift $((${OPTIND} -1))'
981 else
982 type getopt >/dev/null 2>&1 ||
983 bomb "Shell does not support getopts or getopt"
984
985 # Use old-style getopt(1) (doesn't handle whitespace in args).
986 #
987 args="$(getopt ${opts} $*)"
988 [ $? = 0 ] || usage
989 set -- ${args}
990
991 getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
992 optargcmd='OPTARG="$1"; shift'
993 optremcmd=':'
994 fi
995
996 # Parse command line options.
997 #
998 while eval ${getoptcmd}; do
999 case ${opt} in
1000
1001 -a)
1002 eval ${optargcmd}
1003 MACHINE_ARCH=${OPTARG}
1004 opt_a=yes
1005 ;;
1006
1007 -B)
1008 eval ${optargcmd}
1009 BUILDID=${OPTARG}
1010 ;;
1011
1012 -C)
1013 eval ${optargcmd}; resolvepaths OPTARG
1014 CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}"
1015 ;;
1016
1017 -D)
1018 eval ${optargcmd}; resolvepath OPTARG
1019 setmakeenv DESTDIR "${OPTARG}"
1020 ;;
1021
1022 -E)
1023 do_expertmode=true
1024 ;;
1025
1026 -j)
1027 eval ${optargcmd}
1028 parallel="-j ${OPTARG}"
1029 ;;
1030
1031 -M)
1032 eval ${optargcmd}; resolvepath OPTARG
1033 case "${OPTARG}" in
1034 \$*) usage "-M argument must not begin with '\$'"
1035 ;;
1036 *\$*) # can use resolvepath, but can't set TOP_objdir
1037 resolvepath OPTARG
1038 ;;
1039 *) resolvepath OPTARG
1040 TOP_objdir="${OPTARG}${TOP}"
1041 ;;
1042 esac
1043 unsetmakeenv MAKEOBJDIR
1044 setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1045 ;;
1046
1047 # -m overrides MACHINE_ARCH unless "-a" is specified
1048 -m)
1049 eval ${optargcmd}
1050 MACHINE="${OPTARG}"
1051 [ "${opt_a}" != "yes" ] && getarch
1052 ;;
1053
1054 -N)
1055 eval ${optargcmd}
1056 case "${OPTARG}" in
1057 0|1|2|3|4)
1058 setmakeenv MAKEVERBOSE "${OPTARG}"
1059 ;;
1060 *)
1061 usage "'${OPTARG}' is not a valid value for -N"
1062 ;;
1063 esac
1064 ;;
1065
1066 -n)
1067 runcmd=echo
1068 ;;
1069
1070 -O)
1071 eval ${optargcmd}
1072 case "${OPTARG}" in
1073 *\$*) usage "-O argument must not contain '\$'"
1074 ;;
1075 *) resolvepath OPTARG
1076 TOP_objdir="${OPTARG}"
1077 ;;
1078 esac
1079 unsetmakeenv MAKEOBJDIRPREFIX
1080 setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1081 ;;
1082
1083 -o)
1084 MKOBJDIRS=no
1085 ;;
1086
1087 -R)
1088 eval ${optargcmd}; resolvepath OPTARG
1089 setmakeenv RELEASEDIR "${OPTARG}"
1090 ;;
1091
1092 -r)
1093 do_removedirs=true
1094 do_rebuildmake=true
1095 ;;
1096
1097 -S)
1098 eval ${optargcmd}
1099 setmakeenv BUILDSEED "${OPTARG}"
1100 ;;
1101
1102 -T)
1103 eval ${optargcmd}; resolvepath OPTARG
1104 TOOLDIR="${OPTARG}"
1105 export TOOLDIR
1106 ;;
1107
1108 -U)
1109 setmakeenv MKUNPRIVED yes
1110 ;;
1111
1112 -u)
1113 setmakeenv MKUPDATE yes
1114 ;;
1115
1116 -V)
1117 eval ${optargcmd}
1118 case "${OPTARG}" in
1119 # XXX: consider restricting which variables can be changed?
1120 [a-zA-Z_][a-zA-Z_0-9]*=*)
1121 setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1122 ;;
1123 *)
1124 usage "-V argument must be of the form 'var=[value]'"
1125 ;;
1126 esac
1127 ;;
1128
1129 -w)
1130 eval ${optargcmd}; resolvepath OPTARG
1131 makewrapper="${OPTARG}"
1132 ;;
1133
1134 -X)
1135 eval ${optargcmd}; resolvepath OPTARG
1136 setmakeenv X11SRCDIR "${OPTARG}"
1137 ;;
1138
1139 -x)
1140 setmakeenv MKX11 yes
1141 ;;
1142
1143 -Y)
1144 eval ${optargcmd}; resolvepath OPTARG
1145 setmakeenv EXTSRCSRCDIR "${OPTARG}"
1146 ;;
1147
1148 -y)
1149 setmakeenv MKEXTSRC yes
1150 ;;
1151
1152 -Z)
1153 eval ${optargcmd}
1154 # XXX: consider restricting which variables can be unset?
1155 unsetmakeenv "${OPTARG}"
1156 ;;
1157
1158 --)
1159 break
1160 ;;
1161
1162 -'?'|-h)
1163 usage
1164 ;;
1165
1166 esac
1167 done
1168
1169 # Validate operations.
1170 #
1171 eval ${optremcmd}
1172 while [ $# -gt 0 ]; do
1173 op=$1; shift
1174 operations="${operations} ${op}"
1175
1176 case "${op}" in
1177
1178 help)
1179 usage
1180 ;;
1181
1182 makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
1183 ;;
1184
1185 iso-image)
1186 op=iso_image # used as part of a variable name
1187 ;;
1188
1189 iso-image-source)
1190 op=iso_image_source # used as part of a variable name
1191 ;;
1192
1193 live-image)
1194 op=live_image # used as part of a variable name
1195 ;;
1196
1197 install-image)
1198 op=install_image # used as part of a variable name
1199 ;;
1200
1201 kernel=*|releasekernel=*)
1202 arg=${op#*=}
1203 op=${op%%=*}
1204 [ -n "${arg}" ] ||
1205 bomb "Must supply a kernel name with \`${op}=...'"
1206 ;;
1207
1208 modules)
1209 op=modules
1210 ;;
1211
1212 install=*|installmodules=*)
1213 arg=${op#*=}
1214 op=${op%%=*}
1215 [ -n "${arg}" ] ||
1216 bomb "Must supply a directory with \`install=...'"
1217 ;;
1218
1219 rump|rumptest)
1220 op=${op}
1221 ;;
1222
1223 *)
1224 usage "Unknown operation \`${op}'"
1225 ;;
1226
1227 esac
1228 eval do_${op}=true
1229 done
1230 [ -n "${operations}" ] || usage "Missing operation to perform."
1231
1232 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
1233 #
1234 if [ -z "${MACHINE}" ]; then
1235 [ "${uname_s}" = "NetBSD" ] ||
1236 bomb "MACHINE must be set, or -m must be used, for cross builds."
1237 MACHINE=${uname_m}
1238 fi
1239 [ -n "${MACHINE_ARCH}" ] || getarch
1240 validatearch
1241
1242 # Set up default make(1) environment.
1243 #
1244 makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
1245 [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1246 MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}"
1247 MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1248 export MAKEFLAGS MACHINE MACHINE_ARCH
1249 }
1250
1251 # sanitycheck --
1252 # Sanity check after parsing command line options, before rebuildmake.
1253 #
1254 sanitycheck()
1255 {
1256 # Non-root should always use either the -U or -E flag.
1257 #
1258 if ! ${do_expertmode} && \
1259 [ "$id_u" -ne 0 ] && \
1260 [ "${MKUNPRIVED}" = "no" ] ; then
1261 bomb "-U or -E must be set for build as an unprivileged user."
1262 fi
1263
1264 # Install as non-root is a bad idea.
1265 #
1266 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1267 if ${do_expertmode}; then
1268 warning "Will install as an unprivileged user."
1269 else
1270 bomb "-E must be set for install as an unprivileged user."
1271 fi
1272 fi
1273
1274 # If the PATH contains any non-absolute components (including,
1275 # but not limited to, "." or ""), then complain. As an exception,
1276 # allow "" or "." as the last component of the PATH. This is fatal
1277 # if expert mode is not in effect.
1278 #
1279 local path="${PATH}"
1280 path="${path%:}" # delete trailing ":"
1281 path="${path%:.}" # delete trailing ":."
1282 case ":${path}:/" in
1283 *:[!/]*)
1284 if ${do_expertmode}; then
1285 warning "PATH contains non-absolute components"
1286 else
1287 bomb "PATH environment variable must not" \
1288 "contain non-absolute components"
1289 fi
1290 ;;
1291 esac
1292 }
1293
1294 # print_tooldir_make --
1295 # Try to find and print a path to an existing
1296 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1297 # new version of ${toolprefix}make has been built.
1298 #
1299 # * If TOOLDIR was set in the environment or on the command line, use
1300 # that value.
1301 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1302 # /etc/mk.conf, and check whether the resulting directory contains
1303 # a copy of ${toolprefix}make (this should work for everybody who
1304 # doesn't override TOOLDIR via /etc/mk.conf);
1305 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1306 # in the PATH (this might accidentally find a version of make that
1307 # does not understand the syntax used by NetBSD make, and that will
1308 # lead to failure in the next step);
1309 # * If a copy of make was found above, try to use it with
1310 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1311 # result only if it's a directory that already exists;
1312 # * If a value of TOOLDIR was found above, and if
1313 # ${TOOLDIR}/bin/${toolprefix}make exists, print that value.
1314 #
1315 print_tooldir_make()
1316 {
1317 local possible_TOP_OBJ
1318 local possible_TOOLDIR
1319 local possible_make
1320 local tooldir_make
1321
1322 if [ -n "${TOOLDIR}" ]; then
1323 echo "${TOOLDIR}/bin/${toolprefix}make"
1324 return 0
1325 fi
1326
1327 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1328 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1329 #
1330 local host_ostype="${uname_s}-$(
1331 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1332 )-$(
1333 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1334 )"
1335
1336 # Look in a few potential locations for
1337 # ${possible_TOOLDIR}/bin/${toolprefix}make.
1338 # If we find it, then set possible_make.
1339 #
1340 # In the usual case (without interference from environment
1341 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1342 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1343 #
1344 # In practice it's difficult to figure out the correct value
1345 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1346 # options were passed to build.sh, then ${TOP_objdir} will be
1347 # the correct value. We also try a few other possibilities, but
1348 # we do not replicate all the logic of <bsd.obj.mk>.
1349 #
1350 for possible_TOP_OBJ in \
1351 "${TOP_objdir}" \
1352 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1353 "${TOP}" \
1354 "${TOP}/obj" \
1355 "${TOP}/obj.${MACHINE}"
1356 do
1357 [ -n "${possible_TOP_OBJ}" ] || continue
1358 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1359 possible_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1360 if [ -x "${possible_make}" ]; then
1361 break
1362 else
1363 unset possible_make
1364 fi
1365 done
1366
1367 # If the above didn't work, search the PATH for a suitable
1368 # ${toolprefix}make, nbmake, bmake, or make.
1369 #
1370 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1371 : ${possible_make:=$(find_in_PATH nbmake '')}
1372 : ${possible_make:=$(find_in_PATH bmake '')}
1373 : ${possible_make:=$(find_in_PATH make '')}
1374
1375 # At this point, we don't care whether possible_make is in the
1376 # correct TOOLDIR or not; we simply want it to be usable by
1377 # getmakevar to help us find the correct TOOLDIR.
1378 #
1379 # Use ${possible_make} with nobomb_getmakevar to try to find
1380 # the value of TOOLDIR. Believe the result only if it's
1381 # a directory that already exists and contains bin/${toolprefix}make.
1382 #
1383 if [ -x "${possible_make}" ]; then
1384 possible_TOOLDIR="$(
1385 make="${possible_make}" \
1386 nobomb_getmakevar TOOLDIR 2>/dev/null
1387 )"
1388 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1389 && [ -d "${possible_TOOLDIR}" ];
1390 then
1391 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1392 if [ -x "${tooldir_make}" ]; then
1393 echo "${tooldir_make}"
1394 return 0
1395 fi
1396 fi
1397 fi
1398 return 1
1399 }
1400
1401 # rebuildmake --
1402 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1403 # to a path to the nbmake executable. Sets done_rebuildmake=true
1404 # if nbmake was rebuilt.
1405 #
1406 # There is a cyclic dependency between building nbmake and choosing
1407 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1408 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1409 # use getmakevar before we have an up to date version of nbmake; we
1410 # might already have an up to date version of nbmake in TOOLDIR, but we
1411 # don't yet know where TOOLDIR is.
1412 #
1413 # The default value of TOOLDIR also depends on the location of the top
1414 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1415 # after making the top level object directory may produce different
1416 # results.
1417 #
1418 # Strictly speaking, we should do the following:
1419 #
1420 # 1. build a new version of nbmake in a temporary directory;
1421 # 2. use the temporary nbmake to create the top level obj directory;
1422 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1423 # get the corect value of TOOLDIR;
1424 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1425 #
1426 # However, people don't like building nbmake unnecessarily if their
1427 # TOOLDIR has not changed since an earlier build. We try to avoid
1428 # rebuilding a temporary version of nbmake by taking some shortcuts to
1429 # guess a value for TOOLDIR, looking for an existing version of nbmake
1430 # in that TOOLDIR, and checking whether that nbmake is newer than the
1431 # sources used to build it.
1432 #
1433 rebuildmake()
1434 {
1435 make="$(print_tooldir_make)"
1436 if [ -n "${make}" ] && [ -x "${make}" ]; then
1437 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1438 if [ "${f}" -nt "${make}" ]; then
1439 statusmsg "${make} outdated" \
1440 "(older than ${f}), needs building."
1441 do_rebuildmake=true
1442 break
1443 fi
1444 done
1445 else
1446 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1447 do_rebuildmake=true
1448 fi
1449
1450 # Build bootstrap ${toolprefix}make if needed.
1451 if ${do_rebuildmake}; then
1452 statusmsg "Bootstrapping ${toolprefix}make"
1453 ${runcmd} cd "${tmpdir}"
1454 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1455 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1456 ${HOST_SH} "${TOP}/tools/make/configure" ||
1457 bomb "Configure of ${toolprefix}make failed"
1458 ${runcmd} ${HOST_SH} buildmake.sh ||
1459 bomb "Build of ${toolprefix}make failed"
1460 make="${tmpdir}/${toolprefix}make"
1461 ${runcmd} cd "${TOP}"
1462 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1463 done_rebuildmake=true
1464 fi
1465 }
1466
1467 # validatemakeparams --
1468 # Perform some late sanity checks, after rebuildmake,
1469 # but before createmakewrapper or any real work.
1470 #
1471 # Creates the top-level obj directory, because that
1472 # is needed by some of the sanity checks.
1473 #
1474 # Prints status messages reporting the values of several variables.
1475 #
1476 validatemakeparams()
1477 {
1478 # MAKECONF (which defaults to /etc/mk.conf in share/mk/bsd.own.mk)
1479 # can affect many things, so mention it in an early status message.
1480 #
1481 MAKECONF=$(getmakevar MAKECONF)
1482 if [ -e "${MAKECONF}" ]; then
1483 statusmsg2 "MAKECONF file:" "${MAKECONF}"
1484 else
1485 statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)"
1486 fi
1487
1488 if [ "${runcmd}" = "echo" ]; then
1489 TOOLCHAIN_MISSING=no
1490 EXTERNAL_TOOLCHAIN=""
1491 else
1492 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1493 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1494 fi
1495 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1496 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1497 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1498 ${runcmd} echo " MACHINE: ${MACHINE}"
1499 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1500 ${runcmd} echo ""
1501 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1502 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1503 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1504 ${runcmd} echo "in either the environment or mk.conf and rerun"
1505 ${runcmd} echo " ${progname} $*"
1506 exit 1
1507 fi
1508
1509 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1510 # These may be set as build.sh options or in "mk.conf".
1511 # Don't export them as they're only used for tests in build.sh.
1512 #
1513 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1514 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1515 MKUPDATE=$(getmakevar MKUPDATE)
1516
1517 if [ "${MKOBJDIRS}" != "no" ]; then
1518 # Create the top-level object directory.
1519 #
1520 # "make obj NOSUBDIR=" can handle most cases, but it
1521 # can't handle the case where MAKEOBJDIRPREFIX is set
1522 # while the corresponding directory does not exist
1523 # (rules in <bsd.obj.mk> would abort the build). We
1524 # therefore have to handle the MAKEOBJDIRPREFIX case
1525 # without invoking "make obj". The MAKEOBJDIR case
1526 # could be handled either way, but we choose to handle
1527 # it similarly to MAKEOBJDIRPREFIX.
1528 #
1529 if [ -n "${TOP_obj}" ]; then
1530 # It must have been set by the "-M" or "-O"
1531 # command line options, so there's no need to
1532 # use getmakevar
1533 :
1534 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1535 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1536 elif [ -n "$MAKEOBJDIR" ]; then
1537 TOP_obj="$(getmakevar MAKEOBJDIR)"
1538 fi
1539 if [ -n "$TOP_obj" ]; then
1540 ${runcmd} mkdir -p "${TOP_obj}" ||
1541 bomb "Can't create top level object directory" \
1542 "${TOP_obj}"
1543 else
1544 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1545 bomb "Can't create top level object directory" \
1546 "using make obj"
1547 fi
1548
1549 # make obj in tools to ensure that the objdir for "tools"
1550 # is available.
1551 #
1552 ${runcmd} cd tools
1553 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1554 bomb "Failed to make obj in tools"
1555 ${runcmd} cd "${TOP}"
1556 fi
1557
1558 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1559 # and bomb if they have changed from the values we had from the
1560 # command line or environment.
1561 #
1562 # This must be done after creating the top-level object directory.
1563 #
1564 for var in TOOLDIR DESTDIR RELEASEDIR
1565 do
1566 eval oldval=\"\$${var}\"
1567 newval="$(getmakevar $var)"
1568 if ! $do_expertmode; then
1569 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1570 case "$var" in
1571 DESTDIR)
1572 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1573 makeenv="${makeenv} DESTDIR"
1574 ;;
1575 RELEASEDIR)
1576 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1577 makeenv="${makeenv} RELEASEDIR"
1578 ;;
1579 esac
1580 fi
1581 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1582 bomb "Value of ${var} has changed" \
1583 "(was \"${oldval}\", now \"${newval}\")"
1584 fi
1585 eval ${var}=\"\${newval}\"
1586 eval export ${var}
1587 statusmsg2 "${var} path:" "${newval}"
1588 done
1589
1590 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1591 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1592
1593 # Check validity of TOOLDIR and DESTDIR.
1594 #
1595 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1596 bomb "TOOLDIR '${TOOLDIR}' invalid"
1597 fi
1598 removedirs="${TOOLDIR}"
1599
1600 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1601 if ${do_distribution} || ${do_release} || \
1602 [ "${uname_s}" != "NetBSD" ] || \
1603 [ "${uname_m}" != "${MACHINE}" ]; then
1604 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1605 fi
1606 if ! ${do_expertmode}; then
1607 bomb "DESTDIR must != / for non -E (expert) builds"
1608 fi
1609 statusmsg "WARNING: Building to /, in expert mode."
1610 statusmsg " This may cause your system to break! Reasons include:"
1611 statusmsg " - your kernel is not up to date"
1612 statusmsg " - the libraries or toolchain have changed"
1613 statusmsg " YOU HAVE BEEN WARNED!"
1614 else
1615 removedirs="${removedirs} ${DESTDIR}"
1616 fi
1617 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1618 bomb "Must set RELEASEDIR with \`releasekernel=...'"
1619 fi
1620
1621 # If a previous build.sh run used -U (and therefore created a
1622 # METALOG file), then most subsequent build.sh runs must also
1623 # use -U. If DESTDIR is about to be removed, then don't perform
1624 # this check.
1625 #
1626 case "${do_removedirs} ${removedirs} " in
1627 true*" ${DESTDIR} "*)
1628 # DESTDIR is about to be removed
1629 ;;
1630 *)
1631 if [ -e "${DESTDIR}/METALOG" ] && \
1632 [ "${MKUNPRIVED}" = "no" ] ; then
1633 if $do_expertmode; then
1634 warning "A previous build.sh run specified -U."
1635 else
1636 bomb "A previous build.sh run specified -U; you must specify it again now."
1637 fi
1638 fi
1639 ;;
1640 esac
1641
1642 # live-image and install-image targets require binary sets
1643 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
1644 # If release operation is specified with live-image or install-image,
1645 # the release op should be performed with -U for later image ops.
1646 #
1647 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
1648 [ "${MKUNPRIVED}" = "no" ] ; then
1649 bomb "-U must be specified on building release to create images later."
1650 fi
1651 }
1652
1653
1654 createmakewrapper()
1655 {
1656 # Remove the target directories.
1657 #
1658 if ${do_removedirs}; then
1659 for f in ${removedirs}; do
1660 statusmsg "Removing ${f}"
1661 ${runcmd} rm -r -f "${f}"
1662 done
1663 fi
1664
1665 # Recreate $TOOLDIR.
1666 #
1667 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1668 bomb "mkdir of '${TOOLDIR}/bin' failed"
1669
1670 # If we did not previously rebuild ${toolprefix}make, then
1671 # check whether $make is still valid and the same as the output
1672 # from print_tooldir_make. If not, then rebuild make now. A
1673 # possible reason for this being necessary is that the actual
1674 # value of TOOLDIR might be different from the value guessed
1675 # before the top level obj dir was created.
1676 #
1677 if ! ${done_rebuildmake} && \
1678 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
1679 then
1680 rebuildmake
1681 fi
1682
1683 # Install ${toolprefix}make if it was built.
1684 #
1685 if ${done_rebuildmake}; then
1686 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1687 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1688 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1689 make="${TOOLDIR}/bin/${toolprefix}make"
1690 statusmsg "Created ${make}"
1691 fi
1692
1693 # Build a ${toolprefix}make wrapper script, usable by hand as
1694 # well as by build.sh.
1695 #
1696 if [ -z "${makewrapper}" ]; then
1697 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1698 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1699 fi
1700
1701 ${runcmd} rm -f "${makewrapper}"
1702 if [ "${runcmd}" = "echo" ]; then
1703 echo 'cat <<EOF >'${makewrapper}
1704 makewrapout=
1705 else
1706 makewrapout=">>\${makewrapper}"
1707 fi
1708
1709 case "${KSH_VERSION:-${SH_VERSION}}" in
1710 *PD\ KSH*|*MIRBSD\ KSH*)
1711 set +o braceexpand
1712 ;;
1713 esac
1714
1715 eval cat <<EOF ${makewrapout}
1716 #! ${HOST_SH}
1717 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1718 # Generated from: \$NetBSD: build.sh,v 1.260 2012/12/02 19:19:36 apb Exp $
1719 # with these arguments: ${_args}
1720 #
1721
1722 EOF
1723 {
1724 for f in ${makeenv}; do
1725 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1726 eval echo "unset ${f}"
1727 else
1728 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1729 fi
1730 done
1731
1732 eval cat <<EOF
1733 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1734 USETOOLS=yes; export USETOOLS
1735 EOF
1736 } | eval sort -u "${makewrapout}"
1737 eval cat <<EOF "${makewrapout}"
1738
1739 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1740 EOF
1741 [ "${runcmd}" = "echo" ] && echo EOF
1742 ${runcmd} chmod +x "${makewrapper}"
1743 statusmsg2 "Updated makewrapper:" "${makewrapper}"
1744 }
1745
1746 make_in_dir()
1747 {
1748 dir="$1"
1749 op="$2"
1750 ${runcmd} cd "${dir}" ||
1751 bomb "Failed to cd to \"${dir}\""
1752 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1753 bomb "Failed to make ${op} in \"${dir}\""
1754 ${runcmd} cd "${TOP}" ||
1755 bomb "Failed to cd back to \"${TOP}\""
1756 }
1757
1758 buildtools()
1759 {
1760 if [ "${MKOBJDIRS}" != "no" ]; then
1761 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1762 bomb "Failed to make obj-tools"
1763 fi
1764 if [ "${MKUPDATE}" = "no" ]; then
1765 make_in_dir tools cleandir
1766 fi
1767 make_in_dir tools build_install
1768 statusmsg "Tools built to ${TOOLDIR}"
1769 }
1770
1771 getkernelconf()
1772 {
1773 kernelconf="$1"
1774 if [ "${MKOBJDIRS}" != "no" ]; then
1775 # The correct value of KERNOBJDIR might
1776 # depend on a prior "make obj" in
1777 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1778 #
1779 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1780 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1781 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1782 fi
1783 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1784 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1785 case "${kernelconf}" in
1786 */*)
1787 kernelconfpath="${kernelconf}"
1788 kernelconfname="${kernelconf##*/}"
1789 ;;
1790 *)
1791 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1792 kernelconfname="${kernelconf}"
1793 ;;
1794 esac
1795 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1796 }
1797
1798 buildkernel()
1799 {
1800 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1801 # Building tools every time we build a kernel is clearly
1802 # unnecessary. We could try to figure out whether rebuilding
1803 # the tools is necessary this time, but it doesn't seem worth
1804 # the trouble. Instead, we say it's the user's responsibility
1805 # to rebuild the tools if necessary.
1806 #
1807 statusmsg "Building kernel without building new tools"
1808 buildkernelwarned=true
1809 fi
1810 getkernelconf $1
1811 statusmsg2 "Building kernel:" "${kernelconf}"
1812 statusmsg2 "Build directory:" "${kernelbuildpath}"
1813 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1814 bomb "Cannot mkdir: ${kernelbuildpath}"
1815 if [ "${MKUPDATE}" = "no" ]; then
1816 make_in_dir "${kernelbuildpath}" cleandir
1817 fi
1818 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1819 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1820 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1821 -s "${TOP}/sys" "${kernelconfpath}" ||
1822 bomb "${toolprefix}config failed for ${kernelconf}"
1823 make_in_dir "${kernelbuildpath}" depend
1824 make_in_dir "${kernelbuildpath}" all
1825
1826 if [ "${runcmd}" != "echo" ]; then
1827 statusmsg "Kernels built from ${kernelconf}:"
1828 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1829 for kern in ${kernlist:-netbsd}; do
1830 [ -f "${kernelbuildpath}/${kern}" ] && \
1831 echo " ${kernelbuildpath}/${kern}"
1832 done | tee -a "${results}"
1833 fi
1834 }
1835
1836 releasekernel()
1837 {
1838 getkernelconf $1
1839 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1840 ${runcmd} mkdir -p "${kernelreldir}"
1841 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1842 for kern in ${kernlist:-netbsd}; do
1843 builtkern="${kernelbuildpath}/${kern}"
1844 [ -f "${builtkern}" ] || continue
1845 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1846 statusmsg2 "Kernel copy:" "${releasekern}"
1847 if [ "${runcmd}" = "echo" ]; then
1848 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1849 else
1850 gzip -c -9 < "${builtkern}" > "${releasekern}"
1851 fi
1852 done
1853 }
1854
1855 buildmodules()
1856 {
1857 setmakeenv MKBINUTILS no
1858 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
1859 # Building tools every time we build modules is clearly
1860 # unnecessary as well as a kernel.
1861 #
1862 statusmsg "Building modules without building new tools"
1863 buildmoduleswarned=true
1864 fi
1865
1866 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1867 if [ "${MKOBJDIRS}" != "no" ]; then
1868 make_in_dir sys/modules obj
1869 fi
1870 if [ "${MKUPDATE}" = "no" ]; then
1871 make_in_dir sys/modules cleandir
1872 fi
1873 make_in_dir sys/modules dependall
1874 make_in_dir sys/modules install
1875
1876 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1877 }
1878
1879 installmodules()
1880 {
1881 dir="$1"
1882 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
1883 bomb "Failed to make installmodules to ${dir}"
1884 statusmsg "Successful installmodules to ${dir}"
1885 }
1886
1887 installworld()
1888 {
1889 dir="$1"
1890 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1891 bomb "Failed to make installworld to ${dir}"
1892 statusmsg "Successful installworld to ${dir}"
1893 }
1894
1895 # Run rump build&link tests.
1896 #
1897 # To make this feasible for running without having to install includes and
1898 # libraries into destdir (i.e. quick), we only run ld. This is possible
1899 # since the rump kernel is a closed namespace apart from calls to rumpuser.
1900 # Therefore, if ld complains only about rumpuser symbols, rump kernel
1901 # linking was successful.
1902 #
1903 # We test that rump links with a number of component configurations.
1904 # These attempt to mimic what is encountered in the full build.
1905 # See list below. The list should probably be either autogenerated
1906 # or managed elsewhere; keep it here until a better idea arises.
1907 #
1908 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
1909 #
1910
1911 RUMP_LIBSETS='
1912 -lrump,
1913 -lrumpvfs -lrump,
1914 -lrumpvfs -lrumpdev -lrump,
1915 -lrumpnet -lrump,
1916 -lrumpkern_tty -lrumpvfs -lrump,
1917 -lrumpfs_tmpfs -lrumpvfs -lrump,
1918 -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump,
1919 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump,
1920 -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb
1921 -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump,
1922 -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump,
1923 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd
1924 -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump'
1925 dorump()
1926 {
1927 local doclean=""
1928 local doobjs=""
1929
1930 # we cannot link libs without building csu, and that leads to lossage
1931 [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \
1932 'did you mean "rumptest"?'
1933
1934 # create obj and distrib dirs
1935 if [ "${MKOBJDIRS}" != "no" ]; then
1936 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
1937 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
1938 fi
1939 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
1940 || bomb 'could not create distrib-dirs'
1941
1942 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
1943 targlist="${doclean} ${doobjs} dependall install"
1944 # optimize: for test we build only static libs (3x test speedup)
1945 if [ "${1}" = "rumptest" ] ; then
1946 setmakeenv NOPIC 1
1947 setmakeenv NOPROFILE 1
1948 fi
1949 for cmd in ${targlist} ; do
1950 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
1951 done
1952
1953 # if we just wanted to build & install rump, we're done
1954 [ "${1}" != "rumptest" ] && return
1955
1956 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
1957 || bomb "cd to rumpkern failed"
1958 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
1959 # one little, two little, three little backslashes ...
1960 md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )"
1961 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
1962 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
1963
1964 local oIFS="${IFS}"
1965 IFS=","
1966 for set in ${RUMP_LIBSETS} ; do
1967 IFS="${oIFS}"
1968 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
1969 -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \
1970 awk -v quirks="${md_quirks}" '
1971 /undefined reference/ &&
1972 !/more undefined references.*follow/{
1973 if (match($NF,
1974 "`(rumpuser_|__" quirks ")") == 0)
1975 fails[NR] = $0
1976 }
1977 /cannot find -l/{fails[NR] = $0}
1978 /cannot open output file/{fails[NR] = $0}
1979 END{
1980 for (x in fails)
1981 print fails[x]
1982 exit x!=0
1983 }'
1984 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
1985 done
1986 statusmsg "Rump build&link tests successful"
1987 }
1988
1989 main()
1990 {
1991 initdefaults
1992 _args=$@
1993 parseoptions "$@"
1994
1995 sanitycheck
1996
1997 build_start=$(date)
1998 statusmsg2 "${progname} command:" "$0 $*"
1999 statusmsg2 "${progname} started:" "${build_start}"
2000 statusmsg2 "NetBSD version:" "${DISTRIBVER}"
2001 statusmsg2 "MACHINE:" "${MACHINE}"
2002 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
2003 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
2004 statusmsg2 "HOST_SH:" "${HOST_SH}"
2005
2006 rebuildmake
2007 validatemakeparams
2008 createmakewrapper
2009
2010 # Perform the operations.
2011 #
2012 for op in ${operations}; do
2013 case "${op}" in
2014
2015 makewrapper)
2016 # no-op
2017 ;;
2018
2019 tools)
2020 buildtools
2021 ;;
2022
2023 sets)
2024 statusmsg "Building sets from pre-populated ${DESTDIR}"
2025 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2026 bomb "Failed to make ${op}"
2027 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
2028 statusmsg "Built sets to ${setdir}"
2029 ;;
2030
2031 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params)
2032 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2033 bomb "Failed to make ${op}"
2034 statusmsg "Successful make ${op}"
2035 ;;
2036
2037 iso-image|iso-image-source)
2038 ${runcmd} "${makewrapper}" ${parallel} \
2039 CDEXTRA="$CDEXTRA" ${op} ||
2040 bomb "Failed to make ${op}"
2041 statusmsg "Successful make ${op}"
2042 ;;
2043
2044 live-image|install-image)
2045 # install-image and live-image require mtree spec files
2046 # built with UNPRIVED. Assume UNPRIVED build has been
2047 # performed if METALOG file is created in DESTDIR.
2048 if [ ! -e "${DESTDIR}/METALOG" ] ; then
2049 bomb "The release binaries must have been built with -U to create images."
2050 fi
2051 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2052 bomb "Failed to make ${op}"
2053 statusmsg "Successful make ${op}"
2054 ;;
2055 kernel=*)
2056 arg=${op#*=}
2057 buildkernel "${arg}"
2058 ;;
2059
2060 releasekernel=*)
2061 arg=${op#*=}
2062 releasekernel "${arg}"
2063 ;;
2064
2065 modules)
2066 buildmodules
2067 ;;
2068
2069 installmodules=*)
2070 arg=${op#*=}
2071 if [ "${arg}" = "/" ] && \
2072 ( [ "${uname_s}" != "NetBSD" ] || \
2073 [ "${uname_m}" != "${MACHINE}" ] ); then
2074 bomb "'${op}' must != / for cross builds."
2075 fi
2076 installmodules "${arg}"
2077 ;;
2078
2079 install=*)
2080 arg=${op#*=}
2081 if [ "${arg}" = "/" ] && \
2082 ( [ "${uname_s}" != "NetBSD" ] || \
2083 [ "${uname_m}" != "${MACHINE}" ] ); then
2084 bomb "'${op}' must != / for cross builds."
2085 fi
2086 installworld "${arg}"
2087 ;;
2088
2089 rump|rumptest)
2090 dorump "${op}"
2091 ;;
2092
2093 *)
2094 bomb "Unknown operation \`${op}'"
2095 ;;
2096
2097 esac
2098 done
2099
2100 statusmsg2 "${progname} ended:" "$(date)"
2101 if [ -s "${results}" ]; then
2102 echo "===> Summary of results:"
2103 sed -e 's/^===>//;s/^/ /' "${results}"
2104 echo "===> ."
2105 fi
2106 }
2107
2108 main "$@"
2109