GCC Canadian Cross

From OSDev.wiki
Revision as of 13:32, 6 March 2007 by Solar (talk | contribs) (Canadian Cross moved to GCC Canadian Cross: Looks better on the category page, and *is* GCC-specific.)
Jump to navigation Jump to search

Introduction

A Canadian Cross is to first build a cross-compiler for system Y (the host) on system X (the build-system). You would then use that cross-compiler, setting --build=<where this compiler runs> --host=<where the compiler you're building shall run> --target=<where the executables the compiler you're building will build shall run>. This explanation alone should be sufficient to show why this is both non-trivial and error-prone.

"Minor" Canadian Cross

Building a cross-compiler takes some time, so you might want to use a faster machine (like, a PIV) to build a cross-compiler for a lesser machine (like, a Pentium laptop). You don't really need the initial cross-compiler for this, as the system compiler on the build machine (PIV) can generate binaries for the host machine (Pentium) alright.

Unfortunately, GCC doesn't really support this decently. It will generate files for the compiling system instead (since they're nearly identical, right?). There is no way to tell GCC not to, except for hacking the makefile. For our example, the PIV kept adding -march=pentium4, which obviously makes them unsuited for the laptop. The solution is to use sed plus some command-line tricks. This is done after configure (since configure generates the Makefile), and before make (since make uses the Makefile).

 for i in `find ./ -name Makefile`; do mv $i $i.old; cat $i.old | sed -e 's/pentium4/i586/g' >$i; done

This effectively forces the compiler to do i586 compilation.

To make such a "minor" canadian cross, specify --host (the system the compiler shall run on) in addition to --target (the system the compiler shall compile for). Note that you still need the sed line because configure adds -march to the Makefile.