docs/overview.txt
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jul 17 21:44:33 2007 +0000 (2007-07-17)
changeset 276 835178a32fc1
parent 246 372bc84bea36
child 277 4c32aa5569b2
permissions -rw-r--r--
Revisit the extract-config way of working: ct-ng is the sole entry point to crosstool-NG, and ct-ng.extrac-config no longer exists. You now have to call "ct-ng extractconfig </path/to/your/build.log" instead.
     1 File.........: overview.txt
     2 Content......: Overview of how crosstool-NG works.
     3 Copyrigth....: (C) 2007 Yann E. MORIN <yann.morin.1998@anciens.enib.fr>
     4 License......: Creative Commons Attribution Share Alike (CC-by-sa), v2.5
     5 
     6 ________________
     7                /
     8 Introduction  /
     9 _____________/
    10 
    11 crosstool-NG aims at building toolchains. Toolchains are an essential component
    12 in a software development project. It will compile, assemble and link the code
    13 that is being developped. Some pieces of the toolchain will eventually end up
    14 in the resulting binary/ies: static libraries are but an example.
    15 
    16 So, a toolchain is a very sensitive piece of software, as any bug in one of the
    17 components, or a poorly configured component, can lead to execution problems,
    18 ranging from poor performance, to applications ending unexpectedly, to
    19 mis-behaving software (which more than often is hard to detect), to hardware
    20 damage, or even to human risks (which is more than regretable).
    21 
    22 Toolchains are made of different piece of software, each being quite complex
    23 and requiring specially crafted options to build and work seamlessly. This
    24 is usually not that easy, even in the not-so-trivial case of native toolchains.
    25 The work reaches a higher degree of complexity when it comes to cross-
    26 compilation, where it can become quite a nightmare...
    27 
    28 Some cross-toolchains exist on the internet, and can be used for general
    29 development, but they have a number of limitations:
    30   - they can be general purpose, in that they are configured for the majority:
    31     no optimisation for your specific target,
    32   - they can be prepared for a specific target and thus are not easy to use,
    33     nor optimised for, or even supporting your target,
    34   - they often are using ageing components (compiler, C library, etc...) not
    35     supporting special features of your shiny new processor;
    36 On the other side, these toolchain offer some advantages:
    37   - they are ready to use and quite easy to install and setup,
    38   - they are proven if used by a wide community.
    39 
    40 But once you want to get all the juice out of your specific hardware, you will
    41 want to build your own toolchain. This is where crosstool-NG comes into play.
    42 
    43 There are also a number of tools that builds toolchains for specific needs,
    44 which is not really scalable. Examples are:
    45   - buildroot (buildroot.uclibc.org) whose main puprpose is to build root file
    46     systems, hence the name. But once you have your toolchain with buildroot,
    47     part of it is installed in the root-to-be, so if you want to build a whole
    48     new root, you either have to save the existing one as a template and
    49     restore it later, or restart again from scratch. This is not convenient,
    50   - ptxdist (www.pengutronix.de/software/ptxdist), whose purpose is very
    51     similar to buildroot,
    52   - other projects (openembeded.org for example), which is again used to
    53     build root file systems.
    54 
    55 crosstool-NG is really targetted at building toolchains, and only toolchains.
    56 It is then up to you to use it the way you want.
    57 
    58 ___________
    59           /
    60 History  /
    61 ________/
    62 
    63 crosstool was first 'conceived' by Dan Kegel, which offered it to the community,
    64 as a set of scripts, a repository of patches, and some pre-configured, general
    65 purpose setup files to be used to configure crosstool. This is available at
    66 http://www.kegel.com/crosstool, and the subversion repository is hosted on
    67 google at http://code.google.com/p/crosstool/.
    68 
    69 At the time of writing, crosstool only supports building with one C library,
    70 namely glibc, and one C compiler, gcc; it is cripled with historical support
    71 for legacy components, and is some kind of a mess to upgrade. Also, submited
    72 patches take a loooong time before they are integrated mainline.
    73 
    74 I once managed to add support for uClibc-based toolchains, but it did not make
    75 into mainline, mostly because I don't have time to port the patch forward to
    76 the new versions, due in part to the big effort it was taking.
    77 
    78 So I decided to clean up crosstool in the state it was, re-order the things
    79 in place, and add appropriate support for what I needed, that is uClibc
    80 support. That was a disaster, as inclusion into mainline is slow as hell,
    81 and the changes were so numerous.
    82 
    83 The only option left to me was rewrite crosstool from scratch. I decided to go
    84 this way, and name the new implementation crosstool-NG, standing for crosstool
    85 Next Generation, as many other comunity projects do, and as a wink at the TV
    86 series "Star Trek: The Next Generation". ;-)
    87 
    88 ____________________________
    89                            /
    90 Configuring crosstool-NG  /
    91 _________________________/
    92 
    93 crosstool-NG is configured the same way you configure your Linux kernel: by
    94 using a curses-based menu. It is assumed you now how to handle this.
    95 
    96 To enter the menu, type:
    97   ct-ng menuconfig
    98 
    99 Almost every config item has a help entry. Read them carefully.
   100 
   101 String and number options can refer to environment variables. In such a case,
   102 you must use the shell syntax: ${VAR}. You shall neither single- nor double-
   103 quote the string options.
   104 
   105 There are three environment variables that are computed by crosstool-NG, and
   106 that you can use:
   107 
   108 CT_TARGET:
   109   It represents the target triplet you are building for. You can use it for
   110   example in the installation/prefix directory, such as:
   111     /opt/x-tools/${CT_TARGET}
   112 
   113 CT_TOP_DIR:
   114   The top directory where crosstool-NG is running. You shouldn't need it in
   115   most cases. There is one case where you may need it: if you have local
   116   patches and you store them in your running directory, you can refer to them
   117   by using CT_TOP_DIR, such as:
   118     ${CT_TOP_DIR}/patches.myproject
   119 
   120 CT_VERSION:
   121   The version of crosstool-NG you are using. Not much use for you, but it's
   122   there if you need it.
   123 
   124 
   125 Interesting config options |
   126 ---------------------------*
   127 
   128 CT_LOCAL_TARBALLS_DIR:
   129   If you already have sone tarballs in a direcotry, enter it here. That will
   130   speed up the retrieving phase, where crosstool-NG would otherwise download
   131   those tarballs.
   132 
   133 CT_PREFIX_DIR:
   134   This is where the toolchain will be installed in (and for now, where it
   135   will run from).
   136 
   137 CT_TARGET_VENDOR:
   138   An identifier for your toolchain, will take place in the vendor part of the
   139   target triplet. It shall *not* contain spaces or dashes. Usually, keep it
   140   to a one-word string, or use underscores to separate words if you need.
   141   Avoid dots, commas, and special characters.
   142 
   143 CT_TARGET_ALIAS:
   144   An alias for the toolchian. It will be used as a prefix to the toolchain
   145   tools. For example, you will have ${CT_TARGET_ALIAS}-gcc
   146 
   147 Also, if you think you don't see enough versions, you can try to enable one of
   148 those:
   149 
   150 CT_OBSOLETE:
   151   Show obsolete versions or tools. Most of the time, you don't want to base
   152   your toolchain on too old a version (of gcc, for example). But at times, it
   153   can come handy to use such an old version for regression tests. Those old
   154   versions are hidden behind CT_BSOLETE.
   155 
   156 CT_EXPERIMENTAL:
   157   Show experimental versions or tools. Again, you might not want to base your
   158   toolchain on too recent tools (eg. gcc) for production. But if you need a
   159   feature present only in a recent version, or a new tool, you can find them
   160   hidden behind CT_EXPERIMENTAL.
   161 
   162 CT_BROKEN:
   163   Show broken versions or tools. Some usefull tools are currently broken: they
   164   won't compile, run, or worse, cause defects when running. But if you are
   165   brave enough, you can try and debug them. They are hidden behind CT_BROKEN,
   166   which itself is hiddent behind EXPERIMENTAL.
   167 
   168 Re-building an existing toolchain |
   169 ----------------------------------+
   170 
   171 If you have an existing toolchain, you can re-use the options used to build it
   172 to create a new toolchain. That needs a very little bit of effort on your side
   173 but is quite easy. The options to build a toolchain are saved in the build log
   174 file that is saved within the toolchain. crosstool-NG can extract those options
   175 to recreate a new configuration:
   176   ct-ng extractconfig </path/to/your/build.log
   177 
   178 will extract those options, prompt you for the new ones, which you can later
   179 edit with menuconfig.
   180 
   181 Of course, if your build log was compressed, you'd have to use something like:
   182   bzcat /path/to/your/build.log.bz2 |ct-ng extractconfig
   183 
   184 ________________________
   185                        /
   186 Running crosstool-NG  /
   187 _____________________/
   188 
   189 crosstool-NG is configured by a configurator presenting a menu-stuctured set of
   190 options. These options let you specify the way you want your toolchain built,
   191 where you want it installed, what architecture and specific processor it
   192 will support, the version of the components you want to use, etc... The
   193 value for those options are then stored in a configuration file.
   194 
   195 To build the toolchain, simply type:
   196   ct-ng build
   197 
   198 This will use the above configuration to retrieve, extract and patch the
   199 components, build, install and eventually test your newly built toolchain.
   200 
   201 You are then free to add the toolchain /bin directory in your PATH to use
   202 it at will.
   203 
   204 In any case, you can get some terse help. Just type:
   205   ct-ng help
   206 or:
   207   man 1 ct-ng
   208 
   209 
   210 Stoping and restarting a build |
   211 -------------------------------*
   212 
   213 If you want to stop the build after a step you are debugging, you can pass the
   214 variable STOP to make:
   215   ct-ng STOP=some_step
   216 
   217 Conversely, if you want to restart a build at a specific step you are
   218 debugging, you can pass the RESTART variable to make:
   219   ct-ng RESTART=some_step
   220 
   221 Alternatively, you can call make with the name of a step to just do that step:
   222   ct-ng libc_headers
   223 is equivalent to:
   224   ct-ng RESTART=libs_headers STOP=libc_headers
   225 
   226 The shortcuts -step_name and step_name- allow to respectively stop or restart
   227 at that step. Thus:
   228   ct-ng -libc_headers        and:    ct-ng libc_headers-
   229 are equivalent to:
   230   ct-ng STOP=libc_headers    and:    ct-ng RESTART=libc_headers
   231 
   232 To obtain the list of acceptable steps, please call:
   233   ct-ng liststeps
   234 
   235 Note that in order to restart a build, you'll have to say 'Y' to the config
   236 option CT_DEBUG_CT_SAVE_STEPS, and that the previous build effectively went
   237 that far.
   238 
   239 
   240 Testing all toolchains at once |
   241 -------------------------------*
   242 
   243 You can test-build all samples; simply call:
   244   ct-ng regtest
   245 
   246 _______________________
   247                       /
   248 Using the toolchain  /
   249 ____________________/
   250 
   251 Using the toolchain is as simple as adding the toolchain's bin directory in
   252 your PATH, such as:
   253   export PATH="${PATH}:/your/toolchain/path/bin"
   254 
   255 and then using the target triplet to tell the build systems to use your
   256 toolchain:
   257   ./configure --target=your-target-triplet
   258   make CC=your-target-triplet-gcc
   259   make CROSS_COMPILE=your-target-triplet-
   260   and so on...
   261 
   262 When your root directory is ready, it is still missing some important bits: the
   263 toolchain's libraries. To populate your root directory with those libs, just
   264 run:
   265   your-target-triplet-populate -s /your/root -d /your/root-populated
   266 
   267 This will copy /your/root into /your/root-populated, and put the needed and only
   268 the needed libraries there. Thus you don't polute /your/root with any cruft that
   269 would no longer be needed should you have to remove stuff. /your/root always
   270 contains only those things you install in it.
   271 
   272 You can then use /your/root-populated to build up your file system image, a
   273 tarball, or to NFS-mount it from your target, or whatever you need.
   274 
   275 ___________________
   276                   /
   277 Toolchain types  /
   278 ________________/
   279 
   280 There are four kinds of toolchains you could encounter.
   281 
   282 First off, you must understand the following: when it comes to compilers there
   283 are up to four machines involved:
   284   1) the machine configuring the toolchain components: the config machine
   285   2) the machine building the toolchain components:    the build machine
   286   3) the machine running the toolchain:                the host machine
   287   4) the machine the toolchain is generating code for: the target machine
   288 
   289 We can most of the time assume that the config machine and the build machine
   290 are the same. Most of the time, this will be true. The only time it isn't
   291 is if you're using distributed compilation (such as distcc). Let's forget
   292 this for the sake of simplicity.
   293 
   294 So we're left with three machines:
   295  - build
   296  - host
   297  - target
   298 
   299 Any toolchain will involve those three machines. You can be as pretty sure of
   300 this as "2 and 2 are 4". Here is how they come into play:
   301 
   302 1) build == host == target
   303     This is a plain native toolchain, targetting the exact same machine as the
   304     one it is built on, and running again on this exact same machine. You have
   305     to build such a toolchain when you want to use an updated component, such
   306     as a newer gcc for example.
   307     crosstool-NG calls it "native".
   308 
   309 2) build == host != target
   310     This is a classic cross-toolchain, which is expected to be run on the same
   311     machine it is compiled on, and generate code to run on a second machine,
   312     the target.
   313     crosstool-NG calls it "cross".
   314 
   315 3) build != host == target
   316     Such a toolchain is also a native toolchain, as it targets the same machine
   317     as it runs on. But it is build on another machine. You want such a
   318     toolchain when porting to a new architecture, or if the build machine is
   319     much faster than the host machine.
   320     crosstool-NG calls it "cross-native".
   321 
   322 4) build != host != target
   323     This one is called a canadian-toolchain (*), and is tricky. The three
   324     machines in play are different. You might want such a toolchain if you
   325     have a fast build machine, but the users will use it on another machine,
   326     and will produce code to run on a third machine.
   327     crosstool-NG calls it "canadian".
   328 
   329 crosstool-NG can build all these kinds of toolchains (or is aiming at it,
   330 anyway!)
   331 
   332 (*) The term Canadian Cross came about because at the time that these issues
   333     were all being hashed out, Canada had three national political parties.
   334     http://en.wikipedia.org/wiki/Cross_compiler
   335 
   336 _____________
   337             /
   338 Internals  /
   339 __________/
   340 
   341 Internally, crosstool-NG is script-based. To ease usage, the frontend is
   342 Makefile-based.
   343 
   344 Makefile front-end |
   345 -------------------*
   346 
   347 The entry point to crosstool-NG is the Makefile script "ct-ng". Calling this
   348 script with an action will act exactly as if the Makefile was in the current
   349 working directory and make was called with the action as rule. Thus:
   350   ct-ng menuconfig
   351 is equivalent to having the Makefile in CWD, and calling:
   352   make menuconfig
   353 
   354 Having ct-ng as it is avoids copying the Makefile everywhere, and acts as a
   355 traditional command.
   356 
   357 ct-ng loads sub- Makefiles from the library directory $(CT_LIB_DIR), as set up
   358 at configuration time with ./configure.
   359 
   360 ct-ng also search for config files, sub-tools, samples, scripts and patches in
   361 that library directory.
   362 
   363 Kconfig parser |
   364 ---------------*
   365 
   366 The kconfig language is a hacked version, vampirised from the toybox project
   367 by Rob LANDLEY (http://www.landley.net/code/toybox/), itself coming from the
   368 Linux kernel (http://www.linux.org/ http://www.kernel.org/), and (heavily)
   369 adapted to my needs.
   370 
   371 The kconfig parsers (conf and mconf) are not installed pre-built, but as
   372 source files. Thus you can have the directory where crosstool-NG is installed,
   373 exported (via NFS or whatever) and have clients with different architectures
   374 use the same crosstool-NG installation, and most notably, the same set of
   375 patches.
   376 
   377 Build scripts |
   378 --------------*
   379 
   380 To Be Written later...