getopt-gnu: Handle suboptimal getopt_long's abbreviation handling.
authorBruno Haible <bruno@clisp.org>
Sat, 23 Jun 2012 15:08:47 +0000 (17:08 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 23 Jun 2012 15:09:24 +0000 (17:09 +0200)
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): If getopt_long exists but
does not handle abbreviated long options with equivalent
disambiguations, set gl_replace_getopt to yes.
* doc/posix-functions/getopt.texi: Mention the OpenBSD 5.0 problem.

ChangeLog
doc/posix-functions/getopt.texi
m4/getopt.m4

index 74354d5..5c563fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-06-23  Bruno Haible  <bruno@clisp.org>
+
+       getopt-gnu: Handle suboptimal getopt_long's abbreviation handling.
+       * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): If getopt_long exists but
+       does not handle abbreviated long options with equivalent
+       disambiguations, set gl_replace_getopt to yes.
+       * doc/posix-functions/getopt.texi: Mention the OpenBSD 5.0 problem.
+
 2012-06-22  Paul Eggert  <eggert@cs.ucla.edu>
 
        time_r: fix typo that always overrode localtime_r decl
index a3cd890..4cad91b 100644 (file)
@@ -48,6 +48,10 @@ Solaris 11 2010-11, Cygwin 1.5.x.
 The function @code{getopt_long} is missing on some platforms:
 AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, MSVC 9, Interix 3.5.
 @item
+The function @code{getopt_long} does not support abbreviated long options
+where all disambiguations are equivalent on some platforms:
+OpenBSD 5.0.
+@item
 The function @code{getopt_long_only} is missing on some platforms:
 Mac OS X 10.3, FreeBSD 5.2.1, NetBSD 5.0, AIX 5.1, HP-UX 11, IRIX 6.5,
 OSF/1 5.1, Solaris 9, mingw, MSVC 9, Interix 3.5.
index be13337..c5f1563 100644 (file)
@@ -1,4 +1,4 @@
-# getopt.m4 serial 41
+# getopt.m4 serial 42
 dnl Copyright (C) 2002-2006, 2008-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -319,6 +319,48 @@ dnl is ambiguous with environment values that contain newlines.
       ])
     if test "$gl_cv_func_getopt_gnu" = "no"; then
       gl_replace_getopt=yes
+    else
+      AC_CACHE_CHECK([for working GNU getopt_long function],
+        [gl_cv_func_getopt_long_gnu],
+        [AC_RUN_IFELSE(
+           [AC_LANG_PROGRAM(
+              [[#include <getopt.h>
+                #include <stddef.h>
+                #include <string.h>
+              ]],
+              [[static const struct option long_options[] =
+                  {
+                    { "xtremely-",no_argument,       NULL, 1003 },
+                    { "xtra",     no_argument,       NULL, 1001 },
+                    { "xtreme",   no_argument,       NULL, 1002 },
+                    { "xtremely", no_argument,       NULL, 1003 },
+                    { NULL,       0,                 NULL, 0 }
+                  };
+                /* This code fails on OpenBSD 5.0.  */
+                {
+                  static char program[] = "program";
+                  static char xtremel[] = "--xtremel";
+                  char *argv[] = { program, xtremel, NULL };
+                  int option_index;
+                  optind = 1; opterr = 0;
+                  if (getopt_long (2, argv, "", long_options, &option_index) != 1003)
+                    return 1;
+                }
+                return 0;
+              ]])],
+           [gl_cv_func_getopt_long_gnu=yes],
+           [gl_cv_func_getopt_long_gnu=no],
+           [dnl Cross compiling. Guess no on OpenBSD, yes otherwise.
+            case "$host_os" in
+              openbsd*) gl_cv_func_getopt_long_gnu="guessing no";;
+              *)        gl_cv_func_getopt_long_gnu="guessing yes";;
+            esac
+           ])
+        ])
+      case "$gl_cv_func_getopt_long_gnu" in
+        *yes) ;;
+        *) gl_replace_getopt=yes ;;
+      esac
     fi
   fi
 ])