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 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 7 | AC_INIT([gperftools],[2.9.1],[gperftools@googlegroups.com]) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 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 |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 10 | TCMALLOC_SO_VERSION=9:9:5 |
| 11 | PROFILER_SO_VERSION=5:4:5 |
| 12 | TCMALLOC_AND_PROFILER_SO_VERSION=10:4:6 |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 13 | |
| 14 | AC_SUBST(TCMALLOC_SO_VERSION) |
| 15 | AC_SUBST(PROFILER_SO_VERSION) |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 16 | AC_SUBST(TCMALLOC_AND_PROFILER_SO_VERSION) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 17 | |
| 18 | # The argument here is just something that should be in the current directory |
| 19 | # (for sanity checking) |
| 20 | AC_CONFIG_SRCDIR(README) |
| 21 | AC_CONFIG_MACRO_DIR([m4]) |
| 22 | AC_CANONICAL_HOST |
| 23 | AM_INIT_AUTOMAKE([dist-zip]) |
| 24 | AC_CONFIG_HEADERS([src/config.h]) |
| 25 | |
| 26 | AM_MAINTAINER_MODE() |
| 27 | # Export the version information (for tc_version and friends) |
| 28 | TC_VERSION_MAJOR=`expr "$PACKAGE_VERSION" : '\([[0-9]]*\)'` |
| 29 | TC_VERSION_MINOR=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.\([[0-9]]*\)'` |
| 30 | TC_VERSION_PATCH=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.[[0-9]]*\(.*\)$'` |
| 31 | AC_SUBST(TC_VERSION_MAJOR) |
| 32 | AC_SUBST(TC_VERSION_MINOR) |
| 33 | AC_SUBST(TC_VERSION_PATCH) |
| 34 | AC_SUBST(PACKAGE_STRING) |
| 35 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 36 | AX_GENERATE_CHANGELOG |
| 37 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 38 | # 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. |
| 43 | default_enable_cpu_profiler=yes |
| 44 | default_enable_heap_profiler=yes |
| 45 | default_enable_heap_checker=yes |
| 46 | default_enable_debugalloc=yes |
| 47 | default_enable_minimal=no |
| 48 | default_tcmalloc_alignment=16 |
| 49 | need_nanosleep=yes # Used later, to decide if to run ACX_NANOSLEEP |
| 50 | case "$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;; |
| 56 | esac |
| 57 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 58 | # Currently only backtrace works on s390 and OSX. |
| 59 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [ |
| 60 | #if !defined(__s390__) && !defined(__APPLE__) |
| 61 | #error not s390 and not osx |
| 62 | #endif |
| 63 | return 1 |
| 64 | ])], |
| 65 | [default_enable_libunwind=no |
| 66 | default_enable_backtrace=yes], |
| 67 | [default_enable_libunwind=yes |
| 68 | default_enable_backtrace=no]) |
| 69 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 70 | # Disable libunwind linking on ppc64 by default. |
| 71 | AC_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 | |
| 77 | AC_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"]) |
| 82 | AC_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"]) |
| 87 | AC_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"]) |
| 92 | AC_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"]) |
| 97 | AC_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"]) |
| 102 | if test "$enable_minimal" = yes; then |
| 103 | enable_cpu_profiler=no |
| 104 | enable_heap_profiler=no |
| 105 | enable_heap_checker=no |
| 106 | fi |
| 107 | AC_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 Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 111 | [enable_backtrace="$default_enable_backtrace"]) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 112 | AC_ARG_ENABLE([libunwind], |
| 113 | [AS_HELP_STRING([--enable-libunwind], |
| 114 | [enable libunwind linking])], |
| 115 | [], |
| 116 | [enable_libunwind="$default_enable_libunwind"]) |
| 117 | AC_ARG_WITH([tcmalloc-pagesize], |
| 118 | [AS_HELP_STRING([--with-tcmalloc-pagesize], |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 119 | [Set the tcmalloc internal page size to 4K, 8K, 16K, 32K, 64K, 128K or 256K])], |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 120 | [], |
| 121 | [with_tcmalloc_pagesize=$default_tcmalloc_pagesize]) |
| 122 | AC_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 | |
| 128 | case "$with_tcmalloc_pagesize" in |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 129 | 4) |
| 130 | AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 12);; |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 131 | 8) |
| 132 | #Default tcmalloc page size. |
| 133 | ;; |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 134 | 16) |
| 135 | AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 14);; |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 136 | 32) |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 137 | AC_DEFINE(TCMALLOC_PAGE_SIZE_SHIFT, 15);; |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 138 | 64) |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 139 | 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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 145 | *) |
| 146 | AC_MSG_WARN([${with_tcmalloc_pagesize}K size not supported, using default tcmalloc page size.]) |
| 147 | esac |
| 148 | case "$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.]) |
| 157 | esac |
| 158 | |
| 159 | # Checks for programs. |
| 160 | AC_PROG_CXX |
| 161 | AC_PROG_CC |
| 162 | AC_PROG_CPP |
| 163 | AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc |
| 164 | AM_PROG_CC_C_O # shrug: autogen.sh suddenly needs this for some reason |
| 165 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 166 | AX_CXX_COMPILE_STDCXX(11, ext, mandatory) |
| 167 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 168 | # Check if we have an objcopy installed that supports -W |
| 169 | AC_CHECK_TOOL([OBJCOPY], [objcopy], []) |
| 170 | AS_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]) |
| 177 | AM_CONDITIONAL(HAVE_OBJCOPY_WEAKEN, test $gpt_cv_objcopy_weaken = yes) |
| 178 | |
| 179 | AC_PROG_LIBTOOL |
| 180 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 181 | AX_C___ATTRIBUTE__ |
| 182 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 183 | AC_MSG_CHECKING(for __attribute__((aligned(N))) on functions) |
| 184 | AC_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 | )]) |
| 193 | if test "$ac_cv___attribute__aligned_fn" = "yes"; then |
| 194 | AC_DEFINE(HAVE___ATTRIBUTE__ALIGNED_FN, 1, [define if your compiler supports alignment of functions]) |
| 195 | fi |
| 196 | AC_MSG_RESULT($ac_cv___attribute__aligned_fn) |
| 197 | |
| 198 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 199 | # Check whether some low-level functions/files are available |
| 200 | AC_HEADER_STDC |
| 201 | |
| 202 | # TODO(csilvers): we could remove a lot when WITH_CPU_PROFILER etc is "no". |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 203 | AC_CHECK_TYPES([struct mallinfo],,, [#include <malloc.h>]) |
| 204 | AC_CHECK_TYPES([Elf32_Versym],,, [#include <elf.h>]) # for vdso_support.h |
| 205 | AC_CHECK_FUNCS(sbrk) # for tcmalloc to get memory |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 206 | AC_CHECK_FUNCS(__sbrk) # for tcmalloc to get memory |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 207 | AC_CHECK_FUNCS(geteuid) # for turning off services when run as root |
| 208 | AC_CHECK_FUNCS(fork) # for the pthread_atfork setup |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 209 | AC_CHECK_HEADERS(features.h) # for vdso_support.h, __GLIBC__ macros |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 210 | AC_CHECK_HEADERS(malloc.h) # some systems define stuff there, others not |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 211 | AC_CHECK_HEADERS(glob.h) # for heap-profile-table (cleaning up profiles) |
| 212 | AC_CHECK_HEADERS(execinfo.h) # for stacktrace? and heapchecker_unittest |
| 213 | AC_CHECK_HEADERS(unwind.h) # for stacktrace |
| 214 | AC_CHECK_HEADERS(sched.h) # for being nice in our spinlock code |
| 215 | AC_CHECK_HEADERS(conflict-signal.h) # defined on some windows platforms? |
| 216 | AC_CHECK_HEADERS(sys/prctl.h) # for thread_lister (needed by leak-checker) |
| 217 | AC_CHECK_HEADERS(linux/ptrace.h)# also needed by leak-checker |
| 218 | AC_CHECK_HEADERS(sys/syscall.h) |
| 219 | AC_CHECK_HEADERS(sys/socket.h) # optional; for forking out to symbolizer |
| 220 | AC_CHECK_HEADERS(sys/wait.h) # optional; for forking out to symbolizer |
| 221 | AC_CHECK_HEADERS(poll.h) # optional; for forking out to symbolizer |
| 222 | AC_CHECK_HEADERS(fcntl.h) # for tcmalloc_unittest |
| 223 | AC_CHECK_HEADERS(grp.h) # for heapchecker_unittest |
| 224 | AC_CHECK_HEADERS(pwd.h) # for heapchecker_unittest |
| 225 | AC_CHECK_HEADERS(sys/resource.h) # for memalign_unittest.cc |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 226 | AC_CHECK_HEADERS(sys/cdefs.h) # Where glibc defines __THROW |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 227 | # 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. |
| 232 | AC_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 | |
| 241 | if test "$ac_cv_type_struct_mallinfo" = yes; then |
| 242 | AC_SUBST(ac_cv_have_struct_mallinfo, 1) # gperftools/tcmalloc.h needs this |
| 243 | else |
| 244 | AC_SUBST(ac_cv_have_struct_mallinfo, 0) |
| 245 | fi |
| 246 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 247 | # 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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 251 | case "$host" in |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 252 | *-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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 255 | esac |
| 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. |
| 259 | AC_MSG_CHECKING([if int32_t is the same type as intptr_t]) |
| 260 | 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, |
| 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 |
| 270 | if 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) |
| 273 | fi |
| 274 | |
| 275 | # Some tests test the behavior of .so files, and only make sense for dynamic. |
| 276 | AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes) |
| 277 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 278 | # We want to link in libunwind if it is enabled and exists. |
| 279 | UNWIND_LIBS= |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 280 | if test "$enable_libunwind" = yes; then |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 281 | AC_CHECK_HEADERS([libunwind.h], |
| 282 | [AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind) |
| 283 | will_use_libunwind=yes]) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 284 | fi |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 285 | AC_SUBST(UNWIND_LIBS) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 286 | |
| 287 | # On x86_64, instead of libunwind, we can choose to compile with frame-pointers. |
| 288 | AC_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) |
| 292 | AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes) |
| 293 | |
| 294 | AC_MSG_CHECKING([for x86 without frame pointers]) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 295 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])], |
| 296 | [is_x86_64=yes], [is_x86_64=no]) |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 297 | omit_fp_by_default=no |
| 298 | AS_IF([test "$is_x86_64" = yes], [omit_fp_by_default=yes]) |
| 299 | AM_CONDITIONAL(OMIT_FP_BY_DEFAULT, |
| 300 | test "$omit_fp_by_default" = yes) |
| 301 | AC_MSG_RESULT([$omit_fp_by_default]) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 302 | |
| 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). |
| 305 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __i386__ == 1 ? 0 : 1])], |
| 306 | [is_i386=yes], [is_i386=no]) |
| 307 | AM_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. |
| 313 | AC_CACHE_CHECK([if the compiler supports -Wno-unused-result], |
| 314 | perftools_cv_w_no_unused_result, |
| 315 | [OLD_CFLAGS="$CFLAGS" |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 316 | CFLAGS="$CFLAGS -Wno-error -Wunused-result" |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 317 | # 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 Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 321 | # |
| 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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 326 | 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"]) |
| 330 | AM_CONDITIONAL(HAVE_W_NO_UNUSED_RESULT, |
| 331 | test "$perftools_cv_w_no_unused_result" = yes) |
| 332 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 333 | AC_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 | |
| 340 | AM_CONDITIONAL(INSTALL_PPROF, |
| 341 | [test "x$enable_pprof" = xyes]) |
| 342 | |
| 343 | AC_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 | |
| 349 | AS_IF([test "x$enable_dyn_sized_delete" = xyes], |
| 350 | [AC_DEFINE([ENABLE_DYNAMIC_SIZED_DELETE], 1, |
| 351 | [Build runtime detection for sized delete])]) |
| 352 | |
| 353 | AC_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"]) |
| 358 | AS_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 | |
| 365 | AC_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 | |
| 379 | AM_CONDITIONAL(HAVE_SIZED_DEALLOCATION, |
| 380 | test "$perftools_cv_sized_deallocation_result" = yes) |
| 381 | |
| 382 | AC_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 | |
| 392 | AC_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 | |
| 405 | AM_CONDITIONAL(HAVE_F_ALIGNED_NEW, |
| 406 | test "$perftools_cv_have_f_aligned_new" = yes) |
| 407 | |
| 408 | AS_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 | |
| 413 | if 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 |
| 415 | else |
| 416 | AC_SUBST(ac_cv_have_std_align_val_t, 0) |
| 417 | fi |
| 418 | |
| 419 | |
| 420 | AC_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++)]) |
| 433 | AS_IF([test "x$perftools_cv_have_unwind_backtrace" = xyes], |
| 434 | [AC_DEFINE(HAVE_UNWIND_BACKTRACE, 1, [Whether <unwind.h> contains _Unwind_Backtrace])]) |
| 435 | |
| 436 | AS_IF([test "x$will_use_libunwind" = xyes], |
| 437 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __arm__])], |
| 438 | [default_emergency_malloc=yes])]) |
| 439 | |
| 440 | AC_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 | |
| 446 | AM_CONDITIONAL(BUILD_EMERGENCY_MALLOC, [test "x$enable_emergency_malloc" = xyes]) |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 447 | |
| 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) |
| 450 | AH_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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 456 | # Check if __environ is available (for GetenvBeforeMain) |
| 457 | AC_MSG_CHECKING([for __environ]) |
| 458 | AC_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 |
| 476 | AC_MSG_CHECKING([for __thread]) |
| 477 | AC_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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 490 | # 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. |
| 493 | if test "$need_nanosleep" = yes; then |
| 494 | ACX_NANOSLEEP |
| 495 | AC_SUBST(NANOSLEEP_LIBS) |
| 496 | fi |
| 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. |
| 500 | LIBSTDCXX_LA_LINKER_FLAG= |
| 501 | if test -f /usr/sfw/lib/libstdc++.la && ! test -s /usr/sfw/lib/libstdc++.la |
| 502 | then |
| 503 | LIBSTDCXX_LA_LINKER_FLAG='-L$(top_srcdir)/src/solaris' |
| 504 | fi |
| 505 | AC_SUBST(LIBSTDCXX_LA_LINKER_FLAG) |
| 506 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 507 | # In fact, a lot of the code in this directory depends on pthreads |
| 508 | ACX_PTHREAD |
| 509 | |
| 510 | AC_LANG_SAVE |
| 511 | AC_LANG_CPLUSPLUS |
| 512 | AC_MSG_CHECKING([whether pthread symbols are available in C++ without including pthread.h]) |
| 513 | acx_pthread_despite_asking_for=no |
| 514 | AC_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 | ]) |
| 525 | AC_MSG_RESULT([$acx_pthread_despite_asking_for]) |
| 526 | AC_LANG_RESTORE |
| 527 | |
| 528 | AM_CONDITIONAL(HAVE_PTHREAD_DESPITE_ASKING_FOR, test x"$acx_pthread_despite_asking_for" = xyes) |
| 529 | |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 530 | # Figure out where libc has program_invocation_name |
| 531 | AC_PROGRAM_INVOCATION_NAME |
| 532 | |
| 533 | # Make the install prefix available, to figure out where to look for pprof |
| 534 | AC_INSTALL_PREFIX |
| 535 | |
| 536 | dnl only very recent mingw has sleep and nanosleep |
| 537 | case "$host" in |
| 538 | *-mingw*) |
| 539 | AC_CHECK_DECLS([sleep], [], [], [#include <unistd.h>]) |
| 540 | AC_CHECK_DECLS([nanosleep], [], [], [#include <time.h>]) |
| 541 | ;; |
| 542 | esac |
| 543 | |
| 544 | if test "x$enable_backtrace" = xyes; then |
| 545 | AC_CHECK_DECLS([backtrace], [], [], [#include <execinfo.h>]) |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 546 | save_LIBS=$LIBS |
| 547 | LIBS=$UNWIND_LIBS |
| 548 | AC_SEARCH_LIBS([backtrace], [execinfo]) |
| 549 | UNWIND_LIBS=$LIBS |
| 550 | LIBS=$save_LIBS |
Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 551 | fi |
| 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. |
| 555 | AC_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 |
| 570 | AH_TOP([ |
| 571 | #ifndef GPERFTOOLS_CONFIG_H_ |
| 572 | #define GPERFTOOLS_CONFIG_H_ |
| 573 | ]) |
| 574 | |
| 575 | AH_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. |
| 589 | AH_BOTTOM([ |
| 590 | #ifdef __MINGW32__ |
| 591 | #include "windows/mingw.h" |
| 592 | #endif |
| 593 | |
| 594 | #endif /* #ifndef GPERFTOOLS_CONFIG_H_ */ |
| 595 | ]) |
| 596 | AM_CONDITIONAL(MINGW, expr $host : '.*-mingw' >/dev/null 2>&1) |
| 597 | AM_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. |
| 602 | AM_CONDITIONAL(WITH_CPU_PROFILER, test "$enable_cpu_profiler" = yes) |
| 603 | AM_CONDITIONAL(WITH_HEAP_PROFILER, test "$enable_heap_profiler" = yes) |
| 604 | AM_CONDITIONAL(WITH_HEAP_CHECKER, test "$enable_heap_checker" = yes) |
| 605 | AM_CONDITIONAL(WITH_DEBUGALLOC, test "$enable_debugalloc" = yes) |
| 606 | # We make tcmalloc.so if either heap-profiler or heap-checker is asked for. |
| 607 | AM_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) |
| 611 | AM_CONDITIONAL(WITH_STACK_TRACE, test "$enable_cpu_profiler" = yes -o \ |
| 612 | "$enable_heap_profiler" = yes -o \ |
| 613 | "$enable_heap_checker" = yes) |
| 614 | |
| 615 | have_linux_sigev_thread_id=no |
| 616 | AC_MSG_CHECKING([for Linux SIGEV_THREAD_ID]) |
| 617 | AC_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 Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 627 | # Disable large allocation report by default. |
| 628 | AC_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]) |
| 633 | AS_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 |
| 637 | AC_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]) |
| 642 | AS_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 Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 647 | # Write generated configuration file |
| 648 | AC_CONFIG_FILES([Makefile |
| 649 | src/gperftools/tcmalloc.h src/windows/gperftools/tcmalloc.h]) |
| 650 | AC_OUTPUT |
| 651 | |
Brian Silverman | 20350ac | 2021-11-17 18:19:55 -0800 | [diff] [blame] | 652 | AS_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])])])]) |