Author: Aurelien Jarno <aurel32@debian.org>
Author: Sergei Golovan <sgolovan@debian.org>
Author: Pino Toscano <pino@debian.org>

(1) Defines GNU macros not only for Linux but also for any system
    with 'gnu' substring in OS name. Fixes FTBFS on GNU/kFreeBSD and GNU/Hurd.

(2) Undefines BSD4_4 for os_mon application for GNU/Hurd;

(3) Undefines AF_LINK for GNU/Hurd;

(4) Switch some PATH_MAX occurrences to MAXPATHLEN;

--- a/erts/configure.in
+++ b/erts/configure.in
@@ -451,7 +451,7 @@
 
 dnl NOTE: CPPFLAGS will be included in CFLAGS at the end
 case $host_os in
-    linux*) CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE";; 
+    linux*|*gnu*) CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE";; 
     win32)
 	# The ethread library requires _WIN32_WINNT of at least 0x0403.
 	# -D_WIN32_WINNT=* from CPPFLAGS is saved in ETHR_DEFS.
@@ -1209,7 +1209,7 @@
 fi
 
 case $host_os in
-    linux*)
+    linux*|*gnu*)
 	AC_MSG_CHECKING([whether dlopen() needs to be called before first call to dlerror()])
 	if test "x$ETHR_THR_LIB_BASE_TYPE" != "xposix_nptl"; then
 	    AC_DEFINE(ERTS_NEED_DLOPEN_BEFORE_DLERROR,[1],
--- a/lib/os_mon/c_src/memsup.c
+++ b/lib/os_mon/c_src/memsup.c
@@ -99,6 +99,11 @@
 #include <time.h>
 #include <errno.h>
 
+#ifdef __GNU__
+#warning "Undefined BSD4_4 for GNU/Hurd"
+#undef BSD4_4
+#endif
+
 #ifdef BSD4_4
 #include <sys/types.h>
 #include <sys/sysctl.h>
--- a/erts/emulator/drivers/common/inet_drv.c
+++ b/erts/emulator/drivers/common/inet_drv.c
@@ -4821,6 +4821,11 @@
     *x = addr;
     return 0;
 }
+#ifdef __GNU__
+#warning "Undefined AF_LINK for GNU/Hurd"
+#undef AF_LINK
+#endif
+
 
 #endif
 
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -1604,7 +1604,7 @@
     if (!bindir) {
 	/* Determine bindir from absolute path to executable */
 	char *p;
-	char buffer[PATH_MAX];
+	char buffer[MAXPATHLEN];
 	strncpy(buffer, argv[0], sizeof(buffer));
 	buffer[sizeof(buffer)-1] = '\0';
 	
@@ -1618,7 +1618,7 @@
     if (!rootdir) {
 	/* Determine rootdir from absolute path to bindir */
 	char *p;
-	char buffer[PATH_MAX];
+	char buffer[MAXPATHLEN];
 	strncpy(buffer, bindir, sizeof(buffer));
 	buffer[sizeof(buffer)-1] = '\0';
 	
--- a/erts/etc/common/escript.c
+++ b/erts/etc/common/escript.c
@@ -47,7 +47,7 @@
 #  define IS_DIRSEP(c) ((c) == '/')
 #  define DIRSEPSTR "/"
 #  define PATHSEPSTR ":"
-#  define PMAX PATH_MAX
+#  define PMAX MAXPATHLEN
 #  define ERL_NAME "erl"
 #endif
 
--- a/erts/etc/unix/dyn_erl.c
+++ b/erts/etc/unix/dyn_erl.c
@@ -144,8 +144,8 @@
 static char *
 find_prog(char *origpath)
 {
-    char relpath[PATH_MAX];
-    char abspath[PATH_MAX];
+    char relpath[MAXPATHLEN];
+    char abspath[MAXPATHLEN];
 
     strcpy(relpath, origpath);
 
@@ -156,7 +156,7 @@
         envpath = get_env("PATH");
         if (envpath) {
             /* Try to find the executable in the path */
-            char dir[PATH_MAX];
+            char dir[MAXPATHLEN];
             char *beg = envpath;
             char *end;
             int sz;
@@ -270,7 +270,7 @@
     /* List install dir and look for latest erts-vsn */
     DIR *dp;                    /* Pointer to directory structure. */
     struct dirent* dirp;        /* Pointer to directory entry.     */
-    char latest_vsn[PATH_MAX];  /* Latest erts-vsn directory name. */
+    char latest_vsn[MAXPATHLEN];/* Latest erts-vsn directory name. */
 
     dp = opendir(erl_top);
     if (dp == NULL) {
@@ -310,7 +310,7 @@
 
     char *p;
     char *p2;
-    char buffer[PATH_MAX];
+    char buffer[MAXPATHLEN];
 
     strcpy(buffer, erlpath);
 
@@ -353,9 +353,9 @@
     char *p;
     char *abspath;
     char *bindir;            /* Location of executables. */
-    char rootdir[PATH_MAX];  /* Root location of Erlang installation. */
-    char progname[PATH_MAX]; /* Name of this program. */
-    char erlexec[PATH_MAX];  /* Path to erlexec */
+    char rootdir[MAXPATHLEN];/* Root location of Erlang installation. */
+    char progname[MAXPATHLEN];/* Name of this program. */
+    char erlexec[MAXPATHLEN];/* Path to erlexec */
 
     /* Determine progname */
     abspath = find_prog(argv[0]);
