Richard Earnshaw <rearnsha@arm.com>
[deliverable/binutils-gdb.git] / config / acx.m4
CommitLineData
5212e868
NN
1# Autoconf M4 include file defining utility macros for complex Canadian
2# cross builds.
3
dd12c3a8
NN
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
118c4fba
NN
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
dd12c3a8
NN
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}"
b00612cc
PB
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
dd12c3a8
NN
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
5212e868
NN
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####
05cbd757 106# NCN_STRICT_CHECK_TOOLS(variable, progs-to-check-for,[value-if-not-found],[path])
2429c060 107# Like plain AC_CHECK_TOOLS, but require prefix if build!=host.
5212e868 108
05cbd757 109AC_DEFUN([NCN_STRICT_CHECK_TOOLS],
5212e868 110[AC_REQUIRE([_NCN_TOOL_PREFIXES]) []dnl
05cbd757
PB
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
5212e868 121
5212e868 122if test -z "$ac_cv_prog_$1" ; then
05cbd757 123 ifelse([$3],[], [set dummy $2
5212e868 124 if test $build = $host ; then
05cbd757 125 $1="[$]2"
5212e868 126 else
05cbd757
PB
127 $1="${ncn_tool_prefix}[$]2"
128 fi], [$1="$3"])
5212e868 129fi
05cbd757 130]) []dnl # NCN_STRICT_CHECK_TOOLS
5212e868
NN
131
132####
05cbd757
PB
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.
5212e868 135
05cbd757 136AC_DEFUN([NCN_STRICT_CHECK_TARGET_TOOLS],
5212e868 137[AC_REQUIRE([_NCN_TOOL_PREFIXES]) []dnl
2429c060
PB
138if test -n "$with_build_time_tools"; then
139 for ncn_progname in $2; do
140 AC_MSG_CHECKING([for ${ncn_progname} in $with_build_time_tools])
3a35eeb3
PB
141 if test -x $with_build_time_tools/${ncn_progname}; then
142 ac_cv_prog_$1=$with_build_time_tools/${ncn_progname}
2429c060
PB
143 AC_MSG_RESULT(yes)
144 break
145 else
146 AC_MSG_RESULT(no)
147 fi
148 done
149fi
05cbd757 150
2429c060
PB
151if test -z "$ac_cv_prog_$1"; then
152 for ncn_progname in $2; do
153 if test -n "$ncn_target_tool_prefix"; then
154 AC_CHECK_PROG([$1], [${ncn_target_tool_prefix}${ncn_progname}],
155 [${ncn_target_tool_prefix}${ncn_progname}], , [$4])
156 fi
157 if test -z "$ac_cv_prog_$1" && test $build = $target ; then
158 AC_CHECK_PROG([$1], [${ncn_progname}], [${ncn_progname}], , [$4])
159 fi
160 test -n "$ac_cv_prog_$1" && break
161 done
162fi
163
5212e868 164if test -z "$ac_cv_prog_$1" ; then
05cbd757 165 ifelse([$3],[], [set dummy $2
5212e868 166 if test $build = $target ; then
05cbd757 167 $1="[$]2"
5212e868 168 else
05cbd757
PB
169 $1="${ncn_target_tool_prefix}[$]2"
170 fi], [$1="$3"])
5212e868 171fi
05cbd757 172]) []dnl # NCN_STRICT_CHECK_TARGET_TOOLS
2429c060
PB
173
174
175# Backported from Autoconf 2.5x; can go away when and if
176# we switch. Put the OS path separator in $PATH_SEPARATOR.
177AC_DEFUN([ACX_PATH_SEP], [
178# The user is always right.
179if test "${PATH_SEPARATOR+set}" != set; then
180 echo "#! /bin/sh" >conf$$.sh
181 echo "exit 0" >>conf$$.sh
182 chmod +x conf$$.sh
183 if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
184 PATH_SEPARATOR=';'
185 else
186 PATH_SEPARATOR=:
187 fi
188 rm -f conf$$.sh
189fi
190])
191
192
193AC_DEFUN([ACX_TOOL_DIRS], [
194AC_REQUIRE([ACX_PATH_SEP])
195if test "x$exec_prefix" = xNONE; then
196 if test "x$prefix" = xNONE; then
197 gcc_cv_tool_prefix=$ac_default_prefix
198 else
199 gcc_cv_tool_prefix=$prefix
200 fi
201else
202 gcc_cv_tool_prefix=$exec_prefix
203fi
204
205# If there is no compiler in the tree, use the PATH only. In any
206# case, if there is no compiler in the tree nobody should use
207# AS_FOR_TARGET and LD_FOR_TARGET.
208if test x$host = x$build && test -f $srcdir/gcc/BASE-VER; then
209 gcc_version=`cat $srcdir/gcc/BASE-VER`
210 gcc_cv_tool_dirs="$gcc_cv_tool_prefix/libexec/gcc/$target_noncanonical/$gcc_version$PATH_SEPARATOR"
211 gcc_cv_tool_dirs="$gcc_cv_tool_dirs$gcc_cv_tool_prefix/libexec/gcc/$target_noncanonical$PATH_SEPARATOR"
212 gcc_cv_tool_dirs="$gcc_cv_tool_dirs/usr/lib/gcc/$target_noncanonical/$gcc_version$PATH_SEPARATOR"
213 gcc_cv_tool_dirs="$gcc_cv_tool_dirs/usr/lib/gcc/$target_noncanonical$PATH_SEPARATOR"
214 gcc_cv_tool_dirs="$gcc_cv_tool_dirs$gcc_cv_tool_prefix/$target_noncanonical/bin/$target_noncanonical/$gcc_version$PATH_SEPARATOR"
215 gcc_cv_tool_dirs="$gcc_cv_tool_dirs$gcc_cv_tool_prefix/$target_noncanonical/bin$PATH_SEPARATOR"
216else
217 gcc_cv_tool_dirs=
218fi
219
220if test x$build = x$target && test -n "$md_exec_prefix"; then
221 gcc_cv_tool_dirs="$gcc_cv_tool_dirs$md_exec_prefix$PATH_SEPARATOR"
222fi
223
224]) []dnl # ACX_TOOL_DIRS
225
226# ACX_HAVE_GCC_FOR_TARGET
227# Check if the variable GCC_FOR_TARGET really points to a GCC binary.
228AC_DEFUN([ACX_HAVE_GCC_FOR_TARGET], [
229cat > conftest.c << \EOF
230#ifdef __GNUC__
231 gcc_yay;
232#endif
233EOF
234if ($GCC_FOR_TARGET -E conftest.c | grep gcc_yay) > /dev/null 2>&1; then
235 have_gcc_for_target=yes
236else
237 GCC_FOR_TARGET=${ncn_target_tool_prefix}gcc
238 have_gcc_for_target=no
239fi
240rm conftest.c
241])
242
243# ACX_CHECK_INSTALLED_TARGET_TOOL(VAR, PROG)
244# Searching for installed target binutils. We need to take extra care,
245# else we may find the wrong assembler, linker, etc., and lose.
246#
247# First try --with-build-time-tools, if specified.
248#
249# For build != host, we ask the installed GCC for the name of the tool it
250# uses, and accept it if it is an absolute path. This is because the
251# only good choice for a compiler is the same GCC version that is being
252# installed (or we couldn't make target libraries), and we assume that
253# on the host system we'll have not only the same GCC version, but also
254# the same binutils version.
255#
256# For build == host, search the same directories that the installed
257# compiler will search. We used to do this for the assembler, linker,
258# and nm only; for simplicity of configuration, however, we extend this
259# criterion to tools (such as ar and ranlib) that are never invoked by
260# the compiler, to avoid mismatches.
261#
262# Also note we have to check MD_EXEC_PREFIX before checking the user's path
263# if build == target. This makes the most sense only when bootstrapping,
264# but we also do so when build != host. In this case, we hope that the
265# build and host systems will have similar contents of MD_EXEC_PREFIX.
266#
267# If we do not find a suitable binary, then try the user's path.
268
269AC_DEFUN([ACX_CHECK_INSTALLED_TARGET_TOOL], [
270AC_REQUIRE([ACX_TOOL_DIRS])
271AC_REQUIRE([ACX_HAVE_GCC_FOR_TARGET])
272if test -z "$ac_cv_path_$1" ; then
273 if test -n "$with_build_time_tools"; then
3a35eeb3
PB
274 AC_MSG_CHECKING([for $2 in $with_build_time_tools])
275 if test -x $with_build_time_tools/$2; then
276 $1=`cd $with_build_time_tools && pwd`/$2
277 ac_cv_path_$1=[$]$1
278 AC_MSG_RESULT([$ac_cv_path_$1])
279 else
280 AC_MSG_RESULT(no)
281 fi
2429c060
PB
282 elif test $build != $host && test $have_gcc_for_target = yes; then
283 $1=`$GCC_FOR_TARGET --print-prog-name=$2`
284 test [$]$1=$2 && $1=
285 ac_cv_path_$1=[$]$1
286 fi
287fi
288if test -z "$ac_cv_path_$1" ; then
289 AC_PATH_PROG([$1], [$2], [], [$gcc_cv_tool_dirs])
290fi
291if test -z "$ac_cv_path_$1" ; then
292 NCN_STRICT_CHECK_TARGET_TOOLS([$1], [$2])
3a35eeb3
PB
293else
294 $1=$ac_cv_path_$1
2429c060
PB
295fi
296]) []dnl # ACX_CHECK_INSTALLED_TARGET_TOOL
394559cb
DJ
297
298###
299# AC_PROG_CPP_WERROR
300# Used for autoconf 2.5x to force AC_PREPROC_IFELSE to reject code which
301# triggers warnings from the preprocessor. Will be in autoconf 2.58.
302# For now, using this also overrides header checks to use only the
303# preprocessor (matches 2.13 behavior; matching 2.58's behavior is a
304# bit harder from here).
305# Eventually autoconf will default to checking headers with the compiler
306# instead, and we'll have to do this differently.
307
308AC_DEFUN([AC_PROG_CPP_WERROR],
309[AC_REQUIRE([AC_PROG_CPP])dnl
310m4_define([AC_CHECK_HEADER],m4_defn([_AC_CHECK_HEADER_OLD]))
311ac_c_preproc_warn_flag=yes])# AC_PROG_CPP_WERROR
9e07f89d
NN
312
313# Test for GNAT.
314# We require the gnatbind program, and a compiler driver that
315# understands Ada. We use the user's CC setting, already found.
316#
317# Sets the shell variable have_gnat to yes or no as appropriate, and
318# substitutes GNATBIND.
319AC_DEFUN([ACX_PROG_GNAT],
320[AC_REQUIRE([AC_CHECK_TOOL_PREFIX])
321AC_REQUIRE([AC_PROG_CC])
322AC_CHECK_TOOL(GNATBIND, gnatbind, no)
323AC_CACHE_CHECK([whether compiler driver understands Ada],
324 acx_cv_cc_gcc_supports_ada,
325[cat >conftest.adb <<EOF
326procedure conftest is begin null; end conftest;
327EOF
328acx_cv_cc_gcc_supports_ada=no
329# There is a bug in old released versions of GCC which causes the
330# driver to exit successfully when the appropriate language module
331# has not been installed. This is fixed in 2.95.4, 3.0.2, and 3.1.
332# Therefore we must check for the error message as well as an
333# unsuccessful exit.
b8908782
DD
334# Other compilers, like HP Tru64 UNIX cc, exit successfully when
335# given a .adb file, but produce no object file. So we must check
336# if an object file was really produced to guard against this.
9e07f89d 337errors=`(${CC} -c conftest.adb) 2>&1 || echo failure`
b8908782 338if test x"$errors" = x && test -f conftest.$ac_objext; then
9e07f89d 339 acx_cv_cc_gcc_supports_ada=yes
9e07f89d
NN
340fi
341rm -f conftest.*])
342
b8908782 343if test x$GNATBIND != xno && test x$acx_cv_cc_gcc_supports_ada != xno; then
9e07f89d
NN
344 have_gnat=yes
345else
346 have_gnat=no
347fi
348])
4b1cb4fe
DD
349
350dnl 'make compare' can be significantly faster, if cmp itself can
351dnl skip bytes instead of using tail. The test being performed is
352dnl "if cmp --ignore-initial=2 t1 t2 && ! cmp --ignore-initial=1 t1 t2"
353dnl but we need to sink errors and handle broken shells. We also test
354dnl for the parameter format "cmp file1 file2 skip1 skip2" which is
355dnl accepted by cmp on some systems.
356AC_DEFUN([ACX_PROG_CMP_IGNORE_INITIAL],
357[AC_CACHE_CHECK([how to compare bootstrapped objects], gcc_cv_prog_cmp_skip,
358[ echo abfoo >t1
359 echo cdfoo >t2
360 gcc_cv_prog_cmp_skip='tail +16c $$f1 > tmp-foo1; tail +16c $$f2 > tmp-foo2; cmp tmp-foo1 tmp-foo2'
361 if cmp t1 t2 2 2 > /dev/null 2>&1; then
362 if cmp t1 t2 1 1 > /dev/null 2>&1; then
363 :
364 else
365 gcc_cv_prog_cmp_skip='cmp $$f1 $$f2 16 16'
366 fi
367 fi
368 if cmp --ignore-initial=2 t1 t2 > /dev/null 2>&1; then
369 if cmp --ignore-initial=1 t1 t2 > /dev/null 2>&1; then
370 :
371 else
372 gcc_cv_prog_cmp_skip='cmp --ignore-initial=16 $$f1 $$f2'
373 fi
374 fi
375 rm t1 t2
376])
377do_compare="$gcc_cv_prog_cmp_skip"
378AC_SUBST(do_compare)
379])
04cf1b77
PB
380
381dnl See whether we can include both string.h and strings.h.
382AC_DEFUN([ACX_HEADER_STRING],
383[AC_CACHE_CHECK([whether string.h and strings.h may both be included],
384 gcc_cv_header_string,
385[AC_TRY_COMPILE([#include <string.h>
386#include <strings.h>], , gcc_cv_header_string=yes, gcc_cv_header_string=no)])
387if test $gcc_cv_header_string = yes; then
388 AC_DEFINE(STRING_WITH_STRINGS, 1, [Define if you can safely include both <string.h> and <strings.h>.])
389fi
390])
391
392dnl See if stdbool.h properly defines bool and true/false.
393dnl Check whether _Bool is built-in.
394AC_DEFUN([ACX_HEADER_STDBOOL],
395[AC_CACHE_CHECK([for working stdbool.h],
396 ac_cv_header_stdbool_h,
397[AC_TRY_COMPILE([#include <stdbool.h>],
398[bool foo = false;],
399ac_cv_header_stdbool_h=yes, ac_cv_header_stdbool_h=no)])
400if test $ac_cv_header_stdbool_h = yes; then
401 AC_DEFINE(HAVE_STDBOOL_H, 1,
402 [Define if you have a working <stdbool.h> header file.])
403fi
404AC_CACHE_CHECK(for built-in _Bool, gcc_cv_c__bool,
405[AC_TRY_COMPILE(,
406[_Bool foo;],
407gcc_cv_c__bool=yes, gcc_cv_c__bool=no)
408])
409if test $gcc_cv_c__bool = yes; then
410 AC_DEFINE(HAVE__BOOL, 1, [Define if the \`_Bool' type is built-in.])
411fi
412])
413
656fdd47
PB
414dnl See if hard links work and if not, try to substitute $1 or simple copy.
415AC_DEFUN([ACX_PROG_LN],
416[AC_MSG_CHECKING(whether ln works)
417AC_CACHE_VAL(acx_cv_prog_LN,
418[rm -f conftestdata_t
419echo >conftestdata_f
420if ln conftestdata_f conftestdata_t 2>/dev/null
421then
422 acx_cv_prog_LN=ln
423else
424 acx_cv_prog_LN=no
425fi
426rm -f conftestdata_f conftestdata_t
427])dnl
428if test $acx_cv_prog_LN = no; then
429 LN="ifelse([$1],,cp,[$1])"
430 AC_MSG_RESULT([no, using $LN])
431else
432 LN="$acx_cv_prog_LN"
433 AC_MSG_RESULT(yes)
434fi
435AC_SUBST(LN)dnl
436])
437
be01d343
PB
438dnl GCC_TARGET_TOOL(PROGRAM, TARGET-VAR, HOST-VAR, IN-TREE-TOOL, LANGUAGE)
439AC_DEFUN([GCC_TARGET_TOOL],
440[AC_MSG_CHECKING(where to find the target $1)
441if test "x${build}" != "x${host}" ; then
2429c060
PB
442 if expr "x[$]$2" : "x/" > /dev/null; then
443 # We already found the complete path
444 AC_MSG_RESULT(pre-installed in `dirname [$]$2`)
445 else
446 # Canadian cross, just use what we found
447 AC_MSG_RESULT(pre-installed)
448 fi
be01d343
PB
449else
450 ifelse([$4],,,
451 [ok=yes
452 case " ${configdirs} " in
453 *" patsubst([$4], [/.*], []) "*) ;;
454 *) ok=no ;;
455 esac
456 ifelse([$5],,,
457 [case ,${enable_languages}, in
458 *,$5,*) ;;
459 *) ok=no ;;
460 esac])
461 if test $ok = yes; then
462 # An in-tree tool is available and we can use it
463 $2='$$r/$(HOST_SUBDIR)/$4'
464 AC_MSG_RESULT(just compiled)
2429c060
PB
465 el])if expr "x[$]$2" : "x/" > /dev/null; then
466 # We already found the complete path
467 AC_MSG_RESULT(pre-installed in `dirname [$]$2`)
468 elif test "x$target" = "x$host"; then
be01d343
PB
469 # We can use an host tool
470 $2='$($3)'
471 AC_MSG_RESULT(host tool)
472 else
473 # We need a cross tool
474 AC_MSG_RESULT(pre-installed)
475 fi
476fi])
This page took 0.224347 seconds and 4 git commands to generate.