docs/overview.txt
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Oct 10 11:24:31 2009 +0200 (2009-10-10)
changeset 1574 07684767f873
parent 1554 3b8df55987ae
child 1575 eb92c99b17cd
permissions -rw-r--r--
docs: configure no longer accepts --with-contrib

It's been a while that configure does not recognise --with-contrib.
Applying contibutions is to be done manually, using patch.
yann@1
     1
File.........: overview.txt
yann@197
     2
Content......: Overview of how crosstool-NG works.
yann@92
     3
Copyrigth....: (C) 2007 Yann E. MORIN <yann.morin.1998@anciens.enib.fr>
yann@192
     4
License......: Creative Commons Attribution Share Alike (CC-by-sa), v2.5
yann@92
     5
yann@628
     6
____________________
yann@628
     7
                   /
yann@628
     8
Table Of Content  /
yann@628
     9
_________________/
yann@628
    10
yann@628
    11
yann@628
    12
Introduction
yann@628
    13
History
yann@628
    14
Installing crosstool-NG
yann@628
    15
  Install method
yann@628
    16
  The hacker's way
yann@1048
    17
  Preparing for packaging
yann@837
    18
  Shell completion
yann@628
    19
  Contributed code
yann@628
    20
Configuring crosstool-NG
yann@628
    21
  Interesting config options
yann@628
    22
  Re-building an existing toolchain
yann@628
    23
Running crosstool-NG
yann@628
    24
  Stopping and restarting a build
yann@628
    25
  Testing all toolchains at once
yann@628
    26
  Overriding the number of // jobs
yann@1491
    27
  Note on // jobs
yann@1493
    28
  Tools wrapper
yann@628
    29
Using the toolchain
yann@1554
    30
  The 'populate' script
yann@628
    31
Toolchain types
yann@1551
    32
  Seemingly-native toolchains
yann@628
    33
Internals
yann@628
    34
  Makefile front-end
yann@628
    35
  Kconfig parser
yann@628
    36
  Architecture-specific
yann@628
    37
  Adding a new version of a component
yann@628
    38
  Build scripts
yann@628
    39
yann@1
    40
________________
yann@1
    41
               /
yann@1
    42
Introduction  /
yann@1
    43
_____________/
yann@1
    44
yann@1
    45
crosstool-NG aims at building toolchains. Toolchains are an essential component
yann@1
    46
in a software development project. It will compile, assemble and link the code
rpjday@436
    47
that is being developed. Some pieces of the toolchain will eventually end up
yann@1
    48
in the resulting binary/ies: static libraries are but an example.
yann@1
    49
yann@1
    50
So, a toolchain is a very sensitive piece of software, as any bug in one of the
yann@1
    51
components, or a poorly configured component, can lead to execution problems,
yann@1
    52
ranging from poor performance, to applications ending unexpectedly, to
yann@1
    53
mis-behaving software (which more than often is hard to detect), to hardware
rpjday@436
    54
damage, or even to human risks (which is more than regrettable).
yann@1
    55
yann@1
    56
Toolchains are made of different piece of software, each being quite complex
yann@1
    57
and requiring specially crafted options to build and work seamlessly. This
yann@1
    58
is usually not that easy, even in the not-so-trivial case of native toolchains.
yann@1
    59
The work reaches a higher degree of complexity when it comes to cross-
yann@40
    60
compilation, where it can become quite a nightmare...
yann@1
    61
yann@40
    62
Some cross-toolchains exist on the internet, and can be used for general
yann@1
    63
development, but they have a number of limitations:
yann@1
    64
  - they can be general purpose, in that they are configured for the majority:
yann@1
    65
    no optimisation for your specific target,
yann@1
    66
  - they can be prepared for a specific target and thus are not easy to use,
yann@1
    67
    nor optimised for, or even supporting your target,
rpjday@436
    68
  - they often are using aging components (compiler, C library, etc...) not
yann@1
    69
    supporting special features of your shiny new processor;
yann@1
    70
On the other side, these toolchain offer some advantages:
yann@1
    71
  - they are ready to use and quite easy to install and setup,
yann@1
    72
  - they are proven if used by a wide community.
yann@1
    73
yann@1
    74
But once you want to get all the juice out of your specific hardware, you will
yann@197
    75
want to build your own toolchain. This is where crosstool-NG comes into play.
yann@1
    76
rpjday@436
    77
There are also a number of tools that build toolchains for specific needs,
rpjday@436
    78
which are not really scalable. Examples are:
rpjday@436
    79
  - buildroot (buildroot.uclibc.org) whose main purpose is to build root file
yann@1
    80
    systems, hence the name. But once you have your toolchain with buildroot,
yann@1
    81
    part of it is installed in the root-to-be, so if you want to build a whole
yann@1
    82
    new root, you either have to save the existing one as a template and
yann@1
    83
    restore it later, or restart again from scratch. This is not convenient,
yann@1
    84
  - ptxdist (www.pengutronix.de/software/ptxdist), whose purpose is very
yann@1
    85
    similar to buildroot,
yann@702
    86
  - other projects (openembedded.org for example), which are again used to
yann@1
    87
    build root file systems.
yann@1
    88
rpjday@436
    89
crosstool-NG is really targeted at building toolchains, and only toolchains.
yann@1
    90
It is then up to you to use it the way you want.
yann@1
    91
yann@1
    92
___________
yann@1
    93
          /
yann@1
    94
History  /
yann@1
    95
________/
yann@1
    96
rpjday@436
    97
crosstool was first 'conceived' by Dan Kegel, who offered it to the community
yann@1
    98
as a set of scripts, a repository of patches, and some pre-configured, general
yann@1
    99
purpose setup files to be used to configure crosstool. This is available at
yann@203
   100
http://www.kegel.com/crosstool, and the subversion repository is hosted on
yann@203
   101
google at http://code.google.com/p/crosstool/.
yann@1
   102
yann@1
   103
I once managed to add support for uClibc-based toolchains, but it did not make
yann@437
   104
into mainline, mostly because I didn't have time to port the patch forward to
yann@1
   105
the new versions, due in part to the big effort it was taking.
yann@1
   106
yann@1
   107
So I decided to clean up crosstool in the state it was, re-order the things
yann@437
   108
in place, add appropriate support for what I needed, that is uClibc support
yann@437
   109
and a menu-driven configuration, named the new implementation crosstool-NG,
yann@437
   110
(standing for crosstool Next Generation, as many other comunity projects do,
yann@437
   111
and as a wink at the TV series "Star Trek: The Next Generation" ;-) ) and
yann@437
   112
made it available to the community, in case it was of interest to any one.
yann@1
   113
yann@294
   114
___________________________
yann@294
   115
                          /
yann@294
   116
Installing crosstool-NG  /
yann@294
   117
________________________/
yann@294
   118
yann@294
   119
There are two ways you can use crosstool-NG:
yann@294
   120
 - build and install it, then get rid of the sources like you'd do for most
yann@294
   121
   programs,
yann@294
   122
 - or only build it and run from the source directory.
yann@294
   123
yann@294
   124
The former should be used if you got crosstool-NG from a packaged tarball, see
rpjday@436
   125
"Install method", below, while the latter is most useful for developpers that
yann@294
   126
checked the code out from SVN, and want to submit patches, see "The Hacker's
yann@294
   127
way", below.
yann@294
   128
yann@294
   129
Install method |
yann@294
   130
---------------+
yann@294
   131
yann@294
   132
If you go for the install, then you just follow the classical, but yet easy
yann@294
   133
./configure way:
yann@294
   134
  ./configure --prefix=/some/place
yann@294
   135
  make
yann@294
   136
  make install
yann@294
   137
  export PATH="${PATH}:/some/place/bin"
yann@294
   138
yann@294
   139
You can then get rid of crosstool-NG source. Next create a directory to serve
yann@294
   140
as a working place, cd in there and run:
yann@294
   141
  ct-ng help
yann@294
   142
yann@294
   143
See below for complete usage.
yann@294
   144
yann@294
   145
The Hacker's way |
yann@294
   146
-----------------+
yann@294
   147
yann@294
   148
If you go the hacker's way, then the usage is a bit different, although very
yann@294
   149
simple:
yann@294
   150
  ./configure --local
yann@294
   151
  make
yann@294
   152
yann@294
   153
Now, *do not* remove crosstool-NG sources. They are needed to run crosstool-NG!
yann@294
   154
Stay in the directory holding the sources, and run:
yann@294
   155
  ./ct-ng help
yann@294
   156
yann@294
   157
See below for complete usage.
yann@294
   158
yann@1554
   159
Now, provided you used a clone of the repository, you can send me your changes.
yann@1554
   160
See the file README, at the top of crosstool-NG source, for how to submit
yann@1554
   161
changees.
yann@294
   162
yann@1048
   163
Preparing for packaging |
yann@1048
   164
------------------------+
yann@1048
   165
yann@1048
   166
If you plan on packaging crosstool-NG, you surely don't want to install it
yann@1048
   167
in your root file system. The install procedure of crosstool-NG honors the
yann@1048
   168
DESTDIR variable:
yann@1048
   169
yann@1048
   170
  ./configure --prefix=/usr
yann@1048
   171
  make
rpjday@1291
   172
  make DESTDIR=/packaging/place install
yann@1048
   173
yann@837
   174
Shell completion |
yann@837
   175
-----------------+
yann@837
   176
yann@837
   177
crosstool-NG comes with a shell script fragment that defines bash-compatible
yann@837
   178
completion. That shell fragment is currently not installed automatically, but
yann@837
   179
this is planned.
yann@837
   180
yann@837
   181
To install the shell script fragment, you have two options:
yann@837
   182
 - install system-wide, most probably by copying ct-ng.comp into
yann@837
   183
   /etc/bash_completion.d/
yann@837
   184
 - install for a single user, by copying ct-ng.comp into ${HOME}/ and
yann@837
   185
   sourcing this file from your ${HOME}/.bashrc
yann@837
   186
yann@456
   187
Contributed code |
yann@456
   188
-----------------+
yann@456
   189
yann@456
   190
Some people contibuted code that couldn't get merged for various reasons. This
yann@1574
   191
code is available as lzma-compressed patches, in the contrib/ sub-directory.
yann@1574
   192
These patches are to be applied to the source of crosstool-NG, prior to
yann@1574
   193
installing, using something like the following:
yann@1574
   194
  lzcat contrib/foobar.patch.lzma |patch -p1
yann@620
   195
yann@620
   196
There is no guarantee that a particuliar contribution applies to the current
yann@620
   197
version of crosstool-ng, or that it will work at all. Use contributions at
yann@620
   198
your own risk.
yann@620
   199
yann@168
   200
____________________________
yann@168
   201
                           /
yann@168
   202
Configuring crosstool-NG  /
yann@168
   203
_________________________/
yann@168
   204
yann@620
   205
crosstool-NG is configured with a configurator presenting a menu-stuctured set
yann@620
   206
of options. These options let you specify the way you want your toolchain
yann@620
   207
built, where you want it installed, what architecture and specific processor it
yann@277
   208
will support, the version of the components you want to use, etc... The
yann@277
   209
value for those options are then stored in a configuration file.
yann@277
   210
yann@476
   211
The configurator works the same way you configure your Linux kernel. It is
yann@277
   212
assumed you now how to handle this.
yann@168
   213
yann@168
   214
To enter the menu, type:
yann@192
   215
  ct-ng menuconfig
yann@168
   216
yann@203
   217
Almost every config item has a help entry. Read them carefully.
yann@168
   218
yann@168
   219
String and number options can refer to environment variables. In such a case,
yann@192
   220
you must use the shell syntax: ${VAR}. You shall neither single- nor double-
yann@294
   221
quote the string/number options.
yann@168
   222
yann@192
   223
There are three environment variables that are computed by crosstool-NG, and
yann@168
   224
that you can use:
yann@168
   225
yann@168
   226
CT_TARGET:
yann@335
   227
  It represents the target tuple you are building for. You can use it for
yann@168
   228
  example in the installation/prefix directory, such as:
yann@168
   229
    /opt/x-tools/${CT_TARGET}
yann@168
   230
yann@168
   231
CT_TOP_DIR:
yann@182
   232
  The top directory where crosstool-NG is running. You shouldn't need it in
yann@182
   233
  most cases. There is one case where you may need it: if you have local
yann@182
   234
  patches and you store them in your running directory, you can refer to them
yann@168
   235
  by using CT_TOP_DIR, such as:
yann@168
   236
    ${CT_TOP_DIR}/patches.myproject
yann@168
   237
yann@168
   238
CT_VERSION:
yann@192
   239
  The version of crosstool-NG you are using. Not much use for you, but it's
yann@168
   240
  there if you need it.
yann@168
   241
yann@168
   242
Interesting config options |
yann@476
   243
---------------------------+
yann@168
   244
yann@168
   245
CT_LOCAL_TARBALLS_DIR:
yann@277
   246
  If you already have some tarballs in a direcotry, enter it here. That will
yann@197
   247
  speed up the retrieving phase, where crosstool-NG would otherwise download
yann@168
   248
  those tarballs.
yann@168
   249
yann@168
   250
CT_PREFIX_DIR:
yann@168
   251
  This is where the toolchain will be installed in (and for now, where it
yann@437
   252
  will run from). Common use is to add the target tuple in the directory
yann@277
   253
  path, such as (see above):
yann@277
   254
    /opt/x-tools/${CT_TARGET}
yann@168
   255
yann@168
   256
CT_TARGET_VENDOR:
yann@168
   257
  An identifier for your toolchain, will take place in the vendor part of the
yann@335
   258
  target tuple. It shall *not* contain spaces or dashes. Usually, keep it
yann@168
   259
  to a one-word string, or use underscores to separate words if you need.
yann@168
   260
  Avoid dots, commas, and special characters.
yann@168
   261
yann@168
   262
CT_TARGET_ALIAS:
yann@168
   263
  An alias for the toolchian. It will be used as a prefix to the toolchain
yann@168
   264
  tools. For example, you will have ${CT_TARGET_ALIAS}-gcc
yann@168
   265
yann@246
   266
Also, if you think you don't see enough versions, you can try to enable one of
yann@246
   267
those:
yann@246
   268
yann@246
   269
CT_OBSOLETE:
yann@246
   270
  Show obsolete versions or tools. Most of the time, you don't want to base
yann@246
   271
  your toolchain on too old a version (of gcc, for example). But at times, it
yann@246
   272
  can come handy to use such an old version for regression tests. Those old
yann@1300
   273
  versions are hidden behind CT_OBSOLETE. Those versions (or features) are so
yann@1300
   274
  marked because maintaining support for those in crosstool-NG would be too
yann@1300
   275
  costly, time-wise, and time is dear.
yann@246
   276
yann@246
   277
CT_EXPERIMENTAL:
yann@246
   278
  Show experimental versions or tools. Again, you might not want to base your
yann@246
   279
  toolchain on too recent tools (eg. gcc) for production. But if you need a
yann@246
   280
  feature present only in a recent version, or a new tool, you can find them
yann@1300
   281
  hidden behind CT_EXPERIMENTAL. Those versions (or features) did not (yet)
yann@1300
   282
  receive thorough testing in crosstool-NG, and/or are not mature enough to
yann@1300
   283
  be blindly trusted.
yann@246
   284
yann@276
   285
Re-building an existing toolchain |
yann@276
   286
----------------------------------+
yann@276
   287
yann@276
   288
If you have an existing toolchain, you can re-use the options used to build it
yann@276
   289
to create a new toolchain. That needs a very little bit of effort on your side
yann@894
   290
but is quite easy. The options to build a toolchain are saved with the
yann@894
   291
toolchain, and you can retrieve this configuration by running:
yann@894
   292
  ${CT_TARGET}-config
yann@276
   293
yann@894
   294
This will dump the configuration to stdout, so to rebuild a toolchain with this
yann@894
   295
configuration, the following is all you need to do:
yann@894
   296
  ${CT_TARGET}-config >.config
yann@1098
   297
  ct-ng oldconfig
yann@276
   298
yann@894
   299
Then, you can review and change the configuration by running:
yann@894
   300
  ct-ng menuconfig
yann@276
   301
yann@168
   302
________________________
yann@168
   303
                       /
yann@168
   304
Running crosstool-NG  /
yann@168
   305
_____________________/
yann@1
   306
yann@168
   307
To build the toolchain, simply type:
yann@203
   308
  ct-ng build
yann@135
   309
yann@135
   310
This will use the above configuration to retrieve, extract and patch the
yann@135
   311
components, build, install and eventually test your newly built toolchain.
yann@1
   312
yann@1
   313
You are then free to add the toolchain /bin directory in your PATH to use
yann@1
   314
it at will.
yann@1
   315
yann@135
   316
In any case, you can get some terse help. Just type:
yann@192
   317
  ct-ng help
yann@203
   318
or:
yann@203
   319
  man 1 ct-ng
yann@135
   320
rpjday@436
   321
Stopping and restarting a build |
yann@476
   322
--------------------------------+
yann@135
   323
yann@135
   324
If you want to stop the build after a step you are debugging, you can pass the
yann@135
   325
variable STOP to make:
yann@192
   326
  ct-ng STOP=some_step
yann@135
   327
yann@135
   328
Conversely, if you want to restart a build at a specific step you are
yann@135
   329
debugging, you can pass the RESTART variable to make:
yann@192
   330
  ct-ng RESTART=some_step
yann@135
   331
yann@136
   332
Alternatively, you can call make with the name of a step to just do that step:
yann@192
   333
  ct-ng libc_headers
yann@136
   334
is equivalent to:
yann@620
   335
  ct-ng RESTART=libc_headers STOP=libc_headers
yann@136
   336
yann@304
   337
The shortcuts +step_name and step_name+ allow to respectively stop or restart
yann@136
   338
at that step. Thus:
yann@304
   339
  ct-ng +libc_headers        and:    ct-ng libc_headers+
yann@136
   340
are equivalent to:
yann@192
   341
  ct-ng STOP=libc_headers    and:    ct-ng RESTART=libc_headers
yann@136
   342
yann@181
   343
To obtain the list of acceptable steps, please call:
yann@544
   344
  ct-ng list-steps
yann@181
   345
yann@168
   346
Note that in order to restart a build, you'll have to say 'Y' to the config
yann@168
   347
option CT_DEBUG_CT_SAVE_STEPS, and that the previous build effectively went
yann@168
   348
that far.
yann@92
   349
yann@1025
   350
Building all toolchains at once |
yann@1025
   351
--------------------------------+
yann@92
   352
yann@1025
   353
You can build all samples; simply call:
yann@1025
   354
  ct-ng build-all
yann@40
   355
yann@335
   356
Overriding the number of // jobs |
yann@476
   357
---------------------------------+
yann@335
   358
yann@335
   359
If you want to override the number of jobs to run in // (the -j option to
yann@335
   360
make), you can either re-enter the menuconfig, or simply add it on the command
yann@335
   361
line, as such:
yann@335
   362
  ct-ng build.4
yann@335
   363
yann@335
   364
which tells crosstool-NG to override the number of // jobs to 4.
yann@335
   365
yann@335
   366
You can see the actions that support overriding the number of // jobs in
yann@335
   367
the help menu. Those are the ones with [.#] after them (eg. build[.#] or
yann@1025
   368
build-all[.#], and so on...).
yann@1025
   369
yann@1025
   370
Note on // jobs |
yann@1025
   371
----------------+
yann@1025
   372
yann@1025
   373
The crosstool-NG script 'ct-ng' is a Makefile-script. It does *not* execute
yann@1025
   374
in parallel (there is not much to gain). When speaking of // jobs, we are
yann@1025
   375
refering to the number of // jobs when making the *components*. That is, we
yann@1025
   376
speak of the number of // jobs used to build gcc, glibc, and so on...
yann@1025
   377
yann@1493
   378
Tools wrapper |
yann@1493
   379
--------------+
yann@1493
   380
yann@1493
   381
Starting with gcc-4.3 come two new dependencies: GMP and MPFR. With gcc-4.4,
yann@1493
   382
come three new ones: GMP, PPL and CLooG/ppl. These are libraries that enable
yann@1493
   383
advanced features to gcc. Additionally, some of the libraries can be used by
yann@1493
   384
binutils and gdb. Unfortunately, not all systems on which crosstool-NG runs
yann@1493
   385
have all of those libraries. And for those that do, the versions of those
yann@1493
   386
libraries may be older than the version required by gcc.
yann@1493
   387
yann@1493
   388
This is why crosstool-NG builds its own set of libraries as part of the
yann@1493
   389
toolchain.
yann@1493
   390
yann@1493
   391
The libraries are built as shared libraries, because building them as static
yann@1493
   392
libraries has some short-comings. This poses no problem at build time, as
yann@1513
   393
crosstool-NG correctly points gcc (and binutils and gdb) to the correct
yann@1493
   394
place where our own version of the libraries are installed. But it poses
yann@1493
   395
a problem when gcc et al. are run: the place where the libraries are is most
yann@1493
   396
probably not known to the host dynamic linker. Still worse, if the host system
yann@1493
   397
has its own versions, then ld.so would load the wrong library!
yann@1493
   398
yann@1493
   399
So we have to force the dynamic linker to load the correct version. We do this
yann@1493
   400
by using the LD_LIBRARY_PATH variable, that informs the dynamic linker where
yann@1493
   401
to look for shared libraries prior to searching its standard places. But we
yann@1493
   402
can't impose that burden on all the system (because it'd be a nightmare to
yann@1513
   403
configure, and because two toolchains on the same system may use different
yann@1493
   404
versions of the libraries); so we have to do it on a per-toolchain basis.
yann@1493
   405
yann@1493
   406
So we rename all binaries of the toolchain (by adding a dot '.' as their first
yann@1493
   407
character), and add a small program, the so-called "tools wrapper", that
yann@1493
   408
correctly sets LD_LIBRARY_PATH prior to running the real tool.
yann@1493
   409
yann@1493
   410
First, the wrapper was written as a POSIX-compliant shell script. That shell
yann@1493
   411
script is very simple, if not trivial, and works great. The only drawback is
yann@1493
   412
that it does not work on host systems that lack a shell, for example the
yann@1493
   413
MingW32 environment. To solve the issue, the wrapper has been re-written in C,
yann@1493
   414
and compiled at build time. This C wrapper is much more complex than the shell
yann@1493
   415
script, and although it sems to be working, it's been only lightly tested.
yann@1493
   416
Some of the expected short-comings with this C wrapper are;
yann@1493
   417
 - multi-byte file names may not be handled correctly
yann@1493
   418
 - it's really big for what it does
yann@1493
   419
yann@1493
   420
So, the default wrapper installed with your toolchain is the shell script.
yann@1493
   421
If you know that your system is missing a shell, then you shall use the C
yann@1493
   422
wrapper (and report back whether it works, or does not work, for you).
yann@1493
   423
yann@335
   424
yann@227
   425
_______________________
yann@227
   426
                      /
yann@227
   427
Using the toolchain  /
yann@227
   428
____________________/
yann@227
   429
yann@227
   430
Using the toolchain is as simple as adding the toolchain's bin directory in
yann@227
   431
your PATH, such as:
yann@227
   432
  export PATH="${PATH}:/your/toolchain/path/bin"
yann@227
   433
yann@335
   434
and then using the target tuple to tell the build systems to use your
yann@227
   435
toolchain:
yann@335
   436
  ./configure --target=your-target-tuple
yann@294
   437
or
yann@335
   438
  make CC=your-target-tuple-gcc
yann@294
   439
or
yann@335
   440
  make CROSS_COMPILE=your-target-tuple-
yann@294
   441
and so on...
yann@227
   442
yann@476
   443
It is strongly advised not to use the toolchain sys-root directory as an
yann@620
   444
install directory for your programs/packages. If you do so, you will not be
yann@476
   445
able to use your toolchain for another project. It is even strongly advised
yann@476
   446
that your toolchain is chmod-ed to read-only once successfully build, so that
yann@620
   447
you don't go polluting your toolchain with your programs/packages' files.
yann@476
   448
yann@476
   449
Thus, when you build a program/package, install it in a separate directory,
yann@476
   450
eg. /your/root. This directory is the /image/ of what would be in the root file
yann@620
   451
system of your target, and will contain all that your programs/packages have
yann@476
   452
installed.
yann@476
   453
Yann@1405
   454
The 'populate' script |
Yann@1405
   455
----------------------+
Yann@1405
   456
yann@227
   457
When your root directory is ready, it is still missing some important bits: the
yann@227
   458
toolchain's libraries. To populate your root directory with those libs, just
yann@227
   459
run:
yann@335
   460
  your-target-tuple-populate -s /your/root -d /your/root-populated
yann@227
   461
yann@227
   462
This will copy /your/root into /your/root-populated, and put the needed and only
yann@227
   463
the needed libraries there. Thus you don't polute /your/root with any cruft that
yann@227
   464
would no longer be needed should you have to remove stuff. /your/root always
yann@227
   465
contains only those things you install in it.
yann@227
   466
yann@227
   467
You can then use /your/root-populated to build up your file system image, a
yann@227
   468
tarball, or to NFS-mount it from your target, or whatever you need.
yann@227
   469
Yann@1405
   470
The populate script accepts the following options:
yann@294
   471
Yann@1405
   472
 -s src_dir
Yann@1405
   473
    Use 'src_dir' as the un-populated root directory.
yann@294
   474
Yann@1405
   475
 -d dst_dir
Yann@1405
   476
    Put the populated root directory in 'dst_dir'.
Yann@1405
   477
Yann@1405
   478
 -l lib1 [...]
Yann@1405
   479
    Always add specified libraries.
Yann@1405
   480
Yann@1405
   481
 -L file
Yann@1405
   482
    Always add libraries listed in 'file'.
yann@294
   483
yann@294
   484
 -f
Yann@1405
   485
    Remove 'dst_dir' if it previously existed; continue even if any library
Yann@1405
   486
    specified with -l or -L is missing.
yann@294
   487
yann@294
   488
 -v
yann@294
   489
    Be verbose, and tell what's going on (you can see exactly where libs are
yann@294
   490
    coming from).
yann@294
   491
yann@294
   492
 -h
Yann@1405
   493
    Print the help.
Yann@1405
   494
Yann@1405
   495
See 'your-target-tuple-populate -h' for more information on the options.
yann@294
   496
Yann@1406
   497
Here is how populate works:
Yann@1406
   498
Yann@1406
   499
  1) performs some sanity checks:
Yann@1406
   500
     - src_dir and dst_dir are specified
Yann@1406
   501
     - src_dir exists
Yann@1406
   502
     - unless forced, dst_dir does not exist
Yann@1406
   503
     - src_dir != dst_dir
Yann@1406
   504
Yann@1406
   505
  2) copy src_dir to dst_dir
Yann@1406
   506
Yann@1406
   507
  3) add forced libraries to dst_dir
Yann@1406
   508
     - build the list from -l and -L options
Yann@1406
   509
     - get forced libraries from the sysroot (see below for heuristics)
Yann@1406
   510
       - abort on the first missing library, unless -f is specified
Yann@1406
   511
Yann@1406
   512
  4) add all missing libraries to dst_dir
Yann@1406
   513
     - scan dst_dir for every ELF files that are 'executable' or
Yann@1406
   514
       'shared object'
Yann@1406
   515
     - list the "NEEDED Shared library" fields
Yann@1406
   516
       - check if the library is already in dst_dir/lib or dst_dir/usr/lib
Yann@1406
   517
       - if not, get the library from the sysroot
Yann@1406
   518
         - if it's in sysroot/lib, copy it to dst_dir/lib
Yann@1406
   519
         - if it's in sysroot/usr/lib, copy it to dst_dir/usr/lib
Yann@1406
   520
         - in both cases, use the SONAME of the library to create the file
Yann@1406
   521
           in dst_dir
Yann@1406
   522
         - if it was not found in the sysroot, this is an error.
Yann@1406
   523
yann@40
   524
___________________
yann@40
   525
                  /
yann@40
   526
Toolchain types  /
yann@40
   527
________________/
yann@40
   528
yann@40
   529
There are four kinds of toolchains you could encounter.
yann@40
   530
yann@40
   531
First off, you must understand the following: when it comes to compilers there
yann@40
   532
are up to four machines involved:
yann@40
   533
  1) the machine configuring the toolchain components: the config machine
yann@40
   534
  2) the machine building the toolchain components:    the build machine
yann@40
   535
  3) the machine running the toolchain:                the host machine
yann@203
   536
  4) the machine the toolchain is generating code for: the target machine
yann@40
   537
yann@40
   538
We can most of the time assume that the config machine and the build machine
yann@40
   539
are the same. Most of the time, this will be true. The only time it isn't
yann@40
   540
is if you're using distributed compilation (such as distcc). Let's forget
yann@40
   541
this for the sake of simplicity.
yann@40
   542
yann@40
   543
So we're left with three machines:
yann@40
   544
 - build
yann@40
   545
 - host
yann@40
   546
 - target
yann@40
   547
yann@40
   548
Any toolchain will involve those three machines. You can be as pretty sure of
yann@40
   549
this as "2 and 2 are 4". Here is how they come into play:
yann@40
   550
yann@40
   551
1) build == host == target
yann@40
   552
    This is a plain native toolchain, targetting the exact same machine as the
yann@40
   553
    one it is built on, and running again on this exact same machine. You have
yann@40
   554
    to build such a toolchain when you want to use an updated component, such
yann@40
   555
    as a newer gcc for example.
yann@197
   556
    crosstool-NG calls it "native".
yann@40
   557
yann@40
   558
2) build == host != target
yann@40
   559
    This is a classic cross-toolchain, which is expected to be run on the same
yann@40
   560
    machine it is compiled on, and generate code to run on a second machine,
yann@40
   561
    the target.
yann@197
   562
    crosstool-NG calls it "cross".
yann@40
   563
yann@40
   564
3) build != host == target
yann@40
   565
    Such a toolchain is also a native toolchain, as it targets the same machine
yann@40
   566
    as it runs on. But it is build on another machine. You want such a
yann@40
   567
    toolchain when porting to a new architecture, or if the build machine is
yann@40
   568
    much faster than the host machine.
yann@197
   569
    crosstool-NG calls it "cross-native".
yann@40
   570
yann@40
   571
4) build != host != target
yann@92
   572
    This one is called a canadian-toolchain (*), and is tricky. The three
yann@40
   573
    machines in play are different. You might want such a toolchain if you
yann@40
   574
    have a fast build machine, but the users will use it on another machine,
yann@40
   575
    and will produce code to run on a third machine.
yann@197
   576
    crosstool-NG calls it "canadian".
yann@40
   577
yann@197
   578
crosstool-NG can build all these kinds of toolchains (or is aiming at it,
yann@197
   579
anyway!)
yann@40
   580
yann@40
   581
(*) The term Canadian Cross came about because at the time that these issues
yann@40
   582
    were all being hashed out, Canada had three national political parties.
yann@40
   583
    http://en.wikipedia.org/wiki/Cross_compiler
yann@40
   584
yann@1551
   585
Seemingly-native toolchains |
yann@1551
   586
----------------------------+
yann@1551
   587
yann@1551
   588
Seemingly-native toolchains are toolchains that target the same architecture
yann@1551
   589
as the one it is built on, and on which it will run, but the machine tuple
yann@1551
   590
may be different (eg i686 vs. i386, or x86_64-unknown-linux-gnu vs.
yann@1551
   591
x86_64-pc-linux-gnu). This also applies if the target architecture is of the
yann@1551
   592
same kind (eg. x86 vs. x86_64, or ppc vs. ppc64).
yann@1551
   593
yann@1551
   594
Such toolchain is tricky to build, as the configure scripts may incorrectly
yann@1551
   595
assume that files (headers and libs) from the build (or host) machine can be
yann@1551
   596
used by the cross-compiler it is going to build. The problem seems to arise
yann@1551
   597
only with glibc (and eglibc?) starting with version 2.7.
yann@1551
   598
yann@1551
   599
yann@1
   600
_____________
yann@1
   601
            /
yann@1
   602
Internals  /
yann@1
   603
__________/
yann@1
   604
yann@92
   605
Internally, crosstool-NG is script-based. To ease usage, the frontend is
yann@92
   606
Makefile-based.
yann@92
   607
yann@92
   608
Makefile front-end |
yann@476
   609
-------------------+
yann@92
   610
yann@203
   611
The entry point to crosstool-NG is the Makefile script "ct-ng". Calling this
yann@203
   612
script with an action will act exactly as if the Makefile was in the current
yann@203
   613
working directory and make was called with the action as rule. Thus:
yann@203
   614
  ct-ng menuconfig
yann@294
   615
yann@203
   616
is equivalent to having the Makefile in CWD, and calling:
yann@203
   617
  make menuconfig
yann@203
   618
yann@203
   619
Having ct-ng as it is avoids copying the Makefile everywhere, and acts as a
yann@203
   620
traditional command.
yann@203
   621
yann@203
   622
ct-ng loads sub- Makefiles from the library directory $(CT_LIB_DIR), as set up
yann@203
   623
at configuration time with ./configure.
yann@203
   624
yann@437
   625
ct-ng also searches for config files, sub-tools, samples, scripts and patches in
yann@203
   626
that library directory.
yann@92
   627
yann@294
   628
Because of a stupid make behavior/bug I was unable to track down, implicit make
yann@294
   629
rules are disabled: installing with --local would triger those rules, and mconf
yann@294
   630
was unbuildable.
yann@294
   631
yann@182
   632
Kconfig parser |
yann@476
   633
---------------+
yann@92
   634
yann@965
   635
The kconfig language is a hacked version, vampirised from the Linux kernel
yann@965
   636
(http://www.kernel.org/), and (heavily) adapted to my needs.
yann@92
   637
yann@1040
   638
The list of the most notable changes (at least the ones I remember) follows:
yann@1040
   639
- the CONFIG_ prefix has been replaced with CT_
yann@1040
   640
- a leading | in prompts is skipped, and subsequent leading spaces are not
yann@1040
   641
  trimmed
yann@1040
   642
- otherwise leading spaces are silently trimmed
yann@1040
   643
yann@203
   644
The kconfig parsers (conf and mconf) are not installed pre-built, but as
yann@203
   645
source files. Thus you can have the directory where crosstool-NG is installed,
yann@203
   646
exported (via NFS or whatever) and have clients with different architectures
yann@203
   647
use the same crosstool-NG installation, and most notably, the same set of
yann@203
   648
patches.
yann@203
   649
yann@381
   650
Architecture-specific |
yann@476
   651
----------------------+
yann@381
   652
yann@628
   653
Note: this chapter is not really well written, and might thus be a little bit
yann@628
   654
complex to understand. To get a better grasp of what an architecture is, the
yann@628
   655
reader is kindly encouraged to look at the "arch/" sub-directory, and to the
yann@628
   656
existing architectures to see how things are laid out.
yann@628
   657
yann@381
   658
An architecture is defined by:
yann@381
   659
yann@381
   660
 - a human-readable name, in lower case letters, with numbers as appropriate.
yann@628
   661
   The underscore is allowed; space and special characters are not.
yann@628
   662
     Eg.: arm, x86_64
yann@903
   663
 - a file in "config/arch/", named after the architecture's name, and suffixed
yann@903
   664
   with ".in".
yann@903
   665
     Eg.: config/arch/arm.in
yann@903
   666
 - a file in "scripts/build/arch/", named after the architecture's name, and
yann@903
   667
   suffixed with ".sh".
yann@903
   668
     Eg.: scripts/build/arch/arm.sh
yann@628
   669
yann@903
   670
The architecture's ".in" file API:
yann@628
   671
 > the config option "ARCH_%arch%" (where %arch% is to be replaced with the
yann@628
   672
   actual architecture name).
yann@628
   673
   That config option must have *neither* a type, *nor* a prompt! Also, it can
yann@628
   674
   *not* depend on any other config option (EXPERIMENTAL is managed as above).
yann@628
   675
     Eg.:
yann@628
   676
       config ARCH_arm
yann@630
   677
   + mandatory:
yann@702
   678
       defines a (terse) help entry for this architecture:
yann@630
   679
       Eg.:
yann@630
   680
         config ARCH_arm
yann@630
   681
           help
yann@630
   682
             The ARM architecture.
yann@628
   683
   + optional:
yann@628
   684
       selects adequate associated config options.
yann@1038
   685
       Note: 64-bit architectures *shall* select ARCH_64
yann@628
   686
       Eg.:
yann@628
   687
         config ARCH_arm
yann@628
   688
           select ARCH_SUPPORTS_BOTH_ENDIAN
yann@628
   689
           select ARCH_DEFAULT_LE
yann@630
   690
           help
yann@630
   691
             The ARM architecture.
yann@1038
   692
       Eg.:
yann@1038
   693
         config ARCH_x86_64
yann@1038
   694
            select ARCH_64
yann@1038
   695
            help
yann@1038
   696
              The x86_64 architecture.
yann@628
   697
yann@628
   698
 > other target-specific options, at your discretion. Note however that to
yann@628
   699
   avoid name-clashing, such options shall be prefixed with "ARCH_%arch%",
yann@628
   700
   where %arch% is again replaced by the actual architecture name.
yann@628
   701
   (Note: due to historical reasons, and lack of time to clean up the code,
yann@628
   702
    I may have left some config options that do not completely conform to
yann@628
   703
    this, as the architecture name was written all upper case. However, the
yann@628
   704
    prefix is unique among architectures, and does not cause harm).
yann@381
   705
yann@903
   706
The architecture's ".sh" file API:
yann@965
   707
 > the function "CT_DoArchTupleValues"
yann@381
   708
   + parameters: none
yann@381
   709
   + environment:
yann@901
   710
     - all variables from the ".config" file,
yann@901
   711
     - the two variables "target_endian_eb" and "target_endian_el" which are
yann@901
   712
       the endianness suffixes
yann@381
   713
   + return value: 0 upon success, !0 upon failure
yann@381
   714
   + provides:
yann@391
   715
     - mandatory
yann@383
   716
     - the environment variable CT_TARGET_ARCH
yann@389
   717
     - contains:
yann@389
   718
       the architecture part of the target tuple.
yann@389
   719
       Eg.: "armeb" for big endian ARM
yann@389
   720
            "i386" for an i386
yann@389
   721
   + provides:
yann@391
   722
     - optional
yann@389
   723
     - the environment variable CT_TARGET_SYS
yann@456
   724
     - contains:
yann@383
   725
       the sytem part of the target tuple.
yann@383
   726
       Eg.: "gnu" for glibc on most architectures
yann@383
   727
            "gnueabi" for glibc on an ARM EABI
yann@383
   728
     - defaults to:
yann@383
   729
       - for glibc-based toolchain: "gnu"
yann@383
   730
       - for uClibc-based toolchain: "uclibc"
yann@383
   731
   + provides:
yann@383
   732
     - optional
yann@391
   733
     - the environment variable CT_KERNEL_ARCH
yann@383
   734
     - contains:
yann@391
   735
       the architecture name as understandable by the Linux kernel build
yann@391
   736
       system.
yann@391
   737
       Eg.: "arm" for an ARM
yann@391
   738
            "powerpc" for a PowerPC
yann@391
   739
            "i386" for an x86
yann@383
   740
     - defaults to:
yann@391
   741
       ${CT_ARCH}
yann@391
   742
   + provides:
yann@391
   743
     - optional
yann@767
   744
     - the environment variables to configure the cross-gcc (defaults)
yann@767
   745
       - CT_ARCH_WITH_ARCH    : the gcc ./configure switch to select architecture level         ( "--with-arch=${CT_ARCH_ARCH}"   )
yann@767
   746
       - CT_ARCH_WITH_ABI     : the gcc ./configure switch to select ABI level                  ( "--with-abi=${CT_ARCH_ABI}"     )
yann@767
   747
       - CT_ARCH_WITH_CPU     : the gcc ./configure switch to select CPU instruction set        ( "--with-cpu=${CT_ARCH_CPU}"     )
yann@767
   748
       - CT_ARCH_WITH_TUNE    : the gcc ./configure switch to select scheduling                 ( "--with-tune=${CT_ARCH_TUNE}"   )
yann@767
   749
       - CT_ARCH_WITH_FPU     : the gcc ./configure switch to select FPU type                   ( "--with-fpu=${CT_ARCH_FPU}"     )
yann@767
   750
       - CT_ARCH_WITH_FLOAT   : the gcc ./configure switch to select floating point arithmetics ( "--with-float=soft" or /empty/  )
yann@391
   751
   + provides:
yann@391
   752
     - optional
yann@767
   753
     - the environment variables to pass to the cross-gcc to build target binaries (defaults)
yann@391
   754
       - CT_ARCH_ARCH_CFLAG   : the gcc switch to select architecture level                     ( "-march=${CT_ARCH_ARCH}"            )
yann@456
   755
       - CT_ARCH_ABI_CFLAG    : the gcc switch to select ABI level                              ( "-mabi=${CT_ARCH_ABI}"              )
yann@391
   756
       - CT_ARCH_CPU_CFLAG    : the gcc switch to select CPU instruction set                    ( "-mcpu=${CT_ARCH_CPU}"              )
yann@391
   757
       - CT_ARCH_TUNE_CFLAG   : the gcc switch to select scheduling                             ( "-mtune=${CT_ARCH_TUNE}"            )
yann@391
   758
       - CT_ARCH_FPU_CFLAG    : the gcc switch to select FPU type                               ( "-mfpu=${CT_ARCH_FPU}"              )
yann@391
   759
       - CT_ARCH_FLOAT_CFLAG  : the gcc switch to choose floating point arithmetics             ( "-msoft-float" or /empty/           )
yann@391
   760
       - CT_ARCH_ENDIAN_CFLAG : the gcc switch to choose big or little endian                   ( "-mbig-endian" or "-mlittle-endian" )
yann@391
   761
     - default to:
yann@391
   762
       see above.
yann@767
   763
   + provides:
yann@767
   764
     - optional
yann@767
   765
     - the environement variables to configure the core and final compiler, specific to this architecture:
yann@767
   766
       - CT_ARCH_CC_CORE_EXTRA_CONFIG   : additional, architecture specific core gcc ./configure flags
yann@767
   767
       - CT_ARCH_CC_EXTRA_CONFIG        : additional, architecture specific final gcc ./configure flags
yann@767
   768
     - default to:
yann@767
   769
       - all empty
yann@767
   770
   + provides:
yann@767
   771
     - optional
yann@767
   772
     - the architecture-specific CFLAGS and LDFLAGS:
yann@767
   773
       - CT_ARCH_TARGET_CLFAGS
yann@767
   774
       - CT_ARCH_TARGET_LDFLAGS
yann@767
   775
     - default to:
yann@767
   776
       - all empty
yann@628
   777
yann@903
   778
You can have a look at "config/arch/arm.in" and "scripts/build/arch/arm.sh" for
yann@903
   779
a quite complete example of what an actual architecture description looks like.
yann@901
   780
yann@890
   781
Kernel specific |
yann@890
   782
----------------+
yann@890
   783
yann@890
   784
A kernel is defined by:
yann@890
   785
yann@890
   786
 - a human-readable name, in lower case letters, with numbers as appropriate.
yann@890
   787
   The underscore is allowed; space and special characters are not (although
yann@890
   788
   they are internally replaced with underscores.
yann@890
   789
     Eg.: linux, bare-metal
yann@890
   790
 - a file in "config/kernel/", named after the kernel name, and suffixed with
yann@890
   791
   ".in".
yann@890
   792
     Eg.: config/kernel/linux.in, config/kernel/bare-metal.in
yann@901
   793
 - a file in "scripts/build/kernel/", named after the kernel name, and suffixed
yann@901
   794
   with ".sh".
yann@901
   795
     Eg.: scripts/build/kernel/linux.sh, scripts/build/kernel/bare-metal.sh
yann@890
   796
yann@890
   797
The kernel's ".in" file must contain:
yann@890
   798
 > an optional lines containing exactly "# EXPERIMENTAL", starting on the
yann@890
   799
   first column, and without any following space or other character.
yann@890
   800
   If this line is present, then this kernel is considered EXPERIMENTAL,
yann@890
   801
   and correct dependency on EXPERIMENTAL will be set.
yann@901
   802
yann@890
   803
 > the config option "KERNEL_%kernel_name%" (where %kernel_name% is to be
yann@890
   804
   replaced with the actual kernel name, with all special characters and
yann@890
   805
   spaces replaced by underscores).
yann@890
   806
   That config option must have *neither* a type, *nor* a prompt! Also, it can
yann@890
   807
   *not* depends on EXPERIMENTAL.
yann@890
   808
     Eg.: KERNEL_linux, KERNEL_bare_metal
yann@890
   809
   + mandatory:
yann@890
   810
       defines a (terse) help entry for this kernel.
yann@890
   811
       Eg.:
yann@890
   812
         config KERNEL_bare_metal
yann@890
   813
           help
yann@890
   814
             Build a compiler for use without any kernel.
yann@890
   815
   + optional:
yann@890
   816
       selects adequate associated config options.
yann@890
   817
       Eg.:
yann@890
   818
         config KERNEL_bare_metal
yann@890
   819
           select BARE_METAL
yann@890
   820
           help
yann@890
   821
             Build a compiler for use without any kernel.
yann@890
   822
yann@890
   823
 > other kernel specific options, at your discretion. Note however that, to
yann@890
   824
   avoid name-clashing, such options should be prefixed with
yann@890
   825
   "KERNEL_%kernel_name%", where %kernel_name% is again tp be replaced with
yann@890
   826
   the actual kernel name.
yann@890
   827
   (Note: due to historical reasons, and lack of time to clean up the code,
yann@890
   828
    I may have left some config options that do not completely conform to
yann@890
   829
    this, as the kernel name was written all upper case. However, the prefix
yann@890
   830
    is unique among kernels, and does not cause harm).
yann@890
   831
yann@901
   832
The kernel's ".sh" file API:
yann@901
   833
 > is a bash script fragment
yann@901
   834
yann@965
   835
 > defines the function CT_DoKernelTupleValues
yann@965
   836
   + see the architecture's CT_DoArchTupleValues, except for:
yann@965
   837
   + set the environment variable CT_TARGET_KERNEL, the kernel part of the
yann@965
   838
     target tuple
yann@965
   839
   + return value: ignored
yann@965
   840
yann@901
   841
 > defines the function "do_kernel_get":
yann@901
   842
   + parameters: none
yann@901
   843
   + environment:
yann@901
   844
      - all variables from the ".config" file.
yann@901
   845
   + return value: 0 for success, !0 for failure.
yann@901
   846
   + behavior: download the kernel's sources, and store the tarball into
yann@901
   847
     "${CT_TARBALLS_DIR}". To this end, a functions is available, that
yann@901
   848
     abstracts downloading tarballs:
yann@901
   849
     - CT_DoGet <tarball_base_name> <URL1 [URL...]>
yann@901
   850
       Eg.: CT_DoGet linux-2.6.26.5 ftp://ftp.kernel.org/pub/linux/kernel/v2.6
yann@901
   851
     Note: retrieving sources from svn, cvs, git and the likes is not supported
yann@901
   852
     by CT_DoGet. You'll have to do this by hand, as it is done for eglibc in
yann@901
   853
     "scripts/build/libc/eglibc.sh"
yann@901
   854
yann@901
   855
 > defines the function "do_kernel_extract":
yann@901
   856
   + parameters: none
yann@901
   857
   + environment:
yann@901
   858
      - all variables from the ".config" file,
yann@901
   859
   + return value: 0 for success, !0 for failure.
yann@901
   860
   + behavior: extract the kernel's tarball into "${CT_SRC_DIR}", and apply
yann@901
   861
     required patches. To this end, a function is available, that abstracts
yann@901
   862
     extracting tarballs:
yann@901
   863
     - CT_ExtractAndPatch <tarball_base_name>
yann@901
   864
       Eg.: CT_ExtractAndPatch linux-2.6.26.5
yann@901
   865
yann@901
   866
 > defines the function "do_kernel_headers":
yann@901
   867
   + parameters: none
yann@901
   868
   + environment:
yann@901
   869
      - all variables from the ".config" file,
yann@901
   870
   + return value: 0 for success, !0 for failure.
yann@901
   871
   + behavior: install the kernel headers (if any) in "${CT_SYSROOT_DIR}/usr/include"
yann@901
   872
yann@901
   873
 > defines any kernel-specific helper functions
yann@901
   874
   These functions, if any, must be prefixed with "do_kernel_%CT_KERNEL%_",
yann@901
   875
   where '%CT_KERNEL%' is to be replaced with the actual kernel name, to avoid
yann@901
   876
   any name-clashing.
yann@901
   877
yann@901
   878
You can have a look at "config/kernel/linux.in" and "scripts/build/kernel/linux.sh"
yann@903
   879
as an example of what a complex kernel description looks like.
yann@901
   880
yann@620
   881
Adding a new version of a component |
yann@476
   882
------------------------------------+
yann@476
   883
yann@476
   884
When a new component, such as the Linux kernel, gcc or any other is released,
yann@476
   885
adding the new version to crosstool-NG is quite easy. There is a script that
yann@476
   886
will do all that for you:
yann@1095
   887
  scripts/addToolVersion.sh
yann@476
   888
yann@476
   889
Run it with no option to get some help.
yann@381
   890
yann@203
   891
Build scripts |
yann@476
   892
--------------+
yann@203
   893
yann@203
   894
To Be Written later...