1 dnl Copyright (C) 2005-2015 Free Software Foundation, Inc.
3 dnl This file is part of GCC.
5 dnl GCC is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3, or (at your option)
10 dnl GCC is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 dnl GNU General Public License for more details.
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with GCC; see the file COPYING3. If not see
17 dnl <http://www.gnu.org/licenses/>.
19 dnl See whether we need a declaration for a function.
20 dnl The result is highly dependent on the INCLUDES passed in, so make sure
21 dnl to use a different cache variable name in this macro if it is invoked
22 dnl in a different context somewhere else.
23 dnl gcc_AC_CHECK_DECL(SYMBOL,
24 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, INCLUDES]]])
25 AC_DEFUN([gcc_AC_CHECK_DECL],
26 [AC_MSG_CHECKING([whether $1 is declared])
27 AC_CACHE_VAL(gcc_cv_have_decl_$1,
28 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$4],
30 char *(*pfn) = (char *(*)) $1 ;
31 #endif])], eval "gcc_cv_have_decl_$1=yes", eval "gcc_cv_have_decl_$1=no")])
32 if eval "test \"`echo '$gcc_cv_have_decl_'$1`\" = yes"; then
33 AC_MSG_RESULT(yes) ; ifelse([$2], , :, [$2])
35 AC_MSG_RESULT(no) ; ifelse([$3], , :, [$3])
39 dnl Check multiple functions to see whether each needs a declaration.
40 dnl Arrange to define HAVE_DECL_<FUNCTION> to 0 or 1 as appropriate.
41 dnl gcc_AC_CHECK_DECLS(SYMBOLS,
42 dnl [ACTION-IF-NEEDED [, ACTION-IF-NOT-NEEDED [, INCLUDES]]])
43 AC_DEFUN([gcc_AC_CHECK_DECLS],
44 [AC_FOREACH([gcc_AC_Func], [$1],
45 [AH_TEMPLATE(AS_TR_CPP(HAVE_DECL_[]gcc_AC_Func),
46 [Define to 1 if we found a declaration for ']gcc_AC_Func[', otherwise
50 ac_tr_decl=AS_TR_CPP([HAVE_DECL_$ac_func])
51 gcc_AC_CHECK_DECL($ac_func,
52 [AC_DEFINE_UNQUOTED($ac_tr_decl, 1) $2],
53 [AC_DEFINE_UNQUOTED($ac_tr_decl, 0) $3],
54 dnl It is possible that the include files passed in here are local headers
55 dnl which supply a backup declaration for the relevant prototype based on
56 dnl the definition of (or lack of) the HAVE_DECL_ macro. If so, this test
57 dnl will always return success. E.g. see libiberty.h's handling of
58 dnl `basename'. To avoid this, we define the relevant HAVE_DECL_ macro to
59 dnl 1 so that any local headers used do not provide their own prototype
68 dnl 'make compare' can be significantly faster, if cmp itself can
69 dnl skip bytes instead of using tail. The test being performed is
70 dnl "if cmp --ignore-initial=2 t1 t2 && ! cmp --ignore-initial=1 t1 t2"
71 dnl but we need to sink errors and handle broken shells. We also test
72 dnl for the parameter format "cmp file1 file2 skip1 skip2" which is
73 dnl accepted by cmp on some systems.
74 AC_DEFUN([gcc_AC_PROG_CMP_IGNORE_INITIAL],
75 [AC_CACHE_CHECK([for cmp's capabilities], gcc_cv_prog_cmp_skip,
78 gcc_cv_prog_cmp_skip=slowcompare
79 if cmp --ignore-initial=2 t1 t2 > /dev/null 2>&1; then
80 if cmp --ignore-initial=1 t1 t2 > /dev/null 2>&1; then
83 gcc_cv_prog_cmp_skip=gnucompare
86 if test $gcc_cv_prog_cmp_skip = slowcompare ; then
87 if cmp t1 t2 2 2 > /dev/null 2>&1; then
88 if cmp t1 t2 1 1 > /dev/null 2>&1; then
91 gcc_cv_prog_cmp_skip=fastcompare
97 make_compare_target=$gcc_cv_prog_cmp_skip
98 AC_SUBST(make_compare_target)
101 dnl See if symbolic links work and if not, try to substitute either hard links or simple copy.
102 AC_DEFUN([gcc_AC_PROG_LN_S],
103 [AC_MSG_CHECKING(whether ln -s works)
104 AC_CACHE_VAL(gcc_cv_prog_LN_S,
105 [rm -f conftestdata_t
107 if ln -s conftestdata_f conftestdata_t 2>/dev/null
109 gcc_cv_prog_LN_S="ln -s"
111 if ln conftestdata_f conftestdata_t 2>/dev/null
115 if cp -p conftestdata_f conftestdata_t 2>/dev/null
117 gcc_cv_prog_LN_S="cp -p"
123 rm -f conftestdata_f conftestdata_t
125 LN_S="$gcc_cv_prog_LN_S"
126 if test "$gcc_cv_prog_LN_S" = "ln -s"; then
129 if test "$gcc_cv_prog_LN_S" = "ln"; then
130 AC_MSG_RESULT([no, using ln])
132 AC_MSG_RESULT([no, and neither does ln, so using $gcc_cv_prog_LN_S])
138 dnl Define MKDIR_TAKES_ONE_ARG if mkdir accepts only one argument instead
140 AC_DEFUN([gcc_AC_FUNC_MKDIR_TAKES_ONE_ARG],
141 [AC_CACHE_CHECK([if mkdir takes one argument], gcc_cv_mkdir_takes_one_arg,
142 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
143 #include <sys/types.h>
144 #ifdef HAVE_SYS_STAT_H
145 # include <sys/stat.h>
152 #endif], [mkdir ("foo", 0);])],
153 gcc_cv_mkdir_takes_one_arg=no, gcc_cv_mkdir_takes_one_arg=yes)])
154 if test $gcc_cv_mkdir_takes_one_arg = yes ; then
155 AC_DEFINE(MKDIR_TAKES_ONE_ARG, 1, [Define if host mkdir takes a single argument.])
159 AC_DEFUN([gcc_AC_PROG_INSTALL],
160 [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
161 # Find a good install program. We prefer a C program (faster),
162 # so one script is as good as another. But avoid the broken or
163 # incompatible versions:
164 # SysV /etc/install, /usr/sbin/install
165 # SunOS /usr/etc/install
168 # AFS /usr/afsws/bin/install, which mishandles nonexistent args
169 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
170 # ./install, which can be erroneously created by make from ./install.sh.
171 AC_MSG_CHECKING(for a BSD compatible install)
172 if test -z "$INSTALL"; then
173 AC_CACHE_VAL(ac_cv_path_install,
174 [ IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:"
175 for ac_dir in $PATH; do
176 # Account for people who put trailing slashes in PATH elements.
178 /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
180 # OSF1 and SCO ODT 3.0 have their own names for install.
181 for ac_prog in ginstall scoinst install; do
182 if test -f $ac_dir/$ac_prog; then
183 if test $ac_prog = install &&
184 grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
185 # AIX install. It has an incompatible calling convention.
186 # OSF/1 installbsd also uses dspmsg, but is usable.
189 ac_cv_path_install="$ac_dir/$ac_prog -c"
199 if test "${ac_cv_path_install+set}" = set; then
200 INSTALL="$ac_cv_path_install"
202 # As a last resort, use the slow shell script. We don't cache a
203 # path for INSTALL within a source directory, because that will
204 # break other packages using the cache if that directory is
205 # removed, or if the path is relative.
206 INSTALL="$ac_install_sh"
209 dnl We do special magic for INSTALL instead of AC_SUBST, to get
210 dnl relative paths right.
211 AC_MSG_RESULT($INSTALL)
214 # Use test -z because SunOS4 sh mishandles braces in ${var-val}.
215 # It thinks the first close brace ends the variable substitution.
216 test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
217 AC_SUBST(INSTALL_PROGRAM)dnl
219 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
220 AC_SUBST(INSTALL_DATA)dnl
223 dnl Determine if enumerated bitfields are unsigned. ISO C says they can
224 dnl be either signed or unsigned.
226 AC_DEFUN([gcc_AC_C_ENUM_BF_UNSIGNED],
227 [AC_CACHE_CHECK(for unsigned enumerated bitfields, gcc_cv_enum_bf_unsigned,
228 [AC_RUN_IFELSE([AC_LANG_SOURCE([#include <stdlib.h>
229 enum t { BLAH = 128 } ;
230 struct s_t { enum t member : 8; } s ;
234 if (s.member < 0) exit(1);
237 }])], gcc_cv_enum_bf_unsigned=yes, gcc_cv_enum_bf_unsigned=no, gcc_cv_enum_bf_unsigned=yes)])
238 if test $gcc_cv_enum_bf_unsigned = yes; then
239 AC_DEFINE(ENUM_BITFIELDS_ARE_UNSIGNED, 1,
240 [Define if enumerated bitfields are treated as unsigned values.])
243 dnl Probe number of bits in a byte.
244 dnl Note C89 requires CHAR_BIT >= 8.
246 AC_DEFUN([gcc_AC_C_CHAR_BIT],
247 [AC_CACHE_CHECK(for CHAR_BIT, gcc_cv_decl_char_bit,
249 [#ifdef HAVE_LIMITS_H
254 #endif], gcc_cv_decl_char_bit=yes, gcc_cv_decl_char_bit=no)
256 if test $gcc_cv_decl_char_bit = no; then
257 AC_CACHE_CHECK(number of bits in a byte, gcc_cv_c_nbby,
260 while test $i -lt 65; do
261 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,
263 case (unsigned char)((unsigned long)1 << $i) == ((unsigned long)1 << $i):
264 case (unsigned char)((unsigned long)1<<($i-1)) == ((unsigned long)1<<($i-1)):
266 [gcc_cv_c_nbby=$i; break])
269 test -z "$gcc_cv_c_nbby" && gcc_cv_c_nbby=failed
271 if test $gcc_cv_c_nbby = failed; then
272 AC_MSG_ERROR(cannot determine number of bits in a byte)
274 AC_DEFINE_UNQUOTED(CHAR_BIT, $gcc_cv_c_nbby,
275 [Define as the number of bits in a byte, if `limits.h' doesn't.])
279 AC_DEFUN([gcc_AC_INITFINI_ARRAY],
280 [AC_REQUIRE([gcc_SUN_LD_VERSION])dnl
281 AC_ARG_ENABLE(initfini-array,
282 [ --enable-initfini-array use .init_array/.fini_array sections],
284 AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
285 gcc_cv_initfini_array, [dnl
286 if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
289 AC_RUN_IFELSE([AC_LANG_SOURCE([
293 /* We turn on .preinit_array/.init_array/.fini_array support for ia64
294 if it can be used. */
296 int main (void) { return x; }
297 int foo (void) { x = 0; }
298 int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;
300 [gcc_cv_initfini_array=yes], [gcc_cv_initfini_array=no],
301 [gcc_cv_initfini_array=no]);;
303 gcc_cv_initfini_array=no
304 if test $in_tree_ld = yes ; then
305 if test "$gcc_cv_gld_major_version" -eq 2 \
306 -a "$gcc_cv_gld_minor_version" -ge 22 \
307 -o "$gcc_cv_gld_major_version" -gt 2 \
308 && test $in_tree_ld_is_elf = yes; then
309 gcc_cv_initfini_array=yes
311 elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x -a x$gcc_cv_objdump != x ; then
312 cat > conftest.s <<\EOF
313 .section .dtors,"a",%progbits
315 .byte 'A', 'A', 'A', 'A'
316 .section .ctors,"a",%progbits
318 .byte 'B', 'B', 'B', 'B'
319 .section .fini_array.65530,"a",%progbits
321 .byte 'C', 'C', 'C', 'C'
322 .section .init_array.65530,"a",%progbits
324 .byte 'D', 'D', 'D', 'D'
325 .section .dtors.64528,"a",%progbits
327 .byte 'E', 'E', 'E', 'E'
328 .section .ctors.64528,"a",%progbits
330 .byte 'F', 'F', 'F', 'F'
331 .section .fini_array.01005,"a",%progbits
333 .byte 'G', 'G', 'G', 'G'
334 .section .init_array.01005,"a",%progbits
336 .byte 'H', 'H', 'H', 'H'
341 if $gcc_cv_as -o conftest.o conftest.s > /dev/null 2>&1 \
342 && $gcc_cv_ld -o conftest conftest.o > /dev/null 2>&1 \
343 && $gcc_cv_objdump -s -j .init_array conftest \
344 | grep HHHHFFFFDDDDBBBB > /dev/null 2>&1 \
345 && $gcc_cv_objdump -s -j .fini_array conftest \
346 | grep GGGGEEEECCCCAAAA > /dev/null 2>&1; then
347 gcc_cv_initfini_array=yes
350 rm -f conftest conftest.*
353 AC_PREPROC_IFELSE([AC_LANG_SOURCE([
355 # error Not an ELF OS
358 #if defined __GLIBC_PREREQ
359 # if __GLIBC_PREREQ (2, 4)
361 # error GLIBC 2.4 required
364 # if defined __sun__ && defined __svr4__
365 /* Solaris ld.so.1 supports .init_array/.fini_array since Solaris 8. */
367 # error The C library not known to support .init_array/.fini_array
370 ])],, [gcc_cv_initfini_array=no]);;
373 AC_MSG_CHECKING(cross compile... guessing)
374 gcc_cv_initfini_array=no
376 enable_initfini_array=$gcc_cv_initfini_array
378 if test $enable_initfini_array = yes; then
379 AC_DEFINE(HAVE_INITFINI_ARRAY_SUPPORT, 1,
380 [Define .init_array/.fini_array sections are available and working.])
383 dnl # _gcc_COMPUTE_GAS_VERSION
384 dnl # Used by gcc_GAS_VERSION_GTE_IFELSE
387 dnl # gcc_cv_as_gas_srcdir must be defined before this.
388 dnl # This gross requirement will go away eventually.
389 AC_DEFUN([_gcc_COMPUTE_GAS_VERSION],
390 [gcc_cv_as_bfd_srcdir=`echo $srcdir | sed -e 's,/gcc$,,'`/bfd
391 for f in $gcc_cv_as_bfd_srcdir/configure \
392 $gcc_cv_as_gas_srcdir/configure \
393 $gcc_cv_as_gas_srcdir/configure.in \
394 $gcc_cv_as_gas_srcdir/Makefile.in ; do
395 gcc_cv_gas_version=`sed -n -e 's/^[[ ]]*VERSION=[[^0-9A-Za-z_]]*\([[0-9]]*\.[[0-9]]*.*\)/VERSION=\1/p' < $f`
396 if test x$gcc_cv_gas_version != x; then
400 case $gcc_cv_gas_version in
402 *) AC_MSG_ERROR([[cannot find version of in-tree assembler]]);;
404 gcc_cv_gas_major_version=`expr "$gcc_cv_gas_version" : "VERSION=\([[0-9]]*\)"`
405 gcc_cv_gas_minor_version=`expr "$gcc_cv_gas_version" : "VERSION=[[0-9]]*\.\([[0-9]]*\)"`
406 gcc_cv_gas_patch_version=`expr "$gcc_cv_gas_version" : "VERSION=[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)"`
407 case $gcc_cv_gas_patch_version in
408 "") gcc_cv_gas_patch_version="0" ;;
410 gcc_cv_gas_vers=`expr \( \( $gcc_cv_gas_major_version \* 1000 \) \
411 + $gcc_cv_gas_minor_version \) \* 1000 \
412 + $gcc_cv_gas_patch_version`
413 ]) []dnl # _gcc_COMPUTE_GAS_VERSION
415 dnl # gcc_GAS_VERSION_GTE_IFELSE([elf,] major, minor, patchlevel,
416 dnl # [command_if_true = :], [command_if_false = :])
417 dnl # Check to see if the version of GAS is greater than or
418 dnl # equal to the specified version.
420 dnl # The first ifelse() shortens the shell code if the patchlevel
421 dnl # is unimportant (the usual case). The others handle missing
422 dnl # commands. Note that the tests are structured so that the most
423 dnl # common version number cases are tested first.
424 AC_DEFUN([_gcc_GAS_VERSION_GTE_IFELSE],
426 [if test $in_tree_gas_is_elf = yes \
428 [if]) test $gcc_cv_gas_vers -ge `expr \( \( $2 \* 1000 \) + $3 \) \* 1000 + $4`
430 ifelse([$5],,:,[$5])[]dnl
435 AC_DEFUN([gcc_GAS_VERSION_GTE_IFELSE],
436 [AC_REQUIRE([_gcc_COMPUTE_GAS_VERSION])dnl
437 ifelse([$1], elf, [_gcc_GAS_VERSION_GTE_IFELSE($@)],
438 [_gcc_GAS_VERSION_GTE_IFELSE(,$@)])])
441 dnl # Used by gcc_GAS_CHECK_FEATURE
443 AC_DEFUN([gcc_GAS_FLAGS],
444 [AC_CACHE_CHECK([assembler flags], gcc_cv_as_flags,
446 i[[34567]]86-*-linux*)
447 dnl Override the default, which may be incompatible.
450 x86_64-*-linux-gnux32)
451 dnl Override the default, which may be incompatible.
452 gcc_cv_as_flags=--x32
455 dnl Override the default, which may be incompatible.
459 dnl Always pass -arch ppc to assembler.
460 gcc_cv_as_flags="-arch ppc"
468 dnl gcc_GAS_CHECK_FEATURE(description, cv, [[elf,]major,minor,patchlevel],
469 dnl [extra switches to as], [assembler input],
470 dnl [extra testing logic], [command if feature available])
472 dnl Checks for an assembler feature. If we are building an in-tree
473 dnl gas, the feature is available if the associated assembler version
474 dnl is greater than or equal to major.minor.patchlevel. If not, then
475 dnl ASSEMBLER INPUT is fed to the assembler and the feature is available
476 dnl if assembly succeeds. If EXTRA TESTING LOGIC is not the empty string,
477 dnl then it is run instead of simply setting CV to "yes" - it is responsible
478 dnl for doing so, if appropriate.
479 AC_DEFUN([gcc_GAS_CHECK_FEATURE],
480 [AC_REQUIRE([gcc_GAS_FLAGS])dnl
481 AC_CACHE_CHECK([assembler for $1], [$2],
484 if test $in_tree_gas = yes; then
485 gcc_GAS_VERSION_GTE_IFELSE($3, [[$2]=yes])
486 el])if test x$gcc_cv_as != x; then
487 AS_ECHO([ifelse(m4_substr([$5],0,1),[$], "[$5]", '[$5]')]) > conftest.s
488 if AC_TRY_COMMAND([$gcc_cv_as $gcc_cv_as_flags $4 -o conftest.o conftest.s >&AS_MESSAGE_LOG_FD])
490 ifelse([$6],, [$2]=yes, [$6])
492 echo "configure: failed program was" >&AS_MESSAGE_LOG_FD
493 cat conftest.s >&AS_MESSAGE_LOG_FD
495 rm -f conftest.o conftest.s
498 if test $[$2] = yes; then
502 dnl gcc_SUN_LD_VERSION
504 dnl Determines Sun linker version numbers, setting gcc_cv_sun_ld_vers to
505 dnl the complete version number and gcc_cv_sun_ld_vers_{major, minor} to
506 dnl the corresponding fields.
508 dnl ld and ld.so.1 are guaranteed to be updated in lockstep, so ld version
509 dnl numbers can be used in ld.so.1 feature checks even if a different
510 dnl linker is configured.
512 AC_DEFUN([gcc_SUN_LD_VERSION],
514 if test "x${build}" = "x${target}" && test "x${build}" = "x${host}"; then
518 # Solaris 2 ld -V output looks like this for a regular version:
520 # ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1699
522 # but test versions add stuff at the end:
524 # ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1701:onnv-ab196087-6931056-03/25/10
526 gcc_cv_sun_ld_ver=`/usr/ccs/bin/ld -V 2>&1`
527 if echo "$gcc_cv_sun_ld_ver" | grep 'Solaris Link Editors' > /dev/null; then
528 gcc_cv_sun_ld_vers=`echo $gcc_cv_sun_ld_ver | sed -n \
529 -e 's,^.*: 5\.[0-9][0-9]*-\([0-9]\.[0-9][0-9]*\).*$,\1,p'`
530 gcc_cv_sun_ld_vers_major=`expr "$gcc_cv_sun_ld_vers" : '\([0-9]*\)'`
531 gcc_cv_sun_ld_vers_minor=`expr "$gcc_cv_sun_ld_vers" : '[0-9]*\.\([0-9]*\)'`
539 dnl GCC_TARGET_TEMPLATE(KEY)
540 dnl ------------------------
541 dnl Define KEY as a valid configure key on the target machine.
543 m4_define([GCC_TARGET_TEMPLATE],
544 [m4_define([GCC_TARGET_TEMPLATE($1)],[])])
546 dnl AH_TEMPLATE(KEY, DESCRIPTION)
547 dnl -----------------------------
548 dnl Issue an autoheader template for KEY, i.e., a comment composed of
549 dnl DESCRIPTION (properly wrapped), and then #undef KEY. Redefinition
550 dnl of the macro in autoheader.m4, to support definition of only a few
551 dnl keys while compiling target libraries.
553 m4_define([AH_TEMPLATE],
554 [AH_VERBATIM([$1],m4_text_wrap([$2 */], [ ], [/* ])
555 m4_ifdef([GCC_TARGET_TEMPLATE($1)],[],[#ifndef USED_FOR_TARGET
556 ])[#undef $1]m4_ifdef([GCC_TARGET_TEMPLATE($1)],[],[
560 dnl Make sure that build_exeext is looked for
561 AC_DEFUN([gcc_AC_BUILD_EXEEXT], [
562 ac_executable_extensions="$build_exeext"])
564 dnl GCC_GLIBC_VERSION_GTE_IFELSE(MAJOR, MINOR, IF-TRUE, IF-FALSE)
565 dnl -------------------------------------------------------------
566 dnl If the target glibc version ($glibc_version_major.$glibc_version_minor)
567 dnl is at least MAJOR.MINOR, call IF-TRUE, otherwise call IF-FALSE.
568 AC_DEFUN([GCC_GLIBC_VERSION_GTE_IFELSE],
570 AS_IF([test $glibc_version_major -gt $1 \
571 || ( test $glibc_version_major -eq $1 && test $glibc_version_minor -ge $2 )],