2 # m4-getopt.m4 -- Use the installed version of getopt.h if available.
3 # Written by Gary V. Vaughan <gary@gnu.org>
5 # Copyright (C) 2005, 2006 Free Software Foundation, Inc
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
26 # Use the installed version of getopt.h if available.
31 AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h], [AC_INCLUDES_DEFAULT])
33 if test -z "$GETOPT_H"; then
34 AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
37 dnl BSD getopt_log uses an incompatible method to reset option processing,
38 dnl and (as of 2004-10-15) mishandles optional option-arguments.
39 if test -z "$GETOPT_H"; then
40 AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>])
43 if test -z "$GETOPT_H"; then
44 AC_CACHE_CHECK([for working gnu getopt function], [gl_cv_func_gnu_getopt],
46 [AC_LANG_PROGRAM([#include <getopt.h>],
49 myargv[0] = "conftest";
52 return getopt (2, myargv, "+a") != '?';
54 [gl_cv_func_gnu_getopt=yes],
55 [gl_cv_func_gnu_getopt=no],
56 [dnl cross compiling - pessimistically gues based on decls
57 dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
58 dnl option string (as of 2005-05-05).
59 AC_CHECK_DECL([getopt_clip],
60 [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
61 [#include <getopt.h>])])])
62 test X"$gl_cv_func_gnu_getopt" = Xno && GETOPT_H=getopt.h
65 if test -n "$GETOPT_H"; then
66 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
67 [Define to rpl_ if the getopt replacement function should be used.])
70 AM_CONDITIONAL([GETOPT], [test -n "$GETOPT_H"])