--- gcc.spec.orig	2010-11-16 15:58:14.511569004 +0000
+++ gcc.spec	2010-11-17 11:40:12.184013159 +0000
@@ -1,3 +1,22 @@
+%if "%{?cross_target}" == ""
+%define gcc_target %{_target_platform}
+%define target_arch %{_arch}
+%define isnative 1
+%else
+%define gcc_target %{cross_target}
+# need it for libmudflap etc which are target arch
+%undefine _missing_build_ids_terminate_build
+%define target_arch %{expand:%%(echo "%{cross_target}" | sed 's/-.*//')}
+%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
+
 %global DATE 20101112
 %global SVNREV 166681
 %global gcc_version 4.5.1
@@ -6,6 +25,22 @@
 %global gcc_release 5
 %global _unpackaged_files_terminate_build 0
 %global multilib_64_archs sparc64 ppc64 s390x x86_64
+
+
+%if !%{isnative}
+
+%global build_ada 0
+%global build_fortran 0
+%global build_java 0
+%global bootstrap_java 0
+%global build_objc 0
+%global run_tests 0
+%global build_cloog 0
+%global build_libstdcxx_docs 0
+%global build_java_tar 0
+
+%else # isnative
+
 %ifarch %{ix86} x86_64 ia64 ppc ppc64 alpha
 %global build_ada 1
 %else
@@ -32,10 +67,13 @@
 %ifarch x86_64
 %global multilib_32_arch i686
 %endif
+
+%endif # isnative
+
 Summary: Various compilers (C, C++, Objective-C, Java, ...)
-Name: gcc
+Name: %{?cross}gcc
 Version: %{gcc_version}
-Release: %{gcc_release}%{?dist}
+Release: %{gcc_release}.cross12
 # libgcc, libgfortran, libmudflap, libgomp, libstdc++ and crtstuff have
 # GCC Runtime Exception.
 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions
@@ -64,6 +102,7 @@
 # While gcc doesn't include statically linked binaries, during testing
 # -static is used several times.
 BuildRequires: glibc-static
+BuildRequires: %{?cross}binutils >= 2.17.50.0.17-3
 BuildRequires: zlib-devel, gettext, dejagnu, bison, flex, texinfo, sharutils
 # For VTA guality testing
 BuildRequires: gdb
@@ -78,13 +117,22 @@
 # 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} >= 0.9.29-3
+%else
+BuildRequires: glibc-devel%{?crosspost} >= 2.4.90-13
+%endif
 BuildRequires: elfutils-devel >= 0.147
 BuildRequires: elfutils-libelf-devel >= 0.147
+
+
+%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
+%endif
+
 %ifarch %{multilib_64_archs} sparcv9 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
@@ -93,17 +141,23 @@
 # Ada requires Ada to build
 BuildRequires: gcc-gnat >= 3.1, libgnat >= 3.1
 %endif
+
+%if %{isnative}
 %ifarch ia64
 BuildRequires: libunwind >= 0.98
 %endif
+%endif
+
 %if %{build_cloog}
 BuildRequires: ppl >= 0.10, ppl-devel >= 0.10, cloog-ppl >= 0.15, cloog-ppl-devel >= 0.15
 %endif
+
 %if %{build_libstdcxx_docs}
 BuildRequires: doxygen
 BuildRequires: graphviz
 %endif
-Requires: cpp = %{version}-%{release}
+
+Requires: %{?cross}cpp = %{version}-%{release}
 # Need .eh_frame ld optimizations
 # Need proper visibility support
 # Need -pie support
@@ -117,19 +171,29 @@
 # Need binutils that support %gnu_unique_object
 # Need binutils that support .cfi_sections
 # Need binutils that support --no-add-needed
-Requires: binutils >= 2.20.51.0.2-12
+Requires: %{?cross}binutils >= 2.20.51.0.2-12
+
 # 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
 %endif
-Requires: libgcc >= %{version}-%{release}
-Requires: libgomp = %{version}-%{release}
+%endif
+
+Requires: %{?cross}libgcc >= %{version}-%{release}
+Requires: %{?cross}libgomp = %{version}-%{release}
 %if !%{build_ada}
-Obsoletes: gcc-gnat < %{version}-%{release}
-Obsoletes: libgnat < %{version}-%{release}
+Obsoletes: %{?cross}gcc-gnat < %{version}-%{release}
+Obsoletes: %{?cross}libgnat < %{version}-%{release}
 %endif
 %if %{build_cloog}
 Requires: cloog-ppl >= 0.15
@@ -164,6 +228,8 @@
 %ifnarch %{arm}
 %global _gnu %{nil}
 %endif
+
+%if "%{?gcc_target}" == ""
 %ifarch sparcv9
 %global gcc_target_platform sparc64-%{_vendor}-%{_target_os}
 %endif
@@ -173,26 +239,36 @@
 %ifnarch sparcv9 ppc
 %global gcc_target_platform %{_target_platform}
 %endif
+%else
+%global gcc_target_platform %{cross_target}
+%endif
+
 
 %description
 The gcc package contains the GNU Compiler Collection version 4.5.
 You'll need this package in order to compile C code.
 
-%package -n libgcc
+%package -n %{?cross}libgcc
 Summary: GCC version 4.5 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++
@@ -200,34 +276,43 @@
 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
 Requires: glibc >= 2.10.90-7
 
-%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++%{?_isa} = %{version}-%{release}
+Requires: %{?cross}libstdc++%{?_isa} = %{version}-%{release}
 Autoreq: true
+%if %{isnative}
+Requires: %{_prefix}/%{_lib}/libstdc++.so.6
+Obsoletes: libstdc++3-devel
+Obsoletes: libstdc++34-devel
+%endif
 
-%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.
 
-%package -n libstdc++-static
+%package -n %{?cross}libstdc++-static
 Summary: Static libraries for the GNU standard C++ library
 Group: Development/Libraries
-Requires: libstdc++-devel = %{version}-%{release}
+Requires: %{?cross}libstdc++-devel = %{version}-%{release}
 Autoreq: true
 
-%description -n libstdc++-static
+%description -n %{?cross}libstdc++-static
 Static libraries for the GNU standard C++ library. 
 
 %package -n libstdc++-docs
@@ -242,8 +327,8 @@
 %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}
 Autoreq: true
 
 %description objc
@@ -251,84 +336,97 @@
 Mainly used on systems running NeXTSTEP, Objective-C is an
 object-oriented derivative of the C language.
 
-%package objc++
+%package %{?cross}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}, gcc-objc = %{version}-%{release}
 Autoreq: true
 
-%description objc++
+%description %{?cross}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
+%if %{build_fortran}
+%package %{?cross}gfortran
 Summary: Fortran support
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}
-Requires: libgfortran = %{version}-%{release}
+Requires: %{?cross}gcc = %{version}-%{release}
+Requires: %{?cross}libgfortran = %{version}-%{release}
 BuildRequires: gmp-devel >= 4.1.2-8, mpfr-devel >= 2.2.1, libmpc-devel >= 0.8.1
 Requires(post): /sbin/install-info
 Requires(preun): /sbin/install-info
+%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
+%description %{?cross}gfortran
 The gcc-gfortran package provides support for compiling Fortran
 programs with the GNU Compiler Collection.
 
-%package -n libgfortran
+%package -n %{?cross}libgfortran
 Summary: Fortran runtime
 Group: System Environment/Libraries
 Autoreq: true
+%if %{isnative}
+Obsoletes: libf2c
+%endif
 
-%description -n libgfortran
+%description -n %{?cross}libgfortran
 This package contains Fortran shared library which is needed to run
 Fortran dynamically linked programs.
+%endif # build_fortran
+
 
-%package -n libgomp
+%package -n %{?cross}libgomp
 Summary: GCC OpenMP v3.0 shared support library
 Group: System Environment/Libraries
 Requires(post): /sbin/install-info
 Requires(preun): /sbin/install-info
 
-%description -n libgomp
+%description -n %{?cross}libgomp
 This package contains GCC shared support library which is needed
 for OpenMP v3.0 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: %{?cross}libmudflap = %{version}-%{release}
 Requires: gcc = %{version}-%{release}
 
-%description -n libmudflap-devel
+%description -n %{?cross}libmudflap-devel
 This package contains headers for building mudflap-instrumented programs.
 
 To instrument a non-threaded program, add -fmudflap
 option to GCC and when linking add -lmudflap, for threaded programs
 also add -fmudflapth and -lmudflapth.
 
-%package -n libmudflap-static
+%package -n %{?cross}libmudflap-static
 Summary: Static libraries for mudflap support
 Group: Development/Libraries
-Requires: libmudflap-devel = %{version}-%{release}
+Requires: %{?cross}libmudflap-devel = %{version}-%{release}
 
-%description -n libmudflap-static
+%description -n %{?cross}libmudflap-static
 This package contains static libraries for building mudflap-instrumented
 programs.
 
@@ -347,39 +445,41 @@
 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}
 Requires(post): /sbin/install-info
 Requires(preun): /sbin/install-info
+%endif
 Requires: zip >= 2.1
 Requires: gtk2 >= 2.4.0
 Requires: glib2 >= 2.4.0
 Requires: libart_lgpl >= 2.1.0
 %if %{build_java}
-BuildRequires: gtk2-devel >= 2.4.0
-BuildRequires: glib2-devel >= 2.4.0
-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: libart_lgpl-devel%{?crosspost} >= 2.1.0
+BuildRequires: alsa-lib-devel%{?crosspost}
+BuildRequires: libXtst-devel%{?crosspost}
+BuildRequires: libXt-devel%{?crosspost}
 %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%{?_isa} = %{version}-%{release}
+Requires: %{?cross}libgcj%{?_isa} = %{version}-%{release}
 Requires: zlib-devel%{?_isa}
 Requires: /bin/awk
 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).
 
@@ -392,14 +492,16 @@
 %description -n 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}
 Requires(post): /sbin/install-info
 Requires(preun): /sbin/install-info
+%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
@@ -424,41 +526,44 @@
 %package gnat
 Summary: Ada 95 support for GCC
 Group: Development/Languages
-Requires: gcc = %{version}-%{release}
-Requires: libgnat = %{version}-%{release}, libgnat-devel = %{version}-%{release}
+Requires: %{cross}gcc = %{version}-%{release}
+Requires: %{cross}libgnat = %{version}-%{release}
+Requires: %{cross}libgnat-devel = %{version}-%{release}
+%if %{isnative}
 Requires(post): /sbin/install-info
 Requires(preun): /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
 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.
 
-%package -n libgnat-devel
+%package -n %{cross}libgnat-devel
 Summary: GNU Ada 95 libraries
 Group: System Environment/Libraries
 Autoreq: true
 
-%description -n libgnat-devel
+%description -n %{cross}libgnat-devel
 GNAT is a GNU Ada 95 front-end to GCC. This package includes libraries,
 which are required to compile with the GNAT.
 
-%package -n libgnat-static
+%package -n %{cross}libgnat-static
 Summary: GNU Ada 95 static libraries
 Group: System Environment/Libraries
-Requires: libgnat-devel = %{version}-%{release}
+Requires: %{cross}libgnat-devel = %{version}-%{release}
 Autoreq: true
 
-%description -n libgnat-static
+%description -n %{cross}libgnat-static
 GNAT is a GNU Ada 95 front-end to GCC. This package includes static libraries.
 
 %prep
@@ -481,6 +586,13 @@
 %patch15 -p0 -b .libstdc++-docs~
 %endif
 %patch17 -p0 -b .no-add-needed~
+%if 0%{?uclibc}
+%patch200 -p1 -b .uclibc-locale
+# seems 302-c990snprintf might do this one already
+#%patch201 -p1 -b .snprintf
+%patch202 -p1 -b .uclibc-mrvl
+perl -pi -e "s/ld-linux.so.3/ld-uClibc.so.0/g" gcc/config/arm/linux-eabi.h
+%endif
 
 # This testcase doesn't compile.
 rm libjava/testsuite/libjava.lang/PR35020*
@@ -521,6 +633,8 @@
 
 LC_ALL=C sed -i -e 's/\xa0/ /' gcc/doc/options.texi
 
+%if %{isnative}
+
 %ifarch ppc
 if [ -d libstdc++-v3/config/abi/post/powerpc64-linux-gnu ]; then
   mkdir -p libstdc++-v3/config/abi/post/powerpc64-linux-gnu/64
@@ -538,8 +652,17 @@
 fi
 %endif
 
+%endif # isnative
+
 %build
 
+# from original 4.1 cross, probably eliminated in 4.5
+#if [ ! -f /usr/lib/locale/de_DE/LC_CTYPE ]; then
+#  mkdir locale
+#  localedef -f ISO-8859-1 -i de_DE locale/de_DE
+#  export LOCPATH=`pwd`/locale:/usr/lib/locale
+#fi
+
 %if %{build_java}
 export GCJ_PROPERTIES=jdt.compiler.useSingleThread=true
 # gjar isn't usable, so even when GCC source tree no longer includes
@@ -588,6 +711,9 @@
 CC=gcc
 OPT_FLAGS=`echo %{optflags}|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
 OPT_FLAGS=`echo $OPT_FLAGS|sed -e 's/-mcpu=ultrasparc/-mtune=ultrasparc/g;s/-mcpu=v[78]//g'`
 %endif
@@ -612,6 +738,9 @@
   CC=`pwd`/gcc64
 fi
 %endif
+
+%endif # isnative
+
 OPT_FLAGS=`echo "$OPT_FLAGS" | sed -e 's/[[:blank:]]\+/ /g'`
 case "$OPT_FLAGS" in
   *-fasynchronous-unwind-tables*)
@@ -619,6 +748,9 @@
       ../gcc/Makefile.in
     ;;
 esac
+
+%if %{isnative}
+
 CC="$CC" CFLAGS="$OPT_FLAGS" CXXFLAGS="`echo $OPT_FLAGS | sed 's/ -Wall / /g'`" \
 	XCFLAGS="$OPT_FLAGS" TCFLAGS="$OPT_FLAGS" GCJFLAGS="$OPT_FLAGS" \
 	../configure --prefix=%{_prefix} --mandir=%{_mandir} --infodir=%{_infodir} \
@@ -692,6 +824,28 @@
 #GCJFLAGS="$OPT_FLAGS" make %{?_smp_mflags} BOOT_CFLAGS="$OPT_FLAGS" bootstrap
 GCJFLAGS="$OPT_FLAGS" make %{?_smp_mflags} BOOT_CFLAGS="$OPT_FLAGS" profiledbootstrap
 
+%else # !native
+
+../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,c++ --enable-clocale=uclibc \
+%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 # !native
+
 # Make generated man pages even if Pod::Man is not new enough
 perl -pi -e 's/head3/head2/' ../contrib/texi2pod.pl
 for i in ../gcc/doc/*.texi; do
@@ -718,12 +872,14 @@
 	cp -p $i rpm.doc/changelogs/$i
 done
 
+%if %{build_fortran}
 (cd gcc/fortran; for i in ChangeLog*; do
 	cp -p $i ../../rpm.doc/gfortran/$i
 done)
 (cd libgfortran; for i in ChangeLog*; do
 	cp -p $i ../rpm.doc/gfortran/$i.libgfortran
 done)
+%endif
 (cd gcc/objc; for i in README*; do
 	cp -p $i ../../rpm.doc/objc/$i.objc
 done)
@@ -785,13 +941,32 @@
 FULLEPATH=%{buildroot}%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
 
 # fix some things
-ln -sf gcc %{buildroot}%{_prefix}/bin/cc
+ln -sf %{?cross}gcc %{buildroot}%{_prefix}/bin/%{?cross}cc
 mkdir -p %{buildroot}/lib
-ln -sf ..%{_prefix}/bin/cpp %{buildroot}/lib/cpp
-ln -sf gfortran %{buildroot}%{_prefix}/bin/f95
+ln -sf ..%{_prefix}/bin/%{?cross}cpp %{buildroot}/lib/%{?cross}cpp
+%if %{build_fortran}
+ln -sf %{?cross}gfortran %{buildroot}%{_prefix}/bin/%{?cross}f95
+%endif
 rm -f %{buildroot}%{_infodir}/dir
 gzip -9 %{buildroot}%{_infodir}/*.info*
-ln -sf gcc %{buildroot}%{_prefix}/bin/gnatgcc
+%if %{build_ada}
+ln -sf %{?cross}gcc %{buildroot}%{_prefix}/bin/%{?cross}gnatgcc
+%endif
+
+%if !%{isnative}
+
+mkdir -p %{buildroot}/%{_prefix}/%{gcc_target_platform}/bin
+%if %{build_fortran}
+for i in cc c89 c99 gcc c++ g++ gfortran f95; do
+%else
+for i in cc c89 c99 gcc c++ g++; do
+%endif
+  ln -sf ../../bin/%{gcc_target_platform}-$i %{buildroot}%{_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
@@ -819,6 +994,8 @@
   fi
 done
 
+%endif # isnative
+
 for f in `find %{buildroot}%{_prefix}/include/c++/%{gcc_version}/%{gcc_target_platform}/ -name c++config.h`; do
   for i in 1 2 4 8; do
     sed -i -e 's/#define _GLIBCXX_ATOMIC_BUILTINS_'$i' 1/#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_'$i'\
@@ -848,6 +1025,8 @@
 find ../rpm.doc/libstdc++-v3 -name \*~ | xargs rm
 %endif
 
+%if %{isnative}
+
 %ifarch sparcv9 sparc64
 ln -f %{buildroot}%{_prefix}/bin/%{gcc_target_platform}-gcc \
   %{buildroot}%{_prefix}/bin/sparc-%{_vendor}-%{_target_os}-gcc
@@ -857,12 +1036,19 @@
   %{buildroot}%{_prefix}/bin/ppc-%{_vendor}-%{_target_os}-gcc
 %endif
 
+%endif # isnative
+
+%if %{isnative}
+
 %ifarch sparcv9 ppc
 FULLLPATH=$FULLPATH/lib32
 %endif
 %ifarch sparc64 ppc64
 FULLLPATH=$FULLPATH/lib64
 %endif
+
+%endif # isnative
+
 if [ -n "$FULLLPATH" ]; then
   mkdir -p $FULLLPATH
 else
@@ -883,6 +1069,7 @@
   $FULLPATH/libgcj.spec
 %endif
 
+%if %{isnative}
 mkdir -p %{buildroot}/%{_lib}
 mv -f %{buildroot}%{_prefix}/%{_lib}/libgcc_s.so.1 %{buildroot}/%{_lib}/libgcc_s-%{gcc_version}-%{DATE}.so.1
 chmod 755 %{buildroot}/%{_lib}/libgcc_s-%{gcc_version}-%{DATE}.so.1
@@ -911,7 +1098,11 @@
 GROUP ( /lib/libgcc_s.so.1 libgcc.a )' > $FULLPATH/32/libgcc_s.so
 %endif
 
+%endif # isnative
+
+%if %{isnative}
 mv -f %{buildroot}%{_prefix}/%{_lib}/libgomp.spec $FULLPATH/
+%endif # isnative
 
 %if %{build_ada}
 mv -f $FULLPATH/adalib/libgnarl-*.so %{buildroot}%{_prefix}/%{_lib}/
@@ -919,6 +1110,8 @@
 rm -f $FULLPATH/adalib/libgnarl.so* $FULLPATH/adalib/libgnat.so*
 %endif
 
+%if %{isnative}
+
 mkdir -p %{buildroot}%{_prefix}/libexec/getconf
 if gcc/xgcc -B gcc/ -E -dD -xc /dev/null | grep __LONG_MAX__.*2147483647; then
   ln -sf POSIX_V6_ILP32_OFF32 %{buildroot}%{_prefix}/libexec/getconf/default
@@ -926,6 +1119,8 @@
   ln -sf POSIX_V6_LP64_OFF64 %{buildroot}%{_prefix}/libexec/getconf/default
 fi
 
+%endif # isnative
+
 %if %{build_java}
 pushd ../fastjar-%{fastjar_ver}/obj-%{gcc_target_platform}
 make install DESTDIR=%{buildroot}
@@ -939,8 +1134,13 @@
 %endif
 
 mkdir -p %{buildroot}%{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}
+
+%if %{isnative}
+
 mv -f %{buildroot}%{_prefix}/%{_lib}/libstdc++*gdb.py* \
       %{buildroot}%{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}/
+
+      
 pushd ../libstdc++-v3/python
 for i in `find . -name \*.py`; do
   touch -r $i %{buildroot}%{_prefix}/share/gcc-%{gcc_version}/python/$i
@@ -948,11 +1148,17 @@
 touch -r hook.in %{buildroot}%{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}/libstdc++*gdb.py
 popd
 
+%endif # isnative
+
 pushd $FULLPATH
+%if %{isnative}
+
 if [ "%{_lib}" = "lib" ]; then
 ln -sf ../../../libobjc.so.2 libobjc.so
 ln -sf ../../../libstdc++.so.6.*[0-9] libstdc++.so
+%if %{build_fortran}
 ln -sf ../../../libgfortran.so.3.* libgfortran.so
+%endif
 ln -sf ../../../libgomp.so.1.* libgomp.so
 ln -sf ../../../libmudflap.so.0.* libmudflap.so
 ln -sf ../../../libmudflapth.so.0.* libmudflapth.so
@@ -964,7 +1170,9 @@
 else
 ln -sf ../../../../%{_lib}/libobjc.so.2 libobjc.so
 ln -sf ../../../../%{_lib}/libstdc++.so.6.*[0-9] libstdc++.so
+%if %{build_fortran}
 ln -sf ../../../../%{_lib}/libgfortran.so.3.* libgfortran.so
+%endif
 ln -sf ../../../../%{_lib}/libgomp.so.1.* libgomp.so
 ln -sf ../../../../%{_lib}/libmudflap.so.0.* libmudflap.so
 ln -sf ../../../../%{_lib}/libmudflapth.so.0.* libmudflapth.so
@@ -974,16 +1182,26 @@
 ln -sf ../../../../%{_lib}/libgij.so.11.* libgij.so
 %endif
 fi
+
+%endif # isnative
+
+%if %{isnative}
+
 %if %{build_java}
 mv -f %{buildroot}%{_prefix}/%{_lib}/libgcj_bc.so $FULLLPATH/
 %endif
 mv -f %{buildroot}%{_prefix}/%{_lib}/libstdc++.*a $FULLLPATH/
 mv -f %{buildroot}%{_prefix}/%{_lib}/libsupc++.*a $FULLLPATH/
+%if %{build_fortran}
 mv -f %{buildroot}%{_prefix}/%{_lib}/libgfortran.*a .
+%endif
 mv -f %{buildroot}%{_prefix}/%{_lib}/libobjc.*a .
 mv -f %{buildroot}%{_prefix}/%{_lib}/libgomp.*a .
 mv -f %{buildroot}%{_prefix}/%{_lib}/libmudflap{,th}.*a $FULLLPATH/
 
+%endif # isnative
+
+%if %{isnative}
 %if %{build_ada}
 %ifarch sparcv9 ppc
 rm -rf $FULLPATH/64/ada{include,lib}
@@ -1021,12 +1239,16 @@
 fi
 popd
 fi
-%endif
+%endif # build_ada
+%endif # isnative
 
+%if %{isnative}
 %ifarch sparcv9 ppc
 ln -sf ../../../../../lib64/libobjc.so.2 64/libobjc.so
 ln -sf ../`echo ../../../../lib/libstdc++.so.6.*[0-9] | sed s~/lib/~/lib64/~` 64/libstdc++.so
+%if %{build_fortran}
 ln -sf ../`echo ../../../../lib/libgfortran.so.3.* | sed s~/lib/~/lib64/~` 64/libgfortran.so
+%endif
 ln -sf ../`echo ../../../../lib/libgomp.so.1.* | sed s~/lib/~/lib64/~` 64/libgomp.so
 rm -f libmudflap.so libmudflapth.so
 echo 'INPUT ( %{_prefix}/lib/'`echo ../../../../lib/libmudflap.so.0.* | sed 's,^.*libm,libm,'`' )' > libmudflap.so
@@ -1040,7 +1262,10 @@
 ln -sf lib32/libgcj_bc.so libgcj_bc.so
 ln -sf ../lib64/libgcj_bc.so 64/libgcj_bc.so
 %endif
+
+%if %{build_fortran}
 mv -f %{buildroot}%{_prefix}/lib64/libgfortran.*a 64/
+%endif
 mv -f %{buildroot}%{_prefix}/lib64/libobjc.*a 64/
 mv -f %{buildroot}%{_prefix}/lib64/libgomp.*a 64/
 ln -sf lib32/libstdc++.a libstdc++.a
@@ -1057,12 +1282,18 @@
 ln -sf lib32/adalib adalib
 ln -sf ../lib64/adalib 64/adalib
 %endif
-%endif
+%endif # sparc / ppc
+
+%endif # isnative
+
+%if %{isnative}
 %ifarch %{multilib_64_archs}
 mkdir -p 32
 ln -sf ../../../../libobjc.so.2 32/libobjc.so
 ln -sf ../`echo ../../../../lib64/libstdc++.so.6.*[0-9] | sed s~/../lib64/~/~` 32/libstdc++.so
+%if %{build_fortran}
 ln -sf ../`echo ../../../../lib64/libgfortran.so.3.* | sed s~/../lib64/~/~` 32/libgfortran.so
+%endif
 ln -sf ../`echo ../../../../lib64/libgomp.so.1.* | sed s~/../lib64/~/~` 32/libgomp.so
 rm -f libmudflap.so libmudflapth.so
 echo 'INPUT ( %{_prefix}/lib64/'`echo ../../../../lib64/libmudflap.so.0.* | sed 's,^.*libm,libm,'`' )' > libmudflap.so
@@ -1074,10 +1305,19 @@
 ln -sf ../`echo ../../../../lib64/libgcj-tools.so.11.* | sed s~/../lib64/~/~` 32/libgcj-tools.so
 ln -sf ../`echo ../../../../lib64/libgij.so.11.* | sed s~/../lib64/~/~` 32/libgij.so
 %endif
+%endif # isnative
+
+%if %{isnative}
+
 mv -f %{buildroot}%{_prefix}/lib/libgfortran.*a 32/
 mv -f %{buildroot}%{_prefix}/lib/libobjc.*a 32/
 mv -f %{buildroot}%{_prefix}/lib/libgomp.*a 32/
-%endif
+
+%endif # isnative
+
+%endif # multilib_64_archs
+
+%if %{isnative}
 %ifarch sparc64 ppc64
 ln -sf ../lib32/libstdc++.a 32/libstdc++.a
 ln -sf lib64/libstdc++.a libstdc++.a
@@ -1097,7 +1337,8 @@
 ln -sf ../lib32/adalib 32/adalib
 ln -sf lib64/adalib adalib
 %endif
-%else
+%else # ! sparc64 or ppc64
+
 %ifarch %{multilib_64_archs}
 ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libstdc++.a 32/libstdc++.a
 ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/libsupc++.a 32/libsupc++.a
@@ -1110,22 +1351,54 @@
 ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/adainclude 32/adainclude
 ln -sf ../../../%{multilib_32_arch}-%{_vendor}-%{_target_os}/%{gcc_version}/adalib 32/adalib
 %endif
-%endif
-%endif
+
+%endif # multilib_64_archs
+%endif # ! sparc64 or ppc64
+
+
+%endif # isnative
 
 # Strip debug info from Fortran/ObjC/Java static libraries
-strip -g `find . \( -name libgfortran.a -o -name libobjc.a -o -name libgomp.a \
+%if %{isnative}
+
+%{__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`
+
+%else
+
+# mudflap blows an error when stripped
+# *** ERROR: No build ID note found in /projects/mips/try2/rpmbuild/BUILDROOT/armv5tel-redhat-linux-gnueabi-gcc-4.5.1-5.cross11.x86_64/usr/lib/gcc/armv5tel-redhat-linux-gnueabi/4.5.1/libmudflap.so.0.0.0
+#
+# seems to be due to link with ld not gcc, but we're not controlling that
+# from the spec file :-(
+
+%{__strip} -g `find . \( -name libgfortran.a -o -name libobjc.a -o -name libgomp.a \
+		    -o -name libgcc.a -o -name libgcov.a \) -a -type f`
+
+%endif
+
 popd
+
+%if %{isnative}
+
+%if %{build_fortran}
 chmod 755 %{buildroot}%{_prefix}/%{_lib}/libgfortran.so.3.*
+%endif
 chmod 755 %{buildroot}%{_prefix}/%{_lib}/libgomp.so.1.*
 chmod 755 %{buildroot}%{_prefix}/%{_lib}/libmudflap{,th}.so.0.*
 chmod 755 %{buildroot}%{_prefix}/%{_lib}/libobjc.so.2.*
 
+%endif # isnative
+
 %if %{build_ada}
+%if %{isnative}
 chmod 755 %{buildroot}%{_prefix}/%{_lib}/libgnarl*so*
 chmod 755 %{buildroot}%{_prefix}/%{_lib}/libgnat*so*
+%else
+chmod 755 $FULLLPATH/libgnarl*so*
+chmod 755 $FULLLPATH/libgnat*so*
+%endif # isnative
 %endif
 
 mv $FULLPATH/include-fixed/syslimits.h $FULLPATH/include/syslimits.h
@@ -1138,7 +1411,7 @@
   fi
 done
 
-cat > %{buildroot}%{_prefix}/bin/c89 <<"EOF"
+cat > %{buildroot}%{_prefix}/bin/%{?cross}c89 <<"EOF"
 #!/bin/sh
 fl="-std=c89"
 for opt; do
@@ -1150,7 +1423,7 @@
 done
 exec gcc $fl ${1+"$@"}
 EOF
-cat > %{buildroot}%{_prefix}/bin/c99 <<"EOF"
+cat > %{buildroot}%{_prefix}/bin/%{?cross}c99 <<"EOF"
 #!/bin/sh
 fl="-std=c99"
 for opt; do
@@ -1162,15 +1435,21 @@
 done
 exec gcc $fl ${1+"$@"}
 EOF
-chmod 755 %{buildroot}%{_prefix}/bin/c?9
+chmod 755 %{buildroot}%{_prefix}/bin/%{?cross}c?9
+
+%if %{isnative}
 
 mkdir -p %{buildroot}%{_prefix}/sbin
 gcc -static -Os %{SOURCE1} -o %{buildroot}%{_prefix}/sbin/libgcc_post_upgrade
 strip %{buildroot}%{_prefix}/sbin/libgcc_post_upgrade
 
+%endif # isnative
+
 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
@@ -1180,6 +1459,8 @@
 rm -f %{buildroot}%{_prefix}/%{_lib}/libssp*
 rm -f %{buildroot}%{_prefix}/bin/gnative2ascii
 
+%if %{isnative}
+
 %ifarch %{multilib_64_archs}
 # Remove libraries for the other arch on multilib arches
 rm -f %{buildroot}%{_prefix}/lib/lib*.so*
@@ -1191,6 +1472,8 @@
 %endif
 %endif
 
+%endif # isnative
+
 %if %{build_java}
 mkdir -p %{buildroot}%{_prefix}/share/java/gcj-endorsed \
 	 %{buildroot}%{_prefix}/%{_lib}/gcj-%{version}/classmap.db.d
@@ -1210,6 +1493,7 @@
 %endif
 %endif
 
+%if %{run_tests}
 # run the tests.
 make %{?_smp_mflags} -k check ALT_CC_UNDER_TEST=gcc ALT_CXX_UNDER_TEST=g++ RUNTESTFLAGS="--target_board=unix/'{,-fstack-protector}'" || :
 echo ====================TESTING=========================
@@ -1222,10 +1506,47 @@
 tar cf - testlogs-%{_target_platform}-%{version}-%{release} | bzip2 -9c \
   | uuencode testlogs-%{_target_platform}.tar.bz2 || :
 rm -rf testlogs-%{_target_platform}-%{version}-%{release}
+%endif
+
+
+# remove stuff with invariant names we don't want for cross
+
+%if !%{isnative}
+
+rm -f %{buildroot}%{_prefix}/share/info/cpp.info.gz
+rm -f %{buildroot}%{_prefix}/share/info/cppinternals.info.gz
+rm -f %{buildroot}%{_prefix}/share/info/gcc.info.gz
+rm -f %{buildroot}%{_prefix}/share/info/gccinstall.info.gz
+rm -f %{buildroot}%{_prefix}/share/info/gccint.info.gz
+rm -f %{buildroot}%{_prefix}/share/info/libgomp.info.gz
+
+rm -f %{buildroot}%{_prefix}/share/man/man7/fsf-funding.7.gz
+rm -f %{buildroot}%{_prefix}/share/man/man7/gfdl.7.gz
+rm -f %{buildroot}%{_prefix}/share/man/man7/gpl.7.gz
+
+rm -rf %{buildroot}%{_prefix}/share/locale
+
+# invariantly-named host library
+rm -f %{buildroot}%{_libdir}/libiberty.a
+rm -f %{buildroot}%{_libdir}64/libiberty.a
+
+# invariantly named stuff conflicts with native install stuff
+
+rm -rf %{buildroot}%{_prefix}/share/gcc-%{gcc_version}/python
+
+%endif
+
+
 
 %clean
 rm -rf %{buildroot}
 
+#
+# all these pre and posts are knocked out when building cross
+#
+
+%if %{isnative}
+
 %post
 if [ -f %{_infodir}/gcc.info.gz ]; then
   /sbin/install-info \
@@ -1238,25 +1559,25 @@
     --info-dir=%{_infodir} %{_infodir}/gcc.info.gz || :
 fi
 
-%post -n cpp
+%post -n %{?cross}cpp
 if [ -f %{_infodir}/cpp.info.gz ]; then
   /sbin/install-info \
     --info-dir=%{_infodir} %{_infodir}/cpp.info.gz || :
 fi
 
-%preun -n cpp
+%preun -n %{?cross}cpp
 if [ $1 = 0 -a -f %{_infodir}/cpp.info.gz ]; then
   /sbin/install-info --delete \
     --info-dir=%{_infodir} %{_infodir}/cpp.info.gz || :
 fi
 
-%post gfortran
+%post %{?cross}gfortran
 if [ -f %{_infodir}/gfortran.info.gz ]; then
   /sbin/install-info \
     --info-dir=%{_infodir} %{_infodir}/gfortran.info.gz || :
 fi
 
-%preun gfortran
+%preun %{?cross}gfortran
 if [ $1 = 0 -a -f %{_infodir}/gfortran.info.gz ]; then
   /sbin/install-info --delete \
     --info-dir=%{_infodir} %{_infodir}/gfortran.info.gz || :
@@ -1297,17 +1618,17 @@
 # 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
 if [ -f %{_infodir}/cp-tools.info.gz ]; then
   /sbin/install-info \
@@ -1316,7 +1637,7 @@
     --info-dir=%{_infodir} %{_infodir}/fastjar.info.gz || :
 fi
 
-%preun -n libgcj
+%preun -n %{?cross}libgcj
 if [ $1 = 0 -a -f %{_infodir}/cp-tools.info.gz ]; then
   /sbin/install-info --delete \
     --info-dir=%{_infodir} %{_infodir}/cp-tools.info.gz || :
@@ -1324,42 +1645,65 @@
     --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
+%if %{build_fortran}
+%post -n %{?cross}libgfortran -p /sbin/ldconfig
 
-%postun -n libgfortran -p /sbin/ldconfig
+%postun -n %{?cross}libgfortran -p /sbin/ldconfig
+%endif
 
-%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
+%post -n %{?cross}libgomp
 /sbin/ldconfig
 if [ -f %{_infodir}/libgomp.info.gz ]; then
   /sbin/install-info \
     --info-dir=%{_infodir} %{_infodir}/libgomp.info.gz || :
 fi
 
-%preun -n libgomp
+%preun -n %{?cross}libgomp
 if [ $1 = 0 -a -f %{_infodir}/libgomp.info.gz ]; then
   /sbin/install-info --delete \
     --info-dir=%{_infodir} %{_infodir}/libgomp.info.gz || :
 fi
 
-%postun -n libgomp -p /sbin/ldconfig
+%postun -n %{?cross}libgomp -p /sbin/ldconfig
+
+%post -n %{?cross}libmudflap -p /sbin/ldconfig
+
+%postun -n %{?cross}libmudflap -p /sbin/ldconfig
+
+%endif # isnative
+
 
-%post -n libmudflap -p /sbin/ldconfig
 
-%postun -n libmudflap -p /sbin/ldconfig
+#
+# files
+#
+
+
+%if %{isnative}
 
 %files -f %{name}.lang
+
+%else # isnative
+
+%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}
+
 %ifarch ppc
 %{_prefix}/bin/%{_target_platform}-gcc
 %endif
@@ -1370,9 +1714,32 @@
 %{_prefix}/bin/ppc-%{_vendor}-%{_target_os}-gcc
 %endif
 %{_prefix}/bin/%{gcc_target_platform}-gcc
-%{_mandir}/man1/gcc.1*
-%{_mandir}/man1/gcov.1*
+
+%else # !isnative
+
+%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
+%{_prefix}/bin/%{?cross}gcc-%{version}
+%{_prefix}/bin/%{?cross}gccbug
+
+%endif # !isnative
+
+%{_mandir}/man1/%{?cross}gcc.1*
+%{_mandir}/man1/%{?cross}gcov.1*
+
+%if %{isnative}
+
 %{_infodir}/gcc*
+
+%endif # isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/install-tools
+%{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/install-tools
+
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1395,6 +1762,7 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/omp.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/stdint.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/stdint-gcc.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
@@ -1433,6 +1801,7 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/spu2vmx.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/vec_types.h
 %endif
+%endif # isnative
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/collect2
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/crt*.o
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcc.a
@@ -1456,6 +1825,7 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libmudflap.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libmudflapth.so
 %endif
+%if %{isnative}
 %ifarch %{multilib_64_archs}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/crt*.o
@@ -1476,34 +1846,94 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.so
 %endif
+%endif # isnative
+
+%if %{target_arch} == "armv5tel"
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/arm_neon.h
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/mmintrin.h
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/ssp
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libssp*
+%endif
+
+
+%if %{isnative}
+
 %dir %{_prefix}/libexec/getconf
 %{_prefix}/libexec/getconf/default
+
+%endif # isnative
+
+%if ! %{isnative}
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include-fixed
+#%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/plugin
+%{_prefix}/%{gcc_target_platform}/lib/libiberty.a
+%endif
+
 %doc gcc/README* rpm.doc/changelogs/gcc/ChangeLog* gcc/COPYING*
 
-%files -n cpp -f cpplib.lang
+%if %{isnative}
+
+%files -n %{cross}cpp -f cpplib.lang
+
+%else # !isnative
+
+%files -n %{?cross}cpp
+
+%endif # !isnative
+
 %defattr(-,root,root,-)
-/lib/cpp
-%{_prefix}/bin/cpp
-%{_mandir}/man1/cpp.1*
+/lib/%{?cross}cpp
+%{_prefix}/bin/%{?cross}cpp
+%{_mandir}/man1/%{?cross}cpp.1*
+
+%if %{isnative}
+
 %{_infodir}/cpp*
+
+%endif # isnative
+
 %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 # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcc_s.so.1
+
+%endif # !isnative
+
 %doc gcc/COPYING.LIB
 
 %files c++
 %defattr(-,root,root,-)
+
+%if %{isnative}
+
 %{_prefix}/bin/%{gcc_target_platform}-*++
-%{_prefix}/bin/g++
-%{_prefix}/bin/c++
-%{_mandir}/man1/g++.1*
+
+%else # !isnative
+
+%dir %{_prefix}/%{gcc_target_platform}
+%dir %{_prefix}/%{gcc_target_platform}/bin
+%{_prefix}/%{gcc_target_platform}/bin/*++
+
+%endif # !isnative
+
+%{_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}
@@ -1511,6 +1941,9 @@
 %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 sparcv9 ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libstdc++.so
@@ -1532,9 +1965,23 @@
 %endif
 %doc rpm.doc/changelogs/gcc/cp/ChangeLog*
 
-%files -n libstdc++
+%endif # !isnative
+
+%files -n %{cross}libstdc++
 %defattr(-,root,root,-)
+
+%if %{isnative}
+
 %{_prefix}/%{_lib}/libstdc++.so.6*
+
+%else # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so.6*
+
+%endif # !isnative
+
+%if %{isnative}
+
 %dir %{_datadir}/gdb
 %dir %{_datadir}/gdb/auto-load
 %dir %{_datadir}/gdb/auto-load/%{_prefix}
@@ -1543,17 +1990,36 @@
 %dir %{_prefix}/share/gcc-%{gcc_version}
 %{_prefix}/share/gcc-%{gcc_version}/python
 
-%files -n libstdc++-devel
+%endif
+
+%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 # !isnative
+
+%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 # !isnative
+
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
+
+%if %{isnative}
+
 %if 0%{?fedora} < 14
+
 %ifarch sparcv9 ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32/libstdc++.a
@@ -1568,17 +2034,42 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libsupc++.a
 %endif
+
+%endif # fedora < 14
+
+%else # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.a
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libsupc++.a
+
 %endif
+
 %ifnarch sparcv9 ppc %{multilib_64_archs}
+
+%if %{isnative}
+
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so
-%endif
+
+%else # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libstdc++.so
+
+%endif # !isnative
+
+%endif # ifnarch
+
+
 %doc rpm.doc/changelogs/libstdc++-v3/ChangeLog* libstdc++-v3/README*
 
-%files -n libstdc++-static
+%files -n %{cross}libstdc++-static
 %defattr(-,root,root,-)
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
+
+%if %{isnative}
+
 %ifarch sparcv9 ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32/libstdc++.a
@@ -1594,6 +2085,8 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libsupc++.a
 %endif
 
+%endif # !isnative
+
 %if %{build_libstdcxx_docs}
 %files -n libstdc++-docs
 %defattr(-,root,root)
@@ -1601,6 +2094,7 @@
 %doc rpm.doc/libstdc++-v3/html
 %endif
 
+%if %{build_objc}
 %files objc
 %defattr(-,root,root,-)
 %dir %{_prefix}/lib/gcc
@@ -1627,23 +2121,40 @@
 %doc rpm.doc/objc/*
 %doc libobjc/THREADS* rpm.doc/changelogs/libobjc/ChangeLog*
 
-%files objc++
+%files %{cross}objc++
 %defattr(-,root,root,-)
 %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}/cc1objplus
 
-%files -n libobjc
+%files -n %{cross}libobjc
 %defattr(-,root,root,-)
 %{_prefix}/%{_lib}/libobjc.so.2*
 
-%files gfortran
+%endif # build_objc
+
+
+%if %{build_fortran}
+%files %{cross}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 # !isnative
+
+%dir %{_prefix}/%{gcc_target_platform}
+%dir %{_prefix}/%{gcc_target_platform}/bin
+%{_prefix}/%{gcc_target_platform}/bin/gfortran
+%{_prefix}/%{gcc_target_platform}/bin/f95
+
+%endif # !isnative
+
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1655,10 +2166,14 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/finclude/omp_lib.f90
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/finclude/omp_lib.mod
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/finclude/omp_lib_kinds.mod
+
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/f951
 %{_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 sparcv9 ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/64/libgfortranbegin.a
@@ -1671,12 +2186,18 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgfortran.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libgfortran.so
 %endif
+
+%endif # isnative
+
 %doc rpm.doc/gfortran/*
 
-%files -n libgfortran
+
+%files -n %{cross}libgfortran
 %defattr(-,root,root,-)
 %{_prefix}/%{_lib}/libgfortran.so.3*
 
+%endif # build_fortran
+
 %if %{build_java}
 %files java
 %defattr(-,root,root,-)
@@ -1700,6 +2221,9 @@
 %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}/jvgenmain
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcj.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcj-tools.so
+
+%if %{isnative}
+
 %ifarch sparcv9 sparc64 ppc ppc64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcj_bc.so
 %endif
@@ -1718,9 +2242,12 @@
 %{_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 # isnative
+
 %doc rpm.doc/changelogs/gcc/java/ChangeLog*
 
-%files -n libgcj
+%files -n %{cross}libgcj
 %defattr(-,root,root,-)
 %{_prefix}/bin/jv-convert
 %{_prefix}/bin/gij
@@ -1771,7 +2298,7 @@
 %dir %{_prefix}/%{_lib}/gcj-%{version}/classmap.db.d
 %attr(0644,root,root) %verify(not md5 size mtime) %ghost %config(missingok,noreplace) %{_prefix}/%{_lib}/gcj-%{version}/classmap.db
 
-%files -n libgcj-devel
+%files -n %{cross}libgcj-devel
 %defattr(-,root,root,-)
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
@@ -1812,10 +2339,16 @@
 %endif
 
 %if %{build_ada}
-%files gnat
+%files %{cross}gnat
 %defattr(-,root,root,-)
 %{_prefix}/bin/gnat*
+
+%if %{isnative}
+
 %{_infodir}/gnat*
+
+%endif # isnative
+
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1839,12 +2372,17 @@
 %{_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
 
-%files -n libgnat-devel
+%endif # isnative
+
+%files -n %{cross}libgnat-devel
 %defattr(-,root,root,-)
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
@@ -1870,7 +2408,7 @@
 %exclude %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/adalib/libgnarl.a
 %endif
 
-%files -n libgnat-static
+%files -n %{cross}libgnat-static
 %defattr(-,root,root,-)
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
@@ -1894,24 +2432,47 @@
 %endif
 %endif
 
-%files -n libgomp
+%files -n %{cross}libgomp
 %defattr(-,root,root,-)
-%{_prefix}/%{_lib}/libgomp.so.1*
+
+%if %{isnative}
+
 %{_infodir}/libgomp.info*
+%{_prefix}/%{_lib}/libgomp.so.1*
+
+%else # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgomp.so.1*
+
+%endif # !isnative
+
 %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*
 
-%files -n libmudflap-devel
+%else # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.so.0*
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.so.0*
+
+%endif # !isnative
+
+%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}
+
 %if 0%{?fedora} < 14
 %ifarch sparcv9 ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32
@@ -1927,18 +2488,33 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.a
 %endif
-%endif
+
+%endif # fedora < 14
+
 %ifnarch sparcv9 sparc64 ppc ppc64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.so
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.so
 %endif
+
+%else # !isnative
+
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.so
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.so
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflap.a
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.a
+%endif # !isnative
+
 %doc rpm.doc/changelogs/libmudflap/ChangeLog*
 
-%files -n libmudflap-static
+%files -n %{cross}libmudflap-static
 %defattr(-,root,root,-)
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
+
+
+%if %{isnative}
+
 %ifarch sparcv9 ppc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/lib32/libmudflap.a
@@ -1954,6 +2530,8 @@
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libmudflapth.a
 %endif
 
+%endif # isnative
+
 %changelog
 * Fri Nov 12 2010 Jakub Jelinek <jakub@redhat.com> 4.5.1-5
 - update from gcc-4_5-branch
