WHAT I DID.

{In the course of this, I think that cygwin copied binutils CVS into the
winsup CVS. Maybe I'm crazy. The CVS logs shows a full history, so...
But, binutils isn't needed anymore}

Pick a directory to build in. In my case /0g/sandboxes

0) download, ./configure, make and install cocom from
   http://cocom.sourceforge.net/
   (They have an RPM, but I didn't find a .deb)
   This gets you the "shakli" program. It is a program to help create
   fast parsers. I think it is used for the fs emulation layer.

a) extract gcc-4.0.1
b) check out winsup as told on:
           http://cygwin.com/cvs.html

d) cd winsup
      ln -s ../gcc-4.0.1/fixincludes .
      ln -s ../gcc-4.0.1/gcc .
      ln -s ../gcc-4.0.1/libcpp .
      ln -s ../gcc-4.0.1/libstdc++-v3 .
      rm -rf winsup/mingw               # has CC_FOR_TARGET/CC mixups
      rm -rf sid                        # has some problem,and we don't need it
      rm -rf rda                        # has dependency on intl, which
                                        # doesn't get built.


MAKE SURE THAT "." is not in your PATH.
Some symlinks are made by the name "as" which can screw things up.

e) cd ..
   mkdir build
   cd build

   ../../winsup/configure --prefix=/xelerance/cross/win2k --target=i686-pc-cygwin --without-headers --with-newlib --disable-shared --enable-languages=c,c++
   make
   mkdir -p /xelerance/cross/win2k/lib/gcc/i686-pc-cygwin/4.0.1/install-tools/include
   make install

f) cat hello/hello.c
#include <stdio.h>

main(int argc, char *argv[])
{
        printf("hello there\n");
}

        cd hello
        PATH=/xelerance/cross/win2k/bin:$PATH export PATH
        make CC=i686-pc-cygwin-gcc hello
        scp hello win2kmachine:
        ssh win2kmachine ./hello

g) build your favorite stuff, e.g:
   extract libgmp4,
   mkdir build/gmp4
   cd build/gmp4
   PATH=/xelerance/cross/win2k/bin:$PATH export PATH
   CC=i686-pc-cygwin-gcc ../../gmp-4.1.2/configure --prefix=/xelerance/cross/win2k/i686-pc-cygwin/include --host=i686-pc-cygwin --with-pic

   (--with-pic gets rid of some issues that I had with the assembly,
   at a cost of some performance)


WHAT I FIXED
============

CC and CC_FOR_TARGET are confused a lot in the winsup makefiles.
CC is only when building stuff you need to run on the local machine.
The patch is attached against CVS from 2005-08-03.

I had an issue with cp-demangle.c. I never resolved it. I don't get it.
I later found that it was because I had linked libstdc++ to the gcc-3.4.3
version rather than the gcc-4.0.1 version.

I "fixed" it by doing:

In winsup/cygwin/Makefile.in, the build of cygwin0.dll (aka ${TEST_DLL_NAME}),
has to reference -lcygwin, which hasn't been built/installed yet. (it is in
. as libcygwin.a)

I actually don't think we should -lcygwin at all. Two possible solutions are:

      a)  -nostdlib -lstdc++ -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc
      b)  -L.

I prefer (a), because we shouldn't be referencing it all.

I was not able to build mingw, which is why I move it aside in (d).
I did not investigate this deeply, since I don't care about native code for
the moment.

WHAT I DID WRONG
================

The first time, I tried building binutils separately.
This failed when building GCC 3.x. The problem is that the AR_FOR_TARGET
macros used in the makefiles for gcc are, it seems expanded a variable number
of times in different paths, and the t=/echo $$t stuff got expanded by MAKE
rather than by the shell script.

I rebuilt again with the ln-s for binutils, and this didn't happen, because
one never gets to that part of the condition for AR_FOR_TARGET. So there is
still a bug there, but I didn't manage to fix it.

--
] Michael Richardson          Xelerance Corporation, Ottawa, ON |  firewalls  [
] mcr @ xelerance.com           Now doing IPsec training, see   |net architect[
] http://www.sandelman.ca/mcr/    www.xelerance.com/training/   |device driver[
]                    I'm a dad: http://www.sandelman.ca/lrmr/                 [
