Difference between revisions of "GDC/Cross Compiler/crosstool-NG"

From D Wiki
Jump to: navigation, search
(Created page with "{{ParentArticle|GDC > Cross Compiler}} == First things first == === Read the crosstool-NG website === Have a look at http://www.crosstool-ng.org/ ...")
 
 
(4 intermediate revisions by 3 users not shown)
Line 16: Line 16:
 
== Obtaining GDC sources ==
 
== Obtaining GDC sources ==
 
=== Checkout GDC ===
 
=== Checkout GDC ===
First clone the git repository. We'll use the gdc-4.7 branch.
+
First clone the git repository. We'll use the gdc-4.8 branch.
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 22: Line 22:
 
git clone https://github.com/D-Programming-GDC/GDC.git gdc/dev
 
git clone https://github.com/D-Programming-GDC/GDC.git gdc/dev
 
cd gdc/dev
 
cd gdc/dev
git checkout gdc-4.7
+
git checkout gdc-4.8
 
cd ../
 
cd ../
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== Get GCC sources ===
 
=== Get GCC sources ===
Grab GCC sources from a mirror. You will need the full gcc archives. Unpack the archives in the gdc dir. This creates something like gdc/gcc-4.7.1. If you want to keep the original GCC sources, rename the gcc-4.7.1 tarball.
+
Grab GCC sources from a mirror. You will need the full gcc archives. Unpack the archives in the gdc dir. This creates something like gdc/gcc-4.8.2.
  
 
=== Patch GCC sources ===
 
=== Patch GCC sources ===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd gdc/dev
 
cd gdc/dev
./update-gcc.sh ../gcc-4.7.1
+
./update-gcc.sh ../gcc-4.8.2
 
cd ../
 
cd ../
</syntaxhighlight>
 
 
=== Package GCC sources ===
 
We'll now package the GCC sources again, so we'll have a ready to use GCC '''gcc-4.7.1.tar.bz2''' source tarball with the GDC sources included.
 
 
<syntaxhighlight lang="bash">
 
tar -hcjf gcc-4.7.1.tar.bz2 gcc-4.7.1/
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 46: Line 39:
  
 
=== Make crosstool-NG use our patched sources ===
 
=== Make crosstool-NG use our patched sources ===
Start '''ct-ng menuconfig'''. Select '''Paths and misc options''', '''Local tarballs directory''' and enter the path to the directory which contains the patched GCC sources: ''/home/jpf/gdc''. Also make sure '''Try features marked as EXPERIMENTAL''' is set. Select '''C compiler''' in the main menu and make sure '''GCC version''' is set to '''4.7.1'''
+
Start '''ct-ng menuconfig'''. Select '''Paths and misc options''' and make sure '''Try features marked as EXPERIMENTAL''' is set. Select '''C compiler''' in the main menu and set '''GCC version''' to '''Custom gcc'''. Then set '''Full path to custom gcc source''' to the full path of the gdc/gcc-4.8.2 directory.
  
 
=== Enable D language ===
 
=== Enable D language ===
Go to '''C compiler''', select '''Other languages''' and enter '''d'''
+
Go to '''C compiler''', select '''Other languages''' and type '''d'''
  
=== Disabling druntime & phobos ===
+
If this option doesn't appear in the '''C compiler''' menu, then you may need to edit part of your crosstool-NG configuration manually to adjust this. It can hide the option when creating a bare metal cross compiler. You will need to comment out the following lines in your cc.in file.
If druntime & phobos do not yet compile for your target you can disable them:
 
  
Start ct-ng menuconfig, go to "C compiler" and add "--disable-libphobos" to "Core gcc extra config" and "gcc extra config".
+
<syntaxhighlight lang="bash">
 +
if ! BARE_METAL
 +
endif # ! BARE_METAL
 +
</syntaxhighlight>
  
== Build the cross compiler ==
+
Supposing your configuration is in a directory named 'config', you can comment the lines out easily with the following sed command.
We have to make sure crosstool-NG uses our new sources instead of reusing already extracted or downloaded sources. So if you've already built a plain C cross compiler in your working directory, you'll have to delete the extracted / downloaded sources:
 
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
rm .build/src/.gcc-4.7.1.extracted
+
sed -e 's/^\(endif # ! BARE_METAL\|if ! BARE_METAL\)/# \1/' -i config/cc.in
rm .build/src/.gcc-4.7.1.patched
 
rm .build/tarballs/gcc-4.7.1.tar.bz2
 
rm -rf .build/src/gcc-4.7.1
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Disabling druntime & phobos ===
 +
If druntime & phobos do not yet compile for your target you can disable them:
 +
 +
Start ct-ng menuconfig, go to "C compiler" and add "--disable-libphobos" to "Core gcc extra config" and "gcc extra config".
  
 
=== Build it ===
 
=== Build it ===
Line 70: Line 66:
 
ct-ng build
 
ct-ng build
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Running the test suite ==
 +
The object directory in which you'll run make check is ''".build/TARGET-TRIPLET/build/build-cc-final/"'' relative to the folder where you ran ''ct-ng build''. An example would be ''.build/arm-unknown-linux-gnueabihf/build/build-cc-final/''.
 +
 +
Change to this directory then follow [[GDC/Test_Suite#Testing_Cross-compilers]].
 +
 +
 +
[[Category:GDC Compiler]]

Latest revision as of 20:04, 1 September 2015


First things first

Read the crosstool-NG website

Have a look at http://www.crosstool-ng.org/ and see if crosstool-NG fits you needs (Architecture, C library, OS, ...).

Install crosstool-NG

Download crosstool-NG from http://www.crosstool-ng.org/ . Install as described on it's homepage.

Read the documentation

crosstool-NG includes some useful documentation in it's source tarball. Have a look at the "docs" directory.

Build a C cross compiler

Before even trying to build a D cross compiler, built a C cross compiler with the desired configuration. Creating cross compilers is difficult, so you should first get a simple C compiler working before trying to build D.

Obtaining GDC sources

Checkout GDC

First clone the git repository. We'll use the gdc-4.8 branch.

mkdir -p gdc/dev
git clone https://github.com/D-Programming-GDC/GDC.git gdc/dev
cd gdc/dev
git checkout gdc-4.8
cd ../

Get GCC sources

Grab GCC sources from a mirror. You will need the full gcc archives. Unpack the archives in the gdc dir. This creates something like gdc/gcc-4.8.2.

Patch GCC sources

cd gdc/dev
./update-gcc.sh ../gcc-4.8.2
cd ../

Configure crosstool-NG for D

We assume you already have a configuration for your target system which produces a working C compiler so you only need to add D support.

Make crosstool-NG use our patched sources

Start ct-ng menuconfig. Select Paths and misc options and make sure Try features marked as EXPERIMENTAL is set. Select C compiler in the main menu and set GCC version to Custom gcc. Then set Full path to custom gcc source to the full path of the gdc/gcc-4.8.2 directory.

Enable D language

Go to C compiler, select Other languages and type d

If this option doesn't appear in the C compiler menu, then you may need to edit part of your crosstool-NG configuration manually to adjust this. It can hide the option when creating a bare metal cross compiler. You will need to comment out the following lines in your cc.in file.

if ! BARE_METAL
endif # ! BARE_METAL

Supposing your configuration is in a directory named 'config', you can comment the lines out easily with the following sed command.

sed -e 's/^\(endif # ! BARE_METAL\|if ! BARE_METAL\)/# \1/' -i config/cc.in

Disabling druntime & phobos

If druntime & phobos do not yet compile for your target you can disable them:

Start ct-ng menuconfig, go to "C compiler" and add "--disable-libphobos" to "Core gcc extra config" and "gcc extra config".

Build it

ct-ng build

Running the test suite

The object directory in which you'll run make check is ".build/TARGET-TRIPLET/build/build-cc-final/" relative to the folder where you ran ct-ng build. An example would be .build/arm-unknown-linux-gnueabihf/build/build-cc-final/.

Change to this directory then follow GDC/Test_Suite#Testing_Cross-compilers.