configure.ac 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. ## Process this file with autoconf to produce configure.
  2. ## In general, the safest way to proceed is to run ./autogen.sh
  3. # make sure we're interpreted by some minimal autoconf
  4. AC_PREREQ([2.59])
  5. AC_INIT([gperftools],[2.7],[[email protected]])
  6. # Update this value for every release! (A:B:C will map to foo.so.(A-C).C.B)
  7. # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
  8. TCMALLOC_SO_VERSION=9:3:5
  9. PROFILER_SO_VERSION=4:18:4
  10. AC_SUBST(TCMALLOC_SO_VERSION)
  11. AC_SUBST(PROFILER_SO_VERSION)
  12. # The argument here is just something that should be in the current directory
  13. # (for sanity checking)
  14. AC_CONFIG_SRCDIR(README)
  15. AC_CONFIG_MACRO_DIR([m4])
  16. AC_CANONICAL_HOST
  17. AM_INIT_AUTOMAKE([dist-zip])
  18. AC_CONFIG_HEADERS([src/config.h])
  19. AM_MAINTAINER_MODE()
  20. # Export the version information (for tc_version and friends)
  21. TC_VERSION_MAJOR=`expr "$PACKAGE_VERSION" : '\([[0-9]]*\)'`
  22. TC_VERSION_MINOR=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.\([[0-9]]*\)'`
  23. TC_VERSION_PATCH=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.[[0-9]]*\(.*\)$'`
  24. AC_SUBST(TC_VERSION_MAJOR)
  25. AC_SUBST(TC_VERSION_MINOR)
  26. AC_SUBST(TC_VERSION_PATCH)
  27. AC_SUBST(PACKAGE_STRING)
  28. AX_GENERATE_CHANGELOG
  29. # The user can choose not to compile in the heap-profiler, the
  30. # heap-checker, or the cpu-profiler. There's also the possibility
  31. # for a 'fully minimal' compile, which leaves out the stacktrace
  32. # code as well. By default, we include all of these that the
  33. # target system supports.
  34. default_enable_cpu_profiler=yes
  35. default_enable_heap_profiler=yes
  36. default_enable_heap_checker=yes
  37. default_enable_debugalloc=yes
  38. default_enable_minimal=no
  39. default_tcmalloc_alignment=16
  40. need_nanosleep=yes # Used later, to decide if to run ACX_NANOSLEEP
  41. case "$host" in
  42. *-mingw*) default_enable_minimal=yes; default_enable_debugalloc=no;
  43. need_nanosleep=no;;
  44. *-cygwin*) default_enable_heap_checker=no; default_enable_cpu_profiler=no;;
  45. *-freebsd*) default_enable_heap_checker=no;;
  46. *-darwin*) default_enable_heap_checker=no;;
  47. esac
  48. # Currently only backtrace works on s390.
  49. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __s390__])],
  50. [default_enable_libunwind=no
  51. default_enable_backtrace=yes],
  52. [default_enable_libunwind=yes
  53. default_enable_backtrace=no])
  54. # Disable libunwind linking on ppc64 by default.
  55. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __PPC64__])],
  56. [default_enable_libunwind=no
  57. default_tcmalloc_pagesize=64],
  58. [default_enable_libunwind=yes
  59. default_tcmalloc_pagesize=8])
  60. AC_ARG_ENABLE([cpu-profiler],
  61. [AS_HELP_STRING([--disable-cpu-profiler],
  62. [do not build the cpu profiler])],
  63. [],
  64. [enable_cpu_profiler="$default_enable_cpu_profiler"])
  65. AC_ARG_ENABLE([heap-profiler],
  66. [AS_HELP_STRING([--disable-heap-profiler],
  67. [do not build the heap profiler])],
  68. [],
  69. [enable_heap_profiler="$default_enable_heap_profiler"])
  70. AC_ARG_ENABLE([heap-checker],
  71. [AS_HELP_STRING([--disable-heap-checker],
  72. [do not build the heap checker])],
  73. [],
  74. [enable_heap_checker="$default_enable_heap_checker"])
  75. AC_ARG_ENABLE([debugalloc],
  76. [AS_HELP_STRING([--disable-debugalloc],
  77. [do not build versions of libs with debugalloc])],
  78. [],
  79. [enable_debugalloc="$default_enable_debugalloc"])
  80. AC_ARG_ENABLE([minimal],
  81. [AS_HELP_STRING([--enable-minimal],
  82. [build only tcmalloc-minimal (and maybe tcmalloc-minimal-debug)])],
  83. [],
  84. [enable_minimal="$default_enable_minimal"])
  85. if test "$enable_minimal" = yes; then
  86. enable_cpu_profiler=no
  87. enable_heap_profiler=no
  88. enable_heap_checker=no
  89. fi
  90. AC_ARG_ENABLE([stacktrace-via-backtrace],
  91. [AS_HELP_STRING([--enable-stacktrace-via-backtrace],
  92. [enable use of backtrace() for stacktrace capturing (may deadlock)])],
  93. [enable_backtrace=yes],
  94. [enable_backtrace="$default_enable_backtrace"])
  95. AC_ARG_ENABLE([libunwind],
  96. [AS_HELP_STRING([--enable-libunwind],
  97. [enable libunwind linking])],
  98. [],
  99. [enable_libunwind="$default_enable_libunwind"])
  100. AC_ARG_WITH([tcmalloc-pagesize],
  101. [AS_HELP_STRING([--with-tcmalloc-pagesize],
  102. [Set the tcmalloc internal page size to 4K, 8K, 16K, 32K, 64K, 128K or 256K])],
  103. [],
  104. [with_tcmalloc_pagesize=$default_tcmalloc_pagesize])
  105. AC_ARG_WITH([tcmalloc-alignment],
  106. [AS_HELP_STRING([--with-tcmalloc-alignment],
  107. [Set the tcmalloc allocation alignment to 8 or 16 bytes])],
  108. [],
  109. [with_tcmalloc_alignment=$default_tcmalloc_alignment])
  110. case "$with_tcmalloc_pagesize" in
  111. 4)
  112. AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 12);;
  113. 8)
  114. #Default tcmalloc page size.
  115. ;;
  116. 16)
  117. AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 14);;
  118. 32)
  119. AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 15);;
  120. 64)
  121. AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 16);;
  122. 128)
  123. AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 17);;
  124. 256)
  125. AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 18,
  126. [Define internal page size for tcmalloc as number of left bitshift]);;
  127. *)
  128. AC_MSG_WARN([${with_tcmalloc_pagesize}K size not supported, using default tcmalloc page size.])
  129. esac
  130. case "$with_tcmalloc_alignment" in
  131. 8)
  132. AC_DEFINE(TCMALLOC_ALIGN_8BYTES, 1,
  133. [Define 8 bytes of allocation alignment for tcmalloc]);;
  134. 16)
  135. #Default tcmalloc allocation alignment.
  136. ;;
  137. *)
  138. AC_MSG_WARN([${with_tcmalloc_alignment} bytes not supported, using default tcmalloc allocation alignment.])
  139. esac
  140. # Checks for programs.
  141. AC_PROG_CXX
  142. AC_PROG_CC
  143. AC_PROG_CPP
  144. AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
  145. AM_PROG_CC_C_O # shrug: autogen.sh suddenly needs this for some reason
  146. AX_CXX_COMPILE_STDCXX(11, ext, mandatory)
  147. # Check if we have an objcopy installed that supports -W
  148. AC_CHECK_TOOL([OBJCOPY], [objcopy], [])
  149. AS_IF([test -n "$OBJCOPY"], [dnl
  150. AC_CACHE_CHECK([if $OBJCOPY supports -W], gpt_cv_objcopy_weaken, [dnl
  151. AC_LINK_IFELSE([AC_LANG_PROGRAM([void foo() {} int main() {return 0;}])], [dnl
  152. AS_IF(["$OBJCOPY" -W foo conftest$ac_exeext /dev/null],
  153. [gpt_cv_objcopy_weaken=yes], [gpt_cv_objcopy_weaken=no])],
  154. [gpt_cv_objcopy_weaken=no])])],
  155. [gpt_cv_objcopy_weaken=no])
  156. AM_CONDITIONAL(HAVE_OBJCOPY_WEAKEN, test $gpt_cv_objcopy_weaken = yes)
  157. AC_PROG_LIBTOOL
  158. AC_C_INLINE
  159. AX_C___ATTRIBUTE__
  160. AC_MSG_CHECKING(for __attribute__((aligned(N))) on functions)
  161. AC_CACHE_VAL(ac_cv___attribute__aligned_fn, [
  162. AC_TRY_COMPILE(
  163. [#include <stdlib.h>
  164. void foo(void) __attribute__((aligned(128)));
  165. void foo(void) { exit(1); }],
  166. [],
  167. ac_cv___attribute__aligned_fn=yes,
  168. ac_cv___attribute__aligned_fn=no
  169. )])
  170. if test "$ac_cv___attribute__aligned_fn" = "yes"; then
  171. AC_DEFINE(HAVE___ATTRIBUTE__ALIGNED_FN, 1, [define if your compiler supports alignment of functions])
  172. fi
  173. AC_MSG_RESULT($ac_cv___attribute__aligned_fn)
  174. # Check whether some low-level functions/files are available
  175. AC_HEADER_STDC
  176. # TODO(csilvers): we could remove a lot when WITH_CPU_PROFILER etc is "no".
  177. AC_CHECK_TYPES([__int64]) # defined in some windows platforms
  178. AC_CHECK_TYPES([struct mallinfo],,, [#include <malloc.h>])
  179. AC_CHECK_TYPES([Elf32_Versym],,, [#include <elf.h>]) # for vdso_support.h
  180. AC_CHECK_FUNCS(sbrk) # for tcmalloc to get memory
  181. AC_CHECK_FUNCS(__sbrk) # for tcmalloc to get memory
  182. AC_CHECK_FUNCS(geteuid) # for turning off services when run as root
  183. AC_CHECK_FUNCS(fork) # for the pthread_atfork setup
  184. AC_CHECK_HEADERS(features.h) # for vdso_support.h
  185. AC_CHECK_HEADERS(malloc.h) # some systems define stuff there, others not
  186. AC_CHECK_HEADERS(glob.h) # for heap-profile-table (cleaning up profiles)
  187. AC_CHECK_HEADERS(execinfo.h) # for stacktrace? and heapchecker_unittest
  188. AC_CHECK_HEADERS(unwind.h) # for stacktrace
  189. AC_CHECK_HEADERS(sched.h) # for being nice in our spinlock code
  190. AC_CHECK_HEADERS(conflict-signal.h) # defined on some windows platforms?
  191. AC_CHECK_HEADERS(sys/prctl.h) # for thread_lister (needed by leak-checker)
  192. AC_CHECK_HEADERS(linux/ptrace.h)# also needed by leak-checker
  193. AC_CHECK_HEADERS(sys/syscall.h)
  194. AC_CHECK_HEADERS(sys/socket.h) # optional; for forking out to symbolizer
  195. AC_CHECK_HEADERS(sys/wait.h) # optional; for forking out to symbolizer
  196. AC_CHECK_HEADERS(poll.h) # optional; for forking out to symbolizer
  197. AC_CHECK_HEADERS(fcntl.h) # for tcmalloc_unittest
  198. AC_CHECK_HEADERS(grp.h) # for heapchecker_unittest
  199. AC_CHECK_HEADERS(pwd.h) # for heapchecker_unittest
  200. AC_CHECK_HEADERS(sys/resource.h) # for memalign_unittest.cc
  201. AC_CHECK_HEADERS(valgrind.h) # we have a local copy if this isn't found
  202. AC_CHECK_HEADERS(sys/cdefs.h) # Where glibc defines __THROW
  203. AC_CHECK_HEADERS(features.h) # Where __GLIBC__ is defined
  204. # We also need <ucontext.h>/<sys/ucontext.h>, but we get those from
  205. # AC_PC_FROM_UCONTEXT, below.
  206. # We override a lot of memory allocation routines, not all of which are
  207. # standard. For those the system doesn't declare, we'll declare ourselves.
  208. AC_CHECK_DECLS([cfree,
  209. posix_memalign,
  210. memalign,
  211. valloc,
  212. pvalloc],,,
  213. [#define _XOPEN_SOURCE 600
  214. #include <stdlib.h>
  215. #include <malloc.h>])
  216. if test "$ac_cv_type_struct_mallinfo" = yes; then
  217. AC_SUBST(ac_cv_have_struct_mallinfo, 1) # gperftools/tcmalloc.h needs this
  218. else
  219. AC_SUBST(ac_cv_have_struct_mallinfo, 0)
  220. fi
  221. # We hardcode HAVE_MMAP to 1. There are no interesting systems anymore
  222. # without functional mmap. And our windows builds aren't using
  223. # autoconf. So we keep HAVE_MMAP define, but only to distingush
  224. # windows and rest.
  225. AC_DEFINE(HAVE_MMAP, 1, [Define to 1 if you have a working `mmap' system call.])
  226. # If AtomicWord != Atomic32, we need to define two versions of all the
  227. # atomicops functions. If they're the same, we want to define only one.
  228. AC_MSG_CHECKING([if int32_t is the same type as intptr_t])
  229. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]], [[int32_t v1 = 0; intptr_t v2 = 0; return (&v1 - &v2)]])],[AC_DEFINE(INT32_EQUALS_INTPTR, 1,
  230. Define to 1 if int32_t is equivalent to intptr_t)
  231. AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])])
  232. # We want to access the "PC" (Program Counter) register from a struct
  233. # ucontext. Every system has its own way of doing that. We try all the
  234. # possibilities we know about. Note REG_PC should come first (REG_RIP
  235. # is also defined on solaris, but does the wrong thing). But don't
  236. # bother if we're not doing cpu-profiling.
  237. # [*] means that we've not actually tested one of these systems
  238. if test "$enable_cpu_profiler" = yes; then
  239. AC_PC_FROM_UCONTEXT(AC_MSG_WARN(Could not find the PC. Will not try to compile libprofiler...);
  240. enable_cpu_profiler=no)
  241. fi
  242. # Some tests test the behavior of .so files, and only make sense for dynamic.
  243. AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
  244. # We want to link in libunwind if it is enabled and exists.
  245. UNWIND_LIBS=
  246. if test "$enable_libunwind" = yes; then
  247. AC_CHECK_HEADERS([libunwind.h],
  248. [AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind)
  249. will_use_libunwind=yes])
  250. fi
  251. AC_SUBST(UNWIND_LIBS)
  252. # On x86_64, instead of libunwind, we can choose to compile with frame-pointers.
  253. AC_ARG_ENABLE(frame_pointers,
  254. AS_HELP_STRING([--enable-frame-pointers],
  255. [On x86_64 systems, compile with -fno-omit-frame-pointer (see INSTALL)]),
  256. , enable_frame_pointers=no)
  257. AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes)
  258. AC_MSG_CHECKING([for x86 without frame pointers])
  259. # Some x86_64 systems do not insert frame pointers by default.
  260. # We want to see if the current system is one of those.
  261. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])],
  262. [is_x86_64=yes], [is_x86_64=no])
  263. OLD_CFLAGS="$CFLAGS"
  264. CFLAGS="$CFLAGS -S -O2 -o fp.s"
  265. # This test will always fail because we don't name our output file properly.
  266. # We do our own determination of success/failure in the grep, below.
  267. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int f(int x) {return x;}], [return f(0);])],
  268. [:], [:])
  269. x86_no_fp_by_default=no
  270. AS_IF([test "$is_x86_64" = yes && ! grep 'mov.*rsp.*rbp' fp.s >/dev/null 2>&1], [x86_no_fp_by_default=yes])
  271. AM_CONDITIONAL(X86_64_AND_NO_FP_BY_DEFAULT,
  272. test "$x86_no_fp_by_default" = yes)
  273. rm fp.s
  274. CFLAGS="$OLD_CFLAGS"
  275. AC_MSG_RESULT([$x86_no_fp_by_default])
  276. # We need to know if we're i386 so we can turn on -mmms, which is not
  277. # on by default for i386 (it is for x86_64).
  278. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __i386__ == 1 ? 0 : 1])],
  279. [is_i386=yes], [is_i386=no])
  280. AM_CONDITIONAL(I386, test "$is_i386" = yes)
  281. # See if the compiler supports -Wno-unused-result.
  282. # Newer ubuntu's turn on -D_FORTIFY_SOURCE=2, enabling
  283. # __attribute__((warn_unused_result)) for things like write(),
  284. # which we don't care about.
  285. AC_CACHE_CHECK([if the compiler supports -Wno-unused-result],
  286. perftools_cv_w_no_unused_result,
  287. [OLD_CFLAGS="$CFLAGS"
  288. CFLAGS="$CFLAGS -Wno-error -Wunused-result"
  289. # gcc doesn't warn about unknown flags unless it's
  290. # also warning for some other purpose, hence the
  291. # divide-by-0. (We use -Wno-error to make sure the
  292. # divide-by-0 doesn't cause this test to fail!)
  293. #
  294. # Also gcc is giving only warning for unknown flags of
  295. # -Wno-XXX form. So in order to detect support we're
  296. # using -Wunused-result which will cause gcc to give
  297. # error which we can detect.
  298. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return 1/0)],
  299. perftools_cv_w_no_unused_result=yes,
  300. perftools_cv_w_no_unused_result=no)
  301. CFLAGS="$OLD_CFLAGS"])
  302. AM_CONDITIONAL(HAVE_W_NO_UNUSED_RESULT,
  303. test "$perftools_cv_w_no_unused_result" = yes)
  304. AC_ARG_ENABLE([deprecated-pprof],
  305. [AS_HELP_STRING([--disable-deprecated-pprof],
  306. [do not install old deprecated and unmaintained bundled pprof
  307. (see github.com/google/pprof for supported version)])],
  308. [enable_pprof="$enableval"],
  309. [enable_pprof=yes])
  310. AM_CONDITIONAL(INSTALL_PPROF,
  311. [test "x$enable_pprof" = xyes])
  312. AC_ARG_ENABLE([dynamic-sized-delete-support],
  313. [AS_HELP_STRING([--enable-dynamic-sized-delete-support],
  314. [try to build run-time switch for sized delete operator])],
  315. [enable_dyn_sized_delete="$enableval"],
  316. [enable_dyn_sized_delete=no])
  317. AS_IF([test "x$enable_dyn_sized_delete" = xyes],
  318. [AC_DEFINE([ENABLE_DYNAMIC_SIZED_DELETE], 1,
  319. [Build runtime detection for sized delete])])
  320. AC_ARG_ENABLE([sized-delete],
  321. [AS_HELP_STRING([--enable-sized-delete],
  322. [build sized delete operator])],
  323. [enable_sized_delete="$enableval"],
  324. [enable_sized_delete="no"])
  325. AS_IF([test "x$enable_sized_delete" = xyes],
  326. [AC_DEFINE([ENABLE_SIZED_DELETE], 1, [Build sized deletion operators])
  327. AC_MSG_NOTICE([Will build sized deallocation operators])],
  328. [AS_IF([test "x$enable_dyn_sized_delete" = xyes],
  329. [AC_MSG_NOTICE([Will build dynamically detected sized deallocation operators])],
  330. [AC_MSG_NOTICE([Will build sized deallocation operators that ignore size])])])
  331. AC_CACHE_CHECK([if C++ compiler supports -fsized-deallocation],
  332. [perftools_cv_sized_deallocation_result],
  333. [AC_LANG_PUSH(C++)
  334. OLD_CXXFLAGS="$CXXFLAGS"
  335. CXXFLAGS="$CXXFLAGS -fsized-deallocation"
  336. AC_LINK_IFELSE([AC_LANG_PROGRAM(
  337. [[#include <new>
  338. #include <stddef.h>]],
  339. [[static void (* volatile ptr)(void *, size_t) = ::operator delete; (*ptr)(0, 256);]])],
  340. perftools_cv_sized_deallocation_result=yes,
  341. perftools_cv_sized_deallocation_result=no)
  342. CXXFLAGS="$OLD_CXXFLAGS"
  343. AC_LANG_POP(C++)])
  344. AM_CONDITIONAL(HAVE_SIZED_DEALLOCATION,
  345. test "$perftools_cv_sized_deallocation_result" = yes)
  346. AC_CACHE_CHECK([if C++ compiler supports std::align_val_t without options],
  347. [perftools_cv_have_align_val_t],
  348. [AC_LANG_PUSH(C++)
  349. AC_LINK_IFELSE([AC_LANG_PROGRAM(
  350. [[#include <new>]],
  351. [[(::operator delete)((::operator new)(256, std::align_val_t(16)), std::align_val_t(16))]])],
  352. perftools_cv_have_align_val_t=yes,
  353. perftools_cv_have_align_val_t=no)
  354. AC_LANG_POP(C++)])
  355. AC_CACHE_CHECK([if C++ compiler supports -faligned-new],
  356. [perftools_cv_have_f_aligned_new],
  357. [AC_LANG_PUSH(C++)
  358. OLD_CXXFLAGS="$CXXFLAGS"
  359. CXXFLAGS="$CXXFLAGS -faligned-new"
  360. AC_LINK_IFELSE([AC_LANG_PROGRAM(
  361. [[#include <new>]],
  362. [[(::operator delete)((::operator new)(256, std::align_val_t(16)), std::align_val_t(16))]])],
  363. perftools_cv_have_f_aligned_new=yes,
  364. perftools_cv_have_f_aligned_new=no)
  365. CXXFLAGS="$OLD_CXXFLAGS"
  366. AC_LANG_POP(C++)])
  367. AM_CONDITIONAL(HAVE_F_ALIGNED_NEW,
  368. test "$perftools_cv_have_f_aligned_new" = yes)
  369. AS_IF([test "$perftools_cv_have_align_val_t" = yes || test "$perftools_cv_have_f_aligned_new" = yes],
  370. [AC_DEFINE([ENABLE_ALIGNED_NEW_DELETE], 1, [Build new/delete operators for overaligned types])
  371. AC_MSG_NOTICE([Will build new/delete operators for overaligned types])],
  372. AC_MSG_NOTICE([Will not build new/delete operators for overaligned types]))
  373. if test "$perftools_cv_have_align_val_t" = yes || test "$perftools_cv_have_f_aligned_new" = yes; then
  374. AC_SUBST(ac_cv_have_std_align_val_t, 1) # gperftools/tcmalloc.h and windows/gperftools/tcmalloc.h need this
  375. else
  376. AC_SUBST(ac_cv_have_std_align_val_t, 0)
  377. fi
  378. AC_CACHE_CHECK([if target has _Unwind_Backtrace],
  379. [perftools_cv_have_unwind_backtrace],
  380. [AC_LANG_PUSH(C++)
  381. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  382. [[#include <unwind.h>]],
  383. [[&_Unwind_Backtrace]])],
  384. [perftools_cv_have_unwind_backtrace=yes],
  385. [perftools_cv_have_unwind_backtrace=no])
  386. AC_LANG_POP(C++)])
  387. AS_IF([test "x$perftools_cv_have_unwind_backtrace" = xyes],
  388. [AC_DEFINE(HAVE_UNWIND_BACKTRACE, 1, [Whether <unwind.h> contains _Unwind_Backtrace])])
  389. AS_IF([test "x$enable_backtrace" = xyes],
  390. [default_emergency_malloc=yes],
  391. [default_emergency_malloc=no])
  392. AS_IF([test "x$will_use_libunwind" = xyes],
  393. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __arm__])],
  394. [default_emergency_malloc=yes])])
  395. AC_ARG_ENABLE([emergency-malloc],
  396. [AS_HELP_STRING([--enable-emergency-malloc],
  397. [build emergency malloc feature])],
  398. [enable_emergency_malloc="$enableval"],
  399. [enable_emergency_malloc="$default_emergency_malloc"])
  400. AM_CONDITIONAL(BUILD_EMERGENCY_MALLOC, [test "x$enable_emergency_malloc" = xyes])
  401. # Defines PRIuS
  402. AC_COMPILER_CHARACTERISTICS
  403. # Also make sure we get standard PRI... definitions, even with glibc.
  404. # We have to use AH_VERBATIM because we need the #ifdef guard (gcc buglet)
  405. AH_VERBATIM([__STDC_FORMAT_MACROS],
  406. [/* C99 says: define this to get the PRI... macros from stdint.h */
  407. #ifndef __STDC_FORMAT_MACROS
  408. # define __STDC_FORMAT_MACROS 1
  409. #endif])
  410. # Check if __builtin_stack_pointer() is available (for elfcore.h)
  411. AC_MSG_CHECKING([for __builtin_stack_pointer()])
  412. AC_LINK_IFELSE([AC_LANG_PROGRAM(, [void *sp = __builtin_stack_pointer()])],
  413. [AC_DEFINE(HAVE_BUILTIN_STACK_POINTER, 1,
  414. Define to 1 if compiler supports __builtin_stack_pointer)
  415. AC_MSG_RESULT([yes])],
  416. [AC_MSG_RESULT([no])])
  417. # Check if __environ is available (for GetenvBeforeMain)
  418. AC_MSG_CHECKING([for __environ])
  419. AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>],
  420. [char **env = __environ])],
  421. [AC_DEFINE(HAVE___ENVIRON, 1,
  422. [Define to 1 if compiler supports __environ])
  423. AC_MSG_RESULT([yes])],
  424. [AC_MSG_RESULT([no])])
  425. # If we support __thread, that can speed up tcmalloc a bit.
  426. # Note, however, that our code tickles a bug in gcc < 4.1.2
  427. # involving TLS and -fPIC (which our libraries will use) on x86:
  428. # http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
  429. #
  430. # And mingw also does compile __thread but resultant code actually
  431. # fails to work correctly at least in some not so ancient version:
  432. # http://mingw-users.1079350.n2.nabble.com/gcc-4-4-multi-threaded-exception-handling-amp-thread-specifier-not-working-td3440749.html
  433. #
  434. # Also it was reported that earlier gcc versions for mips compile
  435. # __thread but it doesn't really work
  436. AC_MSG_CHECKING([for __thread])
  437. AC_LINK_IFELSE([AC_LANG_PROGRAM([#if defined(__GNUC__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 1) || (__GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ < 2))
  438. #error gcc has this bug: http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
  439. #elif defined(__MINGW32__)
  440. #error mingw doesnt really support tls
  441. #elif defined(__APPLE__)
  442. #error OSX __thread support is known to call malloc which makes it unsafe to use from malloc replacement
  443. #endif
  444. ], [static __thread int p = 0])],
  445. [AC_DEFINE(HAVE_TLS, 1,
  446. Define to 1 if compiler supports __thread)
  447. AC_MSG_RESULT([yes])],
  448. [AC_MSG_RESULT([no])])
  449. # Nanosleep requires extra libraries on some architectures (solaris).
  450. # This sets NANOSLEEP_LIBS. nanosleep doesn't exist on mingw, which
  451. # is fine for us because we don't compile libspinlock, which uses it.
  452. if test "$need_nanosleep" = yes; then
  453. ACX_NANOSLEEP
  454. AC_SUBST(NANOSLEEP_LIBS)
  455. fi
  456. # Solaris 10 6/06 has a bug where /usr/sfw/lib/libstdc++.la is empty.
  457. # If so, we replace it with our own version.
  458. LIBSTDCXX_LA_LINKER_FLAG=
  459. if test -f /usr/sfw/lib/libstdc++.la && ! test -s /usr/sfw/lib/libstdc++.la
  460. then
  461. LIBSTDCXX_LA_LINKER_FLAG='-L$(top_srcdir)/src/solaris'
  462. fi
  463. AC_SUBST(LIBSTDCXX_LA_LINKER_FLAG)
  464. # We also need to check if the kernel supports __thread, which requires uname()
  465. AC_CHECK_DECLS(uname,,, [#include <sys/utsname.h>])
  466. # In fact, a lot of the code in this directory depends on pthreads
  467. ACX_PTHREAD
  468. AC_LANG_SAVE
  469. AC_LANG_CPLUSPLUS
  470. AC_MSG_CHECKING([whether pthread symbols are available in C++ without including pthread.h])
  471. acx_pthread_despite_asking_for=no
  472. AC_LINK_IFELSE(
  473. [AC_LANG_PROGRAM([
  474. #include <string>
  475. #include <vector>
  476. ],[
  477. pthread_t th; pthread_join(th, 0);
  478. ])],[
  479. acx_pthread_despite_asking_for=yes
  480. AC_DEFINE(HAVE_PTHREAD_DESPITE_ASKING_FOR, 1, [defined to 1 if pthread symbols are exposed even without include pthread.h])
  481. AC_DEFINE(HAVE_PTHREAD, 1, [])
  482. ])
  483. AC_MSG_RESULT([$acx_pthread_despite_asking_for])
  484. AC_LANG_RESTORE
  485. AM_CONDITIONAL(HAVE_PTHREAD_DESPITE_ASKING_FOR, test x"$acx_pthread_despite_asking_for" = xyes)
  486. # Find out what namespace 'normal' STL code lives in
  487. AC_CXX_STL_NAMESPACE
  488. # Figure out where libc has program_invocation_name
  489. AC_PROGRAM_INVOCATION_NAME
  490. # Make the install prefix available, to figure out where to look for pprof
  491. AC_INSTALL_PREFIX
  492. dnl only very recent mingw has sleep and nanosleep
  493. case "$host" in
  494. *-mingw*)
  495. AC_CHECK_DECLS([sleep], [], [], [#include <unistd.h>])
  496. AC_CHECK_DECLS([nanosleep], [], [], [#include <time.h>])
  497. ;;
  498. esac
  499. if test "x$enable_backtrace" = xyes; then
  500. AC_CHECK_DECLS([backtrace], [], [], [#include <execinfo.h>])
  501. save_LIBS=$LIBS
  502. LIBS=$UNWIND_LIBS
  503. AC_SEARCH_LIBS([backtrace], [execinfo])
  504. UNWIND_LIBS=$LIBS
  505. LIBS=$save_LIBS
  506. fi
  507. # For windows, this has a non-trivial value (__declspec(export)), but any
  508. # system that uses configure wants this to be the empty string.
  509. AC_DEFINE(PERFTOOLS_DLL_DECL,,
  510. [Always the empty-string on non-windows systems.
  511. On windows, should be "__declspec(dllexport)".
  512. This way, when we compile the dll, we export our functions/classes.
  513. It's safe to define this here because config.h is only used
  514. internally, to compile the DLL, and every DLL source file
  515. #includes "config.h" before anything else.])
  516. # In theory, config.h files shouldn't need a header guard, but we do,
  517. # because we (maybe) #include windows/mingw.h from within config.h,
  518. # and it #includes other .h files. These all have header guards, so
  519. # the end result is if config.h is #included twice, its #undefs get
  520. # evaluated twice, but all the ones in mingw.h/etc only get evaluated
  521. # once, potentially causing trouble. c.f.
  522. # http://code.google.com/p/gperftools/issues/detail?id=246
  523. AH_TOP([
  524. #ifndef GPERFTOOLS_CONFIG_H_
  525. #define GPERFTOOLS_CONFIG_H_
  526. ])
  527. AH_VERBATIM([PTHREADS_CRASHES_IF_RUN_TOO_EARLY],
  528. [/* Mark the systems where we know it's bad if pthreads runs too
  529. early before main (before threads are initialized, presumably). */
  530. #ifdef __FreeBSD__
  531. #define PTHREADS_CRASHES_IF_RUN_TOO_EARLY 1
  532. #endif])
  533. # MinGW uses autoconf, but also needs the windows shim routines
  534. # (since it doesn't have its own support for, say, pthreads).
  535. # This requires us to #include a special header file, and also to
  536. # link in some windows versions of .o's instead of the unix versions.
  537. #
  538. # Also, manually mark systems where we have to be careful how early
  539. # we run pthreads. TODO(csilvers): turn this into an autoconf check.
  540. AH_BOTTOM([
  541. #ifdef __MINGW32__
  542. #include "windows/mingw.h"
  543. #endif
  544. #endif /* #ifndef GPERFTOOLS_CONFIG_H_ */
  545. ])
  546. AM_CONDITIONAL(MINGW, expr $host : '.*-mingw' >/dev/null 2>&1)
  547. AM_CONDITIONAL(OSX, expr $host : '.*-apple-darwin.*' >/dev/null 2>&1)
  548. # Export the --enable flags we set above. We do this at the end so
  549. # other configure rules can enable or disable targets based on what
  550. # they find.
  551. AM_CONDITIONAL(WITH_CPU_PROFILER, test "$enable_cpu_profiler" = yes)
  552. AM_CONDITIONAL(WITH_HEAP_PROFILER, test "$enable_heap_profiler" = yes)
  553. AM_CONDITIONAL(WITH_HEAP_CHECKER, test "$enable_heap_checker" = yes)
  554. AM_CONDITIONAL(WITH_DEBUGALLOC, test "$enable_debugalloc" = yes)
  555. # We make tcmalloc.so if either heap-profiler or heap-checker is asked for.
  556. AM_CONDITIONAL(WITH_HEAP_PROFILER_OR_CHECKER,
  557. test "$enable_heap_profiler" = yes -o \
  558. "$enable_heap_checker" = yes)
  559. # If we don't use any profilers, we don't need stack traces (or pprof)
  560. AM_CONDITIONAL(WITH_STACK_TRACE, test "$enable_cpu_profiler" = yes -o \
  561. "$enable_heap_profiler" = yes -o \
  562. "$enable_heap_checker" = yes)
  563. have_linux_sigev_thread_id=no
  564. AC_MSG_CHECKING([for Linux SIGEV_THREAD_ID])
  565. AC_COMPILE_IFELSE(
  566. [AC_LANG_PROGRAM([[#include <signal.h>
  567. #include <time.h>]],
  568. [[return SIGEV_THREAD_ID || CLOCK_THREAD_CPUTIME_ID || __linux;]])],
  569. [AC_DEFINE(HAVE_LINUX_SIGEV_THREAD_ID, 1,
  570. [Define if this is Linux that has SIGEV_THREAD_ID])
  571. have_linux_sigev_thread_id=yes
  572. AC_MSG_RESULT([yes])],
  573. [AC_MSG_RESULT([no])])
  574. # Disable large allocation report by default.
  575. AC_ARG_ENABLE([large-alloc-report],
  576. [AS_HELP_STRING([--enable-large-alloc-report],
  577. [report very large allocations to stderr])],
  578. [enable_large_alloc_report="$enableval"],
  579. [enable_large_alloc_report=no])
  580. AS_IF([test "x$enable_large_alloc_report" = xyes],
  581. [AC_DEFINE([ENABLE_LARGE_ALLOC_REPORT], 1, [report large allocation])])
  582. # Enable aggressive decommit by default
  583. AC_ARG_ENABLE([aggressive-decommit-by-default],
  584. [AS_HELP_STRING([--enable-aggressive-decommit-by-default],
  585. [enable aggressive decommit by default])],
  586. [enable_aggressive_decommit_by_default="$enableval"],
  587. [enable_aggressive_decommit_by_default=no])
  588. AS_IF([test "x$enable_aggressive_decommit_by_default" = xyes],
  589. [AC_DEFINE([ENABLE_AGGRESSIVE_DECOMMIT_BY_DEFAULT],
  590. 1,
  591. [enable aggressive decommit by default])])
  592. # Write generated configuration file
  593. AC_CONFIG_FILES([Makefile
  594. src/gperftools/tcmalloc.h src/windows/gperftools/tcmalloc.h])
  595. AC_OUTPUT
  596. AS_IF([test "$x86_no_fp_by_default" = yes && test "x$enable_frame_pointers" != xyes && test "x$UNWIND_LIBS" = x && test "x$enable_minimal" != xyes],
  597. [AS_IF([test "x$perftools_cv_have_unwind_backtrace" = xyes],
  598. [AC_MSG_WARN([No frame pointers and no libunwind. Using experimental backtrace capturing via libgcc. Expect crashy cpu profiler.])],
  599. [AS_IF([test "x$enable_backtrace" = xyes],
  600. [AC_MSG_WARN([No frame pointers and no libunwind. Using experimental backtrace(). Expect crashy cpu profiler.])],
  601. [AC_MSG_FAILURE([No frame pointers and no libunwind. The compilation will fail])])])])