By default, Linux builds for the same architecture the host system is running. This is called “native compiling”. An x86 system building an x86 kernel, x86-64 building x86-64, or powerpc building powerpc are all examples of native compiling.
Building different binaries than the host runs is called cross compiling. Cross compiling is hard. The build system for the Linux kernel supports cross compiling via a two step process: 1) Specify a different architecture (ARCH) during the configure, make, and install stages. 2) Supply a cross compiler (CROSS_COMPILE) which can output the correct kind of binary code. An example cross compile command line (building the “arm” architecture) looks like:
make ARCH=arm menuconfig make ARCH=arm CROSS_COMPILE=armv5l-
To specify a different architecture than the host, either define the “ARCH” environment variable or else add “ARCH=xxx” to the make command line for each of the make config, make, and make install stages. The acceptable values for ARCH are the names of the directories in the “arch” subdirectory of the Linux kernel source code, see Architectures for details. All stages of the build must use the same ARCH value, and building a second architecture in the same source directory requires “make distclean”. (Just “make clean” isn’t sufficient, things like the include/asm symlink need to be removed and recreated.)
To specify a cross compiler prefix, define the CROSS_COMPILE environment variable (or add CROSS_COMPILE= to each make command line). Native compiler tools, which output code aimed at the environment they’re running in, usually have a simple name (“gcc”, “ld”, “strip”). Cross compilers usually add a prefix to the name of each tool, indicating the target they produce code for. To tell the Linux kernel build to use a cross compiler named “armv4l-gcc” (and corresponding “armv4l-ld” and “armv4l-strip”) specify “CROSS_COMPILE=armv4l-”. (Prefixes ending in a dash are common, and forgetting the trailing dash in CROSS_COMPILE is a common mistake.