#! /bin/sh -e

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

# DP: Traditional GNU systems don't have a /usr directory.  However, Debian
# DP: systems do, and we support both having a /usr -> . symlink, and having a
# DP: /usr directory like the other ports.  So this patch should NOT go
# DP: upstream.
# DP: 
# DP: Define MAXPATHLEN and PATH_MAX.

--- gcc/config/gnu.h.orig	2004-07-05 21:49:20.000000000 +0200
+++ gcc/config/gnu.h	2006-12-10 12:28:45.000000000 +0100
@@ -6,7 +6,8 @@
 
 /* Standard include directory.  In GNU, "/usr" is a four-letter word.  */
 #undef STANDARD_INCLUDE_DIR
-#define STANDARD_INCLUDE_DIR "/include"
+/* Overriden for Debian GNU/Hurd.  */
+#define STANDARD_INCLUDE_DIR "/usr/include"
 
 /* The system headers under GNU are C++-aware.  */
 #define NO_IMPLICIT_EXTERN_C
--- gcc/config/t-gnu.orig	2004-01-10 07:40:24.000000000 +0100
+++ gcc/config/t-gnu	2006-12-10 12:28:45.000000000 +0100
@@ -1,2 +1,2 @@
 # In GNU, "/usr" is a four-letter word.
-NATIVE_SYSTEM_HEADER_DIR = /include
+NATIVE_SYSTEM_HEADER_DIR = /usr/include
--- gcc/tlink.c.orig	2005-06-25 04:02:01.000000000 +0200
+++ gcc/tlink.c	2006-12-10 12:28:45.000000000 +0100
@@ -34,6 +34,10 @@
 
 #define MAX_ITERATIONS 17
 
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 4096
+#endif
+
 /* Defined in the automatically-generated underscore.c.  */
 extern int prepends_underscore;
 
--- boehm-gc/dyn_load.c.orig	2007-08-13 09:10:48.215678000 +0200
+++ boehm-gc/dyn_load.c	2007-08-13 09:11:09.743969000 +0200
@@ -26,7 +26,7 @@
  * None of this is safe with dlclose and incremental collection.
  * But then not much of anything is safe in the presence of dlclose.
  */
-#if (defined(__linux__) || defined(__GLIBC__)) && !defined(_GNU_SOURCE)
+#if (defined(__linux__) || defined(__GLIBC__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
     /* Can't test LINUX, since this must be define before other includes */
 #   define _GNU_SOURCE
 #endif
