Deploying Source Code to Cygwin VM

1. Unpacking source code

Open Cygwin console, create directory /opt/crosstool/src (mkdir -p), and unpack binutils, gcc, mpc, mpfr, gmp, eglibc and linux into it. Use "tar zxvf" to unpack .tar.gz files and "tar jxvf" to unpack .tar.bz2 files.

You should get the following folders:

C:\Cygwin\opt\crosstool\src\binutils-2.22
C:\Cygwin\opt\crosstool\src\gcc-4.6.3
C:\Cygwin\opt\crosstool\src\mpc-0.9
C:\Cygwin\opt\crosstool\src\mpfr-3.0.1
C:\Cygwin\opt\crosstool\src\gmp-5.0.1
C:\Cygwin\opt\crosstool\src\eglibc-2.13
C:\Cygwin\opt\crosstool\src\linux-3.2.21

Also please unpack patches-for-raspberry-pi-toolchain.tar.gz into /opt/crosstool/src (C:\Cygwin\opt\crosstool).

Also you need to create the following folders:

/opt/crosstool/gcc-4.6.3-eglibc-2.13
/opt/crosstool/gcc-4.6.3-eglibc-2.13/arm-linux-gnueabi
/opt/crosstool/gcc-4.6.3-eglibc-2.13/arm-linux-gnueabihf
 

2. Applying patches

Start Cygwin console and run the following commands:

$ cd /opt/crosstool/src
$ cp -r gcc-4.6.3 gcc-4.6.3.noarmhf
$ cd gcc-4.6.3
$ cat ../gcc--armhf-triplet.diff | patch -p2
$ cat ../gcc--arm-dynamic-linker.diff | patch -p2
$ cat ../gcc--arm-multilib-defaults.diff | patch -p2
$ cd ../eglibc-2.13
$ cat ../eglibc--remove-manual.diff | patch -p1
$ cat ../eglibc--cross-cygwin.diff | patch -p1
$ cd ..
$ cp -r eglibc-2.13 eglibc-2.13.noarmhf
$ cd eglibc-2.13
$ cat ../eglibc--armhf-triplet.diff | patch -p1
$ cat ../eglibc--armhf-linker.diff | patch -p1
$ cat ../eglibc--ldconfig-cache-abi.diff | patch -p1
$ cat ../eglibc--soname-hack.diff | patch -p1
$ cd ..
$ tar -h -zcf gcc-4.6.3-all.tar.gz \
    gcc-4.6.3 gcc-4.6.3.noarmhf
 

3. Preventing eglibc build error on case-insensitive filesystem

eglibc has a problem when built under Cygwin: it needs case-sensitive filesystem, otherwise .os and oS files collide and "make" phase of eglibc build fails with the following error message:

.../build-eglibc/elf/librtld.os: In function `process_envvars':
../eglibc-2.13/elf/rtld.c:2718: undefined reference to `__open'
../eglibc-2.13/elf/rtld.c:2690: undefined reference to `__access'
../build-eglibc/elf/librtld.os: In function `dl_main':
../eglibc-2.13/elf/rtld.c:1657: undefined reference to `__access'

In order to prevent this problem, in eglibc source tree: find all makefiles containing ".oS" string (in that exact case) and replace it with ".oZ". Do not touch ".os" strings.

Here is a list of files to be updated for eglibc-2.13:

extra-lib.mk
Makeconfig
Makerules
linuxthreads/Makefile
nptl/Makefile
sysdeps/i386/i686/Makefile
sysdeps/sparc/sparc32/sparcv9/Makefile
 

4. Creating temporary folders for build

gcc and eglibc, and probably other software and libraries will not build in their source folders. So, please create build-gmp, build-mpfr, build-mpc, build-binutils, build-gcc, build-eglibc and build-linux subfolders in C:\Cygwin\opt\crosstool\src. These subfolders will contain intermediary build results when corresponding software will be built.
 

5. Creating script files

Also please prepare stub batch file C:\Cygwin\opt\crosstool\src\build_gcc_cross.cmd with the following contents:

@echo off
set PATH=C:\Cygwin\bin;%PATH%
bash.exe -l -c /opt/crosstool/src/build_gcc_cross.sh

Also please prepare main build script file C:\Cygwin\opt\crosstool\src\build_gcc_cross.sh with the following contents:

#!/bin/bash

echo "=== build script: OK ==="

and apply Cygwin dos2unix tool to it in order to convert 0x0D,0x0A line endings (DOS/Windows format) to 0x0A line endings (UNIX format).

Then run build_gcc_cross.cmd to make sure scripts work as expected.


It's recommended to shutdown the virtual machine and make snapshot "SNAP-2" when initial deployment is done. Otherwise in case of any errors in future you'll have to start all this Rube Goldbergy again.


>> Read next section or buy already prepared cross-compiler ($10) to save your time.