1## Process this file with automake to produce Makefile.in
2
3# Note: for every library we create, we're explicit about what symbols
4# we export.  In order to avoid complications with C++ mangling, we always
5# use the regexp for of specifying symbols.
6
7# Make sure that when we re-make ./configure, we get the macros we need
8ACLOCAL_AMFLAGS = -I m4
9
10# This is so we can #include <gperftools/foo>
11AM_CPPFLAGS = -I$(top_srcdir)/src
12
13if !WITH_STACK_TRACE
14AM_CPPFLAGS += -DNO_TCMALLOC_SAMPLES
15endif !WITH_STACK_TRACE
16
17# This is mostly based on configure options
18AM_CXXFLAGS =
19
20# These are good warnings to turn on by default.  We also tell gcc
21# that malloc, free, realloc, mmap, etc. are not builtins (these flags
22# are supported since gcc 3.1.1).  gcc doesn't think most of them are
23# builtins now in any case, but it's best to be explicit in case that
24# changes one day.  gcc ignores functions it doesn't understand.
25if GCC
26AM_CXXFLAGS += -Wall -Wwrite-strings -Woverloaded-virtual \
27               -Wno-sign-compare \
28               -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc \
29               -fno-builtin-calloc -fno-builtin-cfree \
30               -fno-builtin-memalign -fno-builtin-posix_memalign \
31               -fno-builtin-valloc -fno-builtin-pvalloc
32# On i386, -mmmx is needed for the mmx-based instructions in
33# atomicops-internal-x86.h.
34if I386
35AM_CXXFLAGS += -mmmx
36endif I386
37endif GCC
38if HAVE_W_NO_UNUSED_RESULT
39AM_CXXFLAGS += -Wno-unused-result
40endif HAVE_W_NO_UNUSED_RESULT
41
42# The -no-undefined flag allows libtool to generate shared libraries for
43# Cygwin and MinGW.  LIBSTDCXX_LA_LINKER_FLAG is used to fix a Solaris bug.
44AM_LDFLAGS = -no-undefined $(LIBSTDCXX_LA_LINKER_FLAG)
45
46# We know our low-level code cannot trigger an exception.  On some
47# systems, such as cygwin, it would be disastrous if they did, because
48# the exception handler might call malloc!  If our low-level routines
49# raised an exception within the malloc, they'd deadlock.  Luckily,
50# we control all this code, and do not need exceptions for it.
51if GCC
52NO_EXCEPTIONS = -fno-exceptions
53else !GCC
54NO_EXCEPTIONS =
55endif !GCC
56
57# These are x86-specific, having to do with frame-pointers.  In
58# particular, some x86_64 systems do not insert frame pointers by
59# default (all i386 systems that I know of, do.  I don't know about
60# non-x86 chips).  We need to tell perftools what to do about that.
61if X86_64_AND_NO_FP_BY_DEFAULT
62if ENABLE_FRAME_POINTERS
63AM_CXXFLAGS += -fno-omit-frame-pointer
64else
65  # TODO(csilvers): check if -fomit-frame-pointer might be in $(CXXFLAGS),
66  #                 before setting this.
67AM_CXXFLAGS += -DNO_FRAME_POINTER
68endif !ENABLE_FRAME_POINTERS
69endif X86_64_AND_NO_FP_BY_DEFAULT
70
71# For windows systems (at least, mingw), we need to tell all our
72# tests to link in libtcmalloc using -u.  This is because libtcmalloc
73# accomplishes its tasks via patching, leaving no work for the linker
74# to identify, so the linker will ignore libtcmalloc by default unless
75# we explicitly create a dependency via -u.
76TCMALLOC_FLAGS =
77if MINGW
78TCMALLOC_FLAGS += -Wl,-u__tcmalloc
79endif MINGW
80
81# If we have objcopy, make malloc/free/etc weak symbols.  That way folks
82# can override our malloc if they want to (they can still use tc_malloc).
83# Note: the weird-looking symbols are the c++ memory functions:
84# (in order) new, new(nothrow), new[], new[](nothrow), delete, delete[]
85# In theory this will break if mangling changes, but that seems pretty
86# unlikely at this point.  Just in case, I throw in versions with an
87# extra underscore as well, which may help on OS X.
88if HAVE_OBJCOPY_WEAKEN
89WEAKEN = $(OBJCOPY) -W malloc -W free -W realloc -W calloc -W cfree \
90         -W memalign -W posix_memalign -W valloc -W pvalloc \
91         -W malloc_stats -W mallopt -W mallinfo \
92         -W _Znwm -W _ZnwmRKSt9nothrow_t -W _Znam -W _ZnamRKSt9nothrow_t \
93         -W _ZdlPv -W _ZdaPv \
94         -W __Znwm -W __ZnwmRKSt9nothrow_t -W __Znam -W __ZnamRKSt9nothrow_t \
95         -W __ZdlPv -W __ZdaPv
96else
97WEAKEN = :
98endif !HAVE_OBJCOPY_WEAKEN
99
100LIBS_TO_WEAKEN =
101
102perftoolsincludedir = $(includedir)/gperftools
103# The .h files you want to install (that is, .h files that people
104# who install this package can include in their own applications.)
105# We'll add to this later, on a library-by-library basis
106perftoolsinclude_HEADERS =
107# tcmalloc.h is a special case, because it's a .h.in file
108nodist_perftoolsinclude_HEADERS = src/gperftools/tcmalloc.h
109noinst_HEADERS = src/gperftools/tcmalloc.h.in
110
111# This is provided for backwards compatibility.  It is populated by
112# files that just forward to the canonical location in
113# perftoolsincludedir.
114googleincludedir = $(includedir)/google
115googleinclude_HEADERS =				\
116   src/google/heap-checker.h			\
117   src/google/heap-profiler.h			\
118   src/google/malloc_extension.h		\
119   src/google/malloc_extension_c.h		\
120   src/google/malloc_hook.h			\
121   src/google/malloc_hook_c.h			\
122   src/google/profiler.h			\
123   src/google/stacktrace.h			\
124   src/google/tcmalloc.h                        \
125   src/windows/google/tcmalloc.h
126
127docdir = $(prefix)/share/doc/$(PACKAGE)-$(VERSION)
128# This is for HTML and other documentation you want to install.
129# Add your documentation files (in doc/) in addition to these
130# top-level boilerplate files.  Also add a TODO file if you have one.
131# We'll add to this later, on a library-by-library basis
132dist_doc_DATA = AUTHORS COPYING ChangeLog INSTALL NEWS README README_windows.txt \
133                TODO
134
135# The libraries (.so's) you want to install
136# We'll add to this later, on a library-by-library basis
137lib_LTLIBRARIES =
138# This is for 'convenience libraries' -- basically just a container for sources
139noinst_LTLIBRARIES =
140## The location of the windows project file for each binary we make
141WINDOWS_PROJECTS = gperftools.sln
142
143# unittests you want to run when people type 'make check'.
144# Note: tests cannot take any arguments!
145# In theory, unittests that are scripts should be added to check_SCRIPTS
146# instead.  But check_SCRIPTS is definitely a second-class testing mechanims:
147# it don't get TESTS_ENVIRONMENT, and it doesn't get success/failure counting
148# (in fact, a script failure aborts all the rest of the tests, even with -k).
149# So, for scripts, we add the script to tests, and also put in an empty
150# rule so automake doesn't try to build the script as a C binary.
151TESTS =
152# TESTS_ENVIRONMENT sets environment variables for when you run unittest.
153# We always get "srcdir" set for free.
154# We'll add to this later, on a library-by-library basis.
155TESTS_ENVIRONMENT =
156# All script tests should be added here
157noinst_SCRIPTS =
158# If your test calls another program that, like the test itself, shouldn't
159# be installed, add it here.  (Stuff in TESTS is automatically added later).
160noinst_PROGRAMS =
161
162# Binaries we might build that should be installed
163bin_PROGRAMS =
164
165# This is my own var, used for extra libraries I make that I need installed
166EXTRA_INSTALL =
167
168## vvvv RULES TO MAKE THE LIBRARIES, BINARIES, AND UNITTESTS
169
170dist_doc_DATA += doc/index.html doc/designstyle.css
171
172
173### ------- library routines, in src/base
174
175# This is a 'convenience library' -- it's not actually installed or anything
176LOGGING_INCLUDES = src/base/logging.h \
177                   src/base/commandlineflags.h \
178                   src/base/basictypes.h \
179                   src/base/dynamic_annotations.h \
180                   src/third_party/valgrind.h
181noinst_LTLIBRARIES += liblogging.la
182liblogging_la_SOURCES = src/base/logging.cc \
183                        src/base/dynamic_annotations.c \
184                        $(LOGGING_INCLUDES)
185
186SYSINFO_INCLUDES = src/base/sysinfo.h \
187                   src/base/logging.h \
188                   src/base/commandlineflags.h \
189                   src/base/cycleclock.h \
190                   src/base/arm_instruction_set_select.h \
191                   src/base/basictypes.h
192noinst_LTLIBRARIES += libsysinfo.la
193libsysinfo_la_SOURCES = src/base/sysinfo.cc \
194                        $(SYSINFO_INCLUDES)
195libsysinfo_la_LIBADD = $(NANOSLEEP_LIBS)
196
197# For MinGW, we use also have to use libwindows Luckily, we need the
198# windows.a library in exactly the same place we need spinlock.a
199# (pretty much everywhere), so we can use the same variable name for
200# each.  We can also optimize the MinGW rule a bit by leaving out
201# files we know aren't used on windows, such as
202# atomicops-internals-x86.cc.  libwindows also obsoletes the need for
203# other files like system_alloc.cc.
204if MINGW
205WINDOWS_INCLUDES = src/windows/port.h \
206                   src/windows/mingw.h \
207                   src/windows/mini_disassembler.h \
208                   src/windows/mini_disassembler_types.h \
209                   src/windows/preamble_patcher.h
210noinst_LTLIBRARIES += libwindows.la
211libwindows_la_SOURCES = $(WINDOWS_INCLUDES) \
212                        src/windows/port.cc \
213                        src/windows/ia32_modrm_map.cc \
214                        src/windows/ia32_opcode_map.cc \
215                        src/windows/mini_disassembler.cc \
216                        src/windows/patch_functions.cc \
217                        src/windows/preamble_patcher.cc \
218                        src/windows/preamble_patcher_with_stub.cc
219# patch_functions.cc uses Psapi.lib.  MSVC has a #pragma for that, but not us.
220libwindows_la_LIBADD = -lPsapi
221
222SPINLOCK_INCLUDES = src/base/spinlock.h \
223                    src/base/spinlock_internal.h \
224                    src/base/spinlock_win32-inl.h \
225                    src/base/spinlock_linux-inl.h \
226                    src/base/spinlock_posix-inl.h \
227                    src/base/synchronization_profiling.h \
228                    src/base/atomicops-internals-macosx.h \
229                    src/base/atomicops-internals-linuxppc.h \
230                    src/base/atomicops-internals-arm-generic.h \
231                    src/base/atomicops-internals-arm-v6plus.h \
232                    src/base/atomicops-internals-windows.h \
233                    src/base/atomicops-internals-x86.h
234noinst_LTLIBRARIES += libspinlock.la
235libspinlock_la_SOURCES = src/base/spinlock.cc \
236                         src/base/spinlock_internal.cc \
237                         $(SPINLOCK_INCLUDES)
238
239LIBSPINLOCK = libwindows.la libspinlock.la libsysinfo.la liblogging.la
240
241# We also need to tell mingw that sysinfo.cc needs shlwapi.lib.
242# (We do this via a #pragma for msvc, but need to do it here for mingw).
243libsysinfo_la_LIBADD += -lshlwapi
244
245# There's a windows-specific unittest we can run.  Right now it's
246# win64-specific, and relies on masm, so we comment it out.
247## TESTS += preamble_patcher_test
248## preamble_patcher_test_SOURCES = src/windows/preamble_patcher_test.cc \
249##                                 src/windows/shortproc.asm \
250##                                 src/windows/auto_testing_hook.h \
251##                                 src/windows/preamble_patcher.h \
252##                                 src/base/basictypes.h \
253##                                 src/base/logging.h
254## preamble_patcher_test_LDFLAGS = $(TCMALLOC_FLAGS)
255## preamble_patcher_test_LDADD = $(LIBTCMALLOC_MINIMAL)
256
257# patch_functions.cc #includes tcmalloc.cc, so no need to link it in.
258TCMALLOC_CC =
259# windows has its own system for threads and system memory allocation.
260MAYBE_THREADS_CC =
261SYSTEM_ALLOC_CC =
262else !MINGW
263# spinlock is the only code that uses atomicops.
264SPINLOCK_INCLUDES = src/base/spinlock.h \
265                    src/base/spinlock_internal.h \
266                    src/base/atomicops.h \
267                    src/base/atomicops-internals-macosx.h \
268                    src/base/atomicops-internals-linuxppc.h \
269                    src/base/atomicops-internals-windows.h \
270                    src/base/atomicops-internals-x86.h
271
272noinst_LTLIBRARIES += libspinlock.la
273libspinlock_la_SOURCES = src/base/spinlock.cc \
274                         src/base/spinlock_internal.cc \
275                         src/base/atomicops-internals-x86.cc \
276                         $(SPINLOCK_INCLUDES)
277libspinlock_la_LIBADD = $(NANOSLEEP_LIBS)
278# spinlock also needs NumCPUs, from libsysinfo, which in turn needs liblogging
279LIBSPINLOCK = libspinlock.la libsysinfo.la liblogging.la
280
281TCMALLOC_CC = src/tcmalloc.cc
282MAYBE_THREADS_CC = src/maybe_threads.cc
283SYSTEM_ALLOC_CC = src/system-alloc.cc
284endif !MINGW
285
286# Add this whether or not we're under MinGW, to keep the tarball complete.
287WINDOWS_PROJECTS += vsprojects/preamble_patcher_test/preamble_patcher_test.vcproj
288# Because we've commented out the test, above, we have to explicitly add
289# the test files to the tarball or automake will leave them out.
290WINDOWS_PROJECTS += src/windows/preamble_patcher_test.cc \
291                    src/windows/shortproc.asm \
292                    src/windows/auto_testing_hook.h
293
294### Unittests
295TESTS += low_level_alloc_unittest
296WINDOWS_PROJECTS += vsprojects/low_level_alloc_unittest/low_level_alloc_unittest.vcproj
297LOW_LEVEL_ALLOC_UNITTEST_INCLUDES = src/base/low_level_alloc.h \
298                                    src/base/basictypes.h \
299                                    src/gperftools/malloc_hook.h \
300                                    src/gperftools/malloc_hook_c.h \
301                                    src/malloc_hook-inl.h \
302                                    src/malloc_hook_mmap_linux.h \
303                                    src/malloc_hook_mmap_freebsd.h \
304                                    $(SPINLOCK_INCLUDES) \
305                                    $(LOGGING_INCLUDES)
306low_level_alloc_unittest_SOURCES = src/base/low_level_alloc.cc \
307                                   src/malloc_hook.cc \
308                                   $(MAYBE_THREADS_CC) \
309                                   src/tests/low_level_alloc_unittest.cc \
310                                   $(LOW_LEVEL_ALLOC_UNITTEST_INCLUDES)
311# By default, MallocHook takes stack traces for use by the heap-checker.
312# We don't need that functionality here, so we turn it off to reduce deps.
313low_level_alloc_unittest_CXXFLAGS = -DNO_TCMALLOC_SAMPLES
314low_level_alloc_unittest_LDADD = $(LIBSPINLOCK)
315
316TESTS += atomicops_unittest
317ATOMICOPS_UNITTEST_INCLUDES = src/base/atomicops.h \
318                              src/base/atomicops-internals-macosx.h \
319                              src/base/atomicops-internals-windows.h \
320                              src/base/atomicops-internals-x86.h \
321                              $(LOGGING_INCLUDES)
322atomicops_unittest_SOURCES = src/tests/atomicops_unittest.cc \
323                             $(ATOMICOPS_UNITTEST_INCLUDES)
324atomicops_unittest_LDADD = $(LIBSPINLOCK)
325
326
327### ------- stack trace
328
329if WITH_STACK_TRACE
330
331### The header files we use.  We divide into categories based on directory
332S_STACKTRACE_INCLUDES = src/stacktrace_config.h \
333                        src/stacktrace_generic-inl.h \
334			src/stacktrace_libunwind-inl.h \
335			src/stacktrace_arm-inl.h \
336			src/stacktrace_powerpc-inl.h \
337			src/stacktrace_x86-inl.h \
338			src/stacktrace_win32-inl.h \
339                        src/base/elf_mem_image.h \
340                        src/base/vdso_support.h
341
342SG_STACKTRACE_INCLUDES = src/gperftools/stacktrace.h
343STACKTRACE_INCLUDES = $(S_STACKTRACE_INCLUDES) $(SG_STACKTRACE_INCLUDES)
344perftoolsinclude_HEADERS += $(SG_STACKTRACE_INCLUDES)
345
346### Making the library
347noinst_LTLIBRARIES += libstacktrace.la
348libstacktrace_la_SOURCES = src/stacktrace.cc \
349                           src/base/elf_mem_image.cc \
350                           src/base/vdso_support.cc \
351                           $(STACKTRACE_INCLUDES)
352libstacktrace_la_LIBADD = $(UNWIND_LIBS) $(LIBSPINLOCK)
353STACKTRACE_SYMBOLS = '(GetStackTrace|GetStackFrames|GetStackTraceWithContext|GetStackFramesWithContext)'
354libstacktrace_la_LDFLAGS = -export-symbols-regex $(STACKTRACE_SYMBOLS)
355
356### Unittests
357TESTS += stacktrace_unittest
358STACKTRACE_UNITTEST_INCLUDES = src/config_for_unittests.h \
359                               src/base/commandlineflags.h \
360                               $(STACKTRACE_INCLUDES) \
361                               $(LOGGING_INCLUDES)
362stacktrace_unittest_SOURCES = src/tests/stacktrace_unittest.cc \
363                              $(STACKTRACE_UNITTEST_INCLUDES)
364stacktrace_unittest_LDADD = libstacktrace.la liblogging.la
365
366### Documentation
367dist_doc_DATA +=
368
369endif WITH_STACK_TRACE
370
371### ------- pprof
372
373# If we are not compiling with stacktrace support, pprof is worthless
374if WITH_STACK_TRACE
375
376bin_SCRIPTS = src/pprof
377
378### Unittests
379
380check_SCRIPTS = pprof_unittest
381pprof_unittest: $(top_srcdir)/src/pprof
382	$(top_srcdir)/src/pprof -test
383
384# Let unittests find pprof if they need to run it
385TESTS_ENVIRONMENT += PPROF_PATH=$(top_srcdir)/src/pprof
386
387### Documentation
388dist_man_MANS = doc/pprof.1
389dist_doc_DATA += doc/pprof_remote_servers.html
390
391# On MSVC, we need our own versions of addr2line and nm to work with pprof.
392WINDOWS_PROJECTS += vsprojects/nm-pdb/nm-pdb.vcproj
393WINDOWS_PROJECTS += vsprojects/addr2line-pdb/addr2line-pdb.vcproj
394# This is a slight abuse of WINDOWS_PROJECTS, but not much
395WINDOWS_PROJECTS += src/windows/nm-pdb.c \
396                    src/windows/addr2line-pdb.c
397
398endif WITH_STACK_TRACE
399
400### ------- tcmalloc_minimal (thread-caching malloc)
401
402### The header files we use.  We divide into categories based on directory
403S_TCMALLOC_MINIMAL_INCLUDES = src/common.h \
404                              src/internal_logging.h \
405                              src/system-alloc.h \
406                              src/packed-cache-inl.h \
407                              $(SPINLOCK_INCLUDES) \
408                              src/tcmalloc_guard.h \
409                              src/base/commandlineflags.h \
410                              src/base/basictypes.h \
411                              src/pagemap.h \
412                              src/sampler.h \
413                              src/central_freelist.h \
414                              src/linked_list.h \
415                              src/libc_override.h \
416                              src/libc_override_gcc_and_weak.h \
417                              src/libc_override_glibc.h \
418                              src/libc_override_osx.h \
419                              src/libc_override_redefine.h \
420                              src/page_heap.h \
421                              src/page_heap_allocator.h \
422                              src/span.h \
423                              src/static_vars.h \
424                              src/symbolize.h \
425                              src/thread_cache.h \
426                              src/stack_trace_table.h \
427                              src/base/thread_annotations.h \
428                              src/malloc_hook-inl.h \
429                              src/malloc_hook_mmap_linux.h \
430                              src/malloc_hook_mmap_freebsd.h \
431                              src/maybe_threads.h
432SG_TCMALLOC_MINIMAL_INCLUDES = src/gperftools/malloc_hook.h \
433                               src/gperftools/malloc_hook_c.h \
434                               src/gperftools/malloc_extension.h \
435                               src/gperftools/malloc_extension_c.h \
436                               src/gperftools/stacktrace.h
437TCMALLOC_MINIMAL_INCLUDES = $(S_TCMALLOC_MINIMAL_INCLUDES) $(SG_TCMALLOC_MINIMAL_INCLUDES)
438perftoolsinclude_HEADERS += $(SG_TCMALLOC_MINIMAL_INCLUDES)
439
440### Making the library
441
442# As we describe at the top of this file, we want to turn off exceptions
443# for all files in this library -- except tcmalloc.cc which needs them
444# to fulfill its API.  Automake doesn't allow per-file CXXFLAGS, so we need
445# to separate into two libraries.
446noinst_LTLIBRARIES += libtcmalloc_minimal_internal.la
447libtcmalloc_minimal_internal_la_SOURCES = src/common.cc \
448                                          src/internal_logging.cc \
449                                          $(SYSTEM_ALLOC_CC) \
450                                          src/memfs_malloc.cc \
451                                          src/central_freelist.cc \
452                                          src/page_heap.cc \
453                                          src/sampler.cc \
454                                          src/span.cc \
455                                          src/stack_trace_table.cc \
456                                          src/static_vars.cc \
457                                          src/symbolize.cc \
458                                          src/thread_cache.cc \
459                                          src/malloc_hook.cc \
460                                          src/malloc_extension.cc \
461                                          $(MAYBE_THREADS_CC) \
462                                          $(TCMALLOC_MINIMAL_INCLUDES)
463# We #define NO_TCMALLOC_SAMPLES, since sampling is turned off for _minimal.
464libtcmalloc_minimal_internal_la_CXXFLAGS = -DNO_TCMALLOC_SAMPLES \
465                                           -DNO_HEAP_CHECK \
466                                           $(PTHREAD_CFLAGS) -DNDEBUG \
467                                           $(AM_CXXFLAGS) $(NO_EXCEPTIONS)
468libtcmalloc_minimal_internal_la_LDFLAGS = $(PTHREAD_CFLAGS)
469libtcmalloc_minimal_internal_la_LIBADD = $(PTHREAD_LIBS) $(LIBSPINLOCK)
470
471lib_LTLIBRARIES += libtcmalloc_minimal.la
472WINDOWS_PROJECTS += vsprojects/libtcmalloc_minimal/libtcmalloc_minimal.vcproj
473libtcmalloc_minimal_la_SOURCES = $(TCMALLOC_CC) $(TCMALLOC_MINIMAL_INCLUDES)
474libtcmalloc_minimal_la_CXXFLAGS = -DNO_TCMALLOC_SAMPLES \
475                                  $(PTHREAD_CFLAGS) -DNDEBUG $(AM_CXXFLAGS)
476# -version-info gets passed to libtool
477libtcmalloc_minimal_la_LDFLAGS = $(PTHREAD_CFLAGS) -version-info @TCMALLOC_SO_VERSION@
478libtcmalloc_minimal_la_LIBADD = libtcmalloc_minimal_internal.la $(PTHREAD_LIBS)
479
480# For windows, we're playing around with trying to do some stacktrace
481# support even with libtcmalloc_minimal.  For everyone else, though,
482# we turn off all stack-trace activity for libtcmalloc_minimal.
483# TODO(csilvers): when we're done experimenting, do something principled here
484if MINGW
485LIBTCMALLOC_MINIMAL = libtcmalloc_minimal.la libstacktrace.la
486else !MINGW
487LIBTCMALLOC_MINIMAL = libtcmalloc_minimal.la
488endif !MINGW
489
490LIBS_TO_WEAKEN += libtcmalloc_minimal.la
491
492### Unittests
493
494# Commented out for the moment because malloc(very_big_num) is broken in
495# standard libc!  At least, in some situations, some of the time.
496## TESTS += malloc_unittest
497## MALLOC_UNITEST_INCLUDES = src/gperftools/malloc_extension.h \
498##                           src/gperftools/malloc_hook.h \
499##                           src/gperftools/malloc_hook_c.h \
500##                           src/malloc_hook-inl.h \
501##                           src/malloc_hook_mmap_linux.h \
502##                           src/malloc_hook_mmap_freebsd.h \
503##                           src/base/basictypes.h \
504##                           src/maybe_threads.h
505## malloc_unittest_SOURCES = src/tests/tcmalloc_unittest.cc \
506##                           src/malloc_hook.cc \
507##                           src/malloc_extension.cc \
508##                           $(MAYBE_THREADS_CC) \
509##                           $(MALLOC_UNITTEST_INCLUDES)
510## malloc_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
511## malloc_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
512## malloc_unittest_LDADD = $(PTHREAD_LIBS)
513
514TESTS += tcmalloc_minimal_unittest
515WINDOWS_PROJECTS += vsprojects/tcmalloc_minimal_unittest/tcmalloc_minimal_unittest.vcproj
516WINDOWS_PROJECTS += vsprojects/tmu-static/tmu-static.vcproj
517tcmalloc_minimal_unittest_SOURCES = src/tests/tcmalloc_unittest.cc \
518                                    src/tests/testutil.h src/tests/testutil.cc \
519                                    $(TCMALLOC_UNITTEST_INCLUDES)
520tcmalloc_minimal_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
521tcmalloc_minimal_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
522# We want libtcmalloc last on the link line, but due to a bug in
523# libtool involving convenience libs, they need to come last on the
524# link line in order to get dependency ordering right.  This is ok:
525# convenience libraries are .a's, so tcmalloc is still the last .so.
526# We also put pthreads after tcmalloc, because some pthread
527# implementations define their own malloc, and we need to go on the
528# first linkline to make sure our malloc 'wins'.
529tcmalloc_minimal_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) \
530                                  liblogging.la $(PTHREAD_LIBS)
531
532TESTS += tcmalloc_minimal_large_unittest
533WINDOWS_PROJECTS += vsprojects/tcmalloc_minimal_large/tcmalloc_minimal_large_unittest.vcproj
534tcmalloc_minimal_large_unittest_SOURCES = src/tests/tcmalloc_large_unittest.cc
535tcmalloc_minimal_large_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
536tcmalloc_minimal_large_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
537tcmalloc_minimal_large_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
538
539# This tests it works to LD_PRELOAD libtcmalloc (tests maybe_threads.cc)
540# In theory this should work under mingw, but mingw has trouble running
541# shell scripts that end in .exe.  And it doesn't seem to build shared
542# libraries anyway (so can't be LD_PRELOADed) -- in fact, anybody who
543# chooses not to build shared libraries won't be able to run this test.
544# TODO(csilvers): figure out how to nix ".exe" or otherwise work under mingw
545if !MINGW
546if !ENABLE_STATIC
547TESTS += maybe_threads_unittest.sh$(EXEEXT)
548maybe_threads_unittest_sh_SOURCES = src/tests/maybe_threads_unittest.sh
549noinst_SCRIPTS += $(maybe_threads_unittest_sh_SOURCES)
550# This script preloads libtcmalloc, and calls two other binaries as well
551# TODO(csilvers): replace by 'if ! cmp $^ $@ >/dev/null 2>&; then ...; fi'
552maybe_threads_unittest.sh$(EXEEXT): $(top_srcdir)/$(maybe_threads_unittest_sh_SOURCES) \
553                           $(LIBTCMALLOC_MINIMAL) \
554                           low_level_alloc_unittest
555	rm -f $@
556	cp -p $(top_srcdir)/$(maybe_threads_unittest_sh_SOURCES) $@
557endif !ENABLE_STATIC
558endif !MINGW
559
560# These all tests components of tcmalloc_minimal
561
562TESTS += addressmap_unittest
563WINDOWS_PROJECTS += vsprojects/addressmap_unittest/addressmap_unittest.vcproj
564ADDRESSMAP_UNITTEST_INCLUDES = src/addressmap-inl.h \
565                               src/base/commandlineflags.h \
566                               $(LOGGING_INCLUDES)
567addressmap_unittest_SOURCES = src/tests/addressmap_unittest.cc \
568                              $(ADDRESSMAP_UNITTEST_INCLUDES)
569if MINGW
570addressmap_unittest_SOURCES += src/windows/port.h src/windows/port.cc
571endif MINGW
572addressmap_unittest_CXXFLAGS = -g $(AM_CXXFLAGS)
573addressmap_unittest_LDADD = liblogging.la
574
575if !MINGW
576TESTS += system_alloc_unittest
577system_alloc_unittest_SOURCES = src/config_for_unittests.h \
578                                src/tests/system-alloc_unittest.cc
579system_alloc_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
580system_alloc_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
581system_alloc_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
582endif !MINGW
583
584TESTS += packed_cache_test
585WINDOWS_PROJECTS += vsprojects/packed-cache_test/packed-cache_test.vcproj
586packed_cache_test_SOURCES = src/tests/packed-cache_test.cc
587packed_cache_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
588packed_cache_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
589packed_cache_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
590
591TESTS += frag_unittest
592WINDOWS_PROJECTS += vsprojects/frag_unittest/frag_unittest.vcproj
593frag_unittest_SOURCES = src/tests/frag_unittest.cc src/config_for_unittests.h
594frag_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
595frag_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
596frag_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
597
598TESTS += markidle_unittest
599WINDOWS_PROJECTS += vsprojects/markidle_unittest/markidle_unittest.vcproj
600markidle_unittest_SOURCES = src/tests/markidle_unittest.cc \
601                            src/config_for_unittests.h \
602                            src/tests/testutil.h src/tests/testutil.cc
603markidle_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
604markidle_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
605markidle_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
606
607TESTS += current_allocated_bytes_test
608WINDOWS_PROJECTS += vsprojects/current_allocated_bytes_test/current_allocated_bytes_test.vcproj
609current_allocated_bytes_test_SOURCES = src/tests/current_allocated_bytes_test.cc \
610                                       src/config_for_unittests.h
611current_allocated_bytes_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
612current_allocated_bytes_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
613current_allocated_bytes_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
614
615TESTS += malloc_hook_test
616WINDOWS_PROJECTS += vsprojects/malloc_hook_test/malloc_hook_test.vcproj
617malloc_hook_test_SOURCES = src/tests/malloc_hook_test.cc \
618                           src/config_for_unittests.h \
619                           src/base/logging.h \
620                           src/gperftools/malloc_hook.h \
621                           src/tests/testutil.h src/tests/testutil.cc
622malloc_hook_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
623malloc_hook_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
624malloc_hook_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
625
626TESTS += malloc_extension_test
627WINDOWS_PROJECTS += vsprojects/malloc_extension_test/malloc_extension_test.vcproj
628malloc_extension_test_SOURCES = src/tests/malloc_extension_test.cc \
629                                src/config_for_unittests.h \
630                                src/base/logging.h \
631                                src/gperftools/malloc_extension.h \
632                                src/gperftools/malloc_extension_c.h
633malloc_extension_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
634malloc_extension_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
635malloc_extension_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
636
637# This doesn't work with static linkage, because libtcmalloc.a isn't
638# happy with C linkage (it misses the stdc++ library).  Likewise with
639# mingw, which links foo.a even though it doesn't set ENABLE_STATIC.
640# TODO(csilvers): set enable_static=true in configure.ac:36?
641if !MINGW
642if !ENABLE_STATIC
643TESTS += malloc_extension_c_test
644malloc_extension_c_test_SOURCES = src/tests/malloc_extension_c_test.c \
645                                  src/gperftools/malloc_extension.h \
646                                  src/gperftools/malloc_extension_c.h
647malloc_extension_c_test_CFLAGS = $(PTHREAD_CFLAGS) $(AM_CFLAGS)
648# -ansi here is just to help ensure the code is bog-standard C.
649if GCC
650malloc_extension_c_test_CFLAGS += -ansi
651endif GCC
652malloc_extension_c_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
653malloc_extension_c_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
654endif !ENABLE_STATIC
655endif !MINGW
656
657if !MINGW
658if !OSX
659TESTS += memalign_unittest
660memalign_unittest_SOURCES = src/tests/memalign_unittest.cc \
661                            src/tcmalloc.h \
662                            src/config_for_unittests.h \
663                            src/tests/testutil.h src/tests/testutil.cc
664memalign_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
665memalign_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
666memalign_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
667endif !OSX
668endif !MINGW
669
670TESTS += page_heap_test
671WINDOWS_PROJECTS += vsprojects/page_heap_test/page_heap_test.vcproj
672page_heap_test_SOURCES = src/tests/page_heap_test.cc \
673                         src/config_for_unittests.h \
674                         src/base/logging.h \
675                         src/common.h \
676                         src/page_heap.h
677page_heap_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
678page_heap_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
679page_heap_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
680
681TESTS += pagemap_unittest
682WINDOWS_PROJECTS += vsprojects/pagemap_unittest/pagemap_unittest.vcproj
683pagemap_unittest_SOURCES = src/tests/pagemap_unittest.cc \
684                           src/config_for_unittests.h \
685                           src/base/logging.h \
686                           src/pagemap.h
687pagemap_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
688pagemap_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
689pagemap_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
690
691TESTS += realloc_unittest
692WINDOWS_PROJECTS += vsprojects/realloc_unittest/realloc_unittest.vcproj
693realloc_unittest_SOURCES = src/tests/realloc_unittest.cc \
694                           src/config_for_unittests.h \
695                           src/base/logging.h
696realloc_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
697realloc_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
698realloc_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
699
700TESTS += stack_trace_table_test
701WINDOWS_PROJECTS += vsprojects/stack_trace_table_test/stack_trace_table_test.vcproj
702stack_trace_table_test_SOURCES = src/tests/stack_trace_table_test.cc \
703                                 src/config_for_unittests.h
704stack_trace_table_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
705stack_trace_table_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
706stack_trace_table_test_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
707
708TESTS += thread_dealloc_unittest
709WINDOWS_PROJECTS += vsprojects/thread_dealloc_unittest/thread_dealloc_unittest.vcproj
710thread_dealloc_unittest_SOURCES = src/tests/thread_dealloc_unittest.cc \
711                                  src/config_for_unittests.h \
712                                  src/tests/testutil.h src/tests/testutil.cc
713thread_dealloc_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
714thread_dealloc_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
715thread_dealloc_unittest_LDADD = $(LIBTCMALLOC_MINIMAL) $(PTHREAD_LIBS)
716
717### Documentation
718dist_doc_DATA += doc/tcmalloc.html \
719                 doc/overview.gif \
720                 doc/pageheap.gif \
721                 doc/spanmap.gif \
722                 doc/threadheap.gif \
723                 doc/t-test1.times.txt \
724                 doc/tcmalloc-opspercpusec.vs.threads.1024.bytes.png 	\
725                 doc/tcmalloc-opspercpusec.vs.threads.128.bytes.png 	\
726                 doc/tcmalloc-opspercpusec.vs.threads.131072.bytes.png 	\
727                 doc/tcmalloc-opspercpusec.vs.threads.16384.bytes.png 	\
728                 doc/tcmalloc-opspercpusec.vs.threads.2048.bytes.png 	\
729                 doc/tcmalloc-opspercpusec.vs.threads.256.bytes.png 	\
730                 doc/tcmalloc-opspercpusec.vs.threads.32768.bytes.png 	\
731                 doc/tcmalloc-opspercpusec.vs.threads.4096.bytes.png 	\
732                 doc/tcmalloc-opspercpusec.vs.threads.512.bytes.png 	\
733                 doc/tcmalloc-opspercpusec.vs.threads.64.bytes.png 	\
734                 doc/tcmalloc-opspercpusec.vs.threads.65536.bytes.png 	\
735                 doc/tcmalloc-opspercpusec.vs.threads.8192.bytes.png 	\
736                 doc/tcmalloc-opspersec.vs.size.1.threads.png 		\
737                 doc/tcmalloc-opspersec.vs.size.12.threads.png 		\
738                 doc/tcmalloc-opspersec.vs.size.16.threads.png 		\
739                 doc/tcmalloc-opspersec.vs.size.2.threads.png 		\
740                 doc/tcmalloc-opspersec.vs.size.20.threads.png 		\
741                 doc/tcmalloc-opspersec.vs.size.3.threads.png 		\
742                 doc/tcmalloc-opspersec.vs.size.4.threads.png 		\
743                 doc/tcmalloc-opspersec.vs.size.5.threads.png 		\
744                 doc/tcmalloc-opspersec.vs.size.8.threads.png
745
746# I don't know how to say "distribute the .dot files but don't install them";
747# noinst doesn't seem to work with data.  I separate them out anyway, in case
748# one day we figure it out.  Regardless, installing the dot files isn't the
749# end of the world.
750dist_doc_DATA += doc/overview.dot \
751                 doc/pageheap.dot \
752                 doc/spanmap.dot \
753                 doc/threadheap.dot
754
755
756### ------- tcmalloc_minimal_debug (thread-caching malloc with debugallocation)
757
758# Like tcmalloc.cc, debugallocation.cc needs exceptions to fulfill its
759# API.  Luckily, we can reuse everything else from tcmalloc_minimal.
760
761if WITH_DEBUGALLOC
762
763lib_LTLIBRARIES += libtcmalloc_minimal_debug.la
764libtcmalloc_minimal_debug_la_SOURCES = src/debugallocation.cc \
765                                       $(TCMALLOC_MINIMAL_INCLUDES)
766libtcmalloc_minimal_debug_la_CXXFLAGS = $(libtcmalloc_minimal_la_CXXFLAGS) \
767                                        -DTCMALLOC_FOR_DEBUGALLOCATION
768# version_info gets passed to libtool
769libtcmalloc_minimal_debug_la_LDFLAGS = $(libtcmalloc_minimal_la_LDFLAGS) \
770                                       -version-info @TCMALLOC_SO_VERSION@
771libtcmalloc_minimal_debug_la_LIBADD = $(libtcmalloc_minimal_la_LIBADD)
772
773LIBS_TO_WEAKEN += libtcmalloc_minimal_debug.la
774
775### Unittests
776
777TESTS += tcmalloc_minimal_debug_unittest
778tcmalloc_minimal_debug_unittest_SOURCES = $(tcmalloc_minimal_unittest_SOURCES)
779tcmalloc_minimal_debug_unittest_CXXFLAGS = $(tcmalloc_minimal_unittest_CXXFLAGS) \
780                                           -DDEBUGALLOCATION
781tcmalloc_minimal_debug_unittest_LDFLAGS = $(tcmalloc_minimal_unittest_LDFLAGS)
782tcmalloc_minimal_debug_unittest_LDADD = libtcmalloc_minimal_debug.la $(PTHREAD_LIBS)
783
784TESTS += malloc_extension_debug_test
785malloc_extension_debug_test_SOURCES = $(malloc_extension_test_SOURCES)
786malloc_extension_debug_test_CXXFLAGS = $(malloc_extension_test_CXXFLAGS)
787malloc_extension_debug_test_LDFLAGS = $(malloc_extension_test_LDFLAGS)
788malloc_extension_debug_test_LDADD = libtcmalloc_minimal_debug.la $(PTHREAD_LIBS)
789
790if !MINGW
791if !OSX
792TESTS += memalign_debug_unittest
793memalign_debug_unittest_SOURCES = $(memalign_unittest_SOURCES)
794memalign_debug_unittest_CXXFLAGS = $(memalign_unittest_CXXFLAGS)
795memalign_debug_unittest_LDFLAGS = $(memalign_unittest_LDFLAGS)
796memalign_debug_unittest_LDADD = libtcmalloc_minimal_debug.la $(PTHREAD_LIBS)
797endif !OSX
798endif !MINGW
799
800TESTS += realloc_debug_unittest
801realloc_debug_unittest_SOURCES = $(realloc_unittest_SOURCES)
802realloc_debug_unittest_CXXFLAGS = $(realloc_unittest_CXXFLAGS)
803realloc_debug_unittest_LDFLAGS = $(realloc_unittest_LDFLAGS)
804realloc_debug_unittest_LDADD = libtcmalloc_minimal_debug.la $(PTHREAD_LIBS)
805
806# debugallocation_test checks that we print a proper stacktrace when
807# debug-allocs fail, so we can't run it if we don't have stacktrace info.
808if WITH_STACK_TRACE
809TESTS += debugallocation_test.sh$(EXEEXT)
810debugallocation_test_sh_SOURCES = src/tests/debugallocation_test.sh
811noinst_SCRIPTS += $(debugallocation_test_sh_SOURCES)
812debugallocation_test.sh$(EXEEXT): $(top_srcdir)/$(debugallocation_test_sh_SOURCES) \
813                                  debugallocation_test
814	rm -f $@
815	cp -p $(top_srcdir)/$(debugallocation_test_sh_SOURCES) $@
816
817# This is the sub-program used by debugallocation_test.sh
818noinst_PROGRAMS += debugallocation_test
819debugallocation_test_SOURCES = src/tests/debugallocation_test.cc
820debugallocation_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
821debugallocation_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
822debugallocation_test_LDADD = libtcmalloc_debug.la $(PTHREAD_LIBS)
823endif WITH_STACK_TRACE
824
825endif WITH_DEBUGALLOC
826
827
828### ------- tcmalloc (thread-caching malloc + heap profiler + heap checker)
829
830if WITH_HEAP_PROFILER_OR_CHECKER
831
832### The header files we use.  We divide into categories based on directory
833S_TCMALLOC_INCLUDES = $(S_TCMALLOC_MINIMAL_INCLUDES) \
834                      $(LOGGING_INCLUDES) \
835                      src/addressmap-inl.h \
836                      src/raw_printer.h \
837                      src/base/elfcore.h \
838                      src/base/googleinit.h \
839                      src/base/linux_syscall_support.h \
840                      src/base/linuxthreads.h \
841                      src/base/stl_allocator.h \
842                      src/base/sysinfo.h \
843                      src/base/thread_lister.h \
844                      src/heap-profile-table.h
845SG_TCMALLOC_INCLUDES = $(SG_TCMALLOC_MINIMAL_INCLUDES) \
846                       src/gperftools/heap-profiler.h \
847                       src/gperftools/heap-checker.h
848TCMALLOC_INCLUDES = $(S_TCMALLOC_INCLUDES) $(SG_TCMALLOC_INCLUDES)
849perftoolsinclude_HEADERS += $(SG_TCMALLOC_INCLUDES)
850
851### Making the library
852
853# As we describe at the top of this file, we want to turn off exceptions
854# for all files in this library -- except tcmalloc.cc which needs them
855# to fulfill its API.  Automake doesn't allow per-file CXXFLAGS, so we need
856# to separate into two libraries.
857noinst_LTLIBRARIES += libtcmalloc_internal.la
858libtcmalloc_internal_la_SOURCES = $(libtcmalloc_minimal_internal_la_SOURCES) \
859                                  $(TCMALLOC_INCLUDES) \
860                                  src/base/low_level_alloc.cc \
861                                  src/heap-profile-table.cc \
862                                  src/heap-profiler.cc \
863                                  src/raw_printer.cc \
864                                  src/memory_region_map.cc
865libtcmalloc_internal_la_CXXFLAGS = $(PTHREAD_CFLAGS) -DNDEBUG \
866                                   $(AM_CXXFLAGS) $(NO_EXCEPTIONS)
867libtcmalloc_internal_la_LDFLAGS = $(PTHREAD_CFLAGS)
868libtcmalloc_internal_la_LIBADD = libstacktrace.la $(PTHREAD_LIBS)
869
870lib_LTLIBRARIES += libtcmalloc.la
871libtcmalloc_la_SOURCES = $(TCMALLOC_CC) $(TCMALLOC_INCLUDES)
872libtcmalloc_la_CXXFLAGS = $(PTHREAD_CFLAGS) -DNDEBUG $(AM_CXXFLAGS)
873libtcmalloc_la_LDFLAGS = $(PTHREAD_CFLAGS) -version-info @TCMALLOC_SO_VERSION@
874libtcmalloc_la_LIBADD = libtcmalloc_internal.la $(PTHREAD_LIBS)
875
876if WITH_HEAP_CHECKER
877# heap-checker-bcad is last, in hopes its global ctor will run first.
878# (Note this is added to libtcmalloc.la, not libtcmalloc_internal.la,
879# but that's ok; the internal/external distinction is only useful for
880# cygwin, and cygwin doesn't use HEAP_CHECKER anyway.)
881HEAP_CHECKER_SOURCES = src/base/thread_lister.c \
882                       src/base/linuxthreads.cc \
883                       src/heap-checker.cc \
884                       src/heap-checker-bcad.cc
885libtcmalloc_la_SOURCES += $(HEAP_CHECKER_SOURCES)
886else !WITH_HEAP_CHECKER
887HEAP_CHECKER_SOURCES =
888libtcmalloc_internal_la_CXXFLAGS += -DNO_HEAP_CHECK
889libtcmalloc_la_CXXFLAGS += -DNO_HEAP_CHECK
890endif !WITH_HEAP_CHECKER
891
892LIBTCMALLOC = libtcmalloc.la
893
894LIBS_TO_WEAKEN += libtcmalloc.la
895
896### Unittests
897
898TESTS += tcmalloc_unittest
899TCMALLOC_UNITTEST_INCLUDES = src/config_for_unittests.h \
900                             src/gperftools/malloc_extension.h
901tcmalloc_unittest_SOURCES = src/tests/tcmalloc_unittest.cc \
902                            src/tcmalloc.h \
903                            src/tests/testutil.h src/tests/testutil.cc \
904                            $(TCMALLOC_UNITTEST_INCLUDES)
905tcmalloc_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
906tcmalloc_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
907# We want libtcmalloc last on the link line, but due to a bug in
908# libtool involving convenience libs, they need to come last on the
909# link line in order to get dependency ordering right.  This is ok:
910# convenience libraries are .a's, so tcmalloc is still the last .so.
911# We also put pthreads after tcmalloc, because some pthread
912# implementations define their own malloc, and we need to go on the
913# first linkline to make sure our malloc 'wins'.
914tcmalloc_unittest_LDADD = $(LIBTCMALLOC) liblogging.la $(PTHREAD_LIBS)
915
916# This makes sure it's safe to link in both tcmalloc and
917# tcmalloc_minimal.  (One would never do this on purpose, but perhaps
918# by accident...)  When we can compile libprofiler, we also link it in
919# to make sure that works too.  NOTE: On OS X, it's *not* safe to
920# link both in (we end up with two copies of every global var, and
921# the code tends to pick one arbitrarily), so don't run the test there.
922# (We define these outside the 'if' because they're reused below.)
923tcmalloc_both_unittest_srcs = src/tests/tcmalloc_unittest.cc \
924                              src/tests/testutil.h src/tests/testutil.cc \
925                              $(TCMALLOC_UNITTEST_INCLUDES)
926tcmalloc_both_unittest_cflags = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
927tcmalloc_both_unittest_lflags = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
928if WITH_CPU_PROFILER
929# We want libtcmalloc last on the link line, but due to a bug in
930# libtool involving convenience libs, they need to come last on the
931# link line in order to get dependency ordering right.  This is ok:
932# convenience libraries are .a's, so tcmalloc is still the last .so.
933# We also put pthreads after tcmalloc, because some pthread
934# implementations define their own malloc, and we need to go on the
935# first linkline to make sure our malloc 'wins'.
936tcmalloc_both_unittest_ladd = $(LIBTCMALLOC) $(LIBTCMALLOC_MINIMAL) \
937                              libprofiler.la liblogging.la $(PTHREAD_LIBS)
938else
939tcmalloc_both_unittest_ladd = $(LIBTCMALLOC) $(LIBTCMALLOC_MINIMAL) \
940                              liblogging.la $(PTHREAD_LIBS)
941endif !WITH_CPU_PROFILER
942if !OSX
943TESTS += tcmalloc_both_unittest
944tcmalloc_both_unittest_SOURCES = $(tcmalloc_both_unittest_srcs)
945tcmalloc_both_unittest_CXXFLAGS = $(tcmalloc_both_unittest_cflags)
946tcmalloc_both_unittest_LDFLAGS = $(tcmalloc_both_unittest_lflags)
947tcmalloc_both_unittest_LDADD = $(tcmalloc_both_unittest_ladd)
948endif !OSX
949
950TESTS += tcmalloc_large_unittest
951tcmalloc_large_unittest_SOURCES = src/tests/tcmalloc_large_unittest.cc
952tcmalloc_large_unittest_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
953tcmalloc_large_unittest_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
954tcmalloc_large_unittest_LDADD = $(LIBTCMALLOC) $(PTHREAD_LIBS)
955
956TESTS += raw_printer_test
957raw_printer_test_SOURCES = src/tests/raw_printer_test.cc
958raw_printer_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
959raw_printer_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
960raw_printer_test_LDADD = $(LIBTCMALLOC) $(PTHREAD_LIBS)
961
962# sampler_test and sampling_test both require sampling to be turned
963# on, which it's not by default.  Use the "standard" value of 2^19.
964TESTS_ENVIRONMENT += TCMALLOC_SAMPLE_PARAMETER=524288
965
966TESTS += sampler_test
967WINDOWS_PROJECTS += vsprojects/sampler_test/sampler_test.vcproj
968sampler_test_SOURCES = src/tests/sampler_test.cc \
969                       src/config_for_unittests.h
970sampler_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
971sampler_test_LDFLAGS = $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
972sampler_test_LDADD = $(LIBTCMALLOC) $(PTHREAD_LIBS) -lm
973
974
975# These unittests often need to run binaries.  They're in the current dir
976TESTS_ENVIRONMENT += BINDIR=.
977TESTS_ENVIRONMENT += TMPDIR=/tmp/perftools
978
979TESTS += sampling_test.sh$(EXEEXT)
980sampling_test_sh_SOURCES = src/tests/sampling_test.sh
981noinst_SCRIPTS += $(sampling_test_sh_SOURCES)
982sampling_test.sh$(EXEEXT): $(top_srcdir)/$(sampling_test_sh_SOURCES) \
983                           sampling_test
984	rm -f $@
985	cp -p $(top_srcdir)/$(sampling_test_sh_SOURCES) $@
986
987# This is the sub-program used by sampling_test.sh
988# The -g is so pprof can get symbol information.
989noinst_PROGRAMS += sampling_test
990SAMPLING_TEST_INCLUDES = src/config_for_unittests.h \
991                         src/base/logging.h \
992                         src/gperftools/malloc_extension.h
993sampling_test_SOURCES = src/tests/sampling_test.cc \
994                        $(SAMPLING_TEST_INCLUDES)
995sampling_test_CXXFLAGS = -g $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
996sampling_test_LDFLAGS = -g $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
997sampling_test_LDADD = $(LIBTCMALLOC) $(PTHREAD_LIBS)
998
999endif WITH_HEAP_PROFILER_OR_CHECKER
1000
1001if WITH_HEAP_PROFILER
1002
1003TESTS += heap-profiler_unittest.sh$(EXEEXT)
1004heap_profiler_unittest_sh_SOURCES = src/tests/heap-profiler_unittest.sh
1005noinst_SCRIPTS += $(heap_profiler_unittest_sh_SOURCES)
1006heap-profiler_unittest.sh$(EXEEXT): $(top_srcdir)/$(heap_profiler_unittest_sh_SOURCES) \
1007                                    heap-profiler_unittest
1008	rm -f $@
1009	cp -p $(top_srcdir)/$(heap_profiler_unittest_sh_SOURCES) $@
1010
1011# These are sub-programs used by heap-profiler_unittest.sh
1012noinst_PROGRAMS += heap-profiler_unittest
1013HEAP_PROFILER_UNITTEST_INCLUDES = src/config_for_unittests.h \
1014                                  src/gperftools/heap-profiler.h
1015heap_profiler_unittest_SOURCES = src/tests/heap-profiler_unittest.cc \
1016                                 $(HEAP_PROFILER_UNITTEST_INCLUDES)
1017heap_profiler_unittest_CXXFLAGS = -g $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
1018heap_profiler_unittest_LDFLAGS = -g $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
1019heap_profiler_unittest_LDADD = $(LIBTCMALLOC) $(PTHREAD_LIBS)
1020
1021# Tests the compatibility include-headers in google/.  Requires a function
1022# defined in the heap-profiler, which is why the test lives here.
1023TESTS += simple_compat_test
1024simple_compat_test_SOURCES = src/tests/simple_compat_test.cc \
1025                             $(googleinclude_HEADERS)
1026simple_compat_test_LDFLAGS = $(TCMALLOC_FLAGS)
1027simple_compat_test_LDADD = $(LIBTCMALLOC)
1028
1029endif WITH_HEAP_PROFILER
1030
1031if WITH_HEAP_CHECKER
1032
1033TESTS += heap-checker_unittest.sh$(EXEEXT)
1034heap_checker_unittest_sh_SOURCES = src/tests/heap-checker_unittest.sh
1035noinst_SCRIPTS += $(heap_checker_unittest_sh_SOURCES)
1036heap-checker_unittest.sh$(EXEEXT): $(top_srcdir)/$(heap_checker_unittest_sh_SOURCES) \
1037                                   heap-checker_unittest
1038	rm -f $@
1039	cp -p $(top_srcdir)/$(heap_checker_unittest_sh_SOURCES) $@
1040
1041TESTS += heap-checker-death_unittest.sh$(EXEEXT)
1042heap_checker_death_unittest_sh_SOURCES = src/tests/heap-checker-death_unittest.sh
1043noinst_SCRIPTS += $(top_srcdir)/$(heap_checker_death_unittest_sh_SOURCES)
1044heap-checker-death_unittest.sh$(EXEEXT): $(heap_checker_death_unittest_sh_SOURCES) \
1045                                         heap-checker_unittest
1046	rm -f $@
1047	cp -p $(top_srcdir)/$(heap_checker_death_unittest_sh_SOURCES) $@
1048
1049# These are sub-programs used by heap-checker_unittest.sh
1050noinst_PROGRAMS += heap-checker_unittest
1051HEAP_CHECKER_UNITTEST_INCLUDES = src/config_for_unittests.h \
1052                                 src/memory_region_map.h \
1053                                 src/base/commandlineflags.h \
1054                                 src/base/googleinit.h \
1055                                 src/gperftools/heap-checker.h \
1056                                 $(LOGGING_INCLUDES)
1057heap_checker_unittest_SOURCES = src/tests/heap-checker_unittest.cc \
1058                                $(HEAP_CHECKER_UNITTEST_INCLUDES)
1059heap_checker_unittest_CXXFLAGS = -g $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
1060heap_checker_unittest_LDFLAGS = -g $(PTHREAD_CFLAGS) $(TCMALLOC_FLAGS)
1061# We want libtcmalloc last on the link line, but due to a bug in
1062# libtool involving convenience libs, they need to come last on the
1063# link line in order to get dependency ordering right.  This is ok:
1064# convenience libraries are .a's, so tcmalloc is still the last .so.
1065# We also put pthreads after tcmalloc, because some pthread
1066# implementations define their own malloc, and we need to go on the
1067# first linkline to make sure our malloc 'wins'.
1068heap_checker_unittest_LDADD = $(LIBTCMALLOC) liblogging.la $(PTHREAD_LIBS)
1069
1070endif WITH_HEAP_CHECKER
1071
1072### Documentation (above and beyond tcmalloc_minimal documentation)
1073if WITH_HEAP_PROFILER
1074dist_doc_DATA += doc/heapprofile.html doc/heap-example1.png
1075endif WITH_HEAP_PROFILER
1076
1077if WITH_HEAP_CHECKER
1078dist_doc_DATA += doc/heap_checker.html
1079endif WITH_HEAP_CHECKER
1080
1081
1082### ------- tcmalloc with debugallocation
1083
1084if WITH_DEBUGALLOC
1085if WITH_HEAP_PROFILER_OR_CHECKER
1086
1087lib_LTLIBRARIES += libtcmalloc_debug.la
1088libtcmalloc_debug_la_SOURCES = src/debugallocation.cc $(HEAP_CHECKER_SOURCES) \
1089                               $(TCMALLOC_INCLUDES)
1090libtcmalloc_debug_la_CXXFLAGS = $(libtcmalloc_la_CXXFLAGS) \
1091                                -DTCMALLOC_FOR_DEBUGALLOCATION
1092libtcmalloc_debug_la_LDFLAGS = $(libtcmalloc_la_LDFLAGS) \
1093                               -version-info @TCMALLOC_SO_VERSION@
1094libtcmalloc_debug_la_LIBADD = $(libtcmalloc_la_LIBADD)
1095
1096LIBS_TO_WEAKEN += libtcmalloc_debug.la
1097
1098### Unittests
1099
1100TESTS += tcmalloc_debug_unittest
1101tcmalloc_debug_unittest_SOURCES = $(tcmalloc_unittest_SOURCES)
1102tcmalloc_debug_unittest_CXXFLAGS = $(tcmalloc_unittest_CXXFLAGS) \
1103                                   -DDEBUGALLOCATION
1104tcmalloc_debug_unittest_LDFLAGS = $(tcmalloc_unittest_LDFLAGS)
1105tcmalloc_debug_unittest_LDADD = libtcmalloc_debug.la $(PTHREAD_LIBS)
1106
1107TESTS += sampler_debug_test
1108sampler_debug_test_SOURCES = $(sampler_test_SOURCES)
1109sampler_debug_test_CXXFLAGS = $(samples_test_CXXFLAGS)
1110sampler_debug_test_LDFLAGS = $(sampler_test_LDFLAGS)
1111sampler_debug_test_LDADD = libtcmalloc_debug.la $(PTHREAD_LIBS) -lm
1112
1113TESTS += sampling_debug_test.sh$(EXEEXT)
1114sampling_debug_test_sh_SOURCES = src/tests/sampling_test.sh
1115sampling_debug_test.sh$(EXEEXT): $(top_srcdir)/$(sampling_test_sh_SOURCES) \
1116                                 sampling_debug_test
1117	rm -f $@
1118	cp -p $(top_srcdir)/$(sampling_test_sh_SOURCES) $@
1119
1120# This is the sub-program using by sampling_debug_test.sh
1121# The -g is so pprof can get symbol information.
1122noinst_PROGRAMS += sampling_debug_test
1123sampling_debug_test_SOURCES = $(sampling_test_SOURCES)
1124sampling_debug_test_CXXFLAGS = $(sampling_test_CXXFLAGS)
1125sampling_debug_test_LDFLAGS = $(sampling_test_LDFLAGS)
1126sampling_debug_test_LDADD = libtcmalloc_debug.la $(PTHREAD_LIBS)
1127
1128endif WITH_HEAP_PROFILER_OR_CHECKER
1129
1130if WITH_HEAP_PROFILER
1131
1132TESTS += heap-profiler_debug_unittest.sh$(EXEEXT)
1133heap_profiler_debug_unittest_sh_SOURCES = src/tests/heap-profiler_unittest.sh
1134heap-profiler_debug_unittest.sh$(EXEEXT): $(top_srcdir)/$(heap_profiler_unittest_sh_SOURCES) \
1135                                    heap-profiler_debug_unittest
1136	rm -f $@
1137	cp -p $(top_srcdir)/$(heap_profiler_unittest_sh_SOURCES) $@
1138
1139# These are sub-programs used by heap-profiler_debug_unittest.sh
1140noinst_PROGRAMS += heap-profiler_debug_unittest
1141heap_profiler_debug_unittest_SOURCES = $(heap_profiler_unittest_SOURCES)
1142heap_profiler_debug_unittest_CXXFLAGS = $(heap_profiler_unittest_CXXFLAGS)
1143heap_profiler_debug_unittest_LDFLAGS = $(heap_profiler_unittest_LDFLAGS)
1144heap_profiler_debug_unittest_LDADD = libtcmalloc_debug.la $(PTHREAD_LIBS)
1145
1146endif WITH_HEAP_PROFILER
1147
1148if WITH_HEAP_CHECKER
1149
1150TESTS += heap-checker_debug_unittest.sh$(EXEEXT)
1151heap_checker_debug_unittest_sh_SOURCES = src/tests/heap-checker_unittest.sh
1152heap-checker_debug_unittest.sh$(EXEEXT): $(top_srcdir)/$(heap_checker_unittest_sh_SOURCES) \
1153                                   heap-checker_debug_unittest
1154	rm -f $@
1155	cp -p $(top_srcdir)/$(heap_checker_unittest_sh_SOURCES) $@
1156
1157# These are sub-programs used by heap-checker_debug_unittest.sh
1158noinst_PROGRAMS += heap-checker_debug_unittest
1159heap_checker_debug_unittest_SOURCES = $(heap_checker_unittest_SOURCES)
1160heap_checker_debug_unittest_CXXFLAGS = $(heap_checker_unittest_CXXFLAGS)
1161heap_checker_debug_unittest_LDFLAGS = $(heap_checker_unittest_LDFLAGS)
1162# We want libtcmalloc last on the link line, but due to a bug in
1163# libtool involving convenience libs, they need to come last on the
1164# link line in order to get dependency ordering right.  This is ok:
1165# convenience libraries are .a's, so tcmalloc is still the last .so.
1166heap_checker_debug_unittest_LDADD = libtcmalloc_debug.la liblogging.la \
1167                                    $(PTHREAD_LIBS)
1168
1169endif WITH_HEAP_CHECKER
1170endif WITH_DEBUGALLOC
1171
1172
1173### ------- CPU profiler
1174
1175if WITH_CPU_PROFILER
1176
1177### The header files we use.  We divide into categories based on directory
1178S_CPU_PROFILER_INCLUDES = src/profiledata.h \
1179                          src/profile-handler.h \
1180                          src/getpc.h \
1181                          src/base/basictypes.h \
1182                          src/base/commandlineflags.h \
1183                          src/base/googleinit.h \
1184                          src/base/logging.h \
1185                          src/base/simple_mutex.h \
1186                          src/base/sysinfo.h \
1187                          $(SPINLOCK_INCLUDES) \
1188                          $(LOGGING_INCLUDES)
1189SG_CPU_PROFILER_INCLUDES = src/gperftools/profiler.h \
1190                           src/gperftools/stacktrace.h
1191CPU_PROFILER_INCLUDES = $(S_CPU_PROFILER_INCLUDES) $(SG_CPU_PROFILER_INCLUDES)
1192perftoolsinclude_HEADERS += $(SG_CPU_PROFILER_INCLUDES)
1193
1194### Making the library
1195lib_LTLIBRARIES += libprofiler.la
1196libprofiler_la_SOURCES = src/profiler.cc \
1197                         src/profile-handler.cc \
1198                         src/profiledata.cc \
1199                         $(CPU_PROFILER_INCLUDES)
1200libprofiler_la_LIBADD = libstacktrace.la
1201# We have to include ProfileData for profiledata_unittest
1202CPU_PROFILER_SYMBOLS = '(ProfilerStart|ProfilerStartWithOptions|ProfilerStop|ProfilerFlush|ProfilerEnable|ProfilerDisable|ProfilingIsEnabledForAllThreads|ProfilerRegisterThread|ProfilerGetCurrentState|ProfilerState|ProfileData|ProfileHandler)'
1203libprofiler_la_LDFLAGS = -export-symbols-regex $(CPU_PROFILER_SYMBOLS) \
1204                         -version-info @PROFILER_SO_VERSION@
1205
1206# See discussion above (under LIBTCMALLOC_MINIMAL) for why we do this.
1207# Basically it's to work around systems where --rpath doesn't work right.
1208LIBPROFILER = libstacktrace.la libprofiler.la
1209
1210### Unittests
1211TESTS += getpc_test
1212#WINDOWS_PROJECTS += vsprojects/getpc_test/getpc_test.vcproj
1213getpc_test_SOURCES = src/tests/getpc_test.cc src/getpc.h
1214
1215TESTS += profiledata_unittest
1216#WINDOWS_PROJECTS += vsprojects/profiledata_unittest/profiledata_unittest.vcproj
1217profiledata_unittest_SOURCES = src/tests/profiledata_unittest.cc \
1218                               src/profiledata.h \
1219                               src/base/commandlineflags.h \
1220                               src/base/logging.h \
1221                               src/base/basictypes.h
1222profiledata_unittest_LDADD = $(LIBPROFILER)
1223
1224TESTS += profile_handler_unittest
1225profile_handler_unittest_SOURCES = src/tests/profile-handler_unittest.cc \
1226                                   src/profile-handler.h
1227profile_handler_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
1228profile_handler_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
1229profile_handler_unittest_LDADD = $(LIBPROFILER) $(PTHREAD_LIBS)
1230
1231TESTS += profiler_unittest.sh$(EXEEXT)
1232profiler_unittest_sh_SOURCES = src/tests/profiler_unittest.sh
1233noinst_SCRIPTS += $(profiler_unittest_sh_SOURCES)
1234profiler_unittest.sh$(EXEEXT): $(top_srcdir)/$(profiler_unittest_sh_SOURCES) \
1235                               profiler1_unittest profiler2_unittest \
1236                               profiler3_unittest profiler4_unittest
1237	rm -f $@
1238	cp -p $(top_srcdir)/$(profiler_unittest_sh_SOURCES) $@
1239
1240# These are sub-programs used by profiler_unittest.sh
1241noinst_PROGRAMS += profiler1_unittest profiler2_unittest profiler3_unittest \
1242                   profiler4_unittest
1243PROFILER_UNITTEST_INCLUDES = src/config_for_unittests.h \
1244                             src/gperftools/profiler.h
1245PROFILER_UNITTEST_SRCS = src/tests/profiler_unittest.cc \
1246                         src/tests/testutil.h src/tests/testutil.cc \
1247                         $(PROFILER_UNITTEST_INCLUDES)
1248profiler1_unittest_SOURCES = $(PROFILER_UNITTEST_SRCS)
1249profiler1_unittest_CXXFLAGS = -g -DNO_THREADS $(AM_CXXFLAGS)
1250profiler1_unittest_LDADD = $(LIBPROFILER)
1251profiler2_unittest_SOURCES = $(PROFILER_UNITTEST_SRCS)
1252profiler2_unittest_CXXFLAGS = -g -DNO_THREADS $(AM_CXXFLAGS)
1253profiler2_unittest_LDADD = -lstacktrace -lprofiler
1254# We depend on -lprofiler but haven't yet said how to build it.  Do so now.
1255profiler2_unittest_DEPENDENCIES = $(LIBPROFILER)
1256profiler3_unittest_SOURCES = $(PROFILER_UNITTEST_SRCS)
1257profiler3_unittest_CXXFLAGS = -g $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
1258profiler3_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
1259profiler3_unittest_LDADD = $(LIBPROFILER) $(PTHREAD_LIBS)
1260profiler4_unittest_SOURCES = $(PROFILER_UNITTEST_SRCS)
1261profiler4_unittest_CXXFLAGS = -g $(PTHREAD_CFLAGS) $(AM_CXXFLAGS)
1262profiler4_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
1263profiler4_unittest_LDADD = -lstacktrace -lprofiler $(PTHREAD_LIBS)
1264# We depend on -lprofiler but haven't yet said how to build it.  Do so now.
1265profiler4_unittest_DEPENDENCIES = $(LIBPROFILER)
1266
1267
1268### Documentation
1269dist_doc_DATA += doc/cpuprofile.html \
1270                 doc/cpuprofile-fileformat.html \
1271                 doc/pprof-test-big.gif \
1272                 doc/pprof-test.gif \
1273                 doc/pprof-vsnprintf-big.gif \
1274                 doc/pprof-vsnprintf.gif
1275
1276endif WITH_CPU_PROFILER
1277
1278
1279### ------- CPU profiler and heap checker, in one!
1280
1281# Ideally, folks who wanted to use both tcmalloc and libprofiler,
1282# could just link them both into their application.  But while this
1283# works fine for .so files, it does not for .a files.  The easiest way
1284# around this -- and I've tried a bunch of the hard ways -- is to just
1285# to create another set of libraries that has both functionality in it.
1286
1287if WITH_HEAP_PROFILER_OR_CHECKER
1288if WITH_CPU_PROFILER
1289
1290lib_LTLIBRARIES += libtcmalloc_and_profiler.la
1291libtcmalloc_and_profiler_la_SOURCES = $(libtcmalloc_la_SOURCES) $(libprofiler_la_SOURCES)
1292libtcmalloc_and_profiler_la_CXXFLAGS = $(libtcmalloc_la_CXXFLAGS) $(libprofiler_la_CXXFLAGS)
1293# Since this library is meant to be used as a .a, I don't worry as much
1294# about .so versioning.  I just give the libtcmalloc version number.
1295# TODO(csilvers): use -export-symbols-regex?
1296libtcmalloc_and_profiler_la_LDFLAGS = $(PTHREAD_CFLAGS) \
1297                                      -version-info @TCMALLOC_SO_VERSION@
1298# We don't include libprofiler_la_LIBADD here because all it adds is
1299# libstacktrace.la, which we already get via libtcmalloc.  Trying to
1300# specify it twice causes link-time duplicate-definition errors. :-(
1301libtcmalloc_and_profiler_la_LIBADD = $(libtcmalloc_la_LIBADD)
1302
1303TESTS += tcmalloc_and_profiler_unittest
1304tcmalloc_and_profiler_unittest_SOURCES = $(tcmalloc_both_unittest_srcs)
1305tcmalloc_and_profiler_unittest_CXXFLAGS = $(tcmalloc_both_unittest_cflags)
1306tcmalloc_and_profiler_unittest_LDFLAGS = $(tcmalloc_both_unittest_lflags)
1307tcmalloc_and_profiler_unittest_LDADD = libtcmalloc_and_profiler.la
1308
1309LIBS_TO_WEAKEN += libtcmalloc_and_profiler.la
1310
1311endif WITH_CPU_PROFILER
1312endif WITH_HEAP_PROFILER_OR_CHECKER
1313
1314## ^^^^ END OF RULES TO MAKE YOUR LIBRARIES, BINARIES, AND UNITTESTS
1315
1316
1317# Do the weakening on some exported libtcmalloc symbols.
1318install-exec-local: all-local
1319all-local: $(LIBS_TO_WEAKEN)
1320	for la in $(LIBS_TO_WEAKEN); do lib=".libs/`basename $$la .la`.a"; [ ! -f "$$lib" ] || $(WEAKEN) "$$lib"; done
1321
1322
1323# This should always include $(TESTS), but may also include other
1324# binaries that you compile but don't want automatically installed.
1325# We'll add to this later, on a library-by-library basis
1326noinst_PROGRAMS += $(TESTS)
1327
1328rpm: dist-gzip packages/rpm.sh packages/rpm/rpm.spec
1329	@cd packages && ./rpm.sh ${PACKAGE} ${VERSION}
1330
1331deb: dist-gzip packages/deb.sh packages/deb/*
1332	@cd packages && ./deb.sh ${PACKAGE} ${VERSION}
1333
1334# http://linux.die.net/man/1/pkg-config, http://pkg-config.freedesktop.org/wiki
1335pkgconfigdir = $(libdir)/pkgconfig
1336pkgconfig_DATA = libtcmalloc.pc libtcmalloc_minimal.pc \
1337                 libtcmalloc_debug.pc libtcmalloc_minimal_debug.pc \
1338                 libprofiler.pc
1339CLEANFILES = $(pkgconfig_DATA)
1340
1341# I get the description and URL lines from the rpm spec. I use sed to
1342# try to rewrite exec_prefix, libdir, and includedir in terms of
1343# prefix, if possible.
1344libtcmalloc.pc: Makefile packages/rpm/rpm.spec
1345	echo 'prefix=$(prefix)' > "$@".tmp
1346	echo 'exec_prefix='`echo '$(exec_prefix)' | sed 's@^$(prefix)@$${prefix}@'` >> "$@".tmp
1347	echo 'libdir='`echo '$(libdir)' | sed 's@^$(exec_prefix)@$${exec_prefix}@'` >> "$@".tmp
1348	echo 'includedir='`echo '$(includedir)' | sed 's@^$(prefix)@$${prefix}@'` >> "$@".tmp
1349	echo '' >> "$@".tmp
1350	echo 'Name: $(PACKAGE)' >> "$@".tmp
1351	echo 'Version: $(VERSION)' >> "$@".tmp
1352	-grep '^Summary:' $(top_srcdir)/packages/rpm/rpm.spec | sed s/^Summary:/Description:/ | head -n1 >> "$@".tmp
1353	-grep '^URL: ' $(top_srcdir)/packages/rpm/rpm.spec >> "$@".tmp
1354	echo 'Requires:' >> "$@".tmp
1355	echo 'Libs: -L$${libdir} -ltcmalloc' >> "$@".tmp
1356	echo 'Libs.private: $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)' >> "$@".tmp
1357	echo 'Cflags: -I$${includedir}' >> "$@".tmp
1358	mv -f "$@".tmp "$@"
1359
1360# The other versions are mostly the same.
1361libtcmalloc_minimal.pc: libtcmalloc.pc
1362	cat libtcmalloc.pc | sed s/-ltcmalloc/-ltcmalloc_minimal/ > "$@"
1363
1364libtcmalloc_debug.pc: libtcmalloc.pc
1365	cat libtcmalloc.pc | sed s/-ltcmalloc/-ltcmalloc_debug/ > "$@"
1366
1367libtcmalloc_minimal_debug.pc: libtcmalloc.pc
1368	cat libtcmalloc.pc | sed s/-ltcmalloc/-ltcmalloc_minimal_debug/ > "$@"
1369
1370libprofiler.pc: libtcmalloc.pc
1371	cat libtcmalloc.pc | sed s/-ltcmalloc/-lprofiler/ > "$@"
1372
1373libtool: $(LIBTOOL_DEPS)
1374	$(SHELL) ./config.status --recheck
1375
1376# Windows wants write permission to .vcproj files and maybe even sln files.
1377dist-hook:
1378	test -e "$(distdir)/vsprojects" \
1379	   && chmod -R u+w $(distdir)/*.sln $(distdir)/vsprojects/
1380
1381EXTRA_DIST = packages/rpm.sh packages/rpm/rpm.spec packages/deb.sh packages/deb \
1382             $(SCRIPTS) libtool \
1383             src/windows/get_mangled_names.cc src/windows/override_functions.cc \
1384             src/windows/config.h src/windows/gperftools/tcmalloc.h \
1385             $(WINDOWS_PROJECTS) \
1386             src/solaris/libstdc++.la
1387