[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.3 Using the Target Type

A ‘configure’ script for a cross compilation tool will use the ‘--target’ option to control how it is built, so that the resulting program will produce programs which run on the appropriate system. In this section we explain how you can write your own configure scripts to support the ‘--target’ option.

You must start by putting ‘AC_CANONICAL_SYSTEM’ in ‘configure.in’.
AC_CANONICAL_SYSTEM’ will look for a ‘--target’ option and canonicalize it using the ‘config.sub’ shell script (for more information about configuration names, canonicalizing them, and ‘config.sub’, see section Configuration Names). ‘AC_CANONICAL_SYSTEM’ will also run ‘AC_CANONICAL_HOST’ to get the host information.

The host and target type will be recorded in the following shell variables:


The canonical configuration name of the host. This will normally be determined by running the ‘config.guess’ shell script, although the user is permitted to override this by using an explicit ‘--host’ option.


The canonical configuration name of the target.


The argument to the ‘--host’ option, if used. Otherwise, the same as the ‘host’ variable.


The argument to the ‘--target’ option. If the user did not specify a ‘--target’ option, this will be the same as ‘host_alias’.


The first three parts of the canonical host configuration name.


The first three parts of the canonical target configuration name.

Note that if ‘host’ and ‘target’ are the same string, you can assume a native configuration. If they are different, you can assume a cross configuration.

It is possible for ‘host’ and ‘target’ to represent the same system, but for the strings to not be identical. For example, if ‘config.guess’ returns ‘sparc-sun-sunos4.1.4’, and somebody configures with ‘--target sparc-sun-sunos4.1’, then the slight differences between the two versions of SunOS may be unimportant for your tool. However, in the general case it can be quite difficult to determine whether the differences between two configuration names are significant or not. Therefore, by convention, if the user specifies a ‘--target’ option without specifying a ‘--host’ option, it is assumed that the user wants to configure a cross compilation tool.

The ‘target’ variable should not be handled in the same way as the ‘target_alias’ variable. In general, whenever the user may actually see a string, ‘target_alias’ should be used. This includes anything which may appear in the file system, such as a directory name or part of a tool name. It also includes any tool output, unless it is clearly labelled as the canonical target configuration name. This permits the user to use the ‘--target’ option to specify how the tool will appear to the outside world. On the other hand, when checking for characteristics of the target system, ‘target’ should be used. This is because a wide variety of ‘--target’ options may map into the same canonical configuration name. You should not attempt to duplicate the canonicalization done by ‘config.sub’ in your own code.

By convention, cross tools are installed with a prefix of the argument used with the ‘--target’ option, also known as ‘target_alias’. If the user does not use the ‘--target’ option, and thus is building a native tool, no prefix is used. For example, if gcc is configured with ‘--target mips-elf’, then the installed binary will be named ‘mips-elf-gcc’. If gcc is configured without a ‘--target’ option, then the installed binary will be named ‘gcc’.

The Autoconf macro ‘AC_ARG_PROGRAM’ will handle the names of binaries for you. If you are using Automake, no more need be done; the programs will automatically be installed with the correct prefixes. Otherwise, see the Autoconf documentation for ‘AC_ARG_PROGRAM’.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Ben Elliston on July 10, 2015 using texi2html 1.82.