
Original binutils cross patch by David Woodhouse:

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

gcc cross patch by Lennert Buytenhek.


Index: SPECS/binutils.spec
===================================================================
--- SPECS.orig/binutils.spec
+++ SPECS/binutils.spec
@@ -1,7 +1,15 @@
+%if "%{?binutils_target}" == ""
+%define binutils_target %{_target_platform}
+%define isnative 1
+%else
+%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
+Release: 1.cross
 License: GPLv3+
 Group: Development/Tools
 URL: http://sources.redhat.com/binutils
@@ -19,7 +27,7 @@
 
 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
@@ -46,7 +54,7 @@
 %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
@@ -56,7 +64,7 @@
 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~
@@ -72,7 +80,7 @@
 %patch9 -p0 -b .bz4923~
 %patch10 -p0 -b .open~
 
-# 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*
@@ -84,24 +92,36 @@
 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
@@ -114,8 +134,9 @@
 %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*
 
@@ -137,10 +158,6 @@
 # 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
@@ -158,22 +175,36 @@
 %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
@@ -204,12 +235,16 @@
 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*
@@ -219,6 +254,7 @@
 %{_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,9 +1,26 @@
+%if "%{?gcc_target}" == ""
+%define gcc_target %{_target_platform}
+%define isnative 1
+%else
+%define isnative 0
+%define cross %{gcc_target}-
+%define crosspost -%{gcc_target}
+%define __strip %{gcc_target}-strip
+%define _lib lib
+%endif
+
 %define DATE 20070816
 %define gcc_version 4.1.2
-%define gcc_release 18
+%define gcc_release 18.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_java 0
+%define build_objc 0
+%define run_tests 0
+%else
+%define multilib_64_archs sparc64 ppc64 s390x x86_64
 %ifarch %{ix86} x86_64 ia64 ppc alpha
 %define build_ada 1
 %else
@@ -29,10 +46,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}.cross
 # libgcc, libgfortran, libmudflap and crtstuff have an exception which allows
 # linking it into any kind of programs or shared libraries without
 # restrictions.
@@ -52,7 +70,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,7 +78,7 @@ 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
+BuildRequires: glibc-devel%{?crosspost} >= 2.4.90-13
 BuildRequires: elfutils-devel >= 0.72
 %ifarch ppc ppc64 s390 s390x sparc sparcv9 alpha
 # Make sure glibc supports TFmode long double
@@ -77,7 +95,7 @@ BuildRequires: gcc-gnat >= 3.1, libgnat 
 %ifarch ia64
 BuildRequires: libunwind >= 0.98
 %endif
-Requires: cpp = %{version}-%{release}
+Requires: %{?cross}cpp = %{version}-%{release}
 # Need .eh_frame ld optimizations
 # Need proper visibility support
 # Need -pie support
@@ -89,15 +107,16 @@ 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
+Requires: glibc-devel%{?crosspost} >= 2.2.90-12
 %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
-Requires: libgcc >= %{version}-%{release}
+Requires: libgcc%{?crosspost} >= %{version}-%{gcc_release}
+%if %{isnative}
 Requires: libgomp = %{version}-%{release}
 Obsoletes: gcc3
 Obsoletes: egcs
@@ -121,6 +140,7 @@ Obsoletes: gcc34
 Obsoletes: gcc35
 Obsoletes: gcc4
 Prereq: /sbin/install-info
+%endif
 AutoReq: true
 
 Patch1: gcc41-ice-hack.patch
@@ -157,6 +177,7 @@ Patch28: gcc41-sparc-niagara.patch
 %ifnarch %{arm}                                                                                                                 
 %define _gnu %{nil}
 %endif
+%if "%{?gcc_target}" == ""
 %ifarch sparc
 %define gcc_target_platform sparc64-%{_vendor}-%{_target_os}
 %endif
@@ -166,6 +187,9 @@ Patch28: gcc41-sparc-niagara.patch
 %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.
@@ -183,13 +207,15 @@ 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: libstdc++%{?crosspost} = %{version}-%{gcc_release}
+Requires: libstdc++-devel%{?crosspost} = %{version}-%{gcc_release}
+%if %{isnative}
 Obsoletes: gcc3-c++
 Obsoletes: gcc34-c++
 Obsoletes: gcc35-c++
 Obsoletes: gcc4-c++
+%endif
 Autoreq: true
 
 %description c++
@@ -255,13 +281,15 @@ 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: libgfortran%{?crosspost} = %{version}-%{gcc_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
@@ -379,16 +407,18 @@ Autoreq: true
 %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}
 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
@@ -566,6 +596,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} \
@@ -637,6 +668,18 @@ 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 --enable-languages=c,c++,fortran \
+	--disable-libgcj --disable-libssp --disable-libgomp \
+	--disable-libmudflap --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
@@ -704,8 +747,6 @@ fi
 export PATH=`pwd`/java_hacks${PATH:+:$PATH}
 %endif
 
-TARGET_PLATFORM=%{gcc_target_platform}
-
 # There are some MP bugs in libstdc++ Makefiles
 make -C %{gcc_target_platform}/libstdc++-v3
 
@@ -722,13 +763,13 @@ 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 %{?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
 
 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
@@ -790,6 +831,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
@@ -801,22 +843,34 @@ 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
+%else
+rm -rf $FULLPATH/include/c++
+ln -sf ../../../../../%{gcc_target_platform}/sys-root%{_prefix}/include/c++/%{version} $FULLPATH/include/c++
+
+ln -sf ../../../../%{gcc_target_platform}/sys-root/%{_lib}/libgcc_s.so.1 $FULLPATH/libgcc_s.so
+%endif
 
+%if %{isnative}
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgomp.spec $FULLPATH/
 mv -f $RPM_BUILD_ROOT%{_prefix}/include/omp.h $FULLPATH/include/
+%endif
 
+%if %{isnative}
 %if %{build_ada}
 mv -f $FULLPATH/adalib/libgnarl-*.so $RPM_BUILD_ROOT%{_prefix}/%{_lib}/
 mv -f $FULLPATH/adalib/libgnat-*.so $RPM_BUILD_ROOT%{_prefix}/%{_lib}/
 rm -f $FULLPATH/adalib/libgnarl.so* $FULLPATH/adalib/libgnat.so*
 %endif
+%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
@@ -827,6 +881,7 @@ fi
 %endif
 
 pushd $FULLPATH
+%if %{isnative}
 if [ "%{_lib}" = "lib" ]; then
 %if %{build_objc}
 ln -sf ../../../libobjc.so.1 libobjc.so
@@ -885,7 +940,12 @@ mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgomp.*a .
 mv -f $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libmudflap{,th}.*a .
 mv -f $RPM_BUILD_ROOT%{_prefix}/include/mf-runtime.h include/
+%else
+ln -sf ../../../../%{gcc_target}/sys-root%{_prefix}/%{_lib}/`echo libstdc++.so.6.*` libstdc++.so
+ln -sf ../../../../%{gcc_target}/sys-root%{_prefix}/%{_lib}/`echo libgfortran.so.1.*` libgfortran.so
+%endif
 
+%if %{isnative}
 %ifarch sparc ppc
 %if %{build_objc}
 ln -sf ../../../../../lib64/libobjc.so.1 64/libobjc.so
@@ -952,23 +1012,28 @@ 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 %{isnative}
 %if %{build_ada}
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgnarl*so*
 chmod 755 $RPM_BUILD_ROOT%{_prefix}/%{_lib}/libgnat*so*
 %endif
+%endif
 
 for h in `find $FULLPATH/include -name \*.h`; do
   if grep -q 'It has been auto-edited by fixincludes from' $h; then
@@ -978,7 +1043,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
@@ -990,7 +1055,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
@@ -1002,15 +1067,19 @@ 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
+%{__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
@@ -1044,7 +1113,7 @@ 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
 
 %post
 /sbin/install-info \
@@ -1056,11 +1125,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 || :
@@ -1146,13 +1215,15 @@ fi
 
 %postun -n libmudflap -p /sbin/ldconfig
 
+%if %{isnative}
 %files -f %{name}.lang
+%else
+%files
+%endif
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/bin/cc
-%{_prefix}/bin/c89
-%{_prefix}/bin/c99
 %{_prefix}/bin/gcc
-%{_prefix}/bin/gcov
 %{_prefix}/bin/protoize
 %{_prefix}/bin/unprotoize
 %ifarch sparc ppc
@@ -1164,12 +1235,18 @@ fi
 %ifarch ppc64
 %{_prefix}/bin/ppc-%{_vendor}-%{_target_os}-gcc
 %endif
+%endif
+%{_prefix}/bin/%{?cross}c89
+%{_prefix}/bin/%{?cross}c99
+%{_prefix}/bin/%{?cross}gcov
 %{_prefix}/bin/%{gcc_target_platform}-gcc
-%{_mandir}/man1/gcc.1*
-%{_mandir}/man1/gcov.1*
+%{_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}
@@ -1177,7 +1254,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
@@ -1187,6 +1266,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/iso646.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/syslimits.h
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/unwind.h
+%if %{isnative}
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/omp.h
 %ifarch %{ix86} x86_64
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/mmintrin.h
@@ -1206,6 +1286,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
@@ -1213,6 +1294,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcov.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcc_eh.a
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/libgcc_s.so
+%if %{isnative}
 %{_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
@@ -1238,35 +1320,52 @@ 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)
+%if %{isnative}
 /lib/cpp
-%{_prefix}/bin/cpp
-%{_mandir}/man1/cpp.1*
 %{_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
 
+%if %{isnative}
 %files -n libgcc
 %defattr(-,root,root)
 /%{_lib}/libgcc_s-%{gcc_version}-%{DATE}.so.1
 /%{_lib}/libgcc_s.so.1
 %{_prefix}/sbin/libgcc_post_upgrade
 %doc gcc/COPYING.LIB
+%endif
 
 %files c++
 %defattr(-,root,root)
+%if %{isnative}
 %{_prefix}/bin/%{gcc_target_platform}-*++
-%{_prefix}/bin/g++
-%{_prefix}/bin/c++
-%{_mandir}/man1/g++.1*
+%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}
+%if !%{isnative}
+%{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/include/c++
+%{_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
 %dir %{_prefix}/libexec/gcc
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
@@ -1292,10 +1391,13 @@ fi
 %endif
 %doc rpm.doc/changelogs/gcc/cp/ChangeLog*
 
+%if %{isnative}
 %files -n libstdc++
 %defattr(-,root,root)
 %{_prefix}/%{_lib}/libstdc++.so.6*
+%endif
 
+%if %{isnative}
 %files -n libstdc++-devel
 %defattr(-,root,root)
 %dir %{_prefix}/include/c++
@@ -1322,6 +1424,7 @@ fi
 %{_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
@@ -1364,21 +1467,25 @@ fi
 
 %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*
+%endif
 %dir %{_prefix}/lib/gcc
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}
 %dir %{_prefix}/libexec/gcc
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}
 %dir %{_prefix}/libexec/gcc/%{gcc_target_platform}/%{gcc_version}
+%if %{isnative}
 %dir %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/finclude
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/finclude/omp_lib.h
 %{_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
+%endif
 %{_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
@@ -1397,9 +1504,11 @@ fi
 %endif
 %doc rpm.doc/gfortran/*
 
+%if %{isnative}
 %files -n libgfortran
 %defattr(-,root,root)
 %{_prefix}/%{_lib}/libgfortran.so.1*
+%endif
 
 %if %{build_java}
 %files java
@@ -1567,16 +1676,21 @@ fi
 %{_prefix}/%{_lib}/libgnarl-*.so
 %endif
 
+%if %{isnative}
 %files -n libgomp
 %defattr(-,root,root)
 %{_prefix}/%{_lib}/libgomp.so.1*
 %doc rpm.doc/changelogs/libgomp/ChangeLog*
+%endif
 
+%if %{isnative}
 %files -n libmudflap
 %defattr(-,root,root)
 %{_prefix}/%{_lib}/libmudflap.so.0*
 %{_prefix}/%{_lib}/libmudflapth.so.0*
+%endif
 
+%if %{isnative}
 %files -n libmudflap-devel
 %defattr(-,root,root)
 %dir %{_prefix}/lib/gcc
@@ -1603,6 +1717,7 @@ fi
 %{_prefix}/lib/gcc/%{gcc_target_platform}/%{gcc_version}/32/libmudflapth.so
 %endif
 %doc rpm.doc/changelogs/libmudflap/ChangeLog*
+%endif
 
 %changelog
 * Thu Aug 16 2007 Jakub Jelinek <jakub@redhat.com> 4.1.2-18
