2 dnl Copyright (C) 2002-2006, 2008-2009 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 # The getopt module assume you want GNU getopt, with getopt_long etc,
8 # rather than vanilla POSIX getopt. This means your code should
9 # always include <getopt.h> for the getopt prototypes.
11 # This is gnulib's entry-point.
14 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
20 # Request the gnulib implementation of the getopt functions unconditionally.
22 AC_DEFUN([gl_REPLACE_GETOPT],
24 dnl Arrange for getopt.h to be created.
25 gl_GETOPT_SUBSTITUTE_HEADER
26 dnl Arrange for unistd.h to include getopt.h.
27 GNULIB_UNISTD_H_GETOPT=1
28 dnl Arrange to compile the getopt implementation.
34 # emacs' configure.in uses this.
35 AC_DEFUN([gl_GETOPT_IFELSE],
37 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
38 AS_IF([test -n "$gl_replace_getopt"], [$1], [$2])
41 # Determine whether to replace the entire getopt facility.
42 AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
45 if test -z "$gl_replace_getopt"; then
46 AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes])
49 if test -z "$gl_replace_getopt"; then
50 AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
53 dnl BSD getopt_long uses an incompatible method to reset option processing,
54 dnl and (as of 2004-10-15) mishandles optional option-arguments.
55 if test -z "$gl_replace_getopt"; then
56 AC_CHECK_DECL([optreset], [gl_replace_getopt=yes], [],
57 [#include <getopt.h>])
60 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
61 dnl option string (as of 2005-05-05).
62 if test -z "$gl_replace_getopt"; then
63 AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt],
65 [AC_LANG_PROGRAM([[#include <getopt.h>]],
68 myargv[0] = "conftest";
71 return getopt (2, myargv, "+a") != '?';
73 [gl_cv_func_gnu_getopt=yes],
74 [gl_cv_func_gnu_getopt=no],
75 [dnl cross compiling - pessimistically guess based on decls
76 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
77 dnl option string (as of 2005-05-05).
78 AC_CHECK_DECL([getopt_clip],
79 [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
80 [#include <getopt.h>])])])
81 if test "$gl_cv_func_gnu_getopt" = "no"; then
87 # emacs' configure.in uses this.
88 AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
91 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
92 [Define to rpl_ if the getopt replacement functions and variables
97 # Prerequisites of lib/getopt*.
98 # emacs' configure.in uses this.
99 AC_DEFUN([gl_PREREQ_GETOPT],
101 AC_CHECK_DECLS_ONCE([getenv])