#! /bin/sh -e

# DP: multiarch-include.dpatch by Stephen Frost <sfrost@debian.org>
# DP: updated for gcc-3.4 by Matthias Klose <doko@debian.org>
# DP:
# DP: Adds the multiarch include directory (/usr/include/TARGET_ALIAS)
# DP: to the system include paths.

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 -p0 < $0
        #cd ${dir}gcc && autoconf
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        #rm ${dir}gcc/configure
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

diff -urN gcc.old/Makefile.in gcc/Makefile.in
--- gcc.old/Makefile.in	2004-06-17 23:56:58.000000000 +0200
+++ gcc/Makefile.in	2004-07-10 01:44:11.000000000 +0200
@@ -2324,6 +2324,7 @@
   -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
+  -DTARGET_MACHINE=\"$(target_alias)\" \
   @TARGET_SYSTEM_ROOT_DEFINE@
 
 LIBCPP_OBJS =	cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpptrad.o \
diff -urN gcc.old/config/i386/t-linux64 gcc/config/i386/t-linux64
--- gcc.old/config/i386/t-linux64	2002-11-28 15:47:02.000000000 +0100
+++ gcc/config/i386/t-linux64	2004-07-10 01:44:11.000000000 +0200
@@ -6,7 +6,7 @@
 
 MULTILIB_OPTIONS = m64/m32
 MULTILIB_DIRNAMES = 64 32 
-MULTILIB_OSDIRNAMES = ../lib64 ../lib
+MULTILIB_OSDIRNAMES = x86_64-linux i486-linux
 
 LIBGCC = stmp-multilib
 INSTALL_LIBGCC = install-multilib
diff -urN gcc.old/config/t-linux gcc/config/t-linux
--- gcc.old/config/t-linux	2003-09-23 20:55:57.000000000 +0200
+++ gcc/config/t-linux	2004-07-10 01:48:41.000000000 +0200
@@ -11,3 +11,10 @@
 LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde-glibc.c \
   $(srcdir)/unwind-sjlj.c $(srcdir)/gthr-gnat.c $(srcdir)/unwind-c.c
 LIB2ADDEHDEP = unwind.inc unwind-dw2-fde.h unwind-dw2-fde.c gthr-gnat.c
+
+MULTILIB_OPTIONS = m32
+MULTILIB_DIRNAMES = 32
+MULTILIB_OSDIRNAMES = $TARGET_ARCH
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
diff -urN gcc.old/cppdefault.c gcc/cppdefault.c
--- gcc.old/cppdefault.c	2003-03-01 15:31:12.000000000 +0100
+++ gcc/cppdefault.c	2004-07-10 01:46:34.000000000 +0200
@@ -29,6 +29,14 @@
 #define STANDARD_INCLUDE_DIR "/usr/include"
 #endif
 
+#ifndef MULTIARCH_STANDARD_INCLUDE_DIR
+#define MULTIARCH_STANDARD_INCLUDE_DIR STANDARD_INCLUDE_DIR "/" TARGET_MACHINE
+#endif
+
+#ifndef MULTIARCH_LOCAL_INCLUDE_DIR
+#define MULTIARCH_LOCAL_INCLUDE_DIR LOCAL_INCLUDE_DIR "/" TARGET_MACHINE
+#endif
+
 #ifndef STANDARD_INCLUDE_COMPONENT
 #define STANDARD_INCLUDE_COMPONENT 0
 #endif
@@ -62,6 +70,10 @@
     /* /usr/local/include comes before the fixincluded header files.  */
     { LOCAL_INCLUDE_DIR, 0, 0, 1, 1 },
 #endif
+#ifdef MULTIARCH_LOCAL_INCLUDE_DIR
+    /* /usr/local/include/$target_alias comes before the fixincluded header files.  */
+    { MULTIARCH_LOCAL_INCLUDE_DIR, 0, 0, 1, 1 },
+#endif
 #ifdef PREFIX_INCLUDE_DIR
     { PREFIX_INCLUDE_DIR, 0, 0, 1, 0 },
 #endif
@@ -81,6 +93,9 @@
     /* Some systems have an extra dir of include files.  */
     { SYSTEM_INCLUDE_DIR, 0, 0, 0, 1 },
 #endif
+#ifdef MULTIARCH_STANDARD_INCLUDE_DIR
+    { MULTIARCH_STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1 },
+#endif
 #ifdef STANDARD_INCLUDE_DIR
     /* /usr/include comes dead last.  */
     { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1 },
