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

Annotation of src/build.sh, Revision 1.265

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

CVSweb <webmaster@jp.NetBSD.org>