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 AC_DEFUN([gl_GETOPT_SUBSTITUTE],
15 gl_GETOPT_SUBSTITUTE_HEADER
19 # emacs' configure.in uses this.
20 AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
23 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
24 [Define to rpl_ if the getopt replacement functions and variables
29 AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
32 if test -z "$gl_replace_getopt"; then
33 AC_CHECK_HEADERS([getopt.h], [], [gl_replace_getopt=yes])
36 if test -z "$gl_replace_getopt"; then
37 AC_CHECK_FUNCS([getopt_long_only], [], [gl_replace_getopt=yes])
40 dnl BSD getopt_long uses an incompatible method to reset option processing,
41 dnl and (as of 2004-10-15) mishandles optional option-arguments.
42 if test -z "$gl_replace_getopt"; then
43 AC_CHECK_DECL([optreset], [gl_replace_getopt=yes], [],
44 [#include <getopt.h>])
47 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
48 dnl option string (as of 2005-05-05).
49 if test -z "$gl_replace_getopt"; then
50 AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt],
52 [AC_LANG_PROGRAM([[#include <getopt.h>]],
55 myargv[0] = "conftest";
58 return getopt (2, myargv, "+a") != '?';
60 [gl_cv_func_gnu_getopt=yes],
61 [gl_cv_func_gnu_getopt=no],
62 [dnl cross compiling - pessimistically guess based on decls
63 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
64 dnl option string (as of 2005-05-05).
65 AC_CHECK_DECL([getopt_clip],
66 [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
67 [#include <getopt.h>])])])
68 if test "$gl_cv_func_gnu_getopt" = "no"; then
74 # emacs' configure.in uses this.
75 AC_DEFUN([gl_GETOPT_IFELSE],
77 AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
78 AS_IF([test -n "$gl_replace_getopt"], [$1], [$2])
81 # This is gnulib's entry-point.
82 AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
84 # Prerequisites of lib/getopt*.
85 # emacs' configure.in uses this.
86 AC_DEFUN([gl_PREREQ_GETOPT],
88 AC_CHECK_DECLS_ONCE([getenv])