build.sh revision 1.384 1 #! /usr/bin/env sh
2 # $NetBSD: build.sh,v 1.384 2024/12/20 14:31:49 martin 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 }
1618
1619 # print_tooldir_program --
1620 # Try to find and show a path to an existing
1621 # ${TOOLDIR}/bin/${toolprefix}program
1622 #
1623 print_tooldir_program()
1624 {
1625 local possible_TOP_OBJ
1626 local possible_TOOLDIR
1627 local possible_program
1628 local tooldir_program
1629 local program=${1}
1630
1631 if [ -n "${TOOLDIR}" ]; then
1632 echo "${TOOLDIR}/bin/${toolprefix}${program}"
1633 return
1634 fi
1635
1636 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
1637 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
1638 #
1639 local host_ostype="${uname_s}-$(
1640 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1641 )-$(
1642 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
1643 )"
1644
1645 # Look in a few potential locations for
1646 # ${possible_TOOLDIR}/bin/${toolprefix}${program}.
1647 # If we find it, then set possible_program.
1648 #
1649 # In the usual case (without interference from environment
1650 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
1651 # "${_SRC_TOP_OBJ_}/tooldir.${host_ostype}".
1652 #
1653 # In practice it's difficult to figure out the correct value
1654 # for _SRC_TOP_OBJ_. In the easiest case, when the -M or -O
1655 # options were passed to build.sh, then ${TOP_objdir} will be
1656 # the correct value. We also try a few other possibilities, but
1657 # we do not replicate all the logic of <bsd.obj.mk>.
1658 #
1659 for possible_TOP_OBJ in \
1660 "${TOP_objdir}" \
1661 "${MAKEOBJDIRPREFIX:+${MAKEOBJDIRPREFIX}${TOP}}" \
1662 "${TOP}" \
1663 "${TOP}/obj" \
1664 "${TOP}/obj.${MACHINE}"
1665 do
1666 [ -n "${possible_TOP_OBJ}" ] || continue
1667 possible_TOOLDIR="${possible_TOP_OBJ}/tooldir.${host_ostype}"
1668 possible_program="${possible_TOOLDIR}/bin/${toolprefix}${program}"
1669 if [ -x "${possible_program}" ]; then
1670 echo ${possible_program}
1671 return;
1672 fi
1673 done
1674 echo ""
1675 }
1676
1677 # print_tooldir_make --
1678 # Try to find and show a path to an existing
1679 # ${TOOLDIR}/bin/${toolprefix}make, for use by rebuildmake() before a
1680 # new version of ${toolprefix}make has been built.
1681 #
1682 # * If TOOLDIR was set in the environment or on the command line, use
1683 # that value.
1684 # * Otherwise try to guess what TOOLDIR would be if not overridden by
1685 # /etc/mk.conf, and check whether the resulting directory contains
1686 # a copy of ${toolprefix}make (this should work for everybody who
1687 # doesn't override TOOLDIR via /etc/mk.conf);
1688 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
1689 # in the PATH (this might accidentally find a version of make that
1690 # does not understand the syntax used by NetBSD make, and that will
1691 # lead to failure in the next step);
1692 # * If a copy of make was found above, try to use it with
1693 # nobomb_getmakevar to find the correct value for TOOLDIR, and believe the
1694 # result only if it's a directory that already exists;
1695 # * If a value of TOOLDIR was found above, and if
1696 # ${TOOLDIR}/bin/${toolprefix}make exists, show that value.
1697 #
1698 print_tooldir_make()
1699 {
1700 local possible_make
1701 local possible_TOOLDIR
1702 local tooldir_make
1703
1704 possible_make=$(print_tooldir_program make)
1705 # If the above didn't work, search the PATH for a suitable
1706 # ${toolprefix}make, nbmake, bmake, or make.
1707 #
1708 : ${possible_make:=$(find_in_PATH ${toolprefix}make '')}
1709 : ${possible_make:=$(find_in_PATH nbmake '')}
1710 : ${possible_make:=$(find_in_PATH bmake '')}
1711 : ${possible_make:=$(find_in_PATH make '')}
1712
1713 # At this point, we don't care whether possible_make is in the
1714 # correct TOOLDIR or not; we simply want it to be usable by
1715 # getmakevar to help us find the correct TOOLDIR.
1716 #
1717 # Use ${possible_make} with nobomb_getmakevar to try to find
1718 # the value of TOOLDIR. Believe the result only if it's
1719 # a directory that already exists and contains bin/${toolprefix}make.
1720 #
1721 if [ -x "${possible_make}" ]; then
1722 possible_TOOLDIR="$(
1723 make="${possible_make}" \
1724 nobomb_getmakevar TOOLDIR 2>/dev/null
1725 )"
1726 if [ $? = 0 ] && [ -n "${possible_TOOLDIR}" ] \
1727 && [ -d "${possible_TOOLDIR}" ];
1728 then
1729 tooldir_make="${possible_TOOLDIR}/bin/${toolprefix}make"
1730 if [ -x "${tooldir_make}" ]; then
1731 echo "${tooldir_make}"
1732 return 0
1733 fi
1734 fi
1735 fi
1736 return 1
1737 }
1738
1739 # rebuildmake --
1740 # Rebuild nbmake in a temporary directory if necessary. Sets $make
1741 # to a path to the nbmake executable. Sets done_rebuildmake=true
1742 # if nbmake was rebuilt.
1743 #
1744 # There is a cyclic dependency between building nbmake and choosing
1745 # TOOLDIR: TOOLDIR may be affected by settings in /etc/mk.conf, so we
1746 # would like to use getmakevar to get the value of TOOLDIR; but we can't
1747 # use getmakevar before we have an up to date version of nbmake; we
1748 # might already have an up to date version of nbmake in TOOLDIR, but we
1749 # don't yet know where TOOLDIR is.
1750 #
1751 # The default value of TOOLDIR also depends on the location of the top
1752 # level object directory, so $(getmakevar TOOLDIR) invoked before or
1753 # after making the top level object directory may produce different
1754 # results.
1755 #
1756 # Strictly speaking, we should do the following:
1757 #
1758 # 1. build a new version of nbmake in a temporary directory;
1759 # 2. use the temporary nbmake to create the top level obj directory;
1760 # 3. use $(getmakevar TOOLDIR) with the temporary nbmake to
1761 # get the correct value of TOOLDIR;
1762 # 4. move the temporary nbmake to ${TOOLDIR}/bin/nbmake.
1763 #
1764 # However, people don't like building nbmake unnecessarily if their
1765 # TOOLDIR has not changed since an earlier build. We try to avoid
1766 # rebuilding a temporary version of nbmake by taking some shortcuts to
1767 # guess a value for TOOLDIR, looking for an existing version of nbmake
1768 # in that TOOLDIR, and checking whether that nbmake is newer than the
1769 # sources used to build it.
1770 #
1771 rebuildmake()
1772 {
1773 make="$(print_tooldir_make)"
1774 if [ -n "${make}" ] && [ -x "${make}" ]; then
1775 for f in usr.bin/make/*.[ch]; do
1776 if [ "${f}" -nt "${make}" ]; then
1777 statusmsg "${make} outdated" \
1778 "(older than ${f}), needs building."
1779 do_rebuildmake=true
1780 break
1781 fi
1782 done
1783 else
1784 statusmsg "No \$TOOLDIR/bin/${toolprefix}make, needs building."
1785 do_rebuildmake=true
1786 fi
1787
1788 # Build bootstrap ${toolprefix}make if needed.
1789 if ! ${do_rebuildmake}; then
1790 return
1791 fi
1792
1793 # Silent configure with MAKEVERBOSE==0
1794 if [ ${MAKEVERBOSE:-2} -eq 0 ]; then
1795 configure_args=--silent
1796 fi
1797
1798 statusmsg "Bootstrapping ${toolprefix}make"
1799 ${runcmd} cd "${tmpdir}"
1800 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1801 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1802 ${HOST_SH} "${TOP}/tools/make/configure" ${configure_args} ||
1803 ( cp ${tmpdir}/config.log ${tmpdir}-config.log
1804 bomb "Configure of ${toolprefix}make failed, see ${tmpdir}-config.log for details" )
1805 ${runcmd} ${HOST_SH} buildmake.sh ||
1806 bomb "Build of ${toolprefix}make failed"
1807 make="${tmpdir}/${toolprefix}make"
1808 ${runcmd} cd "${TOP}"
1809 ${runcmd} rm -f usr.bin/make/*.o
1810 done_rebuildmake=true
1811 }
1812
1813 # validatemakeparams --
1814 # Perform some late sanity checks, after rebuildmake,
1815 # but before createmakewrapper or any real work.
1816 #
1817 # Creates the top-level obj directory, because that
1818 # is needed by some of the sanity checks.
1819 #
1820 # Shows status messages reporting the values of several variables.
1821 #
1822 validatemakeparams()
1823 {
1824 # Determine MAKECONF first, and set in the makewrapper.
1825 # If set in the environment, then use that.
1826 # else if ./mk.conf exists, then set MAKECONF to that,
1827 # else use the default from share/mk/bsd.own.mk (/etc/mk.conf).
1828 #
1829 if [ -n "${MAKECONF+1}" ]; then
1830 setmakeenv MAKECONF "${MAKECONF}"
1831 statusmsg2 "getenv MAKECONF:" "${MAKECONF}"
1832 elif [ -f "${TOP}/mk.conf" ]; then
1833 setmakeenv MAKECONF "${TOP}/mk.conf"
1834 statusmsg2 "mk.conf MAKECONF:" "${MAKECONF}"
1835 else
1836 MAKECONF=$(getmakevar MAKECONF)
1837 setmakeenv MAKECONF "${MAKECONF}"
1838 statusmsg2 "share/mk MAKECONF:" "${MAKECONF}"
1839 fi
1840 if [ -z "${MAKECONF}" ]; then
1841 bomb "MAKECONF must not be empty"
1842 elif [ -e "${MAKECONF}" ]; then
1843 statusmsg2 "MAKECONF file:" "${MAKECONF}"
1844 else
1845 statusmsg2 "MAKECONF file:" "${MAKECONF} (File not found)"
1846 fi
1847
1848 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE.
1849 # These may be set as build.sh options or in "mk.conf".
1850 # Don't export them as they're only used for tests in build.sh.
1851 #
1852 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1853 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1854 MKUPDATE=$(getmakevar MKUPDATE)
1855
1856 # Non-root should always use either the -U or -E flag.
1857 #
1858 if ! ${do_expertmode} && \
1859 [ "$id_u" -ne 0 ] && \
1860 [ "${MKUNPRIVED}" = "no" ] ; then
1861 bomb "-U or -E must be set for build as an unprivileged user"
1862 fi
1863
1864 if [ "${runcmd}" = "echo" ]; then
1865 TOOLCHAIN_MISSING=no
1866 EXTERNAL_TOOLCHAIN=""
1867 else
1868 TOOLCHAIN_MISSING=$(bomb_getmakevar TOOLCHAIN_MISSING)
1869 EXTERNAL_TOOLCHAIN=$(bomb_getmakevar EXTERNAL_TOOLCHAIN)
1870 fi
1871 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1872 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1873 ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
1874 ${runcmd} echo " MACHINE: ${MACHINE}"
1875 ${runcmd} echo " MACHINE_ARCH: ${MACHINE_ARCH}"
1876 ${runcmd} echo ""
1877 ${runcmd} echo "All builds for this platform should be done via a traditional make"
1878 ${runcmd} echo "If you wish to use an external cross-toolchain, set"
1879 ${runcmd} echo " EXTERNAL_TOOLCHAIN=<path to toolchain root>"
1880 ${runcmd} echo "in either the environment or mk.conf and rerun"
1881 ${runcmd} echo " ${progname} $*"
1882 exit 1
1883 fi
1884
1885 if [ "${MKOBJDIRS}" != "no" ]; then
1886 # Create the top-level object directory.
1887 #
1888 # "make obj NOSUBDIR=" can handle most cases, but it
1889 # can't handle the case where MAKEOBJDIRPREFIX is set
1890 # while the corresponding directory does not exist
1891 # (rules in <bsd.obj.mk> would abort the build). We
1892 # therefore have to handle the MAKEOBJDIRPREFIX case
1893 # without invoking "make obj". The MAKEOBJDIR case
1894 # could be handled either way, but we choose to handle
1895 # it similarly to MAKEOBJDIRPREFIX.
1896 #
1897 if [ -n "${TOP_obj}" ]; then
1898 # It must have been set by the "-M" or "-O"
1899 # command line options, so there's no need to
1900 # use getmakevar
1901 :
1902 elif [ -n "$MAKEOBJDIRPREFIX" ]; then
1903 TOP_obj="$(getmakevar MAKEOBJDIRPREFIX)${TOP}"
1904 elif [ -n "$MAKEOBJDIR" ]; then
1905 TOP_obj="$(getmakevar MAKEOBJDIR)"
1906 fi
1907 if [ -n "$TOP_obj" ]; then
1908 ${runcmd} mkdir -p "${TOP_obj}" ||
1909 bomb "Can't create top level object directory" \
1910 "${TOP_obj}"
1911 else
1912 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1913 bomb "Can't create top level object directory" \
1914 "using make obj"
1915 fi
1916
1917 # make obj in tools to ensure that the objdir for "tools"
1918 # is available.
1919 #
1920 ${runcmd} cd tools
1921 ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
1922 bomb "Failed to make obj in tools"
1923 ${runcmd} cd "${TOP}"
1924 fi
1925
1926 # Find TOOLDIR, DESTDIR, and RELEASEDIR, according to getmakevar,
1927 # and bomb if they have changed from the values we had from the
1928 # command line or environment.
1929 #
1930 # This must be done after creating the top-level object directory.
1931 #
1932 for var in TOOLDIR DESTDIR RELEASEDIR
1933 do
1934 eval oldval=\"\$${var}\"
1935 newval="$(getmakevar $var)"
1936 if ! $do_expertmode; then
1937 : ${_SRC_TOP_OBJ_:=$(getmakevar _SRC_TOP_OBJ_)}
1938 case "$var" in
1939 DESTDIR)
1940 : ${newval:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1941 makeenv="${makeenv} DESTDIR"
1942 ;;
1943 RELEASEDIR)
1944 : ${newval:=${_SRC_TOP_OBJ_}/releasedir}
1945 makeenv="${makeenv} RELEASEDIR"
1946 ;;
1947 esac
1948 fi
1949 if [ -n "$oldval" ] && [ "$oldval" != "$newval" ]; then
1950 bomb "Value of ${var} has changed" \
1951 "(was \"${oldval}\", now \"${newval}\")"
1952 fi
1953 eval ${var}=\"\${newval}\"
1954 eval export ${var}
1955 statusmsg2 "${var} path:" "${newval}"
1956 done
1957
1958 # RELEASEMACHINEDIR is just a subdir name, e.g. "i386".
1959 RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1960
1961 # Check validity of TOOLDIR and DESTDIR.
1962 #
1963 if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
1964 bomb "TOOLDIR '${TOOLDIR}' invalid"
1965 fi
1966 removedirs="${TOOLDIR}"
1967
1968 if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
1969 if ${do_distribution} || ${do_release} || \
1970 [ "${uname_s}" != "NetBSD" ] || \
1971 [ "${uname_m}" != "${MACHINE}" ]; then
1972 bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'"
1973 fi
1974 if ! ${do_expertmode}; then
1975 bomb "DESTDIR must != / for non -E (expert) builds"
1976 fi
1977 statusmsg "WARNING: Building to /, in expert mode."
1978 statusmsg " This may cause your system to break! Reasons include:"
1979 statusmsg " - your kernel is not up to date"
1980 statusmsg " - the libraries or toolchain have changed"
1981 statusmsg " YOU HAVE BEEN WARNED!"
1982 else
1983 removedirs="${removedirs} ${DESTDIR}"
1984 fi
1985 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1986 bomb "Must set RELEASEDIR with 'releasekernel=...'"
1987 fi
1988
1989 # If a previous build.sh run used -U (and therefore created a
1990 # METALOG file), then most subsequent build.sh runs must also
1991 # use -U. If DESTDIR is about to be removed, then don't perform
1992 # this check.
1993 #
1994 case "${do_removedirs} ${removedirs} " in
1995 true*" ${DESTDIR} "*)
1996 # DESTDIR is about to be removed
1997 ;;
1998 *)
1999 if [ -e "${DESTDIR}/METALOG" ] && \
2000 [ "${MKUNPRIVED}" = "no" ] ; then
2001 if $do_expertmode; then
2002 warning "A previous build.sh run specified -U"
2003 else
2004 bomb "A previous build.sh run specified -U; you must specify it again now"
2005 fi
2006 fi
2007 ;;
2008 esac
2009
2010 # live-image and install-image targets require binary sets
2011 # (actually DESTDIR/etc/mtree/set.* files) built with MKUNPRIVED.
2012 # If release operation is specified with live-image or install-image,
2013 # the release op should be performed with -U for later image ops.
2014 #
2015 if ${do_release} && ( ${do_live_image} || ${do_install_image} ) && \
2016 [ "${MKUNPRIVED}" = "no" ] ; then
2017 bomb "-U must be specified on building release to create images later"
2018 fi
2019 }
2020
2021
2022 createmakewrapper()
2023 {
2024 # Remove the target directories.
2025 #
2026 if ${do_removedirs}; then
2027 for f in ${removedirs}; do
2028 statusmsg "Removing ${f}"
2029 ${runcmd} rm -r -f "${f}"
2030 done
2031 fi
2032
2033 # Recreate $TOOLDIR.
2034 #
2035 ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
2036 bomb "mkdir of '${TOOLDIR}/bin' failed"
2037
2038 # If we did not previously rebuild ${toolprefix}make, then
2039 # check whether $make is still valid and the same as the output
2040 # from print_tooldir_make. If not, then rebuild make now. A
2041 # possible reason for this being necessary is that the actual
2042 # value of TOOLDIR might be different from the value guessed
2043 # before the top level obj dir was created.
2044 #
2045 if ! ${done_rebuildmake} && \
2046 ( [ ! -x "$make" ] || [ "$make" != "$(print_tooldir_make)" ] )
2047 then
2048 rebuildmake
2049 fi
2050
2051 # Install ${toolprefix}make if it was built.
2052 #
2053 if ${done_rebuildmake}; then
2054 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
2055 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
2056 bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
2057 make="${TOOLDIR}/bin/${toolprefix}make"
2058 statusmsg "Created ${make}"
2059 fi
2060
2061 # Build a ${toolprefix}make wrapper script, usable by hand as
2062 # well as by build.sh.
2063 #
2064 if [ -z "${makewrapper}" ]; then
2065 makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
2066 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
2067 fi
2068
2069 ${runcmd} rm -f "${makewrapper}"
2070 if [ "${runcmd}" = "echo" ]; then
2071 echo 'cat <<EOF >'${makewrapper}
2072 makewrapout=
2073 else
2074 makewrapout=">>\${makewrapper}"
2075 fi
2076
2077 case "${KSH_VERSION:-${SH_VERSION}}" in
2078 *PD\ KSH*|*MIRBSD\ KSH*)
2079 set +o braceexpand
2080 ;;
2081 esac
2082
2083 eval cat <<EOF ${makewrapout}
2084 #! ${HOST_SH}
2085 # Set proper variables to allow easy "make" building of a NetBSD subtree.
2086 # Generated from: \$NetBSD: build.sh,v 1.384 2024/12/20 14:31:49 martin Exp $
2087 # with these arguments: ${_args}
2088 #
2089
2090 EOF
2091 {
2092 sorted_vars="$(for var in ${makeenv}; do echo "${var}" ; done \
2093 | sort -u )"
2094 for var in ${sorted_vars}; do
2095 eval val=\"\${${var}}\"
2096 eval is_set=\"\${${var}+set}\"
2097 if [ -z "${is_set}" ]; then
2098 echo "unset ${var}"
2099 else
2100 qval="$(shell_quote "${val}")"
2101 echo "${var}=${qval}; export ${var}"
2102 fi
2103 done
2104
2105 cat <<EOF
2106
2107 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
2108 EOF
2109 } | eval cat "${makewrapout}"
2110 [ "${runcmd}" = "echo" ] && echo EOF
2111 ${runcmd} chmod +x "${makewrapper}"
2112 statusmsg2 "Updated makewrapper:" "${makewrapper}"
2113 }
2114
2115 make_in_dir()
2116 {
2117 local dir="$1"
2118 local op="$2"
2119 ${runcmd} cd "${dir}" ||
2120 bomb "Failed to cd to \"${dir}\""
2121 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2122 bomb "Failed to make ${op} in \"${dir}\""
2123 ${runcmd} cd "${TOP}" ||
2124 bomb "Failed to cd back to \"${TOP}\""
2125 }
2126
2127 buildtools()
2128 {
2129 if [ "${MKOBJDIRS}" != "no" ]; then
2130 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
2131 bomb "Failed to make obj-tools"
2132 fi
2133 if [ "${MKUPDATE}" = "no" ]; then
2134 make_in_dir tools cleandir
2135 fi
2136 make_in_dir tools build_install
2137 statusmsg "Tools built to ${TOOLDIR}"
2138 }
2139
2140 buildlibs()
2141 {
2142 if [ "${MKOBJDIRS}" != "no" ]; then
2143 ${runcmd} "${makewrapper}" ${parallel} obj ||
2144 bomb "Failed to make obj"
2145 fi
2146 if [ "${MKUPDATE}" = "no" ]; then
2147 make_in_dir lib cleandir
2148 fi
2149 make_in_dir . do-distrib-dirs
2150 make_in_dir . includes
2151 make_in_dir . do-lib
2152 statusmsg "libs built"
2153 }
2154
2155 getkernelconf()
2156 {
2157 kernelconf="$1"
2158 if [ "${MKOBJDIRS}" != "no" ]; then
2159 # The correct value of KERNOBJDIR might
2160 # depend on a prior "make obj" in
2161 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
2162 #
2163 KERNSRCDIR="$(getmakevar KERNSRCDIR)"
2164 KERNARCHDIR="$(getmakevar KERNARCHDIR)"
2165 make_in_dir "${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
2166 fi
2167 KERNCONFDIR="$(getmakevar KERNCONFDIR)"
2168 KERNOBJDIR="$(getmakevar KERNOBJDIR)"
2169 case "${kernelconf}" in
2170 */*)
2171 kernelconfpath="${kernelconf}"
2172 kernelconfname="${kernelconf##*/}"
2173 ;;
2174 *)
2175 kernelconfpath="${KERNCONFDIR}/${kernelconf}"
2176 kernelconfname="${kernelconf}"
2177 ;;
2178 esac
2179 kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
2180 }
2181
2182 diskimage()
2183 {
2184 ARG="$(echo $1 | tr '[:lower:]' '[:upper:]')"
2185 [ -f "${DESTDIR}/etc/mtree/set.base" ] ||
2186 bomb "The release binaries must be built first"
2187 kerneldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
2188 kernel="${kerneldir}/netbsd-${ARG}.gz"
2189 [ -f "${kernel}" ] ||
2190 bomb "The kernel ${kernel} must be built first"
2191 make_in_dir "${NETBSDSRCDIR}/etc" "smp_${1}"
2192 }
2193
2194 buildkernel()
2195 {
2196 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
2197 # Building tools every time we build a kernel is clearly
2198 # unnecessary. We could try to figure out whether rebuilding
2199 # the tools is necessary this time, but it doesn't seem worth
2200 # the trouble. Instead, we say it's the user's responsibility
2201 # to rebuild the tools if necessary.
2202 #
2203 statusmsg "Building kernel without building new tools"
2204 buildkernelwarned=true
2205 fi
2206 getkernelconf $1
2207 statusmsg2 "Building kernel:" "${kernelconf}"
2208 statusmsg2 "Build directory:" "${kernelbuildpath}"
2209 ${runcmd} mkdir -p "${kernelbuildpath}" ||
2210 bomb "Cannot mkdir: ${kernelbuildpath}"
2211 if [ "${MKUPDATE}" = "no" ]; then
2212 make_in_dir "${kernelbuildpath}" cleandir
2213 fi
2214 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
2215 || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first"
2216 CONFIGOPTS=$(getmakevar CONFIGOPTS)
2217 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" ${CONFIGOPTS} \
2218 -b "${kernelbuildpath}" -s "${TOP}/sys" ${configopts} \
2219 "${kernelconfpath}" ||
2220 bomb "${toolprefix}config failed for ${kernelconf}"
2221 make_in_dir "${kernelbuildpath}" depend
2222 make_in_dir "${kernelbuildpath}" all
2223
2224 if [ "${runcmd}" != "echo" ]; then
2225 statusmsg "Kernels built from ${kernelconf}:"
2226 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
2227 for kern in ${kernlist:-netbsd}; do
2228 [ -f "${kernelbuildpath}/${kern}" ] && \
2229 echo " ${kernelbuildpath}/${kern}"
2230 done | tee -a "${results}"
2231 fi
2232 }
2233
2234 releasekernel()
2235 {
2236 getkernelconf $1
2237 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
2238 ${runcmd} mkdir -p "${kernelreldir}"
2239 kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
2240 for kern in ${kernlist:-netbsd}; do
2241 builtkern="${kernelbuildpath}/${kern}"
2242 [ -f "${builtkern}" ] || continue
2243 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
2244 statusmsg2 "Kernel copy:" "${releasekern}"
2245 if [ "${runcmd}" = "echo" ]; then
2246 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
2247 else
2248 gzip -c -9 < "${builtkern}" > "${releasekern}"
2249 fi
2250 done
2251 }
2252
2253 buildkernels()
2254 {
2255 allkernels=$( runcmd= make_in_dir etc '-V ${ALL_KERNELS}' )
2256 for k in $allkernels; do
2257 buildkernel "${k}"
2258 done
2259 }
2260
2261 buildmodules()
2262 {
2263 setmakeenv MKBINUTILS no
2264 if ! ${do_tools} && ! ${buildmoduleswarned:-false}; then
2265 # Building tools every time we build modules is clearly
2266 # unnecessary as well as a kernel.
2267 #
2268 statusmsg "Building modules without building new tools"
2269 buildmoduleswarned=true
2270 fi
2271
2272 statusmsg "Building kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
2273 if [ "${MKOBJDIRS}" != "no" ]; then
2274 make_in_dir sys/modules obj
2275 fi
2276 if [ "${MKUPDATE}" = "no" ]; then
2277 make_in_dir sys/modules cleandir
2278 fi
2279 make_in_dir sys/modules dependall
2280 make_in_dir sys/modules install
2281
2282 statusmsg "Successful build of kernel modules for NetBSD/${MACHINE} ${DISTRIBVER}"
2283 }
2284
2285 builddtb()
2286 {
2287 statusmsg "Building devicetree blobs for NetBSD/${MACHINE} ${DISTRIBVER}"
2288 if [ "${MKOBJDIRS}" != "no" ]; then
2289 make_in_dir sys/dtb obj
2290 fi
2291 if [ "${MKUPDATE}" = "no" ]; then
2292 make_in_dir sys/dtb cleandir
2293 fi
2294 make_in_dir sys/dtb dependall
2295 make_in_dir sys/dtb install
2296
2297 statusmsg "Successful build of devicetree blobs for NetBSD/${MACHINE} ${DISTRIBVER}"
2298 }
2299
2300 buildpkg()
2301 {
2302 local catpkg
2303 local pkgroot
2304 local makejobsarg
2305 local makejobsvar
2306 local quiet
2307 local opsys_version
2308
2309 catpkg="$1"
2310
2311 pkgroot="${TOP_objdir:-${TOP}}/pkgroot"
2312 ${runcmd} mkdir -p "${pkgroot}" ||
2313 bomb "Can't create package root" "${pkgroot}"
2314
2315 # Get a symlink-free absolute path to pkg -- pkgsrc wants this.
2316 #
2317 # XXX See TOP= above regarding pwd -P.
2318 pkgroot=$(unset PWD; cd "${pkgroot}" &&
2319 ((exec pwd -P 2>/dev/null) || (exec pwd 2>/dev/null)))
2320
2321 case $parallel in
2322 "-j "*)
2323 makejobsarg="--make-jobs ${parallel#-j }"
2324 makejobsvar="MAKE_JOBS=${parallel#-j }"
2325 ;;
2326 *) makejobsarg=""
2327 makejobsvar=""
2328 ;;
2329 esac
2330
2331 if [ "${MAKEVERBOSE}" -eq 0 ]; then
2332 quiet="--quiet"
2333 else
2334 quiet=""
2335 fi
2336
2337 # Derived from pkgsrc/mk/bsd.prefs.mk rev. 1.451.
2338 opsys_version=$(echo "${DISTRIBVER}" |
2339 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}')
2340
2341 # Bootstrap pkgsrc if needed.
2342 #
2343 # XXX Redo this if it's out-of-date, not just if it's missing.
2344 if ! [ -x "${pkgroot}/pkg/bin/bmake" ]; then
2345 statusmsg "Bootstrapping pkgsrc"
2346
2347 cat >"${pkgroot}/mk.conf-fragment" <<EOF
2348 USE_CROSS_COMPILE?= no
2349 TOOLDIR= ${TOOLDIR}
2350 CROSS_DESTDIR= ${DESTDIR}
2351 CROSS_MACHINE_ARCH= ${MACHINE_ARCH}
2352 CROSS_OPSYS= NetBSD
2353 CROSS_OS_VERSION= ${DISTRIBVER}
2354 CROSS_OPSYS_VERSION= ${opsys_version}
2355 CROSS_LOWER_OPSYS= netbsd
2356 CROSS_LOWER_OPSYS_VERSUFFIX= # empty
2357 CROSS_LOWER_OS_VARIANT= # empty
2358 CROSS_LOWER_VARIANT_VERSION= # empty
2359 CROSS_LOWER_VENDOR= # empty
2360 CROSS_OBJECT_FMT= ELF
2361
2362 ALLOW_VULNERABLE_PACKAGES= yes
2363 BINPKG_SITES= # empty
2364 FAILOVER_FETCH= yes
2365 FETCH_TIMEOUT= 1800
2366 PASSIVE_FETCH= yes
2367
2368 DISTDIR= ${pkgroot}/distfiles
2369 PACKAGES= ${pkgroot}/packages
2370 WRKOBJDIR= ${pkgroot}/work
2371
2372 # pkgsrc cross-builds are not set up to support native X, but also part
2373 # of the point of pkgsrc cross-build infrastructure is to not need
2374 # native X any more.
2375 X11_TYPE= modular
2376
2377 .-include "${MAKECONF}"
2378
2379 MKDEBUG= no # interferes with pkgsrc builds
2380 EOF
2381
2382 # XXX Set --abi for mips and whatever else needs it?
2383 # XXX Unprivileged native tools, privileged cross.
2384 (cd "${PKGSRCDIR}" && clearmakeenv && ./bootstrap/bootstrap \
2385 ${makejobsarg} \
2386 --mk-fragment "${pkgroot}/mk.conf-fragment" \
2387 --prefix "${pkgroot}/pkg" \
2388 ${quiet} \
2389 --unprivileged \
2390 --workdir "${pkgroot}/bootwork") \
2391 || bomb "Failed to bootstrap pkgsrc"
2392 fi
2393
2394 # Build the package.
2395 (cd "${PKGSRCDIR}/${catpkg}" && clearmakeenv && \
2396 "${pkgroot}/pkg/bin/bmake" package \
2397 USE_CROSS_COMPILE=yes \
2398 ${makejobsvar}) \
2399 || bomb "Failed to build ${catpkg}"
2400 }
2401
2402 installmodules()
2403 {
2404 dir="$1"
2405 ${runcmd} "${makewrapper}" INSTALLMODULESDIR="${dir}" installmodules ||
2406 bomb "Failed to make installmodules to ${dir}"
2407 statusmsg "Successful installmodules to ${dir}"
2408 }
2409
2410 installworld()
2411 {
2412 dir="$1"
2413 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
2414 bomb "Failed to make installworld to ${dir}"
2415 statusmsg "Successful installworld to ${dir}"
2416 }
2417
2418 # Run rump build&link tests.
2419 #
2420 # To make this feasible for running without having to install includes and
2421 # libraries into destdir (i.e. quick), we only run ld. This is possible
2422 # since the rump kernel is a closed namespace apart from calls to rumpuser.
2423 # Therefore, if ld complains only about rumpuser symbols, rump kernel
2424 # linking was successful.
2425 #
2426 # We test that rump links with a number of component configurations.
2427 # These attempt to mimic what is encountered in the full build.
2428 # See list below. The list should probably be either autogenerated
2429 # or managed elsewhere; keep it here until a better idea arises.
2430 #
2431 # Above all, note that THIS IS NOT A SUBSTITUTE FOR A FULL BUILD.
2432 #
2433
2434 # XXX: uwe: kern/56599 - while riastradh addressed librump problems,
2435 # there are still unwanted dependencies:
2436 # net -> net_net
2437 # vfs -> fifo
2438
2439 # -lrumpvfs -> $LRUMPVFS for now
2440 LRUMPVFS="-lrumpvfs -lrumpvfs_nofifofs"
2441
2442 RUMP_LIBSETS="
2443 -lrump,
2444 -lrumpvfs
2445 --no-whole-archive -lrumpvfs_nofifofs -lrump,
2446 -lrumpkern_tty
2447 --no-whole-archive $LRUMPVFS -lrump,
2448 -lrumpfs_tmpfs
2449 --no-whole-archive $LRUMPVFS -lrump,
2450 -lrumpfs_ffs -lrumpfs_msdos
2451 --no-whole-archive $LRUMPVFS -lrumpdev_disk -lrumpdev -lrump,
2452 -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet
2453 --no-whole-archive -lrump,
2454 -lrumpfs_nfs
2455 --no-whole-archive $LRUMPVFS
2456 -lrumpnet_sockin -lrumpnet_virtif -lrumpnet_netinet
2457 --start-group -lrumpnet_net -lrumpnet --end-group -lrump,
2458 -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_rnd -lrumpdev_dm
2459 --no-whole-archive $LRUMPVFS -lrumpdev_disk -lrumpdev -lrumpkern_crypto -lrump
2460 "
2461
2462 dorump()
2463 {
2464 local doclean=""
2465 local doobjs=""
2466
2467 export RUMPKERN_ONLY=1
2468 # create obj and distrib dirs
2469 if [ "${MKOBJDIRS}" != "no" ]; then
2470 make_in_dir "${NETBSDSRCDIR}/etc/mtree" obj
2471 make_in_dir "${NETBSDSRCDIR}/sys/rump" obj
2472 fi
2473 ${runcmd} "${makewrapper}" ${parallel} do-distrib-dirs \
2474 || bomb "Could not create distrib-dirs"
2475
2476 [ "${MKUPDATE}" = "no" ] && doclean="cleandir"
2477 targlist="${doclean} ${doobjs} dependall install"
2478 # optimize: for test we build only static libs (3x test speedup)
2479 if [ "${1}" = "rumptest" ] ; then
2480 setmakeenv NOPIC 1
2481 setmakeenv NOPROFILE 1
2482 fi
2483 for cmd in ${targlist} ; do
2484 make_in_dir "${NETBSDSRCDIR}/sys/rump" ${cmd}
2485 done
2486
2487 # if we just wanted to build & install rump, we're done
2488 [ "${1}" != "rumptest" ] && return
2489
2490 ${runcmd} cd "${NETBSDSRCDIR}/sys/rump/librump/rumpkern" \
2491 || bomb "cd to rumpkern failed"
2492 md_quirks=`${runcmd} "${makewrapper}" -V '${_SYMQUIRK}'`
2493 # one little, two little, three little backslashes ...
2494 md_quirks="$(echo ${md_quirks} | sed 's,\\,\\\\,g'";s/'//g" )"
2495 ${runcmd} cd "${TOP}" || bomb "cd to ${TOP} failed"
2496 tool_ld=`${runcmd} "${makewrapper}" -V '${LD}'`
2497
2498 local oIFS="${IFS}"
2499 IFS=","
2500 for set in ${RUMP_LIBSETS} ; do
2501 IFS="${oIFS}"
2502 ${runcmd} ${tool_ld} -nostdlib -L${DESTDIR}/usr/lib \
2503 -static --whole-archive ${set} --no-whole-archive -lpthread -lc 2>&1 -o /tmp/rumptest.$$ | \
2504 awk -v quirks="${md_quirks}" '
2505 /undefined reference/ &&
2506 !/more undefined references.*follow/{
2507 if (match($NF,
2508 "`(rumpuser_|rumpcomp_|__" quirks ")") == 0)
2509 fails[NR] = $0
2510 }
2511 /cannot find -l/{fails[NR] = $0}
2512 /cannot open output file/{fails[NR] = $0}
2513 END{
2514 for (x in fails)
2515 print fails[x]
2516 exit x!=0
2517 }'
2518 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
2519 done
2520 statusmsg "Rump build&link tests successful"
2521 }
2522
2523 repro_date() {
2524 # try the bsd date fail back the linux one
2525 date -u -r "$1" 2> /dev/null || date -u -d "@$1"
2526 }
2527
2528 setup_mkrepro()
2529 {
2530 local quiet="$1"
2531
2532 if [ ${MKREPRO-no} != "yes" ]; then
2533 return
2534 fi
2535 if [ ${MKREPRO_TIMESTAMP-0} -ne 0 ]; then
2536 return
2537 fi
2538
2539 local dirs=${NETBSDSRCDIR-/usr/src}/
2540 if [ ${MKX11-no} = "yes" ]; then
2541 dirs="$dirs ${X11SRCDIR-/usr/xsrc}/"
2542 fi
2543
2544 MKREPRO_TIMESTAMP=0
2545 NETBSD_REVISIONID=
2546 local d
2547 local t
2548 local tag
2549 local vcs
2550 for d in ${dirs}; do
2551 if [ -d "${d}CVS" ]; then
2552 local cvslatest=$(print_tooldir_program cvslatest)
2553 if [ ! -x "${cvslatest}" ]; then
2554 buildtools
2555 fi
2556 local nbdate=$(print_tooldir_program date)
2557
2558 local cvslatestflags=
2559 if ${do_expertmode}; then
2560 cvslatestflags=-i
2561 fi
2562
2563 t=$("${cvslatest}" ${cvslatestflags} "${d}")
2564 if [ -f "${d}CVS/Tag" ]; then
2565 tag=$( sed 's/^T//' < "${d}CVS/Tag" )
2566 else
2567 tag=HEAD
2568 fi
2569 NETBSD_REVISIONID="${tag}-"$(${nbdate} -u -r ${t} '+%Y%m%d%H%M%S')
2570 vcs=cvs
2571 elif [ -d "${d}.git" -o -f "${d}.git" ]; then
2572 t=$(cd "${d}" && git log -1 --format=%ct)
2573 NETBSD_REVISIONID=$(cd "${d}" && git log -1 --format=%H)
2574 vcs=git
2575 elif [ -d "${d}.hg" ]; then
2576 t=$(hg --repo "$d" log -r . --template '{date.unixtime}\n')
2577 NETBSD_REVISIONID=$(hg --repo "$d" identify --template '{id}\n')
2578 vcs=hg
2579 elif [ -f "${d}.hg_archival.txt" ]; then
2580 local stat=$(print_tooldir_program stat)
2581 if [ ! -x "${stat}" ]; then
2582 buildtools
2583 fi
2584
2585 t=$("${stat}" -t '%s' -f '%m' "${d}.hg_archival.txt")
2586 NETBSD_REVISIONID=$(awk '/^node:/ { print $2 }' < "${d}.hg_archival.txt")
2587 vcs=hg
2588 else
2589 bomb "Cannot determine VCS for '$d'"
2590 fi
2591
2592 if [ -z "$t" ]; then
2593 bomb "Failed to get timestamp for vcs=$vcs in '$d'"
2594 fi
2595
2596 #echo "latest $d $vcs $t"
2597 if [ "$t" -gt "$MKREPRO_TIMESTAMP" ]; then
2598 MKREPRO_TIMESTAMP="$t"
2599 fi
2600 done
2601
2602 [ "${MKREPRO_TIMESTAMP}" -ne 0 ] || bomb "Failed to compute timestamp"
2603 if [ -z "${quiet}" ]; then
2604 statusmsg2 "MKREPRO_TIMESTAMP" \
2605 "$(repro_date "${MKREPRO_TIMESTAMP}")"
2606 fi
2607 export MKREPRO MKREPRO_TIMESTAMP NETBSD_REVISIONID
2608 }
2609
2610 main()
2611 {
2612 initdefaults
2613 _args=$@
2614 parseoptions "$@"
2615
2616 sanitycheck
2617
2618 build_start=$(date)
2619 statusmsg2 "${progname} command:" "$0 $*"
2620 statusmsg2 "${progname} started:" "${build_start}"
2621 statusmsg2 "NetBSD version:" "${DISTRIBVER}"
2622 statusmsg2 "MACHINE:" "${MACHINE}"
2623 statusmsg2 "MACHINE_ARCH:" "${MACHINE_ARCH}"
2624 statusmsg2 "Build platform:" "${uname_s} ${uname_r} ${uname_m}"
2625 statusmsg2 "HOST_SH:" "${HOST_SH}"
2626 if [ -n "${BUILDID}" ]; then
2627 statusmsg2 "BUILDID:" "${BUILDID}"
2628 fi
2629 if [ -n "${BUILDINFO}" ]; then
2630 printf "%b\n" "${BUILDINFO}" | \
2631 while read -r line ; do
2632 [ -s "${line}" ] && continue
2633 statusmsg2 "BUILDINFO:" "${line}"
2634 done
2635 fi
2636
2637 if [ -n "${MAKECONF+1}" ] && [ -z "${MAKECONF}" ]; then
2638 bomb "MAKECONF must not be empty"
2639 fi
2640
2641 rebuildmake
2642 validatemakeparams
2643 createmakewrapper
2644 setup_mkrepro
2645
2646 # Perform the operations.
2647 #
2648 for op in ${operations}; do
2649 case "${op}" in
2650
2651 makewrapper)
2652 # no-op
2653 ;;
2654
2655 tools)
2656 buildtools
2657 ;;
2658 libs)
2659 buildlibs
2660 ;;
2661
2662 sets)
2663 statusmsg "Building sets from pre-populated ${DESTDIR}"
2664 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2665 bomb "Failed to make ${op}"
2666 setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
2667 statusmsg "Built sets to ${setdir}"
2668 ;;
2669
2670 build|distribution|release)
2671 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2672 bomb "Failed to make ${op}"
2673 statusmsg "Successful make ${op}"
2674 ;;
2675
2676 cleandir|obj|sourcesets|syspkgs|params|show-params)
2677 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2678 bomb "Failed to make ${op}"
2679 statusmsg "Successful make ${op}"
2680 ;;
2681
2682 iso-image|iso-image-source)
2683 ${runcmd} "${makewrapper}" ${parallel} \
2684 CDEXTRA="$CDEXTRA" ${op} ||
2685 bomb "Failed to make ${op}"
2686 statusmsg "Successful make ${op}"
2687 ;;
2688
2689 live-image|install-image)
2690 # install-image and live-image require mtree spec files
2691 # built with MKUNPRIVED. Assume MKUNPRIVED build has been
2692 # performed if METALOG file is created in DESTDIR.
2693 if [ ! -e "${DESTDIR}/METALOG" ] ; then
2694 bomb "The release binaries must have been built with -U to create images"
2695 fi
2696 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
2697 bomb "Failed to make ${op}"
2698 statusmsg "Successful make ${op}"
2699 ;;
2700 kernel=*)
2701 arg=${op#*=}
2702 buildkernel "${arg}"
2703 ;;
2704 kernel.gdb=*)
2705 arg=${op#*=}
2706 configopts="-D DEBUG=-g"
2707 buildkernel "${arg}"
2708 ;;
2709 releasekernel=*)
2710 arg=${op#*=}
2711 releasekernel "${arg}"
2712 ;;
2713
2714 kernels)
2715 buildkernels
2716 ;;
2717
2718 disk-image=*)
2719 arg=${op#*=}
2720 diskimage "${arg}"
2721 ;;
2722
2723 dtb)
2724 builddtb
2725 ;;
2726
2727 modules)
2728 buildmodules
2729 ;;
2730
2731 pkg=*)
2732 arg=${op#*=}
2733 if ! [ -d "$PKGSRCDIR"/"$arg" ]; then
2734 bomb "no such package ${arg}"
2735 fi
2736 buildpkg "${arg}"
2737 ;;
2738
2739 installmodules=*)
2740 arg=${op#*=}
2741 if [ "${arg}" = "/" ] && \
2742 ( [ "${uname_s}" != "NetBSD" ] || \
2743 [ "${uname_m}" != "${MACHINE}" ] ); then
2744 bomb "'${op}' must != / for cross builds"
2745 fi
2746 installmodules "${arg}"
2747 ;;
2748
2749 install=*)
2750 arg=${op#*=}
2751 if [ "${arg}" = "/" ] && \
2752 ( [ "${uname_s}" != "NetBSD" ] || \
2753 [ "${uname_m}" != "${MACHINE}" ] ); then
2754 bomb "'${op}' must != / for cross builds"
2755 fi
2756 installworld "${arg}"
2757 ;;
2758
2759 rump)
2760 make_in_dir . do-distrib-dirs
2761 make_in_dir . includes
2762 make_in_dir lib/csu dependall
2763 make_in_dir lib/csu install
2764 make_in_dir external/gpl3/gcc/lib/libgcc dependall
2765 make_in_dir external/gpl3/gcc/lib/libgcc install
2766 dorump "${op}"
2767 ;;
2768
2769 rumptest)
2770 dorump "${op}"
2771 ;;
2772
2773 *)
2774 bomb "Unknown OPERATION '${op}'"
2775 ;;
2776
2777 esac
2778 done
2779
2780 statusmsg2 "${progname} ended:" "$(date)"
2781 if [ -s "${results}" ]; then
2782 echo "===> Summary of results:"
2783 sed -e 's/^===>//;s/^/ /' "${results}"
2784 echo "===> ."
2785 fi
2786 }
2787
2788 main "$@"
2789