1# configure.ac -- Backtrace configure script.
2# Copyright (C) 2012-2016 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
37# with_target_subdir is used when configured as part of a GCC tree.
38if test -n "${with_target_subdir}"; then
39  AM_ENABLE_MULTILIB(, ..)
40fi
41
42AC_CANONICAL_SYSTEM
43target_alias=${target_alias-$host_alias}
44
45AC_USE_SYSTEM_EXTENSIONS
46
47libtool_VERSION=1:0:0
48AC_SUBST(libtool_VERSION)
49
50# 1.11.1: Require that version of automake.
51# foreign: Don't require README, INSTALL, NEWS, etc.
52# no-define: Don't define PACKAGE and VERSION.
53# no-dependencies: Don't generate automatic dependencies.
54#    (because it breaks when using bootstrap-lean, since some of the
55#    headers are gone at "make install" time).
56# -Wall: Issue all automake warnings.
57# -Wno-portability: Don't warn about constructs supported by GNU make.
58#    (because GCC requires GNU make anyhow).
59AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
60
61AM_MAINTAINER_MODE
62
63AC_ARG_WITH(target-subdir,
64[  --with-target-subdir=SUBDIR      Configuring in a subdirectory for target])
65
66# We must force CC to /not/ be precious variables; otherwise
67# the wrong, non-multilib-adjusted value will be used in multilibs.
68# As a side effect, we have to subst CFLAGS ourselves.
69m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
70m4_define([_AC_ARG_VAR_PRECIOUS],[])
71AC_PROG_CC
72m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
73
74AC_SUBST(CFLAGS)
75
76AC_PROG_RANLIB
77
78AC_PROG_AWK
79case "$AWK" in
80"") AC_MSG_ERROR([can't build without awk]) ;;
81esac
82
83LT_INIT
84AM_PROG_LIBTOOL
85
86backtrace_supported=yes
87
88if test -n "${with_target_subdir}"; then
89  # We are compiling a GCC library.  We can assume that the unwind
90  # library exists.
91  BACKTRACE_FILE="backtrace.lo simple.lo"
92else
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])
100fi
101AC_SUBST(BACKTRACE_FILE)
102
103EXTRA_FLAGS=
104if test -n "${with_target_subdir}"; then
105  EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
106else
107  AC_CACHE_CHECK([for -funwind-tables option],
108    [libbacktrace_cv_c_unwind_tables],
109    [CFLAGS_hold="$CFLAGS"
110     CFLAGS="$CFLAGS -funwind-tables"
111     AC_COMPILE_IFELSE(
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
118  fi
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"
123     AC_COMPILE_IFELSE(
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=\$@"
130  fi
131fi
132AC_SUBST(EXTRA_FLAGS)
133
134ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
135			  -Wmissing-prototypes -Wold-style-definition \
136			  -Wmissing-format-attribute -Wcast-qual],
137			  [WARN_FLAGS])
138
139if test -n "${with_target_subdir}"; then
140  WARN_FLAGS="$WARN_FLAGS -Werror"
141fi
142
143AC_SUBST(WARN_FLAGS)
144
145if test -n "${with_target_subdir}"; then
146  GCC_CHECK_UNWIND_GETIPINFO
147else
148  ac_save_CFFLAGS="$CFLAGS"
149  CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
150  AC_MSG_CHECKING([for _Unwind_GetIPInfo])
151  AC_LINK_IFELSE(
152    [AC_LANG_PROGRAM(
153       [#include "unwind.h"
154	struct _Unwind_Context *context;
155	int ip_before_insn = 0;],
156	[return _Unwind_GetIPInfo (context, &ip_before_insn);])],
157	[have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
158  CFLAGS="$ac_save_CFLAGS"
159  AC_MSG_RESULT([$have_unwind_getipinfo])
160  if test "$have_unwind_getipinfo" = "yes"; then
161    AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
162  fi
163fi
164
165# Enable --enable-host-shared.
166AC_ARG_ENABLE(host-shared,
167[AS_HELP_STRING([--enable-host-shared],
168		[build host code as shared libraries])],
169[PIC_FLAG=-fPIC], [PIC_FLAG=])
170AC_SUBST(PIC_FLAG)
171
172# Test for __sync support.
173AC_CACHE_CHECK([__sync extensions],
174[libbacktrace_cv_sys_sync],
175[if test -n "${with_target_subdir}"; then
176   case "${host}" in
177   hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
178   *) libbacktrace_cv_sys_sync=yes ;;
179   esac
180 else
181   AC_LINK_IFELSE(
182     [AC_LANG_PROGRAM([int i;],
183                      [__sync_bool_compare_and_swap (&i, i, i);
184                       __sync_lock_test_and_set (&i, 1);
185                       __sync_lock_release (&i);])],
186     [libbacktrace_cv_sys_sync=yes],
187     [libbacktrace_cv_sys_sync=no])
188 fi])
189BACKTRACE_SUPPORTS_THREADS=0
190if test "$libbacktrace_cv_sys_sync" = "yes"; then
191  BACKTRACE_SUPPORTS_THREADS=1
192  AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
193	    [Define to 1 if you have the __sync functions])
194fi
195AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
196
197# Test for __atomic support.
198AC_CACHE_CHECK([__atomic extensions],
199[libbacktrace_cv_sys_atomic],
200[if test -n "${with_target_subdir}"; then
201   libbacktrace_cv_sys_atomic=yes
202 else
203   AC_LINK_IFELSE(
204     [AC_LANG_PROGRAM([int i;],
205     		      [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
206		       __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
207     [libbacktrace_cv_sys_atomic=yes],
208     [libbacktrace_cv_sys_atomic=no])
209 fi])
210if test "$libbacktrace_cv_sys_atomic" = "yes"; then
211  AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
212	    [Define to 1 if you have the __atomic functions])
213fi
214
215# The library needs to be able to read the executable itself.  Compile
216# a file to determine the executable format.  The awk script
217# filetype.awk prints out the file type.
218AC_CACHE_CHECK([output filetype],
219[libbacktrace_cv_sys_filetype],
220[filetype=
221AC_COMPILE_IFELSE(
222  [AC_LANG_PROGRAM([int i;], [int j;])],
223  [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
224  [AC_MSG_FAILURE([compiler failed])])
225libbacktrace_cv_sys_filetype=$filetype])
226
227# Match the file type to decide what files to compile.
228FORMAT_FILE=
229backtrace_supports_data=yes
230case "$libbacktrace_cv_sys_filetype" in
231elf*) FORMAT_FILE="elf.lo" ;;
232pecoff) FORMAT_FILE="pecoff.lo"
233        backtrace_supports_data=no
234	;;
235*) AC_MSG_WARN([could not determine output file type])
236   FORMAT_FILE="unknown.lo"
237   backtrace_supported=no
238   ;;
239esac
240AC_SUBST(FORMAT_FILE)
241
242# ELF defines.
243elfsize=
244case "$libbacktrace_cv_sys_filetype" in
245elf32) elfsize=32 ;;
246elf64) elfsize=64 ;;
247*)     elfsize=unused
248esac
249AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
250
251BACKTRACE_SUPPORTED=0
252if test "$backtrace_supported" = "yes"; then
253  BACKTRACE_SUPPORTED=1
254fi
255AC_SUBST(BACKTRACE_SUPPORTED)
256
257BACKTRACE_SUPPORTS_DATA=0
258if test "$backtrace_supports_data" = "yes"; then
259  BACKTRACE_SUPPORTS_DATA=1
260fi
261AC_SUBST(BACKTRACE_SUPPORTS_DATA)
262
263AC_CHECK_HEADERS(sys/mman.h)
264if test "$ac_cv_header_sys_mman_h" = "no"; then
265  have_mmap=no
266else
267  if test -n "${with_target_subdir}"; then
268    # When built as a GCC target library, we can't do a link test.  We
269    # simply assume that if we have mman.h, we have mmap.
270    have_mmap=yes
271    case "${host}" in
272    spu-*-*|*-*-msdosdjgpp)
273        # The SPU does not have mmap, but it has a sys/mman.h header file
274        # containing "mmap_eaddr" and the mmap flags, confusing the test.
275        # DJGPP also has sys/man.h, but no mmap
276	have_mmap=no ;;
277    esac
278  else
279    AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
280  fi
281fi
282if test "$have_mmap" = "no"; then
283  VIEW_FILE=read.lo
284  ALLOC_FILE=alloc.lo
285else
286  VIEW_FILE=mmapio.lo
287  AC_PREPROC_IFELSE([
288#include <sys/mman.h>
289#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
290  #error no MAP_ANONYMOUS
291#endif
292], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
293fi
294AC_SUBST(VIEW_FILE)
295AC_SUBST(ALLOC_FILE)
296
297BACKTRACE_USES_MALLOC=0
298if test "$ALLOC_FILE" = "alloc.lo"; then
299  BACKTRACE_USES_MALLOC=1
300fi
301AC_SUBST(BACKTRACE_USES_MALLOC)
302
303# Check for dl_iterate_phdr.
304AC_CHECK_HEADERS(link.h)
305if test "$ac_cv_header_link_h" = "no"; then
306  have_dl_iterate_phdr=no
307else
308  if test -n "${with_target_subdir}"; then
309    # When built as a GCC target library, we can't do a link test.
310    AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
311		    [have_dl_iterate_phdr=no])
312    case "${host}" in
313    *-*-solaris2.10*)
314        # Avoid dl_iterate_phdr on Solaris 10, where it is in the
315    	# header file but is only in -ldl.
316	have_dl_iterate_phdr=no ;;
317    esac
318  else
319    AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
320		  [have_dl_iterate_phdr=no])
321  fi
322fi
323if test "$have_dl_iterate_phdr" = "yes"; then
324  AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
325fi
326
327# Check for the fcntl function.
328if test -n "${with_target_subdir}"; then
329   case "${host}" in
330   *-*-mingw*) have_fcntl=no ;;
331   spu-*-*) have_fcntl=no ;;
332   *) have_fcntl=yes ;;
333   esac
334else
335  AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
336fi
337if test "$have_fcntl" = "yes"; then
338  AC_DEFINE([HAVE_FCNTL], 1,
339	    [Define to 1 if you have the fcntl function])
340fi
341
342AC_CHECK_DECLS(strnlen)
343
344# Check for getexecname function.
345if test -n "${with_target_subdir}"; then
346   case "${host}" in
347   *-*-solaris2*) have_getexecname=yes ;;
348   *) have_getexecname=no ;;
349   esac
350else
351  AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
352fi
353if test "$have_getexecname" = "yes"; then
354  AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
355fi
356
357AC_CACHE_CHECK([whether tests can run],
358  [libbacktrace_cv_sys_native],
359  [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
360     [libbacktrace_cv_sys_native=yes],
361     [libbacktrace_cv_sys_native=no],
362     [libbacktrace_cv_sys_native=no])])
363AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
364
365if test "${multilib}" = "yes"; then
366  multilib_arg="--enable-multilib"
367else
368  multilib_arg=
369fi
370
371AC_CONFIG_FILES(Makefile backtrace-supported.h)
372
373# We need multilib support, but only if configuring for the target.
374AC_CONFIG_COMMANDS([default],
375[if test -n "$CONFIG_FILES"; then
376   if test -n "${with_target_subdir}"; then
377     # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
378     # that multilib installs will end up installed in the correct place.
379     # The testsuite needs it for multilib-aware ABI baseline files.
380     # To work around this not being passed down from config-ml.in ->
381     # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
382     # append it here.  Only modify Makefiles that have just been created.
383     #
384     # Also, get rid of this simulated-VPATH thing that automake does.
385     cat > vpsed << \_EOF
386  s!`test -f '$<' || echo '$(srcdir)/'`!!
387_EOF
388     for i in $SUBDIRS; do
389      case $CONFIG_FILES in
390       *${i}/Makefile*)
391	 #echo "Adding MULTISUBDIR to $i/Makefile"
392	 sed -f vpsed $i/Makefile > tmp
393	 grep '^MULTISUBDIR =' Makefile >> tmp
394	 mv tmp $i/Makefile
395	 ;;
396      esac
397     done
398     rm vpsed
399   fi
400 fi
401],
402[
403# Variables needed in config.status (file generation) which aren't already
404# passed by autoconf.
405SUBDIRS="$SUBDIRS"
406])
407
408AC_OUTPUT
409