From e89eb70d8a04eb23eceafe72215f0f757cc99906 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 7 Sep 2010 12:10:38 -0600 Subject: [PATCH] getopt: handle POSIXLY_CORRECT set but not exported * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Restore pre-existing export state of POSIXLY_CORRECT. Reported by Dustin J. Mitchell. Signed-off-by: Eric Blake --- ChangeLog | 7 +++++++ m4/getopt.m4 | 23 ++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d27d6afb..f3a5ffb3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-09-07 Eric Blake + + getopt: handle POSIXLY_CORRECT set but not exported + * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Restore pre-existing + export state of POSIXLY_CORRECT, due to bash set -o posix. + Reported by Dustin J. Mitchell. + 2010-09-05 Bruno Haible gnulib-tool: Highlight the changed options. diff --git a/m4/getopt.m4 b/m4/getopt.m4 index caa5df435..720f0482a 100644 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -1,4 +1,4 @@ -# getopt.m4 serial 29 +# getopt.m4 serial 30 dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -50,6 +50,7 @@ AC_DEFUN([gl_GETOPT_IFELSE], AC_DEFUN([gl_GETOPT_CHECK_HEADERS], [ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([AC_PROG_AWK]) dnl for awk that supports ENVIRON dnl Persuade Solaris to declare optarg, optind, opterr, optopt. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) @@ -213,7 +214,17 @@ main () # optstring is necessary for programs like m4 that have POSIX-mandated # semantics for supporting options interspersed with files. # Also, since getopt_long is a GNU extension, we require optind=0. - gl_had_POSIXLY_CORRECT=${POSIXLY_CORRECT:+yes} + # Bash ties 'set -o posix' to a non-exported POSIXLY_CORRECT; + # so take care to revert to the correct (non-)export state. +dnl GNU Coding Standards currently allow awk but not env; besides, env +dnl is ambiguous with environment values that contain newlines. + gl_awk_probe='BEGIN { for (v in ENVIRON) + if (v == "POSIXLY_CORRECT") print "x" }' + case ${POSIXLY_CORRECT:+x}`$AWK "$gl_awk_probe"