getopt.m4 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # getopt.m4 serial 14
  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. # The getopt module assume you want GNU getopt, with getopt_long etc,
  7. # rather than vanilla POSIX getopt. This means your code should
  8. # always include <getopt.h> for the getopt prototypes.
  9. AC_DEFUN([gl_GETOPT_SUBSTITUTE],
  10. [
  11. AC_LIBOBJ([getopt])
  12. AC_LIBOBJ([getopt1])
  13. gl_GETOPT_SUBSTITUTE_HEADER
  14. gl_PREREQ_GETOPT
  15. ])
  16. AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
  17. [
  18. GETOPT_H=getopt.h
  19. AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
  20. [Define to rpl_ if the getopt replacement functions and variables
  21. should be used.])
  22. AC_SUBST([GETOPT_H])
  23. ])
  24. AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
  25. [
  26. if test -z "$GETOPT_H"; then
  27. AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h])
  28. fi
  29. if test -z "$GETOPT_H"; then
  30. AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
  31. fi
  32. dnl BSD getopt_long uses an incompatible method to reset option processing,
  33. dnl and (as of 2004-10-15) mishandles optional option-arguments.
  34. if test -z "$GETOPT_H"; then
  35. AC_CHECK_DECL([optreset], [GETOPT_H=getopt.h], [], [#include <getopt.h>])
  36. fi
  37. dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
  38. dnl option string (as of 2005-05-05).
  39. if test -z "$GETOPT_H"; then
  40. AC_CACHE_CHECK([for working GNU getopt function], [gl_cv_func_gnu_getopt],
  41. [AC_RUN_IFELSE(
  42. [AC_LANG_PROGRAM([[#include <getopt.h>]],
  43. [[
  44. char *myargv[3];
  45. myargv[0] = "conftest";
  46. myargv[1] = "-+";
  47. myargv[2] = 0;
  48. return getopt (2, myargv, "+a") != '?';
  49. ]])],
  50. [gl_cv_func_gnu_getopt=yes],
  51. [gl_cv_func_gnu_getopt=no],
  52. [dnl cross compiling - pessimistically guess based on decls
  53. dnl Solaris 10 getopt doesn't handle `+' as a leading character in an
  54. dnl option string (as of 2005-05-05).
  55. AC_CHECK_DECL([getopt_clip],
  56. [gl_cv_func_gnu_getopt=no], [gl_cv_func_gnu_getopt=yes],
  57. [#include <getopt.h>])])])
  58. if test "$gl_cv_func_gnu_getopt" = "no"; then
  59. GETOPT_H=getopt.h
  60. fi
  61. fi
  62. ])
  63. AC_DEFUN([gl_GETOPT_IFELSE],
  64. [
  65. AC_REQUIRE([gl_GETOPT_CHECK_HEADERS])
  66. AS_IF([test -n "$GETOPT_H"], [$1], [$2])
  67. ])
  68. AC_DEFUN([gl_GETOPT], [gl_GETOPT_IFELSE([gl_GETOPT_SUBSTITUTE])])
  69. # Prerequisites of lib/getopt*.
  70. AC_DEFUN([gl_PREREQ_GETOPT],
  71. [
  72. AC_CHECK_DECLS_ONCE([getenv])
  73. ])