Fix i686-pc-cygwin build failure.
[official-gcc.git] / libbacktrace / configure.ac
blob36a6d470fc3be6cccf452854bba9e3ea9ead52d4
1 # configure.ac -- Backtrace configure script.
2 # Copyright (C) 2012-2017 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
6 # met:
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
14 #     distribution.
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_PREREQ(2.64)
33 AC_INIT(package-unused, version-unused,, libbacktrace)
34 AC_CONFIG_SRCDIR(backtrace.h)
35 AC_CONFIG_HEADER(config.h)
37 if test -n "${with_target_subdir}"; then
38   AM_ENABLE_MULTILIB(, ..)
41 AC_CANONICAL_SYSTEM
42 target_alias=${target_alias-$host_alias}
44 AC_USE_SYSTEM_EXTENSIONS
46 libtool_VERSION=1:0:0
47 AC_SUBST(libtool_VERSION)
49 # 1.11.1: Require that version of automake.
50 # foreign: Don't require README, INSTALL, NEWS, etc.
51 # no-define: Don't define PACKAGE and VERSION.
52 # no-dependencies: Don't generate automatic dependencies.
53 #    (because it breaks when using bootstrap-lean, since some of the
54 #    headers are gone at "make install" time).
55 # -Wall: Issue all automake warnings.
56 # -Wno-portability: Don't warn about constructs supported by GNU make.
57 #    (because GCC requires GNU make anyhow).
58 AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
60 AM_MAINTAINER_MODE
62 AC_ARG_WITH(target-subdir,
63 [  --with-target-subdir=SUBDIR      Configuring in a subdirectory for target])
65 # We must force CC to /not/ be precious variables; otherwise
66 # the wrong, non-multilib-adjusted value will be used in multilibs.
67 # As a side effect, we have to subst CFLAGS ourselves.
68 m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
69 m4_define([_AC_ARG_VAR_PRECIOUS],[])
70 AC_PROG_CC
71 m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
73 AC_SUBST(CFLAGS)
75 AC_PROG_RANLIB
77 AC_PROG_AWK
78 case "$AWK" in
79 "") AC_MSG_ERROR([can't build without awk]) ;;
80 esac
82 LT_INIT
83 AM_PROG_LIBTOOL
85 AC_SYS_LARGEFILE
87 backtrace_supported=yes
89 if test -n "${with_target_subdir}"; then
90   # We are compiling a GCC library.  We can assume that the unwind
91   # library exists.
92   BACKTRACE_FILE="backtrace.lo simple.lo"
93 else
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])
102 AC_SUBST(BACKTRACE_FILE)
104 EXTRA_FLAGS=
105 if test -n "${with_target_subdir}"; then
106   EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
107 else
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
133 AC_SUBST(EXTRA_FLAGS)
135 ACX_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])
140 if test -n "${with_target_subdir}"; then
141   WARN_FLAGS="$WARN_FLAGS -Werror"
144 AC_SUBST(WARN_FLAGS)
146 if test -n "${with_target_subdir}"; then
147   GCC_CHECK_UNWIND_GETIPINFO
148 else
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
166 # Enable --enable-host-shared.
167 AC_ARG_ENABLE(host-shared,
168 [AS_HELP_STRING([--enable-host-shared],
169                 [build host code as shared libraries])],
170 [PIC_FLAG=-fPIC], [PIC_FLAG=])
171 AC_SUBST(PIC_FLAG)
173 # Test for __sync support.
174 AC_CACHE_CHECK([__sync extensions],
175 [libbacktrace_cv_sys_sync],
176 [if test -n "${with_target_subdir}"; then
177    case "${host}" in
178    hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
179    *) libbacktrace_cv_sys_sync=yes ;;
180    esac
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])
190 BACKTRACE_SUPPORTS_THREADS=0
191 if 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])
196 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
198 # Test for __atomic support.
199 AC_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])
211 if test "$libbacktrace_cv_sys_atomic" = "yes"; then
212   AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
213             [Define to 1 if you have the __atomic functions])
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.
219 AC_CACHE_CHECK([output filetype],
220 [libbacktrace_cv_sys_filetype],
221 [filetype=
222 AC_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])])
226 libbacktrace_cv_sys_filetype=$filetype])
228 # Match the file type to decide what files to compile.
229 FORMAT_FILE=
230 backtrace_supports_data=yes
231 case "$libbacktrace_cv_sys_filetype" in
232 elf*) FORMAT_FILE="elf.lo" ;;
233 pecoff) FORMAT_FILE="pecoff.lo"
234         backtrace_supports_data=no
235         ;;
236 xcoff) FORMAT_FILE="xcoff.lo"
237        backtrace_supports_data=no
238        ;;
239 *) AC_MSG_WARN([could not determine output file type])
240    FORMAT_FILE="unknown.lo"
241    backtrace_supported=no
242    ;;
243 esac
244 AC_SUBST(FORMAT_FILE)
246 # ELF defines.
247 elfsize=
248 case "$libbacktrace_cv_sys_filetype" in
249 elf32) elfsize=32 ;;
250 elf64) elfsize=64 ;;
251 *)     elfsize=unused
252 esac
253 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
255 BACKTRACE_SUPPORTED=0
256 if test "$backtrace_supported" = "yes"; then
257   BACKTRACE_SUPPORTED=1
259 AC_SUBST(BACKTRACE_SUPPORTED)
261 BACKTRACE_SUPPORTS_DATA=0
262 if test "$backtrace_supports_data" = "yes"; then
263   BACKTRACE_SUPPORTS_DATA=1
265 AC_SUBST(BACKTRACE_SUPPORTS_DATA)
267 GCC_HEADER_STDINT(gstdint.h)
269 AC_CHECK_HEADERS(sys/mman.h)
270 if test "$ac_cv_header_sys_mman_h" = "no"; then
271   have_mmap=no
272 else
273   if test -n "${with_target_subdir}"; then
274     # When built as a GCC target library, we can't do a link test.  We
275     # simply assume that if we have mman.h, we have mmap.
276     have_mmap=yes
277     case "${host}" in
278     spu-*-*|*-*-msdosdjgpp)
279         # The SPU does not have mmap, but it has a sys/mman.h header file
280         # containing "mmap_eaddr" and the mmap flags, confusing the test.
281         # DJGPP also has sys/man.h, but no mmap
282         have_mmap=no ;;
283     esac
284   else
285     AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
286   fi
288 if test "$have_mmap" = "no"; then
289   VIEW_FILE=read.lo
290   ALLOC_FILE=alloc.lo
291 else
292   VIEW_FILE=mmapio.lo
293   AC_PREPROC_IFELSE([
294 #include <sys/mman.h>
295 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
296   #error no MAP_ANONYMOUS
297 #endif
298 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
300 AC_SUBST(VIEW_FILE)
301 AC_SUBST(ALLOC_FILE)
303 BACKTRACE_USES_MALLOC=0
304 if test "$ALLOC_FILE" = "alloc.lo"; then
305   BACKTRACE_USES_MALLOC=1
307 AC_SUBST(BACKTRACE_USES_MALLOC)
309 # Check for dl_iterate_phdr.
310 AC_CHECK_HEADERS(link.h)
311 if test "$ac_cv_header_link_h" = "no"; then
312   have_dl_iterate_phdr=no
313 else
314   if test -n "${with_target_subdir}"; then
315     # When built as a GCC target library, we can't do a link test.
316     AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
317                     [have_dl_iterate_phdr=no])
318     case "${host}" in
319     *-*-solaris2.10*)
320         # Avoid dl_iterate_phdr on Solaris 10, where it is in the
321         # header file but is only in -ldl.
322         have_dl_iterate_phdr=no ;;
323     esac
324   else
325     AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
326                   [have_dl_iterate_phdr=no])
327   fi
329 if test "$have_dl_iterate_phdr" = "yes"; then
330   AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
333 # Check for the fcntl function.
334 if test -n "${with_target_subdir}"; then
335    case "${host}" in
336    *-*-mingw*) have_fcntl=no ;;
337    spu-*-*) have_fcntl=no ;;
338    *) have_fcntl=yes ;;
339    esac
340 else
341   AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
343 if test "$have_fcntl" = "yes"; then
344   AC_DEFINE([HAVE_FCNTL], 1,
345             [Define to 1 if you have the fcntl function])
348 AC_CHECK_DECLS(strnlen)
350 # Check for getexecname function.
351 if test -n "${with_target_subdir}"; then
352    case "${host}" in
353    *-*-solaris2*) have_getexecname=yes ;;
354    *) have_getexecname=no ;;
355    esac
356 else
357   AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
359 if test "$have_getexecname" = "yes"; then
360   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
363 dnl Test whether the compiler supports the -pthread option.
364 AC_CACHE_CHECK([whether -pthread is supported],
365 [libgo_cv_lib_pthread],
366 [CFLAGS_hold=$CFLAGS
367 CFLAGS="$CFLAGS -pthread"
368 AC_COMPILE_IFELSE([[int i;]],
369 [libgo_cv_lib_pthread=yes],
370 [libgo_cv_lib_pthread=no])
371 CFLAGS=$CFLAGS_hold])
372 PTHREAD_CFLAGS=
373 if test "$libgo_cv_lib_pthread" = yes; then
374   PTHREAD_CFLAGS=-pthread
376 AC_SUBST(PTHREAD_CFLAGS)
378 AM_CONDITIONAL(HAVE_PTHREAD, test "$libgo_cv_lib_pthread" = yes)
380 AC_CACHE_CHECK([whether tests can run],
381   [libbacktrace_cv_sys_native],
382   [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
383      [libbacktrace_cv_sys_native=yes],
384      [libbacktrace_cv_sys_native=no],
385      [libbacktrace_cv_sys_native=no])])
386 AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
388 if test "${multilib}" = "yes"; then
389   multilib_arg="--enable-multilib"
390 else
391   multilib_arg=
394 AC_CONFIG_FILES(Makefile backtrace-supported.h)
396 # We need multilib support, but only if configuring for the target.
397 AC_CONFIG_COMMANDS([default],
398 [if test -n "$CONFIG_FILES"; then
399    if test -n "${with_target_subdir}"; then
400      # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
401      # that multilib installs will end up installed in the correct place.
402      # The testsuite needs it for multilib-aware ABI baseline files.
403      # To work around this not being passed down from config-ml.in ->
404      # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
405      # append it here.  Only modify Makefiles that have just been created.
406      #
407      # Also, get rid of this simulated-VPATH thing that automake does.
408      cat > vpsed << \_EOF
409   s!`test -f '$<' || echo '$(srcdir)/'`!!
410 _EOF
411      for i in $SUBDIRS; do
412       case $CONFIG_FILES in
413        *${i}/Makefile*)
414          #echo "Adding MULTISUBDIR to $i/Makefile"
415          sed -f vpsed $i/Makefile > tmp
416          grep '^MULTISUBDIR =' Makefile >> tmp
417          mv tmp $i/Makefile
418          ;;
419       esac
420      done
421      rm vpsed
422    fi
423  fi
426 # Variables needed in config.status (file generation) which aren't already
427 # passed by autoconf.
428 SUBDIRS="$SUBDIRS"
431 AC_OUTPUT