1 # Makefile.am -- Backtrace Makefile.
2 # Copyright (C) 2012-2023 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 as a program,
92 # Add a test to this variable if you want it to be run.
95 # Add a test to this variable if you want it to be built as a Makefile
99 # Add a test to this variable if you want it to be built as a program,
100 # with SOURCES, etc., and run.
103 # Add a file to this variable if you want it to be built for testing.
106 # Flags to use when compiling test programs.
107 libbacktrace_TEST_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) -g
117 check_LTLIBRARIES = libbacktrace_alloc.la
119 libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
120 libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
122 libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
124 check_LTLIBRARIES += libbacktrace_noformat.la
126 libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
127 libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
129 libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
132 if HAVE_OBJCOPY_DEBUGLINK
134 TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
136 check_LTLIBRARIES += libbacktrace_elf_for_test.la
138 libbacktrace_elf_for_test_la_SOURCES = $(libbacktrace_la_SOURCES)
139 libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
140 $(VIEW_FILE) $(ALLOC_FILE)
142 elf_for_test.c: elf.c
143 SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
144 REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
145 $(SED) "s%$$SEARCH%$$REPLACE%" \
150 endif HAVE_OBJCOPY_DEBUGLINK
154 nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
155 SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
156 REPLACE="#undef BACKTRACE_ELF_SIZE\\$${nl}#define BACKTRACE_ELF_SIZE"; \
157 $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
163 nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
164 SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
165 REPLACE="#undef BACKTRACE_XCOFF_SIZE\\$${nl}#define BACKTRACE_XCOFF_SIZE"; \
166 $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
171 test_elf_32_SOURCES = test_format.c testlib.c
172 test_elf_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
173 test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo
175 BUILDTESTS += test_elf_32
177 test_elf_64_SOURCES = test_format.c testlib.c
178 test_elf_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
179 test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo
181 BUILDTESTS += test_elf_64
183 test_macho_SOURCES = test_format.c testlib.c
184 test_macho_CFLAGS = $(libbacktrace_TEST_CFLAGS)
185 test_macho_LDADD = libbacktrace_noformat.la macho.lo
187 BUILDTESTS += test_macho
189 test_xcoff_32_SOURCES = test_format.c testlib.c
190 test_xcoff_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
191 test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
193 BUILDTESTS += test_xcoff_32
195 test_xcoff_64_SOURCES = test_format.c testlib.c
196 test_xcoff_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
197 test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
199 BUILDTESTS += test_xcoff_64
201 test_pecoff_SOURCES = test_format.c testlib.c
202 test_pecoff_CFLAGS = $(libbacktrace_TEST_CFLAGS)
203 test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
205 BUILDTESTS += test_pecoff
207 test_unknown_SOURCES = test_format.c testlib.c
208 test_unknown_CFLAGS = $(libbacktrace_TEST_CFLAGS)
209 test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
211 BUILDTESTS += test_unknown
213 unittest_SOURCES = unittest.c testlib.c
214 unittest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
215 unittest_LDADD = libbacktrace.la
217 BUILDTESTS += unittest
219 unittest_alloc_SOURCES = $(unittest_SOURCES)
220 unittest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
221 unittest_alloc_LDADD = libbacktrace_alloc.la
223 BUILDTESTS += unittest_alloc
225 check_LTLIBRARIES += libbacktrace_instrumented_alloc.la
227 libbacktrace_instrumented_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
228 libbacktrace_instrumented_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) \
229 read.lo instrumented_alloc.lo
231 libbacktrace_instrumented_alloc_la_DEPENDENCIES = \
232 $(libbacktrace_instrumented_alloc_la_LIBADD)
234 instrumented_alloc.lo: alloc.c
236 allocfail_SOURCES = allocfail.c testlib.c
237 allocfail_CFLAGS = $(libbacktrace_TEST_CFLAGS)
238 allocfail_LDADD = libbacktrace_instrumented_alloc.la
240 check_PROGRAMS += allocfail
242 allocfail.sh: allocfail
244 TESTS += allocfail.sh
247 check_DATA += allocfail.dSYM
252 if HAVE_OBJCOPY_DEBUGLINK
254 b2test_SOURCES = $(btest_SOURCES)
255 b2test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
256 b2test_LDFLAGS = -Wl,--build-id
257 b2test_LDADD = libbacktrace_elf_for_test.la
259 check_PROGRAMS += b2test
260 MAKETESTS += b2test_buildid
264 b3test_SOURCES = $(btest_SOURCES)
265 b3test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
266 b3test_LDFLAGS = -Wl,--build-id
267 b3test_LDADD = libbacktrace_elf_for_test.la
269 check_PROGRAMS += b3test
270 MAKETESTS += b3test_dwz_buildid
274 endif HAVE_OBJCOPY_DEBUGLINK
278 btest_SOURCES = btest.c testlib.c
279 btest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
280 btest_LDADD = libbacktrace.la
285 check_DATA += btest.dSYM
290 btest_lto_SOURCES = btest.c testlib.c
291 btest_lto_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O -flto
292 btest_lto_LDADD = libbacktrace.la
294 BUILDTESTS += btest_lto
298 btest_alloc_SOURCES = $(btest_SOURCES)
299 btest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
300 btest_alloc_LDADD = libbacktrace_alloc.la
302 BUILDTESTS += btest_alloc
305 check_DATA += btest_alloc.dSYM
311 rm -f $@ $@_common.debug
314 if $(DWZ) -m $@_common.debug $@_1 $@_2; then \
318 echo "Ignoring dwz errors, assuming that test passes"; \
322 MAKETESTS += btest_dwz
324 if HAVE_OBJCOPY_DEBUGLINK
326 MAKETESTS += btest_dwz_gnudebuglink
328 endif HAVE_OBJCOPY_DEBUGLINK
332 stest_SOURCES = stest.c
333 stest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
334 stest_LDADD = libbacktrace.la
339 check_DATA += stest.dSYM
342 stest_alloc_SOURCES = $(stest_SOURCES)
343 stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
344 stest_alloc_LDADD = libbacktrace_alloc.la
346 BUILDTESTS += stest_alloc
349 check_DATA += stest_alloc.dSYM
354 ztest_SOURCES = ztest.c testlib.c
355 ztest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
356 ztest_LDADD = libbacktrace.la
357 ztest_alloc_LDADD = libbacktrace_alloc.la
361 ztest_alloc_LDADD += -lz
363 ztest_LDADD += $(CLOCK_GETTIME_LINK)
364 ztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
368 ztest_alloc_SOURCES = $(ztest_SOURCES)
369 ztest_alloc_CFLAGS = $(ztest_CFLAGS)
371 BUILDTESTS += ztest_alloc
373 zstdtest_SOURCES = zstdtest.c testlib.c
374 zstdtest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
375 zstdtest_LDADD = libbacktrace.la
376 zstdtest_alloc_LDADD = libbacktrace_alloc.la
379 zstdtest_LDADD += -lzstd
380 zstdtest_alloc_LDADD += -lzstd
382 zstdtest_LDADD += $(CLOCK_GETTIME_LINK)
383 zstdtest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
385 BUILDTESTS += zstdtest
387 zstdtest_alloc_SOURCES = $(zstdtest_SOURCES)
388 zstdtest_alloc_CFLAGS = $(zstdtest_CFLAGS)
390 BUILDTESTS += zstdtest_alloc
394 edtest_SOURCES = edtest.c edtest2_build.c testlib.c
395 edtest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
396 edtest_LDADD = libbacktrace.la
401 check_DATA += edtest.dSYM
404 edtest_alloc_SOURCES = $(edtest_SOURCES)
405 edtest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
406 edtest_alloc_LDADD = libbacktrace_alloc.la
409 check_DATA += edtest_alloc.dSYM
412 BUILDTESTS += edtest_alloc
414 edtest2_build.c: gen_edtest2_build; @true
415 gen_edtest2_build: $(srcdir)/edtest2.c
416 cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
417 $(SHELL) $(srcdir)/../move-if-change tmp-edtest2_build.c edtest2_build.c
424 ttest_SOURCES = ttest.c testlib.c
425 ttest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -pthread
426 ttest_LDADD = libbacktrace.la
429 check_DATA += ttest.dSYM
432 BUILDTESTS += ttest_alloc
434 ttest_alloc_SOURCES = $(ttest_SOURCES)
435 ttest_alloc_CFLAGS = $(ttest_CFLAGS)
436 ttest_alloc_LDADD = libbacktrace_alloc.la
439 check_DATA += ttest_alloc.dSYM
444 if HAVE_OBJCOPY_DEBUGLINK
446 MAKETESTS += btest_gnudebuglink
449 $(OBJCOPY) --only-keep-debug $< $@.debug
450 $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
452 endif HAVE_OBJCOPY_DEBUGLINK
455 ./install-debuginfo-for-buildid.sh \
456 "$(TEST_BUILD_ID_DIR)" \
458 $(OBJCOPY) --strip-debug $< $@
460 if HAVE_COMPRESSED_DEBUG
462 ctestg_SOURCES = btest.c testlib.c
463 ctestg_CFLAGS = $(libbacktrace_TEST_CFLAGS)
464 ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
465 ctestg_LDADD = libbacktrace.la
467 ctesta_SOURCES = btest.c testlib.c
468 ctesta_CFLAGS = $(libbacktrace_TEST_CFLAGS)
469 ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
470 ctesta_LDADD = libbacktrace.la
472 BUILDTESTS += ctestg ctesta
474 if HAVE_COMPRESSED_DEBUG_ZSTD
476 ctestzstd_SOURCES = btest.c testlib.c
477 ctestzstd_CFLAGS = $(libbacktrace_TEST_CFLAGS)
478 ctestzstd_LDFLAGS = -Wl,--compress-debug-sections=zstd
479 ctestzstd_LDADD = libbacktrace.la
481 BUILDTESTS += ctestzstd
485 ctestg_alloc_SOURCES = $(ctestg_SOURCES)
486 ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
487 ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
488 ctestg_alloc_LDADD = libbacktrace_alloc.la
490 ctesta_alloc_SOURCES = $(ctesta_SOURCES)
491 ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
492 ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS)
493 ctesta_alloc_LDADD = libbacktrace_alloc.la
495 BUILDTESTS += ctestg_alloc ctesta_alloc
501 dwarf5_SOURCES = btest.c testlib.c
502 dwarf5_CFLAGS = $(libbacktrace_TEST_CFLAGS) -gdwarf-5
503 dwarf5_LDADD = libbacktrace.la
508 check_DATA += dwarf5.dSYM
511 dwarf5_alloc_SOURCES = $(dwarf5_SOURCES)
512 dwarf5_alloc_CFLAGS = $(dwarf5_CFLAGS)
513 dwarf5_alloc_LDADD = libbacktrace_alloc.la
515 BUILDTESTS += dwarf5_alloc
518 check_DATA += dwarf5_alloc.dSYM
523 mtest_SOURCES = mtest.c testlib.c
524 mtest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
525 mtest_LDADD = libbacktrace.la
530 check_DATA += mtest.dSYM
535 MAKETESTS += mtest_minidebug
538 $(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > $<.dsyms
539 $(NM) $< -P --defined-only | $(AWK) '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > $<.fsyms
540 $(COMM) -13 $<.dsyms $<.fsyms > $<.keepsyms
541 $(OBJCOPY) --only-keep-debug $< $<.dbg
542 $(OBJCOPY) -S --remove-section .gdb_index --remove-section .comment --keep-symbols=$<.keepsyms $<.dbg $<.mdbg
543 $(OBJCOPY) --strip-all --remove-section ..comment $< $<.strip
546 $(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg.xz $<.strip
555 xztest_SOURCES = xztest.c testlib.c
556 xztest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
557 xztest_LDADD = libbacktrace.la
559 xztest_alloc_SOURCES = $(xztest_SOURCES)
560 xztest_alloc_CFLAGS = $(xztest_CFLAGS)
561 xztest_alloc_LDADD = libbacktrace_alloc.la
564 xztest_LDADD += -llzma
565 xztest_alloc_LDADD += -llzma
568 xztest_LDADD += $(CLOCK_GETTIME_LINK)
569 xztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
571 BUILDTESTS += xztest xztest_alloc
575 check_PROGRAMS += $(BUILDTESTS)
577 TESTS += $(MAKETESTS) $(BUILDTESTS)
580 $(MAKETESTS) $(BUILDTESTS) *.debug elf_for_test.c edtest2_build.c \
582 *.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip
587 # We can't use automake's automatic dependency tracking, because it
588 # breaks when using bootstrap-lean. Automatic dependency tracking
589 # with GCC bootstrap will cause some of the objects to depend on
590 # header files in prev-gcc/include, e.g., stddef.h and stdarg.h. When
591 # using bootstrap-lean, prev-gcc is removed after each stage. When
592 # running "make install", those header files will be gone, causing the
593 # library to be rebuilt at install time. That may not succeed.
595 # These manual dependencies do not include dependencies on unwind.h,
596 # even though that is part of GCC, because where to find it depends on
597 # whether we are being built as a host library or a target library.
599 INCDIR = $(top_srcdir)/../include
600 alloc.lo: config.h backtrace.h internal.h
601 backtrace.lo: config.h backtrace.h internal.h
602 btest.lo: $(INCDIR)/filenames.h backtrace.h backtrace-supported.h
603 dwarf.lo: config.h $(INCDIR)/dwarf2.h $(INCDIR)/dwarf2.def \
604 $(INCDIR)/filenames.h backtrace.h internal.h
605 elf.lo: config.h backtrace.h internal.h
606 fileline.lo: config.h backtrace.h internal.h
607 macho.lo: config.h backtrace.h internal.h
608 mmap.lo: config.h backtrace.h internal.h
609 mmapio.lo: config.h backtrace.h internal.h
610 mtest.lo: backtrace.h backtrace-supported.h
611 nounwind.lo: config.h internal.h
612 pecoff.lo: config.h backtrace.h internal.h
613 posix.lo: config.h backtrace.h internal.h
614 print.lo: config.h backtrace.h internal.h
615 read.lo: config.h backtrace.h internal.h
616 simple.lo: config.h backtrace.h internal.h
617 sort.lo: config.h backtrace.h internal.h
618 stest.lo: config.h backtrace.h internal.h
619 state.lo: config.h backtrace.h backtrace-supported.h internal.h
620 unknown.lo: config.h backtrace.h internal.h
621 xcoff.lo: config.h backtrace.h internal.h
622 xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
623 ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
625 include $(top_srcdir)/../multilib.am