Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src * Clean up a bit; always use [] for comparison tests.
details: https://anonhg.NetBSD.org/src/rev/5032c196fd62
branches: trunk
changeset: 516811:5032c196fd62
user: tv <tv%NetBSD.org@localhost>
date: Tue Oct 30 22:33:00 2001 +0000
description:
* Clean up a bit; always use [] for comparison tests.
* Don't require DESTDIR when -b is set.
* Add -n option, which prints the commands that would be run by build.sh,
but doesn't run them (much like make's -n option).
* Auto-resolve relative paths for -D, -R, and -T (but not for the
corresponding environment variables).
* Explicitly declare defaults of all shell variables used where feasible,
rather than sprinkling ${varname-value} expansions.
* Prefix shell true/false variables with "do_" to indicate their use as
actual values in shell expressions (like "$do_buildsystem && echo foo").
diffstat:
build.sh | 109 +++++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 68 insertions(+), 41 deletions(-)
diffs (217 lines):
diff -r a0d2f1375ae6 -r 5032c196fd62 build.sh
--- a/build.sh Tue Oct 30 21:52:26 2001 +0000
+++ b/build.sh Tue Oct 30 22:33:00 2001 +0000
@@ -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 @@
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 @@
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;;
- -D) eval $optargcmd
+ -r) do_removedirs=true; do_rebuildmake=true;;
+
+ -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 @@
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 <<EOF
+ if [ "$runcmd" = "echo" ]; then
+ mkscriptcmd='echo "cat >$makeprog <<EOF" && cat'
+ else
+ mkscriptcmd="cat >$makeprog"
+ fi
+ eval $mkscriptcmd <<EOF
#! /bin/sh
# Set proper variables to allow easy "make" building of a NetBSD subtree.
-# Generated from: \$NetBSD: build.sh,v 1.9 2001/10/30 21:04:05 jmc Exp $
+# Generated from: \$NetBSD: build.sh,v 1.10 2001/10/30 22:33:00 tv Exp $
#
exec $TOOLDIR/bin/nbmake MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH \
USETOOLS=yes USE_NEW_TOOLCHAIN=yes TOOLDIR="$TOOLDIR" \${1+\$@}
EOF
- chmod +x $makeprog
+ [ "$runcmd" = "echo" ] && echo EOF
+ $runcmd chmod +x $makeprog
fi
-if [ "$BOOTSTRAP_ONLY" != "1" ]; then
- exec $makeprog -m `pwd`/share/mk ${buildtarget-build} \
+if $do_buildsystem; then
+ ${runcmd-exec} $makeprog -m `pwd`/share/mk ${buildtarget-build} \
MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \
- $buildjobs $releasedir
+ $buildjobflag $releasedirflag
fi
Home |
Main Index |
Thread Index |
Old Index