Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/build.sh,v rcsdiff: /ftp/cvs/cvsroot/src/build.sh,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.9 retrieving revision 1.10 diff -u -p -r1.9 -r1.10 --- src/build.sh 2001/10/30 21:04:05 1.9 +++ src/build.sh 2001/10/30 22:33:00 1.10 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: build.sh,v 1.9 2001/10/30 21:04:05 jmc Exp $ +# $NetBSD: build.sh,v 1.10 2001/10/30 22:33:00 tv Exp $ # # Top level build wrapper, for a system containing no tools. # @@ -62,28 +62,43 @@ mkdirp () { for _f in "$@"; do if [ "$_f" != "" ]; then - [ -d "$_d$_f" ] || mkdir "$_d$_f" || return 1 + [ -d "$_d$_f" ] || $runcmd mkdir "$_d$_f" || return 1 _d="$_d$_f/" fi done } +resolvepath () { + case $OPTARG in + /*) ;; + *) OPTARG="$cwd/$OPTARG";; + esac +} + usage () { echo "Usage:" echo "$0 [-r] [-a arch] [-j njob] [-m mach] [-D dest] [-R release] [-T tools]" - echo " -b: bootstrap only. Build nbmake, install it and then exit." - echo " -m: set target MACHINE to mach (REQUIRED, or set in environment)" - echo " -D: set DESTDIR to dest (REQUIRED, or set in environment)" - echo " -T: set TOOLDIR to tools (REQUIRED, or set in environment)" + echo " -m: set target MACHINE to mach (REQUIRED)" + echo " -D: set DESTDIR to dest (REQUIRED unless -b is specified)" + echo " -T: set TOOLDIR to tools (REQUIRED)" echo "" echo " -a: set target MACHINE_ARCH to arch (otherwise deduced from MACHINE)" + echo " -b: do not build the system; just build nbmake if required." echo " -j: set NBUILDJOBS to njob" + echo " -n: show the commands that would be executed, but do not execute them" echo " -r: remove TOOLDIR and DESTDIR before the build" echo " -R: build a release (set RELEASEDIR) to release" exit 1 } -opts='a:bhj:m:rD:R:T:' +# Set defaults. +cwd=`pwd` +do_buildsystem=true +do_rebuildmake=false +do_removedirs=false +opt_a=no +opts='a:bhj:m:nrD:R:T:' +runcmd='' if type getopts >/dev/null 2>&1; then # Use POSIX getopts. @@ -100,51 +115,57 @@ else getoptcmd='[ $# -gt 0 ] && opt="$1" && shift' optargcmd='OPTARG="$1"; shift' fi - -opt_a=no + +# Parse command line options. while eval $getoptcmd; do case $opt in -a) eval $optargcmd MACHINE_ARCH=$OPTARG; opt_a=yes;; - -b) BOOTSTRAP_ONLY=1;; + -b) do_buildsystem=false;; -j) eval $optargcmd - buildjobs="NBUILDJOBS=$OPTARG";; + buildjobflag="NBUILDJOBS=$OPTARG";; # -m overrides MACHINE_ARCH unless "-a" is specified -m) eval $optargcmd MACHINE=$OPTARG; [ "$opt_a" != "yes" ] && getarch;; - -r) removedirs=true;; + -n) runcmd=echo;; + + -r) do_removedirs=true; do_rebuildmake=true;; - -D) eval $optargcmd + -D) eval $optargcmd; resolvepath DESTDIR="$OPTARG";; - -R) eval $optargcmd - releasedir="RELEASEDIR=$OPTARG"; buildtarget=release;; + -R) eval $optargcmd; resolvepath + releasedirflag="RELEASEDIR=$OPTARG"; buildtarget=release;; - -T) eval $optargcmd + -T) eval $optargcmd; resolvepath TOOLDIR="$OPTARG";; --) break;; -'?'|-h) usage;; esac; done -for var in MACHINE DESTDIR TOOLDIR; do - if ! eval 'test -n "$'$var'"'; then +# Check required environment; DESTDIR only needed if building. +checkvars='MACHINE TOOLDIR' +$do_buildsystem && checkvars="$checkvars DESTDIR" + +for var in $checkvars; do + if ! eval '[ -n "$'$var'" ]'; then echo "$var must be set in the environment before running build.sh." echo ""; usage fi done # Set up environment. -test -n "$MACHINE_ARCH" || getarch -test -d usr.bin/make || bomb "build.sh must be run from the top source level" +[ -n "$MACHINE_ARCH" ] || getarch +[ -d usr.bin/make ] || bomb "build.sh must be run from the top source level" # Remove the target directories. -if ${removedirs-false}; then +if $do_removedirs; then echo "Removing DESTDIR and TOOLDIR...." - rm -rf $DESTDIR $TOOLDIR + $runcmd rm -rf $DESTDIR $TOOLDIR fi mkdirp $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed" @@ -153,58 +174,64 @@ mkdirp $TOOLDIR/bin || bomb "mkdir of $T if [ -x $TOOLDIR/bin/nbmake ]; then for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do if [ $f -nt $TOOLDIR/bin/nbmake ]; then - rebuildmake=true; break + do_rebuildmake=true; break fi done else - rebuildmake=true + do_rebuildmake=true fi # Build $TOOLDIR/bin/nbmake. -if ${rebuildmake-false}; then +if $do_rebuildmake; then echo "Building nbmake...." # Go to a temporary directory in case building .o's happens. - srcdir=`pwd` tmpdir=${TMPDIR-/tmp}/nbbuild$$ - mkdir $tmpdir || bomb "cannot mkdir: $tmpdir" + $runcmd mkdir $tmpdir || bomb "cannot mkdir: $tmpdir" trap "rm -r -f $tmpdir" 0 trap "exit 1" 1 2 3 15 - cd $tmpdir + $runcmd cd $tmpdir - ${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \ - -o $TOOLDIR/bin/nbmake -I$srcdir/usr.bin/make \ - $srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c \ + ${runcmd-eval} "${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \ + -o $TOOLDIR/bin/nbmake -I$cwd/usr.bin/make \ + $cwd/usr.bin/make/*.c $cwd/usr.bin/make/lst.lib/*.c" \ || bomb "build of nbmake failed" # Clean up. - cd $srcdir - rm -r -f $tmpdir + $runcmd cd $cwd + $runcmd rm -r -f $tmpdir trap 0 1 2 3 15 # Some compilers are just *that* braindead. - rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o + ${runcmd-eval} "rm -f $cwd/usr.bin/make/*.o \ + $cwd/usr.bin/make/lst.lib/*.o" fi # Build a nbmake wrapper script, usable by hand as well as by build.sh. makeprog=$TOOLDIR/bin/nbmake-$MACHINE -if ${rebuildmake-false} || [ ! -f $makeprog ] || [ $makeprog -ot build.sh ]; then +if $do_rebuildmake || [ ! -f $makeprog ] || [ $makeprog -ot build.sh ]; then rm -f $makeprog - cat >$makeprog <