1 # Makefile.am -- Backtrace Makefile.
2 # Copyright (C) 2012-2021 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 if $(DWZ) -m $@_common.debug $@_1 $@_2; then \
310 echo "Ignoring dwz errors, assuming that test passes"; \
316 if HAVE_OBJCOPY_DEBUGLINK
318 TESTS += btest_dwz_gnudebuglink
320 endif HAVE_OBJCOPY_DEBUGLINK
324 stest_SOURCES = stest.c
325 stest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
326 stest_LDADD = libbacktrace.la
331 check_DATA += stest.dSYM
334 stest_alloc_SOURCES = $(stest_SOURCES)
335 stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
336 stest_alloc_LDADD = libbacktrace_alloc.la
338 BUILDTESTS += stest_alloc
341 check_DATA += stest_alloc.dSYM
346 ztest_SOURCES = ztest.c testlib.c
347 ztest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
348 ztest_LDADD = libbacktrace.la
349 ztest_alloc_LDADD = libbacktrace_alloc.la
353 ztest_alloc_LDADD += -lz
355 ztest_LDADD += $(CLOCK_GETTIME_LINK)
356 ztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
360 ztest_alloc_SOURCES = $(ztest_SOURCES)
361 ztest_alloc_CFLAGS = $(ztest_CFLAGS)
363 BUILDTESTS += ztest_alloc
367 edtest_SOURCES = edtest.c edtest2_build.c testlib.c
368 edtest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
369 edtest_LDADD = libbacktrace.la
374 check_DATA += edtest.dSYM
377 edtest_alloc_SOURCES = $(edtest_SOURCES)
378 edtest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
379 edtest_alloc_LDADD = libbacktrace_alloc.la
382 check_DATA += edtest_alloc.dSYM
385 BUILDTESTS += edtest_alloc
387 edtest2_build.c: gen_edtest2_build; @true
388 gen_edtest2_build: $(srcdir)/edtest2.c
389 cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
390 $(SHELL) $(srcdir)/../move-if-change tmp-edtest2_build.c edtest2_build.c
397 ttest_SOURCES = ttest.c testlib.c
398 ttest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -pthread
399 ttest_LDADD = libbacktrace.la
402 check_DATA += ttest.dSYM
405 BUILDTESTS += ttest_alloc
407 ttest_alloc_SOURCES = $(ttest_SOURCES)
408 ttest_alloc_CFLAGS = $(ttest_CFLAGS)
409 ttest_alloc_LDADD = libbacktrace_alloc.la
412 check_DATA += ttest_alloc.dSYM
417 if HAVE_OBJCOPY_DEBUGLINK
419 TESTS += btest_gnudebuglink
422 $(OBJCOPY) --only-keep-debug $< $@.debug
423 $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
425 endif HAVE_OBJCOPY_DEBUGLINK
428 ./install-debuginfo-for-buildid.sh \
429 "$(TEST_BUILD_ID_DIR)" \
431 $(OBJCOPY) --strip-debug $< $@
433 if HAVE_COMPRESSED_DEBUG
435 ctestg_SOURCES = btest.c testlib.c
436 ctestg_CFLAGS = $(libbacktrace_TEST_CFLAGS)
437 ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
438 ctestg_LDADD = libbacktrace.la
440 ctesta_SOURCES = btest.c testlib.c
441 ctesta_CFLAGS = $(libbacktrace_TEST_CFLAGS)
442 ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
443 ctesta_LDADD = libbacktrace.la
445 BUILDTESTS += ctestg ctesta
447 ctestg_alloc_SOURCES = $(ctestg_SOURCES)
448 ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
449 ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
450 ctestg_alloc_LDADD = libbacktrace_alloc.la
452 ctesta_alloc_SOURCES = $(ctesta_SOURCES)
453 ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
454 ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS)
455 ctesta_alloc_LDADD = libbacktrace_alloc.la
457 BUILDTESTS += ctestg_alloc ctesta_alloc
463 dwarf5_SOURCES = btest.c testlib.c
464 dwarf5_CFLAGS = $(libbacktrace_TEST_CFLAGS) -gdwarf-5
465 dwarf5_LDADD = libbacktrace.la
470 check_DATA += dwarf5.dSYM
473 dwarf5_alloc_SOURCES = $(dwarf5_SOURCES)
474 dwarf5_alloc_CFLAGS = $(dwarf5_CFLAGS)
475 dwarf5_alloc_LDADD = libbacktrace_alloc.la
477 BUILDTESTS += dwarf5_alloc
480 check_DATA += dwarf5_alloc.dSYM
485 mtest_SOURCES = mtest.c testlib.c
486 mtest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
487 mtest_LDADD = libbacktrace.la
492 check_DATA += mtest.dSYM
497 TESTS += mtest_minidebug
500 $(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > $<.dsyms
501 $(NM) $< -P --defined-only | $(AWK) '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D" || $$2 == "d") print $$1 }' | sort > $<.fsyms
502 $(COMM) -13 $<.dsyms $<.fsyms > $<.keepsyms
503 $(OBJCOPY) --only-keep-debug $< $<.dbg
504 $(OBJCOPY) -S --remove-section .gdb_index --remove-section .comment --keep-symbols=$<.keepsyms $<.dbg $<.mdbg
505 $(OBJCOPY) --strip-all --remove-section ..comment $< $<.strip
508 $(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg.xz $<.strip
517 xztest_SOURCES = xztest.c testlib.c
518 xztest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
519 xztest_LDADD = libbacktrace.la
521 xztest_alloc_SOURCES = $(xztest_SOURCES)
522 xztest_alloc_CFLAGS = $(xztest_CFLAGS)
523 xztest_alloc_LDADD = libbacktrace_alloc.la
526 xztest_LDADD += -llzma
527 xztest_alloc_LDADD += -llzma
530 xztest_LDADD += $(CLOCK_GETTIME_LINK)
531 xztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
533 BUILDTESTS += xztest xztest_alloc
537 check_PROGRAMS += $(BUILDTESTS)
539 TESTS += $(BUILDTESTS)
542 $(filter-out allocfail.sh,$(TESTS)) *.debug elf_for_test.c edtest2_build.c gen_edtest2_build \
543 *.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip
548 # We can't use automake's automatic dependency tracking, because it
549 # breaks when using bootstrap-lean. Automatic dependency tracking
550 # with GCC bootstrap will cause some of the objects to depend on
551 # header files in prev-gcc/include, e.g., stddef.h and stdarg.h. When
552 # using bootstrap-lean, prev-gcc is removed after each stage. When
553 # running "make install", those header files will be gone, causing the
554 # library to be rebuilt at install time. That may not succeed.
556 # These manual dependencies do not include dependencies on unwind.h,
557 # even though that is part of GCC, because where to find it depends on
558 # whether we are being built as a host library or a target library.
560 INCDIR = $(top_srcdir)/../include
561 alloc.lo: config.h backtrace.h internal.h
562 backtrace.lo: config.h backtrace.h internal.h
563 btest.lo: $(INCDIR)/filenames.h backtrace.h backtrace-supported.h
564 dwarf.lo: config.h $(INCDIR)/dwarf2.h $(INCDIR)/dwarf2.def \
565 $(INCDIR)/filenames.h backtrace.h internal.h
566 elf.lo: config.h backtrace.h internal.h
567 fileline.lo: config.h backtrace.h internal.h
568 macho.lo: config.h backtrace.h internal.h
569 mmap.lo: config.h backtrace.h internal.h
570 mmapio.lo: config.h backtrace.h internal.h
571 mtest.lo: backtrace.h backtrace-supported.h
572 nounwind.lo: config.h internal.h
573 pecoff.lo: config.h backtrace.h internal.h
574 posix.lo: config.h backtrace.h internal.h
575 print.lo: config.h backtrace.h internal.h
576 read.lo: config.h backtrace.h internal.h
577 simple.lo: config.h backtrace.h internal.h
578 sort.lo: config.h backtrace.h internal.h
579 stest.lo: config.h backtrace.h internal.h
580 state.lo: config.h backtrace.h backtrace-supported.h internal.h
581 unknown.lo: config.h backtrace.h internal.h
582 xcoff.lo: config.h backtrace.h internal.h
583 xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
584 ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
586 include $(top_srcdir)/../multilib.am