==================
Crosstool-ng 1.6.1
==================

.. include:: header.rst

.. TODO: tarball (with sources)

.. contents:: Contents

Installing Crosstool-ng
-----------------------

1. Download and build crosstool-ng::

      # Install prerequisites:
      sudo apt-get install flex bison automake libtool ncurses-dev

      version=crosstool-ng-1.6.1
      wget http://ymorin.is-a-geek.org/download/crosstool-ng/$version.tar.bz2
      tar xjvf $version.tar.bz2

      cd $version/
      ./configure --local

      # NOTE: The following "make" command only builds the "ct-ng" tool
      #       (not the compilers, libs, and binutils).
      make
      chmod a+rx ct-ng

2. Configure crosstool-ng to build a specific cross-compiler.  For some
   tips on how to do the configuration, see the section `Configuration
   Options for Crosstool-ng (Glibc)`_ for starters::

      # Finally, start crosstool-ng:
      ./ct-ng menuconfig
      # Note: Read the next section for information on how to configure...
      #
      # Alternatively, do this:
      # TODO: I haven't created the glibc config file yet:
      # cp crosstool-ng-1.6.1-ppc405-nofloat-glibc-config .config
      # or
      # cp crosstool-ng-1.6.1-ppc405-nofloat-uclibc-config .config
      #
      # Then run:
      # ./ct-ng oldconfig


3. Instruct crosstool-ng to build the cross-compiler::

      # After configuring (with menuconfig or oldconfig), build the toolchain:
      unset LD_LIBRARY_PATH LIBRARY_PATH CPATH
      export LD_LIBRARY_PATH LIBRARY_PATH CPATH
      ./ct-ng build

4. If you want both glibc and uClibc support, then repeat the process
   twice.  Once for glibc, and once again for uClibc. See the following
   steps for how to reconfigure crosstool-ng for each.  (Hint: you
   probably do want both uClibc and glibc support).


.. _`Configuration Options for Crosstool-ng`:

Configuration Options for Crosstool-ng (Glibc)
----------------------------------------------

.. WARNING::

    I haven't tested the glibc portion of this tutorial yet.  This is copied from the older
    `crosstool-ng-1.3.2.html`_ tutorial.  Please provide feedback on your experiences if
    you try this.  Thanks.

The first two configuration screens, and the options you should choose
are displayed here.  A more detailed description of the configurations
follows these screenshots:

.. figure:: im-edited/crosstool-01.png

.. figure:: im-edited/crosstool-02.png


Here are the configuration settings to apply:

- Paths and misc options

  - Paths

    - Local tarballs directory: ${HOME}/sources
    - Save new tarballs: Yes
    - Prefix directory: /home/xilinx/crosstool-ng-1.6.1/${CT_TARGET}

  - Build behavior

    - Number of parallel jobs: 3 or 4 (if you have a quad-core computer)

  - Logging

    - Maximum log level to see: EXTRA

- Target options

  - Target Architecture: powerpc
  - Emit assembly for CPU: 405
  - Tune assembly for CPU: 405
  - Floating point: software

- Toolchain options

  - Vendor string: 405
    
- Operating System

  - Target OS: linux
  - Linux kernel version: 2.6.31.12

- binutils

  - binutils version: 2.19.1
  - binutils libraries for the target: Yes (libiberty and libbfd)

- C compiler

  - gcc version: 4.3.2
  - C++: Yes
  - Fortran: Yes (optional)
  - Java: Yes (optional)
  - (Untested: enable any other languages you may want)

- TODO: C-library

  - C library: glibc
  - glibc version: 2.6.1
  - Threading implementation to use: nptl
  - Use the ports addon: Yes

- Debug facilities (Optional, Untested!)

  - dmalloc: Yes (5.5.2)
  - duma: Yes (2_5_14)
  - gdb: Yes

    - Build a static cross gdb: Yes
    - Native gdb: Yes
    - Build a static native gdb: Yes
    - Use GMP and MPFR: yes
    - Version: 6.8

  - ltrace: No (Neither 0.5.3 nor 0.5.2 would build for the uClibc
    configuration)
  - TODO: strace: No (because I couldn't get it to build)

- Tools facilities (Optional, Untested!)

  - libelf: Yes
  - sstrip: No (because I couldn't get it to build)

- Companion libraries

  - TODO: GMP and MPFR

    - Build libraries for target: Yes
    - GMP version: 4.3.1 (was 4.2.4)
    - MPFR version: 2.4.2 (was 2.3.2)
    - TODO: Check the companion libraries builds: Yes (optional)



..    - strace: Yes (4.5.15)
..    - crosstool-NG behavior
..        - Try features marked as EXPERIMENTAL: Yes
..    - GMP and MPFR: Yes

Configuration Options for Crosstool-ng (uClibc)
-----------------------------------------------

Special note: do not build uclibc yourself.  Crosstool-ng will do
this automatically!  The instructions go basically like this:

1. Download and configure uClibc (using ``make menuconfig``) and then
   save the configuration.  This is discussed in more detail
   below.  As a matter of fact, you can skip this step if you
   just use the provided config file, in which case crosstool-ng
   itself will download a copy of uClibc.  Should you choose
   to download uClibc and run menuconfig, you can find it `here
   <http://www.uclibc.org/downloads/uClibc-0.9.30.1.tar.bz2>`_.

2. Configure crosstool-ng (e.g. using ``make menuconfig``) and instruct
   crosstool-ng where to find the configuration file you saved in step 1.
   If you did not specify an alternate name, then then the config file
   will probably be called ``.config`` and will be located in the uclibc
   directory.


uClibc 0.9.30.1 configuration (available `here
<distfiles/uClibc-0.9.30.1-ppc405-nofpu-config>`_):

- Target architecture: powerpc
- Target Architecture Features and Options:

  - Target CPU has a floating point unit (FPU): No
  - Enable full C99 math library support: Yes
  - Enable C99 Floating-point environment: Yes
  - Enable long double support: No

- General Library Settings:

  - POSIX Threading support: Yes
  - Use the older (stable) version of linuxthreads: Yes (but we eventually might want NPTL though...)

- Network Support:

  - Remote Procedure Call (RPC) support: Yes (for NFS)
  - Full RPC support: Yes
  - Reentrant RPC support: Yes

- String and Stdio Support

  - ctype argument checking: Issue a diagnostic and abort()


Crosstool configuration (available `here
<distfiles/crosstool-ng-1.6.1-ppc405-nofloat-uclibc-config>`_):

- Follow the same configuration as for Glibc (described in the previous
  section), and then apply the following additional configuration listed
  in the next bullets.
- C compiler

  - gcc version: 4.2.4 (because 4.3.2 would not build)
  - Java: No (because I could not get this to build)

- C-library:

  - C library: uClibc
  - uClibc version: 0.9.30.1
  - Configuration file: ${CT_LIB_DIR}/uClibc-0.9.30.1-ppc405-nofpu-config (available `here <distfiles/uClibc-0.9.30.1-ppc405-nofpu-config>`_)
  - Threading implementation to use: linuxthreads

- Debug facilities (Optional, Untested!)

  - ltrace: No (Neither 0.5.3 nor 0.5.2 would build)

.. linuxthreads (but really we want NPTL)

Errors
------

"error: C compiler cannot create executables"

    I don't yet know what to do about this error...

..    targets/powerpc-405-linux-uclibc/build/build-cc/powerpc-405-linux-uclibc/libgomp/config.log says::

..        /home/guestl/tmp/crosstool-ng-1.6.1/targets/powerpc-405-linux-uclibc/build/build-cc/./gcc/libgcc_s.so: undefined reference to `copysignl' 

..    http://www.nabble.com/powerpc-unknown-linux-uclibc-with-gcc-4.3.1-build-error-td18917705.html
..    http://lists.uclibc.org/pipermail/uclibc/2008-August/019836.html

Downloads
---------

- TODO: `crosstool-ng-1.6.1-ppc405-nofloat-glibc-config <distfiles/crosstool-ng-1.6.1-ppc405-nofloat-glibc-config>`_
- `crosstool-ng-1.6.1-ppc405-nofloat-uclibc-config <distfiles/crosstool-ng-1.6.1-ppc405-nofloat-uclibc-config>`_
- `uClibc-0.9.30.1-ppc405-nofpu-config <distfiles/uClibc-0.9.30.1-ppc405-nofpu-config>`_
