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