]> icculus.org git repositories - icculus/xz.git/blob - m4/getopt.m4
Cleanups to the code that detects the amount of RAM and
[icculus/xz.git] / m4 / getopt.m4
1 # getopt.m4 serial 14 (modified version)
2 dnl Copyright (C) 2002-2006, 2008 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.
6
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.
10
11 AC_DEFUN([gl_GETOPT_SUBSTITUTE],
12 [
13   AC_LIBOBJ([getopt])
14   AC_LIBOBJ([getopt1])
15   gl_GETOPT_SUBSTITUTE_HEADER
16 ])
17
18 AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
19 [
20   GETOPT_H=getopt.h
21   AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
22     [Define to rpl_ if the getopt replacement functions and variables
23      should be used.])
24   AC_SUBST([GETOPT_H])
25 ])
26
27 AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
28 [
29   if test -z "$GETOPT_H"; then
30     AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h])
31   fi
32
33   dnl BSD getopt_long uses a way to reset option processing, that is different
34   dnl from GNU and Solaris (which copied the GNU behavior). We support both
35   dnl GNU and BSD style resetting of getopt_long(), so there's no need to use
36   dnl GNU getopt_long() on BSD due to different resetting style.
37   dnl
38   dnl With getopt_long(), some BSD versions have a bug in handling optional
39   dnl arguments. This bug appears only if the environment variable
40   dnl POSIXLY_CORRECT has been set, so it shouldn't be too bad in most
41   dnl cases; probably most don't have that variable set. But if we actually
42   dnl hit this bug, it is a real problem due to our heavy use of optional
43   dnl arguments.
44   dnl
45   dnl According to CVS logs, the bug was introduced in OpenBSD in 2003-09-22
46   dnl and copied to FreeBSD in 2004-02-24. It was fixed in both in 2006-09-22,
47   dnl so the affected versions shouldn't be popular anymore anyway. NetBSD
48   dnl never had this bug. TODO: What about Darwin and others?
49   if test -z "$GETOPT_H"; then
50     AC_CHECK_DECL([optreset],
51       [AC_DEFINE([HAVE_OPTRESET], 1,
52         [Define to 1 if getopt.h declares extern int optreset.])],
53       [], [#include <getopt.h>])
54   fi
55
56   dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
57   dnl option string (as of 2005-05-05). We don't use that feature, so this
58   dnl is not a problem for us. Thus, the respective test was removed here.
59 ])
60
61 AC_DEFUN([gl_GETOPT_IFELSE],
62 [
63   AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
64   AS_IF([test -n "$GETOPT_H"], [$1], [$2])
65 ])
66
67 AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])