I was also porting (now already successfully ported) GCC and Binutils to my OS, and I had _exactly_ the same problem, it took me some weeks to fix it.
Indeed the problem is in libcpp/lex.c file, and I solved it just including an exception for my OS (fiwix) in the line 277. I'm using GCC v4.7.1 so if you are using a different version the line number might vary.
Original line:
Code:
#if (GCC_VERSION >= 4005) && (defined(__i386__) || defined(__x86_64__)) && !(defined(__sun__) && defined(__svr4__))
Patched line which includes my OS:
Code:
#if (GCC_VERSION >= 4005) && (defined(__i386__) || defined(__x86_64__)) && !(defined(__sun__) && defined(__svr4__)) && !defined(__fiwix__)
So now, ported GCC v4.7.1 is able to compile natively in my OS and produce pure i386 executables:
Code:
$ gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=./../libexec/gcc/i386-fiwix/4.7.1/lto-wrapper
Target: i386-fiwix
Configured with: ../gcc-4.7.1/configure --host=i386-fiwix --target=i386-fiwix --prefix=/usr --with-arch=i386 -with-buid-sysroot=/home/mikaku/fiwix/sysroot --with-sysroot=/ --with-gmp=/home/mikaku/fiwix/sysroot --with-mpfr=/home/mikaku/fiwix/sysroot --with-mpc=/home/mikaku/fiwix/sysroot --enable-languages=c,c++ --disable-lto --disable-shared --disable-multilib --with-newlib --disable-nls --disable-werror
Thread model: single
gcc version 4.7.1 (GCC)
I hope that helped you.