docs/overview.txt
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Apr 17 22:22:46 2007 +0000 (2007-04-17)
changeset 40 8601bce18905
parent 1 eeea35fbf182
child 92 1159b1384a78
permissions -rw-r--r--
Once in a while I write some documentation... Not often enough...
     1 File.........: overview.txt
     2 Content......: Overview of how ct-ng works.
     3 Copyrigth....: (C) 2006 Yann E. MORIN <yann.morin.1998@anciens.enib.fr>
     4 License......: see COPYING in the root of this package
     5 ________________
     6                /
     7 Introduction  /
     8 _____________/
     9 
    10 crosstool-NG aims at building toolchains. Toolchains are an essential component
    11 in a software development project. It will compile, assemble and link the code
    12 that is being developped. Some pieces of the toolchain will eventually end up
    13 in the resulting binary/ies: static libraries are but an example.
    14 
    15 So, a toolchain is a very sensitive piece of software, as any bug in one of the
    16 components, or a poorly configured component, can lead to execution problems,
    17 ranging from poor performance, to applications ending unexpectedly, to
    18 mis-behaving software (which more than often is hard to detect), to hardware
    19 damage, or even to human risks (which is more than regretable).
    20 
    21 Toolchains are made of different piece of software, each being quite complex
    22 and requiring specially crafted options to build and work seamlessly. This
    23 is usually not that easy, even in the not-so-trivial case of native toolchains.
    24 The work reaches a higher degree of complexity when it comes to cross-
    25 compilation, where it can become quite a nightmare...
    26 
    27 Some cross-toolchains exist on the internet, and can be used for general
    28 development, but they have a number of limitations:
    29   - they can be general purpose, in that they are configured for the majority:
    30     no optimisation for your specific target,
    31   - they can be prepared for a specific target and thus are not easy to use,
    32     nor optimised for, or even supporting your target,
    33   - they often are using ageing components (compiler, C library, etc...) not
    34     supporting special features of your shiny new processor;
    35 On the other side, these toolchain offer some advantages:
    36   - they are ready to use and quite easy to install and setup,
    37   - they are proven if used by a wide community.
    38 
    39 But once you want to get all the juice out of your specific hardware, you will
    40 want to build your own toolchain. This is where crosstool-ng comes into play.
    41 
    42 There are also a number of tools that builds toolchains for specific needs,
    43 which is not really scalable. Examples are:
    44   - buildroot (buildroot.uclibc.org) whose main puprpose is to build root file
    45     systems, hence the name. But once you have your toolchain with buildroot,
    46     part of it is installed in the root-to-be, so if you want to build a whole
    47     new root, you either have to save the existing one as a template and
    48     restore it later, or restart again from scratch. This is not convenient,
    49   - ptxdist (www.pengutronix.de/software/ptxdist), whose purpose is very
    50     similar to buildroot,
    51   - other projects (openembeded.org for example), which is again used to
    52     build root file systems.
    53 
    54 crosstool-NG is really targetted at building toolchains, and only toolchains.
    55 It is then up to you to use it the way you want.
    56 
    57 ___________
    58           /
    59 History  /
    60 ________/
    61 
    62 crosstool was first 'conceived' by Dan Kegel, which offered it to the community,
    63 as a set of scripts, a repository of patches, and some pre-configured, general
    64 purpose setup files to be used to configure crosstool. This is available at
    65 www.kegel.com/crosstool, and the subversion repository is hosted on google at
    66 http://code.google.com/p/crosstool/.
    67 
    68 At the time of writing, crosstool only supports building with one C library,
    69 namely glibc, and one C compiler, gcc; it is cripled with historical support
    70 for legacy components, and is some kind of a mess to upgrade.
    71 
    72 I once managed to add support for uClibc-based toolchains, but it did not make
    73 into mainline, mostly because I don't have time to port the patch forward to
    74 the new versions, due in part to the big effort it was taking.
    75 
    76 So I decided to clean up crosstool in the state it was, re-order the things
    77 in place, and add appropriate support for what I needed, that is uClibc
    78 support.
    79 
    80 The only option left to me was rewrite crosstool from scratch. I decided to go
    81 this way, and name the new implementation ct-ng, standing for crosstool Next
    82 Generation, as many other comunity projects do, and as a wink at the TV series
    83 "Star Trek: The Next Generation". ;-)
    84 
    85 _____________
    86             /
    87 Operation  /
    88 __________/
    89 
    90 ct-ng is configured by a configurator presenting a menu-stuctured set of
    91 options. These options let you specify the way you want your toolchain built,
    92 where you want it installed, what architecture and specific processor it
    93 will support, the version of the components you want to use, etc... The
    94 value for those options are then stored in a configuration file.
    95 
    96 You then simply run make. It will use this configuration file to retrieve,
    97 extract and patch the components, build, install and test your newly built
    98 toolchain.
    99 
   100 You are then free to add the toolchain /bin directory in your PATH to use
   101 it at will.
   102 
   103 
   104 ___________________
   105                   /
   106 Toolchain types  /
   107 ________________/
   108 
   109 There are four kinds of toolchains you could encounter.
   110 
   111 First off, you must understand the following: when it comes to compilers there
   112 are up to four machines involved:
   113   1) the machine configuring the toolchain components: the config machine
   114   2) the machine building the toolchain components:    the build machine
   115   3) the machine running the toolchain:                the host machine
   116   4) the machine the toolchain is building for:        the target machine
   117 
   118 We can most of the time assume that the config machine and the build machine
   119 are the same. Most of the time, this will be true. The only time it isn't
   120 is if you're using distributed compilation (such as distcc). Let's forget
   121 this for the sake of simplicity.
   122 
   123 So we're left with three machines:
   124  - build
   125  - host
   126  - target
   127 
   128 Any toolchain will involve those three machines. You can be as pretty sure of
   129 this as "2 and 2 are 4". Here is how they come into play:
   130 
   131 1) build == host == target
   132     This is a plain native toolchain, targetting the exact same machine as the
   133     one it is built on, and running again on this exact same machine. You have
   134     to build such a toolchain when you want to use an updated component, such
   135     as a newer gcc for example.
   136     ct-ng calls it "native".
   137 
   138 2) build == host != target
   139     This is a classic cross-toolchain, which is expected to be run on the same
   140     machine it is compiled on, and generate code to run on a second machine,
   141     the target.
   142     ct-ng calls it "cross".
   143 
   144 3) build != host == target
   145     Such a toolchain is also a native toolchain, as it targets the same machine
   146     as it runs on. But it is build on another machine. You want such a
   147     toolchain when porting to a new architecture, or if the build machine is
   148     much faster than the host machine.
   149     ct-ng calls it "cross-native".
   150 
   151 4) build != host != target
   152     This one is called a canadian-toolchain (*), is is tricky. The three
   153     machines in play are different. You might want such a toolchain if you
   154     have a fast build machine, but the users will use it on another machine,
   155     and will produce code to run on a third machine.
   156     ct-ng calls it "canadian".
   157 
   158 ct-ng can build all these kinds of toolchains (or is aiming at it, anyway!)
   159 
   160 (*) The term Canadian Cross came about because at the time that these issues
   161     were all being hashed out, Canada had three national political parties.
   162     http://en.wikipedia.org/wiki/Cross_compiler
   163 
   164 _____________
   165             /
   166 Internals  /
   167 __________/
   168 
   169 <To be completed>