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

Annotation of src/build.sh, Revision 1.171.4.3

1.67      thorpej     1: #! /usr/bin/env sh
1.171.4.3! matt        2: #      build.sh,v 1.171.4.2 2008/01/09 01:19:18 matt Exp
1.84      lukem       3: #
1.136     lukem       4: # Copyright (c) 2001-2005 The NetBSD Foundation, Inc.
1.84      lukem       5: # All rights reserved.
                      6: #
                      7: # This code is derived from software contributed to The NetBSD Foundation
                      8: # by Todd Vierling and Luke Mewburn.
                      9: #
                     10: # Redistribution and use in source and binary forms, with or without
                     11: # modification, are permitted provided that the following conditions
                     12: # are met:
                     13: # 1. Redistributions of source code must retain the above copyright
                     14: #    notice, this list of conditions and the following disclaimer.
                     15: # 2. Redistributions in binary form must reproduce the above copyright
                     16: #    notice, this list of conditions and the following disclaimer in the
                     17: #    documentation and/or other materials provided with the distribution.
                     18: # 3. All advertising materials mentioning features or use of this software
                     19: #    must display the following acknowledgement:
                     20: #        This product includes software developed by the NetBSD
                     21: #        Foundation, Inc. and its contributors.
                     22: # 4. Neither the name of The NetBSD Foundation nor the names of its
                     23: #    contributors may be used to endorse or promote products derived
                     24: #    from this software without specific prior written permission.
                     25: #
                     26: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     27: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     30: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36: # POSSIBILITY OF SUCH DAMAGE.
                     37: #
1.1       tv         38: #
                     39: # Top level build wrapper, for a system containing no tools.
                     40: #
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.171.4.1  matt      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.171.4.3! matt      330:        evbppc64|macppc64|ofppc64)
1.160     matt      331:                makewrappermachine=${MACHINE}
                    332:                MACHINE=${MACHINE%64}
                    333:                MACHINE_ARCH=powerpc64
                    334:                ;;
                    335:
1.171.4.2  matt      336:        amigappc|bebox|evbppc|ibmnws|macppc|mvmeppc|ofppc|prep|rs6000|sandpoint)
1.84      lukem     337:                MACHINE_ARCH=powerpc
                    338:                ;;
1.1       tv        339:
1.103     lukem     340:        evbsh3)                 # no default MACHINE_ARCH
                    341:                ;;
                    342:
                    343:        mmeye)
1.84      lukem     344:                MACHINE_ARCH=sh3eb
                    345:                ;;
1.1       tv        346:
1.152     uwe       347:        dreamcast|hpcsh|landisk)
1.84      lukem     348:                MACHINE_ARCH=sh3el
                    349:                ;;
1.1       tv        350:
1.96      fvdl      351:        amd64)
                    352:                MACHINE_ARCH=x86_64
                    353:                ;;
1.62      fredette  354:
1.138     skrll     355:        alpha|i386|sparc|sparc64|vax|ia64)
1.98      lukem     356:                MACHINE_ARCH=${MACHINE}
1.84      lukem     357:                ;;
1.69      thorpej   358:
1.84      lukem     359:        *)
1.98      lukem     360:                bomb "Unknown target MACHINE: ${MACHINE}"
1.84      lukem     361:                ;;
1.4       tv        362:
1.1       tv        363:        esac
                    364: }
                    365:
1.79      lukem     366: validatearch()
                    367: {
1.47      tv        368:        # Ensure that the MACHINE_ARCH exists (and is supported by build.sh).
1.84      lukem     369:        #
1.98      lukem     370:        case "${MACHINE_ARCH}" in
1.47      tv        371:
1.171.4.3! matt      372:        alpha|arm|armeb|hppa|i386|m68000|m68k|mipse[bl]|mips64e[bl]|powerpc|powerpc64|sh3e[bl]|sparc|sparc64|vax|x86_64|ia64)
1.84      lukem     373:                ;;
                    374:
1.101     lukem     375:        "")
                    376:                bomb "No MACHINE_ARCH provided"
                    377:                ;;
                    378:
1.84      lukem     379:        *)
1.98      lukem     380:                bomb "Unknown target MACHINE_ARCH: ${MACHINE_ARCH}"
                    381:                ;;
                    382:
                    383:        esac
                    384:
                    385:        # Determine valid MACHINE_ARCHs for MACHINE
                    386:        #
                    387:        case "${MACHINE}" in
                    388:
                    389:        evbarm)
                    390:                arches="arm armeb"
                    391:                ;;
                    392:
                    393:        evbmips|sbmips)
1.150     matt      394:                arches="mipseb mipsel mips64eb mips64el"
                    395:                ;;
                    396:
                    397:        sgimips)
                    398:                arches="mipseb mips64eb"
1.98      lukem     399:                ;;
                    400:
                    401:        evbsh3)
                    402:                arches="sh3eb sh3el"
                    403:                ;;
                    404:
1.171.4.3! matt      405:        macppc|evbppc|ofppc)
1.148     mrg       406:                arches="powerpc powerpc64"
                    407:                ;;
1.98      lukem     408:        *)
                    409:                oma="${MACHINE_ARCH}"
                    410:                getarch
                    411:                arches="${MACHINE_ARCH}"
                    412:                MACHINE_ARCH="${oma}"
1.84      lukem     413:                ;;
                    414:
1.47      tv        415:        esac
1.98      lukem     416:
                    417:        # Ensure that MACHINE_ARCH supports MACHINE
                    418:        #
                    419:        archok=false
                    420:        for a in ${arches}; do
                    421:                if [ "${a}" = "${MACHINE_ARCH}" ]; then
                    422:                        archok=true
                    423:                        break
                    424:                fi
                    425:        done
                    426:        ${archok} ||
                    427:            bomb "MACHINE_ARCH '${MACHINE_ARCH}' does not support MACHINE '${MACHINE}'"
1.47      tv        428: }
                    429:
1.168     apb       430: nobomb_getmakevar()
1.79      lukem     431: {
1.168     apb       432:        [ -x "${make}" ] || return 1
                    433:        "${make}" -m ${TOP}/share/mk -s -B -f- _x_ <<EOF || return 1
1.15      tv        434: _x_:
                    435:        echo \${$1}
                    436: .include <bsd.prog.mk>
1.70      lukem     437: .include <bsd.kernobj.mk>
1.15      tv        438: EOF
                    439: }
                    440:
1.168     apb       441: raw_getmakevar()
                    442: {
                    443:        [ -x "${make}" ] || bomb "raw_getmakevar $1: ${make} is not executable"
                    444:        nobomb_getmakevar "$1" || bomb "raw_getmakevar $1: ${make} failed"
                    445: }
                    446:
1.98      lukem     447: getmakevar()
1.82      lukem     448: {
1.98      lukem     449:        # raw_getmakevar() doesn't work properly if $make hasn't yet been
                    450:        # built, which can happen when running with the "-n" option.
                    451:        # getmakevar() deals with this by emitting a literal '$'
1.84      lukem     452:        # followed by the variable name, instead of trying to find the
                    453:        # variable's value.
                    454:        #
1.98      lukem     455:        if [ -x "${make}" ]; then
                    456:                raw_getmakevar "$1"
1.82      lukem     457:        else
                    458:                echo "\$$1"
                    459:        fi
                    460: }
                    461:
1.109     lukem     462: setmakeenv()
                    463: {
                    464:        eval "$1='$2'; export $1"
                    465:        makeenv="${makeenv} $1"
                    466: }
                    467:
1.111     lukem     468: unsetmakeenv()
                    469: {
                    470:        eval "unset $1"
                    471:        makeenv="${makeenv} $1"
                    472: }
                    473:
1.131     junyoung  474: # Convert possibly-relative path to absolute path by prepending
                    475: # ${TOP} if necessary.  Also delete trailing "/", if any.
1.79      lukem     476: resolvepath()
                    477: {
1.98      lukem     478:        case "${OPTARG}" in
1.131     junyoung  479:        /)
                    480:                ;;
1.84      lukem     481:        /*)
1.131     junyoung  482:                OPTARG="${OPTARG%/}"
1.84      lukem     483:                ;;
                    484:        *)
1.131     junyoung  485:                OPTARG="${TOP}/${OPTARG%/}"
1.84      lukem     486:                ;;
1.10      tv        487:        esac
                    488: }
                    489:
1.79      lukem     490: usage()
                    491: {
1.84      lukem     492:        if [ -n "$*" ]; then
                    493:                echo ""
                    494:                echo "${progname}: $*"
                    495:        fi
1.70      lukem     496:        cat <<_usage_
1.83      lukem     497:
1.171.4.2  matt      498: Usage: ${progname} [-EnorUux] [-a arch] [-B buildid] [-C cdextras] [-D dest]
1.171.4.1  matt      499:                [-j njob] [-M obj] [-m mach] [-N noisy] [-O obj] [-R release]
                    500:                [-T tools] [-V var=[value]] [-w wrapper] [-X x11src] [-Z var]
1.127     lukem     501:                operation [...]
1.84      lukem     502:
1.86      lukem     503:  Build operations (all imply "obj" and "tools"):
1.125     lukem     504:     build               Run "make build".
                    505:     distribution        Run "make distribution" (includes DESTDIR/etc/ files).
                    506:     release             Run "make release" (includes kernels & distrib media).
1.84      lukem     507:
                    508:  Other operations:
1.125     lukem     509:     help                Show this message and exit.
1.98      lukem     510:     makewrapper         Create ${toolprefix}make-\${MACHINE} wrapper and ${toolprefix}make.
1.125     lukem     511:                         Always performed.
                    512:     obj                 Run "make obj".  [Default unless -o is used]
                    513:     tools               Build and install tools.
                    514:     install=idir        Run "make installworld" to \`idir' to install all sets
                    515:                        except \`etc'.  Useful after "distribution" or "release"
1.105     lukem     516:     kernel=conf         Build kernel with config file \`conf'
1.125     lukem     517:     releasekernel=conf  Install kernel built by kernel=conf to RELEASEDIR.
1.171.4.3! matt      518:     sets                Create binary sets in
        !           519:                        RELEASEDIR/RELEASEMACHINEDIR/binary/sets.
1.125     lukem     520:                        DESTDIR should be populated beforehand.
                    521:     sourcesets          Create source sets in RELEASEDIR/source/sets.
1.171.4.3! matt      522:     syspkgs             Create syspkgs in
        !           523:                        RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
1.171.4.1  matt      524:     iso-image           Create CD-ROM image in RELEASEDIR/iso.
                    525:     iso-image-source    Create CD-ROM image with source in RELEASEDIR/iso.
1.125     lukem     526:     params              Display various make(1) parameters.
1.84      lukem     527:
                    528:  Options:
1.125     lukem     529:     -a arch     Set MACHINE_ARCH to arch.  [Default: deduced from MACHINE]
                    530:     -B buildId  Set BUILDID to buildId.
1.171.4.2  matt      531:     -C cdextras Set CDEXTRA to cdextras
1.119     lukem     532:     -D dest     Set DESTDIR to dest.  [Default: destdir.MACHINE]
1.98      lukem     533:     -E          Set "expert" mode; disables various safety checks.
1.127     lukem     534:                 Should not be used without expert knowledge of the build system.
1.129     wiz       535:     -h          Print this help message.
1.125     lukem     536:     -j njob     Run up to njob jobs in parallel; see make(1) -j.
                    537:     -M obj      Set obj root directory to obj; sets MAKEOBJDIRPREFIX.
1.111     lukem     538:                 Unsets MAKEOBJDIR.
1.125     lukem     539:     -m mach     Set MACHINE to mach; not required if NetBSD native.
1.126     lukem     540:     -N noisy   Set the noisyness (MAKEVERBOSE) level of the build:
1.119     lukem     541:                    0   Quiet
                    542:                    1   Operations are described, commands are suppressed
                    543:                    2   Full output
                    544:                [Default: 2]
1.125     lukem     545:     -n          Show commands that would be executed, but do not execute them.
                    546:     -O obj      Set obj root directory to obj; sets a MAKEOBJDIR pattern.
1.111     lukem     547:                 Unsets MAKEOBJDIRPREFIX.
1.125     lukem     548:     -o          Set MKOBJDIRS=no; do not create objdirs at start of build.
1.119     lukem     549:     -R release  Set RELEASEDIR to release.  [Default: releasedir]
1.125     lukem     550:     -r          Remove contents of TOOLDIR and DESTDIR before building.
1.98      lukem     551:     -T tools    Set TOOLDIR to tools.  If unset, and TOOLDIR is not set in
1.125     lukem     552:                 the environment, ${toolprefix}make will be (re)built unconditionally.
                    553:     -U          Set MKUNPRIVED=yes; build without requiring root privileges,
                    554:                install from an UNPRIVED build with proper file permissions.
                    555:     -u          Set MKUPDATE=yes; do not run "make clean" first.
1.98      lukem     556:                Without this, everything is rebuilt, including the tools.
1.125     lukem     557:     -V v=[val]  Set variable \`v' to \`val'.
                    558:     -w wrapper  Create ${toolprefix}make script as wrapper.
1.119     lukem     559:                 [Default: \${TOOLDIR}/bin/${toolprefix}make-\${MACHINE}]
1.127     lukem     560:     -X x11src   Set X11SRCDIR to x11src.  [Default: /usr/xsrc]
                    561:     -x          Set MKX11=yes; build X11R6 from X11SRCDIR
1.125     lukem     562:     -Z v        Unset ("zap") variable \`v'.
1.83      lukem     563:
1.70      lukem     564: _usage_
1.1       tv        565:        exit 1
                    566: }
                    567:
1.84      lukem     568: parseoptions()
                    569: {
1.171.4.1  matt      570:        opts='a:B:bC:D:dEhi:j:k:M:m:N:nO:oR:rT:tUuV:w:xX:Z:'
1.84      lukem     571:        opt_a=no
                    572:
                    573:        if type getopts >/dev/null 2>&1; then
                    574:                # Use POSIX getopts.
1.98      lukem     575:                #
                    576:                getoptcmd='getopts ${opts} opt && opt=-${opt}'
1.84      lukem     577:                optargcmd=':'
1.98      lukem     578:                optremcmd='shift $((${OPTIND} -1))'
1.84      lukem     579:        else
                    580:                type getopt >/dev/null 2>&1 ||
                    581:                    bomb "/bin/sh shell is too old; try ksh or bash"
                    582:
                    583:                # Use old-style getopt(1) (doesn't handle whitespace in args).
1.98      lukem     584:                #
                    585:                args="$(getopt ${opts} $*)"
1.84      lukem     586:                [ $? = 0 ] || usage
1.98      lukem     587:                set -- ${args}
1.84      lukem     588:
                    589:                getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
                    590:                optargcmd='OPTARG="$1"; shift'
                    591:                optremcmd=':'
                    592:        fi
                    593:
                    594:        # Parse command line options.
                    595:        #
1.98      lukem     596:        while eval ${getoptcmd}; do
                    597:                case ${opt} in
1.84      lukem     598:
                    599:                -a)
1.98      lukem     600:                        eval ${optargcmd}
                    601:                        MACHINE_ARCH=${OPTARG}
1.84      lukem     602:                        opt_a=yes
                    603:                        ;;
                    604:
                    605:                -B)
1.98      lukem     606:                        eval ${optargcmd}
                    607:                        BUILDID=${OPTARG}
1.84      lukem     608:                        ;;
                    609:
                    610:                -b)
1.86      lukem     611:                        usage "'-b' has been replaced by 'makewrapper'"
1.84      lukem     612:                        ;;
                    613:
1.171.4.1  matt      614:                -C)
                    615:                        eval ${optargcmd}; resolvepath
                    616:                        iso_dir=${OPTARG}
                    617:                        ;;
                    618:
1.84      lukem     619:                -D)
1.98      lukem     620:                        eval ${optargcmd}; resolvepath
1.109     lukem     621:                        setmakeenv DESTDIR "${OPTARG}"
1.84      lukem     622:                        ;;
                    623:
                    624:                -d)
                    625:                        usage "'-d' has been replaced by 'distribution'"
                    626:                        ;;
                    627:
                    628:                -E)
                    629:                        do_expertmode=true
                    630:                        ;;
                    631:
                    632:                -i)
                    633:                        usage "'-i idir' has been replaced by 'install=idir'"
                    634:                        ;;
                    635:
                    636:                -j)
1.98      lukem     637:                        eval ${optargcmd}
                    638:                        parallel="-j ${OPTARG}"
1.84      lukem     639:                        ;;
                    640:
                    641:                -k)
                    642:                        usage "'-k conf' has been replaced by 'kernel=conf'"
                    643:                        ;;
                    644:
                    645:                -M)
1.98      lukem     646:                        eval ${optargcmd}; resolvepath
                    647:                        makeobjdir="${OPTARG}"
1.111     lukem     648:                        unsetmakeenv MAKEOBJDIR
1.109     lukem     649:                        setmakeenv MAKEOBJDIRPREFIX "${OPTARG}"
1.84      lukem     650:                        ;;
                    651:
                    652:                        # -m overrides MACHINE_ARCH unless "-a" is specified
                    653:                -m)
1.98      lukem     654:                        eval ${optargcmd}
                    655:                        MACHINE="${OPTARG}"
                    656:                        [ "${opt_a}" != "yes" ] && getarch
1.84      lukem     657:                        ;;
                    658:
1.119     lukem     659:                -N)
                    660:                        eval ${optargcmd}
                    661:                        case "${OPTARG}" in
1.121     lukem     662:                        0|1|2)
                    663:                                setmakeenv MAKEVERBOSE "${OPTARG}"
1.119     lukem     664:                                ;;
                    665:                        *)
                    666:                                usage "'${OPTARG}' is not a valid value for -N"
                    667:                                ;;
                    668:                        esac
                    669:                        ;;
                    670:
1.84      lukem     671:                -n)
                    672:                        runcmd=echo
                    673:                        ;;
                    674:
                    675:                -O)
1.98      lukem     676:                        eval ${optargcmd}; resolvepath
                    677:                        makeobjdir="${OPTARG}"
1.111     lukem     678:                        unsetmakeenv MAKEOBJDIRPREFIX
1.109     lukem     679:                        setmakeenv MAKEOBJDIR "\${.CURDIR:C,^$TOP,$OPTARG,}"
1.84      lukem     680:                        ;;
                    681:
                    682:                -o)
                    683:                        MKOBJDIRS=no
                    684:                        ;;
                    685:
                    686:                -R)
1.98      lukem     687:                        eval ${optargcmd}; resolvepath
1.109     lukem     688:                        setmakeenv RELEASEDIR "${OPTARG}"
1.84      lukem     689:                        ;;
                    690:
                    691:                -r)
                    692:                        do_removedirs=true
                    693:                        do_rebuildmake=true
                    694:                        ;;
                    695:
                    696:                -T)
1.98      lukem     697:                        eval ${optargcmd}; resolvepath
                    698:                        TOOLDIR="${OPTARG}"
1.84      lukem     699:                        export TOOLDIR
                    700:                        ;;
                    701:
                    702:                -t)
                    703:                        usage "'-t' has been replaced by 'tools'"
                    704:                        ;;
1.16      thorpej   705:
1.84      lukem     706:                -U)
1.109     lukem     707:                        setmakeenv MKUNPRIVED yes
1.84      lukem     708:                        ;;
1.44      lukem     709:
1.84      lukem     710:                -u)
1.109     lukem     711:                        setmakeenv MKUPDATE yes
1.84      lukem     712:                        ;;
1.15      tv        713:
1.84      lukem     714:                -V)
1.98      lukem     715:                        eval ${optargcmd}
1.84      lukem     716:                        case "${OPTARG}" in
1.80      lukem     717:                    # XXX: consider restricting which variables can be changed?
1.84      lukem     718:                        [a-zA-Z_][a-zA-Z_0-9]*=*)
1.109     lukem     719:                                setmakeenv "${OPTARG%%=*}" "${OPTARG#*=}"
1.84      lukem     720:                                ;;
                    721:                        *)
                    722:                                usage "-V argument must be of the form 'var=[value]'"
                    723:                                ;;
                    724:                        esac
                    725:                        ;;
                    726:
                    727:                -w)
1.98      lukem     728:                        eval ${optargcmd}; resolvepath
                    729:                        makewrapper="${OPTARG}"
1.84      lukem     730:                        ;;
                    731:
1.127     lukem     732:                -X)
                    733:                        eval ${optargcmd}; resolvepath
                    734:                        setmakeenv X11SRCDIR "${OPTARG}"
                    735:                        ;;
                    736:
                    737:                -x)
                    738:                        setmakeenv MKX11 yes
                    739:                        ;;
                    740:
1.111     lukem     741:                -Z)
                    742:                        eval ${optargcmd}
                    743:                    # XXX: consider restricting which variables can be unset?
                    744:                        unsetmakeenv "${OPTARG}"
                    745:                        ;;
                    746:
1.84      lukem     747:                --)
                    748:                        break
                    749:                        ;;
                    750:
                    751:                -'?'|-h)
                    752:                        usage
                    753:                        ;;
                    754:
                    755:                esac
                    756:        done
                    757:
                    758:        # Validate operations.
                    759:        #
1.98      lukem     760:        eval ${optremcmd}
1.84      lukem     761:        while [ $# -gt 0 ]; do
                    762:                op=$1; shift
1.98      lukem     763:                operations="${operations} ${op}"
1.84      lukem     764:
1.98      lukem     765:                case "${op}" in
1.84      lukem     766:
1.87      lukem     767:                help)
                    768:                        usage
                    769:                        ;;
                    770:
1.142     apb       771:                makewrapper|obj|tools|build|distribution|release|sets|sourcesets|syspkgs|params)
1.80      lukem     772:                        ;;
1.84      lukem     773:
1.146     apb       774:                iso-image)
                    775:                        op=iso_image    # used as part of a variable name
                    776:                        ;;
                    777:
1.171.4.1  matt      778:                iso-image-source)
                    779:                        op=iso_image_source   # used as part of a variable name
                    780:                        ;;
                    781:
1.105     lukem     782:                kernel=*|releasekernel=*)
1.84      lukem     783:                        arg=${op#*=}
                    784:                        op=${op%%=*}
1.98      lukem     785:                        [ -n "${arg}" ] ||
1.105     lukem     786:                            bomb "Must supply a kernel name with \`${op}=...'"
1.84      lukem     787:                        ;;
                    788:
                    789:                install=*)
                    790:                        arg=${op#*=}
                    791:                        op=${op%%=*}
1.98      lukem     792:                        [ -n "${arg}" ] ||
                    793:                            bomb "Must supply a directory with \`install=...'"
1.84      lukem     794:                        ;;
                    795:
1.80      lukem     796:                *)
1.84      lukem     797:                        usage "Unknown operation \`${op}'"
                    798:                        ;;
                    799:
1.80      lukem     800:                esac
1.98      lukem     801:                eval do_${op}=true
1.84      lukem     802:        done
1.98      lukem     803:        [ -n "${operations}" ] || usage "Missing operation to perform."
1.84      lukem     804:
                    805:        # Set up MACHINE*.  On a NetBSD host, these are allowed to be unset.
                    806:        #
1.98      lukem     807:        if [ -z "${MACHINE}" ]; then
                    808:                [ "${uname_s}" = "NetBSD" ] ||
                    809:                    bomb "MACHINE must be set, or -m must be used, for cross builds."
1.84      lukem     810:                MACHINE=${uname_m}
                    811:        fi
1.98      lukem     812:        [ -n "${MACHINE_ARCH}" ] || getarch
1.84      lukem     813:        validatearch
                    814:
                    815:        # Set up default make(1) environment.
                    816:        #
1.98      lukem     817:        makeenv="${makeenv} TOOLDIR MACHINE MACHINE_ARCH MAKEFLAGS"
                    818:        [ -z "${BUILDID}" ] || makeenv="${makeenv} BUILDID"
1.115     jmmv      819:        MAKEFLAGS="-de -m ${TOP}/share/mk ${MAKEFLAGS} MKOBJDIRS=${MKOBJDIRS-yes}"
1.84      lukem     820:        export MAKEFLAGS MACHINE MACHINE_ARCH
                    821: }
                    822:
1.163     apb       823: sanitycheck()
                    824: {
                    825:        # If the PATH contains any non-absolute components (including,
1.170     apb       826:        # but not limited to, "." or ""), then complain.  As an exception,
                    827:        # allow "" or "." as the last component of the PATH.  This is fatal
1.163     apb       828:        # if expert mode is not in effect.
                    829:        #
1.170     apb       830:        local path="${PATH}"
                    831:        path="${path%:}"        # delete trailing ":"
                    832:        path="${path%:.}"       # delete trailing ":."
                    833:        case ":${path}:/" in
                    834:        *:[!/]*)
1.163     apb       835:                if ${do_expertmode}; then
                    836:                        warning "PATH contains non-absolute components"
                    837:                else
1.164     apb       838:                        bomb "PATH environment variable must not" \
                    839:                             "contain non-absolute components"
1.163     apb       840:                fi
                    841:                ;;
                    842:        esac
                    843: }
                    844:
1.168     apb       845: # Try to set a value for TOOLDIR.  This is difficult because of a cyclic
                    846: # dependency: TOOLDIR may be affected by settings in /etc/mk.conf, so
                    847: # we would like to use getmakevar to get the value of TOOLDIR, but we
                    848: # can't use getmakevar before we have an up to date version of nbmake;
                    849: # we might already have an up to date version of nbmake in TOOLDIR, but
                    850: # we don't yet know where TOOLDIR is.
                    851: #
                    852: # In principle, we could break the cycle by building a copy of nbmake
                    853: # in a temporary directory.  However, people who use the default value
                    854: # of TOOLDIR do not like to have nbmake rebuilt every time they run
                    855: # build.sh.
                    856: #
                    857: # We try to please everybody as follows:
                    858: #
                    859: # * If TOOLDIR was set in the environment or on the command line, use
                    860: #   that value.
                    861: # * Otherwise try to guess what TOOLDIR would be if not overridden by
                    862: #   /etc/mk.conf, and check whether the resulting directory contains
                    863: #   a copy of ${toolprefix}make (this should work for everybody who
                    864: #   doesn't override TOOLDIR via /etc/mk.conf);
                    865: # * Failing that, search for ${toolprefix}make, nbmake, bmake, or make,
                    866: #   in the PATH (this might accidentally find a non-NetBSD version of
                    867: #   make, which will lead to failure in the next step);
                    868: # * If a copy of make was found above, try to use it with
                    869: #   nobomb_getmakevar to find the correct value for TOOLDIR;
                    870: # * If all else fails, leave TOOLDIR unset.  Our caller is expected to
                    871: #   be able to cope with this.
                    872: #
                    873: try_set_TOOLDIR()
                    874: {
                    875:        [ -n "${TOOLDIR}" ] && return
                    876:
                    877:        # Set guess_TOOLDIR, in the same way that <bsd.own.mk> would set
                    878:        # TOOLDIR if /etc/mk.conf sisn't interfere.
                    879:        local topobjdir="${TOP}"
                    880:        [ -n "${makeobjdir}" ] && topobjdir="${topobjdir}/${makeobjdir}"
                    881:        local host_ostype="${uname_s}-$(
                    882:                echo "${uname_r}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
                    883:                )$(
                    884:                echo "${uname_p}" | sed -e 's/([^)]*)//g' -e 's/ /_/g'
                    885:                )"
                    886:        local guess_TOOLDIR="${topobjdir}/tooldir.${host_ostype}"
                    887:
                    888:        # Look for a suitable ${toolprefix}make, nbmake, bmake, or make.
                    889:        guess_make="${guess_TOOLDIR}/bin/${toolprefix}make"
                    890:        [ -x "${guess_make}" ] || guess_make=""
                    891:        : ${guess_make:=$(find_in_PATH ${toolprefix}make '')}
                    892:        : ${guess_make:=$(find_in_PATH nbmake '')}
                    893:        : ${guess_make:=$(find_in_PATH bmake '')}
                    894:        : ${guess_make:=$(find_in_PATH make '')}
                    895:
                    896:        # Use ${guess_make} with nobomb_getmakevar
                    897:        if [ -x "${guess_make}" ]; then
                    898:                TOOLDIR=$(make="${guess_make}" nobomb_getmakevar TOOLDIR)
                    899:                [ -n "${TOOLDIR}" ] || unset TOOLDIR
                    900:        fi
                    901: }
                    902:
1.84      lukem     903: rebuildmake()
                    904: {
                    905:        # Test make source file timestamps against installed ${toolprefix}make
1.168     apb       906:        # binary, if TOOLDIR is pre-set or if try_set_TOOLDIR can set it.
1.84      lukem     907:        #
1.168     apb       908:        try_set_TOOLDIR
1.84      lukem     909:        make="${TOOLDIR-nonexistent}/bin/${toolprefix}make"
1.98      lukem     910:        if [ -x "${make}" ]; then
1.84      lukem     911:                for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1.98      lukem     912:                        if [ "${f}" -nt "${make}" ]; then
1.122     lukem     913:                                statusmsg "${make} outdated (older than ${f}), needs building."
1.84      lukem     914:                                do_rebuildmake=true
                    915:                                break
                    916:                        fi
                    917:                done
                    918:        else
1.122     lukem     919:                statusmsg "No ${make}, needs building."
1.84      lukem     920:                do_rebuildmake=true
                    921:        fi
                    922:
                    923:        # Build bootstrap ${toolprefix}make if needed.
1.98      lukem     924:        if ${do_rebuildmake}; then
                    925:                statusmsg "Bootstrapping ${toolprefix}make"
                    926:                ${runcmd} cd "${tmpdir}"
                    927:                ${runcmd} env CC="${HOST_CC-cc}" CPPFLAGS="${HOST_CPPFLAGS}" \
1.84      lukem     928:                        CFLAGS="${HOST_CFLAGS--O}" LDFLAGS="${HOST_LDFLAGS}" \
1.153     apb       929:                        ${HOST_SH} "${TOP}/tools/make/configure" ||
1.98      lukem     930:                    bomb "Configure of ${toolprefix}make failed"
1.153     apb       931:                ${runcmd} ${HOST_SH} buildmake.sh ||
1.98      lukem     932:                    bomb "Build of ${toolprefix}make failed"
                    933:                make="${tmpdir}/${toolprefix}make"
                    934:                ${runcmd} cd "${TOP}"
                    935:                ${runcmd} rm -f usr.bin/make/*.o usr.bin/make/lst.lib/*.o
1.84      lukem     936:        fi
                    937: }
                    938:
                    939: validatemakeparams()
                    940: {
1.98      lukem     941:        if [ "${runcmd}" = "echo" ]; then
1.84      lukem     942:                TOOLCHAIN_MISSING=no
                    943:                EXTERNAL_TOOLCHAIN=""
                    944:        else
1.98      lukem     945:                TOOLCHAIN_MISSING=$(raw_getmakevar TOOLCHAIN_MISSING)
                    946:                EXTERNAL_TOOLCHAIN=$(raw_getmakevar EXTERNAL_TOOLCHAIN)
1.84      lukem     947:        fi
                    948:        if [ "${TOOLCHAIN_MISSING}" = "yes" ] && \
1.86      lukem     949:           [ -z "${EXTERNAL_TOOLCHAIN}" ]; then
1.98      lukem     950:                ${runcmd} echo "ERROR: build.sh (in-tree cross-toolchain) is not yet available for"
                    951:                ${runcmd} echo "        MACHINE:      ${MACHINE}"
                    952:                ${runcmd} echo "        MACHINE_ARCH: ${MACHINE_ARCH}"
                    953:                ${runcmd} echo ""
                    954:                ${runcmd} echo "All builds for this platform should be done via a traditional make"
                    955:                ${runcmd} echo "If you wish to use an external cross-toolchain, set"
                    956:                ${runcmd} echo "        EXTERNAL_TOOLCHAIN=<path to toolchain root>"
                    957:                ${runcmd} echo "in either the environment or mk.conf and rerun"
                    958:                ${runcmd} echo "        ${progname} $*"
1.84      lukem     959:                exit 1
                    960:        fi
                    961:
1.120     lukem     962:        # Normalise MKOBJDIRS, MKUNPRIVED, and MKUPDATE
                    963:        # These may be set as build.sh options or in "mk.conf".
                    964:        # Don't export them as they're only used for tests in build.sh.
                    965:        #
                    966:        MKOBJDIRS=$(getmakevar MKOBJDIRS)
                    967:        MKUNPRIVED=$(getmakevar MKUNPRIVED)
                    968:        MKUPDATE=$(getmakevar MKUPDATE)
                    969:
1.106     lukem     970:        if [ "${MKOBJDIRS}" != "no" ]; then
                    971:                # If setting -M or -O to the root of an obj dir, make sure
                    972:                # the base directory is made before continuing as <bsd.own.mk>
                    973:                # will need this to pick up _SRC_TOP_OBJ_
                    974:                #
                    975:                if [ ! -z "${makeobjdir}" ]; then
                    976:                        ${runcmd} mkdir -p "${makeobjdir}"
                    977:                fi
                    978:
                    979:                # make obj in tools to ensure that the objdir for the top-level
                    980:                # of the source tree and for "tools" is available, in case the
                    981:                # default TOOLDIR setting from <bsd.own.mk> is used, or the
                    982:                # build.sh default DESTDIR and RELEASEDIR is to be used.
                    983:                #
1.98      lukem     984:                ${runcmd} cd tools
                    985:                ${runcmd} "${make}" -m ${TOP}/share/mk obj NOSUBDIR= ||
                    986:                    bomb "Failed to make obj in tools"
                    987:                ${runcmd} cd "${TOP}"
1.84      lukem     988:        fi
1.80      lukem     989:
1.171.4.3! matt      990:        # Find TOOLDIR, DESTDIR, RELEASEDIR, and RELEASEMACHINEDIR.
1.84      lukem     991:        #
1.98      lukem     992:        TOOLDIR=$(getmakevar TOOLDIR)
1.105     lukem     993:        statusmsg "TOOLDIR path:     ${TOOLDIR}"
1.98      lukem     994:        DESTDIR=$(getmakevar DESTDIR)
                    995:        RELEASEDIR=$(getmakevar RELEASEDIR)
1.171.4.3! matt      996:        RELEASEMACHINEDIR=$(getmakevar RELEASEMACHINEDIR)
1.98      lukem     997:        if ! $do_expertmode; then
1.105     lukem     998:                _SRC_TOP_OBJ_=$(getmakevar _SRC_TOP_OBJ_)
                    999:                : ${DESTDIR:=${_SRC_TOP_OBJ_}/destdir.${MACHINE}}
                   1000:                : ${RELEASEDIR:=${_SRC_TOP_OBJ_}/releasedir}
1.99      lukem    1001:                makeenv="${makeenv} DESTDIR RELEASEDIR"
1.98      lukem    1002:        fi
1.99      lukem    1003:        export TOOLDIR DESTDIR RELEASEDIR
1.105     lukem    1004:        statusmsg "DESTDIR path:     ${DESTDIR}"
                   1005:        statusmsg "RELEASEDIR path:  ${RELEASEDIR}"
1.84      lukem    1006:
                   1007:        # Check validity of TOOLDIR and DESTDIR.
                   1008:        #
1.98      lukem    1009:        if [ -z "${TOOLDIR}" ] || [ "${TOOLDIR}" = "/" ]; then
                   1010:                bomb "TOOLDIR '${TOOLDIR}' invalid"
1.84      lukem    1011:        fi
1.98      lukem    1012:        removedirs="${TOOLDIR}"
1.15      tv       1013:
1.98      lukem    1014:        if [ -z "${DESTDIR}" ] || [ "${DESTDIR}" = "/" ]; then
                   1015:                if ${do_build} || ${do_distribution} || ${do_release}; then
                   1016:                        if ! ${do_build} || \
1.84      lukem    1017:                           [ "${uname_s}" != "NetBSD" ] || \
1.98      lukem    1018:                           [ "${uname_m}" != "${MACHINE}" ]; then
1.84      lukem    1019:                                bomb "DESTDIR must != / for cross builds, or ${progname} 'distribution' or 'release'."
                   1020:                        fi
1.98      lukem    1021:                        if ! ${do_expertmode}; then
1.84      lukem    1022:                                bomb "DESTDIR must != / for non -E (expert) builds"
                   1023:                        fi
1.98      lukem    1024:                        statusmsg "WARNING: Building to /, in expert mode."
                   1025:                        statusmsg "         This may cause your system to break!  Reasons include:"
                   1026:                        statusmsg "            - your kernel is not up to date"
                   1027:                        statusmsg "            - the libraries or toolchain have changed"
                   1028:                        statusmsg "         YOU HAVE BEEN WARNED!"
1.1       tv       1029:                fi
1.84      lukem    1030:        else
1.98      lukem    1031:                removedirs="${removedirs} ${DESTDIR}"
1.84      lukem    1032:        fi
1.98      lukem    1033:        if ${do_build} || ${do_distribution} || ${do_release}; then
                   1034:                if ! ${do_expertmode} && \
1.153     apb      1035:                    [ "$(id -u 2>/dev/null)" -ne 0 ] && \
1.124     lukem    1036:                    [ "${MKUNPRIVED}" = "no" ] ; then
1.86      lukem    1037:                        bomb "-U or -E must be set for build as an unprivileged user."
                   1038:                fi
1.171.4.3! matt     1039:        fi
1.105     lukem    1040:        if ${do_releasekernel} && [ -z "${RELEASEDIR}" ]; then
                   1041:                bomb "Must set RELEASEDIR with \`releasekernel=...'"
                   1042:        fi
1.171.4.3! matt     1043:
        !          1044:        # Install as non-root is a bad idea.
        !          1045:        #
        !          1046:        if ${do_install} && [ "$(id -u 2>/dev/null)" -ne 0 ] ; then
        !          1047:                if ${do_expertmode}; then
        !          1048:                        warning "Will install as an unprivileged user."
        !          1049:                else
        !          1050:                        bomb "-E must be set for install as an unprivileged user."
        !          1051:                fi
        !          1052:        fi
        !          1053:
        !          1054:        # If a previous build.sh run used -U (and therefore created a
        !          1055:        # METALOG file), then most subsequent build.sh runs must also
        !          1056:        # use -U.  If DESTDIR is about to be removed, then don't perform
        !          1057:        # this check.
        !          1058:        #
        !          1059:        case "${do_removedirs} ${removedirs} " in
        !          1060:        true*" ${DESTDIR} "*)
        !          1061:                # DESTDIR is about to be removed
        !          1062:                ;;
        !          1063:        *)
        !          1064:                if ( ${do_build} || ${do_distribution} || ${do_release} || \
        !          1065:                    ${do_install} ) && \
        !          1066:                    [ -e "${DESTDIR}/METALOG" ] && \
        !          1067:                    [ "${MKUNPRIVED}" = "no" ] ; then
        !          1068:                        if $do_expertmode; then
        !          1069:                                warning "A previous build.sh run specified -U."
        !          1070:                        else
        !          1071:                                bomb "A previous build.sh run specified -U; you must specify it again now."
        !          1072:                        fi
        !          1073:                fi
        !          1074:                ;;
        !          1075:        esac
1.84      lukem    1076: }
1.30      jmc      1077:
1.15      tv       1078:
1.84      lukem    1079: createmakewrapper()
                   1080: {
                   1081:        # Remove the target directories.
                   1082:        #
1.98      lukem    1083:        if ${do_removedirs}; then
                   1084:                for f in ${removedirs}; do
                   1085:                        statusmsg "Removing ${f}"
                   1086:                        ${runcmd} rm -r -f "${f}"
1.84      lukem    1087:                done
                   1088:        fi
1.15      tv       1089:
1.84      lukem    1090:        # Recreate $TOOLDIR.
                   1091:        #
1.98      lukem    1092:        ${runcmd} mkdir -p "${TOOLDIR}/bin" ||
                   1093:            bomb "mkdir of '${TOOLDIR}/bin' failed"
1.84      lukem    1094:
                   1095:        # Install ${toolprefix}make if it was built.
                   1096:        #
1.98      lukem    1097:        if ${do_rebuildmake}; then
                   1098:                ${runcmd} rm -f "${TOOLDIR}/bin/${toolprefix}make"
                   1099:                ${runcmd} cp "${make}" "${TOOLDIR}/bin/${toolprefix}make" ||
                   1100:                    bomb "Failed to install \$TOOLDIR/bin/${toolprefix}make"
                   1101:                make="${TOOLDIR}/bin/${toolprefix}make"
                   1102:                statusmsg "Created ${make}"
1.84      lukem    1103:        fi
1.15      tv       1104:
1.84      lukem    1105:        # Build a ${toolprefix}make wrapper script, usable by hand as
                   1106:        # well as by build.sh.
                   1107:        #
1.98      lukem    1108:        if [ -z "${makewrapper}" ]; then
1.102     lukem    1109:                makewrapper="${TOOLDIR}/bin/${toolprefix}make-${makewrappermachine:-${MACHINE}}"
1.98      lukem    1110:                [ -z "${BUILDID}" ] || makewrapper="${makewrapper}-${BUILDID}"
1.52      thorpej  1111:        fi
1.4       tv       1112:
1.98      lukem    1113:        ${runcmd} rm -f "${makewrapper}"
                   1114:        if [ "${runcmd}" = "echo" ]; then
                   1115:                echo 'cat <<EOF >'${makewrapper}
1.84      lukem    1116:                makewrapout=
                   1117:        else
1.98      lukem    1118:                makewrapout=">>\${makewrapper}"
1.84      lukem    1119:        fi
1.18      tv       1120:
1.139     isaki    1121:        case "${KSH_VERSION:-${SH_VERSION}}" in
1.149     jnemeth  1122:        *PD\ KSH*|*MIRBSD\ KSH*)
1.135     isaki    1123:                set +o braceexpand
                   1124:                ;;
                   1125:        esac
                   1126:
1.98      lukem    1127:        eval cat <<EOF ${makewrapout}
1.153     apb      1128: #! ${HOST_SH}
1.4       tv       1129: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.171.4.3! matt     1130: # Generated from:  \build.sh,v 1.171.4.2 2008/01/09 01:19:18 matt Exp
1.130     jmc      1131: # with these arguments: ${_args}
1.4       tv       1132: #
1.171.4.2  matt     1133:
1.18      tv       1134: EOF
1.171.4.2  matt     1135:        {
                   1136:                for f in ${makeenv}; do
                   1137:                        if eval "[ -z \"\${$f}\" -a \"\${${f}-X}\" = \"X\" ]"; then
                   1138:                                eval echo "unset ${f}"
                   1139:                        else
                   1140:                                eval echo "${f}=\'\$$(echo ${f})\'\;\ export\ ${f}"
                   1141:                        fi
                   1142:                done
1.18      tv       1143:
1.171.4.2  matt     1144:                eval cat <<EOF
1.154     dyoung   1145: MAKEWRAPPERMACHINE=${makewrappermachine:-${MACHINE}}; export MAKEWRAPPERMACHINE
                   1146: USETOOLS=yes; export USETOOLS
1.171.4.2  matt     1147: EOF
                   1148:        } | eval sort -u "${makewrapout}"
                   1149:        eval cat <<EOF "${makewrapout}"
1.18      tv       1150:
1.98      lukem    1151: exec "\${TOOLDIR}/bin/${toolprefix}make" \${1+"\$@"}
1.4       tv       1152: EOF
1.98      lukem    1153:        [ "${runcmd}" = "echo" ] && echo EOF
                   1154:        ${runcmd} chmod +x "${makewrapper}"
1.105     lukem    1155:        statusmsg "makewrapper:      ${makewrapper}"
1.98      lukem    1156:        statusmsg "Updated ${makewrapper}"
1.84      lukem    1157: }
                   1158:
                   1159: buildtools()
                   1160: {
1.98      lukem    1161:        if [ "${MKOBJDIRS}" != "no" ]; then
                   1162:                ${runcmd} "${makewrapper}" ${parallel} obj-tools ||
                   1163:                    bomb "Failed to make obj-tools"
1.84      lukem    1164:        fi
1.98      lukem    1165:        ${runcmd} cd tools
1.124     lukem    1166:        if [ "${MKUPDATE}" = "no" ]; then
1.144     dsl      1167:                ${runcmd} "${makewrapper}" ${parallel} cleandir ||
                   1168:                    bomb "Failed to make cleandir tools"
1.84      lukem    1169:        fi
1.144     dsl      1170:        ${runcmd} "${makewrapper}" ${parallel} dependall ||
                   1171:            bomb "Failed to make dependall tools"
                   1172:        ${runcmd} "${makewrapper}" ${parallel} install ||
                   1173:            bomb "Failed to make install tools"
1.98      lukem    1174:        statusmsg "Tools built to ${TOOLDIR}"
1.110     lukem    1175:        ${runcmd} cd "${TOP}"
1.84      lukem    1176: }
1.4       tv       1177:
1.105     lukem    1178: getkernelconf()
1.84      lukem    1179: {
1.105     lukem    1180:        kernelconf="$1"
1.114     lukem    1181:        if [ "${MKOBJDIRS}" != "no" ]; then
1.84      lukem    1182:                # The correct value of KERNOBJDIR might
                   1183:                # depend on a prior "make obj" in
                   1184:                # ${KERNSRCDIR}/${KERNARCHDIR}/compile.
                   1185:                #
1.98      lukem    1186:                KERNSRCDIR="$(getmakevar KERNSRCDIR)"
                   1187:                KERNARCHDIR="$(getmakevar KERNARCHDIR)"
                   1188:                ${runcmd} cd "${KERNSRCDIR}/${KERNARCHDIR}/compile"
1.143     dsl      1189:                ${runcmd} "${makewrapper}" ${parallel} obj ||
1.98      lukem    1190:                    bomb "Failed to make obj in ${KERNSRCDIR}/${KERNARCHDIR}/compile"
                   1191:                ${runcmd} cd "${TOP}"
1.84      lukem    1192:        fi
1.98      lukem    1193:        KERNCONFDIR="$(getmakevar KERNCONFDIR)"
                   1194:        KERNOBJDIR="$(getmakevar KERNOBJDIR)"
1.105     lukem    1195:        case "${kernelconf}" in
1.84      lukem    1196:        */*)
1.105     lukem    1197:                kernelconfpath="${kernelconf}"
                   1198:                kernelconfname="${kernelconf##*/}"
1.84      lukem    1199:                ;;
                   1200:        *)
1.105     lukem    1201:                kernelconfpath="${KERNCONFDIR}/${kernelconf}"
                   1202:                kernelconfname="${kernelconf}"
1.84      lukem    1203:                ;;
                   1204:        esac
1.105     lukem    1205:        kernelbuildpath="${KERNOBJDIR}/${kernelconfname}"
                   1206: }
                   1207:
                   1208: buildkernel()
                   1209: {
                   1210:        if ! ${do_tools} && ! ${buildkernelwarned:-false}; then
                   1211:                # Building tools every time we build a kernel is clearly
                   1212:                # unnecessary.  We could try to figure out whether rebuilding
                   1213:                # the tools is necessary this time, but it doesn't seem worth
                   1214:                # the trouble.  Instead, we say it's the user's responsibility
                   1215:                # to rebuild the tools if necessary.
                   1216:                #
                   1217:                statusmsg "Building kernel without building new tools"
                   1218:                buildkernelwarned=true
                   1219:        fi
                   1220:        getkernelconf $1
                   1221:        statusmsg "Building kernel:  ${kernelconf}"
                   1222:        statusmsg "Build directory:  ${kernelbuildpath}"
                   1223:        ${runcmd} mkdir -p "${kernelbuildpath}" ||
                   1224:            bomb "Cannot mkdir: ${kernelbuildpath}"
1.124     lukem    1225:        if [ "${MKUPDATE}" = "no" ]; then
1.105     lukem    1226:                ${runcmd} cd "${kernelbuildpath}"
1.143     dsl      1227:                ${runcmd} "${makewrapper}" ${parallel} cleandir ||
1.105     lukem    1228:                    bomb "Failed to make cleandir in ${kernelbuildpath}"
1.98      lukem    1229:                ${runcmd} cd "${TOP}"
1.16      thorpej  1230:        fi
1.157     rillig   1231:        [ -x "${TOOLDIR}/bin/${toolprefix}config" ] \
                   1232:        || bomb "${TOOLDIR}/bin/${toolprefix}config does not exist. You need to \"$0 tools\" first."
1.105     lukem    1233:        ${runcmd} "${TOOLDIR}/bin/${toolprefix}config" -b "${kernelbuildpath}" \
                   1234:                -s "${TOP}/sys" "${kernelconfpath}" ||
                   1235:            bomb "${toolprefix}config failed for ${kernelconf}"
                   1236:        ${runcmd} cd "${kernelbuildpath}"
1.143     dsl      1237:        ${runcmd} "${makewrapper}" ${parallel} depend ||
1.105     lukem    1238:            bomb "Failed to make depend in ${kernelbuildpath}"
1.98      lukem    1239:        ${runcmd} "${makewrapper}" ${parallel} all ||
1.105     lukem    1240:            bomb "Failed to make all in ${kernelbuildpath}"
1.98      lukem    1241:        ${runcmd} cd "${TOP}"
1.91      lukem    1242:
1.98      lukem    1243:        if [ "${runcmd}" != "echo" ]; then
1.105     lukem    1244:                statusmsg "Kernels built from ${kernelconf}:"
                   1245:                kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
1.91      lukem    1246:                for kern in ${kernlist:-netbsd}; do
1.105     lukem    1247:                        [ -f "${kernelbuildpath}/${kern}" ] && \
                   1248:                            echo "  ${kernelbuildpath}/${kern}"
1.98      lukem    1249:                done | tee -a "${results}"
1.91      lukem    1250:        fi
1.84      lukem    1251: }
                   1252:
1.105     lukem    1253: releasekernel()
                   1254: {
                   1255:        getkernelconf $1
1.171.4.3! matt     1256:        kernelreldir="${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/kernel"
1.105     lukem    1257:        ${runcmd} mkdir -p "${kernelreldir}"
                   1258:        kernlist=$(awk '$1 == "config" { print $2 }' ${kernelconfpath})
                   1259:        for kern in ${kernlist:-netbsd}; do
                   1260:                builtkern="${kernelbuildpath}/${kern}"
                   1261:                [ -f "${builtkern}" ] || continue
                   1262:                releasekern="${kernelreldir}/${kern}-${kernelconfname}.gz"
                   1263:                statusmsg "Kernel copy:      ${releasekern}"
                   1264:                ${runcmd} gzip -c -9 < "${builtkern}" > "${releasekern}"
                   1265:        done
                   1266: }
                   1267:
1.84      lukem    1268: installworld()
                   1269: {
                   1270:        dir="$1"
1.98      lukem    1271:        ${runcmd} "${makewrapper}" INSTALLWORLDDIR="${dir}" installworld ||
                   1272:            bomb "Failed to make installworld to ${dir}"
                   1273:        statusmsg "Successful installworld to ${dir}"
1.84      lukem    1274: }
                   1275:
                   1276:
                   1277: main()
                   1278: {
                   1279:        initdefaults
1.130     jmc      1280:        _args=$@
1.84      lukem    1281:        parseoptions "$@"
1.93      lukem    1282:
1.163     apb      1283:        sanitycheck
                   1284:
1.93      lukem    1285:        build_start=$(date)
1.98      lukem    1286:        statusmsg "${progname} command: $0 $@"
                   1287:        statusmsg "${progname} started: ${build_start}"
1.165     apb      1288:        statusmsg "NetBSD version:   ${DISTRIBVER}"
                   1289:        statusmsg "MACHINE:          ${MACHINE}"
                   1290:        statusmsg "MACHINE_ARCH:     ${MACHINE_ARCH}"
                   1291:        statusmsg "Build platform:   ${uname_s} ${uname_r} ${uname_m}"
1.153     apb      1292:        statusmsg "HOST_SH:          ${HOST_SH}"
                   1293:
1.84      lukem    1294:        rebuildmake
                   1295:        validatemakeparams
                   1296:        createmakewrapper
                   1297:
                   1298:        # Perform the operations.
                   1299:        #
1.98      lukem    1300:        for op in ${operations}; do
                   1301:                case "${op}" in
1.86      lukem    1302:
                   1303:                makewrapper)
                   1304:                        # no-op
                   1305:                        ;;
1.84      lukem    1306:
                   1307:                tools)
                   1308:                        buildtools
                   1309:                        ;;
                   1310:
1.125     lukem    1311:                sets)
                   1312:                        statusmsg "Building sets from pre-populated ${DESTDIR}"
                   1313:                        ${runcmd} "${makewrapper}" ${parallel} ${op} ||
                   1314:                            bomb "Failed to make ${op}"
1.171.4.3! matt     1315:                        setdir=${RELEASEDIR}/${RELEASEMACHINEDIR}/binary/sets
        !          1316:                        statusmsg "Built sets to ${setdir}"
1.125     lukem    1317:                        ;;
1.142     apb      1318:
1.171.4.1  matt     1319:                obj|build|distribution|release|sourcesets|syspkgs|params)
1.98      lukem    1320:                        ${runcmd} "${makewrapper}" ${parallel} ${op} ||
                   1321:                            bomb "Failed to make ${op}"
                   1322:                        statusmsg "Successful make ${op}"
1.84      lukem    1323:                        ;;
                   1324:
1.171.4.1  matt     1325:                iso-image|iso-image-source)
                   1326:                        ${runcmd} "${makewrapper}" ${parallel} \
                   1327:                            CDEXTRA=$iso_dir ${op} ||
                   1328:                            bomb "Failed to make ${op}"
                   1329:                        statusmsg "Successful make ${op}"
                   1330:                        ;;
                   1331:
1.84      lukem    1332:                kernel=*)
                   1333:                        arg=${op#*=}
                   1334:                        buildkernel "${arg}"
1.105     lukem    1335:                        ;;
                   1336:
                   1337:                releasekernel=*)
                   1338:                        arg=${op#*=}
                   1339:                        releasekernel "${arg}"
1.84      lukem    1340:                        ;;
                   1341:
                   1342:                install=*)
                   1343:                        arg=${op#*=}
1.85      lukem    1344:                        if [ "${arg}" = "/" ] && \
                   1345:                            (   [ "${uname_s}" != "NetBSD" ] || \
1.98      lukem    1346:                                [ "${uname_m}" != "${MACHINE}" ] ); then
1.85      lukem    1347:                                bomb "'${op}' must != / for cross builds."
                   1348:                        fi
1.84      lukem    1349:                        installworld "${arg}"
1.70      lukem    1350:                        ;;
1.84      lukem    1351:
1.70      lukem    1352:                *)
1.84      lukem    1353:                        bomb "Unknown operation \`${op}'"
1.70      lukem    1354:                        ;;
1.84      lukem    1355:
1.70      lukem    1356:                esac
1.84      lukem    1357:        done
1.93      lukem    1358:
1.98      lukem    1359:        statusmsg "${progname} ended:   $(date)"
                   1360:        if [ -s "${results}" ]; then
                   1361:                echo "===> Summary of results:"
                   1362:                sed -e 's/^===>//;s/^/  /' "${results}"
                   1363:                echo "===> ."
                   1364:        fi
1.84      lukem    1365: }
                   1366:
                   1367: main "$@"

CVSweb <webmaster@jp.NetBSD.org>