1 # Makefile.am -- Backtrace Makefile.
2 # Copyright (C) 2012-2020 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) $(CET_HOST_FLAGS)
39 noinst_LTLIBRARIES = libbacktrace.la
41 libbacktrace_la_SOURCES = \
72 EXTRA_libbacktrace_la_SOURCES = \
78 libbacktrace_la_LIBADD = \
84 libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
88 # Add a test to this variable if you want it to be built.
91 # Add a test to this variable if you want it to be run.
94 # Add a test to this variable if you want it to be built and run.
97 # Add a file to this variable if you want it to be built for testing.
100 # Flags to use when compiling test programs.
101 libbacktrace_TEST_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) -g
111 check_LTLIBRARIES = libbacktrace_alloc.la
113 libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
114 libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
116 libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
118 check_LTLIBRARIES += libbacktrace_noformat.la
120 libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
121 libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
123 libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
126 if HAVE_OBJCOPY_DEBUGLINK
128 TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
130 check_LTLIBRARIES += libbacktrace_elf_for_test.la
132 libbacktrace_elf_for_test_la_SOURCES = $(libbacktrace_la_SOURCES)
133 libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
134 $(VIEW_FILE) $(ALLOC_FILE)
136 elf_for_test.c: elf.c
137 SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
138 REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
139 $(SED) "s%$$SEARCH%$$REPLACE%" \
144 endif HAVE_OBJCOPY_DEBUGLINK
148 SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
149 REPLACE='#undef BACKTRACE_ELF_SIZE\
150 #define BACKTRACE_ELF_SIZE'; \
151 $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
157 SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
158 REPLACE='#undef BACKTRACE_XCOFF_SIZE\
159 #define BACKTRACE_XCOFF_SIZE'; \
160 $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
165 test_elf_32_SOURCES = test_format.c testlib.c
166 test_elf_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
167 test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo
169 BUILDTESTS += test_elf_32
171 test_elf_64_SOURCES = test_format.c testlib.c
172 test_elf_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
173 test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo
175 BUILDTESTS += test_elf_64
177 test_macho_SOURCES = test_format.c testlib.c
178 test_macho_CFLAGS = $(libbacktrace_TEST_CFLAGS)
179 test_macho_LDADD = libbacktrace_noformat.la macho.lo
181 BUILDTESTS += test_macho
183 test_xcoff_32_SOURCES = test_format.c testlib.c
184 test_xcoff_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
185 test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
187 BUILDTESTS += test_xcoff_32
189 test_xcoff_64_SOURCES = test_format.c testlib.c
190 test_xcoff_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
191 test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
193 BUILDTESTS += test_xcoff_64
195 test_pecoff_SOURCES = test_format.c testlib.c
196 test_pecoff_CFLAGS = $(libbacktrace_TEST_CFLAGS)
197 test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
199 BUILDTESTS += test_pecoff
201 test_unknown_SOURCES = test_format.c testlib.c
202 test_unknown_CFLAGS = $(libbacktrace_TEST_CFLAGS)
203 test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
205 BUILDTESTS += test_unknown
207 unittest_SOURCES = unittest.c testlib.c
208 unittest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
209 unittest_LDADD = libbacktrace.la
211 BUILDTESTS += unittest
213 unittest_alloc_SOURCES = $(unittest_SOURCES)
214 unittest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
215 unittest_alloc_LDADD = libbacktrace_alloc.la
217 BUILDTESTS += unittest_alloc
219 check_LTLIBRARIES += libbacktrace_instrumented_alloc.la
221 libbacktrace_instrumented_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
222 libbacktrace_instrumented_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) \
223 read.lo instrumented_alloc.lo
225 libbacktrace_instrumented_alloc_la_DEPENDENCIES = \
226 $(libbacktrace_instrumented_alloc_la_LIBADD)
228 instrumented_alloc.lo: alloc.c
230 allocfail_SOURCES = allocfail.c testlib.c
231 allocfail_CFLAGS = $(libbacktrace_TEST_CFLAGS)
232 allocfail_LDADD = libbacktrace_instrumented_alloc.la
234 check_PROGRAMS += allocfail
236 allocfail.sh: allocfail
238 TESTS += allocfail.sh
241 check_DATA += allocfail.dSYM
245 if HAVE_OBJCOPY_DEBUGLINK
247 b2test_SOURCES = $(btest_SOURCES)
248 b2test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
249 b2test_LDFLAGS = -Wl,--build-id
250 b2test_LDADD = libbacktrace_elf_for_test.la
252 check_PROGRAMS += b2test
253 TESTS += b2test_buildid
257 b3test_SOURCES = $(btest_SOURCES)
258 b3test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
259 b3test_LDFLAGS = -Wl,--build-id
260 b3test_LDADD = libbacktrace_elf_for_test.la
262 check_PROGRAMS += b3test
263 TESTS += b3test_dwz_buildid
267 endif HAVE_OBJCOPY_DEBUGLINK
270 btest_SOURCES = btest.c testlib.c
271 btest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
272 btest_LDADD = libbacktrace.la
277 check_DATA += btest.dSYM
282 btest_lto_SOURCES = btest.c testlib.c
283 btest_lto_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O -flto
284 btest_lto_LDADD = libbacktrace.la
286 BUILDTESTS += btest_lto
290 btest_alloc_SOURCES = $(btest_SOURCES)
291 btest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
292 btest_alloc_LDADD = libbacktrace_alloc.la
294 BUILDTESTS += btest_alloc
297 check_DATA += btest_alloc.dSYM
303 rm -f $@ $@_common.debug
306 $(DWZ) -m $@_common.debug $@_1 $@_2
312 if HAVE_OBJCOPY_DEBUGLINK
314 TESTS += btest_dwz_gnudebuglink
316 endif HAVE_OBJCOPY_DEBUGLINK
320 stest_SOURCES = stest.c
321 stest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
322 stest_LDADD = libbacktrace.la
327 check_DATA += stest.dSYM
330 stest_alloc_SOURCES = $(stest_SOURCES)
331 stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
332 stest_alloc_LDADD = libbacktrace_alloc.la
334 BUILDTESTS += stest_alloc
337 check_DATA += stest_alloc.dSYM
342 ztest_SOURCES = ztest.c testlib.c
343 ztest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
344 ztest_LDADD = libbacktrace.la
345 ztest_alloc_LDADD = libbacktrace_alloc.la
349 ztest_alloc_LDADD += -lz
351 ztest_LDADD += $(CLOCK_GETTIME_LINK)
352 ztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
356 ztest_alloc_SOURCES = $(ztest_SOURCES)
357 ztest_alloc_CFLAGS = $(ztest_CFLAGS)
359 BUILDTESTS += ztest_alloc
363 edtest_SOURCES = edtest.c edtest2_build.c testlib.c
364 edtest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
365 edtest_LDADD = libbacktrace.la
370 check_DATA += edtest.dSYM
373 edtest_alloc_SOURCES = $(edtest_SOURCES)
374 edtest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
375 edtest_alloc_LDADD = libbacktrace_alloc.la
378 check_DATA += edtest_alloc.dSYM
381 BUILDTESTS += edtest_alloc
383 edtest2_build.c: gen_edtest2_build; @true
384 gen_edtest2_build: $(srcdir)/edtest2.c
385 cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
386 $(SHELL) $(srcdir)/../move-if-change tmp-edtest2_build.c edtest2_build.c
393 ttest_SOURCES = ttest.c testlib.c
394 ttest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -pthread
395 ttest_LDADD = libbacktrace.la
398 check_DATA += ttest.dSYM
401 BUILDTESTS += ttest_alloc
403 ttest_alloc_SOURCES = $(ttest_SOURCES)
404 ttest_alloc_CFLAGS = $(ttest_CFLAGS)
405 ttest_alloc_LDADD = libbacktrace_alloc.la
408 check_DATA += ttest_alloc.dSYM
413 if HAVE_OBJCOPY_DEBUGLINK
415 TESTS += btest_gnudebuglink
418 $(OBJCOPY) --only-keep-debug $< $@.debug
419 $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
421 endif HAVE_OBJCOPY_DEBUGLINK
424 ./install-debuginfo-for-buildid.sh \
425 "$(TEST_BUILD_ID_DIR)" \
427 $(OBJCOPY) --strip-debug $< $@
429 if HAVE_COMPRESSED_DEBUG
431 ctestg_SOURCES = btest.c testlib.c
432 ctestg_CFLAGS = $(libbacktrace_TEST_CFLAGS)
433 ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
434 ctestg_LDADD = libbacktrace.la
436 ctesta_SOURCES = btest.c testlib.c
437 ctesta_CFLAGS = $(libbacktrace_TEST_CFLAGS)
438 ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
439 ctesta_LDADD = libbacktrace.la
441 BUILDTESTS += ctestg ctesta
443 ctestg_alloc_SOURCES = $(ctestg_SOURCES)
444 ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
445 ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
446 ctestg_alloc_LDADD = libbacktrace_alloc.la
448 ctesta_alloc_SOURCES = $(ctesta_SOURCES)
449 ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
450 ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS)
451 ctesta_alloc_LDADD = libbacktrace_alloc.la
453 BUILDTESTS += ctestg_alloc ctesta_alloc
459 dwarf5_SOURCES = btest.c testlib.c
460 dwarf5_CFLAGS = $(libbacktrace_TEST_CFLAGS) -gdwarf-5
461 dwarf5_LDADD = libbacktrace.la
466 check_DATA += dwarf5.dSYM
469 dwarf5_alloc_SOURCES = $(dwarf5_SOURCES)
470 dwarf5_alloc_CFLAGS = $(dwarf5_CFLAGS)
471 dwarf5_alloc_LDADD = libbacktrace_alloc.la
473 BUILDTESTS += dwarf5_alloc
476 check_DATA += dwarf5_alloc.dSYM
483 check_PROGRAMS += $(BUILDTESTS)
485 TESTS += $(BUILDTESTS)
487 CLEANFILES = $(TESTS) *.debug elf_for_test.c edtest2_build.c gen_edtest2_build
492 # We can't use automake's automatic dependency tracking, because it
493 # breaks when using bootstrap-lean. Automatic dependency tracking
494 # with GCC bootstrap will cause some of the objects to depend on
495 # header files in prev-gcc/include, e.g., stddef.h and stdarg.h. When
496 # using bootstrap-lean, prev-gcc is removed after each stage. When
497 # running "make install", those header files will be gone, causing the
498 # library to be rebuilt at install time. That may not succeed.
500 # These manual dependencies do not include dependencies on unwind.h,
501 # even though that is part of GCC, because where to find it depends on
502 # whether we are being built as a host library or a target library.
504 INCDIR = $(top_srcdir)/../include
505 alloc.lo: config.h backtrace.h internal.h
506 backtrace.lo: config.h backtrace.h internal.h
507 btest.lo: (INCDIR)/filenames.h backtrace.h backtrace-supported.h
508 dwarf.lo: config.h $(INCDIR)/dwarf2.h $(INCDIR)/dwarf2.def \
509 $(INCDIR)/filenames.h backtrace.h internal.h
510 elf.lo: config.h backtrace.h internal.h
511 fileline.lo: config.h backtrace.h internal.h
512 macho.lo: config.h backtrace.h internal.h
513 mmap.lo: config.h backtrace.h internal.h
514 mmapio.lo: config.h backtrace.h internal.h
515 nounwind.lo: config.h internal.h
516 pecoff.lo: config.h backtrace.h internal.h
517 posix.lo: config.h backtrace.h internal.h
518 print.lo: config.h backtrace.h internal.h
519 read.lo: config.h backtrace.h internal.h
520 simple.lo: config.h backtrace.h internal.h
521 sort.lo: config.h backtrace.h internal.h
522 stest.lo: config.h backtrace.h internal.h
523 state.lo: config.h backtrace.h backtrace-supported.h internal.h
524 unknown.lo: config.h backtrace.h internal.h
525 xcoff.lo: config.h backtrace.h internal.h
527 include $(top_srcdir)/../multilib.am