1 #! /bin/sh 2 # $NetBSD: build.sh,v 1.2 2001/10/19 02:25:48 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] [-j njobs] [-m machine] [-D destdir] [-T tooldir]" 54 echo " -j: set NBUILDJOBS to njobs" 55 echo " -m: set target MACHINE to machine" 56 echo " -n: do not build a release (just install to DESTDIR)" 57 echo " -r: remove TOOLDIR and DESTDIR before the build" 58 echo " -D: set DESTDIR to destdir" 59 echo " -T: set TOOLDIR to tooldir" 60 exit 1 61 } 62 63 while getopts j:m:nrD:T: opt; do case $opt in 64 j) buildjobs="NBUILDJOBS=$OPTARG";; 65 66 m) MACHINE=$OPTARG; getarch;; # getarch overrides MACHINE_ARCH 67 68 n) buildtarget=build;; 69 70 r) removedirs=true;; 71 72 D) DESTDIR="$OPTARG";; 73 74 T) TOOLDIR="$OPTARG";; 75 76 '?') usage;; 77 esac; done 78 79 for var in DESTDIR TOOLDIR MACHINE; do 80 eval 'test -n "$'$var'"' || \ 81 bomb "$var must be set in the environment before running build.sh" 82 done 83 84 # Set up environment. 85 test -n "$MACHINE_ARCH" || getarch 86 test -d usr.bin/make || bomb "build.sh must be run from the top source level" 87 [ -d $TOOLDIR/bin ] || mkdir -p $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed" 88 89 # Remove the target directories. 90 if ${removedirs-false}; then 91 echo "Removing DESTDIR and TOOLDIR...." 92 rm -rf $DESTDIR $TOOLDIR 93 fi 94 95 # Test make source file timestamps against installed bmake binary. 96 if [ -x $TOOLDIR/bin/bmake ]; then 97 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do 98 if [ $f -nt $TOOLDIR/bin/bmake ]; then 99 rebuildmake=true; break 100 fi 101 done 102 else 103 rebuildmake=true 104 fi 105 106 # Build $TOOLDIR/bin/bmake. 107 if ${rebuildmake-false}; then 108 echo "Building bmake...." 109 110 # Go to a temporary directory in case building .o's happens. 111 srcdir=`pwd` 112 cd ${TMPDIR-/tmp} 113 114 ${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \ 115 -o $TOOLDIR/bin/bmake -I$srcdir/usr.bin/make \ 116 $srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c \ 117 || bomb "build of bmake failed" 118 119 # Clean up. 120 rm -f *.o 121 cd $srcdir 122 123 # Some compilers are just *that* braindead. 124 rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o 125 fi 126 127 $TOOLDIR/bin/bmake ${buildtarget-release} -m `pwd`/share/mk \ 128 MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \ 129 MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH $buildjobs 130