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

Annotation of src/build.sh, Revision 1.175

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

CVSweb <webmaster@jp.NetBSD.org>