configure.ac: Move AM_ENABLE_MULTILIB before AC_PROG_CC.
[official-gcc.git] / libsanitizer / configure.ac
blob031c2710a82f6e7d35275b49410ff731f17c425d
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
4 AC_PREREQ([2.64])
5 AC_INIT(package-unused, version-unused, libsanitizer)
6 AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
8 AM_ENABLE_MULTILIB(, ..)
10 AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
11 AC_ARG_ENABLE(version-specific-runtime-libs,
12 [  --enable-version-specific-runtime-libs    Specify that runtime libraries should be installed in a compiler-specific directory ],
13 [case "$enableval" in
14  yes) version_specific_libs=yes ;;
15  no)  version_specific_libs=no ;;
16  *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
17  esac],
18 [version_specific_libs=no])
19 AC_MSG_RESULT($version_specific_libs)
21 AC_USE_SYSTEM_EXTENSIONS
23 # Do not delete or change the following two lines.  For why, see
24 # http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
25 AC_CANONICAL_SYSTEM
26 target_alias=${target_alias-$host_alias}
27 AC_SUBST(target_alias)
28 GCC_LIBSTDCXX_RAW_CXX_FLAGS
30 AM_INIT_AUTOMAKE(foreign no-dist)
31 AM_MAINTAINER_MODE
33 # Calculate toolexeclibdir
34 # Also toolexecdir, though it's only used in toolexeclibdir
35 case ${version_specific_libs} in
36   yes)
37     # Need the gcc compiler version to know where to install libraries
38     # and header files if --enable-version-specific-runtime-libs option
39     # is selected.
40     toolexecdir='$(libdir)/gcc/$(target_alias)'
41     toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
42     ;;
43   no)
44     if test -n "$with_cross_host" &&
45        test x"$with_cross_host" != x"no"; then
46       # Install a library built with a cross compiler in tooldir, not libdir.
47       toolexecdir='$(exec_prefix)/$(target_alias)'
48       toolexeclibdir='$(toolexecdir)/lib'
49     else
50       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
51       toolexeclibdir='$(libdir)'
52     fi
53     multi_os_directory=`$CC -print-multi-os-directory`
54     case $multi_os_directory in
55       .) ;; # Avoid trailing /.
56       *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
57     esac
58     ;;
59 esac
60 AC_SUBST(toolexecdir)
61 AC_SUBST(toolexeclibdir)
63 # Checks for programs.
64 AC_PROG_CC
65 AC_PROG_CXX
66 AM_PROG_AS
67 AC_PROG_RANLIB
69 AC_LIBTOOL_DLOPEN
70 AM_PROG_LIBTOOL
72 AC_PROG_AWK
73 case "$AWK" in
74 "") AC_MSG_ERROR([can't build without awk]) ;;
75 esac
77 AC_SUBST(enable_shared)
78 AC_SUBST(enable_static)
80 AC_CHECK_SIZEOF([void *])
82 if test "${multilib}" = "yes"; then
83   multilib_arg="--enable-multilib"
84 else
85   multilib_arg=
88 # Get target configury.
89 unset TSAN_SUPPORTED
90 unset LSAN_SUPPORTED
91 . ${srcdir}/configure.tgt
92 AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
93 AM_CONDITIONAL(LSAN_SUPPORTED, [test "x$LSAN_SUPPORTED" = "xyes"])
95 # Check for functions needed.
96 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
98 # Common libraries that we need to link against for all sanitizer libs.
99 link_sanitizer_common='-lpthread -ldl -lm'
101 # Set up the set of additional libraries that we need to link against for libasan.
102 link_libasan=$link_sanitizer_common
103 AC_SUBST(link_libasan)
105 # Set up the set of additional libraries that we need to link against for libtsan.
106 link_libtsan=$link_sanitizer_common
107 AC_SUBST(link_libtsan)
109 # Set up the set of additional libraries that we need to link against for libubsan.
110 link_libubsan=$link_sanitizer_common
111 AC_SUBST(link_libubsan)
113 # Set up the set of additional libraries that we need to link against for liblsan.
114 link_liblsan=$link_sanitizer_common
115 AC_SUBST(link_liblsan)
117 # At least for glibc, clock_gettime is in librt.  But don't pull that
118 # in if it still doesn't give us the function we want.  This
119 # test is copied from libgomp.
120 if test $ac_cv_func_clock_gettime = no; then
121   AC_CHECK_LIB(rt, clock_gettime,
122     [link_libasan="-lrt $link_libasan"
123 link_libtsan="-lrt $link_libtsan"
124 # Other sanitizers do not override clock_* API
128 case "$host" in
129   *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
130   *) MAC_INTERPOSE=false ;;
131 esac
132 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
134 backtrace_supported=yes
136 AC_MSG_CHECKING([for necessary platform features])
137 case "$target" in
138   *-*-linux*)
139     # Some old Linux distributions miss required syscalls.
140     sanitizer_supported=no
141     AC_TRY_COMPILE([#include <sys/syscall.h>],[
142       syscall (__NR_gettid);
143       syscall (__NR_futex);
144       syscall (__NR_exit_group);
145     ], [sanitizer_supported=yes])
146     ;;
147   *)
148     sanitizer_supported=yes
149     ;;
150 esac
151 AC_MSG_RESULT($sanitizer_supported)
152 AM_CONDITIONAL(SANITIZER_SUPPORTED, test "$sanitizer_supported" = yes)
154 # Test for __sync support.
155 AC_CACHE_CHECK([__sync extensions],
156 [libsanitizer_cv_sys_sync],
157 [if test -n "${with_target_subdir}"; then
158    libsanitizer_cv_sys_sync=yes
159  else
160    AC_LINK_IFELSE(
161      [AC_LANG_PROGRAM([int i;],
162                       [__sync_bool_compare_and_swap (&i, i, i);
163                        __sync_lock_test_and_set (&i, 1);
164                        __sync_lock_release (&i);])],
165      [libsanitizer_cv_sys_sync=yes],
166      [libsanitizer_cv_sys_sync=no])
167  fi])
168 if test "$libsanitizer_cv_sys_sync" = "yes"; then
169   AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
170             [Define to 1 if you have the __sync functions])
173 # Test for __atomic support.
174 AC_CACHE_CHECK([__atomic extensions],
175 [libsanitizer_cv_sys_atomic],
176 [if test -n "${with_target_subdir}"; then
177    libsanitizer_cv_sys_atomic=yes
178  else
179    AC_LINK_IFELSE(
180      [AC_LANG_PROGRAM([int i;],
181                       [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
182                        __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
183      [libsanitizer_cv_sys_atomic=yes],
184      [libsanitizer_cv_sys_atomic=no])
185  fi])
186 if test "$libsanitizer_cv_sys_atomic" = "yes"; then
187   AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
188             [Define to 1 if you have the __atomic functions])
191 # The library needs to be able to read the executable itself.  Compile
192 # a file to determine the executable format.  The awk script
193 # filetype.awk prints out the file type.
194 AC_CACHE_CHECK([output filetype],
195 [libsanitizer_cv_sys_filetype],
196 [filetype=
197 AC_COMPILE_IFELSE(
198   [AC_LANG_PROGRAM([int i;], [int j;])],
199   [filetype=`${AWK} -f $srcdir/../libbacktrace/filetype.awk conftest.$ac_objext`],
200   [AC_MSG_FAILURE([compiler failed])])
201 libsanitizer_cv_sys_filetype=$filetype])
203 # Match the file type to decide what files to compile.
204 FORMAT_FILE=
205 case "$libsanitizer_cv_sys_filetype" in
206 elf*) FORMAT_FILE="elf.lo" ;;
207 *) AC_MSG_WARN([could not determine output file type])
208    FORMAT_FILE="unknown.lo"
209    backtrace_supported=no
210    ;;
211 esac
212 AC_SUBST(FORMAT_FILE)
214 # ELF defines.
215 elfsize=
216 case "$libsanitizer_cv_sys_filetype" in
217 elf32) elfsize=32 ;;
218 elf64) elfsize=64 ;;
219 esac
220 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
222 BACKTRACE_SUPPORTED=0
223 if test "$backtrace_supported" = "yes"; then
224   BACKTRACE_SUPPORTED=1
226 AC_SUBST(BACKTRACE_SUPPORTED)
228 GCC_HEADER_STDINT(gstdint.h)
230 AC_CHECK_HEADERS(sys/mman.h alloca.h)
231 if test "$ac_cv_header_sys_mman_h" = "no"; then
232   have_mmap=no
233 else
234   if test -n "${with_target_subdir}"; then
235     # When built as a GCC target library, we can't do a link test.  We
236     # simply assume that if we have mman.h, we have mmap.
237     have_mmap=yes
238   else
239     AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
240   fi
242 if test "$have_mmap" = "no"; then
243   VIEW_FILE=read.lo
244   ALLOC_FILE=alloc.lo
245 else
246   VIEW_FILE=mmapio.lo
247   AC_PREPROC_IFELSE([
248 #include <sys/mman.h>
249 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
250   #error no MAP_ANONYMOUS
251 #endif
252 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
254 AC_SUBST(VIEW_FILE)
255 AC_SUBST(ALLOC_FILE)
257 BACKTRACE_USES_MALLOC=0
258 if test "$ALLOC_FILE" = "alloc.lo"; then
259   BACKTRACE_USES_MALLOC=1
261 AC_SUBST(BACKTRACE_USES_MALLOC)
263 # Don't care about thread support
264 BACKTRACE_SUPPORTS_THREADS=0
265 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
267 # Check for dl_iterate_phdr.
268 AC_CHECK_HEADERS(link.h)
269 if test "$ac_cv_header_link_h" = "no"; then
270   have_dl_iterate_phdr=no
271 else
272   # When built as a GCC target library, we can't do a link test.
273   AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
274                   [have_dl_iterate_phdr=no])
275   case "${host}" in
276   *-*-solaris2.10*)
277     # Avoid dl_iterate_phdr on Solaris 10, where it is in the
278     # header file but is only in -ldl.
279     have_dl_iterate_phdr=no ;;
280   esac
282 if test "$have_dl_iterate_phdr" = "yes"; then
283   AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
286 # Check for the fcntl function.
287 if test -n "${with_target_subdir}"; then
288    case "${host}" in
289    *-*-mingw*) have_fcntl=no ;;
290    *) have_fcntl=yes ;;
291    esac
292 else
293   AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
295 if test "$have_fcntl" = "yes"; then
296   AC_DEFINE([HAVE_FCNTL], 1,
297             [Define to 1 if you have the fcntl function])
300 AC_CHECK_DECLS(strnlen)
302 # Check for getexecname function.
303 if test -n "${with_target_subdir}"; then
304    case "${host}" in
305    *-*-solaris2*) have_getexecname=yes ;;
306    *) have_getexecname=no ;;
307    esac
308 else
309   AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
311 if test "$have_getexecname" = "yes"; then
312   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
315 AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
316                [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
318 AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
319 AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
320 AC_CONFIG_HEADER(config.h)
322 AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
323   [cat > vpsed$$ << \_EOF
324 s!`test -f '$<' || echo '$(srcdir)/'`!!
325 _EOF
326    sed -f vpsed$$ $ac_file > tmp$$
327    mv tmp$$ $ac_file
328    rm vpsed$$
329    echo 'MULTISUBDIR =' >> $ac_file
330    ml_norecursion=yes
331    . ${multi_basedir}/config-ml.in
332    AS_UNSET([ml_norecursion])
335 if test "x$TSAN_SUPPORTED" = "xyes"; then
336   AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]), 
337     [cat > vpsed$$ << \_EOF
338 s!`test -f '$<' || echo '$(srcdir)/'`!!
339 _EOF
340     sed -f vpsed$$ $ac_file > tmp$$
341     mv tmp$$ $ac_file
342     rm vpsed$$
343     echo 'MULTISUBDIR =' >> $ac_file
344     ml_norecursion=yes
345     . ${multi_basedir}/config-ml.in
346     AS_UNSET([ml_norecursion])
350 AC_SUBST([TSAN_TARGET_DEPENDENT_OBJECTS])
352 AC_OUTPUT