Paul Eggert wrote:

>Derek Price <[EMAIL PROTECTED]> writes:
>
>  
>
>>minmax was so nice and small, but would you be willing to add an m4 file
>>which called AC_CHECK_HEADERS([sys/param.h]) and the following lines to
>>the beginning of minmax.h?
>>
>>#ifdef HAVE_SYS_PARAM_H
>># include <sys/param.h>
>>#endif
>>    
>>
>
>Better yet, why not have "configure" check whether <sys/param.h>
>defines MIN and MAX, and include <sys/param.h> only if that's true?
>Similarly for <limits.h>.  That way, minmax.h will include these other
>files only on broken systems.
>
>  
>
>>I'll send the complete patch if you approve.
>>    
>>
>
>Could you please implement something along those lines?  Thanks.
>  
>

Okay, I've attached the patch you suggested, though I am still using the
AC_EGREP_CPP construct you mentioned you disliked in our glob
discussion.  Since this method works when cross-compiling and I've yet
to be convinced it is fragile, I'm going to hold off on a rewrite until
we settle the other discussion.

2005-05-15  Derek Price  <[EMAIL PROTECTED]>

    * lib/minmax.h: Only include <limits.h> and <sys/param.h> when needed.
    * m4/minmax.m4: New file.
    * modules/minmax: Add minmax.m4.

Cheers,

Derek
Index: lib/minmax.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/minmax.h,v
retrieving revision 1.4
diff -u -p -r1.4 minmax.h
--- lib/minmax.h        14 May 2005 06:03:58 -0000      1.4
+++ lib/minmax.h        15 May 2005 18:22:52 -0000
@@ -23,9 +23,14 @@
    MIN, MAX macro redefinitions on some systems; the workaround is to
    #include this file as the last one among the #include list.  */
 
-/* Before we define the following symbols we get the <limits.h> file
-   since otherwise we get redefinitions on some systems.  */
-#include <limits.h>
+/* Before we define the following symbols we try to get the <limits.h>
+   or <sys/param.h> files since otherwise we get redefinitions on some
+   systems.  */
+#ifdef LIMITS_H_HAS_MINMAX
+# include <limits.h>
+#elif SYS_PARAM_H_HAS_MINMAX
+# include <sys/param.h>
+#endif
 
 /* Note: MIN and MAX should be used with two arguments of the
    same type.  They might not return the minimum and maximum of their two
Index: m4/minmax.m4
===================================================================
RCS file: m4/minmax.m4
diff -N m4/minmax.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/minmax.m4        15 May 2005 18:22:52 -0000
@@ -0,0 +1,34 @@
+# minmax.m4 serial 1
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_MINMAX], [gl_PREREQ_MINMAX])
+
+# Prerequisites of minmax.h.
+AC_DEFUN([gl_PREREQ_MINMAX],
+[ dnl This really calls AC_REQUIRE, so just put it first.
+  AC_CHECK_HEADERS_ONCE([sys/param.h],
+    [gl_have_sys_param_h=:], [gl_have_sys_param_h=false])dnl
+
+  AC_EGREP_CPP([gl_minmax_test = MIN],
+[#include <limits.h>
+gl_minmax_test = MIN (xxx, yyy)],
+    [gl_limits_h_has_minmax=false], [gl_limits_h_has_minmax=:])
+
+  if $gl_limits_h_has_minmax; then
+    AC_DEFINE(LIMITS_H_HAS_MINMAX, 1,
+      [Define to 1 if <limits.h> defines the MIN and MAX macros.])
+  elif $gl_have_sys_param_h; then
+    AC_EGREP_CPP([gl_minmax_test = MIN],
+[#include <sys/param.h>
+gl_minmax_test = MIN (xxx, yyy)],
+      [gl_sys_param_h_has_minmax=false], [gl_sys_param_h_has_minmax=:])
+
+    if $gl_sys_param_h_has_minmax; then
+      AC_DEFINE(SYS_PARAM_H_HAS_MINMAX, 1,
+       [Define to 1 if <sys/param.h> defines the MIN and MAX macros.])
+    fi
+  fi
+  :])
Index: modules/minmax
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/minmax,v
retrieving revision 1.3
diff -u -p -r1.3 minmax
--- modules/minmax      28 Sep 2004 20:15:39 -0000      1.3
+++ modules/minmax      15 May 2005 18:22:52 -0000
@@ -3,10 +3,12 @@ MIN, MAX macros.
 
 Files:
 lib/minmax.h
+m4/minmax.m4
 
 Depends-on:
 
 configure.ac:
+gl_MINMAX
 
 Makefile.am:
 lib_SOURCES += minmax.h
_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to