Makefile.am revision 1.8
1# Makefile.am -- Backtrace Makefile.
2# Copyright (C) 2012-2019 Free Software Foundation, Inc.
3
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7
8#     (1) Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10
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
14#     distribution.
15
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.
19
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.
31
32ACLOCAL_AMFLAGS = -I .. -I ../config
33
34AM_CPPFLAGS = -I $(top_srcdir)/../include -I $(top_srcdir)/../libgcc \
35	-I ../libgcc
36
37AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG)
38
39noinst_LTLIBRARIES = libbacktrace.la
40
41libbacktrace_la_SOURCES = \
42	backtrace.h \
43	atomic.c \
44	dwarf.c \
45	fileline.c \
46	internal.h \
47	posix.c \
48	print.c \
49	sort.c \
50	state.c
51
52BACKTRACE_FILES = \
53	backtrace.c \
54	simple.c \
55	nounwind.c
56
57FORMAT_FILES = \
58	elf.c \
59	pecoff.c \
60	unknown.c \
61	xcoff.c
62
63VIEW_FILES = \
64	read.c \
65	mmapio.c
66
67ALLOC_FILES = \
68	alloc.c \
69	mmap.c
70
71EXTRA_libbacktrace_la_SOURCES = \
72	$(BACKTRACE_FILES) \
73	$(FORMAT_FILES) \
74	$(VIEW_FILES) \
75	$(ALLOC_FILES)
76
77libbacktrace_la_LIBADD = \
78	$(BACKTRACE_FILE) \
79	$(FORMAT_FILE) \
80	$(VIEW_FILE) \
81	$(ALLOC_FILE)
82
83libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
84
85# Testsuite.
86
87# Add test to this variable, if you want it to be build.
88check_PROGRAMS =
89
90# Add test to this variable, if you want it to be run.
91TESTS =
92
93# Add test to this variable, if you want it to be build and run.
94BUILDTESTS =
95
96if NATIVE
97check_LTLIBRARIES = libbacktrace_alloc.la
98
99libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
100libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
101
102libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
103
104check_LTLIBRARIES += libbacktrace_noformat.la
105
106libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
107libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
108
109libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
110
111if HAVE_ELF
112if HAVE_OBJCOPY_DEBUGLINK
113
114TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
115
116check_LTLIBRARIES += libbacktrace_elf_for_test.la
117
118libbacktrace_elf_for_test_la_SOURCES = $(libbacktrace_la_SOURCES)
119libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
120	$(VIEW_FILE) $(ALLOC_FILE)
121
122elf_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%" \
126		$< \
127		> $@.tmp
128	mv $@.tmp $@
129
130endif HAVE_OBJCOPY_DEBUGLINK
131endif HAVE_ELF
132
133xcoff_%.c: xcoff.c
134	SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
135	REPLACE='#undef BACKTRACE_XCOFF_SIZE\
136	#define BACKTRACE_XCOFF_SIZE'; \
137	$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
138		$< \
139		> $@.tmp
140	mv $@.tmp $@
141
142test_elf_SOURCES = test_format.c testlib.c
143test_elf_LDADD = libbacktrace_noformat.la elf.lo
144
145BUILDTESTS += test_elf
146
147test_xcoff_32_SOURCES = test_format.c testlib.c
148test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
149
150BUILDTESTS += test_xcoff_32
151
152test_xcoff_64_SOURCES = test_format.c testlib.c
153test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
154
155BUILDTESTS += test_xcoff_64
156
157test_pecoff_SOURCES = test_format.c testlib.c
158test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
159
160BUILDTESTS += test_pecoff
161
162test_unknown_SOURCES = test_format.c testlib.c
163test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
164
165BUILDTESTS += test_unknown
166
167unittest_SOURCES = unittest.c testlib.c
168unittest_LDADD = libbacktrace.la
169
170BUILDTESTS += unittest
171
172unittest_alloc_SOURCES = $(unittest_SOURCES)
173unittest_alloc_LDADD = libbacktrace_alloc.la
174
175BUILDTESTS += unittest_alloc
176
177check_LTLIBRARIES += libbacktrace_instrumented_alloc.la
178
179libbacktrace_instrumented_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
180libbacktrace_instrumented_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) \
181	read.lo instrumented_alloc.lo
182
183libbacktrace_instrumented_alloc_la_DEPENDENCIES = \
184	$(libbacktrace_instrumented_alloc_la_LIBADD)
185
186instrumented_alloc.lo: alloc.c
187
188allocfail_SOURCES = allocfail.c testlib.c
189allocfail_LDADD = libbacktrace_instrumented_alloc.la
190
191check_PROGRAMS += allocfail
192
193allocfail.sh: allocfail
194
195TESTS += allocfail.sh
196
197if HAVE_ELF
198if HAVE_OBJCOPY_DEBUGLINK
199
200b2test_SOURCES = $(btest_SOURCES)
201b2test_CFLAGS = $(btest_CFLAGS)
202b2test_LDFLAGS = -Wl,--build-id
203b2test_LDADD = libbacktrace_elf_for_test.la
204
205check_PROGRAMS += b2test
206TESTS += b2test_buildid
207
208if HAVE_DWZ
209
210b3test_SOURCES = $(btest_SOURCES)
211b3test_CFLAGS = $(btest_CFLAGS)
212b3test_LDFLAGS = -Wl,--build-id
213b3test_LDADD = libbacktrace_elf_for_test.la
214
215check_PROGRAMS += b3test
216TESTS += b3test_dwz_buildid
217
218endif HAVE_DWZ
219
220endif HAVE_OBJCOPY_DEBUGLINK
221endif HAVE_ELF
222
223btest_SOURCES = btest.c testlib.c
224btest_CFLAGS = $(AM_CFLAGS) -g -O
225btest_LDADD = libbacktrace.la
226
227BUILDTESTS += btest
228
229if HAVE_ELF
230
231btest_lto_SOURCES = btest.c testlib.c
232btest_lto_CFLAGS = $(AM_CFLAGS) -g -O -flto
233btest_lto_LDADD = libbacktrace.la
234
235BUILDTESTS += btest_lto
236
237endif HAVE_ELF
238
239btest_alloc_SOURCES = $(btest_SOURCES)
240btest_alloc_CFLAGS = $(btest_CFLAGS)
241btest_alloc_LDADD = libbacktrace_alloc.la
242
243BUILDTESTS += btest_alloc
244
245if HAVE_DWZ
246
247%_dwz: %
248	rm -f $@ $@_common.debug
249	cp $< $@_1
250	cp $< $@_2
251	$(DWZ) -m $@_common.debug $@_1 $@_2
252	rm -f $@_2
253	mv $@_1 $@
254
255TESTS += btest_dwz
256
257if HAVE_OBJCOPY_DEBUGLINK
258
259TESTS += btest_dwz_gnudebuglink
260
261endif HAVE_OBJCOPY_DEBUGLINK
262
263endif HAVE_DWZ
264
265stest_SOURCES = stest.c
266stest_LDADD = libbacktrace.la
267
268BUILDTESTS += stest
269
270stest_alloc_SOURCES = $(stest_SOURCES)
271stest_alloc_LDADD = libbacktrace_alloc.la
272
273BUILDTESTS += stest_alloc
274
275if HAVE_ELF
276
277ztest_SOURCES = ztest.c testlib.c
278ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
279ztest_LDADD = libbacktrace.la
280ztest_alloc_LDADD = libbacktrace_alloc.la
281
282if HAVE_ZLIB
283ztest_LDADD += -lz
284ztest_alloc_LDADD += -lz
285endif
286ztest_LDADD += $(CLOCK_GETTIME_LINK)
287ztest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
288
289BUILDTESTS += ztest
290
291ztest_alloc_SOURCES = $(ztest_SOURCES)
292ztest_alloc_CFLAGS = $(ztest_CFLAGS)
293
294BUILDTESTS += ztest_alloc
295
296endif HAVE_ELF
297
298edtest_SOURCES = edtest.c edtest2_build.c testlib.c
299edtest_LDADD = libbacktrace.la
300
301BUILDTESTS += edtest
302
303edtest_alloc_SOURCES = $(edtest_SOURCES)
304edtest_alloc_LDADD = libbacktrace_alloc.la
305
306BUILDTESTS += edtest_alloc
307
308edtest2_build.c: gen_edtest2_build; @true
309gen_edtest2_build: $(srcdir)/edtest2.c
310	cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
311	$(SHELL) $(srcdir)/../move-if-change tmp-edtest2_build.c edtest2_build.c
312	echo timestamp > $@
313
314if HAVE_PTHREAD
315
316BUILDTESTS += ttest
317
318ttest_SOURCES = ttest.c testlib.c
319ttest_CFLAGS = $(AM_CFLAGS) -pthread
320ttest_LDADD = libbacktrace.la
321
322BUILDTESTS += ttest_alloc
323
324ttest_alloc_SOURCES = $(ttest_SOURCES)
325ttest_alloc_CFLAGS = $(ttest_CFLAGS)
326ttest_alloc_LDADD = libbacktrace_alloc.la
327
328endif HAVE_PTHREAD
329
330if HAVE_OBJCOPY_DEBUGLINK
331
332TESTS += btest_gnudebuglink
333
334%_gnudebuglink: %
335	$(OBJCOPY) --only-keep-debug $< $@.debug
336	$(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
337
338endif HAVE_OBJCOPY_DEBUGLINK
339
340%_buildid: %
341	./install-debuginfo-for-buildid.sh \
342	  "$(TEST_BUILD_ID_DIR)" \
343	  $<
344	$(OBJCOPY) --strip-debug $< $@
345
346if HAVE_COMPRESSED_DEBUG
347
348ctestg_SOURCES = btest.c testlib.c
349ctestg_CFLAGS = $(AM_CFLAGS) -g
350ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
351ctestg_LDADD = libbacktrace.la
352
353ctesta_SOURCES = btest.c testlib.c
354ctesta_CFLAGS = $(AM_CFLAGS) -g
355ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
356ctesta_LDADD = libbacktrace.la
357
358BUILDTESTS += ctestg ctesta
359
360ctestg_alloc_SOURCES = $(ctestg_SOURCES)
361ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
362ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
363ctestg_alloc_LDADD = libbacktrace_alloc.la
364
365ctesta_alloc_SOURCES = $(ctesta_SOURCES)
366ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
367ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS)
368ctesta_alloc_LDADD = libbacktrace_alloc.la
369
370BUILDTESTS += ctestg_alloc ctesta_alloc
371
372endif
373
374endif NATIVE
375
376check_PROGRAMS += $(BUILDTESTS)
377
378TESTS += $(BUILDTESTS)
379
380# We can't use automake's automatic dependency tracking, because it
381# breaks when using bootstrap-lean.  Automatic dependency tracking
382# with GCC bootstrap will cause some of the objects to depend on
383# header files in prev-gcc/include, e.g., stddef.h and stdarg.h.  When
384# using bootstrap-lean, prev-gcc is removed after each stage.  When
385# running "make install", those header files will be gone, causing the
386# library to be rebuilt at install time.  That may not succeed.
387
388# These manual dependencies do not include dependencies on unwind.h,
389# even though that is part of GCC, because where to find it depends on
390# whether we are being built as a host library or a target library.
391
392INCDIR = $(top_srcdir)/../include
393alloc.lo: config.h backtrace.h internal.h
394backtrace.lo: config.h backtrace.h internal.h
395btest.lo: (INCDIR)/filenames.h backtrace.h backtrace-supported.h
396dwarf.lo: config.h $(INCDIR)/dwarf2.h $(INCDIR)/dwarf2.def \
397	$(INCDIR)/filenames.h backtrace.h internal.h
398elf.lo: config.h backtrace.h internal.h
399fileline.lo: config.h backtrace.h internal.h
400mmap.lo: config.h backtrace.h internal.h
401mmapio.lo: config.h backtrace.h internal.h
402nounwind.lo: config.h internal.h
403pecoff.lo: config.h backtrace.h internal.h
404posix.lo: config.h backtrace.h internal.h
405print.lo: config.h backtrace.h internal.h
406read.lo: config.h backtrace.h internal.h
407simple.lo: config.h backtrace.h internal.h
408sort.lo: config.h backtrace.h internal.h
409stest.lo: config.h backtrace.h internal.h
410state.lo: config.h backtrace.h backtrace-supported.h internal.h
411unknown.lo: config.h backtrace.h internal.h
412xcoff.lo: config.h backtrace.h internal.h
413
414include $(top_srcdir)/../multilib.am
415