dpkg-funcs.m4 3.7 KB

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