#! /bin/sh -e

# multiarch-include.dpatch by Stephen Frost <sfrost@debian.org>
#
# Adds the multiarch include directory (/usr/include/TARGET_ALIAS)
# 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
        ;;
    -unpatch)
        patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        ;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

--- gcc/cppdefault.h.orig	2004-05-24 11:48:27.000000000 -0400
+++ gcc/cppdefault.h	2004-05-24 11:58:03.000000000 -0400
@@ -30,6 +30,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
--- gcc/cppdefault.c.orig	2004-05-24 11:40:58.000000000 -0400
+++ gcc/cppdefault.c	2004-05-24 11:58:39.000000000 -0400
@@ -47,6 +47,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
@@ -66,6 +70,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 },
--- gcc/Makefile.in.orig	2004-05-24 12:19:17.000000000 -0400
+++ gcc/Makefile.in	2004-05-24 12:19:54.000000000 -0400
@@ -2205,6 +2205,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 \
