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

Annotation of src/build.sh, Revision 1.134

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

CVSweb <webmaster@jp.NetBSD.org>