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