~ubuntu-branches/ubuntu/precise/wget/precise-proposed

« back to all changes in this revision

Viewing changes to m4/getopt.m4

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-10-19 00:00:09 UTC
  • mfrom: (2.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20111019000009-8p33w3wz4b1rdri0
Tags: 1.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
  - Depend on libssl-dev 0.9.8k-7ubuntu4 (LP: #503339)
* Dropped changes, superseded in Debian:
  - Keep build dependencies in main:
    + debian/control: remove info2man build-dep
    + debian/patches/series: disable wget-infopod_generated_manpage
  - Mark wget Multi-Arch: foreign, so packages that aren't of the same arch
    can depend on it.
* Pass --with-ssl=openssl; we don't want to use gnutls, there's no udeb for
  it.
* Add a second build pass for the udeb, so we can build without libidn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# getopt.m4 serial 21
2
 
dnl Copyright (C) 2002-2006, 2008-2009 Free Software Foundation, Inc.
 
1
# getopt.m4 serial 38
 
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.
9
9
[
10
10
  m4_divert_text([DEFAULTS], [gl_getopt_required=POSIX])
11
11
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12
 
  gl_GETOPT_IFELSE([
13
 
    gl_REPLACE_GETOPT
14
 
  ],
15
 
  [])
 
12
  dnl Other modules can request the gnulib implementation of the getopt
 
13
  dnl functions unconditionally, by defining gl_REPLACE_GETOPT_ALWAYS.
 
14
  dnl argp.m4 does this.
 
15
  m4_ifdef([gl_REPLACE_GETOPT_ALWAYS], [
 
16
    gl_GETOPT_IFELSE([], [])
 
17
    REPLACE_GETOPT=1
 
18
  ], [
 
19
    REPLACE_GETOPT=0
 
20
    gl_GETOPT_IFELSE([
 
21
      REPLACE_GETOPT=1
 
22
    ],
 
23
    [])
 
24
  ])
 
25
  if test $REPLACE_GETOPT = 1; then
 
26
    dnl Arrange for getopt.h to be created.
 
27
    gl_GETOPT_SUBSTITUTE_HEADER
 
28
    dnl Arrange for unistd.h to include getopt.h.
 
29
    GNULIB_UNISTD_H_GETOPT=1
 
30
  fi
16
31
])
17
32
 
18
33
# Request a POSIX compliant getopt function with GNU extensions (such as
25
40
  AC_REQUIRE([gl_FUNC_GETOPT_POSIX])
26
41
])
27
42
 
28
 
# Request the gnulib implementation of the getopt functions unconditionally.
29
 
# argp.m4 uses this.
30
 
AC_DEFUN([gl_REPLACE_GETOPT],
31
 
[
32
 
  dnl Arrange for getopt.h to be created.
33
 
  gl_GETOPT_SUBSTITUTE_HEADER
34
 
  dnl Arrange for unistd.h to include getopt.h.
35
 
  GNULIB_UNISTD_H_GETOPT=1
36
 
  dnl Arrange to compile the getopt implementation.
37
 
  AC_LIBOBJ([getopt])
38
 
  AC_LIBOBJ([getopt1])
39
 
  gl_PREREQ_GETOPT
40
 
])
41
 
 
42
43
# emacs' configure.in uses this.
43
44
AC_DEFUN([gl_GETOPT_IFELSE],
44
45
[
50
51
AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
51
52
[
52
53
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
54
  AC_REQUIRE([AC_PROG_AWK]) dnl for awk that supports ENVIRON
53
55
 
54
56
  dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt.
55
57
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
56
58
 
 
59
  gl_CHECK_NEXT_HEADERS([getopt.h])
 
60
  if test $ac_cv_header_getopt_h = yes; then
 
61
    HAVE_GETOPT_H=1
 
62
  else
 
63
    HAVE_GETOPT_H=0
 
64
  fi
 
65
  AC_SUBST([HAVE_GETOPT_H])
 
66
 
57
67
  gl_replace_getopt=
58
68
 
59
69
  dnl Test whether <getopt.h> is available.
66
76
    AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
67
77
  fi
68
78
 
69
 
  dnl BSD getopt_long uses an incompatible method to reset option processing,
70
 
  dnl but the testsuite does not show a need to use this 'optreset' variable.
71
 
  if false && test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
72
 
    AC_CHECK_DECL([optreset], [gl_replace_getopt=yes], [],
73
 
      [#include <getopt.h>])
74
 
  fi
75
 
 
76
79
  dnl mingw's getopt (in libmingwex.a) does weird things when the options
77
80
  dnl strings starts with '+' and it's not the first call.  Some internal state
78
81
  dnl is left over from earlier calls, and neither setting optind = 0 nor
79
82
  dnl setting optreset = 1 get rid of this internal state.
 
83
  dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
 
84
  dnl POSIX 2008 does not specify leading '+' behavior, but see
 
85
  dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on
 
86
  dnl the next version of POSIX.  For now, we only guarantee leading '+'
 
87
  dnl behavior with getopt-gnu.
80
88
  if test -z "$gl_replace_getopt"; then
81
89
    AC_CACHE_CHECK([whether getopt is POSIX compatible],
82
90
      [gl_cv_func_getopt_posix],
83
91
      [
84
 
        dnl This test fails on mingw and succeeds on all other platforms.
85
 
        AC_TRY_RUN([
 
92
        dnl BSD getopt_long uses an incompatible method to reset option
 
93
        dnl processing.  Existence of the optreset variable, in and of
 
94
        dnl itself, is not a reason to replace getopt, but knowledge
 
95
        dnl of the variable is needed to determine how to reset and
 
96
        dnl whether a reset reparses the environment.  Solaris
 
97
        dnl supports neither optreset nor optind=0, but keeps no state
 
98
        dnl that needs a reset beyond setting optind=1; detect Solaris
 
99
        dnl by getopt_clip.
 
100
        AC_LINK_IFELSE(
 
101
          [AC_LANG_PROGRAM(
 
102
             [[#include <unistd.h>]],
 
103
             [[int *p = &optreset; return optreset;]])],
 
104
          [gl_optind_min=1],
 
105
          [AC_COMPILE_IFELSE(
 
106
             [AC_LANG_PROGRAM(
 
107
                [[#include <getopt.h>]],
 
108
                [[return !getopt_clip;]])],
 
109
             [gl_optind_min=1],
 
110
             [gl_optind_min=0])])
 
111
 
 
112
        dnl This test fails on mingw and succeeds on many other platforms.
 
113
        gl_save_CPPFLAGS=$CPPFLAGS
 
114
        CPPFLAGS="$CPPFLAGS -DOPTIND_MIN=$gl_optind_min"
 
115
        AC_RUN_IFELSE([AC_LANG_SOURCE([[
86
116
#include <unistd.h>
87
117
#include <stdlib.h>
88
118
#include <string.h>
89
119
 
90
 
/* The glibc implementation of getopt supports setting optind = 0 as a means
91
 
   of clearing the internal state, but other implementations don't.  */
92
 
#if (__GLIBC__ >= 2)
93
 
# define OPTIND_MIN 0
94
 
#else
95
 
# define OPTIND_MIN 1
96
 
#endif
97
 
 
98
120
int
99
121
main ()
100
122
{
101
123
  {
102
 
    int argc = 0;
103
 
    char *argv[10];
 
124
    static char program[] = "program";
 
125
    static char a[] = "-a";
 
126
    static char foo[] = "foo";
 
127
    static char bar[] = "bar";
 
128
    char *argv[] = { program, a, foo, bar, NULL };
104
129
    int c;
105
130
 
106
 
    argv[argc++] = "program";
107
 
    argv[argc++] = "-a";
108
 
    argv[argc++] = "foo";
109
 
    argv[argc++] = "bar";
110
131
    optind = OPTIND_MIN;
111
132
    opterr = 0;
112
133
 
113
 
    c = getopt (argc, argv, "ab");
 
134
    c = getopt (4, argv, "ab");
114
135
    if (!(c == 'a'))
115
136
      return 1;
116
 
    c = getopt (argc, argv, "ab");
 
137
    c = getopt (4, argv, "ab");
117
138
    if (!(c == -1))
118
139
      return 2;
119
140
    if (!(optind == 2))
121
142
  }
122
143
  /* Some internal state exists at this point.  */
123
144
  {
124
 
    int argc = 0;
125
 
    char *argv[10];
 
145
    static char program[] = "program";
 
146
    static char donald[] = "donald";
 
147
    static char p[] = "-p";
 
148
    static char billy[] = "billy";
 
149
    static char duck[] = "duck";
 
150
    static char a[] = "-a";
 
151
    static char bar[] = "bar";
 
152
    char *argv[] = { program, donald, p, billy, duck, a, bar, NULL };
126
153
    int c;
127
154
 
128
 
    argv[argc++] = "program";
129
 
    argv[argc++] = "donald";
130
 
    argv[argc++] = "-p";
131
 
    argv[argc++] = "billy";
132
 
    argv[argc++] = "duck";
133
 
    argv[argc++] = "-a";
134
 
    argv[argc++] = "bar";
135
155
    optind = OPTIND_MIN;
136
156
    opterr = 0;
137
157
 
138
 
    c = getopt (argc, argv, "+abp:q:");
 
158
    c = getopt (7, argv, "+abp:q:");
139
159
    if (!(c == -1))
140
160
      return 4;
141
161
    if (!(strcmp (argv[0], "program") == 0))
155
175
    if (!(optind == 1))
156
176
      return 12;
157
177
  }
 
178
  /* Detect MacOS 10.5, AIX 7.1 bug.  */
 
179
  {
 
180
    static char program[] = "program";
 
181
    static char ab[] = "-ab";
 
182
    char *argv[3] = { program, ab, NULL };
 
183
    optind = OPTIND_MIN;
 
184
    opterr = 0;
 
185
    if (getopt (2, argv, "ab:") != 'a')
 
186
      return 13;
 
187
    if (getopt (2, argv, "ab:") != '?')
 
188
      return 14;
 
189
    if (optopt != 'b')
 
190
      return 15;
 
191
    if (optind != 2)
 
192
      return 16;
 
193
  }
158
194
 
159
195
  return 0;
160
196
}
161
 
],
 
197
]])],
162
198
          [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no],
163
199
          [case "$host_os" in
164
 
             mingw*) gl_cv_func_getopt_posix="guessing no";;
165
 
             *)      gl_cv_func_getopt_posix="guessing yes";;
 
200
             mingw*)         gl_cv_func_getopt_posix="guessing no";;
 
201
             darwin* | aix*) gl_cv_func_getopt_posix="guessing no";;
 
202
             *)              gl_cv_func_getopt_posix="guessing yes";;
166
203
           esac
167
204
          ])
 
205
        CPPFLAGS=$gl_save_CPPFLAGS
168
206
      ])
169
207
    case "$gl_cv_func_getopt_posix" in
170
208
      *no) gl_replace_getopt=yes ;;
173
211
 
174
212
  if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
175
213
    AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_getopt_gnu],
176
 
      [AC_RUN_IFELSE(
177
 
        [AC_LANG_PROGRAM([[#include <getopt.h>
178
 
                           #include <stddef.h>
179
 
                           #include <string.h>]],
180
 
           [[
 
214
      [# Even with POSIXLY_CORRECT, the GNU extension of leading '-' in the
 
215
       # optstring is necessary for programs like m4 that have POSIX-mandated
 
216
       # semantics for supporting options interspersed with files.
 
217
       # Also, since getopt_long is a GNU extension, we require optind=0.
 
218
       # Bash ties 'set -o posix' to a non-exported POSIXLY_CORRECT;
 
219
       # so take care to revert to the correct (non-)export state.
 
220
dnl GNU Coding Standards currently allow awk but not env; besides, env
 
221
dnl is ambiguous with environment values that contain newlines.
 
222
       gl_awk_probe='BEGIN { if ("POSIXLY_CORRECT" in ENVIRON) print "x" }'
 
223
       case ${POSIXLY_CORRECT+x}`$AWK "$gl_awk_probe" </dev/null` in
 
224
         xx) gl_had_POSIXLY_CORRECT=exported ;;
 
225
         x)  gl_had_POSIXLY_CORRECT=yes      ;;
 
226
         *)  gl_had_POSIXLY_CORRECT=         ;;
 
227
       esac
 
228
       POSIXLY_CORRECT=1
 
229
       export POSIXLY_CORRECT
 
230
       AC_RUN_IFELSE(
 
231
        [AC_LANG_PROGRAM([[#include <getopt.h>
 
232
                           #include <stddef.h>
 
233
                           #include <string.h>
 
234
           ]GL_NOCRASH[
 
235
           ]], [[
 
236
             int result = 0;
 
237
 
 
238
             nocrash_init();
 
239
 
181
240
             /* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw,
182
241
                and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
183
242
                OSF/1 5.1, Solaris 10.  */
184
243
             {
185
 
               char *myargv[3];
186
 
               myargv[0] = "conftest";
187
 
               myargv[1] = "-+";
188
 
               myargv[2] = 0;
 
244
               static char conftest[] = "conftest";
 
245
               static char plus[] = "-+";
 
246
               char *argv[3] = { conftest, plus, NULL };
189
247
               opterr = 0;
190
 
               if (getopt (2, myargv, "+a") != '?')
191
 
                 return 1;
 
248
               if (getopt (2, argv, "+a") != '?')
 
249
                 result |= 1;
192
250
             }
193
251
             /* This code succeeds on glibc 2.8, mingw,
194
252
                and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11,
195
 
                IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin.  */
 
253
                IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x.  */
196
254
             {
197
 
               char *argv[] = { "program", "-p", "foo", "bar" };
 
255
               static char program[] = "program";
 
256
               static char p[] = "-p";
 
257
               static char foo[] = "foo";
 
258
               static char bar[] = "bar";
 
259
               char *argv[] = { program, p, foo, bar, NULL };
198
260
 
199
261
               optind = 1;
200
262
               if (getopt (4, argv, "p::") != 'p')
201
 
                 return 2;
202
 
               if (optarg != NULL)
203
 
                 return 3;
204
 
               if (getopt (4, argv, "p::") != -1)
205
 
                 return 4;
206
 
               if (optind != 2)
207
 
                 return 5;
208
 
             }
209
 
             return 0;
210
 
           ]])],
211
 
        [gl_cv_func_getopt_gnu=yes],
212
 
        [gl_cv_func_getopt_gnu=no],
213
 
        [dnl Cross compiling. Guess based on host and declarations.
214
 
         case "$host_os" in
215
 
           *-gnu* | mingw*) gl_cv_func_getopt_gnu=no;;
216
 
           *)               gl_cv_func_getopt_gnu=yes;;
 
263
                 result |= 2;
 
264
               else if (optarg != NULL)
 
265
                 result |= 4;
 
266
               else if (getopt (4, argv, "p::") != -1)
 
267
                 result |= 6;
 
268
               else if (optind != 2)
 
269
                 result |= 8;
 
270
             }
 
271
             /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0.  */
 
272
             {
 
273
               static char program[] = "program";
 
274
               static char foo[] = "foo";
 
275
               static char p[] = "-p";
 
276
               char *argv[] = { program, foo, p, NULL };
 
277
               optind = 0;
 
278
               if (getopt (3, argv, "-p") != 1)
 
279
                 result |= 16;
 
280
               else if (getopt (3, argv, "-p") != 'p')
 
281
                 result |= 32;
 
282
             }
 
283
             /* This code fails on glibc 2.11.  */
 
284
             {
 
285
               static char program[] = "program";
 
286
               static char b[] = "-b";
 
287
               static char a[] = "-a";
 
288
               char *argv[] = { program, b, a, NULL };
 
289
               optind = opterr = 0;
 
290
               if (getopt (3, argv, "+:a:b") != 'b')
 
291
                 result |= 64;
 
292
               else if (getopt (3, argv, "+:a:b") != ':')
 
293
                 result |= 64;
 
294
             }
 
295
             /* This code dumps core on glibc 2.14.  */
 
296
             {
 
297
               static char program[] = "program";
 
298
               static char w[] = "-W";
 
299
               static char dummy[] = "dummy";
 
300
               char *argv[] = { program, w, dummy, NULL };
 
301
               optind = opterr = 1;
 
302
               if (getopt (3, argv, "W;") != 'W')
 
303
                 result |= 128;
 
304
             }
 
305
             return result;
 
306
           ]])],
 
307
        [gl_cv_func_getopt_gnu=yes],
 
308
        [gl_cv_func_getopt_gnu=no],
 
309
        [dnl Cross compiling. Guess based on host and declarations.
 
310
         case $host_os:$ac_cv_have_decl_optreset in
 
311
           *-gnu*:* | mingw*:*) gl_cv_func_getopt_gnu=no;;
 
312
           *:yes)               gl_cv_func_getopt_gnu=no;;
 
313
           *)                   gl_cv_func_getopt_gnu=yes;;
217
314
         esac
218
315
        ])
 
316
       case $gl_had_POSIXLY_CORRECT in
 
317
         exported) ;;
 
318
         yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;;
 
319
         *) AS_UNSET([POSIXLY_CORRECT]) ;;
 
320
       esac
219
321
      ])
220
322
    if test "$gl_cv_func_getopt_gnu" = "no"; then
221
323
      gl_replace_getopt=yes