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

Annotation of src/build.sh, Revision 1.151

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

CVSweb <webmaster@jp.NetBSD.org>