~ubuntu-branches/ubuntu/trusty/libidn/trusty

« back to all changes in this revision

Viewing changes to gl/m4/getopt.m4

  • Committer: Bazaar Package Importer
  • Author(s): Simon Josefsson
  • Date: 2011-03-01 16:14:24 UTC
  • mfrom: (1.2.14 upstream) (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110301161424-6vh7822t8aderzap
Tags: 1.20-1
* New upstream release.
* Moved from experimental to unstable after testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# getopt.m4 serial 24
2
 
dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc.
 
1
# getopt.m4 serial 34
 
2
dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
5
5
dnl with or without modifications, as long as this notice is preserved.
50
50
AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
51
51
[
52
52
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
53
  AC_REQUIRE([AC_PROG_AWK]) dnl for awk that supports ENVIRON
53
54
 
54
55
  dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt.
55
56
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
56
57
 
57
58
  gl_CHECK_NEXT_HEADERS([getopt.h])
58
 
  AC_CHECK_HEADERS_ONCE([getopt.h])
59
59
  if test $ac_cv_header_getopt_h = yes; then
60
60
    HAVE_GETOPT_H=1
61
61
  else
75
75
    AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
76
76
  fi
77
77
 
78
 
  dnl BSD getopt_long uses an incompatible method to reset option processing.
79
 
  dnl Existence of the variable, in and of itself, is not a reason to replace
80
 
  dnl getopt, but knowledge of the variable is needed to determine how to
81
 
  dnl reset and whether a reset reparses the environment.
82
 
  if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
83
 
    AC_CHECK_DECLS([optreset], [], [],
84
 
      [[#include <getopt.h>]])
85
 
  fi
86
 
 
87
78
  dnl mingw's getopt (in libmingwex.a) does weird things when the options
88
79
  dnl strings starts with '+' and it's not the first call.  Some internal state
89
80
  dnl is left over from earlier calls, and neither setting optind = 0 nor
90
81
  dnl setting optreset = 1 get rid of this internal state.
91
82
  dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
 
83
  dnl POSIX 2008 does not specify leading '+' behavior, but see
 
84
  dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on
 
85
  dnl the next version of POSIX.  For now, we only guarantee leading '+'
 
86
  dnl behavior with getopt-gnu.
92
87
  if test -z "$gl_replace_getopt"; then
93
88
    AC_CACHE_CHECK([whether getopt is POSIX compatible],
94
89
      [gl_cv_func_getopt_posix],
95
90
      [
96
 
        dnl This test fails on mingw and succeeds on all other platforms.
 
91
        dnl BSD getopt_long uses an incompatible method to reset
 
92
        dnl option processing.  Existence of the variable, in and of
 
93
        dnl itself, is not a reason to replace getopt, but knowledge
 
94
        dnl of the variable is needed to determine how to reset and
 
95
        dnl whether a reset reparses the environment.  Solaris
 
96
        dnl supports neither optreset nor optind=0, but keeps no state
 
97
        dnl that needs a reset beyond setting optind=1; detect Solaris
 
98
        dnl by getopt_clip.
 
99
        AC_COMPILE_IFELSE(
 
100
          [AC_LANG_PROGRAM(
 
101
             [[#include <unistd.h>]],
 
102
             [[int *p = &optreset; return optreset;]])],
 
103
          [gl_optind_min=1],
 
104
          [AC_COMPILE_IFELSE(
 
105
             [AC_LANG_PROGRAM(
 
106
                [[#include <getopt.h>]],
 
107
                [[return !getopt_clip;]])],
 
108
             [gl_optind_min=1],
 
109
             [gl_optind_min=0])])
 
110
 
 
111
        dnl This test fails on mingw and succeeds on many other platforms.
 
112
        gl_save_CPPFLAGS=$CPPFLAGS
 
113
        CPPFLAGS="$CPPFLAGS -DOPTIND_MIN=$gl_optind_min"
97
114
        AC_RUN_IFELSE([AC_LANG_SOURCE([[
98
115
#include <unistd.h>
99
116
#include <stdlib.h>
100
117
#include <string.h>
101
118
 
102
 
#if !HAVE_DECL_OPTRESET
103
 
# define OPTIND_MIN 0
104
 
#else
105
 
# define OPTIND_MIN 1
106
 
#endif
107
 
 
108
119
int
109
120
main ()
110
121
{
167
178
    if (!(optind == 1))
168
179
      return 12;
169
180
  }
 
181
  /* Detect MacOS 10.5, AIX 7.1 bug.  */
 
182
  {
 
183
    char *argv[3] = { "program", "-ab", NULL };
 
184
    optind = OPTIND_MIN;
 
185
    opterr = 0;
 
186
    if (getopt (2, argv, "ab:") != 'a')
 
187
      return 13;
 
188
    if (getopt (2, argv, "ab:") != '?')
 
189
      return 14;
 
190
    if (optopt != 'b')
 
191
      return 15;
 
192
    if (optind != 2)
 
193
      return 16;
 
194
  }
170
195
 
171
196
  return 0;
172
197
}
173
198
]])],
174
199
          [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no],
175
200
          [case "$host_os" in
176
 
             mingw*) gl_cv_func_getopt_posix="guessing no";;
177
 
             *)      gl_cv_func_getopt_posix="guessing yes";;
 
201
             mingw*)         gl_cv_func_getopt_posix="guessing no";;
 
202
             darwin* | aix*) gl_cv_func_getopt_posix="guessing no";;
 
203
             *)              gl_cv_func_getopt_posix="guessing yes";;
178
204
           esac
179
205
          ])
 
206
        CPPFLAGS=$gl_save_CPPFLAGS
180
207
      ])
181
208
    case "$gl_cv_func_getopt_posix" in
182
209
      *no) gl_replace_getopt=yes ;;
189
216
       # optstring is necessary for programs like m4 that have POSIX-mandated
190
217
       # semantics for supporting options interspersed with files.
191
218
       # Also, since getopt_long is a GNU extension, we require optind=0.
192
 
       gl_had_POSIXLY_CORRECT=${POSIXLY_CORRECT:+yes}
 
219
       # Bash ties 'set -o posix' to a non-exported POSIXLY_CORRECT;
 
220
       # so take care to revert to the correct (non-)export state.
 
221
dnl GNU Coding Standards currently allow awk but not env; besides, env
 
222
dnl is ambiguous with environment values that contain newlines.
 
223
       gl_awk_probe='BEGIN { if ("POSIXLY_CORRECT" in ENVIRON) print "x" }'
 
224
       case ${POSIXLY_CORRECT+x}`$AWK "$gl_awk_probe" </dev/null` in
 
225
         xx) gl_had_POSIXLY_CORRECT=exported ;;
 
226
         x)  gl_had_POSIXLY_CORRECT=yes      ;;
 
227
         *)  gl_had_POSIXLY_CORRECT=         ;;
 
228
       esac
193
229
       POSIXLY_CORRECT=1
194
230
       export POSIXLY_CORRECT
195
231
       AC_RUN_IFELSE(
197
233
                           #include <stddef.h>
198
234
                           #include <string.h>
199
235
           ]], [[
 
236
             int result = 0;
200
237
             /* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw,
201
238
                and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
202
239
                OSF/1 5.1, Solaris 10.  */
207
244
               myargv[2] = 0;
208
245
               opterr = 0;
209
246
               if (getopt (2, myargv, "+a") != '?')
210
 
                 return 1;
 
247
                 result |= 1;
211
248
             }
212
249
             /* This code succeeds on glibc 2.8, mingw,
213
250
                and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11,
217
254
 
218
255
               optind = 1;
219
256
               if (getopt (4, argv, "p::") != 'p')
220
 
                 return 2;
221
 
               if (optarg != NULL)
222
 
                 return 3;
223
 
               if (getopt (4, argv, "p::") != -1)
224
 
                 return 4;
225
 
               if (optind != 2)
226
 
                 return 5;
 
257
                 result |= 2;
 
258
               else if (optarg != NULL)
 
259
                 result |= 4;
 
260
               else if (getopt (4, argv, "p::") != -1)
 
261
                 result |= 6;
 
262
               else if (optind != 2)
 
263
                 result |= 8;
227
264
             }
228
265
             /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0.  */
229
266
             {
230
267
               char *argv[] = { "program", "foo", "-p", NULL };
231
268
               optind = 0;
232
269
               if (getopt (3, argv, "-p") != 1)
233
 
                 return 6;
234
 
               if (getopt (3, argv, "-p") != 'p')
235
 
                 return 7;
236
 
             }
237
 
             return 0;
 
270
                 result |= 16;
 
271
               else if (getopt (3, argv, "-p") != 'p')
 
272
                 result |= 32;
 
273
             }
 
274
             /* This code fails on glibc 2.11.  */
 
275
             {
 
276
               char *argv[] = { "program", "-b", "-a", NULL };
 
277
               optind = opterr = 0;
 
278
               if (getopt (3, argv, "+:a:b") != 'b')
 
279
                 result |= 64;
 
280
               else if (getopt (3, argv, "+:a:b") != ':')
 
281
                 result |= 64;
 
282
             }
 
283
             return result;
238
284
           ]])],
239
285
        [gl_cv_func_getopt_gnu=yes],
240
286
        [gl_cv_func_getopt_gnu=no],
245
291
           *)                   gl_cv_func_getopt_gnu=yes;;
246
292
         esac
247
293
        ])
248
 
       if test "$gl_had_POSIXLY_CORRECT" != yes; then
249
 
         AS_UNSET([POSIXLY_CORRECT])
250
 
       fi
 
294
       case $gl_had_POSIXLY_CORRECT in
 
295
         exported) ;;
 
296
         yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;;
 
297
         *) AS_UNSET([POSIXLY_CORRECT]) ;;
 
298
       esac
251
299
      ])
252
300
    if test "$gl_cv_func_getopt_gnu" = "no"; then
253
301
      gl_replace_getopt=yes