libcpp:
[official-gcc.git] / libbacktrace / configure.ac
blob2e5b9c7cb7f3fa0cf13910e962c7a2d939db285f
1 # configure.ac -- Backtrace configure script.
2 # Copyright (C) 2012-2015 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.  
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.
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([disable-shared])
83 AM_PROG_LIBTOOL
85 backtrace_supported=yes
87 if test -n "${with_target_subdir}"; then
88   # We are compiling a GCC library.  We can assume that the unwind
89   # library exists.
90   BACKTRACE_FILE="backtrace.lo simple.lo"
91 else
92   AC_CHECK_HEADER([unwind.h],
93     [AC_CHECK_FUNC([_Unwind_Backtrace],
94                    [BACKTRACE_FILE="backtrace.lo simple.lo"],
95                    [BACKTRACE_FILE="nounwind.lo"
96                     backtrace_supported=no])],
97     [BACKTRACE_FILE="nounwind.lo"
98      backtrace_supported=no])
100 AC_SUBST(BACKTRACE_FILE)
102 EXTRA_FLAGS=
103 if test -n "${with_target_subdir}"; then
104   EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
105 else
106   AC_CACHE_CHECK([for -funwind-tables option],
107     [libbacktrace_cv_c_unwind_tables],
108     [CFLAGS_hold="$CFLAGS"
109      CFLAGS="$CFLAGS -funwind-tables"
110      AC_COMPILE_IFELSE(
111        [AC_LANG_PROGRAM([static int f() { return 0; }], [return f();])],
112        [libbacktrace_cv_c_unwind_tables=yes],
113        [libbacktrace_cv_c_unwind_tables=no])
114      CFLAGS="$CFLAGS_hold"])
115   if test "$libbacktrace_cv_c_unwind_tables" = "yes"; then
116     EXTRA_FLAGS=-funwind-tables
117   fi
118   AC_CACHE_CHECK([for -frandom-seed=string option],
119     [libbacktrace_cv_c_random_seed_string],
120     [CFLAGS_hold="$CFLAGS"
121      CFLAGS="$CFLAGS -frandom-seed=conftest.lo"
122      AC_COMPILE_IFELSE(
123        [AC_LANG_PROGRAM([], [return 0;])],
124        [libbacktrace_cv_c_random_seed_string=yes],
125        [libbacktrace_cv_c_random_seed_string=no])
126      CFLAGS="$CFLAGS_hold"])
127   if test "$libbacktrace_cv_c_random_seed_string" = "yes"; then
128     EXTRA_FLAGS="$EXTRA_FLAGS -frandom-seed=\$@"
129   fi
131 AC_SUBST(EXTRA_FLAGS)
133 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
134                           -Wmissing-prototypes -Wold-style-definition \
135                           -Wmissing-format-attribute -Wcast-qual],
136                           [WARN_FLAGS])
138 if test -n "${with_target_subdir}"; then
139   WARN_FLAGS="$WARN_FLAGS -Werror"
142 AC_SUBST(WARN_FLAGS)
144 if test -n "${with_target_subdir}"; then
145   GCC_CHECK_UNWIND_GETIPINFO
146 else
147   ac_save_CFFLAGS="$CFLAGS"
148   CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
149   AC_MSG_CHECKING([for _Unwind_GetIPInfo])
150   AC_LINK_IFELSE(
151     [AC_LANG_PROGRAM(
152        [#include "unwind.h"
153         struct _Unwind_Context *context;
154         int ip_before_insn = 0;],
155         [return _Unwind_GetIPInfo (context, &ip_before_insn);])],
156         [have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
157   CFLAGS="$ac_save_CFLAGS"
158   AC_MSG_RESULT([$have_unwind_getipinfo])
159   if test "$have_unwind_getipinfo" = "yes"; then
160     AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
161   fi
164 # When building as a target library, shared libraries may want to link
165 # this in.  We don't want to provide another shared library to
166 # complicate dependencies.  Instead, we just compile with -fPIC.
167 PIC_FLAG=
168 if test -n "${with_target_subdir}"; then
169   PIC_FLAG=-fPIC
171 # Similarly, use -fPIC with --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], [])
176 AC_SUBST(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
182    libbacktrace_cv_sys_sync=yes
183  else
184    AC_LINK_IFELSE(
185      [AC_LANG_PROGRAM([int i;],
186                       [__sync_bool_compare_and_swap (&i, i, i);
187                        __sync_lock_test_and_set (&i, 1);
188                        __sync_lock_release (&i);])],
189      [libbacktrace_cv_sys_sync=yes],
190      [libbacktrace_cv_sys_sync=no])
191  fi])
192 BACKTRACE_SUPPORTS_THREADS=0
193 if test "$libbacktrace_cv_sys_sync" = "yes"; then
194   BACKTRACE_SUPPORTS_THREADS=1
195   AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
196             [Define to 1 if you have the __sync functions])
198 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
200 # Test for __atomic support.
201 AC_CACHE_CHECK([__atomic extensions],
202 [libbacktrace_cv_sys_atomic],
203 [if test -n "${with_target_subdir}"; then
204    libbacktrace_cv_sys_atomic=yes
205  else
206    AC_LINK_IFELSE(
207      [AC_LANG_PROGRAM([int i;],
208                       [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
209                        __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
210      [libbacktrace_cv_sys_atomic=yes],
211      [libbacktrace_cv_sys_atomic=no])
212  fi])
213 if test "$libbacktrace_cv_sys_atomic" = "yes"; then
214   AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
215             [Define to 1 if you have the __atomic functions])
218 # The library needs to be able to read the executable itself.  Compile
219 # a file to determine the executable format.  The awk script
220 # filetype.awk prints out the file type.
221 AC_CACHE_CHECK([output filetype],
222 [libbacktrace_cv_sys_filetype],
223 [filetype=
224 AC_COMPILE_IFELSE(
225   [AC_LANG_PROGRAM([int i;], [int j;])],
226   [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
227   [AC_MSG_FAILURE([compiler failed])])
228 libbacktrace_cv_sys_filetype=$filetype])
230 # Match the file type to decide what files to compile.
231 FORMAT_FILE=
232 backtrace_supports_data=yes
233 case "$libbacktrace_cv_sys_filetype" in
234 elf*) FORMAT_FILE="elf.lo" ;;
235 pecoff) FORMAT_FILE="pecoff.lo"
236         backtrace_supports_data=no
237         ;;
238 *) AC_MSG_WARN([could not determine output file type])
239    FORMAT_FILE="unknown.lo"
240    backtrace_supported=no
241    ;;
242 esac
243 AC_SUBST(FORMAT_FILE)
245 # ELF defines.
246 elfsize=
247 case "$libbacktrace_cv_sys_filetype" in
248 elf32) elfsize=32 ;;
249 elf64) elfsize=64 ;;
250 *)     elfsize=unused
251 esac
252 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
254 BACKTRACE_SUPPORTED=0
255 if test "$backtrace_supported" = "yes"; then
256   BACKTRACE_SUPPORTED=1
258 AC_SUBST(BACKTRACE_SUPPORTED)
260 BACKTRACE_SUPPORTS_DATA=0
261 if test "$backtrace_supports_data" = "yes"; then
262   BACKTRACE_SUPPORTS_DATA=1
264 AC_SUBST(BACKTRACE_SUPPORTS_DATA)
266 GCC_HEADER_STDINT(gstdint.h)
268 AC_CHECK_HEADERS(sys/mman.h)
269 if test "$ac_cv_header_sys_mman_h" = "no"; then
270   have_mmap=no
271 else
272   if test -n "${with_target_subdir}"; then
273     # When built as a GCC target library, we can't do a link test.  We
274     # simply assume that if we have mman.h, we have mmap.
275     have_mmap=yes
276   else
277     AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
278   fi
280 if test "$have_mmap" = "no"; then
281   VIEW_FILE=read.lo
282   ALLOC_FILE=alloc.lo
283 else
284   VIEW_FILE=mmapio.lo
285   AC_PREPROC_IFELSE([
286 #include <sys/mman.h>
287 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
288   #error no MAP_ANONYMOUS
289 #endif
290 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
292 AC_SUBST(VIEW_FILE)
293 AC_SUBST(ALLOC_FILE)
295 BACKTRACE_USES_MALLOC=0
296 if test "$ALLOC_FILE" = "alloc.lo"; then
297   BACKTRACE_USES_MALLOC=1
299 AC_SUBST(BACKTRACE_USES_MALLOC)
301 # Check for dl_iterate_phdr.
302 AC_CHECK_HEADERS(link.h)
303 if test "$ac_cv_header_link_h" = "no"; then
304   have_dl_iterate_phdr=no
305 else
306   if test -n "${with_target_subdir}"; then
307     # When built as a GCC target library, we can't do a link test.
308     AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
309                     [have_dl_iterate_phdr=no])
310     case "${host}" in
311     *-*-solaris2.10*)
312         # Avoid dl_iterate_phdr on Solaris 10, where it is in the
313         # header file but is only in -ldl.
314         have_dl_iterate_phdr=no ;;
315     esac
316   else
317     AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
318                   [have_dl_iterate_phdr=no])
319   fi
321 if test "$have_dl_iterate_phdr" = "yes"; then
322   AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
325 # Check for the fcntl function.
326 if test -n "${with_target_subdir}"; then
327    case "${host}" in
328    *-*-mingw*) have_fcntl=no ;;
329    *) have_fcntl=yes ;;
330    esac
331 else
332   AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
334 if test "$have_fcntl" = "yes"; then
335   AC_DEFINE([HAVE_FCNTL], 1,
336             [Define to 1 if you have the fcntl function])
339 AC_CHECK_DECLS(strnlen)
341 # Check for getexecname function.
342 if test -n "${with_target_subdir}"; then
343    case "${host}" in
344    *-*-solaris2*) have_getexecname=yes ;;
345    *) have_getexecname=no ;;
346    esac
347 else
348   AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
350 if test "$have_getexecname" = "yes"; then
351   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
354 AC_CACHE_CHECK([whether tests can run],
355   [libbacktrace_cv_sys_native],
356   [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
357      [libbacktrace_cv_sys_native=yes],
358      [libbacktrace_cv_sys_native=no],
359      [libbacktrace_cv_sys_native=no])])
360 AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
362 if test "${multilib}" = "yes"; then
363   multilib_arg="--enable-multilib"
364 else
365   multilib_arg=
368 AC_CONFIG_FILES(Makefile backtrace-supported.h)
370 # We need multilib support, but only if configuring for the target.
371 AC_CONFIG_COMMANDS([default],
372 [if test -n "$CONFIG_FILES"; then
373    if test -n "${with_target_subdir}"; then
374      # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
375      # that multilib installs will end up installed in the correct place.
376      # The testsuite needs it for multilib-aware ABI baseline files.
377      # To work around this not being passed down from config-ml.in ->
378      # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
379      # append it here.  Only modify Makefiles that have just been created.
380      #
381      # Also, get rid of this simulated-VPATH thing that automake does.
382      cat > vpsed << \_EOF
383   s!`test -f '$<' || echo '$(srcdir)/'`!!
384 _EOF
385      for i in $SUBDIRS; do
386       case $CONFIG_FILES in
387        *${i}/Makefile*)
388          #echo "Adding MULTISUBDIR to $i/Makefile"
389          sed -f vpsed $i/Makefile > tmp
390          grep '^MULTISUBDIR =' Makefile >> tmp
391          mv tmp $i/Makefile
392          ;;
393       esac
394      done
395      rm vpsed
396    fi
397  fi
400 # Variables needed in config.status (file generation) which aren't already
401 # passed by autoconf.
402 SUBDIRS="$SUBDIRS"
405 AC_OUTPUT