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

Annotation of src/build.sh, Revision 1.159

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

CVSweb <webmaster@jp.NetBSD.org>