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

Annotation of src/build.sh, Revision 1.136

1.67      thorpej     1: #! /usr/bin/env sh
1.136   ! lukem       2: #      $NetBSD: build.sh,v 1.135 2005/03/26 06:02:13 isaki Exp $
1.84      lukem       3: #
1.136   ! lukem       4: # Copyright (c) 2001-2005 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: # 3. All advertising materials mentioning features or use of this software
                     19: #    must display the following acknowledgement:
                     20: #        This product includes software developed by the NetBSD
                     21: #        Foundation, Inc. and its contributors.
                     22: # 4. Neither the name of The NetBSD Foundation nor the names of its
                     23: #    contributors may be used to endorse or promote products derived
                     24: #    from this software without specific prior written permission.
                     25: #
                     26: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36: # POSSIBILITY OF SUCH DAMAGE.
                     37: #
1.1       tv         38: #
                     39: # Top level build wrapper, for a system containing no tools.
                     40: #
                     41: # This script should run on any POSIX-compliant shell.  For systems
1.33      tv         42: # with a strange /bin/sh, "ksh" or "bash" may be an ample alternative.
1.1       tv         43: #
1.67      thorpej    44: # Note, however, that due to the way the interpreter is invoked above,
                     45: # if a POSIX-compliant shell is the first in the PATH, you won't have
                     46: # to take any further action.
                     47: #
1.1       tv         48:
1.84      lukem      49: progname=${0##*/}
                     50: toppid=$$
1.98      lukem      51: results=/dev/null
1.82      lukem      52: trap "exit 1" 1 2 3 15
1.84      lukem      53:
1.79      lukem      54: bomb()
                     55: {
1.82      lukem      56:        cat >&2 <<ERRORMESSAGE
                     57:
                     58: ERROR: $@
                     59: *** BUILD ABORTED ***
                     60: ERRORMESSAGE
1.98      lukem      61:        kill ${toppid}          # in case we were invoked from a subshell
1.1       tv         62:        exit 1
                     63: }
1.78      lukem      64:
1.84      lukem      65:
1.98      lukem      66: statusmsg()
                     67: {
                     68:        ${runcmd} echo "===> $@" | tee -a "${results}"
                     69: }
                     70:
1.84      lukem      71: initdefaults()
                     72: {
                     73:        cd "$(dirname $0)"
                     74:        [ -d usr.bin/make ] ||
                     75:            bomb "build.sh must be run from the top source level"
                     76:        [ -f share/mk/bsd.own.mk ] ||
                     77:            bomb "src/share/mk is missing; please re-fetch the source tree"
                     78:
                     79:        uname_s=$(uname -s 2>/dev/null)
                     80:        uname_m=$(uname -m 2>/dev/null)
                     81:
                     82:        # If $PWD is a valid name of the current directory, POSIX mandates
                     83:        # that pwd return it by default which causes problems in the
                     84:        # presence of symlinks.  Unsetting PWD is simpler than changing
                     85:        # every occurrence of pwd to use -P.
                     86:        #
                     87:        # XXX Except that doesn't work on Solaris.
1.98      lukem      88:        #
1.84      lukem      89:        unset PWD
1.124     lukem      90:        TOP=$(/bin/pwd -P 2>/dev/null)
1.84      lukem      91:
                     92:        # Set defaults.
1.98      lukem      93:        #
1.84      lukem      94:        toolprefix=nb
1.98      lukem      95:
1.95      thorpej    96:        # Some systems have a small ARG_MAX.  -X prevents make(1) from
                     97:        # exporting variables in the environment redundantly.
1.98      lukem      98:        #
1.95      thorpej    99:        case "${uname_s}" in
1.97      christos  100:        Darwin | FreeBSD | CYGWIN*)
1.95      thorpej   101:                MAKEFLAGS=-X
                    102:                ;;
                    103:        *)
                    104:                MAKEFLAGS=
                    105:                ;;
                    106:        esac
1.98      lukem     107:
1.84      lukem     108:        makeenv=
                    109:        makewrapper=
1.102     lukem     110:        makewrappermachine=
1.84      lukem     111:        runcmd=
                    112:        operations=
                    113:        removedirs=
                    114:        do_expertmode=false
                    115:        do_rebuildmake=false
                    116:        do_removedirs=false
                    117:
                    118:        # do_{operation}=true if given operation is requested.
                    119:        #
                    120:        do_tools=false
                    121:        do_obj=false
                    122:        do_build=false
                    123:        do_distribution=false
                    124:        do_release=false
                    125:        do_kernel=false
1.105     lukem     126:        do_releasekernel=false
1.84      lukem     127:        do_install=false
1.87      lukem     128:        do_sets=false
1.100     lukem     129:        do_sourcesets=false
1.107     lukem     130:        do_params=false
1.98      lukem     131:
                    132:        # Create scratch directory
                    133:        #
                    134:        tmpdir="${TMPDIR-/tmp}/nbbuild$$"
                    135:        mkdir "${tmpdir}" || bomb "Cannot mkdir: ${tmpdir}"
                    136:        trap "cd /; rm -r -f \"${tmpdir}\"" 0
                    137:        results="${tmpdir}/build.sh.results"
1.116     jmmv      138:
                    139:        # Set source directories
                    140:        #
                    141:        setmakeenv NETBSDSRCDIR "${TOP}"
1.136   ! lukem     142:
        !           143:        # Set various environment variables to known defaults,
        !           144:        # to minimize (cross-)build problems observed "in the field".
        !           145:        #
        !           146:        unsetmakeenv INFODIR
        !           147:        setmakeenv LC_ALL C
1.84      lukem     148: }
1.29      jmc       149:
1.79      lukem     150: getarch()
                    151: {
1.1       tv        152:        # Translate a MACHINE into a default MACHINE_ARCH.
1.84      lukem     153:        #
1.98      lukem     154:        case "${MACHINE}" in
1.1       tv        155:
1.134     gavan     156:        acorn26|acorn32|cats|evbarm|hpcarm|iyonix|netwinder|shark)
1.84      lukem     157:                MACHINE_ARCH=arm
                    158:                ;;
                    159:
1.98      lukem     160:        hp700)
                    161:                MACHINE_ARCH=hppa
                    162:                ;;
                    163:
1.84      lukem     164:        sun2)
                    165:                MACHINE_ARCH=m68000
                    166:                ;;
                    167:
1.98      lukem     168:        amiga|atari|cesfic|hp300|luna68k|mac68k|mvme68k|news68k|next68k|sun3|x68k)
1.84      lukem     169:                MACHINE_ARCH=m68k
                    170:                ;;
1.1       tv        171:
1.101     lukem     172:        evbmips-e[bl]|sbmips-e[bl])
                    173:                MACHINE_ARCH=mips${MACHINE##*-}
1.102     lukem     174:                makewrappermachine=${MACHINE}
1.101     lukem     175:                MACHINE=${MACHINE%-e[bl]}
                    176:                ;;
                    177:
                    178:        evbmips|sbmips)         # no default MACHINE_ARCH
                    179:                ;;
                    180:
                    181:        mipsco|newsmips|sgimips)
1.84      lukem     182:                MACHINE_ARCH=mipseb
                    183:                ;;
1.1       tv        184:
1.101     lukem     185:        algor|arc|cobalt|hpcmips|playstation2|pmax)
1.84      lukem     186:                MACHINE_ARCH=mipsel
                    187:                ;;
1.1       tv        188:
1.84      lukem     189:        pc532)
                    190:                MACHINE_ARCH=ns32k
                    191:                ;;
1.1       tv        192:
1.118     matt      193:        amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|pmppc|prep|sandpoint)
1.84      lukem     194:                MACHINE_ARCH=powerpc
                    195:                ;;
1.1       tv        196:
1.103     lukem     197:        evbsh3-e[bl])
                    198:                MACHINE_ARCH=sh3${MACHINE##*-}
                    199:                makewrappermachine=${MACHINE}
                    200:                MACHINE=${MACHINE%-e[bl]}
                    201:                ;;
                    202:
                    203:        evbsh3)                 # no default MACHINE_ARCH
                    204:                ;;
                    205:
                    206:        mmeye)
1.84      lukem     207:                MACHINE_ARCH=sh3eb
                    208:                ;;
1.1       tv        209:
1.84      lukem     210:        dreamcast|hpcsh)
                    211:                MACHINE_ARCH=sh3el
                    212:                ;;
1.1       tv        213:
1.84      lukem     214:        evbsh5)
                    215:                MACHINE_ARCH=sh5el
                    216:                ;;
1.96      fvdl      217:        amd64)
                    218:                MACHINE_ARCH=x86_64
                    219:                ;;
1.62      fredette  220:
1.128     cl        221:        xen-*)
                    222:                setmakeenv XEN_BUILD "${MACHINE##*-}"
                    223:                setmakeenv KERNARCHDIR "arch/xen"
                    224:                setmakeenv RELEASEMACHINE "xen"
                    225:                setmakeenv RELEASEMACHINEDIR "${MACHINE}"
                    226:                makewrappermachine=${MACHINE}
                    227:                MACHINE=${MACHINE##*-}
                    228:                getarch
                    229:                ;;
                    230:
                    231:        xen)                    # no default MACHINE_ARCH
                    232:                ;;
                    233:
1.96      fvdl      234:        alpha|i386|sparc|sparc64|vax)
1.98      lukem     235:                MACHINE_ARCH=${MACHINE}
1.84      lukem     236:                ;;
1.69      thorpej   237:
1.84      lukem     238:        *)
1.98      lukem     239:                bomb "Unknown target MACHINE: ${MACHINE}"
1.84      lukem     240:                ;;
1.4       tv        241:
1.1       tv        242:        esac
                    243: }
                    244:
1.79      lukem     245: validatearch()
                    246: {
1.47      tv        247:        # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
1.84      lukem     248:        #
1.98      lukem     249:        case "${MACHINE_ARCH}" in
1.47      tv        250:
1.84      lukem     251:        alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|ns32k|powerpc|sh[35]e[bl]|sparc|sparc64|vax|x86_64)
                    252:                ;;
                    253:
1.101     lukem     254:        "")
                    255:                bomb "No MACHINE_ARCH provided"
                    256:                ;;
                    257:
1.84      lukem     258:        *)
1.98      lukem     259:                bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
                    260:                ;;
                    261:
                    262:        esac
                    263:
                    264:        # Determine valid MACHINE_ARCHs for MACHINE
                    265:        #
                    266:        case "${MACHINE}" in
                    267:
                    268:        evbarm)
                    269:                arches="arm armeb"
                    270:                ;;
                    271:
                    272:        evbmips|sbmips)
                    273:                arches="mipseb mipsel"
                    274:                ;;
                    275:
                    276:        evbsh3)
                    277:                arches="sh3eb sh3el"
                    278:                ;;
                    279:
                    280:        evbsh5)
                    281:                arches="sh5eb sh5el"
                    282:                ;;
                    283:
                    284:        *)
                    285:                oma="${MACHINE_ARCH}"
                    286:                getarch
                    287:                arches="${MACHINE_ARCH}"
                    288:                MACHINE_ARCH="${oma}"
1.84      lukem     289:                ;;
                    290:
1.47      tv        291:        esac
1.98      lukem     292:
                    293:        # Ensure that MACHINE_ARCH supports MACHINE
                    294:        #
                    295:        archok=false
                    296:        for a in ${arches}; do
                    297:                if [ "${a}" = "${MACHINE_ARCH}" ]; then
                    298:                        archok=true
                    299:                        break
                    300:                fi
                    301:        done
                    302:        ${archok} ||
                    303:            bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
1.47      tv        304: }
                    305:
1.98      lukem     306: raw_getmakevar()
1.79      lukem     307: {
1.98      lukem     308:        [ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable"
                    309:        "${make}" -m ${TOP}/share/mk -s -f- _x_ <<EOF
1.15      tv        310: _x_:
                    311:        echo \${$1}
                    312: .include <bsd.prog.mk>
1.70      lukem     313: .include <bsd.kernobj.mk>
1.15      tv        314: EOF
                    315: }
                    316:
1.98      lukem     317: getmakevar()
1.82      lukem     318: {
1.98      lukem     319:        # raw_getmakevar() doesn't work properly if $make hasn't yet been
                    320:        # built, which can happen when running with the "-n" option.
                    321:        # getmakevar() deals with this by emitting a literal '$'
1.84      lukem     322:        # followed by the variable name, instead of trying to find the
                    323:        # variable's value.
                    324:        #
1.98      lukem     325:        if [ -x "${make}" ]; then
                    326:                raw_getmakevar "$1"
1.82      lukem     327:        else
                    328:                echo "\$$1"
                    329:        fi
                    330: }
                    331:
1.109     lukem     332: setmakeenv()
                    333: {
                    334:        eval "$1='$2'; export $1"
                    335:        makeenv="${makeenv} $1"
                    336: }
                    337:
1.111     lukem     338: unsetmakeenv()
                    339: {
                    340:        eval "unset $1"
                    341:        makeenv="${makeenv} $1"
                    342: }
                    343:
1.131     junyoung  344: # Convert possibly-relative path to absolute path by prepending
                    345: # ${TOP} if necessary.  Also delete trailing "/", if any.
1.79      lukem     346: resolvepath()
                    347: {
1.98      lukem     348:        case "${OPTARG}" in
1.131     junyoung  349:        /)
                    350:                ;;
1.84      lukem     351:        /*)
1.131     junyoung  352:                OPTARG="${OPTARG%/}"
1.84      lukem     353:                ;;
                    354:        *)
1.131     junyoung  355:                OPTARG="${TOP}/${OPTARG%/}"
1.84      lukem     356:                ;;
1.10      tv        357:        esac
                    358: }
                    359:
1.79      lukem     360: usage()
                    361: {
1.84      lukem     362:        if [ -n "$*" ]; then
                    363:                echo ""
                    364:                echo "${progname}: $*"
                    365:        fi
1.70      lukem     366:        cat <<_usage_
1.83      lukem     367:
1.127     lukem     368: Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-D dest] [-j njob]
1.119     lukem     369:                [-M obj] [-m mach] [-N noisy] [-O obj] [-R release] [-T tools]
1.127     lukem     370:                [-V var=[value]] [-w wrapper] [-X x11src] [-Z var]
                    371:                operation [...]
1.84      lukem     372:
1.86      lukem     373:  Build operations (all imply "obj" and "tools"):
1.125     lukem     374:     build               Run "make build".
                    375:     distribution        Run "make distribution" (includes DESTDIR/etc/ files).
                    376:     release             Run "make release" (includes kernels & distrib media).
1.84      lukem     377:
                    378:  Other operations:
1.125     lukem     379:     help                Show this message and exit.
1.98      lukem     380:     makewrapper         Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
1.125     lukem     381:                         Always performed.
                    382:     obj                 Run "make obj".  [Default unless -o is used]
                    383:     tools               Build and install tools.
                    384:     install=idir        Run "make installworld" to \`idir' to install all sets
                    385:                        except \`etc'.  Useful after "distribution" or "release"
1.105     lukem     386:     kernel=conf         Build kernel with config file \`conf'
1.125     lukem     387:     releasekernel=conf  Install kernel built by kernel=conf to RELEASEDIR.
                    388:     sets                Create binary sets in RELEASEDIR/MACHINE/binary/sets.
                    389:                        DESTDIR should be populated beforehand.
                    390:     sourcesets          Create source sets in RELEASEDIR/source/sets.
                    391:     params              Display various make(1) parameters.
1.84      lukem     392:
                    393:  Options:
1.125     lukem     394:     -a arch     Set MACHINE_ARCH to arch.  [Default: deduced from MACHINE]
                    395:     -B buildId  Set BUILDID to buildId.
1.119     lukem     396:     -D dest     Set DESTDIR to dest.  [Default: destdir.MACHINE]
1.98      lukem     397:     -E          Set "expert" mode; disables various safety checks.
1.127     lukem     398:                 Should not be used without expert knowledge of the build system.
1.129     wiz       399:     -h          Print this help message.
1.125     lukem     400:     -j njob     Run up to njob jobs in parallel; see make(1) -j.
                    401:     -M obj      Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
1.111     lukem     402:                 Unsets MAKEOBJDIR.
1.125     lukem     403:     -m mach     Set MACHINE to mach; not required if NetBSD native.
1.126     lukem     404:     -N noisy   Set the noisyness (MAKEVERBOSE) level of the build:
1.119     lukem     405:                    0   Quiet
                    406:                    1   Operations are described, commands are suppressed
                    407:                    2   Full output
                    408:                [Default: 2]
1.125     lukem     409:     -n          Show commands that would be executed, but do not execute them.
                    410:     -O obj      Set obj root directory to obj; sets a MAKEOBJDIR pattern.
1.111     lukem     411:                 Unsets MAKEOBJDIRPREFIX.
1.125     lukem     412:     -o          Set MKOBJDIRS=no; do not create objdirs at start of build.
1.119     lukem     413:     -R release  Set RELEASEDIR to release.  [Default: releasedir]
1.125     lukem     414:     -r          Remove contents of TOOLDIR and DESTDIR before building.
1.98      lukem     415:     -T tools    Set TOOLDIR to tools.  If unset, and TOOLDIR is not set in
1.125     lukem     416:                 the environment, ${toolprefix}make will be (re)built unconditionally.
                    417:     -U          Set MKUNPRIVED=yes; build without requiring root privileges,
                    418:                install from an UNPRIVED build with proper file permissions.
                    419:     -u          Set MKUPDATE=yes; do not run "make clean" first.
1.98      lukem     420:                Without this, everything is rebuilt, including the tools.
1.125     lukem     421:     -V v=[val]  Set variable \`v' to \`val'.
                    422:     -w wrapper  Create ${toolprefix}make script as wrapper.
1.119     lukem     423:                 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
1.127     lukem     424:     -X x11src   Set X11SRCDIR to x11src.  [Default: /usr/xsrc]
                    425:     -x          Set MKX11=yes; build X11R6 from X11SRCDIR
1.125     lukem     426:     -Z v        Unset ("zap") variable \`v'.
1.83      lukem     427:
1.70      lukem     428: _usage_
1.1       tv        429:        exit 1
                    430: }
                    431:
1.84      lukem     432: parseoptions()
                    433: {
1.127     lukem     434:        opts='a:B:bD:dEhi:j:k:M:m:N:nO:oR:rT:tUuV:w:xX:Z:'
1.84      lukem     435:        opt_a=no
                    436:
                    437:        if type getopts >/dev/null 2>&1; then
                    438:                # Use POSIX getopts.
1.98      lukem     439:                #
                    440:                getoptcmd='getopts ${opts} opt && opt=-${opt}'
1.84      lukem     441:                optargcmd=':'
1.98      lukem     442:                optremcmd='shift $((${OPTIND} -1))'
1.84      lukem     443:        else
                    444:                type getopt >/dev/null 2>&1 ||
                    445:                    bomb "/bin/sh shell is too old; try ksh or bash"
                    446:
                    447:                # Use old-style getopt(1) (doesn't handle whitespace in args).
1.98      lukem     448:                #
                    449:                args="$(getopt ${opts} $*)"
1.84      lukem     450:                [ $? = 0 ] || usage
1.98      lukem     451:                set -- ${args}
1.84      lukem     452:
                    453:                getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
                    454:                optargcmd='OPTARG="$1"; shift'
                    455:                optremcmd=':'
                    456:        fi
                    457:
                    458:        # Parse command line options.
                    459:        #
1.98      lukem     460:        while eval ${getoptcmd}; do
                    461:                case ${opt} in
1.84      lukem     462:
                    463:                -a)
1.98      lukem     464:                        eval ${optargcmd}
                    465:                        MACHINE_ARCH=${OPTARG}
1.84      lukem     466:                        opt_a=yes
                    467:                        ;;
                    468:
                    469:                -B)
1.98      lukem     470:                        eval ${optargcmd}
                    471:                        BUILDID=${OPTARG}
1.84      lukem     472:                        ;;
                    473:
                    474:                -b)
1.86      lukem     475:                        usage "'-b' has been replaced by 'makewrapper'"
1.84      lukem     476:                        ;;
                    477:
                    478:                -D)
1.98      lukem     479:                        eval ${optargcmd}; resolvepath
1.109     lukem     480:                        setmakeenv DESTDIR "${OPTARG}"
1.84      lukem     481:                        ;;
                    482:
                    483:                -d)
                    484:                        usage "'-d' has been replaced by 'distribution'"
                    485:                        ;;
                    486:
                    487:                -E)
                    488:                        do_expertmode=true
                    489:                        ;;
                    490:
                    491:                -i)
                    492:                        usage "'-i idir' has been replaced by 'install=idir'"
                    493:                        ;;
                    494:
                    495:                -j)
1.98      lukem     496:                        eval ${optargcmd}
                    497:                        parallel="-j ${OPTARG}"
1.84      lukem     498:                        ;;
                    499:
                    500:                -k)
                    501:                        usage "'-k conf' has been replaced by 'kernel=conf'"
                    502:                        ;;
                    503:
                    504:                -M)
1.98      lukem     505:                        eval ${optargcmd}; resolvepath
                    506:                        makeobjdir="${OPTARG}"
1.111     lukem     507:                        unsetmakeenv MAKEOBJDIR
1.109     lukem     508:                        setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1.84      lukem     509:                        ;;
                    510:
                    511:                        # -m overrides MACHINE_ARCH unless "-a" is specified
                    512:                -m)
1.98      lukem     513:                        eval ${optargcmd}
                    514:                        MACHINE="${OPTARG}"
                    515:                        [ "${opt_a}" != "yes" ] && getarch
1.84      lukem     516:                        ;;
                    517:
1.119     lukem     518:                -N)
                    519:                        eval ${optargcmd}
                    520:                        case "${OPTARG}" in
1.121     lukem     521:                        0|1|2)
                    522:                                setmakeenv MAKEVERBOSE "${OPTARG}"
1.119     lukem     523:                                ;;
                    524:                        *)
                    525:                                usage "'${OPTARG}' is not a valid value for -N"
                    526:                                ;;
                    527:                        esac
                    528:                        ;;
                    529:
1.84      lukem     530:                -n)
                    531:                        runcmd=echo
                    532:                        ;;
                    533:
                    534:                -O)
1.98      lukem     535:                        eval ${optargcmd}; resolvepath
                    536:                        makeobjdir="${OPTARG}"
1.111     lukem     537:                        unsetmakeenv MAKEOBJDIRPREFIX
1.109     lukem     538:                        setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1.84      lukem     539:                        ;;
                    540:
                    541:                -o)
                    542:                        MKOBJDIRS=no
                    543:                        ;;
                    544:
                    545:                -R)
1.98      lukem     546:                        eval ${optargcmd}; resolvepath
1.109     lukem     547:                        setmakeenv RELEASEDIR "${OPTARG}"
1.84      lukem     548:                        ;;
                    549:
                    550:                -r)
                    551:                        do_removedirs=true
                    552:                        do_rebuildmake=true
                    553:                        ;;
                    554:
                    555:                -T)
1.98      lukem     556:                        eval ${optargcmd}; resolvepath
                    557:                        TOOLDIR="${OPTARG}"
1.84      lukem     558:                        export TOOLDIR
                    559:                        ;;
                    560:
                    561:                -t)
                    562:                        usage "'-t' has been replaced by 'tools'"
                    563:                        ;;
1.16      thorpej   564:
1.84      lukem     565:                -U)
1.109     lukem     566:                        setmakeenv MKUNPRIVED yes
1.84      lukem     567:                        ;;
1.44      lukem     568:
1.84      lukem     569:                -u)
1.109     lukem     570:                        setmakeenv MKUPDATE yes
1.84      lukem     571:                        ;;
1.15      tv        572:
1.84      lukem     573:                -V)
1.98      lukem     574:                        eval ${optargcmd}
1.84      lukem     575:                        case "${OPTARG}" in
1.80      lukem     576:                    # XXX: consider restricting which variables can be changed?
1.84      lukem     577:                        [a-zA-Z_][a-zA-Z_0-9]*=*)
1.109     lukem     578:                                setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1.84      lukem     579:                                ;;
                    580:                        *)
                    581:                                usage "-V argument must be of the form 'var=[value]'"
                    582:                                ;;
                    583:                        esac
                    584:                        ;;
                    585:
                    586:                -w)
1.98      lukem     587:                        eval ${optargcmd}; resolvepath
                    588:                        makewrapper="${OPTARG}"
1.84      lukem     589:                        ;;
                    590:
1.127     lukem     591:                -X)
                    592:                        eval ${optargcmd}; resolvepath
                    593:                        setmakeenv X11SRCDIR "${OPTARG}"
                    594:                        ;;
                    595:
                    596:                -x)
                    597:                        setmakeenv MKX11 yes
                    598:                        ;;
                    599:
1.111     lukem     600:                -Z)
                    601:                        eval ${optargcmd}
                    602:                    # XXX: consider restricting which variables can be unset?
                    603:                        unsetmakeenv "${OPTARG}"
                    604:                        ;;
                    605:
1.84      lukem     606:                --)
                    607:                        break
                    608:                        ;;
                    609:
                    610:                -'?'|-h)
                    611:                        usage
                    612:                        ;;
                    613:
                    614:                esac
                    615:        done
                    616:
                    617:        # Validate operations.
                    618:        #
1.98      lukem     619:        eval ${optremcmd}
1.84      lukem     620:        while [ $# -gt 0 ]; do
                    621:                op=$1; shift
1.98      lukem     622:                operations="${operations} ${op}"
1.84      lukem     623:
1.98      lukem     624:                case "${op}" in
1.84      lukem     625:
1.87      lukem     626:                help)
                    627:                        usage
                    628:                        ;;
                    629:
1.107     lukem     630:                makewrapper|obj|tools|build|distribution|release|sets|sourcesets|params)
1.80      lukem     631:                        ;;
1.84      lukem     632:
1.105     lukem     633:                kernel=*|releasekernel=*)
1.84      lukem     634:                        arg=${op#*=}
                    635:                        op=${op%%=*}
1.98      lukem     636:                        [ -n "${arg}" ] ||
1.105     lukem     637:                            bomb "Must supply a kernel name with \`${op}=...'"
1.84      lukem     638:                        ;;
                    639:
                    640:                install=*)
                    641:                        arg=${op#*=}
                    642:                        op=${op%%=*}
1.98      lukem     643:                        [ -n "${arg}" ] ||
                    644:                            bomb "Must supply a directory with \`install=...'"
1.84      lukem     645:                        ;;
                    646:
1.80      lukem     647:                *)
1.84      lukem     648:                        usage "Unknown operation \`${op}'"
                    649:                        ;;
                    650:
1.80      lukem     651:                esac
1.98      lukem     652:                eval do_${op}=true
1.84      lukem     653:        done
1.98      lukem     654:        [ -n "${operations}" ] || usage "Missing operation to perform."
1.84      lukem     655:
                    656:        # Set up MACHINE*.  On a NetBSD host, these are allowed to be unset.
                    657:        #
1.98      lukem     658:        if [ -z "${MACHINE}" ]; then
                    659:                [ "${uname_s}" = "NetBSD" ] ||
                    660:                    bomb "MACHINE must be set, or -m must be used, for cross builds."
1.84      lukem     661:                MACHINE=${uname_m}
                    662:        fi
1.98      lukem     663:        [ -n "${MACHINE_ARCH}" ] || getarch
1.84      lukem     664:        validatearch
                    665:
                    666:        # Set up default make(1) environment.
                    667:        #
1.98      lukem     668:        makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
                    669:        [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1.115     jmmv      670:        MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1.84      lukem     671:        export MAKEFLAGS MACHINE MACHINE_ARCH
                    672: }
                    673:
                    674: rebuildmake()
                    675: {
                    676:        # Test make source file timestamps against installed ${toolprefix}make
                    677:        # binary, if TOOLDIR is pre-set.
                    678:        #
                    679:        # Note that we do NOT try to grovel "mk.conf" here to find out if
                    680:        # TOOLDIR is set there, because it can contain make variable
                    681:        # expansions and other stuff only parseable *after* we have a working
                    682:        # ${toolprefix}make.  So this logic can only work if the user has
                    683:        # pre-set TOOLDIR in the environment or used the -T option to build.sh.
                    684:        #
                    685:        make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
1.98      lukem     686:        if [ -x "${make}" ]; then
1.84      lukem     687:                for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1.98      lukem     688:                        if [ "${f}" -nt "${make}" ]; then
1.122     lukem     689:                                statusmsg "${make} outdated (older than ${f}), needs building."
1.84      lukem     690:                                do_rebuildmake=true
                    691:                                break
                    692:                        fi
                    693:                done
                    694:        else
1.122     lukem     695:                statusmsg "No ${make}, needs building."
1.84      lukem     696:                do_rebuildmake=true
                    697:        fi
                    698:
                    699:        # Build bootstrap ${toolprefix}make if needed.
1.98      lukem     700:        if ${do_rebuildmake}; then
                    701:                statusmsg "Bootstrapping ${toolprefix}make"
                    702:                ${runcmd} cd "${tmpdir}"
                    703:                ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1.84      lukem     704:                        CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1.113     jmc       705:                        sh "${TOP}/tools/make/configure" ||
1.98      lukem     706:                    bomb "Configure of ${toolprefix}make failed"
                    707:                ${runcmd} sh buildmake.sh ||
                    708:                    bomb "Build of ${toolprefix}make failed"
                    709:                make="${tmpdir}/${toolprefix}make"
                    710:                ${runcmd} cd "${TOP}"
                    711:                ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1.84      lukem     712:        fi
                    713: }
                    714:
                    715: validatemakeparams()
                    716: {
1.98      lukem     717:        if [ "${runcmd}" = "echo" ]; then
1.84      lukem     718:                TOOLCHAIN_MISSING=no
                    719:                EXTERNAL_TOOLCHAIN=""
                    720:        else
1.98      lukem     721:                TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
                    722:                EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
1.84      lukem     723:        fi
                    724:        if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1.86      lukem     725:           [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1.98      lukem     726:                ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
                    727:                ${runcmd} echo "        MACHINE:      ${MACHINE}"
                    728:                ${runcmd} echo "        MACHINE_ARCH: ${MACHINE_ARCH}"
                    729:                ${runcmd} echo ""
                    730:                ${runcmd} echo "All builds for this platform should be done via a traditional make"
                    731:                ${runcmd} echo "If you wish to use an external cross-toolchain, set"
                    732:                ${runcmd} echo "        EXTERNAL_TOOLCHAIN=<path to toolchain root>"
                    733:                ${runcmd} echo "in either the environment or mk.conf and rerun"
                    734:                ${runcmd} echo "        ${progname} $*"
1.84      lukem     735:                exit 1
                    736:        fi
                    737:
1.120     lukem     738:        # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
                    739:        # These may be set as build.sh options or in "mk.conf".
                    740:        # Don't export them as they're only used for tests in build.sh.
                    741:        #
                    742:        MKOBJDIRS=$(getmakevar MKOBJDIRS)
                    743:        MKUNPRIVED=$(getmakevar MKUNPRIVED)
                    744:        MKUPDATE=$(getmakevar MKUPDATE)
                    745:
1.106     lukem     746:        if [ "${MKOBJDIRS}" != "no" ]; then
                    747:                # If setting -M or -O to the root of an obj dir, make sure
                    748:                # the base directory is made before continuing as <bsd.own.mk>
                    749:                # will need this to pick up _SRC_TOP_OBJ_
                    750:                #
                    751:                if [ ! -z "${makeobjdir}" ]; then
                    752:                        ${runcmd} mkdir -p "${makeobjdir}"
                    753:                fi
                    754:
                    755:                # make obj in tools to ensure that the objdir for the top-level
                    756:                # of the source tree and for "tools" is available, in case the
                    757:                # default TOOLDIR setting from <bsd.own.mk> is used, or the
                    758:                # build.sh default DESTDIR and RELEASEDIR is to be used.
                    759:                #
1.98      lukem     760:                ${runcmd} cd tools
                    761:                ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
                    762:                    bomb "Failed to make obj in tools"
                    763:                ${runcmd} cd "${TOP}"
1.84      lukem     764:        fi
1.80      lukem     765:
1.105     lukem     766:        statusmsg "MACHINE:          ${MACHINE}"
                    767:        statusmsg "MACHINE_ARCH:     ${MACHINE_ARCH}"
1.98      lukem     768:
                    769:        # Find TOOLDIR, DESTDIR, and RELEASEDIR.
1.84      lukem     770:        #
1.98      lukem     771:        TOOLDIR=$(getmakevar TOOLDIR)
1.105     lukem     772:        statusmsg "TOOLDIR path:     ${TOOLDIR}"
1.98      lukem     773:        DESTDIR=$(getmakevar DESTDIR)
                    774:        RELEASEDIR=$(getmakevar RELEASEDIR)
                    775:        if ! $do_expertmode; then
1.105     lukem     776:                _SRC_TOP_OBJ_=$(getmakevar _SRC_TOP_OBJ_)
                    777:                : ${DESTDIR:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
                    778:                : ${RELEASEDIR:=${_SRC_TOP_OBJ_}/releasedir}
1.99      lukem     779:                makeenv="${makeenv} DESTDIR RELEASEDIR"
1.98      lukem     780:        fi
1.99      lukem     781:        export TOOLDIR DESTDIR RELEASEDIR
1.105     lukem     782:        statusmsg "DESTDIR path:     ${DESTDIR}"
                    783:        statusmsg "RELEASEDIR path:  ${RELEASEDIR}"
1.84      lukem     784:
                    785:        # Check validity of TOOLDIR and DESTDIR.
                    786:        #
1.98      lukem     787:        if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
                    788:                bomb "TOOLDIR '${TOOLDIR}' invalid"
1.84      lukem     789:        fi
1.98      lukem     790:        removedirs="${TOOLDIR}"
1.15      tv        791:
1.98      lukem     792:        if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
                    793:                if ${do_build} || ${do_distribution} || ${do_release}; then
                    794:                        if ! ${do_build} || \
1.84      lukem     795:                           [ "${uname_s}" != "NetBSD" ] || \
1.98      lukem     796:                           [ "${uname_m}" != "${MACHINE}" ]; then
1.84      lukem     797:                                bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
                    798:                        fi
1.98      lukem     799:                        if ! ${do_expertmode}; then
1.84      lukem     800:                                bomb "DESTDIR must != / for non -E (expert) builds"
                    801:                        fi
1.98      lukem     802:                        statusmsg "WARNING: Building to /, in expert mode."
                    803:                        statusmsg "         This may cause your system to break!  Reasons include:"
                    804:                        statusmsg "            - your kernel is not up to date"
                    805:                        statusmsg "            - the libraries or toolchain have changed"
                    806:                        statusmsg "         YOU HAVE BEEN WARNED!"
1.1       tv        807:                fi
1.84      lukem     808:        else
1.98      lukem     809:                removedirs="${removedirs} ${DESTDIR}"
1.84      lukem     810:        fi
1.98      lukem     811:        if ${do_build} || ${do_distribution} || ${do_release}; then
                    812:                if ! ${do_expertmode} && \
1.108     lukem     813:                    [ $(id -u 2>/dev/null) -ne 0 ] && \
1.124     lukem     814:                    [ "${MKUNPRIVED}" = "no" ] ; then
1.86      lukem     815:                        bomb "-U or -E must be set for build as an unprivileged user."
                    816:                fi
                    817:         fi
1.105     lukem     818:        if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
                    819:                bomb "Must set RELEASEDIR with \`releasekernel=...'"
                    820:        fi
1.84      lukem     821: }
1.30      jmc       822:
1.15      tv        823:
1.84      lukem     824: createmakewrapper()
                    825: {
                    826:        # Remove the target directories.
                    827:        #
1.98      lukem     828:        if ${do_removedirs}; then
                    829:                for f in ${removedirs}; do
                    830:                        statusmsg "Removing ${f}"
                    831:                        ${runcmd} rm -r -f "${f}"
1.84      lukem     832:                done
                    833:        fi
1.15      tv        834:
1.84      lukem     835:        # Recreate $TOOLDIR.
                    836:        #
1.98      lukem     837:        ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
                    838:            bomb "mkdir of '${TOOLDIR}/bin' failed"
1.84      lukem     839:
                    840:        # Install ${toolprefix}make if it was built.
                    841:        #
1.98      lukem     842:        if ${do_rebuildmake}; then
                    843:                ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
                    844:                ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
                    845:                    bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
                    846:                make="${TOOLDIR}/bin/${toolprefix}make"
                    847:                statusmsg "Created ${make}"
1.84      lukem     848:        fi
1.15      tv        849:
1.84      lukem     850:        # Build a ${toolprefix}make wrapper script, usable by hand as
                    851:        # well as by build.sh.
                    852:        #
1.98      lukem     853:        if [ -z "${makewrapper}" ]; then
1.102     lukem     854:                makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1.98      lukem     855:                [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1.52      thorpej   856:        fi
1.4       tv        857:
1.98      lukem     858:        ${runcmd} rm -f "${makewrapper}"
                    859:        if [ "${runcmd}" = "echo" ]; then
                    860:                echo 'cat <<EOF >'${makewrapper}
1.84      lukem     861:                makewrapout=
                    862:        else
1.98      lukem     863:                makewrapout=">>\${makewrapper}"
1.84      lukem     864:        fi
1.18      tv        865:
1.135     isaki     866:        case "${uname_s}" in
                    867:        OpenBSD)
                    868:                set +o braceexpand
                    869:                ;;
                    870:        esac
                    871:
1.98      lukem     872:        eval cat <<EOF ${makewrapout}
1.4       tv        873: #! /bin/sh
                    874: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.136   ! lukem     875: # Generated from:  \$NetBSD: build.sh,v 1.135 2005/03/26 06:02:13 isaki Exp $
1.130     jmc       876: # with these arguments: ${_args}
1.4       tv        877: #
1.18      tv        878: EOF
1.98      lukem     879:        for f in ${makeenv}; do
1.111     lukem     880:                if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
                    881:                        eval echo "unset ${f}" ${makewrapout}
                    882:                else
                    883:                        eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}" ${makewrapout}
                    884:                fi
1.84      lukem     885:        done
1.98      lukem     886:        eval echo "USETOOLS=yes\; export USETOOLS" ${makewrapout}
1.18      tv        887:
1.98      lukem     888:        eval cat <<EOF ${makewrapout}
1.18      tv        889:
1.98      lukem     890: exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1.4       tv        891: EOF
1.98      lukem     892:        [ "${runcmd}" = "echo" ] && echo EOF
                    893:        ${runcmd} chmod +x "${makewrapper}"
1.105     lukem     894:        statusmsg "makewrapper:      ${makewrapper}"
1.98      lukem     895:        statusmsg "Updated ${makewrapper}"
1.84      lukem     896: }
                    897:
                    898: buildtools()
                    899: {
1.98      lukem     900:        if [ "${MKOBJDIRS}" != "no" ]; then
                    901:                ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
                    902:                    bomb "Failed to make obj-tools"
1.84      lukem     903:        fi
1.98      lukem     904:        ${runcmd} cd tools
1.124     lukem     905:        if [ "${MKUPDATE}" = "no" ]; then
1.84      lukem     906:                cleandir=cleandir
                    907:        else
                    908:                cleandir=
                    909:        fi
1.98      lukem     910:        ${runcmd} "${makewrapper}" ${cleandir} dependall install ||
                    911:            bomb "Failed to make tools"
                    912:        statusmsg "Tools built to ${TOOLDIR}"
1.110     lukem     913:        ${runcmd} cd "${TOP}"
1.84      lukem     914: }
1.4       tv        915:
1.105     lukem     916: getkernelconf()
1.84      lukem     917: {
1.105     lukem     918:        kernelconf="$1"
1.114     lukem     919:        if [ "${MKOBJDIRS}" != "no" ]; then
1.84      lukem     920:                # The correct value of KERNOBJDIR might
                    921:                # depend on a prior "make obj" in
                    922:                # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
                    923:                #
1.98      lukem     924:                KERNSRCDIR="$(getmakevar KERNSRCDIR)"
                    925:                KERNARCHDIR="$(getmakevar KERNARCHDIR)"
                    926:                ${runcmd} cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
                    927:                ${runcmd} "${makewrapper}" obj ||
                    928:                    bomb "Failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
                    929:                ${runcmd} cd "${TOP}"
1.84      lukem     930:        fi
1.98      lukem     931:        KERNCONFDIR="$(getmakevar KERNCONFDIR)"
                    932:        KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1.105     lukem     933:        case "${kernelconf}" in
1.84      lukem     934:        */*)
1.105     lukem     935:                kernelconfpath="${kernelconf}"
                    936:                kernelconfname="${kernelconf##*/}"
1.84      lukem     937:                ;;
                    938:        *)
1.105     lukem     939:                kernelconfpath="${KERNCONFDIR}/${kernelconf}"
                    940:                kernelconfname="${kernelconf}"
1.84      lukem     941:                ;;
                    942:        esac
1.105     lukem     943:        kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
                    944: }
                    945:
                    946: buildkernel()
                    947: {
                    948:        if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
                    949:                # Building tools every time we build a kernel is clearly
                    950:                # unnecessary.  We could try to figure out whether rebuilding
                    951:                # the tools is necessary this time, but it doesn't seem worth
                    952:                # the trouble.  Instead, we say it's the user's responsibility
                    953:                # to rebuild the tools if necessary.
                    954:                #
                    955:                statusmsg "Building kernel without building new tools"
                    956:                buildkernelwarned=true
                    957:        fi
                    958:        getkernelconf $1
                    959:        statusmsg "Building kernel:  ${kernelconf}"
                    960:        statusmsg "Build directory:  ${kernelbuildpath}"
                    961:        ${runcmd} mkdir -p "${kernelbuildpath}" ||
                    962:            bomb "Cannot mkdir: ${kernelbuildpath}"
1.124     lukem     963:        if [ "${MKUPDATE}" = "no" ]; then
1.105     lukem     964:                ${runcmd} cd "${kernelbuildpath}"
1.98      lukem     965:                ${runcmd} "${makewrapper}" cleandir ||
1.105     lukem     966:                    bomb "Failed to make cleandir in ${kernelbuildpath}"
1.98      lukem     967:                ${runcmd} cd "${TOP}"
1.16      thorpej   968:        fi
1.105     lukem     969:        ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
                    970:                -s "${TOP}/sys" "${kernelconfpath}" ||
                    971:            bomb "${toolprefix}config failed for ${kernelconf}"
                    972:        ${runcmd} cd "${kernelbuildpath}"
1.98      lukem     973:        ${runcmd} "${makewrapper}" depend ||
1.105     lukem     974:            bomb "Failed to make depend in ${kernelbuildpath}"
1.98      lukem     975:        ${runcmd} "${makewrapper}" ${parallel} all ||
1.105     lukem     976:            bomb "Failed to make all in ${kernelbuildpath}"
1.98      lukem     977:        ${runcmd} cd "${TOP}"
1.91      lukem     978:
1.98      lukem     979:        if [ "${runcmd}" != "echo" ]; then
1.105     lukem     980:                statusmsg "Kernels built from ${kernelconf}:"
                    981:                kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1.91      lukem     982:                for kern in ${kernlist:-netbsd}; do
1.105     lukem     983:                        [ -f "${kernelbuildpath}/${kern}" ] && \
                    984:                            echo "  ${kernelbuildpath}/${kern}"
1.98      lukem     985:                done | tee -a "${results}"
1.91      lukem     986:        fi
1.84      lukem     987: }
                    988:
1.105     lukem     989: releasekernel()
                    990: {
                    991:        getkernelconf $1
                    992:        kernelreldir="${RELEASEDIR}/${MACHINE}/binary/kernel"
                    993:        ${runcmd} mkdir -p "${kernelreldir}"
                    994:        kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
                    995:        for kern in ${kernlist:-netbsd}; do
                    996:                builtkern="${kernelbuildpath}/${kern}"
                    997:                [ -f "${builtkern}" ] || continue
                    998:                releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
                    999:                statusmsg "Kernel copy:      ${releasekern}"
                   1000:                ${runcmd} gzip -c -9 < "${builtkern}" > "${releasekern}"
                   1001:        done
                   1002: }
                   1003:
1.84      lukem    1004: installworld()
                   1005: {
                   1006:        dir="$1"
1.98      lukem    1007:        ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
                   1008:            bomb "Failed to make installworld to ${dir}"
                   1009:        statusmsg "Successful installworld to ${dir}"
1.84      lukem    1010: }
                   1011:
                   1012:
                   1013: main()
                   1014: {
                   1015:        initdefaults
1.130     jmc      1016:        _args=$@
1.84      lukem    1017:        parseoptions "$@"
1.93      lukem    1018:
                   1019:        build_start=$(date)
1.98      lukem    1020:        statusmsg "${progname} command: $0 $@"
                   1021:        statusmsg "${progname} started: ${build_start}"
1.93      lukem    1022:
1.84      lukem    1023:        rebuildmake
                   1024:        validatemakeparams
                   1025:        createmakewrapper
                   1026:
                   1027:        # Perform the operations.
                   1028:        #
1.98      lukem    1029:        for op in ${operations}; do
                   1030:                case "${op}" in
1.86      lukem    1031:
                   1032:                makewrapper)
                   1033:                        # no-op
                   1034:                        ;;
1.84      lukem    1035:
                   1036:                tools)
                   1037:                        buildtools
                   1038:                        ;;
                   1039:
1.125     lukem    1040:                sets)
                   1041:                        statusmsg "Building sets from pre-populated ${DESTDIR}"
                   1042:                        ${runcmd} "${makewrapper}" ${parallel} ${op} ||
                   1043:                            bomb "Failed to make ${op}"
                   1044:                        statusmsg "Successful make ${op}"
                   1045:                        ;;
                   1046:
                   1047:                obj|build|distribution|release|sourcesets|params)
1.98      lukem    1048:                        ${runcmd} "${makewrapper}" ${parallel} ${op} ||
                   1049:                            bomb "Failed to make ${op}"
                   1050:                        statusmsg "Successful make ${op}"
1.84      lukem    1051:                        ;;
                   1052:
                   1053:                kernel=*)
                   1054:                        arg=${op#*=}
                   1055:                        buildkernel "${arg}"
1.105     lukem    1056:                        ;;
                   1057:
                   1058:                releasekernel=*)
                   1059:                        arg=${op#*=}
                   1060:                        releasekernel "${arg}"
1.84      lukem    1061:                        ;;
                   1062:
                   1063:                install=*)
                   1064:                        arg=${op#*=}
1.85      lukem    1065:                        if [ "${arg}" = "/" ] && \
                   1066:                            (   [ "${uname_s}" != "NetBSD" ] || \
1.98      lukem    1067:                                [ "${uname_m}" != "${MACHINE}" ] ); then
1.85      lukem    1068:                                bomb "'${op}' must != / for cross builds."
                   1069:                        fi
1.84      lukem    1070:                        installworld "${arg}"
1.70      lukem    1071:                        ;;
1.84      lukem    1072:
1.70      lukem    1073:                *)
1.84      lukem    1074:                        bomb "Unknown operation \`${op}'"
1.70      lukem    1075:                        ;;
1.84      lukem    1076:
1.70      lukem    1077:                esac
1.84      lukem    1078:        done
1.93      lukem    1079:
1.104     lukem    1080:        statusmsg "${progname} started: ${build_start}"
1.98      lukem    1081:        statusmsg "${progname} ended:   $(date)"
                   1082:        if [ -s "${results}" ]; then
                   1083:                echo "===> Summary of results:"
                   1084:                sed -e 's/^===>//;s/^/  /' "${results}"
                   1085:                echo "===> ."
                   1086:        fi
1.84      lukem    1087: }
                   1088:
                   1089: main "$@"

CVSweb <webmaster@jp.NetBSD.org>