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

Annotation of src/build.sh, Revision 1.132

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

CVSweb <webmaster@jp.NetBSD.org>