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

Annotation of src/build.sh, Revision 1.6

1.1       tv          1: #! /bin/sh
1.6     ! bjh21       2: #  $NetBSD: build.sh,v 1.5 2001/10/24 14:00:24 bjh21 Exp $
1.1       tv          3: #
                      4: # Top level build wrapper, for a system containing no tools.
                      5: #
                      6: # This script should run on any POSIX-compliant shell.  For systems
                      7: # with a strange /bin/sh, "ksh" may be an ample alternative.
                      8: #
                      9:
                     10: bomb () {
                     11:        echo ""
                     12:        echo "ERROR: $@"
                     13:        echo "*** BUILD ABORTED ***"
                     14:        exit 1
                     15: }
                     16:
                     17: getarch () {
                     18:        # Translate a MACHINE into a default MACHINE_ARCH.
                     19:        case $MACHINE in
1.6     ! bjh21      20:                arm26|dnard|evbarm|hpcarm)
1.1       tv         21:                        MACHINE_ARCH=arm;;
                     22:
1.5       bjh21      23:                acorn32|arm32|cats|netwinder)
                     24:                        MACHINE_ARCH=arm32;;
                     25:
1.1       tv         26:                sun2)
                     27:                        MACHINE_ARCH=m68000;;
                     28:
                     29:                amiga|atari|cesfic|hp300|sun3|*68k)
                     30:                        MACHINE_ARCH=m68k;;
                     31:
                     32:                mipsco|newsmips|sgimips)
                     33:                        MACHINE_ARCH=mipseb;;
                     34:
                     35:                algor|arc|cobalt|hpcmips|playstation2|pmax)
                     36:                        MACHINE_ARCH=mipsel;;
                     37:
                     38:                pc532)
                     39:                        MACHINE_ARCH=ns32k;;
                     40:
                     41:                bebox|prep|sandpoint|walnut|*ppc)
                     42:                        MACHINE_ARCH=powerpc;;
                     43:
                     44:                mmeye)
                     45:                        MACHINE_ARCH=sh3eb;;
                     46:
                     47:                dreamcast|evbsh3|hpcsh)
                     48:                        MACHINE_ARCH=sh3el;;
                     49:
1.5       bjh21      50:                alpha|i386|sparc|sparc64|vax|x86_64)
1.4       tv         51:                        MACHINE_ARCH=$MACHINE;;
                     52:
                     53:                *)      bomb "unknown target MACHINE: $MACHINE";;
1.1       tv         54:        esac
                     55: }
                     56:
1.4       tv         57: # Emulate "mkdir -p" for systems that have an Old "mkdir".
                     58: mkdirp () {
                     59:        IFS=/; set -- $@; unset IFS
                     60:        _d=
                     61:        if [ "$1" = "" ]; then _d=/; shift; fi
                     62:
                     63:        for _f in "$@"; do
                     64:                if [ "$_f" != "" ]; then
                     65:                        [ -d "$_d$_f" ] || mkdir "$_d$_f" || return 1
                     66:                        _d="$_d$_f/"
                     67:                fi
                     68:        done
                     69: }
                     70:
1.1       tv         71: usage () {
                     72:        echo "Usage:"
1.4       tv         73:        echo "$0 [-r] [-a arch] [-j njob] [-m mach] [-D dest] [-R release] [-T tools]"
                     74:        echo "    -m: set target MACHINE to mach (REQUIRED, or set in environment)"
                     75:        echo "    -D: set DESTDIR to dest (REQUIRED, or set in environment)"
                     76:        echo "    -T: set TOOLDIR to tools (REQUIRED, or set in environment)"
                     77:        echo ""
                     78:        echo "    -a: set target MACHINE_ARCH to arch (otherwise deduced from MACHINE)"
1.3       tv         79:        echo "    -j: set NBUILDJOBS to njob"
1.1       tv         80:        echo "    -r: remove TOOLDIR and DESTDIR before the build"
1.4       tv         81:        echo "    -R: build a release (set RELEASEDIR) to release"
1.1       tv         82:        exit 1
                     83: }
                     84:
1.4       tv         85: opts='a:hj:m:rD:R:T:'
                     86:
                     87: if type getopts >/dev/null 2>&1; then
                     88:        # Use POSIX getopts.
                     89:        getoptcmd='getopts $opts opt && opt=-$opt'
                     90:        optargcmd=':'
                     91: else
                     92:        type getopt >/dev/null 2>&1 || bomb "/bin/sh shell is too old; try ksh"
1.2       tv         93:
1.4       tv         94:        # Use old-style getopt(1) (doesn't handle whitespace in args).
                     95:        args="`getopt $opts $*`"
                     96:        [ $? = 0 ] || usage
                     97:        set -- $args
1.1       tv         98:
1.4       tv         99:        getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
                    100:        optargcmd='OPTARG="$1"; shift'
                    101: fi
                    102:
                    103: opt_a=no
                    104: while eval $getoptcmd; do case $opt in
                    105:        -a)     eval $optargcmd
                    106:                MACHINE_ARCH=$OPTARG; opt_a=yes;;
1.1       tv        107:
1.4       tv        108:        -j)     eval $optargcmd
                    109:                buildjobs="NBUILDJOBS=$OPTARG";;
1.1       tv        110:
1.4       tv        111:        # -m overrides MACHINE_ARCH unless "-a" is specified
                    112:        -m)     eval $optargcmd
                    113:                MACHINE=$OPTARG; [ "$opt_a" != "yes" ] && getarch;;
1.3       tv        114:
1.4       tv        115:        -r)     removedirs=true;;
1.1       tv        116:
1.4       tv        117:        -D)     eval $optargcmd
                    118:                DESTDIR="$OPTARG";;
                    119:
                    120:        -R)     eval $optargcmd
                    121:                releasedir="RELEASEDIR=$OPTARG"; buildtarget=release;;
                    122:
                    123:        -T)     eval $optargcmd
                    124:                TOOLDIR="$OPTARG";;
                    125:
                    126:        --)             break;;
                    127:        -'?'|-h)        usage;;
1.1       tv        128: esac; done
                    129:
1.4       tv        130: for var in MACHINE DESTDIR TOOLDIR; do
                    131:        if ! eval 'test -n "$'$var'"'; then
                    132:                echo "$var must be set in the environment before running build.sh."
                    133:                echo ""; usage
                    134:        fi
1.1       tv        135: done
                    136:
                    137: # Set up environment.
                    138: test -n "$MACHINE_ARCH" || getarch
                    139: test -d usr.bin/make || bomb "build.sh must be run from the top source level"
                    140:
                    141: # Remove the target directories.
                    142: if ${removedirs-false}; then
                    143:        echo "Removing DESTDIR and TOOLDIR...."
                    144:        rm -rf $DESTDIR $TOOLDIR
                    145: fi
                    146:
1.4       tv        147: mkdirp $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed"
1.3       tv        148:
1.4       tv        149: # Test make source file timestamps against installed nbmake binary.
                    150: if [ -x $TOOLDIR/bin/nbmake ]; then
1.1       tv        151:        for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1.4       tv        152:                if [ $f -nt $TOOLDIR/bin/nbmake ]; then
1.1       tv        153:                        rebuildmake=true; break
                    154:                fi
                    155:        done
                    156: else
                    157:        rebuildmake=true
                    158: fi
                    159:
1.4       tv        160: # Build $TOOLDIR/bin/nbmake.
1.1       tv        161: if ${rebuildmake-false}; then
1.4       tv        162:        echo "Building nbmake...."
1.1       tv        163:
                    164:        # Go to a temporary directory in case building .o's happens.
                    165:        srcdir=`pwd`
1.4       tv        166:        tmpdir=${TMPDIR-/tmp}/nbbuild$$
                    167:
                    168:        mkdir $tmpdir || bomb "cannot mkdir: $tmpdir"
                    169:        trap "rm -r -f $tmpdir" 0
                    170:        trap "exit 1" 1 2 3 15
                    171:        cd $tmpdir
1.1       tv        172:
                    173:        ${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \
1.4       tv        174:                -o $TOOLDIR/bin/nbmake -I$srcdir/usr.bin/make \
1.2       tv        175:                $srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c \
1.4       tv        176:                || bomb "build of nbmake failed"
1.1       tv        177:
                    178:        # Clean up.
                    179:        cd $srcdir
1.4       tv        180:        rm -r -f $tmpdir
                    181:        trap 0 1 2 3 15
1.1       tv        182:
                    183:        # Some compilers are just *that* braindead.
                    184:        rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o
                    185: fi
                    186:
1.4       tv        187: # Build a nbmake wrapper script, usable by hand as well as by build.sh.
                    188: makeprog=$TOOLDIR/bin/nbmake-$MACHINE
                    189:
                    190: if ${rebuildmake-false} || [ ! -f $makeprog ] || [ $makeprog -ot build.sh ]; then
                    191:        rm -f $makeprog
                    192:        cat >$makeprog <<EOF
                    193: #! /bin/sh
                    194: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.6     ! bjh21     195: # Generated from:  \$NetBSD: build.sh,v 1.5 2001/10/24 14:00:24 bjh21 Exp $
1.4       tv        196: #
                    197: exec $TOOLDIR/bin/nbmake MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH \
                    198: USETOOLS=yes USE_NEW_TOOLCHAIN=yes \${1+\$@}
                    199: EOF
                    200:        chmod +x $makeprog
                    201: fi
                    202:
                    203: exec $makeprog -m `pwd`/share/mk ${buildtarget-build} \
1.1       tv        204:        MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \
1.3       tv        205:        $buildjobs $releasedir

CVSweb <webmaster@jp.NetBSD.org>