Deploying Source Code to Cygwin VM

1. Unpacking source code

Open Cygwin console, create directory /opt/crosstool/src (mkdir -p), and unpack binutils, gcc and glibc into it. Use "tar zxf" to unpack .tar.gz files, "tar jxf" to unpack .tar.bz2 files, and "tar Jxf" to unpack .tar.xz files

Also you need to unpack previously prepared Linux API headers into /opt/crosstool.

In the end, you should get the following folders:


2. Applying patch for glibc

Start Cygwin console and run the following commands:

$ cd /opt/crosstool/src/glibc-2.19
$ cat ../glibc--cygwin-sunrpc-hdrs-libs.diff | patch -p1

3. Preventing glibc build error on case-insensitive filesystem

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

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

In order to prevent this problem, in glibc 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 glibc-2.19:

4. Creating temporary folders for build

gcc and glibc, and probably other software will not build in their source folders. So, please create build-binutils, build-gcc, build-glibc 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%
dos2unix.exe /opt/crosstool/src/
bash.exe -l -c /opt/crosstool/src/

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


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

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.