2 # $NetBSD: build.sh,v 1.205 2009/03/09 06:25:51 apb Exp $
4 # Copyright (c) 2001-2009 The NetBSD Foundation, Inc.
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Todd Vierling and Luke Mewburn.
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
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.
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.
32 # Top level build wrapper, for a system containing no tools.
34 # This script should run on any POSIX-compliant shell. If the
35 # first "sh" found in the PATH is a POSIX-compliant shell, then
36 # you should not need to take any special action. Otherwise, you
37 # should set the environment variable HOST_SH to a POSIX-compliant
38 # shell, and invoke build.sh with that shell. (Depending on your
39 # system, one of /bin/ksh, /usr/local/bin/bash, or /usr/xpg4/bin/sh
40 # might be a suitable shell.)
47 trap "exit 1" 1 2 3 15
51 cat >&2 <<ERRORMESSAGE
56 kill ${toppid} # in case we were invoked from a subshell
63 ${runcmd} echo "===> $@" |
tee -a "${results}"
68 statusmsg
"Warning: $@"
71 # Find a program in the PATH, and print the result. If not found,
72 # print a default. If $2 is defined (even if it is an empty string),
73 # then that is the default; otherwise, $1 is used as the default.
77 local result
="${2-"$1"}"
81 for dir
in ${PATH}; do
82 if [ -x "${dir}/${prog}" ]; then
83 result
="${dir}/${prog}"
91 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
92 # Assumes that uname_s, uname_m, and PWD have been set.
95 # Even if ${HOST_SH} is already defined, we still do the
96 # sanity checks at the end.
98 # Solaris has /usr/xpg4/bin/sh.
100 [ -z "${HOST_SH}" ] && [ x
"${uname_s}" = x
"SunOS" ] && \
101 [ -x /usr
/xpg
4/bin
/sh
] && HOST_SH
="/usr/xpg4/bin/sh"
103 # Try to get the name of the shell that's running this script,
104 # by parsing the output from "ps". We assume that, if the host
105 # system's ps command supports -o comm at all, it will do so
106 # in the usual way: a one-line header followed by a one-line
107 # result, possibly including trailing white space. And if the
108 # host system's ps command doesn't support -o comm, we assume
109 # that we'll get an error message on stderr and nothing on
110 # stdout. (We don't try to use ps -o 'comm=' to suppress the
111 # header line, because that is less widely supported.)
113 # If we get the wrong result here, the user can override it by
114 # specifying HOST_SH in the environment.
116 [ -z "${HOST_SH}" ] && HOST_SH
="$(
117 (ps -p $$ -o comm | sed -ne "2s
/[ ${tab}]*\$
//p
") 2>/dev/null )"
119 # If nothing above worked, use "sh". We will later find the
120 # first directory in the PATH that has a "sh" program.
122 [ -z "${HOST_SH}" ] && HOST_SH
="sh"
124 # If the result so far is not an absolute path, try to prepend
125 # PWD or search the PATH.
130 */*) HOST_SH
="${PWD}/${HOST_SH}"
132 *) HOST_SH
="$(find_in_PATH "${HOST_SH}")"
136 # If we don't have an absolute path by now, bomb.
141 *) bomb
"HOST_SH=\"${HOST_SH}\" is not an absolute path."
145 # If HOST_SH is not executable, bomb.
147 [ -x "${HOST_SH}" ] ||
148 bomb
"HOST_SH=\"${HOST_SH}\" is not executable."
160 [ -d usr.bin
/make ] ||
cd "$(dirname $0)"
161 [ -d usr.bin
/make ] ||
162 bomb
"build.sh must be run from the top source level"
163 [ -f share
/mk
/bsd.own.mk
] ||
164 bomb
"src/share/mk is missing; please re-fetch the source tree"
166 # Find information about the build platform. This should be
167 # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
168 # variables in share/mk/bsd.sys.mk.
170 # Note that "uname -p" is not part of POSIX, but we want uname_p
171 # to be set to the host MACHINE_ARCH, if possible. On systems
172 # where "uname -p" fails, prints "unknown", or prints a string
173 # that does not look like an identifier, fall back to using the
174 # output from "uname -m" instead.
176 uname_s
=$
(uname
-s 2>/dev
/null
)
177 uname_r
=$
(uname
-r 2>/dev
/null
)
178 uname_m
=$
(uname
-m 2>/dev
/null
)
179 uname_p
=$
(uname
-p 2>/dev
/null ||
echo "unknown")
181 ''|unknown|
*[^
-_A-Za-z0-9]*) uname_p
="${uname_m}" ;;
184 id_u
=$
(id
-u 2>/dev
/null ||
/usr
/xpg
4/bin
/id
-u 2>/dev
/null
)
186 # If $PWD is a valid name of the current directory, POSIX mandates
187 # that pwd return it by default which causes problems in the
188 # presence of symlinks. Unsetting PWD is simpler than changing
189 # every occurrence of pwd to use -P.
191 # XXX Except that doesn't work on Solaris. Or many Linuces.
194 TOP
=$
(/bin
/pwd -P 2>/dev
/null ||
/bin
/pwd 2>/dev
/null
)
196 # The user can set HOST_SH in the environment, or we try to
197 # guess an appropriate value. Then we set several other
198 # variables from HOST_SH.
201 setmakeenv HOST_SH
"${HOST_SH}"
202 setmakeenv BSHELL
"${HOST_SH}"
203 setmakeenv CONFIG_SHELL
"${HOST_SH}"
209 # Some systems have a small ARG_MAX. -X prevents make(1) from
210 # exporting variables in the environment redundantly.
213 Darwin | FreeBSD | CYGWIN
*)
221 # do_{operation}=true if given operation is requested.
230 do_distribution
=false
233 do_releasekernel
=false
239 do_iso_image_source
=false
242 # Create scratch directory
244 tmpdir
="${TMPDIR-/tmp}/nbbuild$$"
245 mkdir
"${tmpdir}" || bomb
"Cannot mkdir: ${tmpdir}"
246 trap "cd /; rm -r -f \"${tmpdir}\"" 0
247 results
="${tmpdir}/build.sh.results"
249 # Set source directories
251 setmakeenv NETBSDSRCDIR
"${TOP}"
253 # Determine top-level obj directory.
254 # Defaults to the top-level source directory.
255 # If $MAKEOBJDIRPREFIX is set in the environment, use it.
256 # We can't check $MAKEOBJDIR since that may be a make(1)
257 # expression that we can't evaluate at this time.
260 if [ -n "${MAKEOBJDIRPREFIX}" ]; then
261 TOP_objdir
="${MAKEOBJDIRPREFIX}${TOP}"
262 elif [ -n "${MAKEOBJDIR}" ]; then
263 warning
"Can't parse \$(MAKEOBJDIR) \"$MAKEOBJDIR\" to determine top objdir"
266 # Find the version of NetBSD
268 DISTRIBVER
="$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh)"
270 # Set the BUILDSEED to NetBSD-"N"
272 setmakeenv BUILDSEED
"NetBSD-$(${HOST_SH} ${TOP}/sys/conf/osrelease.sh -m)"
274 # Set MKARZERO to "yes"
276 setmakeenv MKARZERO
"yes"
278 # Set various environment variables to known defaults,
279 # to minimize (cross-)build problems observed "in the field".
282 unsetmakeenv LESSCHARSET
288 # Translate some MACHINE name aliases (known only to build.sh)
289 # into proper MACHINE and MACHINE_ARCH names. Save the alias
290 # name in makewrappermachine.
295 makewrappermachine
=${MACHINE}
296 # MACHINE_ARCH is "arm" or "armeb", not "armel"
297 MACHINE_ARCH
=arm
${MACHINE##*-}
298 MACHINE_ARCH
=${MACHINE_ARCH%el}
299 MACHINE
=${MACHINE%-e[bl]}
302 evbmips-e
[bl
]|sbmips-e
[bl
])
303 makewrappermachine
=${MACHINE}
304 MACHINE_ARCH
=mips
${MACHINE##*-}
305 MACHINE
=${MACHINE%-e[bl]}
308 evbmips64-e
[bl
]|sbmips64-e
[bl
])
309 makewrappermachine
=${MACHINE}
310 MACHINE_ARCH
=mips64
${MACHINE##*-}
311 MACHINE
=${MACHINE%64-e[bl]}
315 makewrappermachine
=${MACHINE}
316 MACHINE_ARCH
=sh3
${MACHINE##*-}
317 MACHINE
=${MACHINE%-e[bl]}
322 # Translate a MACHINE into a default MACHINE_ARCH.
326 acorn26|acorn32|cats|hpcarm|iyonix|netwinder|shark|zaurus
)
330 evbarm
) # unspecified MACHINE_ARCH gets LE
331 MACHINE_ARCH
=${MACHINE_ARCH:=arm}
342 amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k
)
346 evbmips|sbmips
) # no default MACHINE_ARCH
349 ews4800mips|mipsco|newsmips|sgimips
)
353 algor|arc|cobalt|hpcmips|playstation2|pmax
)
357 evbppc64|macppc64|ofppc64
)
358 makewrappermachine
=${MACHINE}
359 MACHINE
=${MACHINE%64}
360 MACHINE_ARCH
=powerpc64
363 amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint
)
367 evbsh3
) # no default MACHINE_ARCH
374 dreamcast|hpcsh|landisk
)
382 alpha|i386|sparc|sparc64|vax|ia64
)
383 MACHINE_ARCH
=${MACHINE}
387 bomb
"Unknown target MACHINE: ${MACHINE}"
395 # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
397 case "${MACHINE_ARCH}" in
399 alpha|arm|armeb|hppa|i386|m68000|m68k|mipse
[bl
]|mips64e
[bl
]|powerpc|powerpc64|sh3e
[bl
]|sparc|sparc64|vax|x86_64|ia64
)
403 bomb
"No MACHINE_ARCH provided"
407 bomb
"Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
412 # Determine valid MACHINE_ARCHs for MACHINE
421 arches
="mipseb mipsel mips64eb mips64el"
425 arches
="mipseb mips64eb"
433 arches
="powerpc powerpc64"
436 oma
="${MACHINE_ARCH}"
438 arches
="${MACHINE_ARCH}"
439 MACHINE_ARCH
="${oma}"
444 # Ensure that MACHINE_ARCH supports MACHINE
447 for a
in ${arches}; do
448 if [ "${a}" = "${MACHINE_ARCH}" ]; then
454 bomb
"MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
459 [ -x "${make}" ] ||
return 1
460 "${make}" -m ${TOP}/share
/mk
-s -B -f- _x_
<<EOF || return 1
463 .include <bsd.prog.mk>
464 .include <bsd.kernobj.mk>
470 [ -x "${make}" ] || bomb
"raw_getmakevar $1: ${make} is not executable"
471 nobomb_getmakevar
"$1" || bomb
"raw_getmakevar $1: ${make} failed"
476 # raw_getmakevar() doesn't work properly if $make hasn't yet been
477 # built, which can happen when running with the "-n" option.
478 # getmakevar() deals with this by emitting a literal '$'
479 # followed by the variable name, instead of trying to find the
482 if [ -x "${make}" ]; then
491 eval "$1='$2'; export $1"
492 makeenv
="${makeenv} $1"
498 makeenv
="${makeenv} $1"
501 # Convert possibly-relative paths to absolute paths by prepending
502 # ${TOP} if necessary. Also delete trailing "/", if any.
506 for oa
in ${OPTARG}; do
517 _OPTARG
="${_OPTARG} ${oa}"
522 # Convert possibly-relative path to absolute path by prepending
523 # ${TOP} if necessary. Also delete trailing "/", if any.
533 OPTARG
="${TOP}/${OPTARG%/}"
542 echo "${progname}: $*"
546 Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-C cdextras]
547 [-D dest] [-j njob] [-M obj] [-m mach] [-N noisy]
548 [-O obj] [-R release] [-S seed] [-T tools]
549 [-V var=[value]] [-w wrapper] [-X x11src] [-Z var]
552 Build operations (all imply "obj" and "tools"):
553 build Run "make build".
554 distribution Run "make distribution" (includes DESTDIR/etc/ files).
555 release Run "make release" (includes kernels & distrib media).
558 help Show this message and exit.
559 makewrapper Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
561 cleandir Run "make cleandir". [Default unless -u is used]
562 obj Run "make obj". [Default unless -o is used]
563 tools Build and install tools.
564 install=idir Run "make installworld" to \`idir' to install all sets
565 except \`etc'. Useful after "distribution" or "release"
566 kernel=conf Build kernel with config file \`conf'
567 releasekernel=conf Install kernel built by kernel=conf to RELEASEDIR.
568 sets Create binary sets in
569 RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
570 DESTDIR should be populated beforehand.
571 sourcesets Create source sets in RELEASEDIR/source/sets.
572 syspkgs Create syspkgs in
573 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
574 iso-image Create CD-ROM image in RELEASEDIR/iso.
575 iso-image-source Create CD-ROM image with source in RELEASEDIR/iso.
576 params Display various make(1) parameters.
579 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
580 -B buildId Set BUILDID to buildId.
581 -C cdextras Set CDEXTRA to cdextras
582 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
583 -E Set "expert" mode; disables various safety checks.
584 Should not be used without expert knowledge of the build system.
585 -h Print this help message.
586 -j njob Run up to njob jobs in parallel; see make(1) -j.
587 -M obj Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
589 -m mach Set MACHINE to mach; not required if NetBSD native.
590 -N noisy Set the noisyness (MAKEVERBOSE) level of the build:
591 0 Minimal output ("quiet")
592 1 Describe what is occurring
593 2 Describe what is occurring and echo the actual command
594 3 Ignore the effect of the "@" prefix in make commands
595 4 Trace shell commands using the shell's -x flag
597 -n Show commands that would be executed, but do not execute them.
598 -O obj Set obj root directory to obj; sets a MAKEOBJDIR pattern.
599 Unsets MAKEOBJDIRPREFIX.
600 -o Set MKOBJDIRS=no; do not create objdirs at start of build.
601 -R release Set RELEASEDIR to release. [Default: releasedir]
602 -r Remove contents of TOOLDIR and DESTDIR before building.
603 -S seed Set BUILDSEED to seed. [Default: NetBSD-majorversion]
604 -T tools Set TOOLDIR to tools. If unset, and TOOLDIR is not set in
605 the environment, ${toolprefix}make will be (re)built unconditionally.
606 -U Set MKUNPRIVED=yes; build without requiring root privileges,
607 install from an UNPRIVED build with proper file permissions.
608 -u Set MKUPDATE=yes; do not run "make cleandir" first.
609 Without this, everything is rebuilt, including the tools.
610 -V v=[val] Set variable \`v' to \`val'.
611 -w wrapper Create ${toolprefix}make script as wrapper.
612 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
613 -X x11src Set X11SRCDIR to x11src. [Default: /usr/xsrc]
614 -x Set MKX11=yes; build X11 from X11SRCDIR
615 -Z v Unset ("zap") variable \`v'.
623 opts
='a:B:C:D:Ehj:M:m:N:nO:oR:rS:T:UuV:w:xX:Z:'
626 if type getopts >/dev
/null
2>&1; then
629 getoptcmd
='getopts ${opts} opt && opt=-${opt}'
631 optremcmd
='shift $((${OPTIND} -1))'
633 type getopt
>/dev
/null
2>&1 ||
634 bomb
"/bin/sh shell is too old; try ksh or bash"
636 # Use old-style getopt(1) (doesn't handle whitespace in args).
638 args
="$(getopt ${opts} $*)"
642 getoptcmd
='[ $# -gt 0 ] && opt="$1" && shift'
643 optargcmd
='OPTARG="$1"; shift'
647 # Parse command line options.
649 while eval ${getoptcmd}; do
654 MACHINE_ARCH
=${OPTARG}
664 eval ${optargcmd}; resolvepaths
669 eval ${optargcmd}; resolvepath
670 setmakeenv DESTDIR
"${OPTARG}"
679 parallel
="-j ${OPTARG}"
683 eval ${optargcmd}; resolvepath
684 TOP_objdir
="${OPTARG}${TOP}"
685 unsetmakeenv MAKEOBJDIR
686 setmakeenv MAKEOBJDIRPREFIX
"${OPTARG}"
689 # -m overrides MACHINE_ARCH unless "-a" is specified
693 [ "${opt_a}" != "yes" ] && getarch
700 setmakeenv MAKEVERBOSE
"${OPTARG}"
703 usage
"'${OPTARG}' is not a valid value for -N"
713 eval ${optargcmd}; resolvepath
714 TOP_objdir
="${OPTARG}"
715 unsetmakeenv MAKEOBJDIRPREFIX
716 setmakeenv MAKEOBJDIR
"\${.CURDIR:C,^$TOP,$OPTARG,}"
724 eval ${optargcmd}; resolvepath
725 setmakeenv RELEASEDIR
"${OPTARG}"
735 setmakeenv BUILDSEED
"${OPTARG}"
739 eval ${optargcmd}; resolvepath
745 setmakeenv MKUNPRIVED
yes
749 setmakeenv MKUPDATE
yes
755 # XXX: consider restricting which variables can be changed?
756 [a-zA-Z_
][a-zA-Z_0-9
]*=*)
757 setmakeenv
"${OPTARG%%=*}" "${OPTARG#*=}"
760 usage
"-V argument must be of the form 'var=[value]'"
766 eval ${optargcmd}; resolvepath
767 makewrapper
="${OPTARG}"
771 eval ${optargcmd}; resolvepath
772 setmakeenv X11SRCDIR
"${OPTARG}"
781 # XXX: consider restricting which variables can be unset?
782 unsetmakeenv
"${OPTARG}"
796 # Validate operations.
799 while [ $# -gt 0 ]; do
801 operations
="${operations} ${op}"
809 makewrapper|cleandir|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params
)
813 op
=iso_image
# used as part of a variable name
817 op
=iso_image_source
# used as part of a variable name
820 kernel
=*|releasekernel
=*)
824 bomb
"Must supply a kernel name with \`${op}=...'"
831 bomb
"Must supply a directory with \`install=...'"
835 usage
"Unknown operation \`${op}'"
841 [ -n "${operations}" ] || usage
"Missing operation to perform."
843 # Set up MACHINE*. On a NetBSD host, these are allowed to be unset.
845 if [ -z "${MACHINE}" ]; then
846 [ "${uname_s}" = "NetBSD" ] ||
847 bomb
"MACHINE must be set, or -m must be used, for cross builds."
850 [ -n "${MACHINE_ARCH}" ] || getarch
853 # Set up default make(1) environment.
855 makeenv
="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
856 [ -z "${BUILDID}" ] || makeenv
="${makeenv} BUILDID"
857 MAKEFLAGS
="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
858 export MAKEFLAGS MACHINE MACHINE_ARCH
863 # If the PATH contains any non-absolute components (including,
864 # but not limited to, "." or ""), then complain. As an exception,
865 # allow "" or "." as the last component of the PATH. This is fatal
866 # if expert mode is not in effect.
869 path
="${path%:}" # delete trailing ":"
870 path
="${path%:.}" # delete trailing ":."
873 if ${do_expertmode}; then
874 warning
"PATH contains non-absolute components"
876 bomb
"PATH environment variable must not" \
877 "contain non-absolute components"
883 # Try to set a value for TOOLDIR. This is difficult because of a cyclic
884 # dependency: TOOLDIR may be affected by settings in /etc/mk.conf, so
885 # we would like to use getmakevar to get the value of TOOLDIR, but we
886 # can't use getmakevar before we have an up to date version of nbmake;
887 # we might already have an up to date version of nbmake in TOOLDIR, but
888 # we don't yet know where TOOLDIR is.
890 # In principle, we could break the cycle by building a copy of nbmake
891 # in a temporary directory. However, people who use the default value
892 # of TOOLDIR do not like to have nbmake rebuilt every time they run
895 # We try to please everybody as follows:
897 # * If TOOLDIR was set in the environment or on the command line, use
899 # * Otherwise try to guess what TOOLDIR would be if not overridden by
900 # /etc/mk.conf, and check whether the resulting directory contains
901 # a copy of ${toolprefix}make (this should work for everybody who
902 # doesn't override TOOLDIR via /etc/mk.conf);
903 # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
904 # in the PATH (this might accidentally find a non-NetBSD version of
905 # make, which will lead to failure in the next step);
906 # * If a copy of make was found above, try to use it with
907 # nobomb_getmakevar to find the correct value for TOOLDIR;
908 # * If all else fails, leave TOOLDIR unset. Our caller is expected to
909 # be able to cope with this.
913 [ -n "${TOOLDIR}" ] && return
915 # Set host_ostype to something like "NetBSD-4.5.6-i386". This
916 # is intended to match the HOST_OSTYPE variable in <bsd.own.mk>.
918 local host_ostype
="${uname_s}-$(
919 echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
921 echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
924 # Look in a few potential locations for
925 # ${possible_TOOLDIR}/bin/${toolprefix}make.
926 # If we find it, then set guess_make.
928 # In the usual case (without interference from environment
929 # variables or /etc/mk.conf), <bsd.own.mk> should set TOOLDIR to
930 # "${TOP_objdir}/tooldir.${host_ostype}". However, in practice
931 # we might have the wrong value of TOP_objdir, so we also try
932 # some other possibilities.
934 local possible_TOP_OBJ
935 local possible_TOOLDIR
936 for possible_TOP_OBJ
in "${TOP_objdir}" "${TOP}" "${TOP}/obj" \
937 "${TOP}/obj.${MACHINE}"
939 possible_TOOLDIR
="${possible_TOP_OBJ}/tooldir.${host_ostype}"
940 guess_make
="${possible_TOOLDIR}/bin/${toolprefix}make"
941 if [ -x "${guess_make}" ]; then
948 # If the above didn't work, search the PATH for a suitable
949 # ${toolprefix}make, nbmake, bmake, or make.
951 : ${guess_make:=$(find_in_PATH ${toolprefix}make '')}
952 : ${guess_make:=$(find_in_PATH nbmake '')}
953 : ${guess_make:=$(find_in_PATH bmake '')}
954 : ${guess_make:=$(find_in_PATH make '')}
956 # Use ${guess_make} with nobomb_getmakevar to try to find
957 # the value of TOOLDIR. If this fails, unset TOOLDIR.
960 if [ -x "${guess_make}" ]; then
961 TOOLDIR
=$
(make="${guess_make}" nobomb_getmakevar TOOLDIR
)
962 [ $?
-eq 0 -a -n "${TOOLDIR}" ] ||
unset TOOLDIR
968 # Test make source file timestamps against installed ${toolprefix}make
969 # binary, if TOOLDIR is pre-set or if try_set_TOOLDIR can set it.
972 make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
973 if [ -x "${make}" ]; then
974 for f
in usr.bin
/make
/*.
[ch
] usr.bin
/make
/lst.lib
/*.
[ch
]; do
975 if [ "${f}" -nt "${make}" ]; then
976 statusmsg
"${make} outdated (older than ${f}), needs building."
982 statusmsg
"No ${make}, needs building."
986 # Build bootstrap ${toolprefix}make if needed.
987 if ${do_rebuildmake}; then
988 statusmsg
"Bootstrapping ${toolprefix}make"
989 ${runcmd} cd "${tmpdir}"
990 ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
991 CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
992 ${HOST_SH} "${TOP}/tools
/make
/configure
" ||
993 bomb "Configure of
${toolprefix}make failed
"
994 ${runcmd} ${HOST_SH} buildmake.sh ||
995 bomb "Build of
${toolprefix}make failed
"
996 make="${tmpdir}/${toolprefix}make"
997 ${runcmd} cd "${TOP}"
998 ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1002 validatemakeparams()
1004 if [ "${runcmd}" = "echo" ]; then
1005 TOOLCHAIN_MISSING=no
1006 EXTERNAL_TOOLCHAIN=""
1008 TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
1009 EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
1011 if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1012 [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1013 ${runcmd} echo "ERROR
: build.sh
(in-tree cross-toolchain
) is not yet available
for"
1014 ${runcmd} echo " MACHINE
: ${MACHINE}"
1015 ${runcmd} echo " MACHINE_ARCH
: ${MACHINE_ARCH}"
1017 ${runcmd} echo "All builds
for this platform should be
done via a traditional
make"
1018 ${runcmd} echo "If you wish to use an external cross-toolchain
, set"
1019 ${runcmd} echo " EXTERNAL_TOOLCHAIN
=<path to toolchain root
>"
1020 ${runcmd} echo "in either the environment or mk.conf and rerun
"
1021 ${runcmd} echo " ${progname} $
*"
1025 # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
1026 # These may be set as build.sh options or in "mk.conf
".
1027 # Don't export them as they're only used for tests in build.sh.
1029 MKOBJDIRS=$(getmakevar MKOBJDIRS)
1030 MKUNPRIVED=$(getmakevar MKUNPRIVED)
1031 MKUPDATE=$(getmakevar MKUPDATE)
1033 if [ "${MKOBJDIRS}" != "no
" ]; then
1034 # Try to create the top level object directory before
1035 # running "make obj
", otherwise <bsd.own.mk> will not
1036 # set the correct value for _SRC_TOP_OBJ_.
1038 # If either -M or -O was specified, then we have the
1039 # directory name already.
1041 # If neither -M nor -O was specified, then try to get
1042 # the directory name from bsd.obj.mk's __usrobjdir
1043 # variable, which is set using complex rules. This
1044 # works only if TOP = /usr/src.
1046 top_obj_dir="${TOP_objdir}"
1047 if [ -z "${top_obj_dir}" ]; then
1048 if [ "$TOP" = "/usr
/src
" ]; then
1049 top_obj_dir="$
(getmakevar __usrobjdir
)"
1050 # else __usrobjdir is not actually used
1054 case "$top_obj_dir" in
1056 ${runcmd} mkdir -p "${top_obj_dir}" \
1057 || bomb "Can
't create object" \
1058 "directory ${top_obj_dir}"
1061 # We don't know what the top level object
1062 # directory should be, so we can't create it.
1063 # A nonexistant directory might cause an error
1064 # when we "make obj" later, but we ignore it for
1069 # make obj in tools to ensure that the objdir for the top-level
1070 # of the source tree and for "tools" is available, in case the
1071 # default TOOLDIR setting from <bsd.own.mk> is used, or the
1072 # build.sh default DESTDIR and RELEASEDIR is to be used.
1075 ${runcmd} "${make}" -m ${TOP}/share
/mk obj NOSUBDIR
= ||
1076 bomb
"Failed to make obj in tools"
1077 ${runcmd} cd "${TOP}"
1080 # Find TOOLDIR, DESTDIR, RELEASEDIR, and RELEASEMACHINEDIR.
1082 TOOLDIR
=$
(getmakevar TOOLDIR
)
1083 statusmsg
"TOOLDIR path: ${TOOLDIR}"
1084 DESTDIR
=$
(getmakevar DESTDIR
)
1085 RELEASEDIR
=$
(getmakevar RELEASEDIR
)
1086 RELEASEMACHINEDIR
=$
(getmakevar RELEASEMACHINEDIR
)
1087 if ! $do_expertmode; then
1088 _SRC_TOP_OBJ_
=$
(getmakevar _SRC_TOP_OBJ_
)
1089 : ${DESTDIR:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
1090 : ${RELEASEDIR:=${_SRC_TOP_OBJ_}/releasedir}
1091 makeenv
="${makeenv} DESTDIR RELEASEDIR"
1093 export TOOLDIR DESTDIR RELEASEDIR
1094 statusmsg
"DESTDIR path: ${DESTDIR}"
1095 statusmsg
"RELEASEDIR path: ${RELEASEDIR}"
1097 # Check validity of TOOLDIR and DESTDIR.
1099 if [ -z "${TOOLDIR}" ] ||
[ "${TOOLDIR}" = "/" ]; then
1100 bomb
"TOOLDIR '${TOOLDIR}' invalid"
1102 removedirs
="${TOOLDIR}"
1104 if [ -z "${DESTDIR}" ] ||
[ "${DESTDIR}" = "/" ]; then
1105 if ${do_build} || ${do_distribution} || ${do_release}; then
1106 if ! ${do_build} || \
1107 [ "${uname_s}" != "NetBSD" ] || \
1108 [ "${uname_m}" != "${MACHINE}" ]; then
1109 bomb
"DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
1111 if ! ${do_expertmode}; then
1112 bomb
"DESTDIR must != / for non -E (expert) builds"
1114 statusmsg
"WARNING: Building to /, in expert mode."
1115 statusmsg
" This may cause your system to break! Reasons include:"
1116 statusmsg
" - your kernel is not up to date"
1117 statusmsg
" - the libraries or toolchain have changed"
1118 statusmsg
" YOU HAVE BEEN WARNED!"
1121 removedirs
="${removedirs} ${DESTDIR}"
1123 if ${do_build} || ${do_distribution} || ${do_release}; then
1124 if ! ${do_expertmode} && \
1125 [ "$id_u" -ne 0 ] && \
1126 [ "${MKUNPRIVED}" = "no" ] ; then
1127 bomb
"-U or -E must be set for build as an unprivileged user."
1130 if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
1131 bomb
"Must set RELEASEDIR with \`releasekernel=...'"
1134 # Install as non-root is a bad idea.
1136 if ${do_install} && [ "$id_u" -ne 0 ] ; then
1137 if ${do_expertmode}; then
1138 warning
"Will install as an unprivileged user."
1140 bomb
"-E must be set for install as an unprivileged user."
1144 # If a previous build.sh run used -U (and therefore created a
1145 # METALOG file), then most subsequent build.sh runs must also
1146 # use -U. If DESTDIR is about to be removed, then don't perform
1149 case "${do_removedirs} ${removedirs} " in
1150 true
*" ${DESTDIR} "*)
1151 # DESTDIR is about to be removed
1154 if ( ${do_build} || ${do_distribution} || ${do_release} || \
1155 ${do_install} ) && \
1156 [ -e "${DESTDIR}/METALOG" ] && \
1157 [ "${MKUNPRIVED}" = "no" ] ; then
1158 if $do_expertmode; then
1159 warning
"A previous build.sh run specified -U."
1161 bomb
"A previous build.sh run specified -U; you must specify it again now."
1171 # Remove the target directories.
1173 if ${do_removedirs}; then
1174 for f
in ${removedirs}; do
1175 statusmsg
"Removing ${f}"
1176 ${runcmd} rm -r -f "${f}"
1180 # Recreate $TOOLDIR.
1182 ${runcmd} mkdir
-p "${TOOLDIR}/bin" ||
1183 bomb
"mkdir of '${TOOLDIR}/bin' failed"
1185 # Install ${toolprefix}make if it was built.
1187 if ${do_rebuildmake}; then
1188 ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
1189 ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
1190 bomb
"Failed to install \$TOOLDIR/bin/${toolprefix}make"
1191 make="${TOOLDIR}/bin/${toolprefix}make"
1192 statusmsg
"Created ${make}"
1195 # Build a ${toolprefix}make wrapper script, usable by hand as
1196 # well as by build.sh.
1198 if [ -z "${makewrapper}" ]; then
1199 makewrapper
="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1200 [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1203 ${runcmd} rm -f "${makewrapper}"
1204 if [ "${runcmd}" = "echo" ]; then
1205 echo 'cat <<EOF >'${makewrapper}
1208 makewrapout
=">>\${makewrapper}"
1211 case "${KSH_VERSION:-${SH_VERSION}}" in
1212 *PD\ KSH
*|
*MIRBSD\ KSH
*)
1217 eval cat <<EOF ${makewrapout}
1219 # Set proper variables to allow easy "make" building of a NetBSD subtree.
1220 # Generated from: \$NetBSD: build.sh,v 1.205 2009/03/09 06:25:51 apb Exp $
1221 # with these arguments: ${_args}
1226 for f
in ${makeenv}; do
1227 if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
1228 eval echo "unset ${f}"
1230 eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
1235 MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
1236 USETOOLS=yes; export USETOOLS
1238 } |
eval sort -u "${makewrapout}"
1239 eval cat <<EOF "${makewrapout}"
1241 exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1243 [ "${runcmd}" = "echo" ] && echo EOF
1244 ${runcmd} chmod +x
"${makewrapper}"
1245 statusmsg
"makewrapper: ${makewrapper}"
1246 statusmsg
"Updated ${makewrapper}"
1253 ${runcmd} cd "${dir}" ||
1254 bomb
"Failed to cd to \"${dir}\""
1255 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1256 bomb
"Failed to make ${op} in \"${dir}\""
1257 ${runcmd} cd "${TOP}" ||
1258 bomb
"Failed to cd back to \"${TOP}\""
1263 if [ "${MKOBJDIRS}" != "no" ]; then
1264 ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
1265 bomb
"Failed to make obj-tools"
1267 if [ "${MKUPDATE}" = "no" ]; then
1268 make_in_dir tools cleandir
1270 make_in_dir tools dependall
1271 make_in_dir tools
install
1272 statusmsg
"Tools built to ${TOOLDIR}"
1278 if [ "${MKOBJDIRS}" != "no" ]; then
1279 # The correct value of KERNOBJDIR might
1280 # depend on a prior "make obj" in
1281 # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
1283 KERNSRCDIR
="$(getmakevar KERNSRCDIR)"
1284 KERNARCHDIR
="$(getmakevar KERNARCHDIR)"
1285 make_in_dir
"${KERNSRCDIR}/${KERNARCHDIR}/compile" obj
1287 KERNCONFDIR
="$(getmakevar KERNCONFDIR)"
1288 KERNOBJDIR
="$(getmakevar KERNOBJDIR)"
1289 case "${kernelconf}" in
1291 kernelconfpath
="${kernelconf}"
1292 kernelconfname
="${kernelconf##*/}"
1295 kernelconfpath
="${KERNCONFDIR}/${kernelconf}"
1296 kernelconfname
="${kernelconf}"
1299 kernelbuildpath
="${KERNOBJDIR}/${kernelconfname}"
1304 if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
1305 # Building tools every time we build a kernel is clearly
1306 # unnecessary. We could try to figure out whether rebuilding
1307 # the tools is necessary this time, but it doesn't seem worth
1308 # the trouble. Instead, we say it's the user's responsibility
1309 # to rebuild the tools if necessary.
1311 statusmsg
"Building kernel without building new tools"
1312 buildkernelwarned
=true
1315 statusmsg
"Building kernel: ${kernelconf}"
1316 statusmsg
"Build directory: ${kernelbuildpath}"
1317 ${runcmd} mkdir
-p "${kernelbuildpath}" ||
1318 bomb
"Cannot mkdir: ${kernelbuildpath}"
1319 if [ "${MKUPDATE}" = "no" ]; then
1320 make_in_dir
"${kernelbuildpath}" cleandir
1322 [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
1323 || bomb
"${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1324 ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
1325 -s "${TOP}/sys
" "${kernelconfpath}" ||
1326 bomb "${toolprefix}config failed
for ${kernelconf}"
1327 make_in_dir "${kernelbuildpath}" depend
1328 make_in_dir "${kernelbuildpath}" all
1330 if [ "${runcmd}" != "echo" ]; then
1331 statusmsg "Kernels built from
${kernelconf}:"
1332 kernlist=$(awk '$1 == "config
" { print $2 }' ${kernelconfpath})
1333 for kern in ${kernlist:-netbsd}; do
1334 [ -f "${kernelbuildpath}/${kern}" ] && \
1335 echo " ${kernelbuildpath}/${kern}"
1336 done | tee -a "${results}"
1343 kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary
/kernel
"
1344 ${runcmd} mkdir -p "${kernelreldir}"
1345 kernlist=$(awk '$1 == "config
" { print $2 }' ${kernelconfpath})
1346 for kern in ${kernlist:-netbsd}; do
1347 builtkern="${kernelbuildpath}/${kern}"
1348 [ -f "${builtkern}" ] || continue
1349 releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz
"
1350 statusmsg "Kernel copy
: ${releasekern}"
1351 if [ "${runcmd}" = "echo" ]; then
1352 echo "gzip -c -9 < ${builtkern} > ${releasekern}"
1354 gzip -c -9 < "${builtkern}" > "${releasekern}"
1362 ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
1363 bomb
"Failed to make installworld to ${dir}"
1364 statusmsg
"Successful installworld to ${dir}"
1377 statusmsg
"${progname} command: $0 $@"
1378 statusmsg
"${progname} started: ${build_start}"
1379 statusmsg
"NetBSD version: ${DISTRIBVER}"
1380 statusmsg
"MACHINE: ${MACHINE}"
1381 statusmsg
"MACHINE_ARCH: ${MACHINE_ARCH}"
1382 statusmsg
"Build platform: ${uname_s} ${uname_r} ${uname_m}"
1383 statusmsg
"HOST_SH: ${HOST_SH}"
1389 # Perform the operations.
1391 for op
in ${operations}; do
1403 statusmsg
"Building sets from pre-populated ${DESTDIR}"
1404 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1405 bomb
"Failed to make ${op}"
1406 setdir
=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary
/sets
1407 statusmsg
"Built sets to ${setdir}"
1410 cleandir|obj|build|distribution|release|sourcesets|syspkgs|params
)
1411 ${runcmd} "${makewrapper}" ${parallel} ${op} ||
1412 bomb
"Failed to make ${op}"
1413 statusmsg
"Successful make ${op}"
1416 iso-image|iso-image-source
)
1417 ${runcmd} "${makewrapper}" ${parallel} \
1418 CDEXTRA
="$iso_dir" ${op} ||
1419 bomb
"Failed to make ${op}"
1420 statusmsg
"Successful make ${op}"
1425 buildkernel
"${arg}"
1430 releasekernel
"${arg}"
1435 if [ "${arg}" = "/" ] && \
1436 ( [ "${uname_s}" != "NetBSD" ] || \
1437 [ "${uname_m}" != "${MACHINE}" ] ); then
1438 bomb
"'${op}' must != / for cross builds."
1440 installworld
"${arg}"
1444 bomb
"Unknown operation \`${op}'"
1450 statusmsg
"${progname} ended: $(date)"
1451 if [ -s "${results}" ]; then
1452 echo "===> Summary of results:"
1453 sed -e 's/^===>//;s/^/ /' "${results}"