build.sh revision 1.385 1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.385 2024/12/20 15:56:45 riastradh Exp $
3 #
4 # Copyright (c) 2001-2023 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 show 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 dash bash
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
276 *** BUILD ABORTED ***
277 ERRORMESSAGE
278 kill ${toppid} # in case we were invoked from a subshell
279 exit 1
280 }
281
282 # Quote args to make them safe in the shell.
283 # Usage: quotedlist="$(shell_quote args...)"
284 #
285 # After building up a quoted list, use it by evaling it inside
286 # double quotes, like this:
287 # eval "set -- $quotedlist"
288 # or like this:
289 # eval "\$command $quotedlist \$filename"
290 #
291 shell_quote()
292 {(
293 local result=''
294 local arg qarg
295 LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
296 for arg in "$@" ; do
297 case "${arg}" in
298 '')
299 qarg="''"
300 ;;
301 *[!-./a-zA-Z0-9]*)
302 # Convert each embedded ' to '\'',
303 # then insert ' at the beginning of the first line,
304 # and append ' at the end of the last line.
305 # Finally, elide unnecessary '' pairs at the
306 # beginning and end of the result and as part of
307 # '\'''\'' sequences that result from multiple
308 # adjacent quotes in he input.
309 qarg="$(printf "%s\n" "$arg" | \
310 ${SED:-sed} -e "s/'/'\\\\''/g" \
311 -e "1s/^/'/" -e "\$s/\$/'/" \
312 -e "1s/^''//" -e "\$s/''\$//" \
313 -e "s/'''/'/g"
314 )"
315 ;;
316 *)
317 # Arg is not the empty string, and does not contain
318 # any unsafe characters. Leave it unchanged for
319 # readability.
320 qarg="${arg}"
321 ;;
322 esac
323 result="${result}${result:+ }${qarg}"
324 done
325 printf "%s\n" "$result"
326 )}
327
328 statusmsg()
329 {
330 ${runcmd} echo "===> $@" | tee -a "${results}"
331 }
332
333 statusmsg2()
334 {
335 local msg
336
337 msg="${1}"
338 shift
339 case "${msg}" in
340 ????????????????*) ;;
341 ??????????*) msg="${msg} ";;
342 ?????*) msg="${msg} ";;
343 *) msg="${msg} ";;
344 esac
345 case "${msg}" in
346 ?????????????????????*) ;;
347 ????????????????????) msg="${msg} ";;
348 ???????????????????) msg="${msg} ";;
349 ??????????????????) msg="${msg} ";;
350 ?????????????????) msg="${msg} ";;
351 ????????????????) msg="${msg} ";;
352 esac
353 statusmsg "${msg}$*"
354 }
355
356 warning()
357 {
358 statusmsg "Warning: $@"
359 }
360
361 # Find a program in the PATH, and show the result. If not found,
362 # show a default. If $2 is defined (even if it is an empty string),
363 # then that is the default; otherwise, $1 is used as the default.
364 #
365 find_in_PATH()
366 {
367 local prog="$1"
368 local result="${2-"$1"}"
369 local oldIFS="${IFS}"
370 local dir
371 IFS=":"
372 for dir in ${PATH}; do
373 if [ -x "${dir}/${prog}" ]; then
374 result="${dir}/${prog}"
375 break
376 fi
377 done
378 IFS="${oldIFS}"
379 echo "${result}"
380 }
381
382 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
383 # Assumes that uname_s, uname_m, and PWD have been set.
384 #
385 set_HOST_SH()
386 {
387 # Even if ${HOST_SH} is already defined, we still do the
388 # sanity checks at the end.
389
390 # Solaris has /usr/xpg4/bin/sh.
391 #
392 [ -z "${HOST_SH}" ] && [ x"${uname_s}" = x"SunOS" ] && \
393 [ -x /usr/xpg4/bin/sh ] && HOST_SH="/usr/xpg4/bin/sh"
394
395 # Try to get the name of the shell that's running this script,
396 # by parsing the output from "ps". We assume that, if the host
397 # system's ps command supports -o comm at all, it will do so
398 # in the usual way: a one-line header followed by a one-line
399 # result, possibly including trailing white space. And if the
400 # host system's ps command doesn't support -o comm, we assume
401 # that we'll get an error message on stderr and nothing on
402 # stdout. (We don't try to use ps -o 'comm=' to suppress the
403 # header line, because that is less widely supported.)
404 #
405 # If we get the wrong result here, the user can override it by
406 # specifying HOST_SH in the environment.
407 #
408 [ -z "${HOST_SH}" ] && HOST_SH="$(
409 (ps -p $$ -o comm | sed -ne "2s/[ ${tab}]*\$//p") 2>/dev/null )"
410
411 # If nothing above worked, use "sh". We will later find the
412 # first directory in the PATH that has a "sh" program.
413 #
414 [ -z "${HOST_SH}" ] && HOST_SH="sh"
415
416 # If the result so far is not an absolute path, try to prepend
417 # PWD or search the PATH.
418 #
419 case "${HOST_SH}" in
420 /*) :
421 ;;
422 */*) HOST_SH="${PWD}/${HOST_SH}"
423 ;;
424 *) HOST_SH="$(find_in_PATH "${HOST_SH}")"
425 ;;
426 esac
427
428 # If we don't have an absolute path by now, bomb.
429 #
430 case "${HOST_SH}" in
431 /*) :
432 ;;
433 *) bomb "HOST_SH=\"${HOST_SH}\" is not an absolute path"
434 ;;
435 esac
436
437 # If HOST_SH is not executable, bomb.
438 #
439 [ -x "${HOST_SH}" ] ||
440 bomb "HOST_SH=\"${HOST_SH}\" is not executable"
441
442 # If HOST_SH fails tests, bomb.
443 # ("$0" may be a path that is no longer valid, because we have
444 # performed "cd $(dirname $0)", so don't use $0 here.)
445 #
446 "${HOST_SH}" build.sh --shelltest ||
447 bomb "HOST_SH=\"${HOST_SH}\" failed functionality tests"
448 }
449
450 # initdefaults --
451 # Set defaults before parsing command line options.
452 #
453 initdefaults()
454 {
455 makeenv=
456 makewrapper=
457 makewrappermachine=
458 runcmd=
459 operations=
460 removedirs=
461
462 [ -d usr.bin/make ] || cd "$(dirname $0)"
463 [ -d usr.bin/make ] ||
464 bomb "usr.bin/make not found; build.sh must be run from the top \
465 level of source directory"
466 [ -f share/mk/bsd.own.mk ] ||
467 bomb "src/share/mk is missing; please re-fetch the source tree"
468
469 # Set various environment variables to known defaults,
470 # to minimize (cross-)build problems observed "in the field".
471 #
472 # LC_ALL=C must be set before we try to parse the output from
473 # any command. Other variables are set (or unset) here, before
474 # we parse command line arguments.
475 #
476 # These variables can be overridden via "-V var=value" if
477 # you know what you are doing.
478 #
479 unsetmakeenv C_INCLUDE_PATH
480 unsetmakeenv CPLUS_INCLUDE_PATH
481 unsetmakeenv INFODIR
482 unsetmakeenv LESSCHARSET
483 unsetmakeenv MAKEFLAGS
484 unsetmakeenv TERMINFO
485 setmakeenv LC_ALL C
486
487 # Find information about the build platform. This should be
488 # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
489 # variables in share/mk/bsd.sys.mk.
490 #
491 # Note that "uname -p" is not part of POSIX, but we want uname_p
492 # to be set to the host MACHINE_ARCH, if possible. On systems
493 # where "uname -p" fails, shows "unknown", or shows a string
494 # that does not look like an identifier, fall back to using the
495 # output from "uname -m" instead.
496 #
497 uname_s=$(uname -s 2>/dev/null)
498 uname_r=$(uname -r 2>/dev/null)
499 uname_m=$(uname -m 2>/dev/null)
500 uname_p=$(uname -p 2>/dev/null || echo "unknown")
501 case "${uname_p}" in
502 ''|unknown|*[!-_A-Za-z0-9]*) uname_p="${uname_m}" ;;
503 esac
504
505 id_u=$(id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null)
506
507 # If $PWD is a valid name of the current directory, POSIX mandates
508 # that pwd return it by default which causes problems in the
509 # presence of symlinks. Unsetting PWD is simpler than changing
510 # every occurrence of pwd to use -P.
511 #
512 # XXX Except that doesn't work on Solaris. Or many Linuces.
513 #
514 unset PWD
515 TOP=$( (exec pwd -P 2>/dev/null) || (exec pwd 2>/dev/null) )
516
517 # The user can set HOST_SH in the environment, or we try to
518 # guess an appropriate value. Then we set several other
519 # variables from HOST_SH.
520 #
521 set_HOST_SH
522 setmakeenv HOST_SH "${HOST_SH}"
523 setmakeenv BSHELL "${HOST_SH}"
524 setmakeenv CONFIG_SHELL "${HOST_SH}"
525
526 # Set defaults.
527 #
528 toolprefix=nb
529
530 # Some systems have a small ARG_MAX. -X prevents make(1) from
531 # exporting variables in the environment redundantly.
532 #
533 case "${uname_s}" in
534 Darwin | FreeBSD | CYGWIN*)
535 MAKEFLAGS="-X ${MAKEFLAGS}"
536 ;;
537 esac
538
539 # do_{operation}=true if given operation is requested.
540 #
541 do_expertmode=false
542 do_rebuildmake=false
543 do_removedirs=false
544 do_tools=false
545 do_libs=false
546 do_cleandir=false
547 do_obj=false
548 do_build=false
549 do_distribution=false
550 do_release=false
551 do_kernel=false
552 do_releasekernel=false
553 do_kernels=false
554 do_modules=false
555 do_installmodules=false
556 do_install=false
557 do_sets=false
558 do_sourcesets=false
559 do_syspkgs=false
560 do_pkg=false
561 do_iso_image=false
562 do_iso_image_source=false
563 do_live_image=false
564 do_install_image=false
565 do_disk_image=false
566 do_params=false
567 do_show_params=false
568 do_rump=false
569 do_dtb=false
570
571 # done_{operation}=true if given operation has been done.
572 #
573 done_rebuildmake=false
574
575 # Create scratch directory
576 #
577 tmpdir="${TMPDIR-/tmp}/nbbuild$$"
578 mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
579 trap "cd /; rm -r -f \"${tmpdir}\"" 0
580 results="${tmpdir}/build.sh.results"
581
582 # Set source directories
583 #
584 setmakeenv NETBSDSRCDIR "${TOP}"
585
586 # Make sure KERNOBJDIR is an absolute path if defined
587 #
588 case "${KERNOBJDIR}" in
589 ''|/*) ;;
590 *) KERNOBJDIR="${TOP}/${KERNOBJDIR}"
591 setmakeenv KERNOBJDIR "${KERNOBJDIR}"
592 ;;
593 esac
594
595 # Find the version of NetBSD
596 #
597 DISTRIBVER="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
598
599 # Set the BUILDSEED to NetBSD-"N"
600 #
601 setmakeenv BUILDSEED "NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
602
603 # Set MKARZERO to "yes"
604 #
605 setmakeenv MKARZERO "yes"
606
607 }
608
609 # valid_MACHINE_ARCH -- A multi-line string, listing all valid
610 # MACHINE/MACHINE_ARCH pairs.
611 #
612 # Each line contains a MACHINE and MACHINE_ARCH value, an optional ALIAS
613 # which may be used to refer to the MACHINE/MACHINE_ARCH pair, and an
614 # optional DEFAULT or NO_DEFAULT keyword.
615 #
616 # When a MACHINE corresponds to multiple possible values of
617 # MACHINE_ARCH, then this table should list all allowed combinations.
618 # If the MACHINE is associated with a default MACHINE_ARCH (to be
619 # used when the user specifies the MACHINE but fails to specify the
620 # MACHINE_ARCH), then one of the lines should have the "DEFAULT"
621 # keyword. If there is no default MACHINE_ARCH for a particular
622 # MACHINE, then there should be a line with the "NO_DEFAULT" keyword,
623 # and with a blank MACHINE_ARCH.
624 #
625 valid_MACHINE_ARCH='
626 MACHINE=acorn32 MACHINE_ARCH=earmv4 ALIAS=eacorn32 DEFAULT
627 MACHINE=algor MACHINE_ARCH=mips64el ALIAS=algor64
628 MACHINE=algor MACHINE_ARCH=mipsel DEFAULT
629 MACHINE=alpha MACHINE_ARCH=alpha
630 MACHINE=amd64 MACHINE_ARCH=x86_64
631 MACHINE=amiga MACHINE_ARCH=m68k
632 MACHINE=amigappc MACHINE_ARCH=powerpc
633 MACHINE=arc MACHINE_ARCH=mips64el ALIAS=arc64
634 MACHINE=arc MACHINE_ARCH=mipsel DEFAULT
635 MACHINE=atari MACHINE_ARCH=m68k
636 MACHINE=bebox MACHINE_ARCH=powerpc
637 MACHINE=cats MACHINE_ARCH=earmv4 ALIAS=ecats DEFAULT
638 MACHINE=cesfic MACHINE_ARCH=m68k
639 MACHINE=cobalt MACHINE_ARCH=mips64el ALIAS=cobalt64
640 MACHINE=cobalt MACHINE_ARCH=mipsel DEFAULT
641 MACHINE=dreamcast MACHINE_ARCH=sh3el
642 MACHINE=emips MACHINE_ARCH=mipseb
643 MACHINE=epoc32 MACHINE_ARCH=earmv4 ALIAS=eepoc32 DEFAULT
644 MACHINE=evbarm MACHINE_ARCH= NO_DEFAULT
645 MACHINE=evbarm MACHINE_ARCH=earmv4 ALIAS=evbearmv4-el ALIAS=evbarmv4-el
646 MACHINE=evbarm MACHINE_ARCH=earmv4eb ALIAS=evbearmv4-eb ALIAS=evbarmv4-eb
647 MACHINE=evbarm MACHINE_ARCH=earmv5 ALIAS=evbearmv5-el ALIAS=evbarmv5-el
648 MACHINE=evbarm MACHINE_ARCH=earmv5hf ALIAS=evbearmv5hf-el ALIAS=evbarmv5hf-el
649 MACHINE=evbarm MACHINE_ARCH=earmv5eb ALIAS=evbearmv5-eb ALIAS=evbarmv5-eb
650 MACHINE=evbarm MACHINE_ARCH=earmv5hfeb ALIAS=evbearmv5hf-eb ALIAS=evbarmv5hf-eb
651 MACHINE=evbarm MACHINE_ARCH=earmv6 ALIAS=evbearmv6-el ALIAS=evbarmv6-el
652 MACHINE=evbarm MACHINE_ARCH=earmv6hf ALIAS=evbearmv6hf-el ALIAS=evbarmv6hf-el
653 MACHINE=evbarm MACHINE_ARCH=earmv6eb ALIAS=evbearmv6-eb ALIAS=evbarmv6-eb
654 MACHINE=evbarm MACHINE_ARCH=earmv6hfeb ALIAS=evbearmv6hf-eb ALIAS=evbarmv6hf-eb
655 MACHINE=evbarm MACHINE_ARCH=earmv7 ALIAS=evbearmv7-el ALIAS=evbarmv7-el
656 MACHINE=evbarm MACHINE_ARCH=earmv7eb ALIAS=evbearmv7-eb ALIAS=evbarmv7-eb
657 MACHINE=evbarm MACHINE_ARCH=earmv7hf ALIAS=evbearmv7hf-el ALIAS=evbarmv7hf-el
658 MACHINE=evbarm MACHINE_ARCH=earmv7hfeb ALIAS=evbearmv7hf-eb ALIAS=evbarmv7hf-eb
659 MACHINE=evbarm MACHINE_ARCH=aarch64 ALIAS=evbarm64-el ALIAS=evbarm64
660 MACHINE=evbarm MACHINE_ARCH=aarch64eb ALIAS=evbarm64-eb
661 MACHINE=evbcf MACHINE_ARCH=coldfire
662 MACHINE=evbmips MACHINE_ARCH= NO_DEFAULT
663 MACHINE=evbmips MACHINE_ARCH=mips64eb ALIAS=evbmips64-eb
664 MACHINE=evbmips MACHINE_ARCH=mips64el ALIAS=evbmips64-el
665 MACHINE=evbmips MACHINE_ARCH=mipseb ALIAS=evbmips-eb
666 MACHINE=evbmips MACHINE_ARCH=mipsel ALIAS=evbmips-el
667 MACHINE=evbmips MACHINE_ARCH=mipsn64eb ALIAS=evbmipsn64-eb
668 MACHINE=evbmips MACHINE_ARCH=mipsn64el ALIAS=evbmipsn64-el
669 MACHINE=evbppc MACHINE_ARCH=powerpc DEFAULT
670 MACHINE=evbppc MACHINE_ARCH=powerpc64 ALIAS=evbppc64
671 MACHINE=evbsh3 MACHINE_ARCH= NO_DEFAULT
672 MACHINE=evbsh3 MACHINE_ARCH=sh3eb ALIAS=evbsh3-eb
673 MACHINE=evbsh3 MACHINE_ARCH=sh3el ALIAS=evbsh3-el
674 MACHINE=ews4800mips MACHINE_ARCH=mipseb
675 MACHINE=hp300 MACHINE_ARCH=m68k
676 MACHINE=hppa MACHINE_ARCH=hppa
677 MACHINE=hpcarm MACHINE_ARCH=earmv4 ALIAS=hpcearm DEFAULT
678 MACHINE=hpcmips MACHINE_ARCH=mipsel
679 MACHINE=hpcsh MACHINE_ARCH=sh3el
680 MACHINE=i386 MACHINE_ARCH=i386
681 MACHINE=ia64 MACHINE_ARCH=ia64
682 MACHINE=ibmnws MACHINE_ARCH=powerpc
683 MACHINE=iyonix MACHINE_ARCH=earm ALIAS=eiyonix DEFAULT
684 MACHINE=landisk MACHINE_ARCH=sh3el
685 MACHINE=luna68k MACHINE_ARCH=m68k
686 MACHINE=mac68k MACHINE_ARCH=m68k
687 MACHINE=macppc MACHINE_ARCH=powerpc DEFAULT
688 MACHINE=macppc MACHINE_ARCH=powerpc64 ALIAS=macppc64
689 MACHINE=mipsco MACHINE_ARCH=mipseb
690 MACHINE=mmeye MACHINE_ARCH=sh3eb
691 MACHINE=mvme68k MACHINE_ARCH=m68k
692 MACHINE=mvmeppc MACHINE_ARCH=powerpc
693 MACHINE=netwinder MACHINE_ARCH=earmv4 ALIAS=enetwinder DEFAULT
694 MACHINE=news68k MACHINE_ARCH=m68k
695 MACHINE=newsmips MACHINE_ARCH=mipseb
696 MACHINE=next68k MACHINE_ARCH=m68k
697 MACHINE=ofppc MACHINE_ARCH=powerpc DEFAULT
698 MACHINE=ofppc MACHINE_ARCH=powerpc64 ALIAS=ofppc64
699 MACHINE=or1k MACHINE_ARCH=or1k
700 MACHINE=playstation2 MACHINE_ARCH=mipsel
701 MACHINE=pmax MACHINE_ARCH=mips64el ALIAS=pmax64
702 MACHINE=pmax MACHINE_ARCH=mipsel DEFAULT
703 MACHINE=prep MACHINE_ARCH=powerpc
704 MACHINE=riscv MACHINE_ARCH=riscv64 ALIAS=riscv64 DEFAULT
705 MACHINE=riscv MACHINE_ARCH=riscv32 ALIAS=riscv32
706 MACHINE=rs6000 MACHINE_ARCH=powerpc
707 MACHINE=sandpoint MACHINE_ARCH=powerpc
708 MACHINE=sbmips MACHINE_ARCH= NO_DEFAULT
709 MACHINE=sbmips MACHINE_ARCH=mips64eb ALIAS=sbmips64-eb
710 MACHINE=sbmips MACHINE_ARCH=mips64el ALIAS=sbmips64-el
711 MACHINE=sbmips MACHINE_ARCH=mipseb ALIAS=sbmips-eb
712 MACHINE=sbmips MACHINE_ARCH=mipsel ALIAS=sbmips-el
713 MACHINE=sgimips MACHINE_ARCH=mips64eb ALIAS=sgimips64
714 MACHINE=sgimips MACHINE_ARCH=mipseb DEFAULT
715 MACHINE=shark MACHINE_ARCH=earmv4 ALIAS=eshark DEFAULT
716 MACHINE=sparc MACHINE_ARCH=sparc
717 MACHINE=sparc64 MACHINE_ARCH=sparc64
718 MACHINE=sun2 MACHINE_ARCH=m68000
719 MACHINE=sun3 MACHINE_ARCH=m68k
720 MACHINE=vax MACHINE_ARCH=vax
721 MACHINE=virt68k MACHINE_ARCH=m68k
722 MACHINE=x68k MACHINE_ARCH=m68k
723 MACHINE=zaurus MACHINE_ARCH=earm ALIAS=ezaurus DEFAULT
724 '
725
726 # getarch -- find the default MACHINE_ARCH for a MACHINE,
727 # or convert an alias to a MACHINE/MACHINE_ARCH pair.
728 #
729 # Saves the original value of MACHINE in makewrappermachine before
730 # alias processing.
731 #
732 # Sets MACHINE and MACHINE_ARCH if the input MACHINE value is
733 # recognised as an alias, or recognised as a machine that has a default
734 # MACHINE_ARCH (or that has only one possible MACHINE_ARCH).
735 #
736 # Leaves MACHINE and MACHINE_ARCH unchanged if MACHINE is recognised
737 # as being associated with multiple MACHINE_ARCH values with no default.
738 #
739 # Bombs if MACHINE is not recognised.
740 #
741 getarch()
742 {
743 local IFS
744 local found=""
745 local line
746
747 IFS="${nl}"
748 makewrappermachine="${MACHINE}"
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 *" ALIAS=${MACHINE} "*)
758 # Found a line with a matching ALIAS=<alias>.
759 found="$line"
760 break
761 ;;
762 "MACHINE=${MACHINE} "*" NO_DEFAULT"*)
763 # Found an explicit "NO_DEFAULT" for this MACHINE.
764 found="$line"
765 break
766 ;;
767 "MACHINE=${MACHINE} "*" DEFAULT"*)
768 # Found an explicit "DEFAULT" for this MACHINE.
769 found="$line"
770 break
771 ;;
772 "MACHINE=${MACHINE} "*)
773 # Found a line for this MACHINE. If it's the
774 # first such line, then tentatively accept it.
775 # If it's not the first matching line, then
776 # remember that there was more than one match.
777 case "$found" in
778 '') found="$line" ;;
779 *) found="MULTIPLE_MATCHES" ;;
780 esac
781 ;;
782 esac
783 done
784
785 case "$found" in
786 *NO_DEFAULT*|*MULTIPLE_MATCHES*)
787 # MACHINE is OK, but MACHINE_ARCH is still unknown
788 return
789 ;;
790 "MACHINE="*" MACHINE_ARCH="*)
791 # Obey the MACHINE= and MACHINE_ARCH= parts of the line.
792 IFS=" "
793 for frag in ${found}; do
794 case "$frag" in
795 MACHINE=*|MACHINE_ARCH=*)
796 eval "$frag"
797 ;;
798 esac
799 done
800 ;;
801 *)
802 bomb "Unknown target MACHINE: ${MACHINE}"
803 ;;
804 esac
805 }
806
807 # validatearch -- check that the MACHINE/MACHINE_ARCH pair is supported.
808 #
809 # Bombs if the pair is not supported.
810 #
811 validatearch()
812 {
813 local IFS
814 local line
815 local foundpair=false foundmachine=false foundarch=false
816
817 case "${MACHINE_ARCH}" in
818 "")
819 bomb "No MACHINE_ARCH provided. Use 'build.sh -m ${MACHINE} list-arch' to show options"
820 ;;
821 esac
822
823 IFS="${nl}"
824 for line in ${valid_MACHINE_ARCH}; do
825 line="${line%%#*}" # ignore comments
826 line="$( IFS=" ${tab}" ; echo $line )" # normalise white space
827 case "${line} " in
828 " ")
829 # skip blank lines or comment lines
830 continue
831 ;;
832 "MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} "*)
833 foundpair=true
834 ;;
835 "MACHINE=${MACHINE} "*)
836 foundmachine=true
837 ;;
838 *"MACHINE_ARCH=${MACHINE_ARCH} "*)
839 foundarch=true
840 ;;
841 esac
842 done
843
844 case "${foundpair}:${foundmachine}:${foundarch}" in
845 true:*)
846 : OK
847 ;;
848 *:false:*)
849 bomb "Unknown target MACHINE: ${MACHINE}"
850 ;;
851 *:*:false)
852 bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
853 ;;
854 *)
855 bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
856 ;;
857 esac
858 }
859
860 # listarch -- list valid MACHINE/MACHINE_ARCH/ALIAS values,
861 # optionally restricted to those where the MACHINE and/or MACHINE_ARCH
862 # match specified glob patterns.
863 #
864 listarch()
865 {
866 local machglob="$1" archglob="$2"
867 local IFS
868 local wildcard="*"
869 local line xline frag
870 local line_matches_machine line_matches_arch
871 local found=false
872
873 # Empty machglob or archglob should match anything
874 : "${machglob:=${wildcard}}"
875 : "${archglob:=${wildcard}}"
876
877 IFS="${nl}"
878 for line in ${valid_MACHINE_ARCH}; do
879 line="${line%%#*}" # ignore comments
880 xline="$( IFS=" ${tab}" ; echo $line )" # normalise white space
881 [ -z "${xline}" ] && continue # skip blank or comment lines
882
883 line_matches_machine=false
884 line_matches_arch=false
885
886 IFS=" "
887 for frag in ${xline}; do
888 case "${frag}" in
889 MACHINE=${machglob})
890 line_matches_machine=true ;;
891 ALIAS=${machglob})
892 line_matches_machine=true ;;
893 MACHINE_ARCH=${archglob})
894 line_matches_arch=true ;;
895 esac
896 done
897
898 if $line_matches_machine && $line_matches_arch; then
899 found=true
900 echo "$line"
901 fi
902 done
903 if ! $found; then
904 echo >&2 "No match for" \
905 "MACHINE=${machglob} MACHINE_ARCH=${archglob}"
906 return 1
907 fi
908 return 0
909 }
910
911 # nobomb_getmakevar --
912 # Given the name of a make variable in $1, show make's idea of the
913 # value of that variable, or return 1 if there's an error.
914 #
915 nobomb_getmakevar()
916 {
917 [ -x "${make}" ] || return 1
918 "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
919 _x_:
920 echo \${$1}
921 .include <bsd.prog.mk>
922 .include <bsd.kernobj.mk>
923 EOF
924 }
925
926 # bomb_getmakevar --
927 # Given the name of a make variable in $1, show make's idea of the
928 # value of that variable, or bomb if there's an error.
929 #
930 bomb_getmakevar()
931 {
932 [ -x "${make}" ] || bomb "bomb_getmakevar $1: ${make} is not executable"
933 nobomb_getmakevar "$1" || bomb "bomb_getmakevar $1: ${make} failed"
934 }
935
936 # getmakevar --
937 # Given the name of a make variable in $1, show make's idea of the
938 # value of that variable, or show a literal '$' followed by the
939 # variable name if ${make} is not executable. This is intended for use in
940 # messages that need to be readable even if $make hasn't been built,
941 # such as when build.sh is run with the "-n" option.
942 #
943 getmakevar()
944 {
945 if [ -x "${make}" ]; then
946 bomb_getmakevar "$1"
947 else
948 echo "\$$1"
949 fi
950 }
951
952 setmakeenv()
953 {
954 eval "$1='$2'; export $1"
955 makeenv="${makeenv} $1"
956 }
957
958 safe_setmakeenv()
959 {
960 case "$1" in
961
962 # Look for any vars we want to prohibit here, like:
963 # Bad | Dangerous) usage "Cannot override $1 with -V";;
964
965 # That first char is OK has already been verified.
966 *[!A-Za-z0-9_]*) usage "Bad variable name (-V): '$1'";;
967 esac
968 setmakeenv "$@"
969 }
970
971 unsetmakeenv()
972 {
973 eval "unset $1"
974 makeenv="${makeenv} $1"
975 }
976
977 safe_unsetmakeenv()
978 {
979 case "$1" in
980
981 # Look for any vars user should not be able to unset
982 # Needed | Must_Have) usage "Variable $1 cannot be unset";;
983
984 [!A-Za-z_]* | *[!A-Za-z0-9_]*) usage "Bad variable name (-Z): '$1'";;
985 esac
986 unsetmakeenv "$1"
987 }
988
989 # Clear all variables defined in makeenv. Used to run a subprocess
990 # outside the usual NetBSD build's make environment.
991 #
992 clearmakeenv()
993 {
994 local var
995
996 for var in ${makeenv}; do
997 unset ${var}
998 done
999 }
1000
1001 # Given a variable name in $1, modify the variable in place as follows:
1002 # For each space-separated word in the variable, call resolvepath.
1003 #
1004 resolvepaths()
1005 {
1006 local var="$1"
1007 local val
1008 eval val=\"\${${var}}\"
1009 local newval=''
1010 local word
1011 for word in ${val}; do
1012 resolvepath word
1013 newval="${newval}${newval:+ }${word}"
1014 done
1015 eval ${var}=\"\${newval}\"
1016 }
1017
1018 # Given a variable name in $1, modify the variable in place as follows:
1019 # Convert possibly-relative path to absolute path by prepending
1020 # ${TOP} if necessary. Also delete trailing "/", if any.
1021 #
1022 resolvepath()
1023 {
1024 local var="$1"
1025 local val
1026 eval val=\"\${${var}}\"
1027 case "${val}" in
1028 /)
1029 ;;
1030 /*)
1031 val="${val%/}"
1032 ;;
1033 *)
1034 val="${TOP}/${val%/}"
1035 ;;
1036 esac
1037 eval ${var}=\"\${val}\"
1038 }
1039
1040 # Show synopsis to stdout.
1041 #
1042 synopsis()
1043 {
1044 cat <<_usage_
1045
1046 Usage: ${progname} [-EnoPRrUux] [-a ARCH] [-B BID] [-C EXTRAS]
1047 [-c COMPILER] [-D DEST] [-j NJOB] [-M MOBJ] [-m MACH]
1048 [-N NOISY] [-O OOBJ] [-R RELEASE] [-S SEED] [-T TOOLS]
1049 [-V VAR=[VALUE]] [-w WRAPPER] [-X X11SRC]
1050 [-Z VAR]
1051 OPERATION ...
1052 ${progname} ( -h | -? )
1053
1054 _usage_
1055 }
1056
1057 # Show help to stdout.
1058 #
1059 help()
1060 {
1061 synopsis
1062 cat <<_usage_
1063 Build OPERATIONs (all imply "obj" and "tools"):
1064 build Run "make build".
1065 distribution Run "make distribution" (includes DESTDIR/etc/ files).
1066 release Run "make release" (includes kernels & distrib media).
1067
1068 Other OPERATIONs:
1069 help Show this help message, and exit.
1070 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
1071 Always performed.
1072 cleandir Run "make cleandir". [Default unless -u is used]
1073 dtb Build devicetree blobs.
1074 obj Run "make obj". [Default unless -o is used]
1075 tools Build and install tools.
1076 install=IDIR Run "make installworld" to IDIR to install all sets
1077 except 'etc'. Useful after "distribution" or "release".
1078 kernel=CONF Build kernel with config file CONF.
1079 kernel.gdb=CONF Build kernel (including netbsd.gdb) with config
1080 file CONF.
1081 releasekernel=CONF Install kernel built by kernel=CONF to RELEASEDIR.
1082 kernels Build all kernels.
1083 installmodules=IDIR Run "make installmodules" to IDIR to install all
1084 kernel modules.
1085 modules Build kernel modules.
1086 rumptest Do a linktest for rump (for developers).
1087 sets Create binary sets in
1088 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
1089 DESTDIR should be populated beforehand.
1090 distsets Same as "distribution sets".
1091 sourcesets Create source sets in RELEASEDIR/source/sets.
1092 syspkgs Create syspkgs in
1093 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
1094 pkg=CATEGORY/PKG (EXPERIMENT) Build a package CATEGORY/PKG from pkgsrc.
1095 iso-image Create CD-ROM image in RELEASEDIR/images.
1096 iso-image-source Create CD-ROM image with source in RELEASEDIR/images.
1097 live-image Create bootable live image in
1098 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage.
1099 install-image Create bootable installation image in
1100 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage.
1101 disk-image=TARGET Create bootable disk image in
1102 RELEASEDIR/RELEASEMACHINEDIR/binary/gzimg/TARGET.img.gz.
1103 params Create params file with various make(1) parameters.
1104 show-params Show various make(1) parameters.
1105 list-arch Show a list of valid MACHINE/MACHINE_ARCH values,
1106 and exit. The list may be narrowed by passing glob
1107 patterns or exact values in MACHINE or MACHINE_ARCH.
1108 mkrepro-timestamp Show the latest source timestamp used for reproducible
1109 builds and exit. Requires -P or -V MKREPRO=yes.
1110 show-revisionid Show the revision ID of the current directory
1111 (in SCM dependend format) and exit.
1112 Requires -P or -V MKREPRO=yes.
1113
1114 Options:
1115 -a ARCH Set MACHINE_ARCH=ARCH. [Default: deduced from MACHINE]
1116 -B BID Set BUILDID=BID.
1117 -C EXTRAS Append EXTRAS to CDEXTRA for inclusion on CD-ROM.
1118 -c COMPILER Select compiler from COMPILER:
1119 clang
1120 gcc
1121 [Default: gcc]
1122 -D DEST Set DESTDIR=DEST. [Default: destdir.\${MACHINE}]
1123 -E Set "expert" mode; disables various safety checks.
1124 Should not be used without expert knowledge of the build
1125 system.
1126 -h Show this help message, and exit.
1127 -j NJOB Run up to NJOB jobs in parallel; see make(1) -j.
1128 -M MOBJ Set obj root directory to MOBJ; sets MAKEOBJDIRPREFIX=MOBJ,
1129 unsets MAKEOBJDIR.
1130 -m MACH Set MACHINE=MACH. Some MACH values are actually
1131 aliases that set MACHINE/MACHINE_ARCH pairs.
1132 [Default: deduced from the host system if the host
1133 OS is NetBSD]
1134 -N NOISY Set the noisiness (MAKEVERBOSE) level of the build to NOISY:
1135 0 Minimal output ("quiet").
1136 1 Describe what is occurring.
1137 2 Describe what is occurring and echo the actual
1138 command.
1139 3 Ignore the effect of the "@" prefix in make
1140 commands.
1141 4 Trace shell commands using the shell's -x flag.
1142 [Default: 2]
1143 -n Show commands that would be executed, but do not execute
1144 them.
1145 -O OOBJ Set obj root directory to OOBJ; sets a MAKEOBJDIR pattern
1146 using OOBJ, unsets MAKEOBJDIRPREFIX.
1147 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
1148 -P Set MKREPRO and MKREPRO_TIMESTAMP to the latest source
1149 CVS timestamp for reproducible builds.
1150 -R RELEASE Set RELEASEDIR=RELEASE. [Default: releasedir]
1151 -r Remove contents of TOOLDIR and DESTDIR before building.
1152 -S SEED Set BUILDSEED=SEED. [Default: NetBSD-majorversion]
1153 -T TOOLS Set TOOLDIR=TOOLS. If unset, and TOOLDIR is not set
1154 in the environment, ${toolprefix}make will be (re)built
1155 unconditionally.
1156 -U Set MKUNPRIVED=yes; build without requiring root privileges,
1157 install from an unprivileged build with proper file
1158 permissions.
1159 -u Set MKUPDATE=yes; do not run "make cleandir" first.
1160 Without this, everything is rebuilt, including the tools.
1161 -V VAR=[VALUE] Set variable VAR=VALUE.
1162 -w WRAPPER Create ${toolprefix}make script as WRAPPER.
1163 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
1164 -X X11SRC Set X11SRCDIR=X11SRC. [Default: /usr/xsrc]
1165 -x Set MKX11=yes; build X11 from X11SRCDIR.
1166 -Z VAR Unset ("zap") variable VAR.
1167 -? Show this help message, and exit.
1168
1169 _usage_
1170 }
1171
1172 # Show optional error message, help to stderr, and exit 1.
1173 #
1174 usage()
1175 {
1176 if [ -n "$*" ]; then
1177 echo 1>&2 ""
1178 echo 1>&2 "${progname}: $*"
1179 fi
1180 synopsis 1>&2
1181 exit 1
1182 }
1183
1184 parseoptions()
1185 {
1186 opts='a:B:C:c:D:Ehj:M:m:N:nO:oPR:rS:T:UuV:w:X:xZ:'
1187 opt_a=false
1188 opt_m=false
1189 local did_show_info=false
1190
1191 if type getopts >/dev/null 2>&1; then
1192 # Use POSIX getopts.
1193 #
1194 getoptcmd='getopts :${opts} opt && opt=-${opt}'
1195 optargcmd=':'
1196 optremcmd='shift $((${OPTIND} -1))'
1197 else
1198 type getopt >/dev/null 2>&1 ||
1199 bomb "Shell does not support getopts or getopt"
1200
1201 # Use old-style getopt(1) (doesn't handle whitespace in args).
1202 #
1203 args="$(getopt ${opts} $*)"
1204 [ $? = 0 ] || usage
1205 set -- ${args}
1206
1207 getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
1208 optargcmd='OPTARG="$1"; shift'
1209 optremcmd=':'
1210 fi
1211
1212 # Parse command line options.
1213 #
1214 while eval ${getoptcmd}; do
1215 case ${opt} in
1216
1217 -a)
1218 eval ${optargcmd}
1219 MACHINE_ARCH=${OPTARG}
1220 opt_a=true
1221 ;;
1222
1223 -B)
1224 eval ${optargcmd}
1225 BUILDID=${OPTARG}
1226 ;;
1227
1228 -C)
1229 eval ${optargcmd}; resolvepaths OPTARG
1230 CDEXTRA="${CDEXTRA}${CDEXTRA:+ }${OPTARG}"
1231 ;;
1232
1233 -c)
1234 eval ${optargcmd}
1235 case "${OPTARG}" in
1236 gcc) # default, no variables needed
1237 ;;
1238 clang) setmakeenv HAVE_LLVM yes
1239 setmakeenv MKLLVM yes
1240 setmakeenv MKGCC no
1241 ;;
1242 #pcc) ...
1243 # ;;
1244 *) bomb "Unknown compiler: ${OPTARG}"
1245 esac
1246 ;;
1247
1248 -D)
1249 eval ${optargcmd}; resolvepath OPTARG
1250 setmakeenv DESTDIR "${OPTARG}"
1251 ;;
1252
1253 -E)
1254 do_expertmode=true
1255 ;;
1256
1257 -j)
1258 eval ${optargcmd}
1259 parallel="-j ${OPTARG}"
1260 ;;
1261
1262 -M)
1263 eval ${optargcmd}; resolvepath OPTARG
1264 case "${OPTARG}" in
1265 \$*) usage "-M argument must not begin with '\$'"
1266 ;;
1267 *\$*) # can use resolvepath, but can't set TOP_objdir
1268 resolvepath OPTARG
1269 ;;
1270 *) resolvepath OPTARG
1271 TOP_objdir="${OPTARG}${TOP}"
1272 ;;
1273 esac
1274 unsetmakeenv MAKEOBJDIR
1275 setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1276 ;;
1277
1278 # -m overrides MACHINE_ARCH unless "-a" is specified
1279 -m)
1280 eval ${optargcmd}
1281 MACHINE="${OPTARG}"
1282 opt_m=true
1283 ;;
1284
1285 -N)
1286 eval ${optargcmd}
1287 case "${OPTARG}" in
1288 0|1|2|3|4)
1289 setmakeenv MAKEVERBOSE "${OPTARG}"
1290 ;;
1291 *)
1292 usage "'${OPTARG}' is not a valid value for -N"
1293 ;;
1294 esac
1295 ;;
1296
1297 -n)
1298 runcmd=echo
1299 ;;
1300
1301 -O)
1302 eval ${optargcmd}
1303 case "${OPTARG}" in
1304 *\$*) usage "-O argument must not contain '\$'"
1305 ;;
1306 *) resolvepath OPTARG
1307 TOP_objdir="${OPTARG}"
1308 ;;
1309 esac
1310 unsetmakeenv MAKEOBJDIRPREFIX
1311 setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1312 ;;
1313
1314 -o)
1315 MKOBJDIRS=no
1316 ;;
1317
1318 -P)
1319 MKREPRO=yes
1320 ;;
1321
1322 -R)
1323 eval ${optargcmd}; resolvepath OPTARG
1324 setmakeenv RELEASEDIR "${OPTARG}"
1325 ;;
1326
1327 -r)
1328 do_removedirs=true
1329 do_rebuildmake=true
1330 ;;
1331
1332 -S)
1333 eval ${optargcmd}
1334 setmakeenv BUILDSEED "${OPTARG}"
1335 ;;
1336
1337 -T)
1338 eval ${optargcmd}; resolvepath OPTARG
1339 TOOLDIR="${OPTARG}"
1340 export TOOLDIR
1341 ;;
1342
1343 -U)
1344 setmakeenv MKUNPRIVED yes
1345 ;;
1346
1347 -u)
1348 setmakeenv MKUPDATE yes
1349 ;;
1350
1351 -V)
1352 eval ${optargcmd}
1353 case "${OPTARG}" in
1354 # XXX: consider restricting which variables can be changed?
1355 [a-zA-Z_]*=*)
1356 safe_setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1357 ;;
1358 [a-zA-Z_]*)
1359 safe_setmakeenv "${OPTARG}" ""
1360 ;;
1361 *)
1362 usage "-V argument must be of the form 'VAR[=VALUE]'"
1363 ;;
1364 esac
1365 ;;
1366
1367 -w)
1368 eval ${optargcmd}; resolvepath OPTARG
1369 makewrapper="${OPTARG}"
1370 ;;
1371
1372 -X)
1373 eval ${optargcmd}; resolvepath OPTARG
1374 setmakeenv X11SRCDIR "${OPTARG}"
1375 ;;
1376
1377 -x)
1378 setmakeenv MKX11 yes
1379 ;;
1380
1381 -Z)
1382 eval ${optargcmd}
1383 # XXX: consider restricting which variables can be unset?
1384 safe_unsetmakeenv "${OPTARG}"
1385 ;;
1386
1387 --)
1388 break
1389 ;;
1390
1391 -h)
1392 help
1393 exit 0
1394 ;;
1395
1396 '-?')
1397 if [ "${OPTARG}" = '?' ]; then
1398 help
1399 exit 0
1400 fi
1401 usage "Unknown option -${OPTARG}"
1402 ;;
1403
1404 -:)
1405 usage "Missing argument for option -${OPTARG}"
1406 ;;
1407
1408 *)
1409 usage "Unimplemented option ${opt}"
1410 ;;
1411
1412 esac
1413 done
1414
1415 # Validate operations.
1416 #
1417 eval ${optremcmd}
1418 while [ $# -gt 0 ]; do
1419 op=$1; shift
1420 operations="${operations} ${op}"
1421
1422 case "${op}" in
1423
1424 help)
1425 help
1426 exit 0
1427 ;;
1428
1429 list-arch)
1430 listarch "${MACHINE}" "${MACHINE_ARCH}"
1431 exit
1432 ;;
1433 mkrepro-timestamp)
1434 setup_mkrepro quiet
1435 echo ${MKREPRO_TIMESTAMP:-0}
1436 did_show_info=true
1437 ;;
1438
1439 show-revisionid)
1440 setup_mkrepro quiet
1441 echo ${NETBSD_REVISIONID}
1442 did_show_info=true
1443 ;;
1444
1445 kernel=*|releasekernel=*|kernel.gdb=*)
1446 arg=${op#*=}
1447 op=${op%%=*}
1448 [ -n "${arg}" ] ||
1449 bomb "Must supply a kernel name with '${op}=...'"
1450 ;;
1451
1452 disk-image=*)
1453 arg=${op#*=}
1454 op=disk_image
1455 [ -n "${arg}" ] ||
1456 bomb "Must supply a target name with '${op}=...'"
1457
1458 ;;
1459
1460 pkg=*)
1461 arg=${op#*=}
1462 op=${op%%=*}
1463 [ -n "${arg}" ] ||
1464 bomb "Must supply category/package with 'pkg=...'"
1465 ;;
1466
1467 install=*|installmodules=*)
1468 arg=${op#*=}
1469 op=${op%%=*}
1470 [ -n "${arg}" ] ||
1471 bomb "Must supply a directory with 'install=...'"
1472 ;;
1473
1474 distsets)
1475 operations="$(echo "$operations" | sed 's/distsets/distribution sets/')"
1476 do_sets=true
1477 op=distribution
1478 ;;
1479
1480 build|\
1481 cleandir|\
1482 distribution|\
1483 dtb|\
1484 install-image|\
1485 iso-image-source|\
1486 iso-image|\
1487 kernels|\
1488 libs|\
1489 live-image|\
1490 makewrapper|\
1491 modules|\
1492 obj|\
1493 params|\
1494 release|\
1495 rump|\
1496 rumptest|\
1497 sets|\
1498 show-params|\
1499 sourcesets|\
1500 syspkgs|\
1501 tools)
1502 ;;
1503
1504 *)
1505 usage "Unknown OPERATION '${op}'"
1506 ;;
1507
1508 esac
1509 # ${op} may contain chars that are not allowed in variable
1510 # names. Replace them with '_' before setting do_${op}.
1511 op="$( echo "$op" | tr -s '.-' '__')"
1512 eval do_${op}=true
1513 done
1514
1515 [ "$did_show_info" = true ] && [ ${MKREPRO_TIMESTAMP:-0} -ne 0 ] && exit
1516
1517 [ -n "${operations}" ] || usage "Missing OPERATION to perform"
1518
1519 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
1520 #
1521 if [ -z "${MACHINE}" ]; then
1522 [ "${uname_s}" = "NetBSD" ] ||
1523 bomb "MACHINE must be set, or -m must be used, for cross builds"
1524 MACHINE=${uname_m}
1525 MACHINE_ARCH=${uname_p}
1526 fi
1527 if $opt_m && ! $opt_a; then
1528 # Settings implied by the command line -m option
1529 # override MACHINE_ARCH from the environment (if any).
1530 getarch
1531 fi
1532 [ -n "${MACHINE_ARCH}" ] || getarch
1533 validatearch
1534
1535 # Set up default make(1) environment.
1536 #
1537 makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
1538 [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1539 [ -z "${BUILDINFO}" ] || makeenv="${makeenv} BUILDINFO"
1540 MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS}"
1541 MAKEFLAGS="${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1542 export MAKEFLAGS MACHINE MACHINE_ARCH
1543 setmakeenv USETOOLS "yes"
1544 setmakeenv MAKEWRAPPERMACHINE "${makewrappermachine:-${MACHINE}}"
1545 setmakeenv MAKE_OBJDIR_CHECK_WRITABLE no
1546 }
1547
1548 # sanitycheck --
1549 # Sanity check after parsing command line options, before rebuildmake.
1550 #
1551 sanitycheck()
1552 {
1553 # Install as non-root is a bad idea.
1554 #
1555 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1556 if ${do_expertmode}; then
1557 warning "Will install as an unprivileged user"
1558 else
1559 bomb "-E must be set for install as an unprivileged user"
1560 fi
1561 fi
1562
1563 # If the PATH contains any non-absolute components (including,
1564 # but not limited to, "." or ""), then complain. As an exception,
1565 # allow "" or "." as the last component of the PATH. This is fatal
1566 # if expert mode is not in effect.
1567 #
1568 local path="${PATH}"
1569 path="${path%:}" # delete trailing ":"
1570 path="${path%:.}" # delete trailing ":."
1571 case ":${path}:/" in
1572 *:[!/~]*)
1573 if ${do_expertmode}; then
1574 warning "PATH contains non-absolute components"
1575 else
1576 bomb "PATH environment variable must not" \
1577 "contain non-absolute components"
1578 fi
1579 ;;
1580 esac
1581
1582 while [ ${MKX11-no} = "yes" ]; do # not really a loop
1583 test -n "${X11SRCDIR}" && {
1584 test -d "${X11SRCDIR}/external" ||
1585 bomb "X11SRCDIR (${X11SRCDIR}) does not exist (with -x)"
1586 break
1587 }
1588 for _xd in \
1589 "${NETBSDSRCDIR%/*}/xsrc" \
1590 "${NETBSDSRCDIR}/xsrc" \
1591 /usr/xsrc
1592 do
1593 test -f "${_xd}/Makefile" &&
1594 setmakeenv X11SRCDIR "${_xd}" &&
1595 break 2
1596 done
1597 bomb "Asked to build X11 but no xsrc"
1598 done
1599
1600 while $do_pkg; do # not really a loop
1601 test -n "${PKGSRCDIR}" && {
1602 test -f "${PKGSRCDIR}/mk/bsd.pkg.mk" ||
1603 bomb "PKGSRCDIR (${PKGSRCDIR}) does not exist"
1604 break
1605 }
1606 for _pd in \
1607 "${NETBSDSRCDIR%/*}/pkgsrc" \
1608 "${NETBSDSRCDIR}/pkgsrc" \
1609 /usr/pkgsrc
1610 do
1611 test -f "${_pd}/mk/bsd.pkg.mk" &&
1612 setmakeenv PKGSRCDIR "${_pd}" &&
1613 break 2
1614 done
1615 bomb "Asked to build package but no pkgsrc"
1616 done
1617 if $do_pkg && [ "${MKX11-no}" = yes ]; then
1618 # See comment below about X11_TYPE in pkgsrc mk.conf.
1619 # (Feel free to remove this, and set X11_TYPE to
1620 # native/modular according to MKX11=yes/no, if you want
1621 # to do the work to make X11_TYPE=native cross-builds
1622 # work.)
1623 bomb "Experimental \`build.sh pkg=...'" \
1624 "does not support -x/MKX11=yes"
1625 fi
1626 }
1627
1628 # print_tooldir_program --
1629 # Try to find and show a path to an existing
1630 # ${TOOLDIR}/bin/${toolprefix}program
1631 #
1632 print_tooldir_program()
1633 {
1634 local possible_TOP_OBJ
1635 local possible_TOOLDIR
1636 local possible_program
1637 local tooldir_program
1638 local program=${1}
1639
1640 if [ -n "${TOOLDIR}" ]; then
1641 echo "${TOOLDIR}/bin/${toolprefix}${program}"
1642 return
1643 fi
1644
1645 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1646 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1647 #
1648 local host_ostype="${uname_s}-$(
1649 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1650 )-$(
1651 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1652 )"
1653
1654 # Look in a few potential locations for
1655 # ${possible_TOOLDIR}/bin/${toolprefix}${program}.
1656 # If we find it, then set possible_program.
1657 #
1658 # In the usual case (without interference from environment
1659 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1660 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1661 #
1662 # In practice it's difficult to figure out the correct value
1663 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1664 # options were passed to build.sh, then ${TOP_objdir} will be
1665 # the correct value. We also try a few other possibilities, but
1666 # we do not replicate all the logic of <bsd.obj.mk>.
1667 #
1668 for possible_TOP_OBJ in \
1669 "${TOP_objdir}" \
1670 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1671 "${TOP}" \
1672 "${TOP}/obj" \
1673 "${TOP}/obj.${MACHINE}"
1674 do
1675 [ -n "${possible_TOP_OBJ}" ] || continue
1676 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1677 possible_program="${possible_TOOLDIR}/bin/${toolprefix}${program}"
1678 if [ -x "${possible_program}" ]; then
1679 echo ${possible_program}
1680 return;
1681 fi
1682 done
1683 echo ""
1684 }
1685
1686 # print_tooldir_make --
1687 # Try to find and show a path to an existing
1688 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1689 # new version of ${toolprefix}make has been built.
1690 #
1691 # * If TOOLDIR was set in the environment or on the command line, use
1692 # that value.
1693 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1694 # /etc/mk.conf, and check whether the resulting directory contains
1695 # a copy of ${toolprefix}make (this should work for everybody who
1696 # doesn't override TOOLDIR via /etc/mk.conf);
1697 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1698 # in the PATH (this might accidentally find a version of make that
1699 # does not understand the syntax used by NetBSD make, and that will
1700 # lead to failure in the next step);
1701 # * If a copy of make was found above, try to use it with
1702 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1703 # result only if it's a directory that already exists;
1704 # * If a value of TOOLDIR was found above, and if
1705 # ${TOOLDIR}/bin/${toolprefix}make exists, show that value.
1706 #
1707 print_tooldir_make()
1708 {
1709 local possible_make
1710 local possible_TOOLDIR
1711 local tooldir_make
1712
1713 possible_make=$(print_tooldir_program make)
1714 # If the above didn't work, search the PATH for a suitable
1715 # ${toolprefix}make, nbmake, bmake, or make.
1716 #
1717 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1718 : ${possible_make:=$(find_in_PATH nbmake '')}
1719 : ${possible_make:=$(find_in_PATH bmake '')}
1720 : ${possible_make:=$(find_in_PATH make '')}
1721
1722 # At this point, we don't care whether possible_make is in the
1723 # correct TOOLDIR or not; we simply want it to be usable by
1724 # getmakevar to help us find the correct TOOLDIR.
1725 #
1726 # Use ${possible_make} with nobomb_getmakevar to try to find
1727 # the value of TOOLDIR. Believe the result only if it's
1728 # a directory that already exists and contains bin/${toolprefix}make.
1729 #
1730 if [ -x "${possible_make}" ]; then
1731 possible_TOOLDIR="$(
1732 make="${possible_make}" \
1733 nobomb_getmakevar TOOLDIR 2>/dev/null
1734 )"
1735 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1736 && [ -d "${possible_TOOLDIR}" ];
1737 then
1738 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1739 if [ -x "${tooldir_make}" ]; then
1740 echo "${tooldir_make}"
1741 return 0
1742 fi
1743 fi
1744 fi
1745 return 1
1746 }
1747
1748 # rebuildmake --
1749 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1750 # to a path to the nbmake executable. Sets done_rebuildmake=true
1751 # if nbmake was rebuilt.
1752 #
1753 # There is a cyclic dependency between building nbmake and choosing
1754 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1755 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1756 # use getmakevar before we have an up to date version of nbmake; we
1757 # might already have an up to date version of nbmake in TOOLDIR, but we
1758 # don't yet know where TOOLDIR is.
1759 #
1760 # The default value of TOOLDIR also depends on the location of the top
1761 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1762 # after making the top level object directory may produce different
1763 # results.
1764 #
1765 # Strictly speaking, we should do the following:
1766 #
1767 # 1. build a new version of nbmake in a temporary directory;
1768 # 2. use the temporary nbmake to create the top level obj directory;
1769 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1770 # get the correct value of TOOLDIR;
1771 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1772 #
1773 # However, people don't like building nbmake unnecessarily if their
1774 # TOOLDIR has not changed since an earlier build. We try to avoid
1775 # rebuilding a temporary version of nbmake by taking some shortcuts to
1776 # guess a value for TOOLDIR, looking for an existing version of nbmake
1777 # in that TOOLDIR, and checking whether that nbmake is newer than the
1778 # sources used to build it.
1779 #
1780 rebuildmake()
1781 {
1782 make="$(print_tooldir_make)"
1783 if [ -n "${make}" ] && [ -x "${make}" ]; then
1784 for f in usr.bin/make/*.[ch]; do
1785 if [ "${f}" -nt "${make}" ]; then
1786 statusmsg "${make} outdated" \
1787 "(older than ${f}), needs building."
1788 do_rebuildmake=true
1789 break
1790 fi
1791 done
1792 else
1793 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1794 do_rebuildmake=true
1795 fi
1796
1797 # Build bootstrap ${toolprefix}make if needed.
1798 if ! ${do_rebuildmake}; then
1799 return
1800 fi
1801
1802 # Silent configure with MAKEVERBOSE==0
1803 if [ ${MAKEVERBOSE:-2} -eq 0 ]; then
1804 configure_args=--silent
1805 fi
1806
1807 statusmsg "Bootstrapping ${toolprefix}make"
1808 ${runcmd} cd "${tmpdir}"
1809 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1810 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1811 ${HOST_SH} "${TOP}/tools/make/configure" ${configure_args} ||
1812 ( cp ${tmpdir}/config.log ${tmpdir}-config.log
1813 bomb "Configure of ${toolprefix}make failed, see ${tmpdir}-config.log for details" )
1814 ${runcmd} ${HOST_SH} buildmake.sh ||
1815 bomb "Build of ${toolprefix}make failed"
1816 make="${tmpdir}/${toolprefix}make"
1817 ${runcmd} cd "${TOP}"
1818 ${runcmd} rm -f usr.bin/make/*.o
1819 done_rebuildmake=true
1820 }
1821
1822 # validatemakeparams --
1823 # Perform some late sanity checks, after rebuildmake,
1824 # but before createmakewrapper or any real work.
1825 #
1826 # Creates the top-level obj directory, because that
1827 # is needed by some of the sanity checks.
1828 #
1829 # Shows status messages reporting the values of several variables.
1830 #
1831 validatemakeparams()
1832 {
1833 # Determine MAKECONF first, and set in the makewrapper.
1834 # If set in the environment, then use that.
1835 # else if ./mk.conf exists, then set MAKECONF to that,
1836 # else use the default from share/mk/bsd.own.mk (/etc/mk.conf).
1837 #
1838 if [ -n "${MAKECONF+1}" ]; then
1839 setmakeenv MAKECONF "${MAKECONF}"
1840 statusmsg2 "getenv MAKECONF:" "${MAKECONF}"
1841 elif [ -f "${TOP}/mk.conf" ]; then
1842 setmakeenv MAKECONF "${TOP}/mk.conf"
1843 statusmsg2 "mk.conf MAKECONF:" "${MAKECONF}"
1844 else
1845 MAKECONF=$(getmakevar MAKECONF)
1846 setmakeenv MAKECONF "${MAKECONF}"
1847 statusmsg2 "share/mk MAKECONF:" "${MAKECONF}"
1848 fi
1849 if [ -z "${MAKECONF}" ]; then
1850 bomb "MAKECONF must not be empty"
1851 elif [ -e "${MAKECONF}" ]; then
1852 statusmsg2 "MAKECONF file:" "${MAKECONF}"
1853 else
1854 statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)"
1855 fi
1856
1857 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE.
1858 # These may be set as build.sh options or in "mk.conf".
1859 # Don't export them as they're only used for tests in build.sh.
1860 #
1861 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1862 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1863 MKUPDATE=$(getmakevar MKUPDATE)
1864
1865 # Non-root should always use either the -U or -E flag.
1866 #
1867 if ! ${do_expertmode} && \
1868 [ "$id_u" -ne 0 ] && \
1869 [ "${MKUNPRIVED}" = "no" ] ; then
1870 bomb "-U or -E must be set for build as an unprivileged user"
1871 fi
1872
1873 if [ "${runcmd}" = "echo" ]; then
1874 TOOLCHAIN_MISSING=no
1875 EXTERNAL_TOOLCHAIN=""
1876 else
1877 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1878 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1879 fi
1880 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1881 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1882 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1883 ${runcmd} echo " MACHINE: ${MACHINE}"
1884 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1885 ${runcmd} echo ""
1886 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1887 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1888 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1889 ${runcmd} echo "in either the environment or mk.conf and rerun"
1890 ${runcmd} echo " ${progname} $*"
1891 exit 1
1892 fi
1893
1894 if [ "${MKOBJDIRS}" != "no" ]; then
1895 # Create the top-level object directory.
1896 #
1897 # "make obj NOSUBDIR=" can handle most cases, but it
1898 # can't handle the case where MAKEOBJDIRPREFIX is set
1899 # while the corresponding directory does not exist
1900 # (rules in <bsd.obj.mk> would abort the build). We
1901 # therefore have to handle the MAKEOBJDIRPREFIX case
1902 # without invoking "make obj". The MAKEOBJDIR case
1903 # could be handled either way, but we choose to handle
1904 # it similarly to MAKEOBJDIRPREFIX.
1905 #
1906 if [ -n "${TOP_obj}" ]; then
1907 # It must have been set by the "-M" or "-O"
1908 # command line options, so there's no need to
1909 # use getmakevar
1910 :
1911 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1912 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1913 elif [ -n "$MAKEOBJDIR" ]; then
1914 TOP_obj="$(getmakevar MAKEOBJDIR)"
1915 fi
1916 if [ -n "$TOP_obj" ]; then
1917 ${runcmd} mkdir -p "${TOP_obj}" ||
1918 bomb "Can't create top level object directory" \
1919 "${TOP_obj}"
1920 else
1921 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1922 bomb "Can't create top level object directory" \
1923 "using make obj"
1924 fi
1925
1926 # make obj in tools to ensure that the objdir for "tools"
1927 # is available.
1928 #
1929 ${runcmd} cd tools
1930 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1931 bomb "Failed to make obj in tools"
1932 ${runcmd} cd "${TOP}"
1933 fi
1934
1935 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1936 # and bomb if they have changed from the values we had from the
1937 # command line or environment.
1938 #
1939 # This must be done after creating the top-level object directory.
1940 #
1941 for var in TOOLDIR DESTDIR RELEASEDIR
1942 do
1943 eval oldval=\"\$${var}\"
1944 newval="$(getmakevar $var)"
1945 if ! $do_expertmode; then
1946 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1947 case "$var" in
1948 DESTDIR)
1949 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1950 makeenv="${makeenv} DESTDIR"
1951 ;;
1952 RELEASEDIR)
1953 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1954 makeenv="${makeenv} RELEASEDIR"
1955 ;;
1956 esac
1957 fi
1958 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1959 bomb "Value of ${var} has changed" \
1960 "(was \"${oldval}\", now \"${newval}\")"
1961 fi
1962 eval ${var}=\"\${newval}\"
1963 eval export ${var}
1964 statusmsg2 "${var} path:" "${newval}"
1965 done
1966
1967 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1968 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1969
1970 # Check validity of TOOLDIR and DESTDIR.
1971 #
1972 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1973 bomb "TOOLDIR '${TOOLDIR}' invalid"
1974 fi
1975 removedirs="${TOOLDIR}"
1976
1977 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1978 if ${do_distribution} || ${do_release} || \
1979 [ "${uname_s}" != "NetBSD" ] || \
1980 [ "${uname_m}" != "${MACHINE}" ]; then
1981 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'"
1982 fi
1983 if ! ${do_expertmode}; then
1984 bomb "DESTDIR must != / for non -E (expert) builds"
1985 fi
1986 statusmsg "WARNING: Building to /, in expert mode."
1987 statusmsg " This may cause your system to break! Reasons include:"
1988 statusmsg " - your kernel is not up to date"
1989 statusmsg " - the libraries or toolchain have changed"
1990 statusmsg " YOU HAVE BEEN WARNED!"
1991 else
1992 removedirs="${removedirs} ${DESTDIR}"
1993 fi
1994 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1995 bomb "Must set RELEASEDIR with 'releasekernel=...'"
1996 fi
1997
1998 # If a previous build.sh run used -U (and therefore created a
1999 # METALOG file), then most subsequent build.sh runs must also
2000 # use -U. If DESTDIR is about to be removed, then don't perform
2001 # this check.
2002 #
2003 case "${do_removedirs} ${removedirs} " in
2004 true*" ${DESTDIR} "*)
2005 # DESTDIR is about to be removed
2006 ;;
2007 *)
2008 if [ -e "${DESTDIR}/METALOG" ] && \
2009 [ "${MKUNPRIVED}" = "no" ] ; then
2010 if $do_expertmode; then
2011 warning "A previous build.sh run specified -U"
2012 else
2013 bomb "A previous build.sh run specified -U; you must specify it again now"
2014 fi
2015 fi
2016 ;;
2017 esac
2018
2019 # live-image and install-image targets require binary sets
2020 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
2021 # If release operation is specified with live-image or install-image,
2022 # the release op should be performed with -U for later image ops.
2023 #
2024 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
2025 [ "${MKUNPRIVED}" = "no" ] ; then
2026 bomb "-U must be specified on building release to create images later"
2027 fi
2028 }
2029
2030
2031 createmakewrapper()
2032 {
2033 # Remove the target directories.
2034 #
2035 if ${do_removedirs}; then
2036 for f in ${removedirs}; do
2037 statusmsg "Removing ${f}"
2038 ${runcmd} rm -r -f "${f}"
2039 done
2040 fi
2041
2042 # Recreate $TOOLDIR.
2043 #
2044 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
2045 bomb "mkdir of '${TOOLDIR}/bin' failed"
2046
2047 # If we did not previously rebuild ${toolprefix}make, then
2048 # check whether $make is still valid and the same as the output
2049 # from print_tooldir_make. If not, then rebuild make now. A
2050 # possible reason for this being necessary is that the actual
2051 # value of TOOLDIR might be different from the value guessed
2052 # before the top level obj dir was created.
2053 #
2054 if ! ${done_rebuildmake} && \
2055 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
2056 then
2057 rebuildmake
2058 fi
2059
2060 # Install ${toolprefix}make if it was built.
2061 #
2062 if ${done_rebuildmake}; then
2063 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
2064 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
2065 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
2066 make="${TOOLDIR}/bin/${toolprefix}make"
2067 statusmsg "Created ${make}"
2068 fi
2069
2070 # Build a ${toolprefix}make wrapper script, usable by hand as
2071 # well as by build.sh.
2072 #
2073 if [ -z "${makewrapper}" ]; then
2074 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
2075 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
2076 fi
2077
2078 ${runcmd} rm -f "${makewrapper}"
2079 if [ "${runcmd}" = "echo" ]; then
2080 echo 'cat <<EOF >'${makewrapper}
2081 makewrapout=
2082 else
2083 makewrapout=">>\${makewrapper}"
2084 fi
2085
2086 case "${KSH_VERSION:-${SH_VERSION}}" in
2087 *PD\ KSH*|*MIRBSD\ KSH*)
2088 set +o braceexpand
2089 ;;
2090 esac
2091
2092 eval cat <<EOF ${makewrapout}
2093 #! ${HOST_SH}
2094 # Set proper variables to allow easy "make" building of a NetBSD subtree.
2095 # Generated from: \$NetBSD: build.sh,v 1.385 2024/12/20 15:56:45 riastradh Exp $
2096 # with these arguments: ${_args}
2097 #
2098
2099 EOF
2100 {
2101 sorted_vars="$(for var in ${makeenv}; do echo "${var}" ; done \
2102 | sort -u )"
2103 for var in ${sorted_vars}; do
2104 eval val=\"\${${var}}\"
2105 eval is_set=\"\${${var}+set}\"
2106 if [ -z "${is_set}" ]; then
2107 echo "unset ${var}"
2108 else
2109 qval="$(shell_quote "${val}")"
2110 echo "${var}=${qval}; export ${var}"
2111 fi
2112 done
2113
2114 cat <<EOF
2115
2116 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
2117 EOF
2118 } | eval cat "${makewrapout}"
2119 [ "${runcmd}" = "echo" ] && echo EOF
2120 ${runcmd} chmod +x "${makewrapper}"
2121 statusmsg2 "Updated makewrapper:" "${makewrapper}"
2122 }
2123
2124 make_in_dir()
2125 {
2126 local dir="$1"
2127 local op="$2"
2128 ${runcmd} cd "${dir}" ||
2129 bomb "Failed to cd to \"${dir}\""
2130 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2131 bomb "Failed to make ${op} in \"${dir}\""
2132 ${runcmd} cd "${TOP}" ||
2133 bomb "Failed to cd back to \"${TOP}\""
2134 }
2135
2136 buildtools()
2137 {
2138 if [ "${MKOBJDIRS}" != "no" ]; then
2139 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
2140 bomb "Failed to make obj-tools"
2141 fi
2142 if [ "${MKUPDATE}" = "no" ]; then
2143 make_in_dir tools cleandir
2144 fi
2145 make_in_dir tools build_install
2146 statusmsg "Tools built to ${TOOLDIR}"
2147 }
2148
2149 buildlibs()
2150 {
2151 if [ "${MKOBJDIRS}" != "no" ]; then
2152 ${runcmd} "${makewrapper}" ${parallel} obj ||
2153 bomb "Failed to make obj"
2154 fi
2155 if [ "${MKUPDATE}" = "no" ]; then
2156 make_in_dir lib cleandir
2157 fi
2158 make_in_dir . do-distrib-dirs
2159 make_in_dir . includes
2160 make_in_dir . do-lib
2161 statusmsg "libs built"
2162 }
2163
2164 getkernelconf()
2165 {
2166 kernelconf="$1"
2167 if [ "${MKOBJDIRS}" != "no" ]; then
2168 # The correct value of KERNOBJDIR might
2169 # depend on a prior "make obj" in
2170 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
2171 #
2172 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
2173 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
2174 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
2175 fi
2176 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
2177 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
2178 case "${kernelconf}" in
2179 */*)
2180 kernelconfpath="${kernelconf}"
2181 kernelconfname="${kernelconf##*/}"
2182 ;;
2183 *)
2184 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
2185 kernelconfname="${kernelconf}"
2186 ;;
2187 esac
2188 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
2189 }
2190
2191 diskimage()
2192 {
2193 ARG="$(echo $1 | tr '[:lower:]' '[:upper:]')"
2194 [ -f "${DESTDIR}/etc/mtree/set.base" ] ||
2195 bomb "The release binaries must be built first"
2196 kerneldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
2197 kernel="${kerneldir}/netbsd-${ARG}.gz"
2198 [ -f "${kernel}" ] ||
2199 bomb "The kernel ${kernel} must be built first"
2200 make_in_dir "${NETBSDSRCDIR}/etc" "smp_${1}"
2201 }
2202
2203 buildkernel()
2204 {
2205 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
2206 # Building tools every time we build a kernel is clearly
2207 # unnecessary. We could try to figure out whether rebuilding
2208 # the tools is necessary this time, but it doesn't seem worth
2209 # the trouble. Instead, we say it's the user's responsibility
2210 # to rebuild the tools if necessary.
2211 #
2212 statusmsg "Building kernel without building new tools"
2213 buildkernelwarned=true
2214 fi
2215 getkernelconf $1
2216 statusmsg2 "Building kernel:" "${kernelconf}"
2217 statusmsg2 "Build directory:" "${kernelbuildpath}"
2218 ${runcmd} mkdir -p "${kernelbuildpath}" ||
2219 bomb "Cannot mkdir: ${kernelbuildpath}"
2220 if [ "${MKUPDATE}" = "no" ]; then
2221 make_in_dir "${kernelbuildpath}" cleandir
2222 fi
2223 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
2224 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first"
2225 CONFIGOPTS=$(getmakevar CONFIGOPTS)
2226 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" ${CONFIGOPTS} \
2227 -b "${kernelbuildpath}" -s "${TOP}/sys" ${configopts} \
2228 "${kernelconfpath}" ||
2229 bomb "${toolprefix}config failed for ${kernelconf}"
2230 make_in_dir "${kernelbuildpath}" depend
2231 make_in_dir "${kernelbuildpath}" all
2232
2233 if [ "${runcmd}" != "echo" ]; then
2234 statusmsg "Kernels built from ${kernelconf}:"
2235 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
2236 for kern in ${kernlist:-netbsd}; do
2237 [ -f "${kernelbuildpath}/${kern}" ] && \
2238 echo " ${kernelbuildpath}/${kern}"
2239 done | tee -a "${results}"
2240 fi
2241 }
2242
2243 releasekernel()
2244 {
2245 getkernelconf $1
2246 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
2247 ${runcmd} mkdir -p "${kernelreldir}"
2248 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
2249 for kern in ${kernlist:-netbsd}; do
2250 builtkern="${kernelbuildpath}/${kern}"
2251 [ -f "${builtkern}" ] || continue
2252 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
2253 statusmsg2 "Kernel copy:" "${releasekern}"
2254 if [ "${runcmd}" = "echo" ]; then
2255 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
2256 else
2257 gzip -c -9 < "${builtkern}" > "${releasekern}"
2258 fi
2259 done
2260 }
2261
2262 buildkernels()
2263 {
2264 allkernels=$( runcmd= make_in_dir etc '-V ${ALL_KERNELS}' )
2265 for k in $allkernels; do
2266 buildkernel "${k}"
2267 done
2268 }
2269
2270 buildmodules()
2271 {
2272 setmakeenv MKBINUTILS no
2273 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
2274 # Building tools every time we build modules is clearly
2275 # unnecessary as well as a kernel.
2276 #
2277 statusmsg "Building modules without building new tools"
2278 buildmoduleswarned=true
2279 fi
2280
2281 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
2282 if [ "${MKOBJDIRS}" != "no" ]; then
2283 make_in_dir sys/modules obj
2284 fi
2285 if [ "${MKUPDATE}" = "no" ]; then
2286 make_in_dir sys/modules cleandir
2287 fi
2288 make_in_dir sys/modules dependall
2289 make_in_dir sys/modules install
2290
2291 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
2292 }
2293
2294 builddtb()
2295 {
2296 statusmsg "Building devicetree blobs for NetBSD/${MACHINE} ${DISTRIBVER}"
2297 if [ "${MKOBJDIRS}" != "no" ]; then
2298 make_in_dir sys/dtb obj
2299 fi
2300 if [ "${MKUPDATE}" = "no" ]; then
2301 make_in_dir sys/dtb cleandir
2302 fi
2303 make_in_dir sys/dtb dependall
2304 make_in_dir sys/dtb install
2305
2306 statusmsg "Successful build of devicetree blobs for NetBSD/${MACHINE} ${DISTRIBVER}"
2307 }
2308
2309 buildpkg()
2310 {
2311 local catpkg
2312 local pkgroot
2313 local makejobsarg
2314 local makejobsvar
2315 local quiet
2316 local opsys_version
2317
2318 catpkg="$1"
2319
2320 pkgroot="${TOP_objdir:-${TOP}}/pkgroot"
2321 ${runcmd} mkdir -p "${pkgroot}" ||
2322 bomb "Can't create package root" "${pkgroot}"
2323
2324 # Get a symlink-free absolute path to pkg -- pkgsrc wants this.
2325 #
2326 # XXX See TOP= above regarding pwd -P.
2327 pkgroot=$(unset PWD; cd "${pkgroot}" &&
2328 ((exec pwd -P 2>/dev/null) || (exec pwd 2>/dev/null)))
2329
2330 case $parallel in
2331 "-j "*)
2332 makejobsarg="--make-jobs ${parallel#-j }"
2333 makejobsvar="MAKE_JOBS=${parallel#-j }"
2334 ;;
2335 *) makejobsarg=""
2336 makejobsvar=""
2337 ;;
2338 esac
2339
2340 if [ "${MAKEVERBOSE}" -eq 0 ]; then
2341 quiet="--quiet"
2342 else
2343 quiet=""
2344 fi
2345
2346 # Derived from pkgsrc/mk/bsd.prefs.mk rev. 1.451.
2347 opsys_version=$(echo "${DISTRIBVER}" |
2348 awk -F. '{major=int($1); minor=int($2); if (minor>=100) minor=99; patch=int($3); if (patch>=100) patch=99; printf "%02d%02d%02d", major, minor, patch}')
2349
2350 # Bootstrap pkgsrc if needed.
2351 #
2352 # XXX Redo this if it's out-of-date, not just if it's missing.
2353 if ! [ -x "${pkgroot}/pkg/bin/bmake" ]; then
2354 statusmsg "Bootstrapping pkgsrc"
2355
2356 cat >"${pkgroot}/mk.conf-fragment" <<EOF
2357 USE_CROSS_COMPILE?= no
2358 TOOLDIR= ${TOOLDIR}
2359 CROSS_DESTDIR= ${DESTDIR}
2360 CROSS_MACHINE_ARCH= ${MACHINE_ARCH}
2361 CROSS_OPSYS= NetBSD
2362 CROSS_OS_VERSION= ${DISTRIBVER}
2363 CROSS_OPSYS_VERSION= ${opsys_version}
2364 CROSS_LOWER_OPSYS= netbsd
2365 CROSS_LOWER_OPSYS_VERSUFFIX= # empty
2366 CROSS_LOWER_OS_VARIANT= # empty
2367 CROSS_LOWER_VARIANT_VERSION= # empty
2368 CROSS_LOWER_VENDOR= # empty
2369 CROSS_OBJECT_FMT= ELF
2370
2371 ALLOW_VULNERABLE_PACKAGES= yes
2372 BINPKG_SITES= # empty
2373 FAILOVER_FETCH= yes
2374 FETCH_TIMEOUT= 1800
2375 PASSIVE_FETCH= yes
2376
2377 DISTDIR= ${pkgroot}/distfiles
2378 PACKAGES= ${pkgroot}/packages
2379 WRKOBJDIR= ${pkgroot}/work
2380
2381 # pkgsrc cross-builds are not set up to support native X, but also part
2382 # of the point of pkgsrc cross-build infrastructure is to not need
2383 # native X any more.
2384 #
2385 # (If you fix this, remove the bomb in build.sh pkg=... on MKX11=yes.)
2386 X11_TYPE= modular
2387
2388 .-include "${MAKECONF}"
2389
2390 MKDEBUG= no # interferes with pkgsrc builds
2391 EOF
2392
2393 # XXX Set --abi for mips and whatever else needs it?
2394 # XXX Unprivileged native tools, privileged cross.
2395 (cd "${PKGSRCDIR}" && clearmakeenv && ./bootstrap/bootstrap \
2396 ${makejobsarg} \
2397 --mk-fragment "${pkgroot}/mk.conf-fragment" \
2398 --prefix "${pkgroot}/pkg" \
2399 ${quiet} \
2400 --unprivileged \
2401 --workdir "${pkgroot}/bootwork") \
2402 || bomb "Failed to bootstrap pkgsrc"
2403 fi
2404
2405 # Build the package.
2406 (cd "${PKGSRCDIR}/${catpkg}" && clearmakeenv && \
2407 "${pkgroot}/pkg/bin/bmake" package \
2408 USE_CROSS_COMPILE=yes \
2409 ${makejobsvar}) \
2410 || bomb "Failed to build ${catpkg}"
2411 }
2412
2413 installmodules()
2414 {
2415 dir="$1"
2416 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
2417 bomb "Failed to make installmodules to ${dir}"
2418 statusmsg "Successful installmodules to ${dir}"
2419 }
2420
2421 installworld()
2422 {
2423 dir="$1"
2424 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
2425 bomb "Failed to make installworld to ${dir}"
2426 statusmsg "Successful installworld to ${dir}"
2427 }
2428
2429 # Run rump build&link tests.
2430 #
2431 # To make this feasible for running without having to install includes and
2432 # libraries into destdir (i.e. quick), we only run ld. This is possible
2433 # since the rump kernel is a closed namespace apart from calls to rumpuser.
2434 # Therefore, if ld complains only about rumpuser symbols, rump kernel
2435 # linking was successful.
2436 #
2437 # We test that rump links with a number of component configurations.
2438 # These attempt to mimic what is encountered in the full build.
2439 # See list below. The list should probably be either autogenerated
2440 # or managed elsewhere; keep it here until a better idea arises.
2441 #
2442 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
2443 #
2444
2445 # XXX: uwe: kern/56599 - while riastradh addressed librump problems,
2446 # there are still unwanted dependencies:
2447 # net -> net_net
2448 # vfs -> fifo
2449
2450 # -lrumpvfs -> $LRUMPVFS for now
2451 LRUMPVFS="-lrumpvfs -lrumpvfs_nofifofs"
2452
2453 RUMP_LIBSETS="
2454 -lrump,
2455 -lrumpvfs
2456 --no-whole-archive -lrumpvfs_nofifofs -lrump,
2457 -lrumpkern_tty
2458 --no-whole-archive $LRUMPVFS -lrump,
2459 -lrumpfs_tmpfs
2460 --no-whole-archive $LRUMPVFS -lrump,
2461 -lrumpfs_ffs -lrumpfs_msdos
2462 --no-whole-archive $LRUMPVFS -lrumpdev_disk -lrumpdev -lrump,
2463 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet
2464 --no-whole-archive -lrump,
2465 -lrumpfs_nfs
2466 --no-whole-archive $LRUMPVFS
2467 -lrumpnet_sockin -lrumpnet_virtif -lrumpnet_netinet
2468 --start-group -lrumpnet_net -lrumpnet --end-group -lrump,
2469 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_rnd -lrumpdev_dm
2470 --no-whole-archive $LRUMPVFS -lrumpdev_disk -lrumpdev -lrumpkern_crypto -lrump
2471 "
2472
2473 dorump()
2474 {
2475 local doclean=""
2476 local doobjs=""
2477
2478 export RUMPKERN_ONLY=1
2479 # create obj and distrib dirs
2480 if [ "${MKOBJDIRS}" != "no" ]; then
2481 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
2482 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
2483 fi
2484 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
2485 || bomb "Could not create distrib-dirs"
2486
2487 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
2488 targlist="${doclean} ${doobjs} dependall install"
2489 # optimize: for test we build only static libs (3x test speedup)
2490 if [ "${1}" = "rumptest" ] ; then
2491 setmakeenv NOPIC 1
2492 setmakeenv NOPROFILE 1
2493 fi
2494 for cmd in ${targlist} ; do
2495 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
2496 done
2497
2498 # if we just wanted to build & install rump, we're done
2499 [ "${1}" != "rumptest" ] && return
2500
2501 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
2502 || bomb "cd to rumpkern failed"
2503 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
2504 # one little, two little, three little backslashes ...
2505 md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )"
2506 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
2507 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
2508
2509 local oIFS="${IFS}"
2510 IFS=","
2511 for set in ${RUMP_LIBSETS} ; do
2512 IFS="${oIFS}"
2513 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
2514 -static --whole-archive ${set} --no-whole-archive -lpthread -lc 2>&1 -o /tmp/rumptest.$$ | \
2515 awk -v quirks="${md_quirks}" '
2516 /undefined reference/ &&
2517 !/more undefined references.*follow/{
2518 if (match($NF,
2519 "`(rumpuser_|rumpcomp_|__" quirks ")") == 0)
2520 fails[NR] = $0
2521 }
2522 /cannot find -l/{fails[NR] = $0}
2523 /cannot open output file/{fails[NR] = $0}
2524 END{
2525 for (x in fails)
2526 print fails[x]
2527 exit x!=0
2528 }'
2529 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
2530 done
2531 statusmsg "Rump build&link tests successful"
2532 }
2533
2534 repro_date() {
2535 # try the bsd date fail back the linux one
2536 date -u -r "$1" 2> /dev/null || date -u -d "@$1"
2537 }
2538
2539 setup_mkrepro()
2540 {
2541 local quiet="$1"
2542
2543 if [ ${MKREPRO-no} != "yes" ]; then
2544 return
2545 fi
2546 if [ ${MKREPRO_TIMESTAMP-0} -ne 0 ]; then
2547 return
2548 fi
2549
2550 local dirs=${NETBSDSRCDIR-/usr/src}/
2551 if [ ${MKX11-no} = "yes" ]; then
2552 dirs="$dirs ${X11SRCDIR-/usr/xsrc}/"
2553 fi
2554
2555 MKREPRO_TIMESTAMP=0
2556 NETBSD_REVISIONID=
2557 local d
2558 local t
2559 local tag
2560 local vcs
2561 for d in ${dirs}; do
2562 if [ -d "${d}CVS" ]; then
2563 local cvslatest=$(print_tooldir_program cvslatest)
2564 if [ ! -x "${cvslatest}" ]; then
2565 buildtools
2566 fi
2567 local nbdate=$(print_tooldir_program date)
2568
2569 local cvslatestflags=
2570 if ${do_expertmode}; then
2571 cvslatestflags=-i
2572 fi
2573
2574 t=$("${cvslatest}" ${cvslatestflags} "${d}")
2575 if [ -f "${d}CVS/Tag" ]; then
2576 tag=$( sed 's/^T//' < "${d}CVS/Tag" )
2577 else
2578 tag=HEAD
2579 fi
2580 NETBSD_REVISIONID="${tag}-"$(${nbdate} -u -r ${t} '+%Y%m%d%H%M%S')
2581 vcs=cvs
2582 elif [ -d "${d}.git" -o -f "${d}.git" ]; then
2583 t=$(cd "${d}" && git log -1 --format=%ct)
2584 NETBSD_REVISIONID=$(cd "${d}" && git log -1 --format=%H)
2585 vcs=git
2586 elif [ -d "${d}.hg" ]; then
2587 t=$(hg --repo "$d" log -r . --template '{date.unixtime}\n')
2588 NETBSD_REVISIONID=$(hg --repo "$d" identify --template '{id}\n')
2589 vcs=hg
2590 elif [ -f "${d}.hg_archival.txt" ]; then
2591 local stat=$(print_tooldir_program stat)
2592 if [ ! -x "${stat}" ]; then
2593 buildtools
2594 fi
2595
2596 t=$("${stat}" -t '%s' -f '%m' "${d}.hg_archival.txt")
2597 NETBSD_REVISIONID=$(awk '/^node:/ { print $2 }' < "${d}.hg_archival.txt")
2598 vcs=hg
2599 else
2600 bomb "Cannot determine VCS for '$d'"
2601 fi
2602
2603 if [ -z "$t" ]; then
2604 bomb "Failed to get timestamp for vcs=$vcs in '$d'"
2605 fi
2606
2607 #echo "latest $d $vcs $t"
2608 if [ "$t" -gt "$MKREPRO_TIMESTAMP" ]; then
2609 MKREPRO_TIMESTAMP="$t"
2610 fi
2611 done
2612
2613 [ "${MKREPRO_TIMESTAMP}" -ne 0 ] || bomb "Failed to compute timestamp"
2614 if [ -z "${quiet}" ]; then
2615 statusmsg2 "MKREPRO_TIMESTAMP" \
2616 "$(repro_date "${MKREPRO_TIMESTAMP}")"
2617 fi
2618 export MKREPRO MKREPRO_TIMESTAMP NETBSD_REVISIONID
2619 }
2620
2621 main()
2622 {
2623 initdefaults
2624 _args=$@
2625 parseoptions "$@"
2626
2627 sanitycheck
2628
2629 build_start=$(date)
2630 statusmsg2 "${progname} command:" "$0 $*"
2631 statusmsg2 "${progname} started:" "${build_start}"
2632 statusmsg2 "NetBSD version:" "${DISTRIBVER}"
2633 statusmsg2 "MACHINE:" "${MACHINE}"
2634 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
2635 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
2636 statusmsg2 "HOST_SH:" "${HOST_SH}"
2637 if [ -n "${BUILDID}" ]; then
2638 statusmsg2 "BUILDID:" "${BUILDID}"
2639 fi
2640 if [ -n "${BUILDINFO}" ]; then
2641 printf "%b\n" "${BUILDINFO}" | \
2642 while read -r line ; do
2643 [ -s "${line}" ] && continue
2644 statusmsg2 "BUILDINFO:" "${line}"
2645 done
2646 fi
2647
2648 if [ -n "${MAKECONF+1}" ] && [ -z "${MAKECONF}" ]; then
2649 bomb "MAKECONF must not be empty"
2650 fi
2651
2652 rebuildmake
2653 validatemakeparams
2654 createmakewrapper
2655 setup_mkrepro
2656
2657 # Perform the operations.
2658 #
2659 for op in ${operations}; do
2660 case "${op}" in
2661
2662 makewrapper)
2663 # no-op
2664 ;;
2665
2666 tools)
2667 buildtools
2668 ;;
2669 libs)
2670 buildlibs
2671 ;;
2672
2673 sets)
2674 statusmsg "Building sets from pre-populated ${DESTDIR}"
2675 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2676 bomb "Failed to make ${op}"
2677 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
2678 statusmsg "Built sets to ${setdir}"
2679 ;;
2680
2681 build|distribution|release)
2682 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2683 bomb "Failed to make ${op}"
2684 statusmsg "Successful make ${op}"
2685 ;;
2686
2687 cleandir|obj|sourcesets|syspkgs|params|show-params)
2688 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2689 bomb "Failed to make ${op}"
2690 statusmsg "Successful make ${op}"
2691 ;;
2692
2693 iso-image|iso-image-source)
2694 ${runcmd} "${makewrapper}" ${parallel} \
2695 CDEXTRA="$CDEXTRA" ${op} ||
2696 bomb "Failed to make ${op}"
2697 statusmsg "Successful make ${op}"
2698 ;;
2699
2700 live-image|install-image)
2701 # install-image and live-image require mtree spec files
2702 # built with MKUNPRIVED. Assume MKUNPRIVED build has been
2703 # performed if METALOG file is created in DESTDIR.
2704 if [ ! -e "${DESTDIR}/METALOG" ] ; then
2705 bomb "The release binaries must have been built with -U to create images"
2706 fi
2707 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2708 bomb "Failed to make ${op}"
2709 statusmsg "Successful make ${op}"
2710 ;;
2711 kernel=*)
2712 arg=${op#*=}
2713 buildkernel "${arg}"
2714 ;;
2715 kernel.gdb=*)
2716 arg=${op#*=}
2717 configopts="-D DEBUG=-g"
2718 buildkernel "${arg}"
2719 ;;
2720 releasekernel=*)
2721 arg=${op#*=}
2722 releasekernel "${arg}"
2723 ;;
2724
2725 kernels)
2726 buildkernels
2727 ;;
2728
2729 disk-image=*)
2730 arg=${op#*=}
2731 diskimage "${arg}"
2732 ;;
2733
2734 dtb)
2735 builddtb
2736 ;;
2737
2738 modules)
2739 buildmodules
2740 ;;
2741
2742 pkg=*)
2743 arg=${op#*=}
2744 if ! [ -d "$PKGSRCDIR"/"$arg" ]; then
2745 bomb "no such package ${arg}"
2746 fi
2747 buildpkg "${arg}"
2748 ;;
2749
2750 installmodules=*)
2751 arg=${op#*=}
2752 if [ "${arg}" = "/" ] && \
2753 ( [ "${uname_s}" != "NetBSD" ] || \
2754 [ "${uname_m}" != "${MACHINE}" ] ); then
2755 bomb "'${op}' must != / for cross builds"
2756 fi
2757 installmodules "${arg}"
2758 ;;
2759
2760 install=*)
2761 arg=${op#*=}
2762 if [ "${arg}" = "/" ] && \
2763 ( [ "${uname_s}" != "NetBSD" ] || \
2764 [ "${uname_m}" != "${MACHINE}" ] ); then
2765 bomb "'${op}' must != / for cross builds"
2766 fi
2767 installworld "${arg}"
2768 ;;
2769
2770 rump)
2771 make_in_dir . do-distrib-dirs
2772 make_in_dir . includes
2773 make_in_dir lib/csu dependall
2774 make_in_dir lib/csu install
2775 make_in_dir external/gpl3/gcc/lib/libgcc dependall
2776 make_in_dir external/gpl3/gcc/lib/libgcc install
2777 dorump "${op}"
2778 ;;
2779
2780 rumptest)
2781 dorump "${op}"
2782 ;;
2783
2784 *)
2785 bomb "Unknown OPERATION '${op}'"
2786 ;;
2787
2788 esac
2789 done
2790
2791 statusmsg2 "${progname} ended:" "$(date)"
2792 if [ -s "${results}" ]; then
2793 echo "===> Summary of results:"
2794 sed -e 's/^===>//;s/^/ /' "${results}"
2795 echo "===> ."
2796 fi
2797 }
2798
2799 main "$@"
2800