annotate m4/getopt.m4 @ 441:7b8d89435f30 3.0

Fixed error with forced size pcr operands
author lost@l-w.ca
date Sat, 30 Oct 2010 11:51:25 -0600
parents b8bf63962a99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1 # getopt.m4 serial 24
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
2 dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
6
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
7 # Request a POSIX compliant getopt function.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
8 AC_DEFUN([gl_FUNC_GETOPT_POSIX],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
9 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
10 m4_divert_text([DEFAULTS], [gl_getopt_required=POSIX])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
11 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
12 gl_GETOPT_IFELSE([
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
13 gl_REPLACE_GETOPT
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
14 ],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
15 [])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
16 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
17
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
18 # Request a POSIX compliant getopt function with GNU extensions (such as
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
19 # options with optional arguments) and the functions getopt_long,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
20 # getopt_long_only.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
21 AC_DEFUN([gl_FUNC_GETOPT_GNU],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
22 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
23 m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
24
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
25 AC_REQUIRE([gl_FUNC_GETOPT_POSIX])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
26 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
27
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
28 # Request the gnulib implementation of the getopt functions unconditionally.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
29 # argp.m4 uses this.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
30 AC_DEFUN([gl_REPLACE_GETOPT],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
31 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
32 dnl Arrange for getopt.h to be created.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
33 gl_GETOPT_SUBSTITUTE_HEADER
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
34 dnl Arrange for unistd.h to include getopt.h.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
35 GNULIB_UNISTD_H_GETOPT=1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
36 dnl Arrange to compile the getopt implementation.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
37 AC_LIBOBJ([getopt])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
38 AC_LIBOBJ([getopt1])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
39 gl_PREREQ_GETOPT
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
40 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
41
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
42 # emacs' configure.in uses this.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
43 AC_DEFUN([gl_GETOPT_IFELSE],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
44 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
45 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
46 AS_IF([test -n "$gl_replace_getopt"], [$1], [$2])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
47 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
48
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
49 # Determine whether to replace the entire getopt facility.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
50 AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
51 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
52 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
53
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
54 dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
55 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
56
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
57 gl_CHECK_NEXT_HEADERS([getopt.h])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
58 AC_CHECK_HEADERS_ONCE([getopt.h])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
59 if test $ac_cv_header_getopt_h = yes; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
60 HAVE_GETOPT_H=1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
61 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
62 HAVE_GETOPT_H=0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
63 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
64 AC_SUBST([HAVE_GETOPT_H])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
65
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
66 gl_replace_getopt=
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
67
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
68 dnl Test whether <getopt.h> is available.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
69 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
70 AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
71 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
72
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
73 dnl Test whether the function getopt_long is available.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
74 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
75 AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
76 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
77
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
78 dnl BSD getopt_long uses an incompatible method to reset option processing.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
79 dnl Existence of the variable, in and of itself, is not a reason to replace
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
80 dnl getopt, but knowledge of the variable is needed to determine how to
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
81 dnl reset and whether a reset reparses the environment.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
82 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
83 AC_CHECK_DECLS([optreset], [], [],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
84 [[#include <getopt.h>]])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
85 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
86
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
87 dnl mingw's getopt (in libmingwex.a) does weird things when the options
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
88 dnl strings starts with '+' and it's not the first call. Some internal state
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
89 dnl is left over from earlier calls, and neither setting optind = 0 nor
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
90 dnl setting optreset = 1 get rid of this internal state.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
91 dnl POSIX is silent on optind vs. optreset, so we allow either behavior.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
92 if test -z "$gl_replace_getopt"; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
93 AC_CACHE_CHECK([whether getopt is POSIX compatible],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
94 [gl_cv_func_getopt_posix],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
95 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
96 dnl This test fails on mingw and succeeds on all other platforms.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
97 AC_RUN_IFELSE([AC_LANG_SOURCE([[
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
98 #include <unistd.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
99 #include <stdlib.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
100 #include <string.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
101
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
102 #if !HAVE_DECL_OPTRESET
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
103 # define OPTIND_MIN 0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
104 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
105 # define OPTIND_MIN 1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
106 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
107
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
108 int
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
109 main ()
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
110 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
111 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
112 int argc = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
113 char *argv[10];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
114 int c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
115
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
116 argv[argc++] = "program";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
117 argv[argc++] = "-a";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
118 argv[argc++] = "foo";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
119 argv[argc++] = "bar";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
120 argv[argc] = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
121 optind = OPTIND_MIN;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
122 opterr = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
123
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
124 c = getopt (argc, argv, "ab");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
125 if (!(c == 'a'))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
126 return 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
127 c = getopt (argc, argv, "ab");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
128 if (!(c == -1))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
129 return 2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
130 if (!(optind == 2))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
131 return 3;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
132 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
133 /* Some internal state exists at this point. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
134 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
135 int argc = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
136 char *argv[10];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
137 int c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
138
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
139 argv[argc++] = "program";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
140 argv[argc++] = "donald";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
141 argv[argc++] = "-p";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
142 argv[argc++] = "billy";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
143 argv[argc++] = "duck";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
144 argv[argc++] = "-a";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
145 argv[argc++] = "bar";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
146 argv[argc] = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
147 optind = OPTIND_MIN;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
148 opterr = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
149
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
150 c = getopt (argc, argv, "+abp:q:");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
151 if (!(c == -1))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
152 return 4;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
153 if (!(strcmp (argv[0], "program") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
154 return 5;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
155 if (!(strcmp (argv[1], "donald") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
156 return 6;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
157 if (!(strcmp (argv[2], "-p") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
158 return 7;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
159 if (!(strcmp (argv[3], "billy") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
160 return 8;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
161 if (!(strcmp (argv[4], "duck") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
162 return 9;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
163 if (!(strcmp (argv[5], "-a") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
164 return 10;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
165 if (!(strcmp (argv[6], "bar") == 0))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
166 return 11;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
167 if (!(optind == 1))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
168 return 12;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
169 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
170
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
171 return 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
172 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
173 ]])],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
174 [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
175 [case "$host_os" in
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
176 mingw*) gl_cv_func_getopt_posix="guessing no";;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
177 *) gl_cv_func_getopt_posix="guessing yes";;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
178 esac
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
179 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
180 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
181 case "$gl_cv_func_getopt_posix" in
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
182 *no) gl_replace_getopt=yes ;;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
183 esac
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
184 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
185
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
186 if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
187 AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_getopt_gnu],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
188 [# Even with POSIXLY_CORRECT, the GNU extension of leading '-' in the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
189 # optstring is necessary for programs like m4 that have POSIX-mandated
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
190 # semantics for supporting options interspersed with files.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
191 # Also, since getopt_long is a GNU extension, we require optind=0.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
192 gl_had_POSIXLY_CORRECT=${POSIXLY_CORRECT:+yes}
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
193 POSIXLY_CORRECT=1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
194 export POSIXLY_CORRECT
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
195 AC_RUN_IFELSE(
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
196 [AC_LANG_PROGRAM([[#include <getopt.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
197 #include <stddef.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
198 #include <string.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
199 ]], [[
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
200 /* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
201 and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
202 OSF/1 5.1, Solaris 10. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
203 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
204 char *myargv[3];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
205 myargv[0] = "conftest";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
206 myargv[1] = "-+";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
207 myargv[2] = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
208 opterr = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
209 if (getopt (2, myargv, "+a") != '?')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
210 return 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
211 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
212 /* This code succeeds on glibc 2.8, mingw,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
213 and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
214 IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
215 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
216 char *argv[] = { "program", "-p", "foo", "bar", NULL };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
217
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
218 optind = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
219 if (getopt (4, argv, "p::") != 'p')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
220 return 2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
221 if (optarg != NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
222 return 3;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
223 if (getopt (4, argv, "p::") != -1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
224 return 4;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
225 if (optind != 2)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
226 return 5;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
227 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
228 /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
229 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
230 char *argv[] = { "program", "foo", "-p", NULL };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
231 optind = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
232 if (getopt (3, argv, "-p") != 1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
233 return 6;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
234 if (getopt (3, argv, "-p") != 'p')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
235 return 7;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
236 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
237 return 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
238 ]])],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
239 [gl_cv_func_getopt_gnu=yes],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
240 [gl_cv_func_getopt_gnu=no],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
241 [dnl Cross compiling. Guess based on host and declarations.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
242 case $host_os:$ac_cv_have_decl_optreset in
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
243 *-gnu*:* | mingw*:*) gl_cv_func_getopt_gnu=no;;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
244 *:yes) gl_cv_func_getopt_gnu=no;;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
245 *) gl_cv_func_getopt_gnu=yes;;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
246 esac
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
247 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
248 if test "$gl_had_POSIXLY_CORRECT" != yes; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
249 AS_UNSET([POSIXLY_CORRECT])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
250 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
251 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
252 if test "$gl_cv_func_getopt_gnu" = "no"; then
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
253 gl_replace_getopt=yes
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
254 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
255 fi
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
256 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
257
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
258 # emacs' configure.in uses this.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
259 AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
260 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
261 GETOPT_H=getopt.h
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
262 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
263 [Define to rpl_ if the getopt replacement functions and variables
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
264 should be used.])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
265 AC_SUBST([GETOPT_H])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
266 ])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
267
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
268 # Prerequisites of lib/getopt*.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
269 # emacs' configure.in uses this.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
270 AC_DEFUN([gl_PREREQ_GETOPT],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
271 [
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
272 AC_CHECK_DECLS_ONCE([getenv])
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
273 ])