Multiarch: Adding another target architecture

This is a short guide on how to enable another target architecture using the armv7-unknown-linux-gnueabihf architecture as an example. You can see all currently supported targets by looking at target options reported by

    # cave show gcc::arbor

If you expect you’ll need a different set of options for the new target, consider adding it in a another paludis environment.

  1. Configure the target suboption in /etc/paludis/options.conf

    * /etc/paludis/options.conf *
    
    */* targets: armv7-unknown-linux-gnueabihf

    Make sure not to remove your native target, i.e. the one matching your CHOST.

  2. Setup *FLAGSS in /etc/paludis/bashrc

    * /etc/paludis/bashrc *
    
    armv7_unknown_linux_gnueabihf_CFLAGS="-pipe -O2 -march=armv7-a -mtune=cortex-a9 -mfloat-abi=hard -mfpu=vfpv3"
    armv7_unknown_linux_gnueabihf_CXXFLAGS="-pipe -O2 march=armv7-a -mtune=cortex-a9 -mfloat-abi=hard -mfpu=vfpv3"

    These flags are just a suggestion and you most certainly want to change them to match your hardware (the ones above are suitable for a TI OMAP4). gcc’s documentation lists possible options.

  3. Add a config file for the target’s installed repository

    tool_prefix is the prefix for the toolchain components which is being used to generate the binaries for the target platform, armv7-unknown-linux-gnueabihf- in our case.

    split_debug_location is the location where the split debug information is stored for the packages that are installed.

    cross_compile_host is the target host on which the binaries will run.

    * /etc/paludis/repositories/armv7-unknown-linux-gnueabihf.conf *
    
    format = exndbam
    location = ${root}/var/db/paludis/repositories/cross-installed/armv7-unknown-linux-gnueabihf
    name = armv7-unknown-linux-gnueabihf
    split_debug_location = /usr/armv7-unknown-linux-gnueabihf/lib/debug
    tool_prefix = armv7-unknown-linux-gnueabihf-
    cross_compile_host = armv7-unknown-linux-gnueabihf

    The directory specified by the location option above needs to be created:

    # mkdir /var/db/paludis/repositories/cross-installed/armv7-unknown-linux-gnueabihf
  4. Build binutils with the new target

    # cave resolve --preserve-world binutils
  5. Build gcc[-threads] (threading support requires libc which is not present in target yet)

    * /etc/paludis/options.conf *
    
    sys-devel/gcc -threads
    
    # cave resolve --preserve-world sys-devel/gcc

    This will also pull in eclectic-gcc.

  6. Cross compile linux-headers and glibc

     # cave resolve --preserve-world --make cross-compile sys-kernel/linux-headers
     # cave resolve --preserve-world --make cross-compile --no-dependencies-from sys-libs/glibc sys-libs/glibc

    Dependencies handling isn’t perfect. glibc has a run-time dependency upon timezone-data, but for cross compilation hosts that can’t be built before gcc. Therefore we have to use --no-dependencies-from.

    If you have more than one cross compilation target in the same environment you’ll need to specify --cross-host armv7-unknown-linux-gnueabihf additionally.

  7. Build gcc[threads]

    Enable gcc’s threads option again by removing the previously added temporary sys-devel/gcc -threads from /etc/paludis/options.conf (it’s set by our profiles) and rebuild sys-devel/gcc afterwards:

     # cave resolve --preserve-world gcc --no-follow-installed-dependencies
  8. Cross compile language runtimes.

     # cave resolve --preserve-world --make cross-compile libatomic libgcc libstdc++
  9. Rebuild other packages having a targets suboption

    pkg-config/pkg-conf also have a targets suboption and also need a rebuild. There are more packages, like clang for example, which also offer said option. You can use cave to find out and rebuild them or fine-tune your targets for these packages.

     # cave resolve --complete installed-slots
  10. Start cross compiling other packages

    Now that the toolchain is built and installed you can start building the packages you’re interested in for the new target:

    # cave resolve --make cross-compile <foo>

Copyright 2016 Heiko Becker