dpkg-funcs.m4 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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([
  9. AC_LANG_PROGRAM([[
  10. #include <stdarg.h>
  11. ]], [[
  12. va_list v1, v2;
  13. va_copy(v1, v2);
  14. ]])
  15. ], [
  16. dpkg_cv_va_copy=yes
  17. ], [
  18. dpkg_cv_va_copy=no
  19. ])
  20. ])
  21. AS_IF([test "x$dpkg_cv_va_copy" = "xyes"], [
  22. AC_DEFINE([HAVE_VA_COPY], [1], [Define to 1 if the 'va_copy' macro exists])
  23. ])
  24. ])# DPKG_FUNC_VA_COPY
  25. # DPKG_FUNC_C99_SNPRINTF
  26. # -----------------------
  27. # Define HAVE_C99_SNPRINTF if we have C99 snprintf family semantics
  28. AC_DEFUN([DPKG_FUNC_C99_SNPRINTF], [
  29. AC_CACHE_CHECK([for C99 snprintf functions], [dpkg_cv_c99_snprintf], [
  30. AC_RUN_IFELSE([
  31. AC_LANG_SOURCE([[
  32. #include <stdarg.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35. int test_vsnprintf(const char *fmt, ...)
  36. {
  37. int n;
  38. va_list args;
  39. va_start(args, fmt);
  40. n = vsnprintf(NULL, 0, fmt, args);
  41. va_end(args);
  42. return n;
  43. }
  44. int main()
  45. {
  46. int n;
  47. n = snprintf(NULL, 0, "format %s %d", "string", 10);
  48. if (n != strlen("format string 10"))
  49. return 1;
  50. n = test_vsnprintf("format %s %d", "string", 10);
  51. if (n != strlen("format string 10"))
  52. return 1;
  53. return 0;
  54. }
  55. ]])
  56. ], [
  57. dpkg_cv_c99_snprintf=yes
  58. ], [
  59. dpkg_cv_c99_snprintf=no
  60. ], [
  61. dpkg_cv_c99_snprintf=maybe
  62. ])
  63. AS_IF([test "x$dpkg_cv_c99_snprintf" = "xmaybe"], [
  64. AC_COMPILE_IFELSE([
  65. AC_LANG_SOURCE([[
  66. #define _GNU_SOURCE 1
  67. #include <unistd.h>
  68. #if !defined(_XOPEN_VERSION) || _XOPEN_VERSION < 600
  69. #error "snprintf() has conflicting semantics with C99 on SUSv2 and earlier"
  70. #endif
  71. ]])
  72. ], [
  73. dpkg_cv_c99_snprintf=yes
  74. ], [
  75. dpkg_cv_c99_snprintf=no
  76. ])
  77. ])
  78. ])
  79. AS_IF([test "x$dpkg_cv_c99_snprintf" = "xyes"], [
  80. AC_DEFINE([HAVE_C99_SNPRINTF], [1],
  81. [Define to 1 if the 'snprintf' family is C99 conformant])
  82. ])
  83. AM_CONDITIONAL([HAVE_C99_SNPRINTF], [test "x$dpkg_cv_c99_snprintf" = "xyes"])
  84. ])# DPKG_FUNC_C99_SNPRINTF
  85. # DPKG_USE_MMAP
  86. # -------------
  87. # Define USE_MMAP if mmap() is available and it was requested
  88. AC_DEFUN([DPKG_USE_MMAP], [
  89. AC_ARG_ENABLE([mmap],
  90. [AS_HELP_STRING([--enable-mmap],
  91. [enable usage of unrealiable mmap if available])],
  92. [], [enable_mmap=no])
  93. AS_IF([test "x$enable_mmap" = "xyes"], [
  94. AC_CHECK_FUNCS([mmap])
  95. AC_DEFINE([USE_MMAP], [1], [Use unreliable mmap support])
  96. ])
  97. ])
  98. # DPKG_USE_DISK_PREALLOCATE
  99. # -------------------------
  100. # Define USE_DISK_PREALLOCATE if disk size pre-allocation is available
  101. # and it was requested.
  102. AC_DEFUN([DPKG_USE_DISK_PREALLOCATE], [
  103. AC_ARG_ENABLE([disk-preallocate],
  104. [AS_HELP_STRING([--enable-disk-preallocate],
  105. [enable usage of disk size pre-allocation])],
  106. [], [enable_disk_preallocate=no])
  107. AS_IF([test "x$enable_disk_preallocate" = "xyes"], [
  108. AC_DEFINE([USE_DISK_PREALLOCATE], [1], [Use disk size pre-allocation])
  109. ])
  110. ])
  111. # DPKG_CHECK_PROGNAME
  112. # -------------------
  113. # Check for system implementations of program name tracking.
  114. AC_DEFUN([DPKG_CHECK_PROGNAME], [
  115. AC_MSG_CHECKING([for program_invocation_short_name])
  116. AC_LINK_IFELSE([
  117. AC_LANG_PROGRAM(
  118. [[#include <errno.h>]],
  119. [[const char *p = program_invocation_short_name;]])
  120. ], [
  121. AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
  122. [Define to 1 if you have program_invocation_short_name])
  123. AC_MSG_RESULT([yes])
  124. ], [
  125. AC_MSG_RESULT([no])
  126. ])
  127. AC_MSG_CHECKING([for __progname])
  128. AC_LINK_IFELSE([
  129. AC_LANG_PROGRAM(
  130. [[extern char *__progname;]],
  131. [[printf("%s", __progname);]])
  132. ], [
  133. AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
  134. AC_MSG_RESULT([yes])
  135. ], [
  136. AC_MSG_RESULT([no])
  137. ])
  138. ]) # DPKG_CHECK_PROGNAME
  139. # DPKG_CHECK_COMPAT_FUNCS(LIST)
  140. # -----------------------
  141. # Check each function and define an automake conditional
  142. AC_DEFUN([DPKG_CHECK_COMPAT_FUNCS], [
  143. AC_CHECK_FUNCS([$1])
  144. m4_foreach_w([ac_func], [$1], [
  145. AM_CONDITIONAL([HAVE_]AS_TR_CPP(ac_func),
  146. [test "x$ac_cv_func_[]AS_TR_SH(ac_func)" = "xyes"])
  147. ])
  148. ]) # DPKG_CHECK_COMPAT_FUNCS