1 ## Process this file with autoconf to produce configure.
2 ## In general, the safest way to proceed is to run ./autogen.sh
4 # make sure we're interpreted by some minimal autoconf
7 AC_INIT(gperftools, 2.0, google-perftools@googlegroups.com)
8 # 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
10 TCMALLOC_SO_VERSION=5:0:1
11 PROFILER_SO_VERSION=3:0:3
13 AC_SUBST(TCMALLOC_SO_VERSION)
14 AC_SUBST(PROFILER_SO_VERSION)
16 # The argument here is just something that should be in the current directory
17 # (for sanity checking)
18 AC_CONFIG_SRCDIR(README)
19 AC_CONFIG_MACRO_DIR([m4])
21 AM_INIT_AUTOMAKE([dist-zip])
22 AM_CONFIG_HEADER(src/config.h)
24 # Export the version information (for tc_version and friends)
25 TC_VERSION_MAJOR=`expr "$PACKAGE_VERSION" : '\([[0-9]]*\)'`
26 TC_VERSION_MINOR=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.\([[0-9]]*\)'`
27 TC_VERSION_PATCH=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.[[0-9]]*\(.*\)$'`
28 AC_SUBST(TC_VERSION_MAJOR)
29 AC_SUBST(TC_VERSION_MINOR)
30 AC_SUBST(TC_VERSION_PATCH)
31 AC_SUBST(PACKAGE_STRING)
33 # The user can choose not to compile in the heap-profiler, the
34 # heap-checker, or the cpu-profiler. There's also the possibility
35 # for a 'fully minimal' compile, which leaves out the stacktrace
36 # code as well. By default, we include all of these that the
37 # target system supports.
38 default_enable_cpu_profiler=yes
39 default_enable_heap_profiler=yes
40 default_enable_heap_checker=yes
41 default_enable_debugalloc=yes
42 default_enable_minimal=no
43 need_nanosleep=yes # Used later, to decide if to run ACX_NANOSLEEP
45 *-mingw*) default_enable_minimal=yes; default_enable_debugalloc=no;
47 *-cygwin*) default_enable_heap_checker=no; default_enable_cpu_profiler=no;;
48 *-freebsd*) default_enable_heap_checker=no;;
49 *-darwin*) default_enable_heap_checker=no;;
52 AC_ARG_ENABLE([cpu-profiler],
53 [AS_HELP_STRING([--disable-cpu-profiler],
54 [do not build the cpu profiler])],
56 [enable_cpu_profiler="$default_enable_cpu_profiler"])
57 AC_ARG_ENABLE([heap-profiler],
58 [AS_HELP_STRING([--disable-heap-profiler],
59 [do not build the heap profiler])],
61 [enable_heap_profiler="$default_enable_heap_profiler"])
62 AC_ARG_ENABLE([heap-checker],
63 [AS_HELP_STRING([--disable-heap-checker],
64 [do not build the heap checker])],
66 [enable_heap_checker="$default_enable_heap_checker"])
67 AC_ARG_ENABLE([debugalloc],
68 [AS_HELP_STRING([--disable-debugalloc],
69 [do not build versions of libs with debugalloc])],
71 [enable_debugalloc="$default_enable_debugalloc"])
72 AC_ARG_ENABLE([minimal],
73 [AS_HELP_STRING([--enable-minimal],
74 [build only tcmalloc-minimal (and maybe tcmalloc-minimal-debug)])],
76 [enable_minimal="$default_enable_minimal"])
77 if test "$enable_minimal" = yes; then
78 enable_cpu_profiler=no
79 enable_heap_profiler=no
80 enable_heap_checker=no
84 # Checks for programs.
88 AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
89 AM_PROG_CC_C_O # shrug: autogen.sh suddenly needs this for some reason
91 # Check if we have an objcopy installed that supports -W
92 AC_CHECK_TOOL([OBJCOPY], [objcopy], [])
93 AS_IF([test -n "$OBJCOPY"], [dnl
94 AC_CACHE_CHECK([if $OBJCOPY supports -W], gpt_cv_objcopy_weaken, [dnl
95 AC_LINK_IFELSE([void foo() {} int main() {return 0;}], [dnl
96 AS_IF(["$OBJCOPY" -W foo conftest$ac_exeext /dev/null],
97 [gpt_cv_objcopy_weaken=yes], [gpt_cv_objcopy_weaken=no])],
98 [gpt_cv_objcopy_weaken=no])])],
99 [gpt_cv_objcopy_weaken=no])
100 AM_CONDITIONAL(HAVE_OBJCOPY_WEAKEN, test $gpt_cv_objcopy_weaken = yes)
104 # Disabling fast install keeps libtool from creating wrapper scripts
105 # around the executables it builds. Such scripts have caused failures on
106 # MinGW. Using this option means an extra link step is executed during
108 AC_DISABLE_FAST_INSTALL
111 AC_ENABLE_FAST_INSTALL
116 AC_SUBST(LIBTOOL_DEPS)
117 AM_CONDITIONAL(USE_LIBTOOL, test "x$LIBTOOL" != "x")
122 # Check whether some low-level functions/files are available
125 # TODO(csilvers): we could remove a lot when WITH_CPU_PROFILER etc is "no".
126 AC_CHECK_TYPES([__int64]) # defined in some windows platforms
127 AC_CHECK_TYPES([struct mallinfo],,, [#include <malloc.h>])
128 AC_CHECK_TYPES([Elf32_Versym],,, [#include <elf.h>]) # for vdso_support.h
129 AC_CHECK_FUNCS(sbrk) # for tcmalloc to get memory
130 AC_CHECK_FUNCS(geteuid) # for turning off services when run as root
131 AC_CHECK_HEADERS(features.h) # for vdso_support.h
132 AC_CHECK_HEADERS(malloc.h) # some systems define stuff there, others not
133 AC_CHECK_HEADERS(sys/malloc.h) # where some versions of OS X put malloc.h
134 AC_CHECK_HEADERS(malloc/malloc.h) # another place OS X puts malloc.h (?)
135 AC_CHECK_HEADERS(glob.h) # for heap-profile-table (cleaning up profiles)
136 AC_CHECK_HEADERS(execinfo.h) # for stacktrace? and heapchecker_unittest
137 AC_CHECK_HEADERS(libunwind.h) # for stacktrace
138 AC_CHECK_HEADERS(unwind.h) # for stacktrace
139 AC_CHECK_HEADERS(sched.h) # for being nice in our spinlock code
140 AC_CHECK_HEADERS(conflict-signal.h) # defined on some windows platforms?
141 AC_CHECK_HEADERS(sys/prctl.h) # for thread_lister (needed by leak-checker)
142 AC_CHECK_HEADERS(linux/ptrace.h)# also needed by leak-checker
143 AC_CHECK_HEADERS(sys/syscall.h)
144 AC_CHECK_HEADERS(sys/socket.h) # optional; for forking out to symbolizer
145 AC_CHECK_HEADERS(sys/wait.h) # optional; for forking out to symbolizer
146 AC_CHECK_HEADERS(poll.h) # optional; for forking out to symbolizer
147 AC_CHECK_HEADERS(fcntl.h) # for tcmalloc_unittest
148 AC_CHECK_HEADERS(grp.h) # for heapchecker_unittest
149 AC_CHECK_HEADERS(pwd.h) # for heapchecker_unittest
150 AC_CHECK_HEADERS(sys/resource.h) # for memalign_unittest.cc
151 AC_CHECK_HEADERS(valgrind.h) # we have a local copy if this isn't found
152 AC_CHECK_HEADERS(sys/cdefs.h) # Where glibc defines __THROW
153 AC_CHECK_HEADERS(features.h) # Where __GLIBC__ is defined
154 # We also need <ucontext.h>/<sys/ucontext.h>, but we get those from
155 # AC_PC_FROM_UCONTEXT, below.
157 # We override a lot of memory allocation routines, not all of which are
158 # standard. For those the system doesn't declare, we'll declare ourselves.
159 AC_CHECK_DECLS([cfree,
164 [#define _XOPEN_SOURCE 600
166 #include <malloc.h>])
168 if test "$ac_cv_type_struct_mallinfo" = yes; then
169 AC_SUBST(ac_cv_have_struct_mallinfo, 1) # gperftools/tcmalloc.h needs this
171 AC_SUBST(ac_cv_have_struct_mallinfo, 0)
174 # We need to check for mmap. cygwin supports mmap, but the autoconf
175 # test doesn't work on cygwin:
176 # http://www.cygwin.com/ml/cygwin/2002-04/msg00412.html
177 # This workaround comes from
178 # http://cygwin.com/ml/cygwin/2004-11/msg00138.html
181 ac_cv_func_mmap_fixed_mapped=yes
182 AC_DEFINE(HAVE_MMAP, 1,
183 [Define to 1 if you have a working `mmap' system call.])
189 # If AtomicWord != Atomic32, we need to define two versions of all the
190 # atomicops functions. If they're the same, we want to define only one.
191 AC_MSG_CHECKING([if int32_t is the same type as intptr_t])
192 AC_TRY_COMPILE([#include <stdint.h>],
193 [int32_t v1 = 0; intptr_t v2 = 0; return (&v1 - &v2)],
194 [AC_DEFINE(INT32_EQUALS_INTPTR, 1,
195 Define to 1 if int32_t is equivalent to intptr_t)
196 AC_MSG_RESULT([yes])],
197 [AC_MSG_RESULT([no])])
199 # We want to access the "PC" (Program Counter) register from a struct
200 # ucontext. Every system has its own way of doing that. We try all the
201 # possibilities we know about. Note REG_PC should come first (REG_RIP
202 # is also defined on solaris, but does the wrong thing). But don't
203 # bother if we're not doing cpu-profiling.
204 # [*] means that we've not actually tested one of these systems
205 if test "$enable_cpu_profiler" = yes; then
206 AC_PC_FROM_UCONTEXT(AC_MSG_WARN(Could not find the PC. Will not try to compile libprofiler...);
207 enable_cpu_profiler=no)
210 # Some tests test the behavior of .so files, and only make sense for dynamic.
211 AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
213 # We want to link in libunwind if it exists
214 AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind, UNWIND_LIBS=)
215 AC_SUBST(UNWIND_LIBS)
217 # On x86_64, instead of libunwind, we can choose to compile with frame-pointers
218 # (This isn't needed on i386, where -fno-omit-frame-pointer is the default).
219 AC_ARG_ENABLE(frame_pointers,
220 AS_HELP_STRING([--enable-frame-pointers],
221 [On x86_64 systems, compile with -fno-omit-frame-pointer (see INSTALL)]),
222 , enable_frame_pointers=no)
223 AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes)
225 # Some x86_64 systems do not insert frame pointers by default (all
226 # i386 systems that I know of, do. I don't know about non-x86 chips).
227 # We want to see if the current system is one of those.
228 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])],
229 [is_x86_64=yes], [is_x86_64=no])
231 CFLAGS="$CFLAGS -S -O2 -o fp.s"
232 # This test will always fail because we don't name our output file properly.
233 # We do our own determination of success/failure in the grep, below.
234 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int f(int x) {return x;}], [return f(0);])],
236 AM_CONDITIONAL(X86_64_AND_NO_FP_BY_DEFAULT,
237 test "$is_x86_64" = yes && ! grep 'mov.*rsp.*rbp' fp.s >/dev/null 2>&1)
241 # We need to know if we're i386 so we can turn on -mmms, which is not
242 # on by default for i386 (it is for x86_64).
243 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __i386__ == 1 ? 0 : 1])],
244 [is_i386=yes], [is_i386=no])
245 AM_CONDITIONAL(I386, test "$is_i386" = yes)
247 # See if the compiler supports -Wno-unused-result.
248 # Newer ubuntu's turn on -D_FORTIFY_SOURCE=2, enabling
249 # __attribute__((warn_unused_result)) for things like write(),
250 # which we don't care about.
251 AC_CACHE_CHECK([if the compiler supports -Wno-unused-result],
252 perftools_cv_w_no_unused_result,
253 [OLD_CFLAGS="$CFLAGS"
254 CFLAGS="$CFLAGS -Wno-error -Wno-unused-result"
255 # gcc doesn't warn about unknown flags unless it's
256 # also warning for some other purpose, hence the
257 # divide-by-0. (We use -Wno-error to make sure the
258 # divide-by-0 doesn't cause this test to fail!)
259 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return 1/0)],
260 perftools_cv_w_no_unused_result=yes,
261 perftools_cv_w_no_unused_result=no)
262 CFLAGS="$OLD_CFLAGS"])
263 AM_CONDITIONAL(HAVE_W_NO_UNUSED_RESULT,
264 test "$perftools_cv_w_no_unused_result" = yes)
267 AC_COMPILER_CHARACTERISTICS
269 # Also make sure we get standard PRI... definitions, even with glibc.
270 # We have to use AH_VERBATIM because we need the #ifdef guard (gcc buglet)
271 AH_VERBATIM([__STDC_FORMAT_MACROS],
272 [/* C99 says: define this to get the PRI... macros from stdint.h */
273 #ifndef __STDC_FORMAT_MACROS
274 # define __STDC_FORMAT_MACROS 1
277 # Check if __builtin_stack_pointer() is available (for elfcore.h)
278 AC_MSG_CHECKING([for __builtin_stack_pointer()])
279 AC_LINK_IFELSE([AC_LANG_PROGRAM(, [void *sp = __builtin_stack_pointer()])],
280 [AC_DEFINE(HAVE_BUILTIN_STACK_POINTER, 1,
281 Define to 1 if compiler supports __builtin_stack_pointer)
282 AC_MSG_RESULT([yes])],
283 [AC_MSG_RESULT([no])])
285 # Check if __environ is available (for GetenvBeforeMain)
286 AC_MSG_CHECKING([for __environ])
287 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>],
288 [char **env = __environ])],
289 [AC_DEFINE(HAVE___ENVIRON, 1,
290 [Define to 1 if compiler supports __environ])
291 AC_MSG_RESULT([yes])],
292 [AC_MSG_RESULT([no])])
294 # If we support __thread, that can speed up tcmalloc a bit.
295 # Note, however, that our code tickles a bug in gcc < 4.1.2
296 # involving TLS and -fPIC (which our libraries will use) on x86:
297 # http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
298 AC_MSG_CHECKING([for __thread])
299 AC_LINK_IFELSE([AC_LANG_PROGRAM([#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 1) || (__GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ < 2))
300 #error gcc has this bug: http://gcc.gnu.org/ml/gcc-bugs/2006-09/msg02275.html
301 #endif], [static __thread int p = 0])],
302 [AC_DEFINE(HAVE_TLS, 1,
303 Define to 1 if compiler supports __thread)
304 AC_MSG_RESULT([yes])],
305 [AC_MSG_RESULT([no])])
307 # glibc's __malloc_hook/etc were declared volatile starting in glibc 2.14
308 AC_MSG_CHECKING([if __malloc_hook is declared volatile])
309 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <malloc.h>
310 void* (* volatile __malloc_hook)(size_t, const void*) = 0;],)],
311 [AC_DEFINE(MALLOC_HOOK_MAYBE_VOLATILE, volatile,
312 Define to 'volatile' if __malloc_hook is declared volatile)
313 AC_MSG_RESULT([yes])],
314 [AC_DEFINE(MALLOC_HOOK_MAYBE_VOLATILE, )
315 AC_MSG_RESULT([no])])
317 # Nanosleep requires extra libraries on some architectures (solaris).
318 # This sets NANOSLEEP_LIBS. nanosleep doesn't exist on mingw, which
319 # is fine for us because we don't compile libspinlock, which uses it.
320 if test "$need_nanosleep" = yes; then
322 AC_SUBST(NANOSLEEP_LIBS)
325 # Solaris 10 6/06 has a bug where /usr/sfw/lib/libstdc++.la is empty.
326 # If so, we replace it with our own version.
327 LIBSTDCXX_LA_LINKER_FLAG=
328 if test -f /usr/sfw/lib/libstdc++.la && ! test -s /usr/sfw/lib/libstdc++.la
330 LIBSTDCXX_LA_LINKER_FLAG='-L$(top_srcdir)/src/solaris'
332 AC_SUBST(LIBSTDCXX_LA_LINKER_FLAG)
334 # We also need to check if the kernel supports __thread, which requires uname()
335 AC_CHECK_DECLS(uname,,, [#include <sys/utsname.h>])
337 # In fact, a lot of the code in this directory depends on pthreads
340 # Find out what namespace 'normal' STL code lives in
343 # Figure out where libc has program_invocation_name
344 AC_PROGRAM_INVOCATION_NAME
346 # Make the install prefix available, to figure out where to look for pprof
349 # For windows, this has a non-trivial value (__declspec(export)), but any
350 # system that uses configure wants this to be the empty string.
351 AC_DEFINE(PERFTOOLS_DLL_DECL,,
352 [Always the empty-string on non-windows systems.
353 On windows, should be "__declspec(dllexport)".
354 This way, when we compile the dll, we export our functions/classes.
355 It's safe to define this here because config.h is only used
356 internally, to compile the DLL, and every DLL source file
357 #includes "config.h" before anything else.])
359 # In theory, config.h files shouldn't need a header guard, but we do,
360 # because we (maybe) #include windows/mingw.h from within config.h,
361 # and it #includes other .h files. These all have header guards, so
362 # the end result is if config.h is #included twice, its #undefs get
363 # evaluated twice, but all the ones in mingw.h/etc only get evaluated
364 # once, potentially causing trouble. c.f.
365 # http://code.google.com/p/gperftools/issues/detail?id=246
367 #ifndef GPERFTOOLS_CONFIG_H_
368 #define GPERFTOOLS_CONFIG_H_
371 AH_VERBATIM([PTHREADS_CRASHES_IF_RUN_TOO_EARLY],
372 [/* Mark the systems where we know it's bad if pthreads runs too
373 early before main (before threads are initialized, presumably). */
375 #define PTHREADS_CRASHES_IF_RUN_TOO_EARLY 1
378 # MinGW uses autoconf, but also needs the windows shim routines
379 # (since it doesn't have its own support for, say, pthreads).
380 # This requires us to #include a special header file, and also to
381 # link in some windows versions of .o's instead of the unix versions.
383 # Also, manually mark systems where we have to be careful how early
384 # we run pthreads. TODO(csilvers): turn this into an autoconf check.
387 #include "windows/mingw.h"
390 #endif /* #ifndef GPERFTOOLS_CONFIG_H_ */
392 AM_CONDITIONAL(MINGW, expr $host : '.*-mingw' >/dev/null 2>&1)
393 AM_CONDITIONAL(OSX, expr $host : '.*-apple-darwin.*' >/dev/null 2>&1)
395 # Redhat 7 (and below?) has sys/ucontext.h, but if you try to #include
396 # it directly, the compiler gets upset. So we pretend we don't have
398 if cat /etc/redhat-release 2>/dev/null | grep "Red Hat Linux release 7" >/dev/null 2>&1; then
399 AC_DEFINE(HAVE_SYS_UCONTEXT_H, 0, [<sys/ucontext.h> is broken on redhat 7])
402 # Export the --enable flags we set above. We do this at the end so
403 # other configure rules can enable or disable targets based on what
405 AM_CONDITIONAL(WITH_CPU_PROFILER, test "$enable_cpu_profiler" = yes)
406 AM_CONDITIONAL(WITH_HEAP_PROFILER, test "$enable_heap_profiler" = yes)
407 AM_CONDITIONAL(WITH_HEAP_CHECKER, test "$enable_heap_checker" = yes)
408 AM_CONDITIONAL(WITH_DEBUGALLOC, test "$enable_debugalloc" = yes)
409 # We make tcmalloc.so if either heap-profiler or heap-checker is asked for.
410 AM_CONDITIONAL(WITH_HEAP_PROFILER_OR_CHECKER,
411 test "$enable_heap_profiler" = yes -o \
412 "$enable_heap_checker" = yes)
413 # If we don't use any profilers, we don't need stack traces (or pprof)
414 AM_CONDITIONAL(WITH_STACK_TRACE, test "$enable_cpu_profiler" = yes -o \
415 "$enable_heap_profiler" = yes -o \
416 "$enable_heap_checker" = yes)
418 # Write generated configuration file
419 AC_CONFIG_FILES([Makefile
420 src/gperftools/tcmalloc.h src/windows/gperftools/tcmalloc.h])