docs/overview.txt
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jun 17 12:11:16 2007 +0000 (2007-06-17)
changeset 168 45811aef4097
parent 152 7f74f42ef2cc
child 174 75f3f975e2ad
permissions -rw-r--r--
scripts/showSamples.sh:
- revert sample dumping to not show the components versions;

docs/overview.txt:
- reorder docs/overview.txt so that configuring comes before running,
- tell about regtest;

Makefile:
config/global.in:
- point to docs/overview.txt for the list of steps;
     1 File.........: overview.txt
     2 Content......: Overview of how ct-ng works.
     3 Copyrigth....: (C) 2007 Yann E. MORIN <yann.morin.1998@anciens.enib.fr>
     4 License......: see COPYING in the root of this package
     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 www.kegel.com/crosstool, and the subversion repository is hosted on google at
    67 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 looong 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.
    81 
    82 The only option left to me was rewrite crosstool from scratch. I decided to go
    83 this way, and name the new implementation ct-ng, standing for crosstool Next
    84 Generation, as many other comunity projects do, and as a wink at the TV series
    85 "Star Trek: The Next Generation". ;-)
    86 
    87 ____________________________
    88                            /
    89 Configuring crosstool-NG  /
    90 _________________________/
    91 
    92 crosstool-NG is configured the same way you configure your Linux kernel: by
    93 using a curses-based menu. It is assumed you now how to handle this.
    94 
    95 To enter the menu, type:
    96   make menuconfig
    97 
    98 Almost every config item has a help entry. Read it carefully.
    99 
   100 String and number options can refer to environment variables. In such a case,
   101 you  must use the shell syntax: ${VAR}. No such option is ever needed by make.
   102 You need to neither single- nor double-quote the string options.
   103 
   104 There are three environment variablea that are computed by crosstool-NG, and
   105 that you can use:
   106 
   107 CT_TARGET:
   108   It represents the target triplet you are building for. You can use it for
   109   example in the installation/prefix directory, such as:
   110     /opt/x-tools/${CT_TARGET}
   111 
   112 CT_TOP_DIR:
   113   The top directory where crosstool-NG sits. You shouldn't need it in most
   114   cases. There is one case where you may need it: if you have local patches
   115   and you store them in your copy of crosstool-NG, you can refer to them
   116   by using CT_TOP_DIR, such as:
   117     ${CT_TOP_DIR}/patches.myproject
   118 
   119 CT_VERSION:
   120   The version of crosstool-NG you are using. Not much help for you, but it's
   121   there if you need it.
   122 
   123 
   124 Interesting config options |
   125 ---------------------------*
   126 
   127 CT_LOCAL_TARBALLS_DIR:
   128   If you already have sone tarballs in a direcotry, enter it here. That will
   129   speed up the retrieving phase, where crosstool-ng would otherwise download
   130   those tarballs.
   131 
   132 CT_PREFIX_DIR:
   133   This is where the toolchain will be installed in (and for now, where it
   134   will run from).
   135 
   136 CT_LOG_FILE:
   137   The file where *all* log messages will go. Keep the default, in goes in
   138   ${CT_PREFIX_DIR}/${CT_TARGET}.log
   139 
   140 CT_TARGET_VENDOR:
   141   An identifier for your toolchain, will take place in the vendor part of the
   142   target triplet. It shall *not* contain spaces or dashes. Usually, keep it
   143   to a one-word string, or use underscores to separate words if you need.
   144   Avoid dots, commas, and special characters.
   145 
   146 CT_TARGET_ALIAS:
   147   An alias for the toolchian. It will be used as a prefix to the toolchain
   148   tools. For example, you will have ${CT_TARGET_ALIAS}-gcc
   149 
   150 ________________________
   151                        /
   152 Running crosstool-NG  /
   153 _____________________/
   154 
   155 ct-ng is configured by a configurator presenting a menu-stuctured set of
   156 options. These options let you specify the way you want your toolchain built,
   157 where you want it installed, what architecture and specific processor it
   158 will support, the version of the components you want to use, etc... The
   159 value for those options are then stored in a configuration file.
   160 
   161 To build the toolchain, simply type:
   162   make
   163 
   164 This will use the above configuration to retrieve, extract and patch the
   165 components, build, install and eventually test your newly built toolchain.
   166 
   167 You are then free to add the toolchain /bin directory in your PATH to use
   168 it at will.
   169 
   170 In any case, you can get some terse help. Just type:
   171   make help
   172 
   173 
   174 Stoping and restarting a build |
   175 -------------------------------*
   176 
   177 If you want to stop the build after a step you are debugging, you can pass the
   178 variable STOP to make:
   179   make STOP=some_step
   180 
   181 Conversely, if you want to restart a build at a specific step you are
   182 debugging, you can pass the RESTART variable to make:
   183   make RESTART=some_step
   184 
   185 The list of steps is, in order of appearence in the build process:
   186   - libc_check_config
   187   - kernel_check_config
   188   - kernel_headers
   189   - binutils
   190   - cc_core_pass_1
   191   - libc_headers
   192   - libc_start_files
   193   - cc_core_pass_2
   194   - libfloat
   195   - libc
   196   - cc
   197   - libc_finish
   198   - tools
   199   - debug
   200 
   201 Alternatively, you can call make with the name of a step to just do that step:
   202   make libc_headers
   203 is equivalent to:
   204   make RESTART=libs_headers STOP=libc_headers
   205 
   206 The shortcuts -step_name and step_name- allow to respectively stop or restart
   207 at that step. Thus:
   208   make -libc_headers        and:    make libc_headers-
   209 are equivalent to:
   210   make STOP=libc_headers    and:    make RESTART=libc_headers
   211 
   212 Note that in order to restart a build, you'll have to say 'Y' to the config
   213 option CT_DEBUG_CT_SAVE_STEPS, and that the previous build effectively went
   214 that far.
   215 
   216 
   217 Testing all toolchains at once |
   218 -------------------------------*
   219 
   220 You can test-build all samples; simply call:
   221   make regtest
   222 
   223 ___________________
   224                   /
   225 Toolchain types  /
   226 ________________/
   227 
   228 There are four kinds of toolchains you could encounter.
   229 
   230 First off, you must understand the following: when it comes to compilers there
   231 are up to four machines involved:
   232   1) the machine configuring the toolchain components: the config machine
   233   2) the machine building the toolchain components:    the build machine
   234   3) the machine running the toolchain:                the host machine
   235   4) the machine the toolchain is building for:        the target machine
   236 
   237 We can most of the time assume that the config machine and the build machine
   238 are the same. Most of the time, this will be true. The only time it isn't
   239 is if you're using distributed compilation (such as distcc). Let's forget
   240 this for the sake of simplicity.
   241 
   242 So we're left with three machines:
   243  - build
   244  - host
   245  - target
   246 
   247 Any toolchain will involve those three machines. You can be as pretty sure of
   248 this as "2 and 2 are 4". Here is how they come into play:
   249 
   250 1) build == host == target
   251     This is a plain native toolchain, targetting the exact same machine as the
   252     one it is built on, and running again on this exact same machine. You have
   253     to build such a toolchain when you want to use an updated component, such
   254     as a newer gcc for example.
   255     ct-ng calls it "native".
   256 
   257 2) build == host != target
   258     This is a classic cross-toolchain, which is expected to be run on the same
   259     machine it is compiled on, and generate code to run on a second machine,
   260     the target.
   261     ct-ng calls it "cross".
   262 
   263 3) build != host == target
   264     Such a toolchain is also a native toolchain, as it targets the same machine
   265     as it runs on. But it is build on another machine. You want such a
   266     toolchain when porting to a new architecture, or if the build machine is
   267     much faster than the host machine.
   268     ct-ng calls it "cross-native".
   269 
   270 4) build != host != target
   271     This one is called a canadian-toolchain (*), and is tricky. The three
   272     machines in play are different. You might want such a toolchain if you
   273     have a fast build machine, but the users will use it on another machine,
   274     and will produce code to run on a third machine.
   275     ct-ng calls it "canadian".
   276 
   277 ct-ng can build all these kinds of toolchains (or is aiming at it, anyway!)
   278 
   279 (*) The term Canadian Cross came about because at the time that these issues
   280     were all being hashed out, Canada had three national political parties.
   281     http://en.wikipedia.org/wiki/Cross_compiler
   282 
   283 _____________
   284             /
   285 Internals  /
   286 __________/
   287 
   288 Internally, crosstool-NG is script-based. To ease usage, the frontend is
   289 Makefile-based.
   290 
   291 Makefile front-end |
   292 -------------------*
   293 
   294 The Makefile defines a set of rules to call each action. You can get the
   295 list, along with some terse description, by typing "make help" in your
   296 favourite command line.
   297 
   298 The Makefile sets the version variable from the version file in ${CT_TOP_DIR}
   299 which is then available to others in the CT_VERSION environment variable.
   300 
   301 The kconfig language is a hacked version, vampirised from the toybox project
   302 by Rob LANDLEY (http://www.landley.net/code/toybox/), adapted to my needs.
   303