EDIT: This HOWTO has now been posted on the gentoo-wiki. The version there may be more up to date. This one is now unmaintained.

EDIT: 2007-02-11: Nowdays I think gentoo on colinux would be a better choice for most people than this. It would surely be easer to maintain.

I know it sounds weird, sacreligious even, but there are reasons you would want to do it. The best way of course is to use a distcc enabled livecd but that isn't possible in every situation. So what is one to do? Cygwin to the rescue. It ain't as fast as linux(if you haven't used cygwin much you will be amazed at how slow it compiles stuff), but it will make better use of that cpu than solitaire.

First off there's not much really new in this howto. See references that the bottom. Just thought I would get it all in one place and relate the extra problems and solutions I ran into. This won't get you the smallest or fastest cross toolchain you can get, it is just the basics that worked for me. Also I'm no expert on cross compilers and I've heard they can cause problems with some packages. I haven't had any problems so far but I haven't tested this extensively. If you don't want to compile it all youself then look here.

So, how do we go about this. Well first you need a working cygwin installation, with a full set of build tools. I won't go into that here, there's plenty of info on that over at cygwin.com. You will of course need gcc make and all that. I have cygwin-1.3.22 and gcc-3.2-3 installed for the purposes of this howto.
EDIT: Make sure you choose the "all users" option in the cygwin installation and either have CYGWIN="ntsec tty" in your system environment variables or set it before starting distccd. Thanks Veto.

EDIT: I have been asked to list what packages are needed on cygwin for this. Truth is, I never looked into the minimum requirements for compiling gcc on cygwin. I installed gcc. gcc-g++, make autoconf, automake, m4, and I think those pulled in all the rest I have.

Once you get cygwin installed to your liking and can compile stuff on it you can build the cross-compiler toolchain you will need for compiling programs for linux.

A little convention: Any command that has cygwin$ at the frint is one you execute in the cygwin shell on you windows box and any with linux$ in front is one you run on your gentoo box.

First we set some environment variables. I install to /usr/local/cross-linux because that's where I wanted to put it. You can change that and SRC_ROOT and BUILD but leave the rest alone

Binutils
I have binutils-2.13.90.0.18 on my linux boxes. But couldn't get that to compile on cygwin so I went with binutils-2.13.1. It compiled without a hitch. Now to actually build it. You could also add "--disable-nls" to the configure options but I didn't try it that way.

EDIT:Can't belive I left this out
IMPORTANT Add $prefix/bin to your PATH Before going forward.

Code:

cygwin$ export PATH=$PATH:$prefix/bin

Test

Code:

cygwin$ $TARGET-ld --version
GNU ld version 2.13.1
Copyright 2002 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License. This program has absolutely no warranty.

Binutils looks good so move on.

GLIBC and linux-headers
Everything I read said it wasn't worth it to compile glibc on cygwin so I didn't even try. So get on your linux box and continue. I used glibc-2.3.1 because that's what I have.

GCC
Here I used gcc-3.2.2 since that's what I had on my gentoo boxen. I just grabbed the tarball out of my distfiles and copied it over to the windows box for building.

Code:

cygwin$ cd $SRC_ROOT
cygwin$ tar -xjvf gcc-3.2.2.tar.bz2

At this point you may want to modify gcc to not put the exe extension on executables as it does by default on cygwin. So open $SRC_ROOT/gcc-3.2.2/gcc/config/i386/xm-cygwin.h and comment out the EXECUTABLE_SUFFIX macro. I don't think this is necessary just for distcc use but I did it anyway since this compiler will build linux programs and I can't think of any circumstances where you would want to put the exe extension on them. Anyway now you're ready to build it.

Then empty out your build directory and do the configure, make, make install again. I had to do this but I'm not sure if it is a universal problem with gcc and cygwin or if it was just a problem with my box. It is working fine as far as I can tell so you may want to do this to begin with if your in a hurry. It will have been compiling for a pretty good while before you get this error.

Now when all that's done you should have a working cross-compiler. You can try it out as follows.

That should give you a hello executable that you can copy over to your linux box and run.

distcc
If that's all good now we can compile distcc. This is pretty easy. I used distcc-2.5 because that's what I have on my gentoo boxes. If you've used distcc much you realize that it is important to have the same version on all machines in order for them to play nice.

Now you can just add the windows box to the distcc hosts on a gentoo box and compile something on the linux box and check that it distributes properly.

Optional: Setting up distccd as a service in windows

You will need to have cygrunsrv installed on cygwin for this to work. There are several other ways to do this but I'm just going to cover this one method. Also this will not work on any version of win9x. Only the NT based versions of windows have true services.

First we need a script to make sure distccd gets the proper PATH. I made mine /usr/local/bin/i686-pc-linux-gnu-distccd.sh But you can of course name it whatever.

Appendix: Making it smaller
You probably realized the if you package all this up It makes a huge tarball. I don't really know how far you can go but I was able to reduce it's size by almost half. I haven't tested this extensively so it may break things, I don't know. When you build glibc on the linux box you can remove a bunch of stuff. Delete all the directories inside of /usr/local/cross-linux/i686-pc-linux-gnu except include and lib. You can also remove most of the contents of the lib directory, see khan's article for what you need to leave. Finally when it is all done on the windows box you can remove the info and man directories from /usr/local/cross-linux to save a little more space. I'm sure there are other things you can do as there is a 22MB tarball out there and the smallest I've managed so far is 27MB not including distcc.

EDIT: Various typo corections.

Last edited by PowerFactor on Sun Feb 11, 2007 5:06 pm; edited 11 times in total

Okay, I have created a cross-linux-3.2.2 with binutils and gcc from Gentoo stable (2.13.90 & 3.2.2) and tar.bz2'ed it up. I'm coming in ~28MB. If someone wants a copy or would like to host it, drop me a line. All that is missing is distcc and I'm thinking about building it into cross-linux as well, with the distccd.sh script so it's completely self-containted.

Very cool stuff, now my slackard WinXP boxes can join in the fun when it comes time to compile KDE or X or what have you.

Additonally, from my initial tests it looks like there may be some massaging needed for building gcc-3.2.3/binutils-2.14.x.x.x, I'm running into some issues with gcc-3.2.3 removing some headers and binutils-2.14 possibly being broken...not sure yet, I'm going through the steps again as it was very late last night when I ran into them.

2) Do not make the symlink from include to sys-include, gcc-3.2.3 will copy the needed files from include to sys-include and apparently removes to source...which is a bad thing if you have a symlink.

I now have a new binutils-2.14xxx, glibc-2.3.2, gcc-3.2.3 cross-linux setup for cygwin. Only downside is that it's grown to 48MB, but it looks like some of that is due to keeping the .a's around which I don't mind.

Just so you know, I really appreciate you keeping this HOWTO up to date, it's a great resource for people thinking about doing this. I'm actually suprised more people aren't using cygwin on their resting Windows boxes.

I found one other thing you might want to add for the service part, mine wouldn't start properly and I tracked it down to the install method and something that I needed to add to the cygrunsrv.

1) Install cygwin for all users, not "Only this user"...it'll just make things better down the road.

The last part with the CYGWIN seemed to make it work fine for me on my burner machine and when I snuck a Cygwin install onto my wife's laptop a bit ago. (with the service running and at --nice 19, she'll never know the difference!)

It's damned nifty to do a base cygwin install with just checking off cygrunsrv, 2-3 minutes later you bring over the .tar.bz2 file and untar it and you have a distcc host up and running with service in less than 10 minutes and the machine doesn't have any visible footprint of you ever doing anything.

Thanks Veto, just trying to do a little something for the community. Glad to know someone in getting some use out of it.

Good point on the "all users" install. I've never used the "only for this user" install so I didn't think about it. I've also had CYGWIN="ntsec tty binmode" in my system environment varibles since "the beginning" so I didn't think about that either.

About that tcpip dependancy. Is this a XP box you're running? I have 2k and I don't seem to have that service. At least I cant find it. I tried reinstalling distccd with that dependancy and I didn't get any error. And it starts fine. But when I look at distccd in the services applet it still shows no dependencies, so that makes me more suspicious that I don't have a service by that name on my box.

Hello !
First of all, thanks a lot for this nice HOWTO.
But (yes, there's a but ), I have a little problem with gcc compilation. I followed the first steps and everything worked like a charm. Then, I tried to compile gcc 3.2-3, following the instructions. Gcc itself is ok, but the libraries won't compile. I get stuck with thoses error messages :

It seems like the stdlib.h used is not the good one. So I tried to change its path in include statements, with no luck.
I don't understand why all theses structures are not declared. If somebody could point me out the problem...

I've got a wee bit of a problem. I followed the directions except I replaced binutils, glibc, and gcc with their newer portage counterparts. Whenever I attempt to use distcc, anything that is compiled on the windows machine will result in a "file not recognized: File format not recognized" error. The test hello world program does work fine on my linux machine though. Any ideas?

Kick: I was never able to get gcc-3.2-3(the cygwin gcc) to compile as a cross-compiler. I used gcc-3.2.2 (haven't upgraded any of my boxes to 3.2.3 yet) and Veto was able to sucessfully compile gcc-3.2.3 so you might want to try one of those.

Safrax: If the test program runs then you must have the tools built correctly. My guess is that your PATH is not being set correctly and distcc is using the native cygwin gcc instead of your cross-compiler. Have a look at the distcc section again.

Crappy machine translation for those of us who don't understand french...

Quote:

while installing gentoo on VMware under Windows, that can also go,
after is necessary to see with dimensions performance of compilation!

what think about it?

Is rk187 asking which would perform better at compiling, this or gentoo under vmware? I quite frankly don't know. I don't have a copy of vmware and probably won't anytime soon since I can build a pretty decent box (relative to any that I currently have anyway) for the same money. (And yes, I know they have a free trial.) Plus my windows box presently doesn't really have enough ram to run vmware well. And until recently neither did my main linux box.

Is rk187 asking which would perform better at compiling, this or gentoo under vmware? I quite frankly don't know. I don't have a copy of vmware and probably won't anytime soon since I can build a pretty decent box (relative to any that I currently have anyway) for the same money. (And yes, I know they have a free trial.) Plus my windows box presently doesn't really have enough ram to run vmware well. And until recently neither did my main linux box.

I have a copy of vmware on the same machine im trying to do this cross compiling thing on. It's a lowly 1.7ghz p4 with 256kb of cache, 400mhz fsb and 512mb of sdram. It's not a fast computer by any means. I haven't had much time to test this setup but from initial observations the cygwin cross compiler setup seems to be faster than the vmware virtual machine. The extra overhead for compiling under vmware, set ram limit, virtualization of devices, etc takes its toll on I/O of any form. Cygwin doesn't really have this problem. I guess what I'm saying is that Cygwin should be faster but I dunno if it is or not without more testing.

Should you get any errors while compiling GCC, GLIBC or BINUTILS, you might want to try getting Portage to apply patches on the source. To do this on GCC, you can:

Code:

# ebuild /usr/portage/sys-devel/gcc/gcc-3.3.1-r4.ebuild unpack

That will unpack GCC source, and apply patches at the same time. I think the most important files yet are the branch updates. Anyway, I received a problem in when using variable-length arguments (or something about "format" in the errors) in sscanf while compiling GLIBC using the stock source.

BINUTILS 2.14.0 straight from GNU should compile without fail using Cygwin GCC. (At least it did not in my case). It failed with 2.14.90.0 (... perhaps because I had not used portage-patched BINUTILS?)

Having troubles once I get to the section on compiling gcc (3.3.2-r2) on the cygwin machine. One error had to do with a missing wchar.h, where I had to edit _G_config.h to change:
#include <wchar.h> -> #include <bits/wchar.h>

Maybe we ought to build an ebuild to handle this for us so that we can always have a sync'd cross-compiler with our linux systems that can just be installed on the cygwin systems. Any thoughts?

Oh yes, I absolutely agree this idea. It would be much easier than downloading sources, patching, passing right configuration options and compiling, all by hand on the Cygwin distcc host, each time Gentoo GCC is updated. I'm ready to thoroughly test any ebuild written in this way.