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