dpkg-funcs.m4 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # Copyright © 2005 Scott James Remnant <scott@netsplit.com>
  2. # Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
  3. # DPKG_FUNC_VA_COPY
  4. # -----------------
  5. # Define HAVE_VA_COPY if we have va_copy, fail if they can't be assigned
  6. AC_DEFUN([DPKG_FUNC_VA_COPY],
  7. [AC_CACHE_CHECK([for va_copy], [dpkg_cv_va_copy],
  8. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  9. [[#include <stdarg.h>
  10. int main()
  11. {
  12. va_list v1, v2;
  13. va_copy (v1, v2);
  14. exit (0);
  15. }
  16. ]])],
  17. [dpkg_cv_va_copy=yes],
  18. [dpkg_cv_va_copy=no],
  19. [dpkg_cv_va_copy=no])])
  20. AS_IF([test "x$dpkg_cv_va_copy" = "xyes"],
  21. [AC_DEFINE([HAVE_VA_COPY], 1,
  22. [Define to 1 if the 'va_copy' macro exists])])
  23. ])# DPKG_FUNC_VA_COPY
  24. # DPKG_FUNC_C99_SNPRINTF
  25. # -----------------------
  26. # Define HAVE_C99_SNPRINTF if we have C99 snprintf family semantics
  27. AC_DEFUN([DPKG_FUNC_C99_SNPRINTF],
  28. [AC_CACHE_CHECK([for C99 snprintf functions], [dpkg_cv_c99_snprintf],
  29. [AC_RUN_IFELSE([AC_LANG_SOURCE([[
  30. #include <stdarg.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. int test_vsnprintf(const char *fmt, ...)
  34. {
  35. int n;
  36. va_list args;
  37. va_start(args, fmt);
  38. n = vsnprintf(NULL, 0, fmt, args);
  39. va_end(args);
  40. return n;
  41. }
  42. int main()
  43. {
  44. int n;
  45. n = snprintf(NULL, 0, "format %s %d", "string", 10);
  46. if (n != strlen("format string 10"))
  47. return 1;
  48. n = test_vsnprintf("format %s %d", "string", 10);
  49. if (n != strlen("format string 10"))
  50. return 1;
  51. return 0;
  52. }
  53. ]])],
  54. [dpkg_cv_c99_snprintf=yes],
  55. [dpkg_cv_c99_snprintf=no],
  56. [dpkg_cv_c99_snprintf=no])])
  57. AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"],
  58. [AC_DEFINE([HAVE_C99_SNPRINTF], 1,
  59. [Define to 1 if the 'snprintf' family is C99 conformant])],
  60. )
  61. AM_CONDITIONAL(HAVE_C99_SNPRINTF, [test "x$dpkg_cv_c99_snprintf" = "xyes"])
  62. ])# DPKG_FUNC_C99_SNPRINTF
  63. # DPKG_MMAP
  64. # ---------
  65. # Define USE_MMAP if mmap() is available and it was requested
  66. AC_DEFUN([DPKG_MMAP],
  67. [
  68. AC_ARG_ENABLE([mmap],
  69. AS_HELP_STRING([--enable-mmap],
  70. [enable usage of unrealiable mmap if available]),
  71. [],
  72. [enable_mmap=no])
  73. AS_IF([test "x$enable_mmap" = "xyes"], [
  74. AC_CHECK_FUNCS([mmap])
  75. AC_DEFINE(USE_MMAP, 1, [Use unreliable mmap support])
  76. ])
  77. ])
  78. # DPKG_CHECK_PROGNAME
  79. # -------------------
  80. # Check for system implementations of program name tracking.
  81. AC_DEFUN([DPKG_CHECK_PROGNAME],
  82. [
  83. AC_MSG_CHECKING([for program_invocation_short_name])
  84. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <errno.h>]],
  85. [[const char *p = program_invocation_short_name;]])],
  86. [AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
  87. [Define to 1 if you have program_invocation_short_name])
  88. AC_MSG_RESULT([yes])],
  89. [AC_MSG_RESULT([no])])
  90. AC_MSG_CHECKING([for __progname])
  91. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  92. [[extern char *__progname;
  93. const char *p = __progname;]])],
  94. [AC_DEFINE([HAVE___PROGNAME], [1],
  95. [Define to 1 if you have __progname])
  96. AC_MSG_RESULT([yes])],
  97. [AC_MSG_RESULT([no])])
  98. ]) # DPKG_CHECK_PROGNAME
  99. # DPKG_CHECK_COMPAT_FUNCS(LIST)
  100. # -----------------------
  101. # Check each function and define an automake conditional
  102. AC_DEFUN([DPKG_CHECK_COMPAT_FUNCS],
  103. [
  104. AC_CHECK_FUNCS([$1])
  105. m4_foreach_w([ac_func], [$1], [
  106. AM_CONDITIONAL(HAVE_[]AS_TR_CPP(ac_func),
  107. [test "x$ac_cv_func_[]AS_TR_SH(ac_func)" = "xyes"])
  108. ])
  109. ]) # DPKG_CHECK_COMPAT_FUNCS