annotate m4/getopt.m4 @ 6587:453776fca04b

Work around porting bugs reported by Dieter in <http://lists.gnu.org/archive/html/bug-bison/2006-01/msg00049.html>. * lib/getopt.c (_NOPROTO): Remove; no longer needed. Include <stdlib.h> and <unistd.h> in all environments; it's safe now. Include "getopt.h" first, to check interface. (getenv): Declare only if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV. * lib/strndup.c [!_LIBC]: Include "strndup.h" to get prototype. (__strndup): Revert to K&R-style function dfns, the glibc style. * lib/strnlen.c: Don't claim it's taken from glibc; it's not. (strnlen, __strnlen): Remove #defines and #undefs; not needed. Include strnlen.h first, to get prototype properly. (strnlen): Renamed from __strnlen. Remove weak alias. * m4/getopt.m4 (gl_PREREQ_GETOPT): Check for getenv decl.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 24 Jan 2006 07:40:58 +0000
parents 29087842aa86
children c34c3fd8f414
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6587
453776fca04b Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents: 6052
diff changeset
1 # getopt.m4 serial 12
453776fca04b Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents: 6052
diff changeset
2 dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5611
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5478
diff changeset
3 dnl This file is free software; the Free Software Foundation
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5478
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
87c42e194f4a Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5478
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
4107
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6
5193
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
7 # The getopt module assume you want GNU getopt, with getopt_long etc,
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
8 # rather than vanilla POSIX getopt. This means your your code should
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
9 # always include <getopt.h> for the getopt prototypes.
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
10
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
11 AC_DEFUN([gl_GETOPT_SUBSTITUTE],
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
12 [
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
13 AC_LIBOBJ([getopt])
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
14 AC_LIBOBJ([getopt1])
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
15 gl_GETOPT_SUBSTITUTE_HEADER
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
16 gl_PREREQ_GETOPT
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
17 ])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
18
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
19 AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
20 [
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
21 GETOPT_H=getopt.h
5427
e314bbc551bf (gl_GETOPT_SUBSTITUTE): Define __GETOPT_PREFIX instead
Paul Eggert <eggert@cs.ucla.edu>
parents: 5423
diff changeset
22 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
e314bbc551bf (gl_GETOPT_SUBSTITUTE): Define __GETOPT_PREFIX instead
Paul Eggert <eggert@cs.ucla.edu>
parents: 5423
diff changeset
23 [Define to rpl_ if the getopt replacement functions and variables
e314bbc551bf (gl_GETOPT_SUBSTITUTE): Define __GETOPT_PREFIX instead
Paul Eggert <eggert@cs.ucla.edu>
parents: 5423
diff changeset
24 should be used.])
5193
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
25 AC_SUBST([GETOPT_H])
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
26 ])
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
27
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
28 AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
4107
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 [
6052
29087842aa86 * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Do not override the results
Paul Eggert <eggert@cs.ucla.edu>
parents: 6007
diff changeset
30 if test -z "$GETOPT_H"; then
29087842aa86 * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Do not override the results
Paul Eggert <eggert@cs.ucla.edu>
parents: 6007
diff changeset
31 AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h])
29087842aa86 * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Do not override the results
Paul Eggert <eggert@cs.ucla.edu>
parents: 6007
diff changeset
32 fi
29087842aa86 * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Do not override the results
Paul Eggert <eggert@cs.ucla.edu>
parents: 6007
diff changeset
33
5478
fca5a7f08a72 (gl_GETOPT): Check if GETOPT_H is already set, in
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 5427
diff changeset
34 if test -z "$GETOPT_H"; then
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
35 AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
36 fi
5193
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
37
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
38 dnl BSD getopt_long uses an incompatible method to reset option processing,
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
39 dnl and (as of 2004-10-15) mishandles optional option-arguments.
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
40 if test -z "$GETOPT_H"; then
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
41 AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
42 fi
5819
16b0f8ffe787 * getopt.m4 (gl_GETOPT): Check for Solaris 10 getopt, and avoid
Paul Eggert <eggert@cs.ucla.edu>
parents: 5611
diff changeset
43
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
44 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
45 dnl option string (as of 2005-05-05).
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
46 if test -z "$GETOPT_H"; then
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
47 AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt],
5838
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
48 [AC_RUN_IFELSE(
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
49 [AC_LANG_PROGRAM([#include <getopt.h>],
5838
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
50 [[
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
51 char *myargv[3];
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
52 myargv[0] = "conftest";
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
53 myargv[1] = "-+";
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
54 myargv[2] = 0;
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
55 return getopt (2, myargv, "+a") != '?';
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
56 ]])],
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
57 [gl_cv_func_gnu_getopt=yes],
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
58 [gl_cv_func_gnu_getopt=no],
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
59 [dnl cross compiling - pessimistically guess based on decls
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
60 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
61 dnl option string (as of 2005-05-05).
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
62 AC_CHECK_DECL([getopt_clip],
5838
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
63 [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
dcdcb5e92aa2 * getopt.m4 (gl_GETOPT): Check for Solaris 10 bug, not decl, when
Paul Eggert <eggert@cs.ucla.edu>
parents: 5819
diff changeset
64 [#include <getopt.h>])])])
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
65 if test "$gl_cv_func_gnu_getopt" = "no"; then
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
66 GETOPT_H=getopt.h
5478
fca5a7f08a72 (gl_GETOPT): Check if GETOPT_H is already set, in
Sergey Poznyakoff <gray@gnu.org.ua>
parents: 5427
diff changeset
67 fi
5193
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
68 fi
4107
7c1a6b73f48e An autoconf macro for its associated module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 ])
5193
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
70
6007
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
71 AC_DEFUN([gl_GETOPT_IFELSE],
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
72 [
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
73 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
74 AS_IF([test -n "$GETOPT_H"], [$1], [$2])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
75 ])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
76
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
77 AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
5b580599ba01 Add support to getopt for Emacs, which doesn't use LIBOBJS in the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5838
diff changeset
78
5193
f9f7d9ea394a (gl_GETOPT_SUBSTITUTE, gl_PREREQ_GETOPT): New macros.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4653
diff changeset
79 # Prerequisites of lib/getopt*.
6587
453776fca04b Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents: 6052
diff changeset
80 AC_DEFUN([gl_PREREQ_GETOPT],
453776fca04b Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents: 6052
diff changeset
81 [
453776fca04b Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents: 6052
diff changeset
82 AC_CHECK_DECLS_ONCE([getenv])
453776fca04b Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents: 6052
diff changeset
83 ])