blob: 3a99b85106754f38cd679773f150ccbe29dfe61e [file] [log] [blame]
csilvers51b48752007-03-22 03:00:33 +00001## Process this file with autoconf to produce configure.
csilversc437e1f2007-07-18 18:30:50 +00002## In general, the safest way to proceed is to run ./autogen.sh
csilvers51b48752007-03-22 03:00:33 +00003
4# make sure we're interpreted by some minimal autoconf
Aliaksey Kandratsenka43809082013-08-29 18:51:48 +03005AC_PREREQ([2.59])
csilvers51b48752007-03-22 03:00:33 +00006
Aliaksey Kandratsenka632de292016-03-12 11:48:20 -08007AC_INIT([gperftools],[2.5],[gperftools@googlegroups.com])
csilvers7375b4f2011-02-05 00:19:37 +00008# 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
Aliaksey Kandratsenka632de292016-03-12 11:48:20 -080010TCMALLOC_SO_VERSION=7:0:3
11PROFILER_SO_VERSION=4:8:4
csilvers3014cf12010-11-18 01:07:25 +000012
13AC_SUBST(TCMALLOC_SO_VERSION)
14AC_SUBST(PROFILER_SO_VERSION)
15
csilvers51b48752007-03-22 03:00:33 +000016# The argument here is just something that should be in the current directory
17# (for sanity checking)
18AC_CONFIG_SRCDIR(README)
csilvers3014cf12010-11-18 01:07:25 +000019AC_CONFIG_MACRO_DIR([m4])
csilversedd03a82009-03-11 20:50:03 +000020AC_CANONICAL_HOST
csilversc437e1f2007-07-18 18:30:50 +000021AM_INIT_AUTOMAKE([dist-zip])
chappedm@gmail.com1363bc62012-11-04 17:21:00 +000022AC_CONFIG_HEADERS([src/config.h])
csilvers51b48752007-03-22 03:00:33 +000023
Aliaksey Kandratsenkaf8a21632013-12-06 12:23:48 -080024AM_MAINTAINER_MODE()
csilvers19dfa9e2009-09-11 18:42:32 +000025# Export the version information (for tc_version and friends)
26TC_VERSION_MAJOR=`expr "$PACKAGE_VERSION" : '\([[0-9]]*\)'`
csilversf633b402011-08-11 22:06:22 +000027TC_VERSION_MINOR=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.\([[0-9]]*\)'`
28TC_VERSION_PATCH=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.[[0-9]]*\(.*\)$'`
csilvers19dfa9e2009-09-11 18:42:32 +000029AC_SUBST(TC_VERSION_MAJOR)
30AC_SUBST(TC_VERSION_MINOR)
31AC_SUBST(TC_VERSION_PATCH)
32AC_SUBST(PACKAGE_STRING)
33
csilversedd03a82009-03-11 20:50:03 +000034# The user can choose not to compile in the heap-profiler, the
35# heap-checker, or the cpu-profiler. There's also the possibility
36# for a 'fully minimal' compile, which leaves out the stacktrace
37# code as well. By default, we include all of these that the
38# target system supports.
39default_enable_cpu_profiler=yes
40default_enable_heap_profiler=yes
41default_enable_heap_checker=yes
csilvers19dfa9e2009-09-11 18:42:32 +000042default_enable_debugalloc=yes
csilversedd03a82009-03-11 20:50:03 +000043default_enable_minimal=no
Raphael Moreira Zinsly3f55d872014-12-23 10:29:49 -020044default_tcmalloc_alignment=16
csilversedd03a82009-03-11 20:50:03 +000045need_nanosleep=yes # Used later, to decide if to run ACX_NANOSLEEP
46case "$host" in
csilvers19dfa9e2009-09-11 18:42:32 +000047 *-mingw*) default_enable_minimal=yes; default_enable_debugalloc=no;
48 need_nanosleep=no;;
csilversbeb6a9a2009-04-18 00:02:25 +000049 *-cygwin*) default_enable_heap_checker=no; default_enable_cpu_profiler=no;;
csilversedd03a82009-03-11 20:50:03 +000050 *-freebsd*) default_enable_heap_checker=no;;
51 *-darwin*) default_enable_heap_checker=no;;
52esac
53
Bryan Chan644a6bd2016-01-22 12:26:47 -050054# Currently only backtrace works on s390x.
55AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __s390x__])],
56 [default_enable_libunwind=no
57 default_enable_backtrace=yes],
58 [default_enable_libunwind=yes
59 default_enable_backtrace=no])
60
Raphael Moreira Zinsly8eb4ed72014-11-27 14:11:09 -020061# Disable libunwind linking on ppc64 by default.
62AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __PPC64__])],
Raphael Moreira Zinslyb8b027d2014-12-23 10:55:22 -020063 [default_enable_libunwind=no
64 default_tcmalloc_pagesize=64],
65 [default_enable_libunwind=yes
66 default_tcmalloc_pagesize=8])
Raphael Moreira Zinsly8eb4ed72014-11-27 14:11:09 -020067
csilversedd03a82009-03-11 20:50:03 +000068AC_ARG_ENABLE([cpu-profiler],
69 [AS_HELP_STRING([--disable-cpu-profiler],
70 [do not build the cpu profiler])],
71 [],
72 [enable_cpu_profiler="$default_enable_cpu_profiler"])
73AC_ARG_ENABLE([heap-profiler],
74 [AS_HELP_STRING([--disable-heap-profiler],
75 [do not build the heap profiler])],
76 [],
77 [enable_heap_profiler="$default_enable_heap_profiler"])
78AC_ARG_ENABLE([heap-checker],
79 [AS_HELP_STRING([--disable-heap-checker],
80 [do not build the heap checker])],
81 [],
82 [enable_heap_checker="$default_enable_heap_checker"])
csilvers19dfa9e2009-09-11 18:42:32 +000083AC_ARG_ENABLE([debugalloc],
84 [AS_HELP_STRING([--disable-debugalloc],
85 [do not build versions of libs with debugalloc])],
86 [],
87 [enable_debugalloc="$default_enable_debugalloc"])
csilversedd03a82009-03-11 20:50:03 +000088AC_ARG_ENABLE([minimal],
89 [AS_HELP_STRING([--enable-minimal],
csilvers19dfa9e2009-09-11 18:42:32 +000090 [build only tcmalloc-minimal (and maybe tcmalloc-minimal-debug)])],
csilversedd03a82009-03-11 20:50:03 +000091 [],
92 [enable_minimal="$default_enable_minimal"])
93if test "$enable_minimal" = yes; then
94 enable_cpu_profiler=no
95 enable_heap_profiler=no
96 enable_heap_checker=no
97fi
Aliaksey Kandratsenka125e5ed2014-04-12 12:38:19 -070098AC_ARG_ENABLE([stacktrace-via-backtrace],
99 [AS_HELP_STRING([--enable-stacktrace-via-backtrace],
100 [enable use of backtrace() for stacktrace capturing (may deadlock)])],
101 [enable_backtrace=yes],
Bryan Chan644a6bd2016-01-22 12:26:47 -0500102 [enable_backtrace="$default_enable_backtrace"])
Raphael Moreira Zinsly8eb4ed72014-11-27 14:11:09 -0200103AC_ARG_ENABLE([libunwind],
104 [AS_HELP_STRING([--enable-libunwind],
105 [enable libunwind linking])],
106 [],
107 [enable_libunwind="$default_enable_libunwind"])
Raphael Moreira Zinsly3f55d872014-12-23 10:29:49 -0200108AC_ARG_WITH([tcmalloc-pagesize],
109 [AS_HELP_STRING([--with-tcmalloc-pagesize],
110 [Set the tcmalloc internal page size to 8K, 32K or 64K])],
111 [],
112 [with_tcmalloc_pagesize=$default_tcmalloc_pagesize])
113AC_ARG_WITH([tcmalloc-alignment],
114 [AS_HELP_STRING([--with-tcmalloc-alignment],
115 [Set the tcmalloc allocation alignment to 8 or 16 bytes])],
116 [],
117 [with_tcmalloc_alignment=$default_tcmalloc_alignment])
118
119case "$with_tcmalloc_pagesize" in
120 8)
121 #Default tcmalloc page size.
122 ;;
123 32)
124 AC_DEFINE(TCMALLOC_32K_PAGES, 1,
125 [Define 32K of internal pages size for tcmalloc]);;
126 64)
127 AC_DEFINE(TCMALLOC_64K_PAGES, 1,
128 [Define 64K of internal pages size for tcmalloc]);;
129 *)
130 AC_MSG_WARN([${with_tcmalloc_pagesize}K size not supported, using default tcmalloc page size.])
131esac
132case "$with_tcmalloc_alignment" in
133 8)
134 AC_DEFINE(TCMALLOC_ALIGN_8BYTES, 1,
135 [Define 8 bytes of allocation alignment for tcmalloc]);;
136 16)
137 #Default tcmalloc allocation alignment.
138 ;;
139 *)
140 AC_MSG_WARN([${with_tcmalloc_alignment} bytes not supported, using default tcmalloc allocation alignment.])
141esac
csilversedd03a82009-03-11 20:50:03 +0000142
csilvers51b48752007-03-22 03:00:33 +0000143# Checks for programs.
csilversa6076ed2011-10-18 20:57:45 +0000144AC_PROG_CXX
csilvers51b48752007-03-22 03:00:33 +0000145AC_PROG_CC
146AC_PROG_CPP
csilvers49b74b92007-08-17 20:56:15 +0000147AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
csilversbeb6a9a2009-04-18 00:02:25 +0000148AM_PROG_CC_C_O # shrug: autogen.sh suddenly needs this for some reason
149
csilvers2197cc62009-06-10 02:04:26 +0000150# Check if we have an objcopy installed that supports -W
151AC_CHECK_TOOL([OBJCOPY], [objcopy], [])
csilvers8c7d2282011-05-19 21:37:12 +0000152AS_IF([test -n "$OBJCOPY"], [dnl
153 AC_CACHE_CHECK([if $OBJCOPY supports -W], gpt_cv_objcopy_weaken, [dnl
chappedm@gmail.com1363bc62012-11-04 17:21:00 +0000154 AC_LINK_IFELSE([AC_LANG_PROGRAM([void foo() {} int main() {return 0;}])], [dnl
csilvers8c7d2282011-05-19 21:37:12 +0000155 AS_IF(["$OBJCOPY" -W foo conftest$ac_exeext /dev/null],
156 [gpt_cv_objcopy_weaken=yes], [gpt_cv_objcopy_weaken=no])],
157 [gpt_cv_objcopy_weaken=no])])],
158 [gpt_cv_objcopy_weaken=no])
159AM_CONDITIONAL(HAVE_OBJCOPY_WEAKEN, test $gpt_cv_objcopy_weaken = yes)
csilvers2197cc62009-06-10 02:04:26 +0000160
Aliaksey Kandratsenkaf2163172013-11-16 15:05:45 -0800161AC_PROG_LIBTOOL
csilvers51b48752007-03-22 03:00:33 +0000162
163AC_C_INLINE
164AX_C___ATTRIBUTE__
165
166# Check whether some low-level functions/files are available
167AC_HEADER_STDC
168
csilversedd03a82009-03-11 20:50:03 +0000169# TODO(csilvers): we could remove a lot when WITH_CPU_PROFILER etc is "no".
csilvers51b48752007-03-22 03:00:33 +0000170AC_CHECK_TYPES([__int64]) # defined in some windows platforms
csilvers74ad5d52007-04-16 20:49:32 +0000171AC_CHECK_TYPES([struct mallinfo],,, [#include <malloc.h>])
csilversedd03a82009-03-11 20:50:03 +0000172AC_CHECK_TYPES([Elf32_Versym],,, [#include <elf.h>]) # for vdso_support.h
csilvers51b48752007-03-22 03:00:33 +0000173AC_CHECK_FUNCS(sbrk) # for tcmalloc to get memory
csilversc437e1f2007-07-18 18:30:50 +0000174AC_CHECK_FUNCS(geteuid) # for turning off services when run as root
chappedm@gmail.combd3b3a72013-03-10 20:17:21 +0000175AC_CHECK_FUNCS(fork) # for the pthread_atfork setup
csilvers2197cc62009-06-10 02:04:26 +0000176AC_CHECK_HEADERS(features.h) # for vdso_support.h
csilversc437e1f2007-07-18 18:30:50 +0000177AC_CHECK_HEADERS(malloc.h) # some systems define stuff there, others not
178AC_CHECK_HEADERS(glob.h) # for heap-profile-table (cleaning up profiles)
csilvers91fad382007-03-22 03:28:56 +0000179AC_CHECK_HEADERS(execinfo.h) # for stacktrace? and heapchecker_unittest
csilvers74ad5d52007-04-16 20:49:32 +0000180AC_CHECK_HEADERS(unwind.h) # for stacktrace
csilvers2197cc62009-06-10 02:04:26 +0000181AC_CHECK_HEADERS(sched.h) # for being nice in our spinlock code
csilvers19dfa9e2009-09-11 18:42:32 +0000182AC_CHECK_HEADERS(conflict-signal.h) # defined on some windows platforms?
csilvers49b74b92007-08-17 20:56:15 +0000183AC_CHECK_HEADERS(sys/prctl.h) # for thread_lister (needed by leak-checker)
184AC_CHECK_HEADERS(linux/ptrace.h)# also needed by leak-checker
185AC_CHECK_HEADERS(sys/syscall.h)
csilversedd03a82009-03-11 20:50:03 +0000186AC_CHECK_HEADERS(sys/socket.h) # optional; for forking out to symbolizer
187AC_CHECK_HEADERS(sys/wait.h) # optional; for forking out to symbolizer
csilvers19dfa9e2009-09-11 18:42:32 +0000188AC_CHECK_HEADERS(poll.h) # optional; for forking out to symbolizer
csilvers49b74b92007-08-17 20:56:15 +0000189AC_CHECK_HEADERS(fcntl.h) # for tcmalloc_unittest
csilvers91fad382007-03-22 03:28:56 +0000190AC_CHECK_HEADERS(grp.h) # for heapchecker_unittest
csilvers74ad5d52007-04-16 20:49:32 +0000191AC_CHECK_HEADERS(pwd.h) # for heapchecker_unittest
csilvers100e6572008-06-14 02:30:53 +0000192AC_CHECK_HEADERS(sys/resource.h) # for memalign_unittest.cc
csilvers92beff82010-03-23 20:39:55 +0000193AC_CHECK_HEADERS(valgrind.h) # we have a local copy if this isn't found
csilvers8c7d2282011-05-19 21:37:12 +0000194AC_CHECK_HEADERS(sys/cdefs.h) # Where glibc defines __THROW
195AC_CHECK_HEADERS(features.h) # Where __GLIBC__ is defined
csilvers92beff82010-03-23 20:39:55 +0000196# We also need <ucontext.h>/<sys/ucontext.h>, but we get those from
197# AC_PC_FROM_UCONTEXT, below.
198
csilversc437e1f2007-07-18 18:30:50 +0000199# We override a lot of memory allocation routines, not all of which are
200# standard. For those the system doesn't declare, we'll declare ourselves.
201AC_CHECK_DECLS([cfree,
202 posix_memalign,
203 memalign,
204 valloc,
205 pvalloc],,,
206 [#define _XOPEN_SOURCE 600
207 #include <stdlib.h>
208 #include <malloc.h>])
209
csilvers2197cc62009-06-10 02:04:26 +0000210if test "$ac_cv_type_struct_mallinfo" = yes; then
csilvers4e9432c2012-02-04 00:07:36 +0000211 AC_SUBST(ac_cv_have_struct_mallinfo, 1) # gperftools/tcmalloc.h needs this
csilvers2197cc62009-06-10 02:04:26 +0000212else
213 AC_SUBST(ac_cv_have_struct_mallinfo, 0)
214fi
215
csilvers100e6572008-06-14 02:30:53 +0000216# We need to check for mmap. cygwin supports mmap, but the autoconf
217# test doesn't work on cygwin:
218# http://www.cygwin.com/ml/cygwin/2002-04/msg00412.html
219# This workaround comes from
220# http://cygwin.com/ml/cygwin/2004-11/msg00138.html
221case "$host" in
alkondratenko@gmail.com8bf45222013-03-11 19:15:46 +0000222 *-*-mingw*)
223 dnl mingw doesn't have mmap, not worth
224 dnl checking. Especially given that mingw can be a
225 dnl cross-compiler
226 ;;
csilvers8c7d2282011-05-19 21:37:12 +0000227 *-*-cygwin*)
228 ac_cv_func_mmap_fixed_mapped=yes
csilvers100e6572008-06-14 02:30:53 +0000229 AC_DEFINE(HAVE_MMAP, 1,
230 [Define to 1 if you have a working `mmap' system call.])
231 ;;
chappedm@gmail.com86a55312012-11-04 19:12:42 +0000232 *) if test "$cross_compiling" = yes; then
233 ac_cv_func_mmap_fixed_mapped=yes
234 AC_DEFINE(HAVE_MMAP, 1,
235 [Define to 1 if you have a working `mmap' system call.])
236 else
237 AC_FUNC_MMAP
238 fi
csilvers100e6572008-06-14 02:30:53 +0000239 ;;
240esac
241
csilversc437e1f2007-07-18 18:30:50 +0000242# If AtomicWord != Atomic32, we need to define two versions of all the
243# atomicops functions. If they're the same, we want to define only one.
244AC_MSG_CHECKING([if int32_t is the same type as intptr_t])
chappedm@gmail.com1363bc62012-11-04 17:21:00 +0000245AC_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,
csilversc437e1f2007-07-18 18:30:50 +0000246 Define to 1 if int32_t is equivalent to intptr_t)
chappedm@gmail.com1363bc62012-11-04 17:21:00 +0000247 AC_MSG_RESULT([yes])],[AC_MSG_RESULT([no])])
csilvers74ad5d52007-04-16 20:49:32 +0000248
csilvers49b74b92007-08-17 20:56:15 +0000249# We want to access the "PC" (Program Counter) register from a struct
250# ucontext. Every system has its own way of doing that. We try all the
251# possibilities we know about. Note REG_PC should come first (REG_RIP
csilversedd03a82009-03-11 20:50:03 +0000252# is also defined on solaris, but does the wrong thing). But don't
253# bother if we're not doing cpu-profiling.
254# [*] means that we've not actually tested one of these systems
255if test "$enable_cpu_profiler" = yes; then
csilvers5b80f012009-11-10 16:24:57 +0000256 AC_PC_FROM_UCONTEXT(AC_MSG_WARN(Could not find the PC. Will not try to compile libprofiler...);
csilvers19dfa9e2009-09-11 18:42:32 +0000257 enable_cpu_profiler=no)
csilvers49b74b92007-08-17 20:56:15 +0000258fi
259
csilvers5b80f012009-11-10 16:24:57 +0000260# Some tests test the behavior of .so files, and only make sense for dynamic.
261AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
262
Raphael Moreira Zinsly8eb4ed72014-11-27 14:11:09 -0200263# We want to link in libunwind or libexecinfo if it it is enabled and exists.
264if test "$enable_libunwind" = yes; then
265 AC_CHECK_HEADERS(libunwind.h) # for stacktrace
266 AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind,
267 [AC_CHECK_LIB(execinfo, backtrace, UNWIND_LIBS=-lexecinfo, UNWIND_LIBS=)])
268 AC_SUBST(UNWIND_LIBS)
Aliaksey Kandratsenka4f3410e2016-02-21 13:52:47 -0800269 will_use_libunwind=yes
Raphael Moreira Zinsly8eb4ed72014-11-27 14:11:09 -0200270else
271 AC_CHECK_LIB(execinfo, backtrace, UNWIND_LIBS=-lexecinfo, UNWIND_LIBS=)
272 AC_SUBST(UNWIND_LIBS)
273fi
csilvers74ad5d52007-04-16 20:49:32 +0000274
chappedm@gmail.comc5662662012-11-03 14:13:21 +0000275# On x86_64, instead of libunwind, we can choose to compile with frame-pointers.
csilvers8a0a3102008-02-13 00:55:09 +0000276AC_ARG_ENABLE(frame_pointers,
277 AS_HELP_STRING([--enable-frame-pointers],
csilvers74ad5d52007-04-16 20:49:32 +0000278 [On x86_64 systems, compile with -fno-omit-frame-pointer (see INSTALL)]),
csilvers8a0a3102008-02-13 00:55:09 +0000279 , enable_frame_pointers=no)
csilvers5b80f012009-11-10 16:24:57 +0000280AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes)
281
Aliaksey Kandratsenkab5e584d2014-02-16 19:41:37 -0800282AC_MSG_CHECKING([for x86 without frame pointers])
chappedm@gmail.comc5662662012-11-03 14:13:21 +0000283# Some x86_64 systems do not insert frame pointers by default.
csilvers5b80f012009-11-10 16:24:57 +0000284# We want to see if the current system is one of those.
csilvers74ad5d52007-04-16 20:49:32 +0000285AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])],
286 [is_x86_64=yes], [is_x86_64=no])
csilvers5b80f012009-11-10 16:24:57 +0000287OLD_CFLAGS="$CFLAGS"
288CFLAGS="$CFLAGS -S -O2 -o fp.s"
289# This test will always fail because we don't name our output file properly.
290# We do our own determination of success/failure in the grep, below.
291AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int f(int x) {return x;}], [return f(0);])],
292 [:], [:])
Aliaksey Kandratsenkab5e584d2014-02-16 19:41:37 -0800293x86_no_fp_by_default=no
294AS_IF([test "$is_x86_64" = yes && ! grep 'mov.*rsp.*rbp' fp.s >/dev/null 2>&1], [x86_no_fp_by_default=yes])
csilvers5b80f012009-11-10 16:24:57 +0000295AM_CONDITIONAL(X86_64_AND_NO_FP_BY_DEFAULT,
Aliaksey Kandratsenkab5e584d2014-02-16 19:41:37 -0800296 test "$x86_no_fp_by_default" = yes)
csilvers5b80f012009-11-10 16:24:57 +0000297rm fp.s
298CFLAGS="$OLD_CFLAGS"
Aliaksey Kandratsenkab5e584d2014-02-16 19:41:37 -0800299AC_MSG_RESULT([$x86_no_fp_by_default])
300
csilvers5b80f012009-11-10 16:24:57 +0000301
csilvers2a7b3b82011-12-23 00:45:49 +0000302# We need to know if we're i386 so we can turn on -mmms, which is not
303# on by default for i386 (it is for x86_64).
304AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __i386__ == 1 ? 0 : 1])],
305 [is_i386=yes], [is_i386=no])
306AM_CONDITIONAL(I386, test "$is_i386" = yes)
307
csilvers100c38c2011-07-16 01:07:10 +0000308# See if the compiler supports -Wno-unused-result.
309# Newer ubuntu's turn on -D_FORTIFY_SOURCE=2, enabling
310# __attribute__((warn_unused_result)) for things like write(),
311# which we don't care about.
312AC_CACHE_CHECK([if the compiler supports -Wno-unused-result],
313 perftools_cv_w_no_unused_result,
314 [OLD_CFLAGS="$CFLAGS"
Aliaksey Kandratsenka8cc75ac2015-10-04 11:04:12 -0700315 CFLAGS="$CFLAGS -Wno-error -Wunused-result"
csilvers100c38c2011-07-16 01:07:10 +0000316 # gcc doesn't warn about unknown flags unless it's
317 # also warning for some other purpose, hence the
318 # divide-by-0. (We use -Wno-error to make sure the
319 # divide-by-0 doesn't cause this test to fail!)
Aliaksey Kandratsenka8cc75ac2015-10-04 11:04:12 -0700320 #
321 # Also gcc is giving only warning for unknown flags of
322 # -Wno-XXX form. So in order to detect support we're
323 # using -Wunused-result which will cause gcc to give
324 # error which we can detect.
csilvers100c38c2011-07-16 01:07:10 +0000325 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return 1/0)],
326 perftools_cv_w_no_unused_result=yes,
327 perftools_cv_w_no_unused_result=no)
328 CFLAGS="$OLD_CFLAGS"])
329AM_CONDITIONAL(HAVE_W_NO_UNUSED_RESULT,
330 test "$perftools_cv_w_no_unused_result" = yes)
csilvers51b48752007-03-22 03:00:33 +0000331
Aliaksey Kandratsenka6fdfc5a2015-10-24 23:16:45 -0700332AC_ARG_ENABLE([dynamic-sized-delete-support],
Aliaksey Kandratsenka06811b32016-03-05 15:08:50 -0800333 [AS_HELP_STRING([--enable-dynamic-sized-delete-support],
334 [try to build run-time switch for sized delete operator])],
Aliaksey Kandratsenka6fdfc5a2015-10-24 23:16:45 -0700335 [enable_dyn_sized_delete="$enableval"],
Aliaksey Kandratsenka06811b32016-03-05 15:08:50 -0800336 [enable_dyn_sized_delete=no])
Aliaksey Kandratsenka6fdfc5a2015-10-24 23:16:45 -0700337
338AS_IF([test "x$enable_dyn_sized_delete" = xyes],
339 [AC_DEFINE([ENABLE_DYNAMIC_SIZED_DELETE], 1,
340 [Build runtime detection for sized delete])])
341
Aliaksey Kandratsenkaa9db0ae2015-10-04 21:12:28 -0700342AC_ARG_ENABLE([sized-delete],
343 [AS_HELP_STRING([--enable-sized-delete],
344 [build sized delete operator])],
345 [enable_sized_delete="$enableval"],
346 [enable_sized_delete="no"])
347AS_IF([test "x$enable_sized_delete" = xyes],
348 [AC_DEFINE([ENABLE_SIZED_DELETE], 1, [Build sized deletion operators])
349 AC_MSG_NOTICE([Will build sized deallocation operators])],
Aliaksey Kandratsenka08e034a2016-02-06 16:19:54 -0800350 [AS_IF([test "x$enable_dyn_sized_delete" = xyes],
351 [AC_MSG_NOTICE([Will build dynamically detected sized deallocation operators])],
352 [AC_MSG_NOTICE([Will not build sized deallocation operators])])])
Aliaksey Kandratsenkaa9db0ae2015-10-04 21:12:28 -0700353
Aliaksey Kandratsenka782165f2016-03-05 15:47:25 -0800354AC_CACHE_CHECK([if C++ compiler supports -fsized-deallocation],
355 [perftools_cv_sized_deallocation_result],
356 [AC_LANG_PUSH(C++)
357 OLD_CXXFLAGS="$CXXFLAGS"
358 CXXFLAGS="$CXXFLAGS -fsized-deallocation"
359 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,)],
360 perftools_cv_sized_deallocation_result=yes,
361 perftools_cv_sized_deallocation_result=no)
362 CXXFLAGS="$OLD_CXXFLAGS"
363 AC_LANG_POP(C++)])
Aliaksey Kandratsenkaa9db0ae2015-10-04 21:12:28 -0700364
Aliaksey Kandratsenka88686972015-10-04 11:15:37 -0700365AM_CONDITIONAL(HAVE_SIZED_DEALLOCATION,
366 test "$perftools_cv_sized_deallocation_result" = yes)
367
Aliaksey Kandratsenka9095ed02016-02-20 20:33:27 -0800368AC_CACHE_CHECK([if target has _Unwind_Backtrace],
369 [perftools_cv_have_unwind_backtrace],
370 [AC_LANG_PUSH(C++)
371 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
372 [[#include <unwind.h>]],
373 [[&_Unwind_Backtrace]])],
374 [perftools_cv_have_unwind_backtrace=yes],
375 [perftools_cv_have_unwind_backtrace=no])
376 AC_LANG_POP(C++)])
377AS_IF([test "x$perftools_cv_have_unwind_backtrace" = xyes],
378 [AC_DEFINE(HAVE_UNWIND_BACKTRACE, 1, [Whether <unwind.h> contains _Unwind_Backtrace])])
379
Aliaksey Kandratsenka4f3410e2016-02-21 13:52:47 -0800380AS_IF([test "x$enable_backtrace" = xyes],
381 [default_emergency_malloc=yes],
382 [default_emergency_malloc=no])
383
384AS_IF([test "x$will_use_libunwind" = xyes],
385 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __arm__])],
386 [default_emergency_malloc=yes])])
387
Aliaksey Kandratsenka7f120512016-01-31 23:17:50 -0800388AC_ARG_ENABLE([emergency-malloc],
389 [AS_HELP_STRING([--enable-emergency-malloc],
390 [build emergency malloc feature])],
391 [enable_emergency_malloc="$enableval"],
Aliaksey Kandratsenka4f3410e2016-02-21 13:52:47 -0800392 [enable_emergency_malloc="$default_emergency_malloc"])
Aliaksey Kandratsenka7f120512016-01-31 23:17:50 -0800393
394AM_CONDITIONAL(BUILD_EMERGENCY_MALLOC, [test "x$enable_emergency_malloc" = xyes])
395
csilvers51b48752007-03-22 03:00:33 +0000396# Defines PRIuS
397AC_COMPILER_CHARACTERISTICS
398
csilvers49b74b92007-08-17 20:56:15 +0000399# 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)
401AH_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
csilvers91fad382007-03-22 03:28:56 +0000407# Check if __builtin_stack_pointer() is available (for elfcore.h)
408AC_MSG_CHECKING([for __builtin_stack_pointer()])
csilvers74ad5d52007-04-16 20:49:32 +0000409AC_LINK_IFELSE([AC_LANG_PROGRAM(, [void *sp = __builtin_stack_pointer()])],
csilvers91fad382007-03-22 03:28:56 +0000410 [AC_DEFINE(HAVE_BUILTIN_STACK_POINTER, 1,
411 Define to 1 if compiler supports __builtin_stack_pointer)
412 AC_MSG_RESULT([yes])],
413 [AC_MSG_RESULT([no])])
414
chappedm@gmail.com84b983c2012-12-22 20:06:47 +0000415# Check for __builtin_expect()
416AC_MSG_CHECKING([for __builtin_expect()])
417AC_LINK_IFELSE([AC_LANG_PROGRAM(, return __builtin_expect(main != 0, 1))],
418 [AC_DEFINE(HAVE_BUILTIN_EXPECT, 1,
419 Define to 1 if compiler supports __builtin_expect)
420 AC_MSG_RESULT([yes])],
421 [AC_MSG_RESULT([no])])
422
csilversa94d5f72009-12-02 18:15:13 +0000423# Check if __environ is available (for GetenvBeforeMain)
424AC_MSG_CHECKING([for __environ])
425AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>],
426 [char **env = __environ])],
427 [AC_DEFINE(HAVE___ENVIRON, 1,
428 [Define to 1 if compiler supports __environ])
429 AC_MSG_RESULT([yes])],
430 [AC_MSG_RESULT([no])])
431
csilvers74ad5d52007-04-16 20:49:32 +0000432# If we support __thread, that can speed up tcmalloc a bit.
csilvers6fa2a252008-12-13 01:35:42 +0000433# Note, however, that our code tickles a bug in gcc < 4.1.2
434# involving TLS and -fPIC (which our libraries will use) on x86:
435# http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
alkondratenko@gmail.com7896dcb2013-03-11 19:16:47 +0000436#
437# And mingw also does compile __thread but resultant code actually
438# fails to work correctly at least in some not so ancient version:
439# http://mingw-users.1079350.n2.nabble.com/gcc-4-4-multi-threaded-exception-handling-amp-thread-specifier-not-working-td3440749.html
xiaoyur34760b12172014-01-11 11:39:53 +0800440#
441# Also it was reported that earlier gcc versions for mips compile
442# __thread but it doesn't really work
csilvers74ad5d52007-04-16 20:49:32 +0000443AC_MSG_CHECKING([for __thread])
xiaoyur34760b12172014-01-11 11:39:53 +0800444AC_LINK_IFELSE([AC_LANG_PROGRAM([#if defined(__GNUC__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 1) || (__GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ < 2))
csilvers6fa2a252008-12-13 01:35:42 +0000445#error gcc has this bug: http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
Aliaksey Kandratsenka819a2b02013-08-29 19:00:31 +0300446#elif defined(__MINGW32__)
Aliaksey Kandratsenkae9837152014-01-11 16:28:15 -0800447#error mingw doesnt really support tls
Aliaksey Kandratsenka819a2b02013-08-29 19:00:31 +0300448#elif defined(__APPLE__)
449#error OSX __thread support is known to call malloc which makes it unsafe to use from malloc replacement
alkondratenko@gmail.com7896dcb2013-03-11 19:16:47 +0000450#endif
451], [static __thread int p = 0])],
csilvers74ad5d52007-04-16 20:49:32 +0000452 [AC_DEFINE(HAVE_TLS, 1,
csilvers100c38c2011-07-16 01:07:10 +0000453 Define to 1 if compiler supports __thread)
csilvers74ad5d52007-04-16 20:49:32 +0000454 AC_MSG_RESULT([yes])],
455 [AC_MSG_RESULT([no])])
456
csilvers100c38c2011-07-16 01:07:10 +0000457# glibc's __malloc_hook/etc were declared volatile starting in glibc 2.14
458AC_MSG_CHECKING([if __malloc_hook is declared volatile])
459AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <malloc.h>
460void* (* volatile __malloc_hook)(size_t, const void*) = 0;],)],
461 [AC_DEFINE(MALLOC_HOOK_MAYBE_VOLATILE, volatile,
462 Define to 'volatile' if __malloc_hook is declared volatile)
463 AC_MSG_RESULT([yes])],
csilversd2faf462011-07-27 04:18:01 +0000464 [AC_DEFINE(MALLOC_HOOK_MAYBE_VOLATILE, )
csilvers100c38c2011-07-16 01:07:10 +0000465 AC_MSG_RESULT([no])])
466
csilversedd03a82009-03-11 20:50:03 +0000467# Nanosleep requires extra libraries on some architectures (solaris).
468# This sets NANOSLEEP_LIBS. nanosleep doesn't exist on mingw, which
469# is fine for us because we don't compile libspinlock, which uses it.
470if test "$need_nanosleep" = yes; then
471 ACX_NANOSLEEP
472 AC_SUBST(NANOSLEEP_LIBS)
473fi
474
475# Solaris 10 6/06 has a bug where /usr/sfw/lib/libstdc++.la is empty.
476# If so, we replace it with our own version.
477LIBSTDCXX_LA_LINKER_FLAG=
478if test -f /usr/sfw/lib/libstdc++.la && ! test -s /usr/sfw/lib/libstdc++.la
479then
480 LIBSTDCXX_LA_LINKER_FLAG='-L$(top_srcdir)/src/solaris'
481fi
482AC_SUBST(LIBSTDCXX_LA_LINKER_FLAG)
483
csilvers74ad5d52007-04-16 20:49:32 +0000484# We also need to check if the kernel supports __thread, which requires uname()
485AC_CHECK_DECLS(uname,,, [#include <sys/utsname.h>])
486
487# In fact, a lot of the code in this directory depends on pthreads
csilvers51b48752007-03-22 03:00:33 +0000488ACX_PTHREAD
489
Aliaksey Kandratsenka4c274b92014-01-04 18:28:36 -0800490AC_LANG_SAVE
491AC_LANG_CPLUSPLUS
492AC_MSG_CHECKING([whether pthread symbols are available in C++ without including pthread.h])
493acx_pthread_despite_asking_for=no
494AC_LINK_IFELSE(
495 [AC_LANG_PROGRAM([
496 #include <string>
497 #include <vector>
498 ],[
499 pthread_t th; pthread_join(th, 0);
500 ])],[
501 acx_pthread_despite_asking_for=yes
502 AC_DEFINE(HAVE_PTHREAD_DESPITE_ASKING_FOR, 1, [defined to 1 if pthread symbols are exposed even without include pthread.h])
503 AC_DEFINE(HAVE_PTHREAD, 1, [])
504 ])
505AC_MSG_RESULT([$acx_pthread_despite_asking_for])
506AC_LANG_RESTORE
507
Thomas Klausnerfd3379a2014-02-25 21:41:07 +0100508AM_CONDITIONAL(HAVE_PTHREAD_DESPITE_ASKING_FOR, test x"$acx_pthread_despite_asking_for" = xyes)
Aliaksey Kandratsenka4c274b92014-01-04 18:28:36 -0800509
csilvers51b48752007-03-22 03:00:33 +0000510# Find out what namespace 'normal' STL code lives in
511AC_CXX_STL_NAMESPACE
512
csilvers51b48752007-03-22 03:00:33 +0000513# Figure out where libc has program_invocation_name
514AC_PROGRAM_INVOCATION_NAME
515
516# Make the install prefix available, to figure out where to look for pprof
517AC_INSTALL_PREFIX
518
alkondratenko@gmail.comd8e12e92013-07-20 21:35:14 +0000519dnl only very recent mingw has sleep and nanosleep
520case "$host" in
521 *-mingw*)
522 AC_CHECK_DECLS([sleep], [], [], [#include <unistd.h>])
523 AC_CHECK_DECLS([nanosleep], [], [], [#include <time.h>])
524 ;;
525esac
526
Aliaksey Kandratsenka125e5ed2014-04-12 12:38:19 -0700527if test "x$enable_backtrace" = xyes; then
528 AC_CHECK_DECLS([backtrace], [], [], [#include <execinfo.h>])
529fi
alkondratenko@gmail.comd8e12e92013-07-20 21:35:14 +0000530
csilversc437e1f2007-07-18 18:30:50 +0000531# For windows, this has a non-trivial value (__declspec(export)), but any
532# system that uses configure wants this to be the empty string.
533AC_DEFINE(PERFTOOLS_DLL_DECL,,
534 [Always the empty-string on non-windows systems.
535 On windows, should be "__declspec(dllexport)".
536 This way, when we compile the dll, we export our functions/classes.
537 It's safe to define this here because config.h is only used
538 internally, to compile the DLL, and every DLL source file
539 #includes "config.h" before anything else.])
540
csilverscb7393c2010-06-21 15:59:56 +0000541# In theory, config.h files shouldn't need a header guard, but we do,
542# because we (maybe) #include windows/mingw.h from within config.h,
543# and it #includes other .h files. These all have header guards, so
544# the end result is if config.h is #included twice, its #undefs get
545# evaluated twice, but all the ones in mingw.h/etc only get evaluated
546# once, potentially causing trouble. c.f.
csilvers4e9432c2012-02-04 00:07:36 +0000547# http://code.google.com/p/gperftools/issues/detail?id=246
csilverscb7393c2010-06-21 15:59:56 +0000548AH_TOP([
csilvers4e9432c2012-02-04 00:07:36 +0000549#ifndef GPERFTOOLS_CONFIG_H_
550#define GPERFTOOLS_CONFIG_H_
csilverscb7393c2010-06-21 15:59:56 +0000551])
552
csilversc2eedce2011-08-26 21:08:59 +0000553AH_VERBATIM([PTHREADS_CRASHES_IF_RUN_TOO_EARLY],
554 [/* Mark the systems where we know it's bad if pthreads runs too
555 early before main (before threads are initialized, presumably). */
556#ifdef __FreeBSD__
557#define PTHREADS_CRASHES_IF_RUN_TOO_EARLY 1
558#endif])
559
csilvers11b02f72007-11-29 23:39:24 +0000560# MinGW uses autoconf, but also needs the windows shim routines
561# (since it doesn't have its own support for, say, pthreads).
562# This requires us to #include a special header file, and also to
563# link in some windows versions of .o's instead of the unix versions.
csilvers100c38c2011-07-16 01:07:10 +0000564#
565# Also, manually mark systems where we have to be careful how early
566# we run pthreads. TODO(csilvers): turn this into an autoconf check.
csilvers11b02f72007-11-29 23:39:24 +0000567AH_BOTTOM([
568#ifdef __MINGW32__
569#include "windows/mingw.h"
570#endif
csilverscb7393c2010-06-21 15:59:56 +0000571
csilvers4e9432c2012-02-04 00:07:36 +0000572#endif /* #ifndef GPERFTOOLS_CONFIG_H_ */
csilvers11b02f72007-11-29 23:39:24 +0000573])
csilversedd03a82009-03-11 20:50:03 +0000574AM_CONDITIONAL(MINGW, expr $host : '.*-mingw' >/dev/null 2>&1)
csilvers100c38c2011-07-16 01:07:10 +0000575AM_CONDITIONAL(OSX, expr $host : '.*-apple-darwin.*' >/dev/null 2>&1)
csilversedd03a82009-03-11 20:50:03 +0000576
577# Export the --enable flags we set above. We do this at the end so
578# other configure rules can enable or disable targets based on what
579# they find.
580AM_CONDITIONAL(WITH_CPU_PROFILER, test "$enable_cpu_profiler" = yes)
581AM_CONDITIONAL(WITH_HEAP_PROFILER, test "$enable_heap_profiler" = yes)
582AM_CONDITIONAL(WITH_HEAP_CHECKER, test "$enable_heap_checker" = yes)
csilvers19dfa9e2009-09-11 18:42:32 +0000583AM_CONDITIONAL(WITH_DEBUGALLOC, test "$enable_debugalloc" = yes)
csilversedd03a82009-03-11 20:50:03 +0000584# We make tcmalloc.so if either heap-profiler or heap-checker is asked for.
585AM_CONDITIONAL(WITH_HEAP_PROFILER_OR_CHECKER,
586 test "$enable_heap_profiler" = yes -o \
587 "$enable_heap_checker" = yes)
588# If we don't use any profilers, we don't need stack traces (or pprof)
589AM_CONDITIONAL(WITH_STACK_TRACE, test "$enable_cpu_profiler" = yes -o \
590 "$enable_heap_profiler" = yes -o \
591 "$enable_heap_checker" = yes)
csilvers11b02f72007-11-29 23:39:24 +0000592
Aliaksey Kandratsenka1108d832014-09-07 13:09:14 -0700593have_linux_sigev_thread_id=no
594AC_MSG_CHECKING([for Linux SIGEV_THREAD_ID])
595AC_COMPILE_IFELSE(
596 [AC_LANG_PROGRAM([[#include <signal.h>
597 #include <time.h>]],
598 [[return SIGEV_THREAD_ID || CLOCK_THREAD_CPUTIME_ID || __linux;]])],
599 [AC_DEFINE(HAVE_LINUX_SIGEV_THREAD_ID, 1,
600 [Define if this is Linux that has SIGEV_THREAD_ID])
601 have_linux_sigev_thread_id=yes
602 AC_MSG_RESULT([yes])],
603 [AC_MSG_RESULT([no])])
604
csilvers51b48752007-03-22 03:00:33 +0000605# Write generated configuration file
csilvers4e9432c2012-02-04 00:07:36 +0000606AC_CONFIG_FILES([Makefile
607 src/gperftools/tcmalloc.h src/windows/gperftools/tcmalloc.h])
csilvers51b48752007-03-22 03:00:33 +0000608AC_OUTPUT
Aliaksey Kandratsenkab5e584d2014-02-16 19:41:37 -0800609
Aliaksey Kandratsenka125e5ed2014-04-12 12:38:19 -0700610AS_IF([test "$x86_no_fp_by_default" = yes && test "x$enable_frame_pointers" != xyes && test "x$UNWIND_LIBS" = x && test "x$enable_minimal" != xyes],
Aliaksey Kandratsenka9095ed02016-02-20 20:33:27 -0800611 [AS_IF([test "x$perftools_cv_have_unwind_backtrace" = xyes],
612 [AC_MSG_WARN([No frame pointers and no libunwind. Using experimental backtrace capturing via libgcc])],
613 [AS_IF([test "x$enable_backtrace" = xyes],
Aliaksey Kandratsenka7f120512016-01-31 23:17:50 -0800614 [AC_MSG_WARN([No frame pointers and no libunwind. Using experimental backtrace()])],
Aliaksey Kandratsenka9095ed02016-02-20 20:33:27 -0800615 [AC_MSG_FAILURE([No frame pointers and no libunwind. The compilation will fail])])])])