Annotation of src/build.sh, Revision 1.9
1.1 tv 1: #! /bin/sh
1.9 ! jmc 2: # $NetBSD: build.sh,v 1.8 2001/10/29 19:47:51 tv 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.7 matt 20: arm26|dnard|evbarm|hpcarm|netwinder)
1.1 tv 21: MACHINE_ARCH=arm;;
22:
1.7 matt 23: acorn32|arm32|cats)
1.5 bjh21 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]"
1.9 ! jmc 74: echo " -b: bootstrap only. Build nbmake, install it and then exit."
1.4 tv 75: echo " -m: set target MACHINE to mach (REQUIRED, or set in environment)"
76: echo " -D: set DESTDIR to dest (REQUIRED, or set in environment)"
77: echo " -T: set TOOLDIR to tools (REQUIRED, or set in environment)"
78: echo ""
79: echo " -a: set target MACHINE_ARCH to arch (otherwise deduced from MACHINE)"
1.3 tv 80: echo " -j: set NBUILDJOBS to njob"
1.1 tv 81: echo " -r: remove TOOLDIR and DESTDIR before the build"
1.4 tv 82: echo " -R: build a release (set RELEASEDIR) to release"
1.1 tv 83: exit 1
84: }
85:
1.9 ! jmc 86: opts='a:bhj:m:rD:R:T:'
1.4 tv 87:
88: if type getopts >/dev/null 2>&1; then
89: # Use POSIX getopts.
90: getoptcmd='getopts $opts opt && opt=-$opt'
91: optargcmd=':'
92: else
93: type getopt >/dev/null 2>&1 || bomb "/bin/sh shell is too old; try ksh"
1.2 tv 94:
1.4 tv 95: # Use old-style getopt(1) (doesn't handle whitespace in args).
96: args="`getopt $opts $*`"
97: [ $? = 0 ] || usage
98: set -- $args
1.1 tv 99:
1.4 tv 100: getoptcmd='[ $# -gt 0 ] && opt="$1" && shift'
101: optargcmd='OPTARG="$1"; shift'
102: fi
103:
104: opt_a=no
105: while eval $getoptcmd; do case $opt in
106: -a) eval $optargcmd
107: MACHINE_ARCH=$OPTARG; opt_a=yes;;
1.1 tv 108:
1.9 ! jmc 109: -b) BOOTSTRAP_ONLY=1;;
! 110:
1.4 tv 111: -j) eval $optargcmd
112: buildjobs="NBUILDJOBS=$OPTARG";;
1.1 tv 113:
1.4 tv 114: # -m overrides MACHINE_ARCH unless "-a" is specified
115: -m) eval $optargcmd
116: MACHINE=$OPTARG; [ "$opt_a" != "yes" ] && getarch;;
1.3 tv 117:
1.4 tv 118: -r) removedirs=true;;
1.1 tv 119:
1.4 tv 120: -D) eval $optargcmd
121: DESTDIR="$OPTARG";;
122:
123: -R) eval $optargcmd
124: releasedir="RELEASEDIR=$OPTARG"; buildtarget=release;;
125:
126: -T) eval $optargcmd
127: TOOLDIR="$OPTARG";;
128:
129: --) break;;
130: -'?'|-h) usage;;
1.1 tv 131: esac; done
132:
1.4 tv 133: for var in MACHINE DESTDIR TOOLDIR; do
134: if ! eval 'test -n "$'$var'"'; then
135: echo "$var must be set in the environment before running build.sh."
136: echo ""; usage
137: fi
1.1 tv 138: done
139:
140: # Set up environment.
141: test -n "$MACHINE_ARCH" || getarch
142: test -d usr.bin/make || bomb "build.sh must be run from the top source level"
143:
144: # Remove the target directories.
145: if ${removedirs-false}; then
146: echo "Removing DESTDIR and TOOLDIR...."
147: rm -rf $DESTDIR $TOOLDIR
148: fi
149:
1.4 tv 150: mkdirp $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed"
1.3 tv 151:
1.4 tv 152: # Test make source file timestamps against installed nbmake binary.
153: if [ -x $TOOLDIR/bin/nbmake ]; then
1.1 tv 154: for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
1.4 tv 155: if [ $f -nt $TOOLDIR/bin/nbmake ]; then
1.1 tv 156: rebuildmake=true; break
157: fi
158: done
159: else
160: rebuildmake=true
161: fi
162:
1.4 tv 163: # Build $TOOLDIR/bin/nbmake.
1.1 tv 164: if ${rebuildmake-false}; then
1.4 tv 165: echo "Building nbmake...."
1.1 tv 166:
167: # Go to a temporary directory in case building .o's happens.
168: srcdir=`pwd`
1.4 tv 169: tmpdir=${TMPDIR-/tmp}/nbbuild$$
170:
171: mkdir $tmpdir || bomb "cannot mkdir: $tmpdir"
172: trap "rm -r -f $tmpdir" 0
173: trap "exit 1" 1 2 3 15
174: cd $tmpdir
1.1 tv 175:
176: ${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \
1.4 tv 177: -o $TOOLDIR/bin/nbmake -I$srcdir/usr.bin/make \
1.2 tv 178: $srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c \
1.4 tv 179: || bomb "build of nbmake failed"
1.1 tv 180:
181: # Clean up.
182: cd $srcdir
1.4 tv 183: rm -r -f $tmpdir
184: trap 0 1 2 3 15
1.1 tv 185:
186: # Some compilers are just *that* braindead.
187: rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o
188: fi
189:
1.4 tv 190: # Build a nbmake wrapper script, usable by hand as well as by build.sh.
191: makeprog=$TOOLDIR/bin/nbmake-$MACHINE
192:
193: if ${rebuildmake-false} || [ ! -f $makeprog ] || [ $makeprog -ot build.sh ]; then
194: rm -f $makeprog
195: cat >$makeprog <<EOF
196: #! /bin/sh
197: # Set proper variables to allow easy "make" building of a NetBSD subtree.
1.9 ! jmc 198: # Generated from: \$NetBSD: build.sh,v 1.8 2001/10/29 19:47:51 tv Exp $
1.4 tv 199: #
200: exec $TOOLDIR/bin/nbmake MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH \
1.8 tv 201: USETOOLS=yes USE_NEW_TOOLCHAIN=yes TOOLDIR="$TOOLDIR" \${1+\$@}
1.4 tv 202: EOF
203: chmod +x $makeprog
204: fi
205:
1.9 ! jmc 206: if [ "$BOOTSTRAP_ONLY" != "1" ]; then
! 207: exec $makeprog -m `pwd`/share/mk ${buildtarget-build} \
! 208: MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \
! 209: $buildjobs $releasedir
! 210: fi
CVSweb <webmaster@jp.NetBSD.org>