1# Autoconf M4 include file defining utility macros for complex Canadian 2# cross builds. 3 4dnl #### 5dnl # _GCC_TOPLEV_NONCANONICAL_BUILD 6dnl # $build_alias or canonical $build if blank. 7dnl # Used when we would use $build_alias, but empty is not OK. 8AC_DEFUN([_GCC_TOPLEV_NONCANONICAL_BUILD], 9[AC_REQUIRE([AC_CANONICAL_BUILD]) []dnl 10case ${build_alias} in 11 "") build_noncanonical=${build} ;; 12 *) build_noncanonical=${build_alias} ;; 13esac 14]) []dnl # _GCC_TOPLEV_NONCANONICAL_BUILD 15 16dnl #### 17dnl # _GCC_TOPLEV_NONCANONICAL_HOST 18dnl # $host_alias, or $build_noncanonical if blank. 19dnl # Used when we would use $host_alias, but empty is not OK. 20AC_DEFUN([_GCC_TOPLEV_NONCANONICAL_HOST], 21[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_BUILD]) []dnl 22case ${host_alias} in 23 "") host_noncanonical=${build_noncanonical} ;; 24 *) host_noncanonical=${host_alias} ;; 25esac 26]) []dnl # _GCC_TOPLEV_NONCANONICAL_HOST 27 28dnl #### 29dnl # _GCC_TOPLEV_NONCANONICAL_TARGET 30dnl # $target_alias or $host_noncanonical if blank. 31dnl # Used when we would use $target_alias, but empty is not OK. 32AC_DEFUN([_GCC_TOPLEV_NONCANONICAL_TARGET], 33[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_HOST]) []dnl 34case ${target_alias} in 35 "") target_noncanonical=${host_noncanonical} ;; 36 *) target_noncanonical=${target_alias} ;; 37esac 38]) []dnl # _GCC_TOPLEV_NONCANONICAL_TARGET 39 40dnl #### 41dnl # ACX_NONCANONICAL_BUILD 42dnl # Like underscored version, but AC_SUBST's. 43AC_DEFUN([ACX_NONCANONICAL_BUILD], 44[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_BUILD]) []dnl 45AC_SUBST(build_noncanonical) 46]) []dnl # ACX_NONCANONICAL_BUILD 47 48dnl #### 49dnl # ACX_NONCANONICAL_HOST 50dnl # Like underscored version, but AC_SUBST's. 51AC_DEFUN([ACX_NONCANONICAL_HOST], 52[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_HOST]) []dnl 53AC_SUBST(host_noncanonical) 54]) []dnl # ACX_NONCANONICAL_HOST 55 56dnl #### 57dnl # ACX_NONCANONICAL_TARGET 58dnl # Like underscored version, but AC_SUBST's. 59AC_DEFUN([ACX_NONCANONICAL_TARGET], 60[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_TARGET]) []dnl 61AC_SUBST(target_noncanonical) 62]) []dnl # ACX_NONCANONICAL_TARGET 63 64dnl #### 65dnl # GCC_TOPLEV_SUBDIRS 66dnl # GCC & friends build 'build', 'host', and 'target' tools. These must 67dnl # be separated into three well-known subdirectories of the build directory: 68dnl # build_subdir, host_subdir, and target_subdir. The values are determined 69dnl # here so that they can (theoretically) be changed in the future. They 70dnl # were previously reproduced across many different files. 71dnl # 72dnl # This logic really amounts to very little with autoconf 2.13; it will 73dnl # amount to a lot more with autoconf 2.5x. 74AC_DEFUN([GCC_TOPLEV_SUBDIRS], 75[AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_TARGET]) []dnl 76AC_REQUIRE([_GCC_TOPLEV_NONCANONICAL_BUILD]) []dnl 77# Prefix 'build-' so this never conflicts with target_subdir. 78build_subdir="build-${build_noncanonical}" 79# --srcdir=. covers the toplevel, while "test -d" covers the subdirectories 80if ( test $srcdir = . && test -d gcc ) \ 81 || test -d $srcdir/../host-${host_noncanonical}; then 82 host_subdir="host-${host_noncanonical}" 83else 84 host_subdir=. 85fi 86# No prefix. 87target_subdir=${target_noncanonical} 88AC_SUBST([build_subdir]) []dnl 89AC_SUBST([host_subdir]) []dnl 90AC_SUBST([target_subdir]) []dnl 91]) []dnl # GCC_TOPLEV_SUBDIRS 92 93 94#### 95# _NCN_TOOL_PREFIXES: Some stuff that oughtta be done in AC_CANONICAL_SYSTEM 96# or AC_INIT. 97# These demand that AC_CANONICAL_SYSTEM be called beforehand. 98AC_DEFUN([_NCN_TOOL_PREFIXES], 99[ncn_tool_prefix= 100test -n "$host_alias" && ncn_tool_prefix=$host_alias- 101ncn_target_tool_prefix= 102test -n "$target_alias" && ncn_target_tool_prefix=$target_alias- 103]) []dnl # _NCN_TOOL_PREFIXES 104 105#### 106# NCN_STRICT_CHECK_TOOLS(variable, progs-to-check-for,[value-if-not-found],[path]) 107# Like plain AC_CHECK_TOOLS, but require prefix if build!=target. 108 109AC_DEFUN([NCN_STRICT_CHECK_TOOLS], 110[AC_REQUIRE([_NCN_TOOL_PREFIXES]) []dnl 111for ncn_progname in $2; do 112 if test -n "$ncn_tool_prefix"; then 113 AC_CHECK_PROG([$1], [${ncn_tool_prefix}${ncn_progname}], 114 [${ncn_tool_prefix}${ncn_progname}], , [$4]) 115 fi 116 if test -z "$ac_cv_prog_$1" && test $build = $host ; then 117 AC_CHECK_PROG([$1], [${ncn_progname}], [${ncn_progname}], , [$4]) 118 fi 119 test -n "$ac_cv_prog_$1" && break 120done 121 122if test -z "$ac_cv_prog_$1" ; then 123 ifelse([$3],[], [set dummy $2 124 if test $build = $host ; then 125 $1="[$]2" 126 else 127 $1="${ncn_tool_prefix}[$]2" 128 fi], [$1="$3"]) 129fi 130]) []dnl # NCN_STRICT_CHECK_TOOLS 131 132#### 133# NCN_STRICT_CHECK_TARGET_TOOLS(variable, progs-to-check-for,[value-if-not-found],[path]) 134# Like CVS Autoconf AC_CHECK_TARGET_TOOLS, but require prefix if build!=target. 135 136AC_DEFUN([NCN_STRICT_CHECK_TARGET_TOOLS], 137[AC_REQUIRE([_NCN_TOOL_PREFIXES]) []dnl 138for ncn_progname in $2; do 139 if test -n "$ncn_target_tool_prefix"; then 140 AC_CHECK_PROG([$1], [${ncn_target_tool_prefix}${ncn_progname}], 141 [${ncn_target_tool_prefix}${ncn_progname}], , [$4]) 142 fi 143 if test -z "$ac_cv_prog_$1" && test $build = $target ; then 144 AC_CHECK_PROG([$1], [${ncn_progname}], [${ncn_progname}], , [$4]) 145 fi 146 test -n "$ac_cv_prog_$1" && break 147done 148 149if test -z "$ac_cv_prog_$1" ; then 150 ifelse([$3],[], [set dummy $2 151 if test $build = $target ; then 152 $1="[$]2" 153 else 154 $1="${ncn_target_tool_prefix}[$]2" 155 fi], [$1="$3"]) 156fi 157]) []dnl # NCN_STRICT_CHECK_TARGET_TOOLS 158 159### 160# AC_PROG_CPP_WERROR 161# Used for autoconf 2.5x to force AC_PREPROC_IFELSE to reject code which 162# triggers warnings from the preprocessor. Will be in autoconf 2.58. 163# For now, using this also overrides header checks to use only the 164# preprocessor (matches 2.13 behavior; matching 2.58's behavior is a 165# bit harder from here). 166# Eventually autoconf will default to checking headers with the compiler 167# instead, and we'll have to do this differently. 168 169AC_DEFUN([AC_PROG_CPP_WERROR], 170[AC_REQUIRE([AC_PROG_CPP])dnl 171m4_define([AC_CHECK_HEADER],m4_defn([_AC_CHECK_HEADER_OLD])) 172ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR 173 174# Test for GNAT. 175# We require the gnatbind program, and a compiler driver that 176# understands Ada. We use the user's CC setting, already found. 177# 178# Sets the shell variable have_gnat to yes or no as appropriate, and 179# substitutes GNATBIND. 180AC_DEFUN([ACX_PROG_GNAT], 181[AC_REQUIRE([AC_CHECK_TOOL_PREFIX]) 182AC_REQUIRE([AC_PROG_CC]) 183AC_CHECK_TOOL(GNATBIND, gnatbind, no) 184AC_CACHE_CHECK([whether compiler driver understands Ada], 185 acx_cv_cc_gcc_supports_ada, 186[cat >conftest.adb <<EOF 187procedure conftest is begin null; end conftest; 188EOF 189acx_cv_cc_gcc_supports_ada=no 190# There is a bug in old released versions of GCC which causes the 191# driver to exit successfully when the appropriate language module 192# has not been installed. This is fixed in 2.95.4, 3.0.2, and 3.1. 193# Therefore we must check for the error message as well as an 194# unsuccessful exit. 195# Other compilers, like HP Tru64 UNIX cc, exit successfully when 196# given a .adb file, but produce no object file. So we must check 197# if an object file was really produced to guard against this. 198errors=`(${CC} -c conftest.adb) 2>&1 || echo failure` 199if test x"$errors" = x && test -f conftest.$ac_objext; then 200 acx_cv_cc_gcc_supports_ada=yes 201fi 202rm -f conftest.*]) 203 204if test x$GNATBIND != xno && test x$acx_cv_cc_gcc_supports_ada != xno; then 205 have_gnat=yes 206else 207 have_gnat=no 208fi 209]) 210 211dnl 'make compare' can be significantly faster, if cmp itself can 212dnl skip bytes instead of using tail. The test being performed is 213dnl "if cmp --ignore-initial=2 t1 t2 && ! cmp --ignore-initial=1 t1 t2" 214dnl but we need to sink errors and handle broken shells. We also test 215dnl for the parameter format "cmp file1 file2 skip1 skip2" which is 216dnl accepted by cmp on some systems. 217AC_DEFUN([ACX_PROG_CMP_IGNORE_INITIAL], 218[AC_CACHE_CHECK([how to compare bootstrapped objects], gcc_cv_prog_cmp_skip, 219[ echo abfoo >t1 220 echo cdfoo >t2 221 gcc_cv_prog_cmp_skip='tail +16c $$f1 > tmp-foo1; tail +16c $$f2 > tmp-foo2; cmp tmp-foo1 tmp-foo2' 222 if cmp t1 t2 2 2 > /dev/null 2>&1; then 223 if cmp t1 t2 1 1 > /dev/null 2>&1; then 224 : 225 else 226 gcc_cv_prog_cmp_skip='cmp $$f1 $$f2 16 16' 227 fi 228 fi 229 if cmp --ignore-initial=2 t1 t2 > /dev/null 2>&1; then 230 if cmp --ignore-initial=1 t1 t2 > /dev/null 2>&1; then 231 : 232 else 233 gcc_cv_prog_cmp_skip='cmp --ignore-initial=16 $$f1 $$f2' 234 fi 235 fi 236 rm t1 t2 237]) 238do_compare="$gcc_cv_prog_cmp_skip" 239AC_SUBST(do_compare) 240]) 241 242dnl See whether we can include both string.h and strings.h. 243AC_DEFUN([ACX_HEADER_STRING], 244[AC_CACHE_CHECK([whether string.h and strings.h may both be included], 245 gcc_cv_header_string, 246[AC_TRY_COMPILE([#include <string.h> 247#include <strings.h>], , gcc_cv_header_string=yes, gcc_cv_header_string=no)]) 248if test $gcc_cv_header_string = yes; then 249 AC_DEFINE(STRING_WITH_STRINGS, 1, [Define if you can safely include both <string.h> and <strings.h>.]) 250fi 251]) 252 253dnl See if stdbool.h properly defines bool and true/false. 254dnl Check whether _Bool is built-in. 255AC_DEFUN([ACX_HEADER_STDBOOL], 256[AC_CACHE_CHECK([for working stdbool.h], 257 ac_cv_header_stdbool_h, 258[AC_TRY_COMPILE([#include <stdbool.h>], 259[bool foo = false;], 260ac_cv_header_stdbool_h=yes, ac_cv_header_stdbool_h=no)]) 261if test $ac_cv_header_stdbool_h = yes; then 262 AC_DEFINE(HAVE_STDBOOL_H, 1, 263 [Define if you have a working <stdbool.h> header file.]) 264fi 265AC_CACHE_CHECK(for built-in _Bool, gcc_cv_c__bool, 266[AC_TRY_COMPILE(, 267[_Bool foo;], 268gcc_cv_c__bool=yes, gcc_cv_c__bool=no) 269]) 270if test $gcc_cv_c__bool = yes; then 271 AC_DEFINE(HAVE__BOOL, 1, [Define if the \`_Bool' type is built-in.]) 272fi 273]) 274 275dnl See if hard links work and if not, try to substitute $1 or simple copy. 276AC_DEFUN([ACX_PROG_LN], 277[AC_MSG_CHECKING(whether ln works) 278AC_CACHE_VAL(acx_cv_prog_LN, 279[rm -f conftestdata_t 280echo >conftestdata_f 281if ln conftestdata_f conftestdata_t 2>/dev/null 282then 283 acx_cv_prog_LN=ln 284else 285 acx_cv_prog_LN=no 286fi 287rm -f conftestdata_f conftestdata_t 288])dnl 289if test $acx_cv_prog_LN = no; then 290 LN="ifelse([$1],,cp,[$1])" 291 AC_MSG_RESULT([no, using $LN]) 292else 293 LN="$acx_cv_prog_LN" 294 AC_MSG_RESULT(yes) 295fi 296AC_SUBST(LN)dnl 297]) 298 299dnl GCC_TARGET_TOOL(PROGRAM, TARGET-VAR, HOST-VAR, IN-TREE-TOOL, LANGUAGE) 300AC_DEFUN([GCC_TARGET_TOOL], 301[AC_MSG_CHECKING(where to find the target $1) 302if test "x${build}" != "x${host}" ; then 303 # Canadian cross, just use what we found 304 AC_MSG_RESULT(pre-installed) 305else 306 ifelse([$4],,, 307 [ok=yes 308 case " ${configdirs} " in 309 *" patsubst([$4], [/.*], []) "*) ;; 310 *) ok=no ;; 311 esac 312 ifelse([$5],,, 313 [case ,${enable_languages}, in 314 *,$5,*) ;; 315 *) ok=no ;; 316 esac]) 317 if test $ok = yes; then 318 # An in-tree tool is available and we can use it 319 $2='$$r/$(HOST_SUBDIR)/$4' 320 AC_MSG_RESULT(just compiled) 321 el])if test "x$target" = "x$host"; then 322 # We can use an host tool 323 $2='$($3)' 324 AC_MSG_RESULT(host tool) 325 else 326 # We need a cross tool 327 AC_MSG_RESULT(pre-installed) 328 fi 329fi]) 330