automake: Cross-Compilation
1
1 2.2.8 Cross-Compilation
1 -----------------------
1
1 To “cross-compile” is to build on one platform a binary that will run on
1 another platform. When speaking of cross-compilation, it is important
1 to distinguish between the “build platform” on which the compilation is
1 performed, and the “host platform” on which the resulting executable is
1 expected to run. The following ‘configure’ options are used to specify
1 each of them:
1
1 ‘--build=BUILD’
1 The system on which the package is built.
1 ‘--host=HOST’
1 The system where built programs and libraries will run.
1
1 When the ‘--host’ is used, ‘configure’ will search for the
1 cross-compiling suite for this platform. Cross-compilation tools
1 commonly have their target architecture as prefix of their name. For
1 instance my cross-compiler for MinGW32 has its binaries called
1 ‘i586-mingw32msvc-gcc’, ‘i586-mingw32msvc-ld’, ‘i586-mingw32msvc-as’,
1 etc.
1
1 Here is how we could build ‘amhello-1.0’ for ‘i586-mingw32msvc’ on a
1 GNU/Linux PC.
1
1 ~/amhello-1.0 % ./configure --build i686-pc-linux-gnu --host i586-mingw32msvc
1 checking for a BSD-compatible install... /usr/bin/install -c
1 checking whether build environment is sane... yes
1 checking for gawk... gawk
1 checking whether make sets $(MAKE)... yes
1 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1 checking for C compiler default output file name... a.exe
1 checking whether the C compiler works... yes
1 checking whether we are cross compiling... yes
1 checking for suffix of executables... .exe
1 checking for suffix of object files... o
1 checking whether we are using the GNU C compiler... yes
1 checking whether i586-mingw32msvc-gcc accepts -g... yes
1 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1 ...
1 ~/amhello-1.0 % make
1 ...
1 ~/amhello-1.0 % cd src; file hello.exe
1 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1
1 The ‘--host’ and ‘--build’ options are usually all we need for
1 cross-compiling. The only exception is if the package being built is
1 itself a cross-compiler: we need a third option to specify its target
1 architecture.
1
1 ‘--target=TARGET’
1 When building compiler tools: the system for which the tools will
1 create output.
1
1 For instance when installing GCC, the GNU Compiler Collection, we can
1 use ‘--target=TARGET’ to specify that we want to build GCC as a
1 cross-compiler for TARGET. Mixing ‘--build’ and ‘--target’, we can
1 actually cross-compile a cross-compiler; such a three-way
1 cross-compilation is known as a “Canadian cross”.
1
1 ⇒Specifying the System Type (autoconf)Specifying Names, for
1 more information about these ‘configure’ options.
1