]> git.proxmox.com Git - rustc.git/blame - src/libbacktrace/configure.ac
New upstream version 1.28.0~beta.14+dfsg1
[rustc.git] / src / libbacktrace / configure.ac
CommitLineData
1a4d82fc 1# configure.ac -- Backtrace configure script.
94b46f34 2# Copyright (C) 2012-2018 Free Software Foundation, Inc.
1a4d82fc
JJ
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
94b46f34 9# notice, this list of conditions and the following disclaimer.
1a4d82fc
JJ
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
94b46f34
XL
14# distribution.
15
1a4d82fc
JJ
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
32AC_PREREQ(2.64)
33AC_INIT(package-unused, version-unused,, libbacktrace)
34AC_CONFIG_SRCDIR(backtrace.h)
35AC_CONFIG_HEADER(config.h)
94b46f34 36AC_CONFIG_MACRO_DIR(config)
1a4d82fc 37
94b46f34 38# with_target_subdir is used when configured as part of a GCC tree.
9346a6ac
AL
39if test -n "${with_target_subdir}"; then
40 AM_ENABLE_MULTILIB(, ..)
41fi
42
1a4d82fc
JJ
43AC_CANONICAL_SYSTEM
44target_alias=${target_alias-$host_alias}
45
46AC_USE_SYSTEM_EXTENSIONS
47
48libtool_VERSION=1:0:0
49AC_SUBST(libtool_VERSION)
50
51# 1.11.1: Require that version of automake.
52# foreign: Don't require README, INSTALL, NEWS, etc.
53# no-define: Don't define PACKAGE and VERSION.
54# no-dependencies: Don't generate automatic dependencies.
55# (because it breaks when using bootstrap-lean, since some of the
56# headers are gone at "make install" time).
57# -Wall: Issue all automake warnings.
58# -Wno-portability: Don't warn about constructs supported by GNU make.
59# (because GCC requires GNU make anyhow).
60AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
61
62AM_MAINTAINER_MODE
63
64AC_ARG_WITH(target-subdir,
65[ --with-target-subdir=SUBDIR Configuring in a subdirectory for target])
66
67# We must force CC to /not/ be precious variables; otherwise
68# the wrong, non-multilib-adjusted value will be used in multilibs.
69# As a side effect, we have to subst CFLAGS ourselves.
70m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
71m4_define([_AC_ARG_VAR_PRECIOUS],[])
72AC_PROG_CC
73m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
74
75AC_SUBST(CFLAGS)
76
1a4d82fc
JJ
77AC_PROG_AWK
78case "$AWK" in
79"") AC_MSG_ERROR([can't build without awk]) ;;
80esac
81
9cc50fc6 82LT_INIT
1a4d82fc
JJ
83AM_PROG_LIBTOOL
84
94b46f34
XL
85AC_SYS_LARGEFILE
86
1a4d82fc
JJ
87backtrace_supported=yes
88
89if test -n "${with_target_subdir}"; then
90 # We are compiling a GCC library. We can assume that the unwind
91 # library exists.
1a4d82fc
JJ
92 BACKTRACE_FILE="backtrace.lo simple.lo"
93else
94 AC_CHECK_HEADER([unwind.h],
95 [AC_CHECK_FUNC([_Unwind_Backtrace],
96 [BACKTRACE_FILE="backtrace.lo simple.lo"],
97 [BACKTRACE_FILE="nounwind.lo"
98 backtrace_supported=no])],
99 [BACKTRACE_FILE="nounwind.lo"
100 backtrace_supported=no])
101fi
102AC_SUBST(BACKTRACE_FILE)
103
104EXTRA_FLAGS=
105if test -n "${with_target_subdir}"; then
106 EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
107else
108 AC_CACHE_CHECK([for -funwind-tables option],
109 [libbacktrace_cv_c_unwind_tables],
110 [CFLAGS_hold="$CFLAGS"
111 CFLAGS="$CFLAGS -funwind-tables"
112 AC_COMPILE_IFELSE(
113 [AC_LANG_PROGRAM([static int f() { return 0; }], [return f();])],
114 [libbacktrace_cv_c_unwind_tables=yes],
115 [libbacktrace_cv_c_unwind_tables=no])
116 CFLAGS="$CFLAGS_hold"])
117 if test "$libbacktrace_cv_c_unwind_tables" = "yes"; then
118 EXTRA_FLAGS=-funwind-tables
119 fi
120 AC_CACHE_CHECK([for -frandom-seed=string option],
121 [libbacktrace_cv_c_random_seed_string],
122 [CFLAGS_hold="$CFLAGS"
123 CFLAGS="$CFLAGS -frandom-seed=conftest.lo"
124 AC_COMPILE_IFELSE(
125 [AC_LANG_PROGRAM([], [return 0;])],
126 [libbacktrace_cv_c_random_seed_string=yes],
127 [libbacktrace_cv_c_random_seed_string=no])
128 CFLAGS="$CFLAGS_hold"])
129 if test "$libbacktrace_cv_c_random_seed_string" = "yes"; then
130 EXTRA_FLAGS="$EXTRA_FLAGS -frandom-seed=\$@"
131 fi
132fi
133AC_SUBST(EXTRA_FLAGS)
134
135ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
136 -Wmissing-prototypes -Wold-style-definition \
137 -Wmissing-format-attribute -Wcast-qual],
138 [WARN_FLAGS])
139
140if test -n "${with_target_subdir}"; then
141 WARN_FLAGS="$WARN_FLAGS -Werror"
142fi
143
144AC_SUBST(WARN_FLAGS)
145
146if test -n "${with_target_subdir}"; then
147 GCC_CHECK_UNWIND_GETIPINFO
148else
149 ac_save_CFFLAGS="$CFLAGS"
150 CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
151 AC_MSG_CHECKING([for _Unwind_GetIPInfo])
152 AC_LINK_IFELSE(
153 [AC_LANG_PROGRAM(
154 [#include "unwind.h"
155 struct _Unwind_Context *context;
156 int ip_before_insn = 0;],
157 [return _Unwind_GetIPInfo (context, &ip_before_insn);])],
158 [have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
159 CFLAGS="$ac_save_CFLAGS"
160 AC_MSG_RESULT([$have_unwind_getipinfo])
161 if test "$have_unwind_getipinfo" = "yes"; then
162 AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
163 fi
164fi
165
9cc50fc6 166# Enable --enable-host-shared.
1a4d82fc
JJ
167AC_ARG_ENABLE(host-shared,
168[AS_HELP_STRING([--enable-host-shared],
169 [build host code as shared libraries])],
9cc50fc6 170[PIC_FLAG=-fPIC], [PIC_FLAG=])
1a4d82fc
JJ
171AC_SUBST(PIC_FLAG)
172
173# Test for __sync support.
174AC_CACHE_CHECK([__sync extensions],
175[libbacktrace_cv_sys_sync],
176[if test -n "${with_target_subdir}"; then
9cc50fc6
SL
177 case "${host}" in
178 hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
179 *) libbacktrace_cv_sys_sync=yes ;;
180 esac
1a4d82fc
JJ
181 else
182 AC_LINK_IFELSE(
183 [AC_LANG_PROGRAM([int i;],
184 [__sync_bool_compare_and_swap (&i, i, i);
185 __sync_lock_test_and_set (&i, 1);
186 __sync_lock_release (&i);])],
187 [libbacktrace_cv_sys_sync=yes],
188 [libbacktrace_cv_sys_sync=no])
189 fi])
190BACKTRACE_SUPPORTS_THREADS=0
191if test "$libbacktrace_cv_sys_sync" = "yes"; then
192 BACKTRACE_SUPPORTS_THREADS=1
193 AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
194 [Define to 1 if you have the __sync functions])
195fi
196AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
197
198# Test for __atomic support.
199AC_CACHE_CHECK([__atomic extensions],
200[libbacktrace_cv_sys_atomic],
201[if test -n "${with_target_subdir}"; then
202 libbacktrace_cv_sys_atomic=yes
203 else
204 AC_LINK_IFELSE(
205 [AC_LANG_PROGRAM([int i;],
206 [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
207 __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
208 [libbacktrace_cv_sys_atomic=yes],
209 [libbacktrace_cv_sys_atomic=no])
210 fi])
211if test "$libbacktrace_cv_sys_atomic" = "yes"; then
212 AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
213 [Define to 1 if you have the __atomic functions])
214fi
215
216# The library needs to be able to read the executable itself. Compile
217# a file to determine the executable format. The awk script
218# filetype.awk prints out the file type.
219AC_CACHE_CHECK([output filetype],
220[libbacktrace_cv_sys_filetype],
221[filetype=
222AC_COMPILE_IFELSE(
223 [AC_LANG_PROGRAM([int i;], [int j;])],
224 [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
225 [AC_MSG_FAILURE([compiler failed])])
226libbacktrace_cv_sys_filetype=$filetype])
227
228# Match the file type to decide what files to compile.
229FORMAT_FILE=
e9174d1e 230backtrace_supports_data=yes
1a4d82fc
JJ
231case "$libbacktrace_cv_sys_filetype" in
232elf*) FORMAT_FILE="elf.lo" ;;
e9174d1e
SL
233pecoff) FORMAT_FILE="pecoff.lo"
234 backtrace_supports_data=no
235 ;;
94b46f34
XL
236xcoff*) FORMAT_FILE="xcoff.lo"
237 backtrace_supports_data=no
238 ;;
ea8adc8c
XL
239macho*) FORMAT_FILE="macho.lo"
240 backtrace_supports_data=no
241 ;;
1a4d82fc
JJ
242*) AC_MSG_WARN([could not determine output file type])
243 FORMAT_FILE="unknown.lo"
244 backtrace_supported=no
245 ;;
246esac
247AC_SUBST(FORMAT_FILE)
248
249# ELF defines.
250elfsize=
251case "$libbacktrace_cv_sys_filetype" in
252elf32) elfsize=32 ;;
253elf64) elfsize=64 ;;
e9174d1e 254*) elfsize=unused
1a4d82fc
JJ
255esac
256AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
257
94b46f34
XL
258# XCOFF defines.
259xcoffsize=
260case "$libbacktrace_cv_sys_filetype" in
261xcoff32) xcoffsize=32 ;;
262xcoff64) xcoffsize=64 ;;
263*) xcoffsize=unused
264esac
265AC_DEFINE_UNQUOTED([BACKTRACE_XCOFF_SIZE], [$xcoffsize], [XCOFF size: 32 or 64])
266
1a4d82fc
JJ
267BACKTRACE_SUPPORTED=0
268if test "$backtrace_supported" = "yes"; then
269 BACKTRACE_SUPPORTED=1
270fi
271AC_SUBST(BACKTRACE_SUPPORTED)
272
e9174d1e
SL
273BACKTRACE_SUPPORTS_DATA=0
274if test "$backtrace_supports_data" = "yes"; then
275 BACKTRACE_SUPPORTS_DATA=1
276fi
277AC_SUBST(BACKTRACE_SUPPORTS_DATA)
278
1a4d82fc
JJ
279AC_CHECK_HEADERS(sys/mman.h)
280if test "$ac_cv_header_sys_mman_h" = "no"; then
281 have_mmap=no
282else
283 if test -n "${with_target_subdir}"; then
284 # When built as a GCC target library, we can't do a link test. We
285 # simply assume that if we have mman.h, we have mmap.
286 have_mmap=yes
e9174d1e 287 case "${host}" in
9cc50fc6 288 spu-*-*|*-*-msdosdjgpp)
e9174d1e
SL
289 # The SPU does not have mmap, but it has a sys/mman.h header file
290 # containing "mmap_eaddr" and the mmap flags, confusing the test.
9cc50fc6 291 # DJGPP also has sys/man.h, but no mmap
e9174d1e
SL
292 have_mmap=no ;;
293 esac
1a4d82fc
JJ
294 else
295 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
296 fi
297fi
ea8adc8c
XL
298
299case "${host_os}" in
300darwin*)
301 have_mmap=no ;;
302esac
303
1a4d82fc
JJ
304if test "$have_mmap" = "no"; then
305 VIEW_FILE=read.lo
306 ALLOC_FILE=alloc.lo
307else
308 VIEW_FILE=mmapio.lo
309 AC_PREPROC_IFELSE([
310#include <sys/mman.h>
311#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
312 #error no MAP_ANONYMOUS
313#endif
314], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
315fi
316AC_SUBST(VIEW_FILE)
317AC_SUBST(ALLOC_FILE)
318
319BACKTRACE_USES_MALLOC=0
320if test "$ALLOC_FILE" = "alloc.lo"; then
321 BACKTRACE_USES_MALLOC=1
322fi
323AC_SUBST(BACKTRACE_USES_MALLOC)
324
325# Check for dl_iterate_phdr.
326AC_CHECK_HEADERS(link.h)
327if test "$ac_cv_header_link_h" = "no"; then
328 have_dl_iterate_phdr=no
329else
330 if test -n "${with_target_subdir}"; then
331 # When built as a GCC target library, we can't do a link test.
332 AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
333 [have_dl_iterate_phdr=no])
334 case "${host}" in
335 *-*-solaris2.10*)
336 # Avoid dl_iterate_phdr on Solaris 10, where it is in the
337 # header file but is only in -ldl.
338 have_dl_iterate_phdr=no ;;
339 esac
340 else
341 AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
342 [have_dl_iterate_phdr=no])
343 fi
344fi
345if test "$have_dl_iterate_phdr" = "yes"; then
346 AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
347fi
348
94b46f34
XL
349# Check for loadquery.
350AC_CHECK_HEADERS(sys/ldr.h)
351if test "$ac_cv_header_sys_ldr_h" = "no"; then
352 have_loadquery=no
353else
354 if test -n "${with_target_subdir}"; then
355 # When built as a GCC target library, we can't do a link test.
356 AC_EGREP_HEADER([loadquery], [sys/ldr.h], [have_loadquery=yes],
357 [have_loadquery=no])
358 else
359 AC_CHECK_FUNC([loadquery], [have_loadquery=yes],
360 [have_loadquery=no])
361 fi
362fi
363if test "$have_loadquery" = "yes"; then
364 AC_DEFINE(HAVE_LOADQUERY, 1, [Define if AIX loadquery is available.])
365fi
366
1a4d82fc
JJ
367# Check for the fcntl function.
368if test -n "${with_target_subdir}"; then
369 case "${host}" in
370 *-*-mingw*) have_fcntl=no ;;
9cc50fc6 371 spu-*-*) have_fcntl=no ;;
1a4d82fc
JJ
372 *) have_fcntl=yes ;;
373 esac
374else
375 AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
376fi
377if test "$have_fcntl" = "yes"; then
378 AC_DEFINE([HAVE_FCNTL], 1,
379 [Define to 1 if you have the fcntl function])
380fi
381
382AC_CHECK_DECLS(strnlen)
94b46f34 383AC_CHECK_FUNCS(lstat readlink)
1a4d82fc
JJ
384
385# Check for getexecname function.
386if test -n "${with_target_subdir}"; then
387 case "${host}" in
388 *-*-solaris2*) have_getexecname=yes ;;
389 *) have_getexecname=no ;;
390 esac
391else
392 AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
393fi
394if test "$have_getexecname" = "yes"; then
395 AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
396fi
397
94b46f34
XL
398# Check for the clock_gettime function.
399AC_CHECK_FUNCS(clock_gettime)
400clock_gettime_link=
401# At least for glibc, clock_gettime is in librt. But don't
402# pull that in if it still doesn't give us the function we want. This
403# test is copied from libgomp, and modified to not link in -lrt as
404# we're using this for test timing only.
405if test "$ac_cv_func_clock_gettime" = no; then
406 AC_CHECK_LIB(rt, clock_gettime,
407 [CLOCK_GETTIME_LINK=-lrt
408 AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
409 [Define to 1 if you have the `clock_gettime' function.])])
410fi
411AC_SUBST(CLOCK_GETTIME_LINK)
412
413dnl Test whether the compiler supports the -pthread option.
414AC_CACHE_CHECK([whether -pthread is supported],
415[libgo_cv_lib_pthread],
416[CFLAGS_hold=$CFLAGS
417CFLAGS="$CFLAGS -pthread"
418AC_COMPILE_IFELSE([[int i;]],
419[libgo_cv_lib_pthread=yes],
420[libgo_cv_lib_pthread=no])
421CFLAGS=$CFLAGS_hold])
422PTHREAD_CFLAGS=
423if test "$libgo_cv_lib_pthread" = yes; then
424 PTHREAD_CFLAGS=-pthread
425fi
426AC_SUBST(PTHREAD_CFLAGS)
427
428AM_CONDITIONAL(HAVE_PTHREAD, test "$libgo_cv_lib_pthread" = yes)
429
430AC_CHECK_LIB([z], [compress], [])
431if test $ac_cv_lib_z_compress = "yes"; then
432 AC_DEFINE(HAVE_ZLIB, 1, [Define if -lz is available.])
433fi
434AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_lib_z_compress" = yes)
435
436dnl Test whether the linker supports the --compress_debug_sections option.
437AC_CACHE_CHECK([whether --compress-debug-sections is supported],
438[libgo_cv_ld_compress],
439[LDFLAGS_hold=$LDFLAGS
440LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zlib-gnu"
441AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
442[libgo_cv_ld_compress=yes],
443[libgo_cv_ld_compress=no])
444LDFLAGS=$LDFLAGS_hold])
445AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
446
447AC_ARG_VAR(OBJCOPY, [location of objcopy])
448AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
449AC_CACHE_CHECK([whether objcopy supports debuglink],
450[libbacktrace_cv_objcopy_debuglink],
451[if test -n "${with_target_subdir}"; then
452 libbacktrace_cv_objcopy_debuglink=no
453elif ${OBJCOPY} --add-gnu-debuglink=x /bin/ls /tmp/ls$$; then
454 rm -f /tmp/ls$$
455 libbacktrace_cv_objcopy_debuglink=yes
456else
457 libbacktrace_cv_objcopy_debuglink=no
458fi])
459AM_CONDITIONAL(HAVE_OBJCOPY_DEBUGLINK, test "$libbacktrace_cv_objcopy_debuglink" = yes)
460
1a4d82fc
JJ
461AC_CACHE_CHECK([whether tests can run],
462 [libbacktrace_cv_sys_native],
463 [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
464 [libbacktrace_cv_sys_native=yes],
465 [libbacktrace_cv_sys_native=no],
466 [libbacktrace_cv_sys_native=no])])
467AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
468
469if test "${multilib}" = "yes"; then
470 multilib_arg="--enable-multilib"
471else
472 multilib_arg=
473fi
474
475AC_CONFIG_FILES(Makefile backtrace-supported.h)
476
477# We need multilib support, but only if configuring for the target.
478AC_CONFIG_COMMANDS([default],
479[if test -n "$CONFIG_FILES"; then
480 if test -n "${with_target_subdir}"; then
481 # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
482 # that multilib installs will end up installed in the correct place.
483 # The testsuite needs it for multilib-aware ABI baseline files.
484 # To work around this not being passed down from config-ml.in ->
485 # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
486 # append it here. Only modify Makefiles that have just been created.
487 #
488 # Also, get rid of this simulated-VPATH thing that automake does.
489 cat > vpsed << \_EOF
490 s!`test -f '$<' || echo '$(srcdir)/'`!!
491_EOF
492 for i in $SUBDIRS; do
493 case $CONFIG_FILES in
494 *${i}/Makefile*)
495 #echo "Adding MULTISUBDIR to $i/Makefile"
496 sed -f vpsed $i/Makefile > tmp
497 grep '^MULTISUBDIR =' Makefile >> tmp
498 mv tmp $i/Makefile
499 ;;
500 esac
501 done
502 rm vpsed
503 fi
504 fi
505],
506[
507# Variables needed in config.status (file generation) which aren't already
508# passed by autoconf.
509SUBDIRS="$SUBDIRS"
510])
511
512AC_OUTPUT