Home | History | Annotate | Line # | Download | only in src
build.sh revision 1.1
      1  1.1  tv #! /bin/sh
      2  1.1  tv #  $NetBSD: build.sh,v 1.1 2001/10/19 02:21:03 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.1  tv 		acorn32|cats|dnard|evbarm|hpcarm|netwinder)
     21  1.1  tv 			MACHINE_ARCH=arm;;
     22  1.1  tv 
     23  1.1  tv 		sun2)
     24  1.1  tv 			MACHINE_ARCH=m68000;;
     25  1.1  tv 
     26  1.1  tv 		amiga|atari|cesfic|hp300|sun3|*68k)
     27  1.1  tv 			MACHINE_ARCH=m68k;;
     28  1.1  tv 
     29  1.1  tv 		mipsco|newsmips|sgimips)
     30  1.1  tv 			MACHINE_ARCH=mipseb;;
     31  1.1  tv 
     32  1.1  tv 		algor|arc|cobalt|hpcmips|playstation2|pmax)
     33  1.1  tv 			MACHINE_ARCH=mipsel;;
     34  1.1  tv 
     35  1.1  tv 		pc532)
     36  1.1  tv 			MACHINE_ARCH=ns32k;;
     37  1.1  tv 
     38  1.1  tv 		bebox|prep|sandpoint|walnut|*ppc)
     39  1.1  tv 			MACHINE_ARCH=powerpc;;
     40  1.1  tv 
     41  1.1  tv 		mmeye)
     42  1.1  tv 			MACHINE_ARCH=sh3eb;;
     43  1.1  tv 
     44  1.1  tv 		dreamcast|evbsh3|hpcsh)
     45  1.1  tv 			MACHINE_ARCH=sh3el;;
     46  1.1  tv 
     47  1.1  tv 		*)	MACHINE_ARCH=$MACHINE;;
     48  1.1  tv 	esac
     49  1.1  tv }
     50  1.1  tv 
     51  1.1  tv usage () {
     52  1.1  tv 	echo "Usage:"
     53  1.1  tv 	echo "$0 [-nr] [-m machine] [-D destdir] [-T tooldir]"
     54  1.1  tv 	echo "    -m: set target MACHINE to machine"
     55  1.1  tv 	echo "    -n: do not build a release (just install to DESTDIR)"
     56  1.1  tv 	echo "    -r: remove TOOLDIR and DESTDIR before the build"
     57  1.1  tv 	echo "    -D: set DESTDIR to destdir"
     58  1.1  tv 	echo "    -T: set TOOLDIR to tooldir"
     59  1.1  tv 	exit 1
     60  1.1  tv }
     61  1.1  tv 
     62  1.1  tv while getopts m:nrD:T: opt; do case $opt in
     63  1.1  tv 	m)	MACHINE=$OPTARG; getarch;; # getarch overrides MACHINE_ARCH
     64  1.1  tv 
     65  1.1  tv 	n)	buildtarget=build;;
     66  1.1  tv 
     67  1.1  tv 	r)	removedirs=true;;
     68  1.1  tv 
     69  1.1  tv 	D)	DESTDIR="$OPTARG";;
     70  1.1  tv 
     71  1.1  tv 	T)	TOOLDIR="$OPTARG";;
     72  1.1  tv 
     73  1.1  tv 	'?')	usage;;
     74  1.1  tv esac; done
     75  1.1  tv 
     76  1.1  tv for var in DESTDIR TOOLDIR MACHINE; do
     77  1.1  tv 	eval 'test -n "$'$var'"' || \
     78  1.1  tv 		bomb "$var must be set in the environment before running build.sh"
     79  1.1  tv done
     80  1.1  tv 
     81  1.1  tv # Set up environment.
     82  1.1  tv test -n "$MACHINE_ARCH" || getarch
     83  1.1  tv test -d usr.bin/make || bomb "build.sh must be run from the top source level"
     84  1.1  tv [ -d $TOOLDIR/bin ] || mkdir -p $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed"
     85  1.1  tv 
     86  1.1  tv # Remove the target directories.
     87  1.1  tv if ${removedirs-false}; then
     88  1.1  tv 	echo "Removing DESTDIR and TOOLDIR...."
     89  1.1  tv 	rm -rf $DESTDIR $TOOLDIR
     90  1.1  tv fi
     91  1.1  tv 
     92  1.1  tv # Test make source file timestamps against installed bmake binary.
     93  1.1  tv if [ -x $TOOLDIR/bin/bmake ]; then
     94  1.1  tv 	for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do
     95  1.1  tv 		if [ $f -nt $TOOLDIR/bin/bmake ]; then
     96  1.1  tv 			rebuildmake=true; break
     97  1.1  tv 		fi
     98  1.1  tv 	done
     99  1.1  tv else
    100  1.1  tv 	rebuildmake=true
    101  1.1  tv fi
    102  1.1  tv 
    103  1.1  tv # Build $TOOLDIR/bin/bmake.
    104  1.1  tv if ${rebuildmake-false}; then
    105  1.1  tv 	echo "Building bmake...."
    106  1.1  tv 
    107  1.1  tv 	# Go to a temporary directory in case building .o's happens.
    108  1.1  tv 	srcdir=`pwd`
    109  1.1  tv 	cd ${TMPDIR-/tmp}
    110  1.1  tv 
    111  1.1  tv 	${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \
    112  1.1  tv 		-o $TOOLDIR/bin/bmake -I$srcdir/usr.bin/make \
    113  1.1  tv 		$srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c
    114  1.1  tv 
    115  1.1  tv 	# Clean up.
    116  1.1  tv 	rm -f *.o
    117  1.1  tv 	cd $srcdir
    118  1.1  tv 
    119  1.1  tv 	# Some compilers are just *that* braindead.
    120  1.1  tv 	rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o
    121  1.1  tv fi
    122  1.1  tv 
    123  1.1  tv $TOOLDIR/bin/bmake ${buildtarget-release} -m `pwd`/share/mk \
    124  1.1  tv 	MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \
    125  1.1  tv 	MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH
    126