configure.ac 28 KB

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