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
5AC_PREREQ(2.57)
6
7AC_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
10TCMALLOC_SO_VERSION=5:0:1
11PROFILER_SO_VERSION=3:0:3
12
13AC_SUBST(TCMALLOC_SO_VERSION)
14AC_SUBST(PROFILER_SO_VERSION)
15
16# The argument here is just something that should be in the current directory
17# (for sanity checking)
18AC_CONFIG_SRCDIR(README)
19AC_CONFIG_MACRO_DIR([m4])
20AC_CANONICAL_HOST
21AM_INIT_AUTOMAKE([dist-zip])
22AM_CONFIG_HEADER(src/config.h)
23
24# Export the version information (for tc_version and friends)
25TC_VERSION_MAJOR=`expr "$PACKAGE_VERSION" : '\([[0-9]]*\)'`
26TC_VERSION_MINOR=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.\([[0-9]]*\)'`
27TC_VERSION_PATCH=`expr "$PACKAGE_VERSION" : '[[0-9]]*\.[[0-9]]*\(.*\)$'`
28AC_SUBST(TC_VERSION_MAJOR)
29AC_SUBST(TC_VERSION_MINOR)
30AC_SUBST(TC_VERSION_PATCH)
31AC_SUBST(PACKAGE_STRING)
32
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.
38default_enable_cpu_profiler=yes
39default_enable_heap_profiler=yes
40default_enable_heap_checker=yes
41default_enable_debugalloc=yes
42default_enable_minimal=no
43need_nanosleep=yes   # Used later, to decide if to run ACX_NANOSLEEP
44case "$host" in
45   *-mingw*) default_enable_minimal=yes; default_enable_debugalloc=no;
46             need_nanosleep=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;;
50esac
51
52AC_ARG_ENABLE([cpu-profiler],
53              [AS_HELP_STRING([--disable-cpu-profiler],
54                              [do not build the cpu profiler])],
55              [],
56              [enable_cpu_profiler="$default_enable_cpu_profiler"])
57AC_ARG_ENABLE([heap-profiler],
58              [AS_HELP_STRING([--disable-heap-profiler],
59                              [do not build the heap profiler])],
60              [],
61              [enable_heap_profiler="$default_enable_heap_profiler"])
62AC_ARG_ENABLE([heap-checker],
63              [AS_HELP_STRING([--disable-heap-checker],
64                              [do not build the heap checker])],
65              [],
66              [enable_heap_checker="$default_enable_heap_checker"])
67AC_ARG_ENABLE([debugalloc],
68              [AS_HELP_STRING([--disable-debugalloc],
69                              [do not build versions of libs with debugalloc])],
70              [],
71              [enable_debugalloc="$default_enable_debugalloc"])
72AC_ARG_ENABLE([minimal],
73              [AS_HELP_STRING([--enable-minimal],
74                              [build only tcmalloc-minimal (and maybe tcmalloc-minimal-debug)])],
75              [],
76              [enable_minimal="$default_enable_minimal"])
77if test "$enable_minimal" = yes; then
78  enable_cpu_profiler=no
79  enable_heap_profiler=no
80  enable_heap_checker=no
81fi
82
83
84# Checks for programs.
85AC_PROG_CXX
86AC_PROG_CC
87AC_PROG_CPP
88AM_CONDITIONAL(GCC, test "$GCC" = yes)   # let the Makefile know if we're gcc
89AM_PROG_CC_C_O      # shrug: autogen.sh suddenly needs this for some reason
90
91# Check if we have an objcopy installed that supports -W
92AC_CHECK_TOOL([OBJCOPY], [objcopy], [])
93AS_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])
100AM_CONDITIONAL(HAVE_OBJCOPY_WEAKEN, test $gpt_cv_objcopy_weaken = yes)
101
102case $host_os in
103  *mingw*)
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
107    # "make install".
108    AC_DISABLE_FAST_INSTALL
109    ;;
110   *)
111    AC_ENABLE_FAST_INSTALL
112    ;;
113esac
114
115AC_PROG_LIBTOOL
116AC_SUBST(LIBTOOL_DEPS)
117AM_CONDITIONAL(USE_LIBTOOL, test "x$LIBTOOL" != "x")
118
119AC_C_INLINE
120AX_C___ATTRIBUTE__
121
122# Check whether some low-level functions/files are available
123AC_HEADER_STDC
124
125# TODO(csilvers): we could remove a lot when WITH_CPU_PROFILER etc is "no".
126AC_CHECK_TYPES([__int64])       # defined in some windows platforms
127AC_CHECK_TYPES([struct mallinfo],,, [#include <malloc.h>])
128AC_CHECK_TYPES([Elf32_Versym],,, [#include <elf.h>])   # for vdso_support.h
129AC_CHECK_FUNCS(sbrk)            # for tcmalloc to get memory
130AC_CHECK_FUNCS(geteuid)         # for turning off services when run as root
131AC_CHECK_HEADERS(features.h)    # for vdso_support.h
132AC_CHECK_HEADERS(malloc.h)      # some systems define stuff there, others not
133AC_CHECK_HEADERS(sys/malloc.h)  # where some versions of OS X put malloc.h
134AC_CHECK_HEADERS(malloc/malloc.h)  # another place OS X puts malloc.h (?)
135AC_CHECK_HEADERS(glob.h)        # for heap-profile-table (cleaning up profiles)
136AC_CHECK_HEADERS(execinfo.h)    # for stacktrace? and heapchecker_unittest
137AC_CHECK_HEADERS(libunwind.h)   # for stacktrace
138AC_CHECK_HEADERS(unwind.h)      # for stacktrace
139AC_CHECK_HEADERS(sched.h)       # for being nice in our spinlock code
140AC_CHECK_HEADERS(conflict-signal.h)      # defined on some windows platforms?
141AC_CHECK_HEADERS(sys/prctl.h)   # for thread_lister (needed by leak-checker)
142AC_CHECK_HEADERS(linux/ptrace.h)# also needed by leak-checker
143AC_CHECK_HEADERS(sys/syscall.h)
144AC_CHECK_HEADERS(sys/socket.h)  # optional; for forking out to symbolizer
145AC_CHECK_HEADERS(sys/wait.h)    # optional; for forking out to symbolizer
146AC_CHECK_HEADERS(poll.h)        # optional; for forking out to symbolizer
147AC_CHECK_HEADERS(fcntl.h)       # for tcmalloc_unittest
148AC_CHECK_HEADERS(grp.h)         # for heapchecker_unittest
149AC_CHECK_HEADERS(pwd.h)         # for heapchecker_unittest
150AC_CHECK_HEADERS(sys/resource.h)         # for memalign_unittest.cc
151AC_CHECK_HEADERS(valgrind.h)    # we have a local copy if this isn't found
152AC_CHECK_HEADERS(sys/cdefs.h)   # Where glibc defines __THROW
153AC_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.
156
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.
159AC_CHECK_DECLS([cfree,
160                posix_memalign,
161                memalign,
162                valloc,
163                pvalloc],,,
164               [#define _XOPEN_SOURCE 600
165                #include <stdlib.h>
166                #include <malloc.h>])
167
168if test "$ac_cv_type_struct_mallinfo" = yes; then
169  AC_SUBST(ac_cv_have_struct_mallinfo, 1)   # gperftools/tcmalloc.h needs this
170else
171  AC_SUBST(ac_cv_have_struct_mallinfo, 0)
172fi
173
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
179case "$host" in
180  *-*-cygwin*)
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.])
184               ;;
185            *) AC_FUNC_MMAP
186               ;;
187esac
188
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.
191AC_MSG_CHECKING([if int32_t is the same type as intptr_t])
192AC_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])])
198
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
205if 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)
208fi
209
210# Some tests test the behavior of .so files, and only make sense for dynamic.
211AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
212
213# We want to link in libunwind if it exists
214AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind, UNWIND_LIBS=)
215AC_SUBST(UNWIND_LIBS)
216
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).
219AC_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)
223AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes)
224
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.
228AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])],
229                  [is_x86_64=yes], [is_x86_64=no])
230OLD_CFLAGS="$CFLAGS"
231CFLAGS="$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.
234AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int f(int x) {return x;}], [return f(0);])],
235                  [:], [:])
236AM_CONDITIONAL(X86_64_AND_NO_FP_BY_DEFAULT,
237               test "$is_x86_64" = yes && ! grep 'mov.*rsp.*rbp' fp.s >/dev/null 2>&1)
238rm fp.s
239CFLAGS="$OLD_CFLAGS"
240
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).
243AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __i386__ == 1 ? 0 : 1])],
244                  [is_i386=yes], [is_i386=no])
245AM_CONDITIONAL(I386, test "$is_i386" = yes)
246
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.
251AC_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"])
263AM_CONDITIONAL(HAVE_W_NO_UNUSED_RESULT,
264	       test "$perftools_cv_w_no_unused_result" = yes)
265
266# Defines PRIuS
267AC_COMPILER_CHARACTERISTICS
268
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)
271AH_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
275#endif])
276
277# Check if __builtin_stack_pointer() is available (for elfcore.h)
278AC_MSG_CHECKING([for __builtin_stack_pointer()])
279AC_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])])
284
285# Check if __environ is available (for GetenvBeforeMain)
286AC_MSG_CHECKING([for __environ])
287AC_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])])
293
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
298AC_MSG_CHECKING([for __thread])
299AC_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])])
306
307# glibc's __malloc_hook/etc were declared volatile starting in glibc 2.14
308AC_MSG_CHECKING([if __malloc_hook is declared volatile])
309AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <malloc.h>
310void* (* 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])])
316
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.
320if test "$need_nanosleep" = yes; then
321  ACX_NANOSLEEP
322  AC_SUBST(NANOSLEEP_LIBS)
323fi
324
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.
327LIBSTDCXX_LA_LINKER_FLAG=
328if test -f /usr/sfw/lib/libstdc++.la && ! test -s /usr/sfw/lib/libstdc++.la
329then
330  LIBSTDCXX_LA_LINKER_FLAG='-L$(top_srcdir)/src/solaris'
331fi
332AC_SUBST(LIBSTDCXX_LA_LINKER_FLAG)
333
334# We also need to check if the kernel supports __thread, which requires uname()
335AC_CHECK_DECLS(uname,,, [#include <sys/utsname.h>])
336
337# In fact, a lot of the code in this directory depends on pthreads
338ACX_PTHREAD
339
340# Find out what namespace 'normal' STL code lives in
341AC_CXX_STL_NAMESPACE
342
343# Figure out where libc has program_invocation_name
344AC_PROGRAM_INVOCATION_NAME
345
346# Make the install prefix available, to figure out where to look for pprof
347AC_INSTALL_PREFIX
348
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.
351AC_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.])
358
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
366AH_TOP([
367#ifndef GPERFTOOLS_CONFIG_H_
368#define GPERFTOOLS_CONFIG_H_
369])
370
371AH_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).  */
374#ifdef __FreeBSD__
375#define PTHREADS_CRASHES_IF_RUN_TOO_EARLY 1
376#endif])
377
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.
382#
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.
385AH_BOTTOM([
386#ifdef __MINGW32__
387#include "windows/mingw.h"
388#endif
389
390#endif  /* #ifndef GPERFTOOLS_CONFIG_H_ */
391])
392AM_CONDITIONAL(MINGW, expr $host : '.*-mingw' >/dev/null 2>&1)
393AM_CONDITIONAL(OSX, expr $host : '.*-apple-darwin.*' >/dev/null 2>&1)
394
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
397# it.
398if cat /etc/redhat-release 2>/dev/null | grep "Red Hat Linux release 7" >/dev/null 2>&1; then
399AC_DEFINE(HAVE_SYS_UCONTEXT_H, 0, [<sys/ucontext.h> is broken on redhat 7])
400fi
401
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
404# they find.
405AM_CONDITIONAL(WITH_CPU_PROFILER, test "$enable_cpu_profiler" = yes)
406AM_CONDITIONAL(WITH_HEAP_PROFILER, test "$enable_heap_profiler" = yes)
407AM_CONDITIONAL(WITH_HEAP_CHECKER, test "$enable_heap_checker" = yes)
408AM_CONDITIONAL(WITH_DEBUGALLOC, test "$enable_debugalloc" = yes)
409# We make tcmalloc.so if either heap-profiler or heap-checker is asked for.
410AM_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)
414AM_CONDITIONAL(WITH_STACK_TRACE, test "$enable_cpu_profiler" = yes -o \
415                                      "$enable_heap_profiler" = yes -o \
416                                      "$enable_heap_checker" = yes)
417
418# Write generated configuration file
419AC_CONFIG_FILES([Makefile
420                 src/gperftools/tcmalloc.h src/windows/gperftools/tcmalloc.h])
421AC_OUTPUT
422