==================
Crosstool-ng 1.3.2
==================

.. include:: header.rst

.. WARNING::

    Please refer to the newer `Crosstool-ng 1.6.1
    <crosstool-ng-1.6.1.html>`_ tutorial.

    This 1.3.2 tutorial is outdated.  There are now many problems that
    are likely to occur to prevent you from using crosstool-ng 1.3.2.
    These problems include crosstool-ng-1.3.2 dies if you have a more
    recent version of Bash, and some other problems that I cannot
    remember.

.. 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.3.2
      wget http://ymorin.is-a-geek.org/download/crosstool-ng/$version.tar.bz2
      tar xjvf $version.tar.bz2

      cd $version/
      ./configure --local
      # NOTE: You may get an error that looks like this:
      # Computing version string... 1.3.2
      # Checking for '/bin/bash'... /bin/bash: wrong version string: expecting regexp '^GNU bash, version 3\.'
      # Bailing out...
      #
      # If you get that error, then manually edit the "configure" file
      # and apply this patch to disable the Bash version check:
      #
      # Index: crosstool-ng-1.3.2/configure
      # ===================================================================
      # --- crosstool-ng-1.3.2.orig/configure 2010-04-14 10:50:14.018166725 -0600
      # +++ crosstool-ng-1.3.2/configure  2010-04-14 10:51:47.819250235 -0600
      # @@ -33,7 +33,7 @@
      #  #         - 'autoconf2.50' is to be found in the PATH
      #  #
      #  TOOLS_TO_CHECK='
      # -/bin/bash/^GNU bash, version 3\.
      # +/bin/bash/^GNU bash, version
      #  make/^GNU Make
      #  gcc/
      #  gawk/^GNU Awk

      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:
      # cp crosstool-ng-1.3.2-ppc405-nofloat-glibc-config .config
      # or
      # cp crosstool-ng-1.3.2-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. Repeat the process twice.  Once for glibc, and again for uClibc.


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

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

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.3.2/${CT_TARGET}

  - Build behavior

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

  - 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.27.6

- GMP and MPFR

  - Build libraries for target: Yes
  - GMP version: 4.2.4
  - MPFR version: 2.3.2

- binutils

  - binutils version: 2.19
  - 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)

- C-library

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

- Tools (Optional, Untested!)

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

- 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: Yes (0.4)
  - strace: No (because I couldn't get it to build)


..    - 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. Configure uclibc (using ``make menuconfig``) and then save the
   configuration.  This is discussed in more detail below.

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 configuration (available `here
<distfiles/uClibc-0.9.30-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 really 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.3.2-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
  - Configuration file: ${CT_LIB_DIR}/uClibc-0.9.30-ppc405-nofpu-config (available `here <distfiles/uClibc-0.9.30-ppc405-nofpu-config>`_)
  - Threading implementation to use: linuxthreads

.. 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.3.2/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
---------

- `crosstool-ng-1.3.2-ppc405-nofloat-glibc-config <distfiles/crosstool-ng-1.3.2-ppc405-nofloat-glibc-config>`_
- `crosstool-ng-1.3.2-ppc405-nofloat-uclibc-config <distfiles/crosstool-ng-1.3.2-ppc405-nofloat-uclibc-config>`_
- `uClibc-0.9.30-ppc405-nofpu-config <distfiles/uClibc-0.9.30-ppc405-nofpu-config>`_
