blob: b21beea11b02efceb7b8b8628e5fa17d063adf23 [file] [log] [blame]
Bernhard Rosenkraenzer84c11392012-09-27 01:39:09 +01591# configure.ac -- Backtrace configure script.
2# Copyright (C) 2012 Free Software Foundation, Inc.
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
9# notice, this list of conditions and the following disclaimer.
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
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.
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)
36
37AC_CANONICAL_SYSTEM
38target_alias=${target_alias-$host_alias}
39
40AC_USE_SYSTEM_EXTENSIONS
41
42libtool_VERSION=1:0:0
43AC_SUBST(libtool_VERSION)
44
45AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define -Wall -Wno-portability])
46
47AM_MAINTAINER_MODE
48
49AC_ARG_WITH(target-subdir,
50[ --with-target-subdir=SUBDIR Configuring in a subdirectory for target])
51
52# We must force CC to /not/ be precious variables; otherwise
53# the wrong, non-multilib-adjusted value will be used in multilibs.
54# As a side effect, we have to subst CFLAGS ourselves.
55m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
56m4_define([_AC_ARG_VAR_PRECIOUS],[])
57AC_PROG_CC
58m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
59
60AC_SUBST(CFLAGS)
61
62AC_PROG_RANLIB
63
64AC_PROG_AWK
65case "$AWK" in
66"") AC_MSG_ERROR([can't build without awk]) ;;
67esac
68
69LT_INIT([disable-shared])
70AM_PROG_LIBTOOL
71
72backtrace_supported=yes
73
74if test -n "${with_target_subdir}"; then
75 # We are compiling a GCC library. We can assume that the unwind
76 # library exists.
77 AM_ENABLE_MULTILIB(, ..)
78 BACKTRACE_FILE="backtrace.lo simple.lo"
79else
80 AC_CHECK_HEADER([unwind.h],
81 [AC_CHECK_FUNC([_Unwind_Backtrace],
82 [BACKTRACE_FILE="backtrace.lo simple.lo"],
83 [BACKTRACE_FILE="nounwind.lo"
84 backtrace_supported=no])],
85 [BACKTRACE_FILE="nounwind.lo"
86 backtrace_supported=no])
87fi
88AC_SUBST(BACKTRACE_FILE)
89
90ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
91 -Wmissing-prototypes -Wold-style-definition \
92 -Wmissing-format-attribute -Wcast-qual],
93 [WARN_FLAGS])
94
95if test "x$GCC" = "xyes"; then
96 WARN_FLAGS="$WARN_FLAGS -Werror"
97fi
98
99AC_SUBST(WARN_FLAGS)
100
101if test -n "${with_target_subdir}"; then
102 GCC_CHECK_UNWIND_GETIPINFO
103else
104 AC_CHECK_FUNC(_Unwind_GetIPInfo, [have_unwind_getipinfo=yes],
105 [have_unwind_getipinfo=no])
106 if test "$have_unwind_getipinfo" = "yes"; then
107 AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
108 fi
109fi
110
111# When building as a target library, shared libraries may want to link
112# this in. We don't want to provide another shared library to
113# complicate dependencies. Instead, we just compile with -fPIC.
114PIC_FLAG=
115if test -n "${with_target_subdir}"; then
116 PIC_FLAG=-fPIC
117fi
118AC_SUBST(PIC_FLAG)
119
120# Test for __sync support.
121AC_CACHE_CHECK([__sync extensions],
122[libbacktrace_cv_sys_sync],
123[if test -n "${with_target_subdir}"; then
124 libbacktrace_cv_sys_sync=yes
125 else
126 AC_LINK_IFELSE(
127 [AC_LANG_PROGRAM([int i;],
128 [__sync_bool_compare_and_swap (&i, i, i);
129 __sync_lock_test_and_set (&i, 1);
130 __sync_lock_release (&i);])],
131 [libbacktrace_cv_sys_sync=yes],
132 [libbacktrace_cv_sys_sync=no])
133 fi])
134BACKTRACE_SUPPORTS_THREADS=0
135if test "$libbacktrace_cv_sys_sync" = "yes"; then
136 BACKTRACE_SUPPORTS_THREADS=1
137 AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
138 [Define to 1 if you have the __sync functions])
139fi
140AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
141
142# The library needs to be able to read the executable itself. Compile
143# a file to determine the executable format. The awk script
144# filetype.awk prints out the file type.
145AC_CACHE_CHECK([output filetype],
146[libbacktrace_cv_sys_filetype],
147[filetype=
148AC_COMPILE_IFELSE(
149 [AC_LANG_PROGRAM([int i;], [int j;])],
150 [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
151 [AC_MSG_FAILURE([compiler failed])])
152libbacktrace_cv_sys_filetype=$filetype])
153
154# Match the file type to decide what files to compile.
155FORMAT_FILE=
156case "$libbacktrace_cv_sys_filetype" in
157elf*) FORMAT_FILE="elf.lo" ;;
158*) AC_MSG_WARN([could not determine output file type])
159 FORMAT_FILE="unknown.lo"
160 backtrace_supported=no
161 ;;
162esac
163AC_SUBST(FORMAT_FILE)
164
165# ELF defines.
166elfsize=
167case "$libbacktrace_cv_sys_filetype" in
168elf32) elfsize=32 ;;
169elf64) elfsize=64 ;;
170esac
171AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
172
173BACKTRACE_SUPPORTED=0
174if test "$backtrace_supported" = "yes"; then
175 BACKTRACE_SUPPORTED=1
176fi
177AC_SUBST(BACKTRACE_SUPPORTED)
178
179GCC_HEADER_STDINT(gstdint.h)
180
181AC_CHECK_HEADERS(sys/mman.h)
182if test "$ac_cv_header_sys_mman_h" = "no"; then
183 have_mmap=no
184else
185 if test -n "${with_target_subdir}"; then
186 # When built as a GCC target library, we can't do a link test. We
187 # simply assume that if we have mman.h, we have mmap.
188 have_mmap=yes
189 else
190 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
191 fi
192fi
193if test "$have_mmap" = "no"; then
194 VIEW_FILE=read.lo
195 ALLOC_FILE=alloc.lo
196else
197 VIEW_FILE=mmapio.lo
198 AC_PREPROC_IFELSE([
199#include <sys/mman.h>
200#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
201 #error no MAP_ANONYMOUS
202#endif
203], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
204fi
205AC_SUBST(VIEW_FILE)
206AC_SUBST(ALLOC_FILE)
207
208BACKTRACE_USES_MALLOC=0
209if test "$ALLOC_FILE" = "alloc.lo"; then
210 BACKTRACE_USES_MALLOC=1
211fi
212AC_SUBST(BACKTRACE_USES_MALLOC)
213
214# Check for the fcntl function.
215if test -n "${with_target_subdir}"; then
216 case "${host}" in
217 *-*-mingw*) have_fcntl=no ;;
218 *) have_fcntl=yes ;;
219 esac
220else
221 AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
222fi
223if test "$have_fcntl" = "yes"; then
224 AC_DEFINE([HAVE_FCNTL], 1,
225 [Define to 1 if you have the fcntl function])
226fi
227
228AC_CHECK_DECLS(strnlen)
229
230AC_CACHE_CHECK([whether tests can run],
231 [libbacktrace_cv_sys_native],
232 [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
233 [libbacktrace_cv_sys_native=yes],
234 [libbacktrace_cv_sys_native=no],
235 [libbacktrace_cv_sys_native=no])])
236AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
237
238if test "${multilib}" = "yes"; then
239 multilib_arg="--enable-multilib"
240else
241 multilib_arg=
242fi
243
244AC_CONFIG_FILES(Makefile backtrace-supported.h)
245
246# We need multilib support, but only if configuring for the target.
247AC_CONFIG_COMMANDS([default],
248[if test -n "$CONFIG_FILES"; then
249 if test -n "${with_target_subdir}"; then
250 # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
251 # that multilib installs will end up installed in the correct place.
252 # The testsuite needs it for multilib-aware ABI baseline files.
253 # To work around this not being passed down from config-ml.in ->
254 # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
255 # append it here. Only modify Makefiles that have just been created.
256 #
257 # Also, get rid of this simulated-VPATH thing that automake does.
258 cat > vpsed << \_EOF
259 s!`test -f '$<' || echo '$(srcdir)/'`!!
260_EOF
261 for i in $SUBDIRS; do
262 case $CONFIG_FILES in
263 *${i}/Makefile*)
264 #echo "Adding MULTISUBDIR to $i/Makefile"
265 sed -f vpsed $i/Makefile > tmp
266 grep '^MULTISUBDIR =' Makefile >> tmp
267 mv tmp $i/Makefile
268 ;;
269 esac
270 done
271 rm vpsed
272 fi
273 fi
274],
275[
276# Variables needed in config.status (file generation) which aren't already
277# passed by autoconf.
278SUBDIRS="$SUBDIRS"
279])
280
281AC_OUTPUT