From: Bruno Haible Date: Sat, 23 Jun 2012 15:08:47 +0000 (+0200) Subject: getopt-gnu: Handle suboptimal getopt_long's abbreviation handling. X-Git-Tag: v0.1~591 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=ae480d585dfa17a0a4cca3998251b22c069bef44 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. --- diff --git a/ChangeLog b/ChangeLog index 74354d51c..5c563fd2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-06-23 Bruno Haible + + 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 time_r: fix typo that always overrode localtime_r decl diff --git a/doc/posix-functions/getopt.texi b/doc/posix-functions/getopt.texi index a3cd89054..4cad91b25 100644 --- a/doc/posix-functions/getopt.texi +++ b/doc/posix-functions/getopt.texi @@ -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. diff --git a/m4/getopt.m4 b/m4/getopt.m4 index be1333772..c5f15630c 100644 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -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 + #include + #include + ]], + [[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 ])