configure.tgt (i[3456]86): Handle -mx32 like -m64.
[official-gcc.git] / libbacktrace / configure.ac
blob243ce22582f74f6880c606d765e3f600bec1b32c
1 # configure.ac -- Backtrace configure script.
2 # Copyright (C) 2012 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 AC_CANONICAL_SYSTEM
38 target_alias=${target_alias-$host_alias}
40 AC_USE_SYSTEM_EXTENSIONS
42 libtool_VERSION=1:0:0
43 AC_SUBST(libtool_VERSION)
45 # 1.11.1: Require that version of automake.
46 # foreign: Don't require README, INSTALL, NEWS, etc.
47 # no-define: Don't define PACKAGE and VERSION.
48 # no-dependencies: Don't generate automatic dependencies.
49 #    (because it breaks when using bootstrap-lean, since some of the
50 #    headers are gone at "make install" time).
51 # -Wall: Issue all automake warnings.
52 # -Wno-portability: Don't warn about constructs supported by GNU make.
53 #    (because GCC requires GNU make anyhow).
54 AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
56 AM_MAINTAINER_MODE
58 AC_ARG_WITH(target-subdir,
59 [  --with-target-subdir=SUBDIR      Configuring in a subdirectory for target])
61 # We must force CC to /not/ be precious variables; otherwise
62 # the wrong, non-multilib-adjusted value will be used in multilibs.
63 # As a side effect, we have to subst CFLAGS ourselves.
64 m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
65 m4_define([_AC_ARG_VAR_PRECIOUS],[])
66 AC_PROG_CC
67 m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
69 AC_SUBST(CFLAGS)
71 AC_PROG_RANLIB
73 AC_PROG_AWK
74 case "$AWK" in
75 "") AC_MSG_ERROR([can't build without awk]) ;;
76 esac
78 LT_INIT([disable-shared])
79 AM_PROG_LIBTOOL
81 backtrace_supported=yes
83 if test -n "${with_target_subdir}"; then
84   # We are compiling a GCC library.  We can assume that the unwind
85   # library exists.
86   AM_ENABLE_MULTILIB(, ..)
87   BACKTRACE_FILE="backtrace.lo simple.lo"
88 else
89   AC_CHECK_HEADER([unwind.h],
90     [AC_CHECK_FUNC([_Unwind_Backtrace],
91                    [BACKTRACE_FILE="backtrace.lo simple.lo"],
92                    [BACKTRACE_FILE="nounwind.lo"
93                     backtrace_supported=no])],
94     [BACKTRACE_FILE="nounwind.lo"
95      backtrace_supported=no])
97 AC_SUBST(BACKTRACE_FILE)
99 EXTRA_FLAGS=
100 if test -n "${with_target_subdir}"; then
101   EXTRA_FLAGS=-funwind-tables
102 else
103   AC_CACHE_CHECK([for -funwind-tables option],
104     [libbacktrace_cv_c_unwind_tables],
105     [CFLAGS_hold="$CFLAGS"
106      CFLAGS="$CFLAGS -funwind-tables"
107      AC_COMPILE_IFELSE(
108        [AC_LANG_PROGRAM([static int f() { return 0; }], [return f();])],
109        [libbacktrace_cv_c_unwind_tables=yes],
110        [libbacktrace_cv_c_unwind_tables=no])
111      CFLAGS="$CFLAGS_hold"])
112    if test "$libbacktrace_cv_c_unwind_tables" = "yes"; then
113      EXTRA_FLAGS=-funwind-tables
114    fi
116 AC_SUBST(EXTRA_FLAGS)
118 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
119                           -Wmissing-prototypes -Wold-style-definition \
120                           -Wmissing-format-attribute -Wcast-qual],
121                           [WARN_FLAGS])
123 if test -n "${with_target_subdir}"; then
124   WARN_FLAGS="$WARN_FLAGS -Werror"
127 AC_SUBST(WARN_FLAGS)
129 if test -n "${with_target_subdir}"; then
130   GCC_CHECK_UNWIND_GETIPINFO
131 else
132   ac_save_CFFLAGS="$CFLAGS"
133   CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
134   AC_MSG_CHECKING([for _Unwind_GetIPInfo])
135   AC_COMPILE_IFELSE(
136     [AC_LANG_PROGRAM(
137        [#include "unwind.h"
138         struct _Unwind_Context *context;
139         int ip_before_insn = 0;],
140         [return _Unwind_GetIPInfo (context, &ip_before_insn);])],
141         [have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
142   CFLAGS="$ac_save_CFLAGS"
143   AC_MSG_RESULT([$have_unwind_getipinfo])
144   if test "$have_unwind_getipinfo" = "yes"; then
145     AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
146   fi
149 # When building as a target library, shared libraries may want to link
150 # this in.  We don't want to provide another shared library to
151 # complicate dependencies.  Instead, we just compile with -fPIC.
152 PIC_FLAG=
153 if test -n "${with_target_subdir}"; then
154   PIC_FLAG=-fPIC
156 AC_SUBST(PIC_FLAG)
158 # Test for __sync support.
159 AC_CACHE_CHECK([__sync extensions],
160 [libbacktrace_cv_sys_sync],
161 [if test -n "${with_target_subdir}"; then
162    libbacktrace_cv_sys_sync=yes
163  else
164    AC_LINK_IFELSE(
165      [AC_LANG_PROGRAM([int i;],
166                       [__sync_bool_compare_and_swap (&i, i, i);
167                        __sync_lock_test_and_set (&i, 1);
168                        __sync_lock_release (&i);])],
169      [libbacktrace_cv_sys_sync=yes],
170      [libbacktrace_cv_sys_sync=no])
171  fi])
172 BACKTRACE_SUPPORTS_THREADS=0
173 if test "$libbacktrace_cv_sys_sync" = "yes"; then
174   BACKTRACE_SUPPORTS_THREADS=1
175   AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
176             [Define to 1 if you have the __sync functions])
178 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
180 # The library needs to be able to read the executable itself.  Compile
181 # a file to determine the executable format.  The awk script
182 # filetype.awk prints out the file type.
183 AC_CACHE_CHECK([output filetype],
184 [libbacktrace_cv_sys_filetype],
185 [filetype=
186 AC_COMPILE_IFELSE(
187   [AC_LANG_PROGRAM([int i;], [int j;])],
188   [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
189   [AC_MSG_FAILURE([compiler failed])])
190 libbacktrace_cv_sys_filetype=$filetype])
192 # Match the file type to decide what files to compile.
193 FORMAT_FILE=
194 case "$libbacktrace_cv_sys_filetype" in
195 elf*) FORMAT_FILE="elf.lo" ;;
196 *) AC_MSG_WARN([could not determine output file type])
197    FORMAT_FILE="unknown.lo"
198    backtrace_supported=no
199    ;;
200 esac
201 AC_SUBST(FORMAT_FILE)
203 # ELF defines.
204 elfsize=
205 case "$libbacktrace_cv_sys_filetype" in
206 elf32) elfsize=32 ;;
207 elf64) elfsize=64 ;;
208 esac
209 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
211 BACKTRACE_SUPPORTED=0
212 if test "$backtrace_supported" = "yes"; then
213   BACKTRACE_SUPPORTED=1
215 AC_SUBST(BACKTRACE_SUPPORTED)
217 GCC_HEADER_STDINT(gstdint.h)
219 AC_CHECK_HEADERS(sys/mman.h)
220 if test "$ac_cv_header_sys_mman_h" = "no"; then
221   have_mmap=no
222 else
223   if test -n "${with_target_subdir}"; then
224     # When built as a GCC target library, we can't do a link test.  We
225     # simply assume that if we have mman.h, we have mmap.
226     have_mmap=yes
227   else
228     AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
229   fi
231 if test "$have_mmap" = "no"; then
232   VIEW_FILE=read.lo
233   ALLOC_FILE=alloc.lo
234 else
235   VIEW_FILE=mmapio.lo
236   AC_PREPROC_IFELSE([
237 #include <sys/mman.h>
238 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
239   #error no MAP_ANONYMOUS
240 #endif
241 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
243 AC_SUBST(VIEW_FILE)
244 AC_SUBST(ALLOC_FILE)
246 BACKTRACE_USES_MALLOC=0
247 if test "$ALLOC_FILE" = "alloc.lo"; then
248   BACKTRACE_USES_MALLOC=1
250 AC_SUBST(BACKTRACE_USES_MALLOC)
252 # Check for dl_iterate_phdr.
253 AC_CHECK_HEADERS(link.h)
254 if test "$ac_cv_header_link_h" = "no"; then
255   have_dl_iterate_phdr=no
256 else
257   if test -n "${with_target_subdir}"; then
258     # When built as a GCC target library, we can't do a link test.
259     AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
260                     [have_dl_iterate_phdr=no])
261     case "${host}" in
262     *-*-solaris2.10*)
263         # Avoid dl_iterate_phdr on Solaris 10, where it is in the
264         # header file but is only in -ldl.
265         have_dl_iterate_phdr=no ;;
266     esac
267   else
268     AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
269                   [have_dl_iterate_phdr=no])
270   fi
272 if test "$have_dl_iterate_phdr" = "yes"; then
273   AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
276 # Check for the fcntl function.
277 if test -n "${with_target_subdir}"; then
278    case "${host}" in
279    *-*-mingw*) have_fcntl=no ;;
280    *) have_fcntl=yes ;;
281    esac
282 else
283   AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
285 if test "$have_fcntl" = "yes"; then
286   AC_DEFINE([HAVE_FCNTL], 1,
287             [Define to 1 if you have the fcntl function])
290 AC_CHECK_DECLS(strnlen)
292 # Check for getexecname function.
293 if test -n "${with_target_subdir}"; then
294    case "${host}" in
295    *-*-solaris2*) have_getexecname=yes ;;
296    *) have_getexecname=no ;;
297    esac
298 else
299   AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
301 if test "$have_getexecname" = "yes"; then
302   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
305 AC_CACHE_CHECK([whether tests can run],
306   [libbacktrace_cv_sys_native],
307   [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
308      [libbacktrace_cv_sys_native=yes],
309      [libbacktrace_cv_sys_native=no],
310      [libbacktrace_cv_sys_native=no])])
311 AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
313 if test "${multilib}" = "yes"; then
314   multilib_arg="--enable-multilib"
315 else
316   multilib_arg=
319 AC_CONFIG_FILES(Makefile backtrace-supported.h)
321 # We need multilib support, but only if configuring for the target.
322 AC_CONFIG_COMMANDS([default],
323 [if test -n "$CONFIG_FILES"; then
324    if test -n "${with_target_subdir}"; then
325      # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
326      # that multilib installs will end up installed in the correct place.
327      # The testsuite needs it for multilib-aware ABI baseline files.
328      # To work around this not being passed down from config-ml.in ->
329      # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
330      # append it here.  Only modify Makefiles that have just been created.
331      #
332      # Also, get rid of this simulated-VPATH thing that automake does.
333      cat > vpsed << \_EOF
334   s!`test -f '$<' || echo '$(srcdir)/'`!!
335 _EOF
336      for i in $SUBDIRS; do
337       case $CONFIG_FILES in
338        *${i}/Makefile*)
339          #echo "Adding MULTISUBDIR to $i/Makefile"
340          sed -f vpsed $i/Makefile > tmp
341          grep '^MULTISUBDIR =' Makefile >> tmp
342          mv tmp $i/Makefile
343          ;;
344       esac
345      done
346      rm vpsed
347    fi
348  fi
351 # Variables needed in config.status (file generation) which aren't already
352 # passed by autoconf.
353 SUBDIRS="$SUBDIRS"
356 AC_OUTPUT