docs/overview.txt
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jun 17 14:51:37 2007 +0000 (2007-06-17)
changeset 174 75f3f975e2ad
parent 168 45811aef4097
child 181 ff64ca4ebe48
permissions -rw-r--r--
The log file is no longer configurable: it is always "${CT_PREFIX_DIR}/build.log".
Add an option to compress the log file upon successfull build.
Make rendering the toolchain read-only optional.
A few eye-candy fixes.
yann@1
     1
File.........: overview.txt
yann@1
     2
Content......: Overview of how ct-ng works.
yann@92
     3
Copyrigth....: (C) 2007 Yann E. MORIN <yann.morin.1998@anciens.enib.fr>
yann@1
     4
License......: see COPYING in the root of this package
yann@92
     5
yann@1
     6
________________
yann@1
     7
               /
yann@1
     8
Introduction  /
yann@1
     9
_____________/
yann@1
    10
yann@1
    11
crosstool-NG aims at building toolchains. Toolchains are an essential component
yann@1
    12
in a software development project. It will compile, assemble and link the code
yann@1
    13
that is being developped. Some pieces of the toolchain will eventually end up
yann@1
    14
in the resulting binary/ies: static libraries are but an example.
yann@1
    15
yann@1
    16
So, a toolchain is a very sensitive piece of software, as any bug in one of the
yann@1
    17
components, or a poorly configured component, can lead to execution problems,
yann@1
    18
ranging from poor performance, to applications ending unexpectedly, to
yann@1
    19
mis-behaving software (which more than often is hard to detect), to hardware
yann@1
    20
damage, or even to human risks (which is more than regretable).
yann@1
    21
yann@1
    22
Toolchains are made of different piece of software, each being quite complex
yann@1
    23
and requiring specially crafted options to build and work seamlessly. This
yann@1
    24
is usually not that easy, even in the not-so-trivial case of native toolchains.
yann@1
    25
The work reaches a higher degree of complexity when it comes to cross-
yann@40
    26
compilation, where it can become quite a nightmare...
yann@1
    27
yann@40
    28
Some cross-toolchains exist on the internet, and can be used for general
yann@1
    29
development, but they have a number of limitations:
yann@1
    30
  - they can be general purpose, in that they are configured for the majority:
yann@1
    31
    no optimisation for your specific target,
yann@1
    32
  - they can be prepared for a specific target and thus are not easy to use,
yann@1
    33
    nor optimised for, or even supporting your target,
yann@1
    34
  - they often are using ageing components (compiler, C library, etc...) not
yann@1
    35
    supporting special features of your shiny new processor;
yann@1
    36
On the other side, these toolchain offer some advantages:
yann@1
    37
  - they are ready to use and quite easy to install and setup,
yann@1
    38
  - they are proven if used by a wide community.
yann@1
    39
yann@1
    40
But once you want to get all the juice out of your specific hardware, you will
yann@1
    41
want to build your own toolchain. This is where crosstool-ng comes into play.
yann@1
    42
yann@1
    43
There are also a number of tools that builds toolchains for specific needs,
yann@1
    44
which is not really scalable. Examples are:
yann@1
    45
  - buildroot (buildroot.uclibc.org) whose main puprpose is to build root file
yann@1
    46
    systems, hence the name. But once you have your toolchain with buildroot,
yann@1
    47
    part of it is installed in the root-to-be, so if you want to build a whole
yann@1
    48
    new root, you either have to save the existing one as a template and
yann@1
    49
    restore it later, or restart again from scratch. This is not convenient,
yann@1
    50
  - ptxdist (www.pengutronix.de/software/ptxdist), whose purpose is very
yann@1
    51
    similar to buildroot,
yann@1
    52
  - other projects (openembeded.org for example), which is again used to
yann@1
    53
    build root file systems.
yann@1
    54
yann@1
    55
crosstool-NG is really targetted at building toolchains, and only toolchains.
yann@1
    56
It is then up to you to use it the way you want.
yann@1
    57
yann@1
    58
___________
yann@1
    59
          /
yann@1
    60
History  /
yann@1
    61
________/
yann@1
    62
yann@1
    63
crosstool was first 'conceived' by Dan Kegel, which offered it to the community,
yann@1
    64
as a set of scripts, a repository of patches, and some pre-configured, general
yann@1
    65
purpose setup files to be used to configure crosstool. This is available at
yann@1
    66
www.kegel.com/crosstool, and the subversion repository is hosted on google at
yann@1
    67
http://code.google.com/p/crosstool/.
yann@1
    68
yann@1
    69
At the time of writing, crosstool only supports building with one C library,
yann@1
    70
namely glibc, and one C compiler, gcc; it is cripled with historical support
yann@92
    71
for legacy components, and is some kind of a mess to upgrade. Also, submited
yann@92
    72
patches take a looong time before they are integrated mainline.
yann@1
    73
yann@1
    74
I once managed to add support for uClibc-based toolchains, but it did not make
yann@1
    75
into mainline, mostly because I don't have time to port the patch forward to
yann@1
    76
the new versions, due in part to the big effort it was taking.
yann@1
    77
yann@1
    78
So I decided to clean up crosstool in the state it was, re-order the things
yann@1
    79
in place, and add appropriate support for what I needed, that is uClibc
yann@1
    80
support.
yann@1
    81
yann@1
    82
The only option left to me was rewrite crosstool from scratch. I decided to go
yann@1
    83
this way, and name the new implementation ct-ng, standing for crosstool Next
yann@1
    84
Generation, as many other comunity projects do, and as a wink at the TV series
yann@1
    85
"Star Trek: The Next Generation". ;-)
yann@1
    86
yann@168
    87
____________________________
yann@168
    88
                           /
yann@168
    89
Configuring crosstool-NG  /
yann@168
    90
_________________________/
yann@168
    91
yann@168
    92
crosstool-NG is configured the same way you configure your Linux kernel: by
yann@168
    93
using a curses-based menu. It is assumed you now how to handle this.
yann@168
    94
yann@168
    95
To enter the menu, type:
yann@168
    96
  make menuconfig
yann@168
    97
yann@168
    98
Almost every config item has a help entry. Read it carefully.
yann@168
    99
yann@168
   100
String and number options can refer to environment variables. In such a case,
yann@168
   101
you  must use the shell syntax: ${VAR}. No such option is ever needed by make.
yann@168
   102
You need to neither single- nor double-quote the string options.
yann@168
   103
yann@168
   104
There are three environment variablea that are computed by crosstool-NG, and
yann@168
   105
that you can use:
yann@168
   106
yann@168
   107
CT_TARGET:
yann@168
   108
  It represents the target triplet you are building for. You can use it for
yann@168
   109
  example in the installation/prefix directory, such as:
yann@168
   110
    /opt/x-tools/${CT_TARGET}
yann@168
   111
yann@168
   112
CT_TOP_DIR:
yann@168
   113
  The top directory where crosstool-NG sits. You shouldn't need it in most
yann@168
   114
  cases. There is one case where you may need it: if you have local patches
yann@168
   115
  and you store them in your copy of crosstool-NG, you can refer to them
yann@168
   116
  by using CT_TOP_DIR, such as:
yann@168
   117
    ${CT_TOP_DIR}/patches.myproject
yann@168
   118
yann@168
   119
CT_VERSION:
yann@168
   120
  The version of crosstool-NG you are using. Not much help for you, but it's
yann@168
   121
  there if you need it.
yann@168
   122
yann@168
   123
yann@168
   124
Interesting config options |
yann@168
   125
---------------------------*
yann@168
   126
yann@168
   127
CT_LOCAL_TARBALLS_DIR:
yann@168
   128
  If you already have sone tarballs in a direcotry, enter it here. That will
yann@168
   129
  speed up the retrieving phase, where crosstool-ng would otherwise download
yann@168
   130
  those tarballs.
yann@168
   131
yann@168
   132
CT_PREFIX_DIR:
yann@168
   133
  This is where the toolchain will be installed in (and for now, where it
yann@168
   134
  will run from).
yann@168
   135
yann@168
   136
CT_TARGET_VENDOR:
yann@168
   137
  An identifier for your toolchain, will take place in the vendor part of the
yann@168
   138
  target triplet. It shall *not* contain spaces or dashes. Usually, keep it
yann@168
   139
  to a one-word string, or use underscores to separate words if you need.
yann@168
   140
  Avoid dots, commas, and special characters.
yann@168
   141
yann@168
   142
CT_TARGET_ALIAS:
yann@168
   143
  An alias for the toolchian. It will be used as a prefix to the toolchain
yann@168
   144
  tools. For example, you will have ${CT_TARGET_ALIAS}-gcc
yann@168
   145
yann@168
   146
________________________
yann@168
   147
                       /
yann@168
   148
Running crosstool-NG  /
yann@168
   149
_____________________/
yann@1
   150
yann@1
   151
ct-ng is configured by a configurator presenting a menu-stuctured set of
yann@1
   152
options. These options let you specify the way you want your toolchain built,
yann@1
   153
where you want it installed, what architecture and specific processor it
yann@1
   154
will support, the version of the components you want to use, etc... The
yann@1
   155
value for those options are then stored in a configuration file.
yann@1
   156
yann@168
   157
To build the toolchain, simply type:
yann@135
   158
  make
yann@135
   159
yann@135
   160
This will use the above configuration to retrieve, extract and patch the
yann@135
   161
components, build, install and eventually test your newly built toolchain.
yann@1
   162
yann@1
   163
You are then free to add the toolchain /bin directory in your PATH to use
yann@1
   164
it at will.
yann@1
   165
yann@135
   166
In any case, you can get some terse help. Just type:
yann@135
   167
  make help
yann@135
   168
yann@135
   169
yann@135
   170
Stoping and restarting a build |
yann@135
   171
-------------------------------*
yann@135
   172
yann@135
   173
If you want to stop the build after a step you are debugging, you can pass the
yann@135
   174
variable STOP to make:
yann@135
   175
  make STOP=some_step
yann@135
   176
yann@135
   177
Conversely, if you want to restart a build at a specific step you are
yann@135
   178
debugging, you can pass the RESTART variable to make:
yann@135
   179
  make RESTART=some_step
yann@135
   180
yann@135
   181
The list of steps is, in order of appearence in the build process:
yann@135
   182
  - libc_check_config
yann@135
   183
  - kernel_check_config
yann@135
   184
  - kernel_headers
yann@135
   185
  - binutils
yann@152
   186
  - cc_core_pass_1
yann@135
   187
  - libc_headers
yann@136
   188
  - libc_start_files
yann@152
   189
  - cc_core_pass_2
yann@135
   190
  - libfloat
yann@135
   191
  - libc
yann@135
   192
  - cc
yann@135
   193
  - libc_finish
yann@148
   194
  - tools
yann@135
   195
  - debug
yann@135
   196
yann@136
   197
Alternatively, you can call make with the name of a step to just do that step:
yann@136
   198
  make libc_headers
yann@136
   199
is equivalent to:
yann@136
   200
  make RESTART=libs_headers STOP=libc_headers
yann@136
   201
yann@136
   202
The shortcuts -step_name and step_name- allow to respectively stop or restart
yann@136
   203
at that step. Thus:
yann@148
   204
  make -libc_headers        and:    make libc_headers-
yann@136
   205
are equivalent to:
yann@148
   206
  make STOP=libc_headers    and:    make RESTART=libc_headers
yann@136
   207
yann@168
   208
Note that in order to restart a build, you'll have to say 'Y' to the config
yann@168
   209
option CT_DEBUG_CT_SAVE_STEPS, and that the previous build effectively went
yann@168
   210
that far.
yann@92
   211
yann@92
   212
yann@168
   213
Testing all toolchains at once |
yann@168
   214
-------------------------------*
yann@92
   215
yann@168
   216
You can test-build all samples; simply call:
yann@168
   217
  make regtest
yann@40
   218
yann@40
   219
___________________
yann@40
   220
                  /
yann@40
   221
Toolchain types  /
yann@40
   222
________________/
yann@40
   223
yann@40
   224
There are four kinds of toolchains you could encounter.
yann@40
   225
yann@40
   226
First off, you must understand the following: when it comes to compilers there
yann@40
   227
are up to four machines involved:
yann@40
   228
  1) the machine configuring the toolchain components: the config machine
yann@40
   229
  2) the machine building the toolchain components:    the build machine
yann@40
   230
  3) the machine running the toolchain:                the host machine
yann@40
   231
  4) the machine the toolchain is building for:        the target machine
yann@40
   232
yann@40
   233
We can most of the time assume that the config machine and the build machine
yann@40
   234
are the same. Most of the time, this will be true. The only time it isn't
yann@40
   235
is if you're using distributed compilation (such as distcc). Let's forget
yann@40
   236
this for the sake of simplicity.
yann@40
   237
yann@40
   238
So we're left with three machines:
yann@40
   239
 - build
yann@40
   240
 - host
yann@40
   241
 - target
yann@40
   242
yann@40
   243
Any toolchain will involve those three machines. You can be as pretty sure of
yann@40
   244
this as "2 and 2 are 4". Here is how they come into play:
yann@40
   245
yann@40
   246
1) build == host == target
yann@40
   247
    This is a plain native toolchain, targetting the exact same machine as the
yann@40
   248
    one it is built on, and running again on this exact same machine. You have
yann@40
   249
    to build such a toolchain when you want to use an updated component, such
yann@40
   250
    as a newer gcc for example.
yann@40
   251
    ct-ng calls it "native".
yann@40
   252
yann@40
   253
2) build == host != target
yann@40
   254
    This is a classic cross-toolchain, which is expected to be run on the same
yann@40
   255
    machine it is compiled on, and generate code to run on a second machine,
yann@40
   256
    the target.
yann@40
   257
    ct-ng calls it "cross".
yann@40
   258
yann@40
   259
3) build != host == target
yann@40
   260
    Such a toolchain is also a native toolchain, as it targets the same machine
yann@40
   261
    as it runs on. But it is build on another machine. You want such a
yann@40
   262
    toolchain when porting to a new architecture, or if the build machine is
yann@40
   263
    much faster than the host machine.
yann@40
   264
    ct-ng calls it "cross-native".
yann@40
   265
yann@40
   266
4) build != host != target
yann@92
   267
    This one is called a canadian-toolchain (*), and is tricky. The three
yann@40
   268
    machines in play are different. You might want such a toolchain if you
yann@40
   269
    have a fast build machine, but the users will use it on another machine,
yann@40
   270
    and will produce code to run on a third machine.
yann@40
   271
    ct-ng calls it "canadian".
yann@40
   272
yann@40
   273
ct-ng can build all these kinds of toolchains (or is aiming at it, anyway!)
yann@40
   274
yann@40
   275
(*) The term Canadian Cross came about because at the time that these issues
yann@40
   276
    were all being hashed out, Canada had three national political parties.
yann@40
   277
    http://en.wikipedia.org/wiki/Cross_compiler
yann@40
   278
yann@1
   279
_____________
yann@1
   280
            /
yann@1
   281
Internals  /
yann@1
   282
__________/
yann@1
   283
yann@92
   284
Internally, crosstool-NG is script-based. To ease usage, the frontend is
yann@92
   285
Makefile-based.
yann@92
   286
yann@92
   287
Makefile front-end |
yann@92
   288
-------------------*
yann@92
   289
yann@92
   290
The Makefile defines a set of rules to call each action. You can get the
yann@92
   291
list, along with some terse description, by typing "make help" in your
yann@92
   292
favourite command line.
yann@92
   293
yann@92
   294
The Makefile sets the version variable from the version file in ${CT_TOP_DIR}
yann@92
   295
which is then available to others in the CT_VERSION environment variable.
yann@92
   296
yann@92
   297
The kconfig language is a hacked version, vampirised from the toybox project
yann@92
   298
by Rob LANDLEY (http://www.landley.net/code/toybox/), adapted to my needs.
yann@92
   299