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

Annotation of src/build.sh, Revision 1.144

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

CVSweb <webmaster@jp.NetBSD.org>