Skip to content

Sourcery G++ Lite for ARM GNU Linux (2009q3 67) for Mac OS X

UnhandledException edited this page Aug 5, 2011 · 3 revisions

Prebuilt Binaries

If you are lazy and would rather just download the binaries, you may do so here. However, you cannot simply extract it to any directory of your choice. Please read the section Create the Final Disk Image below for instructions on how to extract it correctly.

Create a Scratch Disk Image

Some components needed to build the toolchain need to reside on a case-sensitive filesystem. The default filesystem on Mac OS X is case-insensitive. The workaround, therefore, is to create a disk image with a case-sensitive filesystem and use that as our scratch area where we will be building the toolchain.

Use the Disk Utility and create a 6GB image. The Save As field can be anything you like, but the Name field must be exactly armx-scratch. Select Mac OS Extended (Case-sensitive, Journaled) in the Format field.

Install the Required GNU Tools

We also need to install several GNU tools. Some of the tools we will install may seem redundant since Mac OS X already ships with them (e.g., sed and awk). However, the tools that ship with Mac OS X are not compatible with some of the CodeSourcery components. We will install these tools to /usr/local. It is important to build at least the gettext library as 32-bit as explained later; however, we are choosing to build everything as 32-bit.

sed:

tar -x -C /Volumes/armx-scratch -f sed-4.2.tar.gz
pushd /Volumes/armx-scratch/sed-4.2
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4 install
popd
rm -rf /Volumes/armx-scratch/sed-4.2

awk:

tar -x -C /Volumes/armx-scratch -f gawk-4.0.0.tar.gz
pushd /Volumes/armx-scratch/gawk-4.0.0
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4 install
popd
rm -rf /Volumes/armx-scratch/gawk-4.0.0

texinfo:

tar -x -C /Volumes/armx-scratch -f texinfo-4.13a.tar.gz
pushd /Volumes/armx-scratch/texinfo-4.13
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4 install
popd
rm -rf /Volumes/armx-scratch/texinfo-4.13

tar (needed by the CodeSourcery build script itself due to the use of options like --owner=0 --group=0):

tar -x -C /Volumes/armx-scratch -f tar-1.26.tar.gz
pushd /Volumes/armx-scratch/tar-1.26
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4 install
popd
rm -rf /Volumes/armx-scratch/tar-1.26

cp from coreutils (needed by the CodeSourcery build script itself due to the use of options like -d):

tar -x -C /Volumes/armx-scratch -f coreutils-8.12.tar.gz
pushd /Volumes/armx-scratch/coreutils-8.12
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4
cp src/cp /usr/local/bin/
popd
rm -rf /Volumes/armx-scratch/coreutils-8.12

readelf from binutils:

tar -x -C /Volumes/armx-scratch -f binutils-2.21.1.tar.gz
pushd /Volumes/armx-scratch/binutils-2.21.1
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4
cp binutils/readelf /usr/local/bin/
popd
rm -rf /Volumes/armx-scratch/binutils-2.21.1

gettext:

tar -x -C /Volumes/armx-scratch -f gettext-0.18.1.1.tar.gz
pushd /Volumes/armx-scratch/gettext-0.18.1.1
CC='gcc -arch i386' CXX='g++ -arch i386' ./configure --prefix=/usr/local
make -j4 install
popd
rm -rf /Volumes/armx-scratch/gettext-0.18.1.1

Install MacTex

The build process within the CodeSourcery toolchain generates PDF documentation and needs a TeX distribution installed on the build machine. I was first reluctant to download a giant package just for this purpose and tried BasicTeX from TexLive only to find out that the build failed and gave me some eccentric error that I could not fix. So I gave up and installed the full MacTex distribution. Unfortunately, the latest MacTex distribution at the time of writing (MacTex 2011) is incompatible with building the PDF documentation for the binutils package include in this version of CodeSourcery distribution. So, I had to download MacTex 2010 instead. Finding older releases of MacTex turned out to be a challenge. I googled for mactex20100907.zip and finally found it. You may want to uninstall MacTex once the toolchain is built. They have very good instructions on how to uninstall their distribution on their website.

Download CodeSourcery G++ Lite Source Tarball

Download arm-2009q3-67-arm-none-linux-gnueabi.src.tar.bz2. Extract the CodeSourcery source tarball by doing:

    mkdir -p /Volumes/armx-scratch/src

    tar -zx -C /Volumes/armx-scratch/src --strip-components 1 -f arm-2009q3-67-arm-none-linux-gnueabi.src.tar.bz2

    pushd /Volumes/armx-scratch/src

    tar zxvf binutils-2009q3-67.tar.bz2
    tar zxvf cloog-2009q3-67.tar.bz2
    tar zxvf coreutils-2009q3-67.tar.bz2
    tar zxvf expat-2009q3-67.tar.bz2
    tar zxvf gcc-2009q3-67.tar.bz2
    tar zxvf gdb-2009q3-67.tar.bz2
    tar zxvf glibc_localedef-2009q3-67.tar.bz2
    tar zxvf glibc_ports-2009q3-67.tar.bz2
    tar zxvf glibc-2009q3-67.tar.bz2
    tar zxvf gmp-2009q3-67.tar.bz2
    tar zxvf libiconv-2009q3-67.tar.bz2
    tar zxvf linux-2009q3-67.tar.bz2
    tar zxvf make-2009q3-67.tar.bz2
    tar zxvf mpfr-2009q3-67.tar.bz2
    tar zxvf ppl-2009q3-67.tar.bz2
    tar zxvf zlib-2009q3-67.tar.bz2

    rm binutils-2009q3-67.tar.bz2
    rm cloog-2009q3-67.tar.bz2
    rm coreutils-2009q3-67.tar.bz2
    rm expat-2009q3-67.tar.bz2
    rm gcc-2009q3-67.tar.bz2
    rm gdb-2009q3-67.tar.bz2
    rm glibc_localedef-2009q3-67.tar.bz2
    rm glibc_ports-2009q3-67.tar.bz2
    rm glibc-2009q3-67.tar.bz2
    rm gmp-2009q3-67.tar.bz2
    rm libiconv-2009q3-67.tar.bz2
    rm linux-2009q3-67.tar.bz2
    rm make-2009q3-67.tar.bz2
    rm mpfr-2009q3-67.tar.bz2
    rm ppl-2009q3-67.tar.bz2
    rm zlib-2009q3-67.tar.bz2

    popd

Apply Mac OS X Specific Patches

Download armx-2009q3-67-patches.zip. Extract the zip file to /Volumes/armx-scratch/src. Then apply the patches by doing:

    cd /Volumes/armx-scratch/src
    
    patch -N -p0 < gcc-44.patch
    patch -p0 < glibc_localedef-2.10.patch
    patch -p0 < glibc-2.10.patch

Build the Toolchain

Now clone the ARMx repository on your Mac and run the build-2009q3-67.sh to build the repository. If everything goes well, you should find the toolchain in the /Volumes/armx-scratch/pkg/ directory.

Create the Final Disk Image

For the exact same reason as before, the toolchain must not only be built on case-sensitive filesystem but reside on a case-sensitive filesystem as well. So we will deploy our toolchain to disk image with a case-sensitive filesystem.

Use the Disk Utility and create an image large enough to hold the toolchain plus any other libraries you intend to add in the future for your custom projects. I recommed selecting a minimum of 500MB. The Save As field can be anything you like, but the Name field must be exactly arm-x. Select Mac OS Extended (Case-sensitive, Journaled) in the Format field.

Strictly speaking, the Name field does not have to be arm-x. Doing so, however, will make it easy when we add more libraries to the image as we can simply hard-code the /Volumes/arm-x path on our build system to deploy our future development libraries to this disk image.

Using a disk image as opposed to deploying the toolchain also has several advantages:

  1. Users don't have to install the tools. They simply double-click the image and voila! all the needed tools become online.

  2. Managing multiple versions of the toolchain becomes very easy. Simply make sure that the correct version is mounted at the time of performing a build to make sure that the desired version of the toolchain is used. No more changing the PATH variable!

The disk image will be mounted automatically once created. Deploy the toolchain to the image by doing:

tar -zx -C /Volumes/arm-x/ --strip-components 1 -f ARMx-2009q3-67.tar.bz2

Using the Disk Image

I recommend adding the /Volumes/arm-x directory to the user's PATH. I recommend doing the following:

cat > /etc/paths.d/ARMx <<'EOF0'
/Volumes/arm-x/bin
EOF0
Clone this wiki locally