1 #! /bin/sh 2 # $NetBSD: build.sh,v 1.3 2001/10/19 16:43:47 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 [-r] [-j njob] [-m mach] [-D dest] [-R release] [-T tools]" 54 echo " -j: set NBUILDJOBS to njob" 55 echo " -m: set target MACHINE to mach" 56 echo " -r: remove TOOLDIR and DESTDIR before the build" 57 echo " -D: set DESTDIR to dest" 58 echo " -R: build a release to release" 59 echo " -T: set TOOLDIR to tools" 60 exit 1 61 } 62 63 while getopts hj:m:rD:R:T: opt; do case $opt in 64 j) buildjobs="NBUILDJOBS=$OPTARG";; 65 66 m) MACHINE=$OPTARG; getarch;; # getarch overrides MACHINE_ARCH 67 68 r) removedirs=true;; 69 70 D) DESTDIR="$OPTARG";; 71 72 R) releasedir="RELEASEDIR=$OPTARG"; buildtarget=release;; 73 74 T) TOOLDIR="$OPTARG";; 75 76 '?'|h) 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 88 # Remove the target directories. 89 if ${removedirs-false}; then 90 echo "Removing DESTDIR and TOOLDIR...." 91 rm -rf $DESTDIR $TOOLDIR 92 fi 93 94 [ -d $TOOLDIR/bin ] || mkdir -p $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed" 95 96 # Test make source file timestamps against installed bmake binary. 97 if [ -x $TOOLDIR/bin/bmake ]; then 98 for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do 99 if [ $f -nt $TOOLDIR/bin/bmake ]; then 100 rebuildmake=true; break 101 fi 102 done 103 else 104 rebuildmake=true 105 fi 106 107 # Build $TOOLDIR/bin/bmake. 108 if ${rebuildmake-false}; then 109 echo "Building bmake...." 110 111 # Go to a temporary directory in case building .o's happens. 112 srcdir=`pwd` 113 cd ${TMPDIR-/tmp} 114 115 ${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \ 116 -o $TOOLDIR/bin/bmake -I$srcdir/usr.bin/make \ 117 $srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c \ 118 || bomb "build of bmake failed" 119 120 # Clean up. 121 rm -f *.o 122 cd $srcdir 123 124 # Some compilers are just *that* braindead. 125 rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o 126 fi 127 128 $TOOLDIR/bin/bmake ${buildtarget-build} -m `pwd`/share/mk \ 129 MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \ 130 MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH \ 131 $buildjobs $releasedir 132