build.sh revision 1.259 1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.259 2012/11/15 23:51:53 joerg 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 # If the PATH contains any non-absolute components (including,
1257 # but not limited to, "." or ""), then complain. As an exception,
1258 # allow "" or "." as the last component of the PATH. This is fatal
1259 # if expert mode is not in effect.
1260 #
1261 local path="${PATH}"
1262 path="${path%:}" # delete trailing ":"
1263 path="${path%:.}" # delete trailing ":."
1264 case ":${path}:/" in
1265 *:[!/]*)
1266 if ${do_expertmode}; then
1267 warning "PATH contains non-absolute components"
1268 else
1269 bomb "PATH environment variable must not" \
1270 "contain non-absolute components"
1271 fi
1272 ;;
1273 esac
1274 }
1275
1276 # print_tooldir_make --
1277 # Try to find and print a path to an existing
1278 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1279 # new version of ${toolprefix}make has been built.
1280 #
1281 # * If TOOLDIR was set in the environment or on the command line, use
1282 # that value.
1283 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1284 # /etc/mk.conf, and check whether the resulting directory contains
1285 # a copy of ${toolprefix}make (this should work for everybody who
1286 # doesn't override TOOLDIR via /etc/mk.conf);
1287 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1288 # in the PATH (this might accidentally find a version of make that
1289 # does not understand the syntax used by NetBSD make, and that will
1290 # lead to failure in the next step);
1291 # * If a copy of make was found above, try to use it with
1292 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1293 # result only if it's a directory that already exists;
1294 # * If a value of TOOLDIR was found above, and if
1295 # ${TOOLDIR}/bin/${toolprefix}make exists, print that value.
1296 #
1297 print_tooldir_make()
1298 {
1299 local possible_TOP_OBJ
1300 local possible_TOOLDIR
1301 local possible_make
1302 local tooldir_make
1303
1304 if [ -n "${TOOLDIR}" ]; then
1305 echo "${TOOLDIR}/bin/${toolprefix}make"
1306 return 0
1307 fi
1308
1309 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1310 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1311 #
1312 local host_ostype="${uname_s}-$(
1313 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1314 )-$(
1315 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1316 )"
1317
1318 # Look in a few potential locations for
1319 # ${possible_TOOLDIR}/bin/${toolprefix}make.
1320 # If we find it, then set possible_make.
1321 #
1322 # In the usual case (without interference from environment
1323 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1324 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1325 #
1326 # In practice it's difficult to figure out the correct value
1327 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1328 # options were passed to build.sh, then ${TOP_objdir} will be
1329 # the correct value. We also try a few other possibilities, but
1330 # we do not replicate all the logic of <bsd.obj.mk>.
1331 #
1332 for possible_TOP_OBJ in \
1333 "${TOP_objdir}" \
1334 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1335 "${TOP}" \
1336 "${TOP}/obj" \
1337 "${TOP}/obj.${MACHINE}"
1338 do
1339 [ -n "${possible_TOP_OBJ}" ] || continue
1340 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1341 possible_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1342 if [ -x "${possible_make}" ]; then
1343 break
1344 else
1345 unset possible_make
1346 fi
1347 done
1348
1349 # If the above didn't work, search the PATH for a suitable
1350 # ${toolprefix}make, nbmake, bmake, or make.
1351 #
1352 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1353 : ${possible_make:=$(find_in_PATH nbmake '')}
1354 : ${possible_make:=$(find_in_PATH bmake '')}
1355 : ${possible_make:=$(find_in_PATH make '')}
1356
1357 # At this point, we don't care whether possible_make is in the
1358 # correct TOOLDIR or not; we simply want it to be usable by
1359 # getmakevar to help us find the correct TOOLDIR.
1360 #
1361 # Use ${possible_make} with nobomb_getmakevar to try to find
1362 # the value of TOOLDIR. Believe the result only if it's
1363 # a directory that already exists and contains bin/${toolprefix}make.
1364 #
1365 if [ -x "${possible_make}" ]; then
1366 possible_TOOLDIR="$(
1367 make="${possible_make}" \
1368 nobomb_getmakevar TOOLDIR 2>/dev/null
1369 )"
1370 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1371 && [ -d "${possible_TOOLDIR}" ];
1372 then
1373 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1374 if [ -x "${tooldir_make}" ]; then
1375 echo "${tooldir_make}"
1376 return 0
1377 fi
1378 fi
1379 fi
1380 return 1
1381 }
1382
1383 # rebuildmake --
1384 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1385 # to a path to the nbmake executable. Sets done_rebuildmake=true
1386 # if nbmake was rebuilt.
1387 #
1388 # There is a cyclic dependency between building nbmake and choosing
1389 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1390 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1391 # use getmakevar before we have an up to date version of nbmake; we
1392 # might already have an up to date version of nbmake in TOOLDIR, but we
1393 # don't yet know where TOOLDIR is.
1394 #
1395 # The default value of TOOLDIR also depends on the location of the top
1396 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1397 # after making the top level object directory may produce different
1398 # results.
1399 #
1400 # Strictly speaking, we should do the following:
1401 #
1402 # 1. build a new version of nbmake in a temporary directory;
1403 # 2. use the temporary nbmake to create the top level obj directory;
1404 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1405 # get the corect value of TOOLDIR;
1406 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1407 #
1408 # However, people don't like building nbmake unnecessarily if their
1409 # TOOLDIR has not changed since an earlier build. We try to avoid
1410 # rebuilding a temporary version of nbmake by taking some shortcuts to
1411 # guess a value for TOOLDIR, looking for an existing version of nbmake
1412 # in that TOOLDIR, and checking whether that nbmake is newer than the
1413 # sources used to build it.
1414 #
1415 rebuildmake()
1416 {
1417 make="$(print_tooldir_make)"
1418 if [ -n "${make}" ] && [ -x "${make}" ]; then
1419 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1420 if [ "${f}" -nt "${make}" ]; then
1421 statusmsg "${make} outdated" \
1422 "(older than ${f}), needs building."
1423 do_rebuildmake=true
1424 break
1425 fi
1426 done
1427 else
1428 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1429 do_rebuildmake=true
1430 fi
1431
1432 # Build bootstrap ${toolprefix}make if needed.
1433 if ${do_rebuildmake}; then
1434 statusmsg "Bootstrapping ${toolprefix}make"
1435 ${runcmd} cd "${tmpdir}"
1436 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1437 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1438 ${HOST_SH} "${TOP}/tools/make/configure" ||
1439 bomb "Configure of ${toolprefix}make failed"
1440 ${runcmd} ${HOST_SH} buildmake.sh ||
1441 bomb "Build of ${toolprefix}make failed"
1442 make="${tmpdir}/${toolprefix}make"
1443 ${runcmd} cd "${TOP}"
1444 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1445 done_rebuildmake=true
1446 fi
1447 }
1448
1449 # validatemakeparams --
1450 # Perform some late sanity checks, after rebuildmake,
1451 # but before createmakewrapper or any real work.
1452 #
1453 # Creates the top-level obj directory, because that
1454 # is needed by some of the sanity checks.
1455 #
1456 # Prints status messages reporting the values of several variables.
1457 #
1458 validatemakeparams()
1459 {
1460 # MAKECONF (which defaults to /etc/mk.conf in share/mk/bsd.own.mk)
1461 # can affect many things, so mention it in an early status message.
1462 #
1463 MAKECONF=$(getmakevar MAKECONF)
1464 if [ -e "${MAKECONF}" ]; then
1465 statusmsg2 "MAKECONF file:" "${MAKECONF}"
1466 else
1467 statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)"
1468 fi
1469
1470 if [ "${runcmd}" = "echo" ]; then
1471 TOOLCHAIN_MISSING=no
1472 EXTERNAL_TOOLCHAIN=""
1473 else
1474 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1475 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1476 fi
1477 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1478 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1479 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1480 ${runcmd} echo " MACHINE: ${MACHINE}"
1481 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1482 ${runcmd} echo ""
1483 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1484 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1485 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1486 ${runcmd} echo "in either the environment or mk.conf and rerun"
1487 ${runcmd} echo " ${progname} $*"
1488 exit 1
1489 fi
1490
1491 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1492 # These may be set as build.sh options or in "mk.conf".
1493 # Don't export them as they're only used for tests in build.sh.
1494 #
1495 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1496 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1497 MKUPDATE=$(getmakevar MKUPDATE)
1498
1499 if [ "${MKOBJDIRS}" != "no" ]; then
1500 # Create the top-level object directory.
1501 #
1502 # "make obj NOSUBDIR=" can handle most cases, but it
1503 # can't handle the case where MAKEOBJDIRPREFIX is set
1504 # while the corresponding directory does not exist
1505 # (rules in <bsd.obj.mk> would abort the build). We
1506 # therefore have to handle the MAKEOBJDIRPREFIX case
1507 # without invoking "make obj". The MAKEOBJDIR case
1508 # could be handled either way, but we choose to handle
1509 # it similarly to MAKEOBJDIRPREFIX.
1510 #
1511 if [ -n "${TOP_obj}" ]; then
1512 # It must have been set by the "-M" or "-O"
1513 # command line options, so there's no need to
1514 # use getmakevar
1515 :
1516 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1517 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1518 elif [ -n "$MAKEOBJDIR" ]; then
1519 TOP_obj="$(getmakevar MAKEOBJDIR)"
1520 fi
1521 if [ -n "$TOP_obj" ]; then
1522 ${runcmd} mkdir -p "${TOP_obj}" ||
1523 bomb "Can't create top level object directory" \
1524 "${TOP_obj}"
1525 else
1526 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1527 bomb "Can't create top level object directory" \
1528 "using make obj"
1529 fi
1530
1531 # make obj in tools to ensure that the objdir for "tools"
1532 # is available.
1533 #
1534 ${runcmd} cd tools
1535 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1536 bomb "Failed to make obj in tools"
1537 ${runcmd} cd "${TOP}"
1538 fi
1539
1540 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1541 # and bomb if they have changed from the values we had from the
1542 # command line or environment.
1543 #
1544 # This must be done after creating the top-level object directory.
1545 #
1546 for var in TOOLDIR DESTDIR RELEASEDIR
1547 do
1548 eval oldval=\"\$${var}\"
1549 newval="$(getmakevar $var)"
1550 if ! $do_expertmode; then
1551 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1552 case "$var" in
1553 DESTDIR)
1554 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1555 makeenv="${makeenv} DESTDIR"
1556 ;;
1557 RELEASEDIR)
1558 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1559 makeenv="${makeenv} RELEASEDIR"
1560 ;;
1561 esac
1562 fi
1563 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1564 bomb "Value of ${var} has changed" \
1565 "(was \"${oldval}\", now \"${newval}\")"
1566 fi
1567 eval ${var}=\"\${newval}\"
1568 eval export ${var}
1569 statusmsg2 "${var} path:" "${newval}"
1570 done
1571
1572 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1573 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1574
1575 # Check validity of TOOLDIR and DESTDIR.
1576 #
1577 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1578 bomb "TOOLDIR '${TOOLDIR}' invalid"
1579 fi
1580 removedirs="${TOOLDIR}"
1581
1582 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1583 if ${do_build} || ${do_distribution} || ${do_release}; then
1584 if ! ${do_build} || \
1585 [ "${uname_s}" != "NetBSD" ] || \
1586 [ "${uname_m}" != "${MACHINE}" ]; then
1587 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1588 fi
1589 if ! ${do_expertmode}; then
1590 bomb "DESTDIR must != / for non -E (expert) builds"
1591 fi
1592 statusmsg "WARNING: Building to /, in expert mode."
1593 statusmsg " This may cause your system to break! Reasons include:"
1594 statusmsg " - your kernel is not up to date"
1595 statusmsg " - the libraries or toolchain have changed"
1596 statusmsg " YOU HAVE BEEN WARNED!"
1597 fi
1598 else
1599 removedirs="${removedirs} ${DESTDIR}"
1600 fi
1601 if ${do_build} || ${do_distribution} || ${do_release}; then
1602 if ! ${do_expertmode} && \
1603 [ "$id_u" -ne 0 ] && \
1604 [ "${MKUNPRIVED}" = "no" ] ; then
1605 bomb "-U or -E must be set for build as an unprivileged user."
1606 fi
1607 fi
1608 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1609 bomb "Must set RELEASEDIR with \`releasekernel=...'"
1610 fi
1611
1612 # Install as non-root is a bad idea.
1613 #
1614 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1615 if ${do_expertmode}; then
1616 warning "Will install as an unprivileged user."
1617 else
1618 bomb "-E must be set for install as an unprivileged user."
1619 fi
1620 fi
1621
1622 # If a previous build.sh run used -U (and therefore created a
1623 # METALOG file), then most subsequent build.sh runs must also
1624 # use -U. If DESTDIR is about to be removed, then don't perform
1625 # this check.
1626 #
1627 case "${do_removedirs} ${removedirs} " in
1628 true*" ${DESTDIR} "*)
1629 # DESTDIR is about to be removed
1630 ;;
1631 *)
1632 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1633 ${do_install} ) && \
1634 [ -e "${DESTDIR}/METALOG" ] && \
1635 [ "${MKUNPRIVED}" = "no" ] ; then
1636 if $do_expertmode; then
1637 warning "A previous build.sh run specified -U."
1638 else
1639 bomb "A previous build.sh run specified -U; you must specify it again now."
1640 fi
1641 fi
1642 ;;
1643 esac
1644
1645 # live-image and install-image targets require binary sets
1646 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
1647 # If release operation is specified with live-image or install-image,
1648 # the release op should be performed with -U for later image ops.
1649 #
1650 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
1651 [ "${MKUNPRIVED}" = "no" ] ; then
1652 bomb "-U must be specified on building release to create images later."
1653 fi
1654 }
1655
1656
1657 createmakewrapper()
1658 {
1659 # Remove the target directories.
1660 #
1661 if ${do_removedirs}; then
1662 for f in ${removedirs}; do
1663 statusmsg "Removing ${f}"
1664 ${runcmd} rm -r -f "${f}"
1665 done
1666 fi
1667
1668 # Recreate $TOOLDIR.
1669 #
1670 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
1671 bomb "mkdir of '${TOOLDIR}/bin' failed"
1672
1673 # If we did not previously rebuild ${toolprefix}make, then
1674 # check whether $make is still valid and the same as the output
1675 # from print_tooldir_make. If not, then rebuild make now. A
1676 # possible reason for this being necessary is that the actual
1677 # value of TOOLDIR might be different from the value guessed
1678 # before the top level obj dir was created.
1679 #
1680 if ! ${done_rebuildmake} && \
1681 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
1682 then
1683 rebuildmake
1684 fi
1685
1686 # Install ${toolprefix}make if it was built.
1687 #
1688 if ${done_rebuildmake}; then
1689 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1690 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1691 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
1692 make="${TOOLDIR}/bin/${toolprefix}make"
1693 statusmsg "Created ${make}"
1694 fi
1695
1696 # Build a ${toolprefix}make wrapper script, usable by hand as
1697 # well as by build.sh.
1698 #
1699 if [ -z "${makewrapper}" ]; then
1700 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1701 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1702 fi
1703
1704 ${runcmd} rm -f "${makewrapper}"
1705 if [ "${runcmd}" = "echo" ]; then
1706 echo 'cat <<EOF >'${makewrapper}
1707 makewrapout=
1708 else
1709 makewrapout=">>\${makewrapper}"
1710 fi
1711
1712 case "${KSH_VERSION:-${SH_VERSION}}" in
1713 *PD\ KSH*|*MIRBSD\ KSH*)
1714 set +o braceexpand
1715 ;;
1716 esac
1717
1718 eval cat <<EOF ${makewrapout}
1719 #! ${HOST_SH}
1720 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1721 # Generated from: \$NetBSD: build.sh,v 1.259 2012/11/15 23:51:53 joerg Exp $
1722 # with these arguments: ${_args}
1723 #
1724
1725 EOF
1726 {
1727 for f in ${makeenv}; do
1728 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1729 eval echo "unset ${f}"
1730 else
1731 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1732 fi
1733 done
1734
1735 eval cat <<EOF
1736 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1737 USETOOLS=yes; export USETOOLS
1738 EOF
1739 } | eval sort -u "${makewrapout}"
1740 eval cat <<EOF "${makewrapout}"
1741
1742 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1743 EOF
1744 [ "${runcmd}" = "echo" ] && echo EOF
1745 ${runcmd} chmod +x "${makewrapper}"
1746 statusmsg2 "Updated makewrapper:" "${makewrapper}"
1747 }
1748
1749 make_in_dir()
1750 {
1751 dir="$1"
1752 op="$2"
1753 ${runcmd} cd "${dir}" ||
1754 bomb "Failed to cd to \"${dir}\""
1755 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1756 bomb "Failed to make ${op} in \"${dir}\""
1757 ${runcmd} cd "${TOP}" ||
1758 bomb "Failed to cd back to \"${TOP}\""
1759 }
1760
1761 buildtools()
1762 {
1763 if [ "${MKOBJDIRS}" != "no" ]; then
1764 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1765 bomb "Failed to make obj-tools"
1766 fi
1767 if [ "${MKUPDATE}" = "no" ]; then
1768 make_in_dir tools cleandir
1769 fi
1770 make_in_dir tools build_install
1771 statusmsg "Tools built to ${TOOLDIR}"
1772 }
1773
1774 getkernelconf()
1775 {
1776 kernelconf="$1"
1777 if [ "${MKOBJDIRS}" != "no" ]; then
1778 # The correct value of KERNOBJDIR might
1779 # depend on a prior "make obj" in
1780 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1781 #
1782 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
1783 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
1784 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1785 fi
1786 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
1787 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1788 case "${kernelconf}" in
1789 */*)
1790 kernelconfpath="${kernelconf}"
1791 kernelconfname="${kernelconf##*/}"
1792 ;;
1793 *)
1794 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
1795 kernelconfname="${kernelconf}"
1796 ;;
1797 esac
1798 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
1799 }
1800
1801 buildkernel()
1802 {
1803 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1804 # Building tools every time we build a kernel is clearly
1805 # unnecessary. We could try to figure out whether rebuilding
1806 # the tools is necessary this time, but it doesn't seem worth
1807 # the trouble. Instead, we say it's the user's responsibility
1808 # to rebuild the tools if necessary.
1809 #
1810 statusmsg "Building kernel without building new tools"
1811 buildkernelwarned=true
1812 fi
1813 getkernelconf $1
1814 statusmsg2 "Building kernel:" "${kernelconf}"
1815 statusmsg2 "Build directory:" "${kernelbuildpath}"
1816 ${runcmd} mkdir -p "${kernelbuildpath}" ||
1817 bomb "Cannot mkdir: ${kernelbuildpath}"
1818 if [ "${MKUPDATE}" = "no" ]; then
1819 make_in_dir "${kernelbuildpath}" cleandir
1820 fi
1821 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1822 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1823 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1824 -s "${TOP}/sys" "${kernelconfpath}" ||
1825 bomb "${toolprefix}config failed for ${kernelconf}"
1826 make_in_dir "${kernelbuildpath}" depend
1827 make_in_dir "${kernelbuildpath}" all
1828
1829 if [ "${runcmd}" != "echo" ]; then
1830 statusmsg "Kernels built from ${kernelconf}:"
1831 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1832 for kern in ${kernlist:-netbsd}; do
1833 [ -f "${kernelbuildpath}/${kern}" ] && \
1834 echo " ${kernelbuildpath}/${kern}"
1835 done | tee -a "${results}"
1836 fi
1837 }
1838
1839 releasekernel()
1840 {
1841 getkernelconf $1
1842 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1843 ${runcmd} mkdir -p "${kernelreldir}"
1844 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1845 for kern in ${kernlist:-netbsd}; do
1846 builtkern="${kernelbuildpath}/${kern}"
1847 [ -f "${builtkern}" ] || continue
1848 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
1849 statusmsg2 "Kernel copy:" "${releasekern}"
1850 if [ "${runcmd}" = "echo" ]; then
1851 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1852 else
1853 gzip -c -9 < "${builtkern}" > "${releasekern}"
1854 fi
1855 done
1856 }
1857
1858 buildmodules()
1859 {
1860 setmakeenv MKBINUTILS no
1861 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
1862 # Building tools every time we build modules is clearly
1863 # unnecessary as well as a kernel.
1864 #
1865 statusmsg "Building modules without building new tools"
1866 buildmoduleswarned=true
1867 fi
1868
1869 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1870 if [ "${MKOBJDIRS}" != "no" ]; then
1871 make_in_dir sys/modules obj
1872 fi
1873 if [ "${MKUPDATE}" = "no" ]; then
1874 make_in_dir sys/modules cleandir
1875 fi
1876 make_in_dir sys/modules dependall
1877 make_in_dir sys/modules install
1878
1879 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
1880 }
1881
1882 installmodules()
1883 {
1884 dir="$1"
1885 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
1886 bomb "Failed to make installmodules to ${dir}"
1887 statusmsg "Successful installmodules to ${dir}"
1888 }
1889
1890 installworld()
1891 {
1892 dir="$1"
1893 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1894 bomb "Failed to make installworld to ${dir}"
1895 statusmsg "Successful installworld to ${dir}"
1896 }
1897
1898 # Run rump build&link tests.
1899 #
1900 # To make this feasible for running without having to install includes and
1901 # libraries into destdir (i.e. quick), we only run ld. This is possible
1902 # since the rump kernel is a closed namespace apart from calls to rumpuser.
1903 # Therefore, if ld complains only about rumpuser symbols, rump kernel
1904 # linking was successful.
1905 #
1906 # We test that rump links with a number of component configurations.
1907 # These attempt to mimic what is encountered in the full build.
1908 # See list below. The list should probably be either autogenerated
1909 # or managed elsewhere; keep it here until a better idea arises.
1910 #
1911 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
1912 #
1913
1914 RUMP_LIBSETS='
1915 -lrump,
1916 -lrumpvfs -lrump,
1917 -lrumpvfs -lrumpdev -lrump,
1918 -lrumpnet -lrump,
1919 -lrumpkern_tty -lrumpvfs -lrump,
1920 -lrumpfs_tmpfs -lrumpvfs -lrump,
1921 -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump,
1922 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump,
1923 -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb
1924 -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump,
1925 -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump,
1926 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd
1927 -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump'
1928 dorump()
1929 {
1930 local doclean=""
1931 local doobjs=""
1932
1933 # we cannot link libs without building csu, and that leads to lossage
1934 [ "${1}" != "rumptest" ] && bomb 'build.sh rump not yet functional. ' \
1935 'did you mean "rumptest"?'
1936
1937 # create obj and distrib dirs
1938 if [ "${MKOBJDIRS}" != "no" ]; then
1939 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
1940 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
1941 fi
1942 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
1943 || bomb 'could not create distrib-dirs'
1944
1945 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
1946 targlist="${doclean} ${doobjs} dependall install"
1947 # optimize: for test we build only static libs (3x test speedup)
1948 if [ "${1}" = "rumptest" ] ; then
1949 setmakeenv NOPIC 1
1950 setmakeenv NOPROFILE 1
1951 fi
1952 for cmd in ${targlist} ; do
1953 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
1954 done
1955
1956 # if we just wanted to build & install rump, we're done
1957 [ "${1}" != "rumptest" ] && return
1958
1959 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
1960 || bomb "cd to rumpkern failed"
1961 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
1962 # one little, two little, three little backslashes ...
1963 md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )"
1964 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
1965 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
1966
1967 local oIFS="${IFS}"
1968 IFS=","
1969 for set in ${RUMP_LIBSETS} ; do
1970 IFS="${oIFS}"
1971 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
1972 -static --whole-archive ${set} 2>&1 -o /tmp/rumptest.$$ | \
1973 awk -v quirks="${md_quirks}" '
1974 /undefined reference/ &&
1975 !/more undefined references.*follow/{
1976 if (match($NF,
1977 "`(rumpuser_|__" quirks ")") == 0)
1978 fails[NR] = $0
1979 }
1980 /cannot find -l/{fails[NR] = $0}
1981 /cannot open output file/{fails[NR] = $0}
1982 END{
1983 for (x in fails)
1984 print fails[x]
1985 exit x!=0
1986 }'
1987 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
1988 done
1989 statusmsg "Rump build&link tests successful"
1990 }
1991
1992 main()
1993 {
1994 initdefaults
1995 _args=$@
1996 parseoptions "$@"
1997
1998 sanitycheck
1999
2000 build_start=$(date)
2001 statusmsg2 "${progname} command:" "$0 $*"
2002 statusmsg2 "${progname} started:" "${build_start}"
2003 statusmsg2 "NetBSD version:" "${DISTRIBVER}"
2004 statusmsg2 "MACHINE:" "${MACHINE}"
2005 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
2006 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
2007 statusmsg2 "HOST_SH:" "${HOST_SH}"
2008
2009 rebuildmake
2010 validatemakeparams
2011 createmakewrapper
2012
2013 # Perform the operations.
2014 #
2015 for op in ${operations}; do
2016 case "${op}" in
2017
2018 makewrapper)
2019 # no-op
2020 ;;
2021
2022 tools)
2023 buildtools
2024 ;;
2025
2026 sets)
2027 statusmsg "Building sets from pre-populated ${DESTDIR}"
2028 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2029 bomb "Failed to make ${op}"
2030 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
2031 statusmsg "Built sets to ${setdir}"
2032 ;;
2033
2034 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params)
2035 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2036 bomb "Failed to make ${op}"
2037 statusmsg "Successful make ${op}"
2038 ;;
2039
2040 iso-image|iso-image-source)
2041 ${runcmd} "${makewrapper}" ${parallel} \
2042 CDEXTRA="$CDEXTRA" ${op} ||
2043 bomb "Failed to make ${op}"
2044 statusmsg "Successful make ${op}"
2045 ;;
2046
2047 live-image|install-image)
2048 # install-image and live-image require mtree spec files
2049 # built with UNPRIVED. Assume UNPRIVED build has been
2050 # performed if METALOG file is created in DESTDIR.
2051 if [ ! -e "${DESTDIR}/METALOG" ] ; then
2052 bomb "The release binaries must have been built with -U to create images."
2053 fi
2054 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2055 bomb "Failed to make ${op}"
2056 statusmsg "Successful make ${op}"
2057 ;;
2058 kernel=*)
2059 arg=${op#*=}
2060 buildkernel "${arg}"
2061 ;;
2062
2063 releasekernel=*)
2064 arg=${op#*=}
2065 releasekernel "${arg}"
2066 ;;
2067
2068 modules)
2069 buildmodules
2070 ;;
2071
2072 installmodules=*)
2073 arg=${op#*=}
2074 if [ "${arg}" = "/" ] && \
2075 ( [ "${uname_s}" != "NetBSD" ] || \
2076 [ "${uname_m}" != "${MACHINE}" ] ); then
2077 bomb "'${op}' must != / for cross builds."
2078 fi
2079 installmodules "${arg}"
2080 ;;
2081
2082 install=*)
2083 arg=${op#*=}
2084 if [ "${arg}" = "/" ] && \
2085 ( [ "${uname_s}" != "NetBSD" ] || \
2086 [ "${uname_m}" != "${MACHINE}" ] ); then
2087 bomb "'${op}' must != / for cross builds."
2088 fi
2089 installworld "${arg}"
2090 ;;
2091
2092 rump|rumptest)
2093 dorump "${op}"
2094 ;;
2095
2096 *)
2097 bomb "Unknown operation \`${op}'"
2098 ;;
2099
2100 esac
2101 done
2102
2103 statusmsg2 "${progname} ended:" "$(date)"
2104 if [ -s "${results}" ]; then
2105 echo "===> Summary of results:"
2106 sed -e 's/^===>//;s/^/ /' "${results}"
2107 echo "===> ."
2108 fi
2109 }
2110
2111 main "$@"
2112