bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] getopt: omit HAVE_OPTRESET, HAVE_GETOPT_CLIP from config.h


From: Paul Eggert
Subject: [PATCH] getopt: omit HAVE_OPTRESET, HAVE_GETOPT_CLIP from config.h
Date: Fri, 21 Jan 2011 22:35:25 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7

This is continuing my Emacs-inspired campaign to put
config.h on a diet.

* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Do not put the
symbols HAVE_OPTRESET and HAVE_GETOPT_CLIP into config.h,
as they are needed only for configure's test case.
This removes two unnecessary symbols from config.h.
---
 ChangeLog    |    6 ++++++
 m4/getopt.m4 |   45 ++++++++++++++++++++++++---------------------
 2 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5093e9c..d915713 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2011-01-21  Paul Eggert  <address@hidden>
 
+       getopt: omit HAVE_OPTRESET, HAVE_GETOPT_CLIP from config.h
+       * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Do not put the
+       symbols HAVE_OPTRESET and HAVE_GETOPT_CLIP into config.h,
+       as they are needed only for configure's test case.
+       This removes two unnecessary symbols from config.h.
+
        gl_CHECK_NEXT_HEADERS implies AC_CHECK_HEADERS_ONCE
        * m4/include_next.m4 (gl_CHECK_HEXT_HEADERS): Document this.
        * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Don't bother to invoke
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index d351b84..035a530 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -1,4 +1,4 @@
-# getopt.m4 serial 33
+# getopt.m4 serial 34
 dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -75,20 +75,6 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
     AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
   fi
 
-  dnl BSD getopt_long uses an incompatible method to reset option processing.
-  dnl Existence of the variable, in and of itself, is not a reason to replace
-  dnl getopt, but knowledge of the variable is needed to determine how to
-  dnl reset and whether a reset reparses the environment.
-  dnl Solaris supports neither optreset nor optind=0, but keeps no state that
-  dnl needs a reset beyond setting optind=1; detect Solaris by getopt_clip.
-  if test -z "$gl_replace_getopt"; then
-    AC_CHECK_DECLS([optreset], [],
-      [AC_CHECK_DECLS([getopt_clip], [], [],
-        [[#include <getopt.h>]])
-      ],
-      [[#include <getopt.h>]])
-  fi
-
   dnl mingw's getopt (in libmingwex.a) does weird things when the options
   dnl strings starts with '+' and it's not the first call.  Some internal state
   dnl is left over from earlier calls, and neither setting optind = 0 nor
@@ -102,18 +88,34 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
     AC_CACHE_CHECK([whether getopt is POSIX compatible],
       [gl_cv_func_getopt_posix],
       [
+        dnl BSD getopt_long uses an incompatible method to reset
+        dnl option processing.  Existence of the variable, in and of
+        dnl itself, is not a reason to replace getopt, but knowledge
+        dnl of the variable is needed to determine how to reset and
+        dnl whether a reset reparses the environment.  Solaris
+        dnl supports neither optreset nor optind=0, but keeps no state
+        dnl that needs a reset beyond setting optind=1; detect Solaris
+        dnl by getopt_clip.
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM(
+             [[#include <unistd.h>]],
+             [[int *p = &optreset; return optreset;]])],
+          [gl_optind_min=1],
+          [AC_COMPILE_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[#include <getopt.h>]],
+                [[return !getopt_clip;]])],
+             [gl_optind_min=1],
+             [gl_optind_min=0])])
+
         dnl This test fails on mingw and succeeds on many other platforms.
+        gl_save_CPPFLAGS=$CPPFLAGS
+        CPPFLAGS="$CPPFLAGS -DOPTIND_MIN=$gl_optind_min"
         AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
-#if !HAVE_DECL_OPTRESET && !HAVE_DECL_GETOPT_CLIP
-# define OPTIND_MIN 0
-#else
-# define OPTIND_MIN 1
-#endif
-
 int
 main ()
 {
@@ -201,6 +203,7 @@ main ()
              *)              gl_cv_func_getopt_posix="guessing yes";;
            esac
           ])
+        CPPFLAGS=$gl_save_CPPFLAGS
       ])
     case "$gl_cv_func_getopt_posix" in
       *no) gl_replace_getopt=yes ;;
-- 
1.7.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]