1 # configure.ac -- Backtrace configure script.
2 # Copyright (C) 2012-2019 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 AC_INIT(package-unused, version-unused,, libbacktrace)
33 AC_CONFIG_SRCDIR(backtrace.h)
34 AC_CONFIG_HEADER(config.h)
36 if test -n "${with_target_subdir}"; then
37 AM_ENABLE_MULTILIB(, ..)
41 target_alias=${target_alias-$host_alias}
43 AC_USE_SYSTEM_EXTENSIONS
46 AC_SUBST(libtool_VERSION)
48 # 1.11.1: Require that version of automake.
49 # foreign: Don't require README, INSTALL, NEWS, etc.
50 # no-define: Don't define PACKAGE and VERSION.
51 # no-dependencies: Don't generate automatic dependencies.
52 # (because it breaks when using bootstrap-lean, since some of the
53 # headers are gone at "make install" time).
54 # -Wall: Issue all automake warnings.
55 # -Wno-portability: Don't warn about constructs supported by GNU make.
56 # (because GCC requires GNU make anyhow).
57 AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
61 AC_ARG_WITH(target-subdir,
62 [ --with-target-subdir=SUBDIR Configuring in a subdirectory for target])
64 # We must force CC to /not/ be precious variables; otherwise
65 # the wrong, non-multilib-adjusted value will be used in multilibs.
66 # As a side effect, we have to subst CFLAGS ourselves.
67 m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
68 m4_define([_AC_ARG_VAR_PRECIOUS],[])
70 m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
78 "") AC_MSG_ERROR([can't build without awk]) ;;
86 backtrace_supported=yes
88 if test -n "${with_target_subdir}"; then
89 # We are compiling a GCC library. We can assume that the unwind
91 BACKTRACE_FILE="backtrace.lo simple.lo"
93 AC_CHECK_HEADER([unwind.h],
94 [AC_CHECK_FUNC([_Unwind_Backtrace],
95 [BACKTRACE_FILE="backtrace.lo simple.lo"],
96 [BACKTRACE_FILE="nounwind.lo"
97 backtrace_supported=no])],
98 [BACKTRACE_FILE="nounwind.lo"
99 backtrace_supported=no])
101 AC_SUBST(BACKTRACE_FILE)
104 if test -n "${with_target_subdir}"; then
105 EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
107 AC_CACHE_CHECK([for -funwind-tables option],
108 [libbacktrace_cv_c_unwind_tables],
109 [CFLAGS_hold="$CFLAGS"
110 CFLAGS="$CFLAGS -funwind-tables"
112 [AC_LANG_PROGRAM([static int f() { return 0; }], [return f();])],
113 [libbacktrace_cv_c_unwind_tables=yes],
114 [libbacktrace_cv_c_unwind_tables=no])
115 CFLAGS="$CFLAGS_hold"])
116 if test "$libbacktrace_cv_c_unwind_tables" = "yes"; then
117 EXTRA_FLAGS=-funwind-tables
119 AC_CACHE_CHECK([for -frandom-seed=string option],
120 [libbacktrace_cv_c_random_seed_string],
121 [CFLAGS_hold="$CFLAGS"
122 CFLAGS="$CFLAGS -frandom-seed=conftest.lo"
124 [AC_LANG_PROGRAM([], [return 0;])],
125 [libbacktrace_cv_c_random_seed_string=yes],
126 [libbacktrace_cv_c_random_seed_string=no])
127 CFLAGS="$CFLAGS_hold"])
128 if test "$libbacktrace_cv_c_random_seed_string" = "yes"; then
129 EXTRA_FLAGS="$EXTRA_FLAGS -frandom-seed=\$@"
133 if test -n "${with_target_subdir}"; then
134 # Add CET specific flags is Intel CET is enabled.
135 GCC_CET_FLAGS(CET_FLAGS)
136 EXTRA_FLAGS="$EXTRA_FLAGS $CET_FLAGS"
138 AC_SUBST(EXTRA_FLAGS)
140 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
141 -Wmissing-prototypes -Wold-style-definition \
142 -Wmissing-format-attribute -Wcast-qual],
145 if test -n "${with_target_subdir}"; then
146 WARN_FLAGS="$WARN_FLAGS -Werror"
151 if test -n "${with_target_subdir}"; then
152 GCC_CHECK_UNWIND_GETIPINFO
154 ac_save_CFFLAGS="$CFLAGS"
155 CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
156 AC_MSG_CHECKING([for _Unwind_GetIPInfo])
160 struct _Unwind_Context *context;
161 int ip_before_insn = 0;],
162 [return _Unwind_GetIPInfo (context, &ip_before_insn);])],
163 [have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
164 CFLAGS="$ac_save_CFLAGS"
165 AC_MSG_RESULT([$have_unwind_getipinfo])
166 if test "$have_unwind_getipinfo" = "yes"; then
167 AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
171 # Enable --enable-host-shared.
172 AC_ARG_ENABLE(host-shared,
173 [AS_HELP_STRING([--enable-host-shared],
174 [build host code as shared libraries])],
175 [PIC_FLAG=-fPIC], [PIC_FLAG=])
178 # Test for __sync support.
179 AC_CACHE_CHECK([__sync extensions],
180 [libbacktrace_cv_sys_sync],
181 [if test -n "${with_target_subdir}"; then
183 hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
184 *) libbacktrace_cv_sys_sync=yes ;;
188 [AC_LANG_PROGRAM([int i;],
189 [__sync_bool_compare_and_swap (&i, i, i);
190 __sync_lock_test_and_set (&i, 1);
191 __sync_lock_release (&i);])],
192 [libbacktrace_cv_sys_sync=yes],
193 [libbacktrace_cv_sys_sync=no])
195 BACKTRACE_SUPPORTS_THREADS=0
196 if test "$libbacktrace_cv_sys_sync" = "yes"; then
197 BACKTRACE_SUPPORTS_THREADS=1
198 AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
199 [Define to 1 if you have the __sync functions])
201 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
203 # Test for __atomic support.
204 AC_CACHE_CHECK([__atomic extensions],
205 [libbacktrace_cv_sys_atomic],
206 [if test -n "${with_target_subdir}"; then
207 libbacktrace_cv_sys_atomic=yes
210 [AC_LANG_PROGRAM([int i;],
211 [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
212 __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
213 [libbacktrace_cv_sys_atomic=yes],
214 [libbacktrace_cv_sys_atomic=no])
216 if test "$libbacktrace_cv_sys_atomic" = "yes"; then
217 AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
218 [Define to 1 if you have the __atomic functions])
221 # The library needs to be able to read the executable itself. Compile
222 # a file to determine the executable format. The awk script
223 # filetype.awk prints out the file type.
224 AC_CACHE_CHECK([output filetype],
225 [libbacktrace_cv_sys_filetype],
228 [AC_LANG_PROGRAM([int i;], [int j;])],
229 [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
230 [AC_MSG_FAILURE([compiler failed])])
231 libbacktrace_cv_sys_filetype=$filetype])
233 # Match the file type to decide what files to compile.
235 backtrace_supports_data=yes
236 case "$libbacktrace_cv_sys_filetype" in
237 elf*) FORMAT_FILE="elf.lo" ;;
238 pecoff) FORMAT_FILE="pecoff.lo"
239 backtrace_supports_data=no
241 xcoff*) FORMAT_FILE="xcoff.lo"
242 backtrace_supports_data=no
244 *) AC_MSG_WARN([could not determine output file type])
245 FORMAT_FILE="unknown.lo"
246 backtrace_supported=no
249 AC_SUBST(FORMAT_FILE)
253 case "$libbacktrace_cv_sys_filetype" in
258 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
262 case "$libbacktrace_cv_sys_filetype" in
263 xcoff32) xcoffsize=32 ;;
264 xcoff64) xcoffsize=64 ;;
267 AC_DEFINE_UNQUOTED([BACKTRACE_XCOFF_SIZE], [$xcoffsize], [XCOFF size: 32 or 64])
269 BACKTRACE_SUPPORTED=0
270 if test "$backtrace_supported" = "yes"; then
271 BACKTRACE_SUPPORTED=1
273 AC_SUBST(BACKTRACE_SUPPORTED)
275 BACKTRACE_SUPPORTS_DATA=0
276 if test "$backtrace_supports_data" = "yes"; then
277 BACKTRACE_SUPPORTS_DATA=1
279 AC_SUBST(BACKTRACE_SUPPORTS_DATA)
281 GCC_HEADER_STDINT(gstdint.h)
283 AC_CHECK_HEADERS(sys/mman.h)
284 if test "$ac_cv_header_sys_mman_h" = "no"; then
287 if test -n "${with_target_subdir}"; then
288 # When built as a GCC target library, we can't do a link test. We
289 # simply assume that if we have mman.h, we have mmap.
292 spu-*-*|*-*-msdosdjgpp)
293 # The SPU does not have mmap, but it has a sys/mman.h header file
294 # containing "mmap_eaddr" and the mmap flags, confusing the test.
295 # DJGPP also has sys/man.h, but no mmap
299 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
302 if test "$have_mmap" = "no"; then
307 AC_PREPROC_IFELSE([AC_LANG_SOURCE([
308 #include <sys/mman.h>
309 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
310 #error no MAP_ANONYMOUS
312 ])], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
317 BACKTRACE_USES_MALLOC=0
318 if test "$ALLOC_FILE" = "alloc.lo"; then
319 BACKTRACE_USES_MALLOC=1
321 AC_SUBST(BACKTRACE_USES_MALLOC)
323 # Check for dl_iterate_phdr.
324 AC_CHECK_HEADERS(link.h)
325 if test "$ac_cv_header_link_h" = "no"; then
326 have_dl_iterate_phdr=no
328 if test -n "${with_target_subdir}"; then
329 # When built as a GCC target library, we can't do a link test.
330 AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
331 [have_dl_iterate_phdr=no])
334 # Avoid dl_iterate_phdr on Solaris 10, where it is in the
335 # header file but is only in -ldl.
336 have_dl_iterate_phdr=no ;;
339 AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
340 [have_dl_iterate_phdr=no])
343 if test "$have_dl_iterate_phdr" = "yes"; then
344 AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
347 # Check for loadquery.
348 AC_CHECK_HEADERS(sys/ldr.h)
349 if test "$ac_cv_header_sys_ldr_h" = "no"; then
352 if test -n "${with_target_subdir}"; then
353 # When built as a GCC target library, we can't do a link test.
354 AC_EGREP_HEADER([loadquery], [sys/ldr.h], [have_loadquery=yes],
357 AC_CHECK_FUNC([loadquery], [have_loadquery=yes],
361 if test "$have_loadquery" = "yes"; then
362 AC_DEFINE(HAVE_LOADQUERY, 1, [Define if AIX loadquery is available.])
365 # Check for the fcntl function.
366 if test -n "${with_target_subdir}"; then
368 *-*-mingw*) have_fcntl=no ;;
369 spu-*-*) have_fcntl=no ;;
373 AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
375 if test "$have_fcntl" = "yes"; then
376 AC_DEFINE([HAVE_FCNTL], 1,
377 [Define to 1 if you have the fcntl function])
380 AC_CHECK_DECLS(strnlen)
381 AC_CHECK_FUNCS(lstat readlink)
383 # Check for getexecname function.
384 if test -n "${with_target_subdir}"; then
386 *-*-solaris2*) have_getexecname=yes ;;
387 *) have_getexecname=no ;;
390 AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
392 if test "$have_getexecname" = "yes"; then
393 AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
396 # Check for the clock_gettime function.
397 AC_CHECK_FUNCS(clock_gettime)
399 # At least for glibc, clock_gettime is in librt. But don't
400 # pull that in if it still doesn't give us the function we want. This
401 # test is copied from libgomp, and modified to not link in -lrt as
402 # we're using this for test timing only.
403 if test "$ac_cv_func_clock_gettime" = no; then
404 AC_CHECK_LIB(rt, clock_gettime,
405 [CLOCK_GETTIME_LINK=-lrt
406 AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
407 [Define to 1 if you have the `clock_gettime' function.])])
409 AC_SUBST(CLOCK_GETTIME_LINK)
411 dnl Test whether the compiler supports the -pthread option.
412 AC_CACHE_CHECK([whether -pthread is supported],
413 [libgo_cv_lib_pthread],
415 CFLAGS="$CFLAGS -pthread"
416 AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
417 [libgo_cv_lib_pthread=yes],
418 [libgo_cv_lib_pthread=no])
419 CFLAGS=$CFLAGS_hold])
421 if test "$libgo_cv_lib_pthread" = yes; then
422 PTHREAD_CFLAGS=-pthread
424 AC_SUBST(PTHREAD_CFLAGS)
426 AM_CONDITIONAL(HAVE_PTHREAD, test "$libgo_cv_lib_pthread" = yes)
428 AC_CHECK_LIB([z], [compress],
429 [AC_DEFINE(HAVE_ZLIB, 1, [Define if -lz is available.])])
430 AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_lib_z_compress" = yes)
432 dnl Test whether the linker supports the --compress_debug_sections option.
433 AC_CACHE_CHECK([whether --compress-debug-sections is supported],
434 [libgo_cv_ld_compress],
435 [LDFLAGS_hold=$LDFLAGS
436 LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zlib-gnu"
437 AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
438 [libgo_cv_ld_compress=yes],
439 [libgo_cv_ld_compress=no])
440 LDFLAGS=$LDFLAGS_hold])
441 AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
443 AC_ARG_VAR(OBJCOPY, [location of objcopy])
444 AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
445 AC_CACHE_CHECK([whether objcopy supports debuglink],
446 [libbacktrace_cv_objcopy_debuglink],
447 [if test -n "${with_target_subdir}"; then
448 libbacktrace_cv_objcopy_debuglink=no
449 elif ${OBJCOPY} --add-gnu-debuglink=x /bin/ls /tmp/ls$$; then
451 libbacktrace_cv_objcopy_debuglink=yes
453 libbacktrace_cv_objcopy_debuglink=no
455 AM_CONDITIONAL(HAVE_OBJCOPY_DEBUGLINK, test "$libbacktrace_cv_objcopy_debuglink" = yes)
457 AC_CACHE_CHECK([whether tests can run],
458 [libbacktrace_cv_sys_native],
459 [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
460 [libbacktrace_cv_sys_native=yes],
461 [libbacktrace_cv_sys_native=no],
462 [libbacktrace_cv_sys_native=no])])
463 AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
465 if test "${multilib}" = "yes"; then
466 multilib_arg="--enable-multilib"
471 AC_CONFIG_FILES(Makefile backtrace-supported.h)
473 # We need multilib support, but only if configuring for the target.
474 AC_CONFIG_COMMANDS([default],
475 [if test -n "$CONFIG_FILES"; then
476 if test -n "${with_target_subdir}"; then
477 # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
478 # that multilib installs will end up installed in the correct place.
479 # The testsuite needs it for multilib-aware ABI baseline files.
480 # To work around this not being passed down from config-ml.in ->
481 # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
482 # append it here. Only modify Makefiles that have just been created.
484 # Also, get rid of this simulated-VPATH thing that automake does.
486 s!`test -f '$<' || echo '$(srcdir)/'`!!
488 for i in $SUBDIRS; do
489 case $CONFIG_FILES in
491 #echo "Adding MULTISUBDIR to $i/Makefile"
492 sed -f vpsed $i/Makefile > tmp
493 grep '^MULTISUBDIR =' Makefile >> tmp
503 # Variables needed in config.status (file generation) which aren't already
504 # passed by autoconf.