configure.ac 28 KB

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