#! /bin/sh -e

# DP: Patch author: Stuart Anderson <anderson@netsweng.com>
# DP: Upstream status: Not submitted
# DP: Description: add full tri-arch support. Include linux64.h also fix up
# DP: Description: the directory names so that o32 is the default and follow
# DP: Description: the glibc convention for 32 & 64 bit names

dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
        patch $pdir -f --no-backup-if-mismatch -p1 < $0
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- src/gcc/config/mips/linux64.h	2007-08-02 12:49:31.000000000 +0200
+++ src/gcc/config/mips/linux64.h	2008-03-14 14:33:41.000000000 +0100
@@ -24,7 +24,7 @@
 #define DRIVER_SELF_SPECS \
 NO_SHARED_SPECS \
 " %{!EB:%{!EL:%(endian_spec)}}" \
-" %{!mabi=*: -mabi=n32}"
+" %{!mabi=*: -mabi=32}"
 
 #undef SUBTARGET_ASM_SPEC
 #define SUBTARGET_ASM_SPEC "\
--- src/gcc/config/mips/t-linux64	2006-06-06 14:51:24.000000000 +0200
+++ src/gcc/config/mips/t-linux64	2008-03-14 14:26:21.000000000 +0100
@@ -1,5 +1,5 @@
 MULTILIB_OPTIONS = mabi=n32/mabi=32/mabi=64
-MULTILIB_DIRNAMES = n32 32 64
+MULTILIB_DIRNAMES = n32 . 64
 MULTILIB_OSDIRNAMES = ../lib32 ../lib ../lib64
 
 EXTRA_MULTILIB_PARTS=crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o
--- src/gcc/config.gcc	2008-01-29 17:28:10.000000000 +0100
+++ src/gcc/config.gcc	2008-03-14 14:26:21.000000000 +0100
@@ -1680,7 +1680,8 @@
 	test x$with_llsc != x || with_llsc=yes
 	;;
 mips*-*-linux*)				# Linux MIPS, either endian.
-        tm_file="dbxelf.h elfos.h svr4.h linux.h ${tm_file} mips/linux.h"
+        tm_file="dbxelf.h elfos.h svr4.h linux.h ${tm_file} mips/linux.h mips/linux64.h"
+	tmake_file="${tmake_file} mips/t-linux64"
 	case ${target} in
         mipsisa32r2*)
 		tm_defines="${tm_defines} MIPS_ISA_DEFAULT=33"
