
Original binutils cross patch by David Woodhouse:

	https://www.redhat.com/archives/fedora-devel-list/2007-June/msg01607.html

gcc and gdb cross patches by Lennert Buytenhek.


Index: SPECS/binutils.spec
===================================================================
--- SPECS.orig/binutils.spec
+++ SPECS/binutils.spec
@@ -1,7 +1,16 @@
+%if "%{?cross_target}" == ""
+%define binutils_target %{_target_platform}
+%define isnative 1
+%else
+%define binutils_target %{cross_target}
+%define cross %{binutils_target}-
+%define isnative 0
+%endif
+
 Summary: A GNU collection of binary utilities.
-Name: binutils
+Name: %{?cross}binutils
 Version: 2.17.50.0.18
-Release: 1.fa1
+Release: 1.fa1.cross4
 License: GPLv3+
 Group: Development/Tools
 URL: http://sources.redhat.com/binutils
@@ -20,7 +29,7 @@ Patch11: binutils-2.17.50.0.18-texinfo-v
 
 Buildroot: %{_tmppath}/binutils-root
 BuildRequires: texinfo >= 4.0, dejagnu, gettext, flex, bison
-Conflicts: gcc-c++ < 4.0.0
+Conflicts: %{?cross}gcc-c++ < 4.0.0
 Prereq: /sbin/install-info
 %ifarch ia64
 Obsoletes: gnupro
@@ -47,7 +56,7 @@ addresses to file and line).
 %package devel
 Summary: BFD and opcodes static libraries and header files
 Group: System Environment/Libraries
-Conflicts: binutils < 2.17.50.0.3-4
+Conflicts: %{?cross}binutils < 2.17.50.0.3-4
 Prereq: /sbin/install-info
 
 %description devel
@@ -57,7 +66,7 @@ have a stable ABI.  Developers starting 
 to consider using libelf instead of BFD.
 
 %prep
-%setup -q
+%setup -q -n binutils-%{version}
 %patch1 -p0 -b .ltconfig-multilib~
 %patch2 -p0 -b .ppc64-pie~
 %patch3 -p0 -b .place-orphan~
@@ -74,7 +83,7 @@ to consider using libelf instead of BFD.
 %patch10 -p0 -b .open~
 %patch11 -p0 -b .texinfo~
 
-# On ppc64 we might use 64K pages
+# On ppc64 we might use 64KiB pages
 sed -i -e '/#define.*ELF_COMMONPAGESIZE/s/0x1000$/0x10000/' bfd/elf*ppc.c
 # LTP sucks
 perl -pi -e 's/i\[3-7\]86/i[34567]86/g' */conf*
@@ -86,24 +95,36 @@ sed -i -e 's/^libbfd_la_LDFLAGS = /&-Wl,
 sed -i -e 's/^libopcodes_la_LDFLAGS = /&-Wl,-Bsymbolic-functions /' opcodes/Makefile.{am,in}
 fi
 touch */configure
+sed -i -e 's/^ PACKAGE=/ PACKAGE=%{?cross}/' */configure
 
 %build
-mkdir build-%{_target_platform}
-cd build-%{_target_platform}
+mkdir build-%{binutils_target}
+cd build-%{binutils_target}
 CARGS=
-%ifarch sparc ppc s390
-CARGS=--enable-64-bit-bfd
-%endif
-%ifarch ia64
-CARGS=--enable-targets=i386-linux
+case %{binutils_target} in
+    sparc*|ppc*|s390*)
+	CARGS=--enable-64-bit-bfd
+	;;
+    ia64*)
+	CARGS=--enable-targets=i386-linux
+	;;
+esac
+%if %{isnative}
+    SHAREDARGS=--enable-shared
+    TARGET=%{binutils_target}
+    SYSROOT=
+%else
+    SHAREDARGS=--disable-shared
+    TARGET="--build=%{_target_platform} --host=%{_target_platform} --target=%{binutils_target}"
+    SYSROOT="--with-sysroot=yes"
 %endif
 CC="gcc -L`pwd`/bfd/.libs/" CFLAGS="${CFLAGS:-%optflags}" ../configure \
-  %{_target_platform} --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} \
+  $TARGET --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} \
   --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} \
   --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} \
   --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} \
   --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} \
-  --infodir=%{_infodir} --enable-shared $CARGS --disable-werror \
+  --infodir=%{_infodir} $SHAREDARGS $CARGS --disable-werror $SYSROOT \
   --with-bugurl=http://bugzilla.redhat.com/bugzilla/
 make %{_smp_mflags} tooldir=%{_prefix} all
 make %{_smp_mflags} tooldir=%{_prefix} info
@@ -116,8 +137,9 @@ cd ..
 %install
 rm -rf %{buildroot}
 mkdir -p %{buildroot}%{_prefix}
-cd build-%{_target_platform}
+cd build-%{binutils_target}
 %makeinstall
+%if %{isnative}
 make prefix=%{buildroot}%{_prefix} infodir=%{buildroot}%{_infodir} install-info
 gzip -q9f %{buildroot}%{_infodir}/*.info*
 
@@ -139,10 +161,6 @@ rm -f %{buildroot}%{_prefix}/%{_lib}/lib
 # Remove libtool files, which reference the .so libs
 rm -f %{buildroot}%{_prefix}/%{_lib}/lib{bfd,opcodes}.la
 
-# This one comes from gcc
-rm -f %{buildroot}%{_infodir}/dir
-rm -rf %{buildroot}%{_prefix}/%{_target_platform}
-
 %ifarch %{ix86} x86_64 ppc ppc64 s390 s390x sparc sparc64
 sed -i -e '/^#include "ansidecl.h"/{p;s~^.*$~#include <bits/wordsize.h>~;}' \
 %ifarch %{ix86} x86_64
@@ -160,22 +178,36 @@ sed -i -e '/^#include "ansidecl.h"/{p;s~
 %endif
 touch -r ../bfd/bfd-in2.h %{buildroot}%{_prefix}/include/bfd.h
 
+%else # native
+# For cross-binutils we drop the documentation.
+rm -rf %{buildroot}%{_infodir}
+#rm -rf %{buildroot}%{_prefix}/share/locale
+#rm -rf %{buildroot}%{_mandir}
+rm -rf %{buildroot}%{_prefix}/%{_lib}/libiberty.a
+%endif # native
+
+# This one comes from gcc
+rm -f %{buildroot}%{_infodir}/dir
+#rm -rf %{buildroot}%{_prefix}/%{binutils_target}
+
+
 cd ..
-%find_lang binutils
-%find_lang opcodes
-%find_lang bfd
-%find_lang gas
-%find_lang ld
-%find_lang gprof
-cat opcodes.lang >> binutils.lang
-cat bfd.lang >> binutils.lang
-cat gas.lang >> binutils.lang
-cat ld.lang >> binutils.lang
-cat gprof.lang >> binutils.lang
+%find_lang %{?cross}binutils
+%find_lang %{?cross}opcodes
+%find_lang %{?cross}bfd
+%find_lang %{?cross}gas
+%find_lang %{?cross}ld
+%find_lang %{?cross}gprof
+cat %{?cross}opcodes.lang >> %{?cross}binutils.lang
+cat %{?cross}bfd.lang >> %{?cross}binutils.lang
+cat %{?cross}gas.lang >> %{?cross}binutils.lang
+cat %{?cross}ld.lang >> %{?cross}binutils.lang
+cat %{?cross}gprof.lang >> %{?cross}binutils.lang
 
 %clean
 rm -rf %{buildroot}
 
+%if %{isnative}
 %post
 /sbin/ldconfig
 /sbin/install-info --info-dir=%{_infodir} %{_infodir}/as.info.gz
@@ -206,12 +238,16 @@ exit 0
 if [ $1 = 0 ] ;then
   /sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/bfd.info.gz || :
 fi
+%endif # native
 
-%files -f binutils.lang
+%files -f %{?cross}binutils.lang
 %defattr(-,root,root)
 %doc README
 %{_prefix}/bin/*
 %{_mandir}/man1/*
+%if !%{isnative}
+%{_prefix}/%{binutils_target}
+%else
 %{_prefix}/%{_lib}/lib*.so
 %{_infodir}/[^b]*info*
 %{_infodir}/binutils*info*
@@ -221,6 +257,7 @@ fi
 %{_prefix}/include/*
 %{_prefix}/%{_lib}/lib*.a
 %{_infodir}/bfd*info*
+%endif # native
 
 %changelog
 * Thu Aug 16 2007 Jakub Jelinek <jakub@redhat.com> 2.17.50.0.18-1
Index: SPECS/gcc41.spec
===================================================================
--- SPECS.orig/gcc41.spec
+++ SPECS/gcc41.spec
@@ -1,14 +1,36 @@
+%if "%{?cross_target}" == ""
+%define gcc_target %{_target_platform}
+%define isnative 1
+%else
+%define gcc_target %{cross_target}
+%define isnative 0
+%define cross %{gcc_target}-
+%define crosspost -%{gcc_target}
+%define __strip %{gcc_target}-strip
+%define _lib lib
+%define _use_internal_dependency_generator 0
+%define __find_requires %{nil}
+%define __find_provides %{nil}
+%endif
+
 %define DATE 20070925
 %define gcc_version 4.1.2
-%define gcc_release 33
+%define gcc_release 33.fa1
 %define _unpackaged_files_terminate_build 0
-%define multilib_64_archs sparc64 ppc64 s390x x86_64
 %define include_gappletviewer 1
+%if !%{isnative}
+%define build_ada 0
+%define build_fortran 0
+%define build_java 0
+%define build_objc 0
+%define run_tests 0
+%else
 %ifarch %{ix86} x86_64 ia64 ppc alpha
 %define build_ada 1
 %else
 %define build_ada 0
 %endif
+%define build_fortran 1
 %ifnarch %{arm}
 %define build_java 1
 %define build_objc 1
@@ -17,6 +39,7 @@
 %define build_objc 0
 %endif
 %define run_tests 0
+%define multilib_64_archs sparc64 ppc64 s390x x86_64
 %ifarch s390x
 %define multilib_32_arch s390
 %endif
@@ -29,10 +52,11 @@
 %ifarch x86_64
 %define multilib_32_arch i386
 %endif
+%endif
 Summary: Various compilers (C, C++, Objective-C, Java, ...)
-Name: gcc
+Name: %{?cross}gcc
 Version: %{gcc_version}
-Release: %{gcc_release}.fa1
+Release: %{gcc_release}.cross4
 # libgcc, libgfortran, libmudflap and crtstuff have an exception which allows
 # linking it into any kind of programs or shared libraries without
 # restrictions.
@@ -52,7 +76,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version
 # Need binutils which support mffgpr and mftgpr >= 2.17.50.0.2-8
 # Need binutils which support 2-argument .movsp >= 2.17.50.0.5
 # Need binutils which support --build-id >= 2.17.50.0.17-3
-BuildRequires: binutils >= 2.17.50.0.17-3
+BuildRequires: %{?cross}binutils >= 2.17.50.0.17-3
 BuildRequires: zlib-devel, gettext, dejagnu, bison, flex, texinfo, sharutils
 %if %{build_java}
 BuildRequires: gcc-java, libgcj, /usr/share/java/eclipse-ecj.jar, zip, unzip
@@ -60,24 +84,32 @@ BuildRequires: gcc-java, libgcj, /usr/sh
 # Make sure pthread.h doesn't contain __thread tokens
 # Make sure glibc supports stack protector
 # Make sure glibc supports DT_GNU_HASH
-BuildRequires: glibc-devel >= 2.4.90-13
+%if 0%{?uclibc}
+BuildRequires: uClibc-devel%{?crosspost}
+%else
+BuildRequires: glibc-devel%{?crosspost} >= 2.4.90-13
+%endif
 BuildRequires: elfutils-devel >= 0.72
+%if %{isnative}
 %ifarch ppc ppc64 s390 s390x sparc sparcv9 alpha
 # Make sure glibc supports TFmode long double
-BuildRequires: glibc >= 2.3.90-35
+BuildRequires: glibc%{?crosspost} >= 2.3.90-35
 %endif
 %ifarch %{multilib_64_archs} sparc ppc
 # Ensure glibc{,-devel} is installed for both multilib arches
 BuildRequires: /lib/libc.so.6 /usr/lib/libc.so /lib64/libc.so.6 /usr/lib64/libc.so
 %endif
+%endif
 %if %{build_ada}
 # Ada requires Ada to build
 BuildRequires: gcc-gnat >= 3.1, libgnat >= 3.1
 %endif
+%if %{isnative}
 %ifarch ia64
 BuildRequires: libunwind >= 0.98
 %endif
-Requires: cpp = %{version}-%{release}
+%endif
+Requires: %{?cross}cpp = %{version}-%{release}
 # Need .eh_frame ld optimizations
 # Need proper visibility support
 # Need -pie support
@@ -89,16 +121,23 @@ Requires: cpp = %{version}-%{release}
 # Need binutils that support mffgpr/mftgpr
 # Need binutils that support 2-argument .movsp
 # Need binutils that support --build-id
-Requires: binutils >= 2.17.50.0.17-3
+Requires: %{?cross}binutils >= 2.17.50.0.17-3
 # Make sure gdb will understand DW_FORM_strp
-Conflicts: gdb < 5.1-2
-Requires: glibc-devel >= 2.2.90-12
+Conflicts: %{?cross}gdb < 5.1-2
+%if 0%{?uclibc}
+Requires: uClibc-devel%{?crosspost}
+%else
+Requires: glibc-devel%{?crosspost} >= 2.2.90-12
+%endif
+%if %{isnative}
 %ifarch ppc ppc64 s390 s390x sparc sparcv9 alpha
 # Make sure glibc supports TFmode long double
-Requires: glibc >= 2.3.90-35
+Requires: glibc%{?crosspost} >= 2.3.90-35
+%endif
 %endif
-Requires: libgcc >= %{version}-%{release}
-Requires: libgomp = %{version}-%{release}
+Requires: %{?cross}libgcc >= %{version}-%{release}
+Requires: %{?cross}libgomp = %{version}-%{release}
+%if %{isnative}
 Obsoletes: gcc3
 Obsoletes: egcs
 %ifarch sparc
@@ -110,10 +149,12 @@ Obsoletes: gcc-ppc32
 Obsoletes: gcc-c++-ppc32
 %endif
 Obsoletes: gcc-chill
+%endif
 %if !%{build_ada}
-Obsoletes: gcc-gnat < %{version}-%{release}
-Obsoletes: libgnat < %{version}-%{release}
+Obsoletes: %{?cross}gcc-gnat < %{version}-%{gcc_release}
+Obsoletes: %{?cross}libgnat < %{version}-%{gcc_release}
 %endif
+%if %{isnative}
 %ifarch sparc sparc64
 Obsoletes: egcs64
 %endif
@@ -121,6 +162,7 @@ Obsoletes: gcc34
 Obsoletes: gcc35
 Obsoletes: gcc4
 Prereq: /sbin/install-info
+%endif
 AutoReq: true
 
 Patch1: gcc41-ice-hack.patch
@@ -183,6 +225,7 @@ Patch106: 128250.diff
 %ifnarch %{arm}
 %define _gnu %{nil}
 %endif
+%if "%{?gcc_target}" == ""
 %ifarch sparc
 %define gcc_target_platform sparc64-%{_vendor}-%{_target_os}
 %endif
@@ -192,30 +235,35 @@ Patch106: 128250.diff
 %ifnarch sparc ppc
 %define gcc_target_platform %{_target_platform}
 %endif
+%else
+%define gcc_target_platform %{gcc_target}
+%endif
 
 %description
 The gcc package contains the GNU Compiler Collection version 4.1.
 You'll need this package in order to compile C code.
 
-%package -n libgcc
+%package -n %{?cross}libgcc
 Summary: GCC version 4.1 shared support library
 Group: System Environment/Libraries
 Autoreq: false
 
-%description -n libgcc
+%description -n %{?cross}libgcc
 This package contains GCC shared support library which is needed
 e.g. for exception handling support.
 
 %package c++
 Summary: C++ support for GCC
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}
-Requires: libstdc++ = %{version}-%{release}
-Requires: libstdc++-devel = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
+Requires: %{?cross}libstdc++ = %{version}-%{release}
+Requires: %{?cross}libstdc++-devel = %{version}-%{release}
+%if %{isnative}
 Obsoletes: gcc3-c++
 Obsoletes: gcc34-c++
 Obsoletes: gcc35-c++
 Obsoletes: gcc4-c++
+%endif
 Autoreq: true
 
 %description c++
@@ -223,26 +271,31 @@ This package adds C++ support to the GNU
 It includes support for most of the current C++ specification,
 including templates and exception handling.
 
-%package -n libstdc++
+%package -n %{?cross}libstdc++
 Summary: GNU Standard C++ Library
 Group: System Environment/Libraries
+%if %{isnative}
 Obsoletes: libstdc++3
 Obsoletes: libstdc++34
+%endif
 Autoreq: true
 
-%description -n libstdc++
+%description -n %{?cross}libstdc++
 The libstdc++ package contains a rewritten standard compliant GCC Standard
 C++ Library.
 
-%package -n libstdc++-devel
+%package -n %{?cross}libstdc++-devel
 Summary: Header files and libraries for C++ development
 Group: Development/Libraries
-Requires: libstdc++ = %{version}-%{release}, %{_prefix}/%{_lib}/libstdc++.so.6
+Requires: %{?cross}libstdc++ = %{version}-%{release}
+%if %{isnative}
+Requires: %{_prefix}/%{_lib}/libstdc++.so.6
 Obsoletes: libstdc++3-devel
 Obsoletes: libstdc++34-devel
+%endif
 Autoreq: true
 
-%description -n libstdc++-devel
+%description -n %{?cross}libstdc++-devel
 This is the GNU implementation of the standard C++ libraries.  This
 package includes the header files and libraries needed for C++
 development. This includes rewritten implementation of STL.
@@ -250,9 +303,11 @@ development. This includes rewritten imp
 %package objc
 Summary: Objective-C support for GCC
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}
-Requires: libobjc = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
+Requires: %{?cross}libobjc = %{version}-%{release}
+%if %{isnative}
 Obsoletes: gcc3-objc
+%endif
 Autoreq: true
 
 %description objc
@@ -263,70 +318,75 @@ object-oriented derivative of the C lang
 %package objc++
 Summary: Objective-C++ support for GCC
 Group: Development/Languages
-Requires: gcc-c++ = %{version}-%{release}, gcc-objc = %{version}-%{release}
+Requires: %{?cross}gcc-c++ = %{version}-%{release}
+Requires: %{?cross}gcc-objc = %{version}-%{release}
 Autoreq: true
 
 %description objc++
 gcc-objc++ package provides Objective-C++ support for the GCC.
 
-%package -n libobjc
+%package -n %{?cross}libobjc
 Summary: Objective-C runtime
 Group: System Environment/Libraries
 Autoreq: true
 
-%description -n libobjc
+%description -n %{?cross}libobjc
 This package contains Objective-C shared library which is needed to run
 Objective-C dynamically linked programs.
 
 %package gfortran
 Summary: Fortran 95 support
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}
-Requires: libgfortran = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
+Requires: %{?cross}libgfortran = %{version}-%{release}
+%if %{isnative}
 BuildRequires: gmp-devel >= 4.1.2-8, mpfr-devel >= 2.2.1
 Prereq: /sbin/install-info
 Obsoletes: gcc3-g77
 Obsoletes: gcc-g77
 Obsoletes: gcc4-gfortran
+%endif
 Autoreq: true
 
 %description gfortran
 The gcc-gfortran package provides support for compiling Fortran 95
 programs with the GNU Compiler Collection.
 
-%package -n libgfortran
+%package -n %{?cross}libgfortran
 Summary: Fortran 95 runtime
 Group: System Environment/Libraries
+%if %{isnative}
 Obsoletes: libf2c
+%endif
 Autoreq: true
 
-%description -n libgfortran
+%description -n %{?cross}libgfortran
 This package contains Fortran 95 shared library which is needed to run
 Fortran 95 dynamically linked programs.
 
-%package -n libgomp
+%package -n %{?cross}libgomp
 Summary: GCC OpenMP 2.5 shared support library
 Group: System Environment/Libraries
 
-%description -n libgomp
+%description -n %{?cross}libgomp
 This package contains GCC shared support library which is needed
 for OpenMP 2.5 support.
 
-%package -n libmudflap
+%package -n %{?cross}libmudflap
 Summary: GCC mudflap shared support library
 Group: System Environment/Libraries
 
-%description -n libmudflap
+%description -n %{?cross}libmudflap
 This package contains GCC shared support library which is needed
 for mudflap support.
 
-%package -n libmudflap-devel
+%package -n %{?cross}libmudflap-devel
 Summary: GCC mudflap support
 Group: Development/Libraries
-Requires: libmudflap = %{version}-%{release}
-Requires: gcc = %{version}-%{release}
+Requires: %{?cross}libmudflap = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
 
-%description -n libmudflap-devel
+%description -n %{?cross}libmudflap-devel
 This package contains headers and static libraries for building
 mudflap-instrumented programs.
 
@@ -337,84 +397,100 @@ also add -fmudflapth and -lmudflapth.
 %package java
 Summary: Java support for GCC
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}
-Requires: libgcj = %{version}-%{release}
-Requires: libgcj-devel = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
+Requires: %{?cross}libgcj = %{version}-%{release}
+Requires: %{?cross}libgcj-devel = %{version}-%{release}
+%if %{isnative}
 Requires: /usr/share/java/eclipse-ecj.jar
 Obsoletes: gcc3-java
 Obsoletes: gcc34-java
 Obsoletes: gcc35-java
 Obsoletes: gcc4-java
 Prereq: /sbin/install-info
+%endif
 Autoreq: true
 
 %description java
 This package adds support for compiling Java(tm) programs and
 bytecode into native code.
 
-%package -n libgcj
+%package -n %{?cross}libgcj
 Summary: Java runtime library for gcc
 Group: System Environment/Libraries
+%if %{isnative}
 Prereq: /sbin/install-info
+%endif
 Requires: zip >= 2.1
-Requires: gtk2 >= 2.4.0
-Requires: glib2 >= 2.4.0
-Requires: libart_lgpl >= 2.1.0
+Requires: gtk2%{?crosspost} >= 2.4.0
+Requires: glib2%{?crosspost} >= 2.4.0
+Requires: libart_lgpl%{?crosspost} >= 2.1.0
 %if %{build_java}
-BuildRequires: gtk2-devel >= 2.4.0
-BuildRequires: glib2-devel >= 2.4.0
-BuildRequires: firefox-devel
-BuildRequires: libart_lgpl-devel >= 2.1.0
-BuildRequires: alsa-lib-devel
-BuildRequires: libXtst-devel
-BuildRequires: libXt-devel
+BuildRequires: gtk2-devel%{?crosspost} >= 2.4.0
+BuildRequires: glib2-devel%{?crosspost} >= 2.4.0
+BuildRequires: firefox-devel%{?crosspost}
+BuildRequires: libart_lgpl-devel%{?crosspost} >= 2.1.0
+BuildRequires: alsa-lib-devel%{?crosspost}
+BuildRequires: libXtst-devel%{?crosspost}
+BuildRequires: libXt-devel%{?crosspost}
 %endif
+%if %{isnative}
 Obsoletes: gcc-libgcj
 Obsoletes: libgcj3
 Obsoletes: libgcj34
 Obsoletes: libgcj4
+%endif
 Autoreq: true
 
-%description -n libgcj
+%description -n %{?cross}libgcj
 The Java(tm) runtime library. You will need this package to run your Java
 programs compiled using the Java compiler from GNU Compiler Collection (gcj).
 
-%package -n libgcj-devel
+%package -n %{?cross}libgcj-devel
 Summary: Libraries for Java development using GCC
 Group: Development/Languages
-Requires: libgcj = %{version}-%{release}, %{_prefix}/%{_lib}/libgcj.so.8rh
-Requires: zlib-devel, %{_prefix}/%{_lib}/libz.so
+Requires: %{?cross}libgcj = %{version}-%{release}
+Requires: zlib-devel%{?crosspost}
+%if %{isnative}
+Requires: %{_prefix}/%{_lib}/libgcj.so.8rh
+Requires: %{_prefix}/%{_lib}/libz.so
+%endif
 Requires: /bin/awk
+%if %{isnative}
 Obsoletes: libgcj3-devel
 Obsoletes: libgcj34-devel
 Obsoletes: libgcj4-devel
+%endif
 Autoreq: false
 Autoprov: false
 
-%description -n libgcj-devel
+%description -n %{?cross}libgcj-devel
 The Java(tm) static libraries and C header files. You will need this
 package to compile your Java programs using the GCC Java compiler (gcj).
 
-%package -n libgcj-src
+%package -n %{?cross}libgcj-src
 Summary: Java library sources from GCC4 preview
 Group: System Environment/Libraries
-Requires: libgcj = %{version}-%{release}
+Requires: %{?cross}libgcj = %{version}-%{release}
+%if %{isnative}
 Obsoletes: libgcj4-src
+%endif
 Autoreq: true
 
-%description -n libgcj-src
+%description -n %{?cross}libgcj-src
 The Java(tm) runtime library sources for use in Eclipse.
 
-%package -n cpp
+%package -n %{?cross}cpp
 Summary: The C Preprocessor.
 Group: Development/Languages
+%if %{isnative}
 Prereq: /sbin/install-info
 %ifarch ia64
 Obsoletes: gnupro
 %endif
+%endif
 Autoreq: true
 
-%description -n cpp
+%description -n %{?cross}cpp
 Cpp is the GNU C-Compatible Compiler Preprocessor.
 Cpp is a macro processor which is used automatically
 by the C compiler to transform your program before actual
@@ -439,22 +515,27 @@ macros.
 %package gnat
 Summary: Ada 95 support for GCC
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}, libgnat = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
+Requires: %{?cross}libgnat = %{version}-%{release}
+%if %{isnative}
 Obsoletes: gnat-devel, gcc3-gnat
 Prereq: /sbin/install-info
+%endif
 Autoreq: true
 
 %description gnat
 GNAT is a GNU Ada 95 front-end to GCC. This package includes development tools,
 the documents and Ada 95 compiler.
 
-%package -n libgnat
+%package -n %{?cross}libgnat
 Summary: GNU Ada 95 runtime shared libraries
 Group: System Environment/Libraries
+%if %{isnative}
 Obsoletes: gnat libgnat3
+%endif
 Autoreq: true
 
-%description -n libgnat
+%description -n %{?cross}libgnat
 GNAT is a GNU Ada 95 front-end to GCC. This package includes shared libraries,
 which are required to run programs compiled with the GNAT.
 
@@ -514,6 +595,9 @@ which are required to run programs compi
 %patch104 -p0 -b .java-arm5
 %patch105 -p0 -b .java-arm6
 %patch106 -p1 -b .128250
+%if 0%{?uclibc}
+perl -pi -e "s/ld-linux.so.3/ld-uClibc.so.0/g" gcc/config/arm/linux-eabi.h
+%endif
 
 sed -i -e 's/4\.1\.3/4.1.2/' gcc/BASE-VER gcc/version.c
 sed -i -e 's/" (Red Hat[^)]*)"/" (Red Hat %{version}-%{gcc_release})"/' gcc/version.c
@@ -530,6 +614,7 @@ perl -pi -e 's/^check: check-recursive/i
 
 ./contrib/gcc_update --touch
 
+%if %{isnative}
 %ifarch ppc
 if [ -d libstdc++-v3/config/abi/powerpc64-linux-gnu ]; then
   mkdir -p libstdc++-v3/config/abi/powerpc64-linux-gnu/64
@@ -546,6 +631,7 @@ if [ -d libstdc++-v3/config/abi/sparc64-
   rm -rf libstdc++-v3/config/abi/sparc64-linux-gnu/32
 fi
 %endif
+%endif
 
 %build
 
@@ -590,6 +676,7 @@ cd ..
 CC=gcc
 OPT_FLAGS=`echo $RPM_OPT_FLAGS|sed -e 's/\(-Wp,\)\?-D_FORTIFY_SOURCE=[12]//g'`
 OPT_FLAGS=`echo $OPT_FLAGS|sed -e 's/-m64//g;s/-m32//g;s/-m31//g'`
+%if %{isnative}
 %ifarch sparc sparc64
 OPT_FLAGS=`echo $OPT_FLAGS|sed -e 's/-mcpu=ultrasparc/-mtune=ultrasparc/g;s/-mcpu=v[78]//g'`
 %endif
@@ -611,6 +698,7 @@ EOF
   CC=`pwd`/gcc64
 fi
 %endif
+%endif
 OPT_FLAGS=`echo "$OPT_FLAGS" | sed -e 's/[[:blank:]]\+/ /g'`
 case "$OPT_FLAGS" in
   *-fasynchronous-unwind-tables*)
@@ -618,6 +706,7 @@ case "$OPT_FLAGS" in
       ../gcc/Makefile.in
     ;;
 esac
+%if %{isnative}
 CC="$CC" CFLAGS="$OPT_FLAGS" CXXFLAGS="$OPT_FLAGS" XCFLAGS="$OPT_FLAGS" TCFLAGS="$OPT_FLAGS" \
 	GCJFLAGS="$OPT_FLAGS" \
 	../configure --prefix=%{_prefix} --mandir=%{_mandir} --infodir=%{_infodir} \
@@ -689,6 +778,26 @@ rm -rf testlogs-%{_target_platform}-%{ve
 
 # Make protoize
 make -C gcc CC="./xgcc -B ./ -O2" proto
+%else
+../configure --prefix=%{_prefix} --mandir=%{_mandir} \
+	--infodir=%{_infodir} --enable-shared --enable-threads=posix \
+	--enable-checking=release --with-system-zlib --enable-__cxa_atexit \
+	--disable-libunwind-exceptions \
+%if 0%{?uclibc}
+	--enable-languages=c \
+%else
+%if !%{build_fortran}
+	--enable-languages=c,c++ \
+%else
+	--enable-languages=c,c++,fortran \
+%endif
+%endif
+	--disable-libgcj --with-sysroot=yes \
+	--enable-version-specific-runtime-libs \
+	--target=%{gcc_target_platform}
+
+make %{?_smp_mflags}
+%endif
 
 # Make generated man pages even if Pod::Man is not new enough
 perl -pi -e 's/head3/head2/' ../contrib/texi2pod.pl
@@ -756,10 +865,10 @@ fi
 export PATH=`pwd`/java_hacks${PATH:+:$PATH}
 %endif
 
-TARGET_PLATFORM=%{gcc_target_platform}
-
+%if 0%{!?uclibc:1}
 # There are some MP bugs in libstdc++ Makefiles
 make -C %{gcc_target_platform}/libstdc++-v3
+%endif
 
 make prefix=$RPM_BUILD_ROOT%{_prefix} mandir=$RPM_BUILD_ROOT%{_mandir} \
   infodir=$RPM_BUILD_ROOT%{_infodir} install
@@ -774,14 +883,22 @@ FULLPATH=$RPM_BUILD_ROOT%{_prefix}/lib/g
 FULLEPATH=$RPM_BUILD_ROOT%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
 
 # fix some things
-ln -sf gcc $RPM_BUILD_ROOT%{_prefix}/bin/cc
+ln -sf %{?cross}gcc $RPM_BUILD_ROOT%{_prefix}/bin/%{?cross}cc
 mkdir -p $RPM_BUILD_ROOT/lib
-ln -sf ..%{_prefix}/bin/cpp $RPM_BUILD_ROOT/lib/cpp
-ln -sf gfortran $RPM_BUILD_ROOT%{_prefix}/bin/f95
+ln -sf ..%{_prefix}/bin/%{?cross}cpp $RPM_BUILD_ROOT/lib/%{?cross}cpp
+ln -sf %{?cross}gfortran $RPM_BUILD_ROOT%{_prefix}/bin/%{?cross}f95
 rm -f $RPM_BUILD_ROOT%{_infodir}/dir
 gzip -9 $RPM_BUILD_ROOT%{_infodir}/*.info*
-ln -sf gcc $RPM_BUILD_ROOT%{_prefix}/bin/gnatgcc
+ln -sf %{?cross}gcc $RPM_BUILD_ROOT%{_prefix}/bin/%{?cross}gnatgcc
 
+%if !%{isnative}
+mkdir -p $RPM_BUILD_ROOT/%{_prefix}/%{gcc_target_platform}/bin
+for i in cc c89 c99 gcc c++ g++ gfortran f95; do
+  ln -sf ../../bin/%{gcc_target_platform}-$i $RPM_BUILD_ROOT%{_prefix}/%{gcc_target_platform}/bin/$i
+done
+%endif
+
+%if %{isnative}
 cxxconfig="`find %{gcc_target_platform}/libstdc++-v3/include -name c++config.h`"
 for i in `find %{gcc_target_platform}/[36]*/libstdc++-v3/include -name c++config.h 2>/dev/null`; do
   if ! diff -up $cxxconfig $i; then
@@ -807,6 +924,7 @@ EOF
     break
   fi
 done
+%endif
 
 # Nuke bits/stdc++.h.gch dirs
 # 1) there is no bits/stdc++.h header installed, so when gch file can't be
@@ -819,6 +937,7 @@ done
 # shipping this for everybody is unnecessary.
 rm -rf $RPM_BUILD_ROOT%{_prefix}/include/c++/%{gcc_version}/%{gcc_target_platform}/bits/stdc++.h.gch
 
+%if %{isnative}
 %ifarch sparc sparc64
 ln -f $RPM_BUILD_ROOT%{_prefix}/bin/%{gcc_target_platform}-gcc \
   $RPM_BUILD_ROOT%{_prefix}/bin/sparc-%{_vendor}-%{_target_os}-gcc
@@ -827,13 +946,16 @@ ln -f $RPM_BUILD_ROOT%{_prefix}/bin/%{gc
 ln -f $RPM_BUILD_ROOT%{_prefix}/bin/%{gcc_target_platform}-gcc \
   $RPM_BUILD_ROOT%{_prefix}/bin/ppc-%{_vendor}-%{_target_os}-gcc
 %endif
+%endif
 
+%if %{isnative}
 %ifarch sparc ppc
 FULLLPATH=$FULLPATH/lib32
 %endif
 %ifarch sparc64 ppc64
 FULLLPATH=$FULLPATH/lib64
 %endif
+%endif
 if [ -n "$FULLLPATH" ]; then
   mkdir -p $FULLLPATH
 else
@@ -853,6 +975,7 @@ sed -i -e 's/lib: /&%%{static:%%eJava pr
   $FULLPATH/libgcj.spec
 %endif
 
+%if %{isnative}
 mkdir -p $RPM_BUILD_ROOT/%{_lib}
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgcc_s.so.1 $RPM_BUILD_ROOT/%{_lib}/libgcc_s-%{gcc_version}-%{DATE}.so.1
 chmod 755 $RPM_BUILD_ROOT/%{_lib}/libgcc_s-%{gcc_version}-%{DATE}.so.1
@@ -864,8 +987,11 @@ ln -sf /lib64/libgcc_s.so.1 $FULLPATH/64
 %ifarch %{multilib_64_archs}
 ln -sf /lib/libgcc_s.so.1 $FULLPATH/32/libgcc_s.so
 %endif
+%endif
 
+%if %{isnative}
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgomp.spec $FULLPATH/
+%endif
 mv -f $RPM_BUILD_ROOT%{_prefix}/include/omp.h $FULLPATH/include/
 
 %if %{build_ada}
@@ -874,12 +1000,14 @@ mv -f $FULLPATH/adalib/libgnat-*.so $RPM
 rm -f $FULLPATH/adalib/libgnarl.so* $FULLPATH/adalib/libgnat.so*
 %endif
 
+%if %{isnative}
 mkdir -p $RPM_BUILD_ROOT%{_prefix}/libexec/getconf
 if gcc/xgcc -B gcc/ -E -dD -xc /dev/null | grep __LONG_MAX__.*2147483647; then
   ln -sf POSIX_V6_ILP32_OFF32 $RPM_BUILD_ROOT%{_prefix}/libexec/getconf/default
 else
   ln -sf POSIX_V6_LP64_OFF64 $RPM_BUILD_ROOT%{_prefix}/libexec/getconf/default
 fi
+%endif
 
 %if %{build_java}
 if [ "%{_lib}" != "lib" ]; then
@@ -890,6 +1018,7 @@ fi
 %endif
 
 pushd $FULLPATH
+%if %{isnative}
 if [ "%{_lib}" = "lib" ]; then
 %if %{build_objc}
 ln -sf ../../../libobjc.so.1 libobjc.so
@@ -935,6 +1064,9 @@ ln -sf ../../../../../%{_lib}/libgnat-*.
 cd ..
 %endif
 fi
+%endif
+
+%if %{isnative}
 %if %{build_java}
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgcj_bc.so $FULLLPATH/
 %endif
@@ -947,8 +1079,10 @@ mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/
 %endif
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgomp.*a .
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libmudflap{,th}.*a $FULLLPATH/
+%endif
 mv -f $RPM_BUILD_ROOT%{_prefix}/include/mf-runtime.h include/
 
+%if %{isnative}
 %ifarch sparc ppc
 %if %{build_objc}
 ln -sf ../../../../../lib64/libobjc.so.1 64/libobjc.so
@@ -1023,22 +1157,30 @@ ln -sf ../../../%{multilib_32_arch}-%{_v
 %endif
 %endif
 %endif
+%endif
 
 # Strip debug info from Fortran/ObjC/Java static libraries
-strip -g `find . \( -name libgfortran.a -o -name libobjc.a -o -name libgomp.a \
+%{__strip} -g `find . \( -name libgfortran.a -o -name libobjc.a -o -name libgomp.a \
 		    -o -name libmudflap.a -o -name libmudflapth.a \
 		    -o -name libgcc.a -o -name libgcov.a \) -a -type f`
 popd
+%if %{isnative}
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgfortran.so.1.*
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgomp.so.1.*
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libmudflap{,th}.so.0.*
 %if %{build_objc}
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libobjc.so.1.*
 %endif
+%endif
 
 %if %{build_ada}
+%if %{isnative}
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgnarl*so*
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgnat*so*
+%else
+chmod 755 $FULLLPATH/libgnarl*so*
+chmod 755 $FULLLPATH/libgnat*so*
+%endif
 %endif
 
 for h in `find $FULLPATH/include -name \*.h`; do
@@ -1049,7 +1191,7 @@ for h in `find $FULLPATH/include -name \
   fi
 done
 
-cat > $RPM_BUILD_ROOT%{_prefix}/bin/c89 <<"EOF"
+cat > $RPM_BUILD_ROOT%{_prefix}/bin/%{?cross}c89 <<"EOF"
 #!/bin/sh
 fl="-std=c89"
 for opt; do
@@ -1061,7 +1203,7 @@ for opt; do
 done
 exec gcc $fl ${1+"$@"}
 EOF
-cat > $RPM_BUILD_ROOT%{_prefix}/bin/c99 <<"EOF"
+cat > $RPM_BUILD_ROOT%{_prefix}/bin/%{?cross}c99 <<"EOF"
 #!/bin/sh
 fl="-std=c99"
 for opt; do
@@ -1073,23 +1215,30 @@ for opt; do
 done
 exec gcc $fl ${1+"$@"}
 EOF
-chmod 755 $RPM_BUILD_ROOT%{_prefix}/bin/c?9
+chmod 755 $RPM_BUILD_ROOT%{_prefix}/bin/%{?cross}c?9
 
+%if %{isnative}
 mkdir -p $RPM_BUILD_ROOT%{_prefix}/sbin
 gcc -static -Os %{SOURCE1} -o $RPM_BUILD_ROOT%{_prefix}/sbin/libgcc_post_upgrade
 strip $RPM_BUILD_ROOT%{_prefix}/sbin/libgcc_post_upgrade
+%endif
 
 cd ..
+%if %{isnative}
 %find_lang %{name}
 %find_lang cpplib
+%endif
 
 # Remove binaries we will not be including, so that they don't end up in
 # gcc-debuginfo
 rm -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/{libffi*,libiberty.a}
+rm -f $RPM_BUILD_ROOT%{_prefix}/%{gcc_target_platform}/%{_lib}/{libffi*,libiberty.a}
 rm -f $FULLEPATH/install-tools/{mkheaders,fixincl}
 rm -f $RPM_BUILD_ROOT%{_prefix}/lib/{32,64}/libiberty.a
 rm -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libssp*
+rm -f $FULLPATH/libssp*
 
+%if %{isnative}
 %ifarch %{multilib_64_archs}
 # Remove libraries for the other arch on multilib arches
 rm -f $RPM_BUILD_ROOT%{_prefix}/lib/lib*.so*
@@ -1100,6 +1249,7 @@ rm -f $RPM_BUILD_ROOT%{_prefix}/lib64/li
 rm -f $RPM_BUILD_ROOT%{_prefix}/lib64/lib*.a
 %endif
 %endif
+%endif
 
 %if %{build_java}
 mkdir -p $RPM_BUILD_ROOT%{_prefix}/share/java/gcj-endorsed \
@@ -1115,8 +1265,9 @@ echo '.so man1/protoize.1' > $RPM_BUILD_
 chmod 644 $RPM_BUILD_ROOT%{_mandir}/man1/unprotoize.1
 
 %clean
-rm -rf $RPM_BUILD_ROOT
+#rm -rf $RPM_BUILD_ROOT
 
+%if %{isnative}
 %post
 /sbin/install-info \
   --info-dir=%{_infodir} %{_infodir}/gcc.info.gz || :
@@ -1127,11 +1278,11 @@ if [ $1 = 0 ]; then
     --info-dir=%{_infodir} %{_infodir}/gcc.info.gz || :
 fi
 
-%post -n cpp
+%post -n %{?cross}cpp
 /sbin/install-info \
   --info-dir=%{_infodir} %{_infodir}/cpp.info.gz || :
 
-%preun -n cpp
+%preun -n %{?cross}cpp
 if [ $1 = 0 ]; then
   /sbin/install-info --delete \
     --info-dir=%{_infodir} %{_infodir}/cpp.info.gz || :
@@ -1178,52 +1329,58 @@ fi
 # Because glibc Prereq's libgcc and /sbin/ldconfig
 # comes from glibc, it might not exist yet when
 # libgcc is installed
-%post -n libgcc -p %{_prefix}/sbin/libgcc_post_upgrade
+%post -n %{?cross}libgcc -p %{_prefix}/sbin/libgcc_post_upgrade
 
-%post -n libstdc++ -p /sbin/ldconfig
+%post -n %{?cross}libstdc++ -p /sbin/ldconfig
 
-%postun -n libstdc++ -p /sbin/ldconfig
+%postun -n %{?cross}libstdc++ -p /sbin/ldconfig
 
-%post -n libobjc -p /sbin/ldconfig
+%post -n %{?cross}libobjc -p /sbin/ldconfig
 
-%postun -n libobjc -p /sbin/ldconfig
+%postun -n %{?cross}libobjc -p /sbin/ldconfig
 
-%post -n libgcj
+%post -n %{?cross}libgcj
 /sbin/ldconfig
 /sbin/install-info \
   --info-dir=%{_infodir} %{_infodir}/fastjar.info.gz || :
 
-%preun -n libgcj
+%preun -n %{?cross}libgcj
 if [ $1 = 0 ]; then
   /sbin/install-info --delete \
     --info-dir=%{_infodir} %{_infodir}/fastjar.info.gz || :
 fi
 
-%postun -n libgcj -p /sbin/ldconfig
+%postun -n %{?cross}libgcj -p /sbin/ldconfig
 
-%post -n libgfortran -p /sbin/ldconfig
+%post -n %{?cross}libgfortran -p /sbin/ldconfig
 
-%postun -n libgfortran -p /sbin/ldconfig
+%postun -n %{?cross}libgfortran -p /sbin/ldconfig
 
-%post -n libgnat -p /sbin/ldconfig
+%post -n %{?cross}libgnat -p /sbin/ldconfig
 
-%postun -n libgnat -p /sbin/ldconfig
+%postun -n %{?cross}libgnat -p /sbin/ldconfig
 
-%post -n libgomp -p /sbin/ldconfig
+%post -n %{?cross}libgomp -p /sbin/ldconfig
 
-%postun -n libgomp -p /sbin/ldconfig
+%postun -n %{?cross}libgomp -p /sbin/ldconfig
 
-%post -n libmudflap -p /sbin/ldconfig
+%post -n %{?cross}libmudflap -p /sbin/ldconfig
 
-%postun -n libmudflap -p /sbin/ldconfig
+%postun -n %{?cross}libmudflap -p /sbin/ldconfig
+%endif
 
+%if %{isnative}
 %files -f %{name}.lang
+%else
+%files
+%endif
 %defattr(-,root,root)
-%{_prefix}/bin/cc
-%{_prefix}/bin/c89
-%{_prefix}/bin/c99
-%{_prefix}/bin/gcc
-%{_prefix}/bin/gcov
+%{_prefix}/bin/%{?cross}cc
+%{_prefix}/bin/%{?cross}c89
+%{_prefix}/bin/%{?cross}c99
+%{_prefix}/bin/%{?cross}gcc
+%{_prefix}/bin/%{?cross}gcov
+%if %{isnative}
 %{_prefix}/bin/protoize
 %{_prefix}/bin/unprotoize
 %ifarch sparc ppc
@@ -1236,11 +1393,21 @@ fi
 %{_prefix}/bin/ppc-%{_vendor}-%{_target_os}-gcc
 %endif
 %{_prefix}/bin/%{gcc_target_platform}-gcc
-%{_mandir}/man1/gcc.1*
-%{_mandir}/man1/gcov.1*
+%else
+%dir %{_prefix}/%{gcc_target_platform}
+%dir %{_prefix}/%{gcc_target_platform}/bin
+%{_prefix}/%{gcc_target_platform}/bin/cc
+%{_prefix}/%{gcc_target_platform}/bin/c89
+%{_prefix}/%{gcc_target_platform}/bin/c99
+%{_prefix}/%{gcc_target_platform}/bin/gcc
+%endif
+%{_mandir}/man1/%{?cross}gcc.1*
+%{_mandir}/man1/%{?cross}gcov.1*
+%if %{isnative}
 %{_mandir}/man1/protoize.1*
 %{_mandir}/man1/unprotoize.1*
 %{_infodir}/gcc*
+%endif
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1248,7 +1415,9 @@ fi
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include
+%if %{isnative}
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/SYSCALLS.c.X
+%endif
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/stddef.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/stdarg.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/varargs.h
@@ -1259,6 +1428,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/syslimits.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/unwind.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/omp.h
+%if %{isnative}
 %ifarch %{ix86} x86_64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/mmintrin.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/xmmintrin.h
@@ -1277,6 +1447,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/altivec.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/spe.h
 %endif
+%endif
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/README
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/collect2
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/crt*.o
@@ -1287,6 +1458,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgomp.spec
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgomp.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgomp.so
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/crt*.o
@@ -1323,32 +1495,50 @@ fi
 %endif
 %dir %{_prefix}/libexec/getconf
 %{_prefix}/libexec/getconf/default
+%endif
 %doc gcc/README* rpm.doc/changelogs/gcc/ChangeLog* gcc/COPYING*
 
+%if %{isnative}
 %files -n cpp -f cpplib.lang
+%else
+%files -n %{?cross}cpp
+%endif
 %defattr(-,root,root)
-/lib/cpp
-%{_prefix}/bin/cpp
-%{_mandir}/man1/cpp.1*
+/lib/%{?cross}cpp
+%if %{isnative}
 %{_infodir}/cpp*
+%endif
+%{_prefix}/bin/%{?cross}cpp
+%{_mandir}/man1/%{?cross}cpp.1*
 %dir %{_prefix}/libexec/gcc
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cc1
 
-%files -n libgcc
+%files -n %{?cross}libgcc
 %defattr(-,root,root)
+%if %{isnative}
 /%{_lib}/libgcc_s-%{gcc_version}-%{DATE}.so.1
 /%{_lib}/libgcc_s.so.1
 %{_prefix}/sbin/libgcc_post_upgrade
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcc_s.so.1
+%endif
 %doc gcc/COPYING.LIB
 
+%if 0%{!?uclibc:1}
 %files c++
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/bin/%{gcc_target_platform}-*++
-%{_prefix}/bin/g++
-%{_prefix}/bin/c++
-%{_mandir}/man1/g++.1*
+%else
+%dir %{_prefix}/%{gcc_target_platform}
+%dir %{_prefix}/%{gcc_target_platform}/bin
+%{_prefix}/%{gcc_target_platform}/bin/*++
+%endif
+%{_prefix}/bin/%{?cross}g++
+%{_prefix}/bin/%{?cross}c++
+%{_mandir}/man1/%{?cross}g++.1*
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1356,6 +1546,7 @@ fi
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cc1plus
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libstdc++.so
@@ -1375,22 +1566,39 @@ fi
 %ifarch sparc sparc64 ppc ppc64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.a
 %endif
+%endif
 %doc rpm.doc/changelogs/gcc/cp/ChangeLog*
+%endif
 
-%files -n libstdc++
+%if 0%{!?uclibc:1}
+%files -n %{?cross}libstdc++
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/%{_lib}/libstdc++.so.6*
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so.6*
+%endif
+%endif
 
-%files -n libstdc++-devel
+%if 0%{!?uclibc:1}
+%files -n %{?cross}libstdc++-devel
 %defattr(-,root,root)
+%if %{isnative}
 %dir %{_prefix}/include/c++
 %dir %{_prefix}/include/c++/%{gcc_version}
 %{_prefix}/include/c++/%{gcc_version}/[^gjos]*
 %{_prefix}/include/c++/%{gcc_version}/os*
 %{_prefix}/include/c++/%{gcc_version}/s[^u]*
+%else
+%dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/c++
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/c++/[^gjos]*
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/c++/os*
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/c++/s[^u]*
+%endif
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32/libstdc++.a
@@ -1406,7 +1614,13 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libsupc++.a
 %endif
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.a
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libsupc++.a
+%endif
 %doc rpm.doc/changelogs/libstdc++-v3/ChangeLog* libstdc++-v3/README* libstdc++-v3/docs/html/
+%endif
 
 %if %{build_objc}
 %files objc
@@ -1422,6 +1636,7 @@ fi
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cc1obj
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libobjc.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libobjc.so
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libobjc.a
@@ -1432,6 +1647,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libobjc.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libobjc.so
 %endif
+%endif
 %doc rpm.doc/objc/*
 %doc libobjc/THREADS* rpm.doc/changelogs/libobjc/ChangeLog*
 
@@ -1442,17 +1658,25 @@ fi
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/cc1objplus
 
-%files -n libobjc
+%files -n %{?cross}libobjc
 %defattr(-,root,root)
 %{_prefix}/%{_lib}/libobjc.so.1*
 %endif
 
+%if %{build_fortran}
 %files gfortran
 %defattr(-,root,root)
-%{_prefix}/bin/gfortran
-%{_prefix}/bin/f95
-%{_mandir}/man1/gfortran.1*
+%{_prefix}/bin/%{?cross}gfortran
+%{_prefix}/bin/%{?cross}f95
+%{_mandir}/man1/%{?cross}gfortran.1*
+%if %{isnative}
 %{_infodir}/gfortran*
+%else
+%dir %{_prefix}/%{gcc_target_platform}
+%dir %{_prefix}/%{gcc_target_platform}/bin
+%{_prefix}/%{gcc_target_platform}/bin/gfortran
+%{_prefix}/%{gcc_target_platform}/bin/f95
+%endif
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1468,6 +1692,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgfortranbegin.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgfortran.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgfortran.so
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libgfortranbegin.a
@@ -1480,11 +1705,19 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgfortran.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgfortran.so
 %endif
+%endif
 %doc rpm.doc/gfortran/*
+%endif
 
-%files -n libgfortran
+%if %{build_fortran}
+%files -n %{?cross}libgfortran
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/%{_lib}/libgfortran.so.1*
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgfortran.so.1*
+%endif
+%endif
 
 %if %{build_java}
 %files java
@@ -1513,6 +1746,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcj_bc.so
 %endif
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgij.so
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libgcj.so
@@ -1527,9 +1761,10 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgcj_bc.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgij.so
 %endif
+%endif
 %doc rpm.doc/changelogs/gcc/java/ChangeLog*
 
-%files -n libgcj
+%files -n %{?cross}libgcj
 %defattr(-,root,root)
 %{_prefix}/bin/jv-convert
 %{_prefix}/bin/gij
@@ -1588,7 +1823,7 @@ fi
 %doc rpm.doc/README.libgcjwebplugin.so
 %endif
 
-%files -n libgcj-devel
+%files -n %{?cross}libgcj-devel
 %defattr(-,root,root)
 %{_prefix}/bin/addr2name.awk
 %dir %{_prefix}/lib/gcc
@@ -1622,7 +1857,7 @@ fi
 %doc rpm.doc/boehm-gc/* rpm.doc/fastjar/* rpm.doc/libffi/*
 %doc rpm.doc/libjava/*
 
-%files -n libgcj-src
+%files -n %{?cross}libgcj-src
 %defattr(-,root,root)
 %dir %{_prefix}/share/java
 %{_prefix}/share/java/src*.zip
@@ -1632,9 +1867,11 @@ fi
 %if %{build_ada}
 %files gnat
 %defattr(-,root,root)
-%{_prefix}/bin/gnat*
+%{_prefix}/bin/%{?cross}gnat*
+%if %{isnative}
 %{_prefix}/bin/gpr*
 %{_infodir}/gnat*
+%endif
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1646,29 +1883,44 @@ fi
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/gnat1
 %doc rpm.doc/changelogs/gcc/ada/ChangeLog*
 
-%files -n libgnat
+%files -n %{?cross}libgnat
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/%{_lib}/libgnat-*.so
 %{_prefix}/%{_lib}/libgnarl-*.so
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgnat-*.so
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgnarl-*.so
+%endif
 %endif
 
-%files -n libgomp
+%files -n %{?cross}libgomp
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/%{_lib}/libgomp.so.1*
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgomp.so.1*
+%endif
 %doc rpm.doc/changelogs/libgomp/ChangeLog*
 
-%files -n libmudflap
+%files -n %{?cross}libmudflap
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/%{_lib}/libmudflap.so.0*
 %{_prefix}/%{_lib}/libmudflapth.so.0*
+%else
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.so.0*
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.so.0*
+%endif
 
-%files -n libmudflap-devel
+%files -n %{?cross}libmudflap-devel
 %defattr(-,root,root)
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/mf-runtime.h
+%if %{isnative}
 %ifarch sparc ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32/libmudflap.a
@@ -1685,6 +1937,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.so
 %endif
+%endif
 %doc rpm.doc/changelogs/libmudflap/ChangeLog*
 
 %changelog
Index: SPECS/gdb.spec
===================================================================
--- SPECS.orig/gdb.spec
+++ SPECS/gdb.spec
@@ -1,9 +1,19 @@
+%if "%{?cross_target}" == ""
+%define gdb_target %{_target_platform}
+%define isnative 1
+%else
+%define gdb_target %{cross_target}
+%define cross %{gdb_target}-
+%define isnative 0
+%define _unpackaged_files_terminate_build 0
+%endif
+
 # Define this if you want to skip the strip step and preserve debug info.
 # Useful for testing.
 #define __debug_install_post : > %{_builddir}/%{?buildsubdir}/debugfiles.list
 
 Summary: A GNU source-level debugger for C, C++, Java and other languages
-Name: gdb
+Name: %{?cross}gdb
 
 # Set version to contents of gdb/version.in.
 # NOTE: the FSF gdb versions are numbered N.M for official releases, like 6.3 
@@ -11,7 +21,7 @@ Name: gdb
 Version: 6.6
 
 # The release always contains a leading reserved number, start it at 1.
-Release: 35%{?dist}
+Release: 35%{?dist}.cross4
 
 License: GPL
 Group: Development/Debuggers
@@ -26,7 +36,7 @@ URL: http://gnu.org/software/gdb/
 # Make sure we get rid of the old package gdb64, now that we have unified
 # support for 32-64 bits in one single 64-bit gdb.
 %ifarch ppc64
-Obsoletes: gdb64 < 5.3.91
+Obsoletes: %{?cross}gdb64 < 5.3.91
 %endif
 
 # GDB patches have the format gdb-<version>-bz<red-hat-bz-#>-<desc>.patch;
@@ -404,8 +414,10 @@ Requires: libunwind >= 0.99-0.1.frysk200
 BuildRequires: prelink
 %endif
  
+%if %{isnative}
 Requires(post): /sbin/install-info
 Requires(preun): /sbin/install-info
+%endif
 
 %description
 GDB, the GNU debugger, allows you to debug programs written in C, C++,
@@ -600,7 +612,12 @@ enable_build_warnings="$enable_build_war
 %else
 	--without-libunwind				\
 %endif
+%if %{isnative}
 	%{_target_platform}
+%else
+	--build=%{_target_platform} --host=%{_target_platform} --target=%{gdb_target} \
+	--with-sysroot=yes
+%endif
 
 make %{?_smp_mflags}
 make %{?_smp_mflags} info
@@ -608,6 +625,7 @@ make %{?_smp_mflags} info
 # Copy the <sourcetree>/gdb/NEWS file to the directory above it.
 cp $RPM_BUILD_DIR/%{gdb_src}/gdb/NEWS $RPM_BUILD_DIR/%{gdb_src}
 
+%if %{isnative}
 %check
 # Initially we're in the %{gdb_src} directory.
 cd %{gdb_build}
@@ -639,6 +657,7 @@ uuencode gdb-%{_target_platform}.tar.bz2
 cd ../..
 echo ====================TESTING END=====================
 %endif
+%endif
 
 %install
 # Initially we're in the %{gdb_src} directory.
@@ -671,6 +690,7 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%if %{isnative}
 %post
 # This step is part of the installation of the RPM. Not to be confused
 # with the 'make install ' of the build (rpmbuild) process.
@@ -679,7 +699,9 @@ rm -rf $RPM_BUILD_ROOT
 /sbin/install-info --info-dir=%{_infodir} %{_infodir}/gdb.info.gz || :
 /sbin/install-info --info-dir=%{_infodir} %{_infodir}/gdbint.info.gz || :
 /sbin/install-info --info-dir=%{_infodir} %{_infodir}/stabs.info.gz || :
+%endif
 
+%if %{isnative}
 %preun
 if [ $1 = 0 ]; then
 	/sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/annotate.info.gz || :
@@ -687,16 +709,19 @@ if [ $1 = 0 ]; then
 	/sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/gdbint.info.gz || :
 	/sbin/install-info --delete --info-dir=%{_infodir} %{_infodir}/stabs.info.gz || :
 fi
+%endif
 
 %files
 %defattr(-,root,root)
 %doc COPYING COPYING.LIB README NEWS
-/usr/bin/*
+/usr/bin/%{?cross}*
 %{_mandir}/*/*
+%if %{isnative}
 %{_infodir}/annotate.info*
 %{_infodir}/gdb.info*
 %{_infodir}/gdbint.info*
 %{_infodir}/stabs.info*
+%endif
 
 # don't include the files in include, they are part of binutils
 
