summaryrefslogtreecommitdiff
path: root/ltdl/m4/m4-getopt.m4
blob: a58764ec2948b4b90d8eb723c85dc85990499553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#                                                            -*- Autoconf -*-
# m4-getopt.m4 -- Use the installed version of getopt.h if available.
# Written by Gary V. Vaughan <gary@gnu.org>
#
# Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc
#
# This file is part of GNU M4.
#
# GNU M4 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNU M4 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# serial 2

# M4_GETOPT
# ---------
# Use the installed version of getopt.h if available.
AC_DEFUN([M4_GETOPT],
[GETOPT_H=
AC_SUBST([GETOPT_H])

AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h], [AC_INCLUDES_DEFAULT])

if test -z "$GETOPT_H"; then
  AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
fi

dnl BSD getopt_log uses an incompatible method to reset option processing,
dnl and (as of 2004-10-15) mishandles optional option-arguments.
if test -z "$GETOPT_H"; then
  AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>])
fi

if test -z "$GETOPT_H"; then
  AC_CACHE_CHECK([for working gnu getopt function], [gl_cv_func_gnu_getopt],
    [AC_RUN_IFELSE(
      [AC_LANG_PROGRAM([#include <getopt.h>],
	[[
	  char *myargv[3];
	  myargv[0] = "conftest";
	  myargv[1] = "-+";
	  myargv[2] = 0;
	  return getopt (2, myargv, "+a") != '?';
	]])],
      [gl_cv_func_gnu_getopt=yes],
      [gl_cv_func_gnu_getopt=no],
      [dnl cross compiling - pessimistically gues based on decls
       dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
       dnl option string (as of 2005-05-05).
       AC_CHECK_DECL([getopt_clip],
	 [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
	 [#include <getopt.h>])])])
  test X"$gl_cv_func_gnu_getopt" = Xno && GETOPT_H=getopt.h
fi

if test -n "$GETOPT_H"; then
  AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
    [Define to rpl_ if the getopt replacement function should be used.])
fi

AM_CONDITIONAL([GETOPT], [test -n "$GETOPT_H"])
])# M4_GETOPT