26.4.6.1 Supporting Building with a Cross Compiler in Configure Scripts

back: supporting cross compiler
forward: supporting cross compiler in make
 
fastback: cross compilation
up: supporting cross compiler
fastforward: installing gnu autotools
top: autoconf, automake, and libtool
contents: table of contents
index: index
about: about this document

In a `configure.in' file, after calling `AC_PROG_CC' , you can find out whether the program is being built by a cross compiler by examining the shell variable `cross_compiling' . If the compiler is a cross compiler, which means that this is a Canadian Cross, `cross_compiling' will be `yes' . In a normal configuration, `cross_compiling' will be `no' .

You ordinarily do not need to know the type of the build system in a `configure' script. However, if you do need that information, you can get it by using the macro `AC_CANONICAL_SYSTEM' , the same macro which is used to determine the target system. This macro will set the variables `build' , `build_alias' , `build_cpu' , `build_vendor' , and `build_os' , which correspond to the similar `target' and `host' variables, except that they describe the build system. See section 26.3 Using the Target Type.

When writing tests in `configure.in' , you must remember that you want to test the host environment, not the build environment. Macros which use the compiler, such as like `AC_CHECK_FUNCS' , will test the host environment. That is because the tests will be done by running the compiler, which is actually a build cross host compiler. If the compiler can find the function, that means that the function is present in the host environment.

Tests like `test -f /dev/ptyp0' , on the other hand, will test the build environment. Remember that the `configure' script is running on the build system, not the host system. If your `configure' scripts examines files, those files will be on the build system. Whatever you determine based on those files may or may not be the case on the host system.

Most Autoconf macros will work correctly when building with a cross compiler. The main exception is `AC_TRY_RUN' . This macro tries to compile and run a test program. This will fail when building with a cross compiler, because the program will be compiled for the host system, which means that it will not run on the build system.

The `AC_TRY_RUN' macro provides an optional argument to tell the `configure' script what to do when building with a cross compiler. If that argument is not present, you will get a warning when you run `autoconf' :

 
 warning: AC_TRY_RUN called without default to allow cross compiling 
This tells you that the resulting `configure' script will not work when building with a cross compiler.

In some cases while it may better to perform a test at configure time, it is also possible to perform the test at run time (see section 23.3.2 Testing system features at application runtime). In such a case you can use the cross compiling argument to `AC_TRY_RUN' to tell your program that the test could not be performed at configure time.

There are a few other autoconf macros which will not work correctly when building with a cross compiler: a partial list is `AC_FUNC_GETPGRP' , `AC_FUNC_SETPGRP' , `AC_FUNC_SETVBUF_REVERSED' , and `AC_SYS_RESTARTABLE_SYSCALLS' . The `AC_CHECK_SIZEOF' macro is generally not very useful when building with a cross compiler; it permits an optional argument indicating the default size , but there is no way to know what the correct default should be.


This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html


GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net