jemalloc.m4 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. dnl -------------------------------------------------------- -*- autoconf -*-
  2. dnl SPDX-License-Identifier: Apache-2.0
  3. dnl
  4. dnl jemalloc.m4: Trafficserver's jemalloc autoconf macros
  5. dnl modified to skip other TS_ helpers
  6. dnl
  7. AC_DEFUN([TS_CHECK_JEMALLOC], [
  8. AC_ARG_WITH([jemalloc-prefix],
  9. [AS_HELP_STRING([--with-jemalloc-prefix=PREFIX],[Specify the jemalloc prefix [default=""]])],
  10. [
  11. jemalloc_prefix="$withval"
  12. ],[
  13. if test "`uname -s`" = "Darwin"; then
  14. jemalloc_prefix="je_"
  15. else
  16. jemalloc_prefix=""
  17. fi
  18. ]
  19. )
  20. AC_DEFINE_UNQUOTED([prefix_jemalloc], [${jemalloc_prefix}], [jemalloc prefix])
  21. enable_jemalloc=no
  22. AC_ARG_WITH([jemalloc], [AS_HELP_STRING([--with-jemalloc=DIR], [use a specific jemalloc library])],
  23. [
  24. if test "$withval" != "no"; then
  25. if test "x${enable_tcmalloc}" = "xyes"; then
  26. AC_MSG_ERROR([Cannot compile with both jemalloc and tcmalloc])
  27. fi
  28. enable_jemalloc=yes
  29. jemalloc_base_dir="$withval"
  30. case "$withval" in
  31. yes)
  32. jemalloc_base_dir="/usr"
  33. AC_MSG_CHECKING(checking for jemalloc includes standard directories)
  34. ;;
  35. *":"*)
  36. jemalloc_include="`echo $withval |sed -e 's/:.*$//'`"
  37. jemalloc_ldflags="`echo $withval |sed -e 's/^.*://'`"
  38. AC_MSG_CHECKING(checking for jemalloc includes in $jemalloc_include libs in $jemalloc_ldflags)
  39. ;;
  40. *)
  41. jemalloc_include="$withval/include"
  42. jemalloc_ldflags="$withval/lib"
  43. AC_MSG_CHECKING(checking for jemalloc includes in $withval)
  44. ;;
  45. esac
  46. fi
  47. ])
  48. has_jemalloc=0
  49. if test "$enable_jemalloc" != "no"; then
  50. jemalloc_have_headers=0
  51. jemalloc_have_libs=0
  52. if test "$jemalloc_base_dir" != "/usr"; then
  53. CFLAGS="${CFLAGS} -I${jemalloc_include}"
  54. LDFLAGS="${LDFLAGS} -L${jemalloc_ldflags}"
  55. LIBTOOL_LINK_FLAGS="${LIBTOOL_LINK_FLAGS} -R${jemalloc_ldflags}"
  56. fi
  57. func="${jemalloc_prefix}malloc_stats_print"
  58. AC_CHECK_LIB(jemalloc, ${func}, [jemalloc_have_libs=1])
  59. if test "$jemalloc_have_libs" != "0"; then
  60. AC_CHECK_HEADERS([jemalloc/jemalloc.h], [jemalloc_have_headers=1])
  61. fi
  62. if test "$jemalloc_have_headers" != "0"; then
  63. has_jemalloc=1
  64. LIBS="${LIBS} -ljemalloc"
  65. AC_DEFINE(has_jemalloc, [1], [Link/compile against jemalloc])
  66. else
  67. AC_MSG_ERROR([Couldn't find a jemalloc installation])
  68. fi
  69. fi
  70. AC_SUBST(has_jemalloc)
  71. ])