1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 14:30:50 -08:00

Merge from gnulib.

* m4/getopt.m4: Copy new version from gnulib, incorporating:
getopt-posix: No longer guarantee that option processing is resettable.
This commit is contained in:
Paul Eggert 2012-06-27 17:07:33 -07:00
parent 0b6b25d572
commit 059e4fb5ed
2 changed files with 117 additions and 116 deletions

View file

@ -1,3 +1,9 @@
2012-06-28 Paul Eggert <eggert@cs.ucla.edu>
Merge from gnulib.
* m4/getopt.m4: Copy new version from gnulib, incorporating:
getopt-posix: No longer guarantee that option processing is resettable.
2012-06-27 Glenn Morris <rgm@gnu.org> 2012-06-27 Glenn Morris <rgm@gnu.org>
* configure.in: Only check for paxctl on gnu-linux. (Bug#11398#26) * configure.in: Only check for paxctl on gnu-linux. (Bug#11398#26)

View file

@ -1,4 +1,4 @@
# getopt.m4 serial 42 # getopt.m4 serial 43
dnl Copyright (C) 2002-2006, 2008-2012 Free Software Foundation, Inc. dnl Copyright (C) 2002-2006, 2008-2012 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
@ -74,11 +74,6 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes]) AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
fi 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
dnl setting optreset = 1 get rid of this internal state.
dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
dnl POSIX 2008 does not specify leading '+' behavior, but see dnl POSIX 2008 does not specify leading '+' behavior, but see
dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on
dnl the next version of POSIX. For now, we only guarantee leading '+' dnl the next version of POSIX. For now, we only guarantee leading '+'
@ -87,37 +82,22 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
AC_CACHE_CHECK([whether getopt is POSIX compatible], AC_CACHE_CHECK([whether getopt is POSIX compatible],
[gl_cv_func_getopt_posix], [gl_cv_func_getopt_posix],
[ [
dnl BSD getopt_long uses an incompatible method to reset option dnl Merging these three different test programs into a single one
dnl processing. Existence of the optreset variable, in and of dnl would require a reset mechanism. On BSD systems, it can be done
dnl itself, is not a reason to replace getopt, but knowledge dnl through 'optreset'; on some others (glibc), it can be done by
dnl of the variable is needed to determine how to reset and dnl setting 'optind' to 0; on others again (HP-UX, IRIX, OSF/1,
dnl whether a reset reparses the environment. Solaris dnl Solaris 9, musl libc), there is no such mechanism.
dnl supports neither optreset nor optind=0, but keeps no state if test $cross_compiling = no; then
dnl that needs a reset beyond setting optind=1; detect Solaris dnl Sanity check. Succeeds everywhere (except on MSVC,
dnl by getopt_clip. dnl which lacks <unistd.h> and getopt() entirely).
AC_LINK_IFELSE( AC_RUN_IFELSE(
[AC_LANG_PROGRAM( [AC_LANG_SOURCE([[
[[#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 <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
int int
main () main ()
{
{ {
static char program[] = "program"; static char program[] = "program";
static char a[] = "-a"; static char a[] = "-a";
@ -126,9 +106,6 @@ main ()
char *argv[] = { program, a, foo, bar, NULL }; char *argv[] = { program, a, foo, bar, NULL };
int c; int c;
optind = OPTIND_MIN;
opterr = 0;
c = getopt (4, argv, "ab"); c = getopt (4, argv, "ab");
if (!(c == 'a')) if (!(c == 'a'))
return 1; return 1;
@ -137,8 +114,22 @@ main ()
return 2; return 2;
if (!(optind == 2)) if (!(optind == 2))
return 3; return 3;
return 0;
} }
/* Some internal state exists at this point. */ ]])],
[gl_cv_func_getopt_posix=maybe],
[gl_cv_func_getopt_posix=no])
if test $gl_cv_func_getopt_posix = maybe; then
dnl Sanity check with '+'. Succeeds everywhere (except on MSVC,
dnl which lacks <unistd.h> and getopt() entirely).
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int
main ()
{ {
static char program[] = "program"; static char program[] = "program";
static char donald[] = "donald"; static char donald[] = "donald";
@ -150,9 +141,6 @@ main ()
char *argv[] = { program, donald, p, billy, duck, a, bar, NULL }; char *argv[] = { program, donald, p, billy, duck, a, bar, NULL };
int c; int c;
optind = OPTIND_MIN;
opterr = 0;
c = getopt (7, argv, "+abp:q:"); c = getopt (7, argv, "+abp:q:");
if (!(c == -1)) if (!(c == -1))
return 4; return 4;
@ -172,14 +160,26 @@ main ()
return 11; return 11;
if (!(optind == 1)) if (!(optind == 1))
return 12; return 12;
return 0;
} }
/* Detect Mac OS X 10.5, AIX 7.1 bug. */ ]])],
[gl_cv_func_getopt_posix=maybe],
[gl_cv_func_getopt_posix=no])
fi
if test $gl_cv_func_getopt_posix = maybe; then
dnl Detect Mac OS X 10.5, AIX 7.1, mingw bug.
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int
main ()
{ {
static char program[] = "program"; static char program[] = "program";
static char ab[] = "-ab"; static char ab[] = "-ab";
char *argv[3] = { program, ab, NULL }; char *argv[3] = { program, ab, NULL };
optind = OPTIND_MIN;
opterr = 0;
if (getopt (2, argv, "ab:") != 'a') if (getopt (2, argv, "ab:") != 'a')
return 13; return 13;
if (getopt (2, argv, "ab:") != '?') if (getopt (2, argv, "ab:") != '?')
@ -188,19 +188,18 @@ main ()
return 15; return 15;
if (optind != 2) if (optind != 2)
return 16; return 16;
}
return 0; return 0;
} }
]])], ]])],
[gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no], [gl_cv_func_getopt_posix=yes],
[case "$host_os" in [gl_cv_func_getopt_posix=no])
mingw*) gl_cv_func_getopt_posix="guessing no";; fi
darwin* | aix*) gl_cv_func_getopt_posix="guessing no";; else
case "$host_os" in
darwin* | aix* | mingw*) gl_cv_func_getopt_posix="guessing no";;
*) gl_cv_func_getopt_posix="guessing yes";; *) gl_cv_func_getopt_posix="guessing yes";;
esac esac
]) fi
CPPFLAGS=$gl_save_CPPFLAGS
]) ])
case "$gl_cv_func_getopt_posix" in case "$gl_cv_func_getopt_posix" in
*no) gl_replace_getopt=yes ;; *no) gl_replace_getopt=yes ;;
@ -304,12 +303,8 @@ dnl is ambiguous with environment values that contain newlines.
]])], ]])],
[gl_cv_func_getopt_gnu=yes], [gl_cv_func_getopt_gnu=yes],
[gl_cv_func_getopt_gnu=no], [gl_cv_func_getopt_gnu=no],
[dnl Cross compiling. Guess based on host and declarations. [dnl Cross compiling. Assume the worst, even on glibc platforms.
case $host_os:$ac_cv_have_decl_optreset in gl_cv_func_getopt_gnu="guessing no"
*-gnu*:* | mingw*:*) gl_cv_func_getopt_gnu=no;;
*:yes) gl_cv_func_getopt_gnu=no;;
*) gl_cv_func_getopt_gnu=yes;;
esac
]) ])
case $gl_had_POSIXLY_CORRECT in case $gl_had_POSIXLY_CORRECT in
exported) ;; exported) ;;
@ -317,7 +312,7 @@ dnl is ambiguous with environment values that contain newlines.
*) AS_UNSET([POSIXLY_CORRECT]) ;; *) AS_UNSET([POSIXLY_CORRECT]) ;;
esac esac
]) ])
if test "$gl_cv_func_getopt_gnu" = "no"; then if test "$gl_cv_func_getopt_gnu" != yes; then
gl_replace_getopt=yes gl_replace_getopt=yes
else else
AC_CACHE_CHECK([for working GNU getopt_long function], AC_CACHE_CHECK([for working GNU getopt_long function],