1 # Makefile.am -- Backtrace Makefile.
2 # Copyright (C) 2012-2019 Free Software Foundation, Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # (1) Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
11 # (2) Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in
13 # the documentation and/or other materials provided with the
16 # (3) The name of the author may not be used to
17 # endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
32 ACLOCAL_AMFLAGS = -I .. -I ../config
34 AM_CPPFLAGS = -I $(top_srcdir)/../include -I $(top_srcdir)/../libgcc \
37 AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG)
39 noinst_LTLIBRARIES = libbacktrace.la
41 libbacktrace_la_SOURCES = \
71 EXTRA_libbacktrace_la_SOURCES = \
77 libbacktrace_la_LIBADD = \
83 libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
87 # Add test to this variable, if you want it to be build.
90 # Add test to this variable, if you want it to be run.
93 # Add test to this variable, if you want it to be build and run.
97 check_LTLIBRARIES = libbacktrace_alloc.la
99 libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
100 libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
102 libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
104 check_LTLIBRARIES += libbacktrace_noformat.la
106 libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
107 libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
109 libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
112 if HAVE_OBJCOPY_DEBUGLINK
114 TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
116 check_LTLIBRARIES += libbacktrace_elf_for_test.la
118 libbacktrace_elf_for_test_la_SOURCES = $(libbacktrace_la_SOURCES)
119 libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
120 $(VIEW_FILE) $(ALLOC_FILE)
122 elf_for_test.c: elf.c
123 SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
124 REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
125 $(SED) "s%$$SEARCH%$$REPLACE%" \
130 endif HAVE_OBJCOPY_DEBUGLINK
134 SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
135 REPLACE='#undef BACKTRACE_ELF_SIZE\
136 #define BACKTRACE_ELF_SIZE'; \
137 $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
143 SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
144 REPLACE='#undef BACKTRACE_XCOFF_SIZE\
145 #define BACKTRACE_XCOFF_SIZE'; \
146 $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
151 test_elf_32_SOURCES = test_format.c testlib.c
152 test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo
154 BUILDTESTS += test_elf_32
156 test_elf_64_SOURCES = test_format.c testlib.c
157 test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo
159 BUILDTESTS += test_elf_64
161 test_xcoff_32_SOURCES = test_format.c testlib.c
162 test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
164 BUILDTESTS += test_xcoff_32
166 test_xcoff_64_SOURCES = test_format.c testlib.c
167 test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
169 BUILDTESTS += test_xcoff_64
171 test_pecoff_SOURCES = test_format.c testlib.c
172 test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
174 BUILDTESTS += test_pecoff
176 test_unknown_SOURCES = test_format.c testlib.c
177 test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
179 BUILDTESTS += test_unknown
181 unittest_SOURCES = unittest.c testlib.c
182 unittest_LDADD = libbacktrace.la
184 BUILDTESTS += unittest
186 unittest_alloc_SOURCES = $(unittest_SOURCES)
187 unittest_alloc_LDADD = libbacktrace_alloc.la
189 BUILDTESTS += unittest_alloc
191 check_LTLIBRARIES += libbacktrace_instrumented_alloc.la
193 libbacktrace_instrumented_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
194 libbacktrace_instrumented_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) \
195 read.lo instrumented_alloc.lo
197 libbacktrace_instrumented_alloc_la_DEPENDENCIES = \
198 $(libbacktrace_instrumented_alloc_la_LIBADD)
200 instrumented_alloc.lo: alloc.c
202 allocfail_SOURCES = allocfail.c testlib.c
203 allocfail_LDADD = libbacktrace_instrumented_alloc.la
205 check_PROGRAMS += allocfail
207 allocfail.sh: allocfail
209 TESTS += allocfail.sh
212 if HAVE_OBJCOPY_DEBUGLINK
214 b2test_SOURCES = $(btest_SOURCES)
215 b2test_CFLAGS = $(btest_CFLAGS)
216 b2test_LDFLAGS = -Wl,--build-id
217 b2test_LDADD = libbacktrace_elf_for_test.la
219 check_PROGRAMS += b2test
220 TESTS += b2test_buildid
224 b3test_SOURCES = $(btest_SOURCES)
225 b3test_CFLAGS = $(btest_CFLAGS)
226 b3test_LDFLAGS = -Wl,--build-id
227 b3test_LDADD = libbacktrace_elf_for_test.la
229 check_PROGRAMS += b3test
230 TESTS += b3test_dwz_buildid
234 endif HAVE_OBJCOPY_DEBUGLINK
237 btest_SOURCES = btest.c testlib.c
238 btest_CFLAGS = $(AM_CFLAGS) -g -O
239 btest_LDADD = libbacktrace.la
245 btest_lto_SOURCES = btest.c testlib.c
246 btest_lto_CFLAGS = $(AM_CFLAGS) -g -O -flto
247 btest_lto_LDADD = libbacktrace.la
249 BUILDTESTS += btest_lto
253 btest_alloc_SOURCES = $(btest_SOURCES)
254 btest_alloc_CFLAGS = $(btest_CFLAGS)
255 btest_alloc_LDADD = libbacktrace_alloc.la
257 BUILDTESTS += btest_alloc
262 rm -f $@ $@_common.debug
265 $(DWZ) -m $@_common.debug $@_1 $@_2
271 if HAVE_OBJCOPY_DEBUGLINK
273 TESTS += btest_dwz_gnudebuglink
275 endif HAVE_OBJCOPY_DEBUGLINK
279 stest_SOURCES = stest.c
280 stest_LDADD = libbacktrace.la
284 stest_alloc_SOURCES = $(stest_SOURCES)
285 stest_alloc_LDADD = libbacktrace_alloc.la
287 BUILDTESTS += stest_alloc
291 ztest_SOURCES = ztest.c testlib.c
292 ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
293 ztest_LDADD = libbacktrace.la
294 ztest_alloc_LDADD = libbacktrace_alloc.la
298 ztest_alloc_LDADD += -lz
300 ztest_LDADD += $(CLOCK_GETTIME_LINK)
301 ztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
305 ztest_alloc_SOURCES = $(ztest_SOURCES)
306 ztest_alloc_CFLAGS = $(ztest_CFLAGS)
308 BUILDTESTS += ztest_alloc
312 edtest_SOURCES = edtest.c edtest2_build.c testlib.c
313 edtest_LDADD = libbacktrace.la
317 edtest_alloc_SOURCES = $(edtest_SOURCES)
318 edtest_alloc_LDADD = libbacktrace_alloc.la
320 BUILDTESTS += edtest_alloc
322 edtest2_build.c: gen_edtest2_build; @true
323 gen_edtest2_build: $(srcdir)/edtest2.c
324 cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
325 $(SHELL) $(srcdir)/../move-if-change tmp-edtest2_build.c edtest2_build.c
332 ttest_SOURCES = ttest.c testlib.c
333 ttest_CFLAGS = $(AM_CFLAGS) -pthread
334 ttest_LDADD = libbacktrace.la
336 BUILDTESTS += ttest_alloc
338 ttest_alloc_SOURCES = $(ttest_SOURCES)
339 ttest_alloc_CFLAGS = $(ttest_CFLAGS)
340 ttest_alloc_LDADD = libbacktrace_alloc.la
344 if HAVE_OBJCOPY_DEBUGLINK
346 TESTS += btest_gnudebuglink
349 $(OBJCOPY) --only-keep-debug $< $@.debug
350 $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
352 endif HAVE_OBJCOPY_DEBUGLINK
355 ./install-debuginfo-for-buildid.sh \
356 "$(TEST_BUILD_ID_DIR)" \
358 $(OBJCOPY) --strip-debug $< $@
360 if HAVE_COMPRESSED_DEBUG
362 ctestg_SOURCES = btest.c testlib.c
363 ctestg_CFLAGS = $(AM_CFLAGS) -g
364 ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
365 ctestg_LDADD = libbacktrace.la
367 ctesta_SOURCES = btest.c testlib.c
368 ctesta_CFLAGS = $(AM_CFLAGS) -g
369 ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
370 ctesta_LDADD = libbacktrace.la
372 BUILDTESTS += ctestg ctesta
374 ctestg_alloc_SOURCES = $(ctestg_SOURCES)
375 ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
376 ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
377 ctestg_alloc_LDADD = libbacktrace_alloc.la
379 ctesta_alloc_SOURCES = $(ctesta_SOURCES)
380 ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
381 ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS)
382 ctesta_alloc_LDADD = libbacktrace_alloc.la
384 BUILDTESTS += ctestg_alloc ctesta_alloc
390 check_PROGRAMS += $(BUILDTESTS)
392 TESTS += $(BUILDTESTS)
394 # We can't use automake's automatic dependency tracking, because it
395 # breaks when using bootstrap-lean. Automatic dependency tracking
396 # with GCC bootstrap will cause some of the objects to depend on
397 # header files in prev-gcc/include, e.g., stddef.h and stdarg.h. When
398 # using bootstrap-lean, prev-gcc is removed after each stage. When
399 # running "make install", those header files will be gone, causing the
400 # library to be rebuilt at install time. That may not succeed.
402 # These manual dependencies do not include dependencies on unwind.h,
403 # even though that is part of GCC, because where to find it depends on
404 # whether we are being built as a host library or a target library.
406 INCDIR = $(top_srcdir)/../include
407 alloc.lo: config.h backtrace.h internal.h
408 backtrace.lo: config.h backtrace.h internal.h
409 btest.lo: (INCDIR)/filenames.h backtrace.h backtrace-supported.h
410 dwarf.lo: config.h $(INCDIR)/dwarf2.h $(INCDIR)/dwarf2.def \
411 $(INCDIR)/filenames.h backtrace.h internal.h
412 elf.lo: config.h backtrace.h internal.h
413 fileline.lo: config.h backtrace.h internal.h
414 mmap.lo: config.h backtrace.h internal.h
415 mmapio.lo: config.h backtrace.h internal.h
416 nounwind.lo: config.h internal.h
417 pecoff.lo: config.h backtrace.h internal.h
418 posix.lo: config.h backtrace.h internal.h
419 print.lo: config.h backtrace.h internal.h
420 read.lo: config.h backtrace.h internal.h
421 simple.lo: config.h backtrace.h internal.h
422 sort.lo: config.h backtrace.h internal.h
423 stest.lo: config.h backtrace.h internal.h
424 state.lo: config.h backtrace.h backtrace-supported.h internal.h
425 unknown.lo: config.h backtrace.h internal.h
426 xcoff.lo: config.h backtrace.h internal.h
428 include $(top_srcdir)/../multilib.am