Index: ChangeLog
===================================================================
RCS file: /sources/findutils/findutils/ChangeLog,v
retrieving revision 1.204
diff -u -p -r1.204 ChangeLog
--- ChangeLog	9 Jun 2007 12:05:04 -0000	1.204
+++ ChangeLog	9 Jun 2007 12:20:37 -0000
@@ -1,5 +1,21 @@
 2007-06-09  James Youngman  <jay@gnu.org>
 
+	Ensure that <config.h> is included before any system header
+	* find/defs.h: Do not include <config.h> from "defs.h".  Instead
+	just complain if it was not already included, since it needs  to
+	be included first of all, even before system headers (in case
+	gnulib had replaced a system header).  Check
+	ALREADY_INCLUDED_CONFIG_H to determine this.
+	* configure.in: Always define ALREADY_INCLUDED_CONFIG_H in
+	config.h.
+	* find/find.c: Include config.h before defs.h.
+	* find/finddata.c: ditto.
+	* find/fstfind.c: ditto.
+	* find/parser.c: ditto.
+	* find/pred.c: ditto.
+	* find/util.c: ditto
+	* find/tree.c: ditto (fixing Savannah bug #20128).
+
 	* m4/noreturn.m4 (jy_AC_ATTRIBUTE_NORETURN): Use AC_LANG_PROGRAM
 	inside AC_COMPILE_IFELSE.
 
Index: configure.in
===================================================================
RCS file: /sources/findutils/findutils/configure.in,v
retrieving revision 1.123
diff -u -p -r1.123 configure.in
--- configure.in	3 Jun 2007 12:12:55 -0000	1.123
+++ configure.in	9 Jun 2007 12:20:37 -0000
@@ -233,7 +233,7 @@ dnl but findutils doesn't want to suppor
 dnl and wants to support an additional one (RE_SYNTAX_EMACS|RE_DOT_NEWLINE).
 dnl Hence they need to know if they are being compiled into findutils or not.
 AC_DEFINE([FINDUTILS], 1, [Define if we are compiling GNU findutils])
-
+AC_DEFINE([ALREADY_INCLUDED_CONFIG_H], 1, [Define so that source code can verify that config.h was already included])
 
 # This is necessary so that .o files in LIBOBJS are also built via
 # the ANSI2KNR-filtering rules.
Index: find/defs.h
===================================================================
RCS file: /sources/findutils/findutils/find/defs.h,v
retrieving revision 1.78
diff -u -p -r1.78 defs.h
--- find/defs.h	27 May 2007 15:21:17 -0000	1.78
+++ find/defs.h	9 Jun 2007 12:20:37 -0000
@@ -1,5 +1,5 @@
 /* defs.h -- data types and declarations.
-   Copyright (C) 1990, 91, 92, 93, 94, 2000, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1990, 91, 92, 93, 94, 2000, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -19,7 +19,21 @@
 #ifndef INC_DEFS_H
 #define INC_DEFS_H 1
 
-#include <config.h>
+#if !defined(ALREADY_INCLUDED_CONFIG_H)
+/*
+ * Savannah bug #20128: if we include some system header and it
+ * includes some othersecond system header, the second system header
+ * may in fact turn out to be a file provided by gnulib.  For that
+ * situation, we need to have already included <config.h> so that the
+ * Gnulib files have access to the information probed by their
+ * configure script fragments.  So <config.h> should be the first
+ * thing included.
+ */
+#error "<config.h> should be #included before defs.h, and indeed before any other header"
+Please stop compiling the program now
+#endif
+
+
 #include <sys/types.h>
 
 /* XXX: some of these includes probably don't belong in a common header file */
Index: find/find.c
===================================================================
RCS file: /sources/findutils/findutils/find/find.c,v
retrieving revision 1.117
diff -u -p -r1.117 find.c
--- find/find.c	1 May 2007 09:46:30 -0000	1.117
+++ find/find.c	9 Jun 2007 12:20:37 -0000
@@ -27,6 +27,7 @@
 */
 
 
+#include <config.h>
 #include "defs.h"
 
 #define USE_SAFE_CHDIR 1
@@ -44,9 +45,9 @@
 #endif
 #include <openat.h>
 
-#include "../gnulib/lib/xalloc.h"
-#include "../gnulib/lib/human.h"
-#include "../gnulib/lib/canonicalize.h"
+#include "xalloc.h"
+#include "human.h"
+#include "canonicalize.h"
 #include <modetype.h>
 
 #include "closeout.h"
Index: find/finddata.c
===================================================================
RCS file: /sources/findutils/findutils/find/finddata.c,v
retrieving revision 1.4
diff -u -p -r1.4 finddata.c
--- find/finddata.c	23 Dec 2005 19:02:59 -0000	1.4
+++ find/finddata.c	9 Jun 2007 12:20:37 -0000
@@ -1,6 +1,6 @@
 /* finddata.c -- global data for "find".
    Copyright (C) 1990, 91, 92, 93, 94, 2000, 
-                 2003, 2004, 2005 Free Software Foundation, Inc.
+                 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,6 +18,8 @@
    USA.
 */
 
+#include <config.h>
+
 #include "defs.h"
 
 
Index: find/ftsfind.c
===================================================================
RCS file: /sources/findutils/findutils/find/ftsfind.c,v
retrieving revision 1.31
diff -u -p -r1.31 ftsfind.c
--- find/ftsfind.c	5 May 2007 11:16:47 -0000	1.31
+++ find/ftsfind.c	9 Jun 2007 12:20:37 -0000
@@ -28,6 +28,7 @@
 */
 
 
+#include <config.h>
 #include "defs.h"
 
 
@@ -45,11 +46,8 @@
 #endif
 
 #include <unistd.h>
-#if defined(HAVE_FCNTL_H)
-#include <fcntl.h>
-#endif
 
-#include "../gnulib/lib/xalloc.h"
+#include "xalloc.h"
 #include "closeout.h"
 #include <modetype.h>
 #include "quotearg.h"
Index: find/parser.c
===================================================================
RCS file: /sources/findutils/findutils/find/parser.c,v
retrieving revision 1.123
diff -u -p -r1.123 parser.c
--- find/parser.c	31 May 2007 09:05:21 -0000	1.123
+++ find/parser.c	9 Jun 2007 12:20:38 -0000
@@ -1,6 +1,6 @@
 /* parser.c -- convert the command line args into an expression tree.
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000, 2001, 2003, 
-                 2004, 2005, 2006 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
    USA.
 */
 
+#include <config.h>
 
 #include "defs.h"
 #include <ctype.h>
Index: find/pred.c
===================================================================
RCS file: /sources/findutils/findutils/find/pred.c,v
retrieving revision 1.98
diff -u -p -r1.98 pred.c
--- find/pred.c	31 May 2007 09:05:21 -0000	1.98
+++ find/pred.c	9 Jun 2007 12:20:39 -0000
@@ -1,6 +1,6 @@
 /* pred.c -- execute the expression tree.
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000, 2003, 
-                 2004, 2005 Free Software Foundation, Inc.
+                 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
    USA.
 */
 
+#include <config.h>
 #include "defs.h"
 
 #include <fnmatch.h>
Index: find/tree.c
===================================================================
RCS file: /sources/findutils/findutils/find/tree.c,v
retrieving revision 1.35
diff -u -p -r1.35 tree.c
--- find/tree.c	6 May 2007 12:35:07 -0000	1.35
+++ find/tree.c	9 Jun 2007 12:20:39 -0000
@@ -17,11 +17,13 @@
    USA.
 */
 
+#include <config.h>
+#include "defs.h"
+
 #include <assert.h>
 #include <stdlib.h>
 
-#include "defs.h"
-#include "../gnulib/lib/xalloc.h"
+#include "xalloc.h"
 #include "error.h"
 
 
Index: find/util.c
===================================================================
RCS file: /sources/findutils/findutils/find/util.c,v
retrieving revision 1.42
diff -u -p -r1.42 util.c
--- find/util.c	26 May 2007 10:37:26 -0000	1.42
+++ find/util.c	9 Jun 2007 12:20:39 -0000
@@ -17,6 +17,7 @@
    USA.
 */
 
+#include <config.h>
 #include "defs.h"
 
 #ifdef HAVE_FCNTL_H
