[BACK]Return to build.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src

Annotation of src/build.sh, Revision 1.258

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

CVSweb <webmaster@jp.NetBSD.org>