#!/bin/bash
#	$Id: patch-binutils,v 1.11 2002/12/27 06:03:16 mrustad Exp $
# Modify binutils to not build everything that comes out of CVS.
# Also patch config.sub to accept mipsisa32-brecis-elf

mkdir -p disabled

list="expect newlib libgloss sid libgui tcl itcl tk tix"
if [ "`uname`" = "Darwin" ] ; then
	list="${list} gdb sim"
fi

for name in ${list} ; do
	if [ -d ${name} ] ; then
		mv ${name} disabled
	fi
done

echo Updating config.sub
patch config.sub << "END_OF_PATCH"
--- config.sub.orig	Fri Mar 15 20:30:58 2002
+++ config.sub	Fri Mar 15 20:30:58 2002
@@ -299,6 +299,7 @@
 	| mips64orionel-* | mips64vr4100-* | mips64vr4100el-* \
 	| mips64vr4300-* | mips64vr4300el-* | mipsbe-* | mipseb-* \
 	| mipsle-* | mipsel-* | mipstx39-* | mipstx39el-* \
+	| mipsisa32-* \
 	| none-* | np1-* | ns16k-* | ns32k-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
END_OF_PATCH

echo Updating bfd/config.bfd
patch bfd/config.bfd << "END_OF_PATCH"
--- config.bfd.orig	Mon Jul  1 03:31:52 2002
+++ config.bfd	Wed Oct 23 22:54:41 2002
@@ -736,7 +736,7 @@
     targ_defvec=bfd_elf32_littlemips_vec
     targ_selvecs="bfd_elf32_bigmips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec"
     ;;
-  mips*-*-elf* | mips*-*-rtems* | mips*-*-vxworks*)
+  mips*-*-elf* | mips*-*-rtems* | mips*-*-vxworks* | mips*-*-uclinux*)
     targ_defvec=bfd_elf32_bigmips_vec
     targ_selvecs="bfd_elf32_littlemips_vec bfd_elf64_bigmips_vec bfd_elf64_littlemips_vec"
     ;;
END_OF_PATCH

echo Updating ld/configure.tgt
patch ld/configure.tgt << "END_OF_PATCH"
--- ld/configure.tgt.orig	Wed Oct 23 23:42:57 2002
+++ ld/configure.tgt	Wed Oct 23 23:44:31 2002
@@ -384,6 +384,7 @@
 mips*vr5000-*-elf*)	targ_emul=elf32b4300 ;;
 mips*el-*-elf*)		targ_emul=elf32elmip ;;
 mips*-*-elf*)		targ_emul=elf32ebmip ;;
+mips*-*-uclinux*)	targ_emul=elf32buclinuxmips ;;
 mips*el-*-rtems*)	targ_emul=elf32elmip ;;
 mips*-*-rtems*)		targ_emul=elf32ebmip ;;
 mips*el-*-vxworks*)	targ_emul=elf32elmip ;;
END_OF_PATCH

echo Updating gas/configure
patch gas/configure << "END_OF_PATCH"
--- gas/configure.orig	Thu Oct 24 10:48:00 2002
+++ gas/configure	Thu Oct 24 10:53:28 2002
@@ -2522,6 +2522,7 @@
       mips-*-lnews*)        fmt=ecoff em=lnews ;;
       mips-*-riscos*)       fmt=ecoff ;;
       mips*-*-linux*)	    fmt=elf em=tmips ;;
+      mips*-*-uclinux*)     fmt=elf ;;
       mips-*-sysv4*MP* | mips-*-gnu*)
 			    fmt=elf em=tmips ;;
       mips-*-sysv*)         fmt=ecoff ;;
END_OF_PATCH

echo Updating gas/configure.in
patch gas/configure.in << "END_OF_PATCH"
--- configure.in.orig	Thu Oct 24 10:55:00 2002
+++ configure.in	Thu Oct 24 10:55:43 2002
@@ -369,6 +369,7 @@
       mips-*-lnews*)        fmt=ecoff em=lnews ;;
       mips-*-riscos*)       fmt=ecoff ;;
       mips*-*-linux*)	    fmt=elf em=tmips ;;
+      mips*-*-uclinux*)     fmt=elf ;;
       mips-*-sysv4*MP* | mips-*-gnu*)
 			    fmt=elf em=tmips ;;
       mips-*-sysv*)         fmt=ecoff ;;
END_OF_PATCH

echo Patching ld/Makefile.in
patch ld/Makefile.in << "END_OF_PATCH"
--- Makefile.in.orig	Thu Oct 24 10:55:00 2002
+++ Makefile.in		Thu Dec 23 19:16:00 2002
@@ -268,6 +268,7 @@
 	eelf32btsmip.o \
 	eelf32ltsmip.o \
 	eelf32ebmip.o \
+	eelf32buclinuxmips.o \
 	eelf32elmip.o \
 	eelf32fr30.o \
 	eelf32frv.o \
@@ -1292,6 +1293,10 @@
   $(srcdir)/emulparams/elf32bmip.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ebmip "$(tdir_elf32ebmip)"
+eelf32buclinuxmips.c: $(srcdir)/emulparams/elf32bmip.sh \
+  $(srcdir)/emulparams/elf32buclinuxmips.sh \
+  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32buclinuxmips "$(tdir_elf32buclinuxmips)"
 eelf32elmip.c: $(srcdir)/emulparams/elf32elmip.sh \
   $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
END_OF_PATCH
echo Adding ld/emulparams/elf32buclinuxmips.sh
cat > ld/emulparams/elf32buclinuxmips.sh << "END_OF_FILE"
EMBEDDED=yes
. ${srcdir}/emulparams/elf32bmip.sh
TEXT_START_ADDR=0x0
NONPAGED_TEXT_START_ADDR=0x0
unset DATA_ADDR
MAXPAGESIZE=0x1000
unset SHLIB_TEXT_START_ADDR
unset OTHER_SECTIONS
unset GENERATE_SHLIB_SCRIPT
END_OF_FILE

# End of patch-binutils
