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