Cross Compiling FreeBSD for Fun and Profit

Summary

Introduction

Notes

For the sake of illustration, the document assumes that:

Notation Used

Obtaining FreeBSD

The reader can obtain the sources as noted in the Handbook chapter titled Obtaining FreeBSD. The reader should place the sources in /home/bob/src.

Setting up Build Environment

For architectures that are supported by FreeBSD, cross-building is relatively easy. For architectures that FreeBSD doesn't support, more work is required.

The FreeBSD build system uses three environment variables to control which platform to build (TARGET), which target architecture to build (TARGET_ARCH), and where to put the results (MAKEOBJDIRPREFX). By default, FreeBSD builds the current architecture and places the results in /usr/obj, or in this example /home/bob/obj.

When cross-compiling however, FreeBSD places binaries in $MAKEOBJDIRPREFIX/$TARGET (for cases where $TARGET == $TARGET_ARCH, e.g. amd64) or $MAKEOBJDIRPREFIX/$TARGET.$TARGET_ARCH (for cases where $TARGET != $TARGET_ARCH). In this example, the directory used will be /home/bob/obj/arm.armeb.

make.conf / src.conf

A standard make.conf and src.conf file can contain variables or make snippets which tune build behavior. /usr/share/examples/etc/make.conf has more details on some recommended make.conf tunable items, and src.conf(5) lists some of the variables that one could put in src.conf . The following notes some potential pitfalls in using these files for cross-compiling, make universe, make tinderbox, etc:

CPUTYPE= core2

CPUTYPE?= core2

KERNCONF= XEN

CPUTYPE?= XEN

Building and Installing World

The following subsections show the reader how they could build and install world for the big-endian ARM architecture from scratch.

Go to the Source Directory

% cd /home/bob/src

Build World

% make buildworld TARGET=arm TARGET_ARCH=armeb MAKEOBJDIRPREFIX=/home/bob/obj

Install World

% mkdir /home/bob/my-armeb

% make installworld DESTDIR=/home/bob/my-armeb TARGET=arm TARGET_ARCH=armeb MAKEOBJDIRPREFIX=/home/bob/obj

% make distribution DESTDIR=/home/bob/my-armeb TARGET=arm TARGET_ARCH=armeb MAKEOBJDIRPREFIX=/home/bob/obj

What's Next

The above example demonstrated how one could build world and install world with armeb. This should provide you with the building blocks required to build the FreeBSD base system for any cross-compilation environment.

Cheat sheet

http://lists.freebsd.org/pipermail/freebsd-current/2006-July/064384.html

A_Brief_Guide_To_Cross_Compiling_FreeBSD (last edited 2012-01-23 08:58:25 by GarrettCooper)