[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH] cross-compilation for binutils.



On Sat, 2008-07-05 at 16:10 +0200, Enrico Scholz wrote:
> David Woodhouse <dwmw2 infradead org> writes:
> 
> >> Something like
> >> 
> >> | --enable-targets=%_host
> >> 
> >> should be added everytime to allow e.g. 'strip' to work on both native
> >> and on target binaries.  This is required when building cross-rpms which
> >> are providing target and native binaries.
> >
> > Is it really? You already have to use the appropriate compiler and
> > linker for native vs. target binaries -- why can't you use the
> > appropriate version of 'strip', too?
> 
> rpm magic; final %__spec_install_post makes something like
> 
> + /usr/lib/rpm/redhat/brp-compress
> + /usr/lib/rpm/redhat/brp-strip-static-archive arm-iwmmxt-linux-gnueabi-strip
> + /usr/lib/rpm/redhat/brp-strip-comment-note arm-iwmmxt-linux-gnueabi-strip arm-iwmmxt-linux-gnueabi-objdump
> +
> 
> and does not differ between target and native binaries.

Hm, OK. I suppose it doesn't hurt much. Updated patch then...

Index: binutils.spec
===================================================================
RCS file: /cvs/pkgs/rpms/binutils/F-9/binutils.spec,v
retrieving revision 1.132
diff -u -r1.132 binutils.spec
--- binutils.spec	8 Apr 2008 14:06:03 -0000	1.132
+++ binutils.spec	5 Jul 2008 14:51:20 -0000
@@ -1,5 +1,13 @@
+%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.18.50.0.6
 Release: 2
 License: GPLv3+
@@ -54,7 +62,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~
@@ -68,7 +76,7 @@
 %patch7 -p0 -b .version~
 %patch8 -p0 -b .pclmul~
 
-# 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*
@@ -80,24 +88,37 @@
 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}
+echo target is %{binutils_target}
+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="--target %{binutils_target} --enable-targets=%_host"
+   SYSROOT="--with-sysroot=/usr/%{binutils_target}/sys-root"
 %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 \
   --with-bugurl=http://bugzilla.redhat.com/bugzilla/
 make %{_smp_mflags} tooldir=%{_prefix} all
 make %{_smp_mflags} tooldir=%{_prefix} info
@@ -110,8 +131,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*
 
@@ -133,10 +155,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
@@ -154,22 +172,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
@@ -200,12 +232,14 @@
 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}/%{_lib}/lib*.so
 %{_infodir}/[^b]*info*
 %{_infodir}/binutils*info*
@@ -215,8 +249,12 @@
 %{_prefix}/include/*
 %{_prefix}/%{_lib}/lib*.a
 %{_infodir}/bfd*info*
+%endif # native
 
 %changelog
+* Sat Jul  5 2008 David Woodhouse <dwmw2 linux intel com> 2.18.50.0.6-3
+- Add %%{binutils_target} macro to support building cross-binutils
+
 * Tue Apr  8 2008 Jakub Jelinek <jakub redhat com> 2.18.50.0.6-2
 - backport .clmul -> .pclmul renaming
 


-- 
dwmw2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]