1 1.1 tv #! /bin/sh 2 1.4 tv # $NetBSD: build.sh,v 1.4 2001/10/24 02:39:56 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.4 tv alpha|arm26|i386|sparc|sparc64|vax|x86_64) 48 1.4 tv MACHINE_ARCH=$MACHINE;; 49 1.4 tv 50 1.4 tv *) bomb "unknown target MACHINE: $MACHINE";; 51 1.1 tv esac 52 1.1 tv } 53 1.1 tv 54 1.4 tv # Emulate "mkdir -p" for systems that have an Old "mkdir". 55 1.4 tv mkdirp () { 56 1.4 tv IFS=/; set -- $@; unset IFS 57 1.4 tv _d= 58 1.4 tv if [ "$1" = "" ]; then _d=/; shift; fi 59 1.4 tv 60 1.4 tv for _f in "$@"; do 61 1.4 tv if [ "$_f" != "" ]; then 62 1.4 tv [ -d "$_d$_f" ] || mkdir "$_d$_f" || return 1 63 1.4 tv _d="$_d$_f/" 64 1.4 tv fi 65 1.4 tv done 66 1.4 tv } 67 1.4 tv 68 1.1 tv usage () { 69 1.1 tv echo "Usage:" 70 1.4 tv echo "$0 [-r] [-a arch] [-j njob] [-m mach] [-D dest] [-R release] [-T tools]" 71 1.4 tv echo " -m: set target MACHINE to mach (REQUIRED, or set in environment)" 72 1.4 tv echo " -D: set DESTDIR to dest (REQUIRED, or set in environment)" 73 1.4 tv echo " -T: set TOOLDIR to tools (REQUIRED, or set in environment)" 74 1.4 tv echo "" 75 1.4 tv echo " -a: set target MACHINE_ARCH to arch (otherwise deduced from MACHINE)" 76 1.3 tv echo " -j: set NBUILDJOBS to njob" 77 1.1 tv echo " -r: remove TOOLDIR and DESTDIR before the build" 78 1.4 tv echo " -R: build a release (set RELEASEDIR) to release" 79 1.1 tv exit 1 80 1.1 tv } 81 1.1 tv 82 1.4 tv opts='a:hj:m:rD:R:T:' 83 1.4 tv 84 1.4 tv if type getopts >/dev/null 2>&1; then 85 1.4 tv # Use POSIX getopts. 86 1.4 tv getoptcmd='getopts $opts opt && opt=-$opt' 87 1.4 tv optargcmd=':' 88 1.4 tv else 89 1.4 tv type getopt >/dev/null 2>&1 || bomb "/bin/sh shell is too old; try ksh" 90 1.2 tv 91 1.4 tv # Use old-style getopt(1) (doesn't handle whitespace in args). 92 1.4 tv args="`getopt $opts $*`" 93 1.4 tv [ $? = 0 ] || usage 94 1.4 tv set -- $args 95 1.1 tv 96 1.4 tv getoptcmd='[ $# -gt 0 ] && opt="$1" && shift' 97 1.4 tv optargcmd='OPTARG="$1"; shift' 98 1.4 tv fi 99 1.4 tv 100 1.4 tv opt_a=no 101 1.4 tv while eval $getoptcmd; do case $opt in 102 1.4 tv -a) eval $optargcmd 103 1.4 tv MACHINE_ARCH=$OPTARG; opt_a=yes;; 104 1.1 tv 105 1.4 tv -j) eval $optargcmd 106 1.4 tv buildjobs="NBUILDJOBS=$OPTARG";; 107 1.1 tv 108 1.4 tv # -m overrides MACHINE_ARCH unless "-a" is specified 109 1.4 tv -m) eval $optargcmd 110 1.4 tv MACHINE=$OPTARG; [ "$opt_a" != "yes" ] && getarch;; 111 1.3 tv 112 1.4 tv -r) removedirs=true;; 113 1.1 tv 114 1.4 tv -D) eval $optargcmd 115 1.4 tv DESTDIR="$OPTARG";; 116 1.4 tv 117 1.4 tv -R) eval $optargcmd 118 1.4 tv releasedir="RELEASEDIR=$OPTARG"; buildtarget=release;; 119 1.4 tv 120 1.4 tv -T) eval $optargcmd 121 1.4 tv TOOLDIR="$OPTARG";; 122 1.4 tv 123 1.4 tv --) break;; 124 1.4 tv -'?'|-h) usage;; 125 1.1 tv esac; done 126 1.1 tv 127 1.4 tv for var in MACHINE DESTDIR TOOLDIR; do 128 1.4 tv if ! eval 'test -n "$'$var'"'; then 129 1.4 tv echo "$var must be set in the environment before running build.sh." 130 1.4 tv echo ""; usage 131 1.4 tv fi 132 1.1 tv done 133 1.1 tv 134 1.1 tv # Set up environment. 135 1.1 tv test -n "$MACHINE_ARCH" || getarch 136 1.1 tv test -d usr.bin/make || bomb "build.sh must be run from the top source level" 137 1.1 tv 138 1.1 tv # Remove the target directories. 139 1.1 tv if ${removedirs-false}; then 140 1.1 tv echo "Removing DESTDIR and TOOLDIR...." 141 1.1 tv rm -rf $DESTDIR $TOOLDIR 142 1.1 tv fi 143 1.1 tv 144 1.4 tv mkdirp $TOOLDIR/bin || bomb "mkdir of $TOOLDIR/bin failed" 145 1.3 tv 146 1.4 tv # Test make source file timestamps against installed nbmake binary. 147 1.4 tv if [ -x $TOOLDIR/bin/nbmake ]; then 148 1.1 tv for f in usr.bin/make/*.[ch] usr.bin/make/lst.lib/*.[ch]; do 149 1.4 tv if [ $f -nt $TOOLDIR/bin/nbmake ]; then 150 1.1 tv rebuildmake=true; break 151 1.1 tv fi 152 1.1 tv done 153 1.1 tv else 154 1.1 tv rebuildmake=true 155 1.1 tv fi 156 1.1 tv 157 1.4 tv # Build $TOOLDIR/bin/nbmake. 158 1.1 tv if ${rebuildmake-false}; then 159 1.4 tv echo "Building nbmake...." 160 1.1 tv 161 1.1 tv # Go to a temporary directory in case building .o's happens. 162 1.1 tv srcdir=`pwd` 163 1.4 tv tmpdir=${TMPDIR-/tmp}/nbbuild$$ 164 1.4 tv 165 1.4 tv mkdir $tmpdir || bomb "cannot mkdir: $tmpdir" 166 1.4 tv trap "rm -r -f $tmpdir" 0 167 1.4 tv trap "exit 1" 1 2 3 15 168 1.4 tv cd $tmpdir 169 1.1 tv 170 1.1 tv ${HOST_CC-cc} ${HOST_CFLAGS} -DMAKE_BOOTSTRAP \ 171 1.4 tv -o $TOOLDIR/bin/nbmake -I$srcdir/usr.bin/make \ 172 1.2 tv $srcdir/usr.bin/make/*.c $srcdir/usr.bin/make/lst.lib/*.c \ 173 1.4 tv || bomb "build of nbmake failed" 174 1.1 tv 175 1.1 tv # Clean up. 176 1.1 tv cd $srcdir 177 1.4 tv rm -r -f $tmpdir 178 1.4 tv trap 0 1 2 3 15 179 1.1 tv 180 1.1 tv # Some compilers are just *that* braindead. 181 1.1 tv rm -f $srcdir/usr.bin/make/*.o $srcdir/usr.bin/make/lst.lib/*.o 182 1.1 tv fi 183 1.1 tv 184 1.4 tv # Build a nbmake wrapper script, usable by hand as well as by build.sh. 185 1.4 tv makeprog=$TOOLDIR/bin/nbmake-$MACHINE 186 1.4 tv 187 1.4 tv if ${rebuildmake-false} || [ ! -f $makeprog ] || [ $makeprog -ot build.sh ]; then 188 1.4 tv rm -f $makeprog 189 1.4 tv cat >$makeprog <<EOF 190 1.4 tv #! /bin/sh 191 1.4 tv # Set proper variables to allow easy "make" building of a NetBSD subtree. 192 1.4 tv # Generated from: \$NetBSD: build.sh,v 1.4 2001/10/24 02:39:56 tv Exp $ 193 1.4 tv # 194 1.4 tv exec $TOOLDIR/bin/nbmake MACHINE=$MACHINE MACHINE_ARCH=$MACHINE_ARCH \ 195 1.4 tv USETOOLS=yes USE_NEW_TOOLCHAIN=yes \${1+\$@} 196 1.4 tv EOF 197 1.4 tv chmod +x $makeprog 198 1.4 tv fi 199 1.4 tv 200 1.4 tv exec $makeprog -m `pwd`/share/mk ${buildtarget-build} \ 201 1.1 tv MKTOOLS=yes DESTDIR="$DESTDIR" TOOLDIR="$TOOLDIR" \ 202 1.3 tv $buildjobs $releasedir 203