Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.9KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_with_mpatrol.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_WITH_MPATROL(DEFAULT)
  8. #
  9. # DESCRIPTION
  10. #
  11. # Integrates the mpatrol malloc debugging library into a new or existing
  12. # project and also attempts to determine the support libraries that need
  13. # to be linked in when libmpatrol is used.
  14. #
  15. # It takes one optional parameter specifying whether mpatrol should be
  16. # included in the project (`yes') or not (`no'). This can also be
  17. # specified as `threads' if you wish to use the threadsafe version of the
  18. # mpatrol library. You can override the value of the optional parameter
  19. # with the `--with-mpatrol' option to the resulting `configure' shell
  20. # script.
  21. #
  22. # LICENSE
  23. #
  24. # Copyright (c) 2008 Graeme S. Roy <graeme@epc.co.uk>
  25. #
  26. # Copying and distribution of this file, with or without modification, are
  27. # permitted in any medium without royalty provided the copyright notice
  28. # and this notice are preserved. This file is offered as-is, without any
  29. # warranty.
  30. #serial 6
  31. AU_ALIAS([AM_WITH_MPATROL], [AX_WITH_MPATROL])
  32. AC_DEFUN([AX_WITH_MPATROL], [
  33. # Firstly, determine if the mpatrol library should be used.
  34. AC_MSG_CHECKING(if mpatrol should be used)
  35. AC_ARG_WITH(mpatrol,
  36. [ --with-mpatrol build with the mpatrol library],
  37. [case "$withval" in
  38. threads)
  39. ax_with_mpatrol=1
  40. ax_with_mpatrol_threads=1;;
  41. yes)
  42. ax_with_mpatrol=1
  43. ax_with_mpatrol_threads=0;;
  44. no)
  45. ax_with_mpatrol=0
  46. ax_with_mpatrol_threads=0;;
  47. *)
  48. AC_MSG_RESULT(no)
  49. AC_MSG_ERROR(invalid value $withval for --with-mpatrol);;
  50. esac
  51. ],
  52. [if test "x[$1]" = x
  53. then
  54. ax_with_mpatrol=0
  55. ax_with_mpatrol_threads=0
  56. elif test "[$1]" = no
  57. then
  58. ax_with_mpatrol=0
  59. ax_with_mpatrol_threads=0
  60. elif test "[$1]" = yes
  61. then
  62. ax_with_mpatrol=1
  63. ax_with_mpatrol_threads=0
  64. elif test "[$1]" = threads
  65. then
  66. ax_with_mpatrol=1
  67. ax_with_mpatrol_threads=1
  68. else
  69. AC_MSG_RESULT(no)
  70. AC_MSG_ERROR(invalid argument [$1])
  71. fi
  72. ]
  73. )
  74. if test "$ax_with_mpatrol" = 1
  75. then
  76. AC_MSG_RESULT(yes)
  77. # Next, determine which support libraries are available on this
  78. # system. If we don't do this here then we can't link later with
  79. # the mpatrol library to perform any further tests.
  80. ax_with_mpatrol_libs=""
  81. AC_CHECK_LIB(ld, ldopen,
  82. ax_with_mpatrol_libs="$ax_with_mpatrol_libs -lld")
  83. AC_CHECK_LIB(elf, elf_begin,
  84. ax_with_mpatrol_libs="$ax_with_mpatrol_libs -lelf")
  85. AC_CHECK_LIB(bfd, bfd_init,
  86. ax_with_mpatrol_libs="$ax_with_mpatrol_libs -lbfd -liberty", ,
  87. -liberty)
  88. AC_CHECK_LIB(imagehlp, SymInitialize,
  89. ax_with_mpatrol_libs="$ax_with_mpatrol_libs -limagehlp")
  90. AC_CHECK_LIB(cl, U_get_previous_frame,
  91. ax_with_mpatrol_libs="$ax_with_mpatrol_libs -lcl")
  92. AC_CHECK_LIB(exc, unwind,
  93. ax_with_mpatrol_libs="$ax_with_mpatrol_libs -lexc")
  94. # Now determine which libraries really need to be linked in with
  95. # the version of libmpatrol that is on this system. For example,
  96. # if the system has libelf and libbfd, we need to determine which
  97. # of these, if any, libmpatrol was built with support for.
  98. ax_with_mpatrol_libs2=""
  99. AC_CHECK_LIB(mpatrol, __mp_libld,
  100. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lld", ,
  101. $ax_with_mpatrol_libs)
  102. AC_CHECK_LIB(mpatrol, __mp_libelf,
  103. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lelf", ,
  104. $ax_with_mpatrol_libs)
  105. AC_CHECK_LIB(mpatrol, __mp_libbfd,
  106. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lbfd -liberty", ,
  107. $ax_with_mpatrol_libs)
  108. AC_CHECK_LIB(mpatrol, __mp_libimagehlp,
  109. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -limagehlp", ,
  110. $ax_with_mpatrol_libs)
  111. AC_CHECK_LIB(mpatrol, __mp_libcl,
  112. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lcl", ,
  113. $ax_with_mpatrol_libs)
  114. AC_CHECK_LIB(mpatrol, __mp_libexc,
  115. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lexc", ,
  116. $ax_with_mpatrol_libs)
  117. # If we are using the threadsafe mpatrol library then we may also need
  118. # to link in the threads library. We check blindly for pthreads here
  119. # even if we don't need them (in which case it doesn't matter) since
  120. # the threads libraries are linked in by default on AmigaOS, Windows
  121. # and Netware and it is only UNIX systems that we need to worry about.
  122. if test "$ax_with_mpatrol_threads" = 1
  123. then
  124. AC_CHECK_LIB(pthread, pthread_mutex_init,
  125. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lpthread", [
  126. AC_CHECK_LIB(pthreads, pthread_mutex_init,
  127. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lpthreads", [
  128. AC_CHECK_LIB(thread, pthread_mutex_init,
  129. ax_with_mpatrol_libs2="$ax_with_mpatrol_libs2 -lthread")
  130. ]
  131. )
  132. ]
  133. )
  134. fi
  135. # We now know what libraries to use in order to link with libmpatrol.
  136. AC_DEFINE(HAVE_MPATROL, 1, [Define if using mpatrol])
  137. if test "$ax_with_mpatrol_threads" = 1
  138. then
  139. LIBS="-lmpatrolmt $ax_with_mpatrol_libs2 $LIBS"
  140. else
  141. LIBS="-lmpatrol $ax_with_mpatrol_libs2 $LIBS"
  142. fi
  143. # Finally, verify that mpatrol is correctly installed and that we can
  144. # link a simple program with it.
  145. AC_CACHE_CHECK(for working mpatrol, am_cv_with_mpatrol, [
  146. AC_TRY_LINK([#include <mpatrol.h>], [
  147. int main(void)
  148. {
  149. malloc(4);
  150. return EXIT_SUCCESS;
  151. }
  152. ],
  153. [am_cv_with_mpatrol=yes],
  154. [am_cv_with_mpatrol=no]
  155. )
  156. ]
  157. )
  158. if test "$am_cv_with_mpatrol" = no
  159. then
  160. AC_MSG_ERROR(mpatrol not installed correctly)
  161. fi
  162. else
  163. AC_MSG_RESULT(no)
  164. fi
  165. ]
  166. )