51b0c4e4e47f5c58a20231cf91967b8a921b6152
[platform/upstream/binutils.git] / packaging / cross-x86_64-binutils.spec
1 Name:         cross-x86_64-binutils
2 ExcludeArch: x86_64
3 %define cross 1
4 %define TARGET x86_64
5 BuildRequires:  bison
6 BuildRequires:  flex
7 BuildRequires:  gcc-c++
8 # for the testsuite
9 BuildRequires:  glibc-devel-static
10 # for some gold tests
11 BuildRequires:  bc
12 BuildRequires:  makeinfo
13 BuildRequires:  zlib-devel-static
14 Requires(pre):  update-alternatives
15 Version:        2.24.51
16 Release:        0
17 #
18 # RUN_TESTS
19 %define run_tests %(test ! -f %_sourcedir/RUN_TESTS ; echo $?)
20 # check the vanilla binutils, with no patches applied
21 # TEST_VANILLA
22 %define test_vanilla %(test ! -f %_sourcedir/TEST_VANILLA ; echo $?)
23 #
24 # handle test suite failures
25 #
26 %ifarch alpha %arm hppa mips sh4 %sparc
27 %define make_check_handling     true
28 %else
29 # XXX check again
30 # XXX disabled because gold is seriously broken for now
31 %define make_check_handling     true
32 %endif
33 # let make check fail anyway if RUN_TESTS was requested
34 %if %{run_tests}
35 %define make_check_handling     false
36 %endif
37 # handle all binary object formats supported by SuSE (and a few more)
38 %ifarch %ix86 %arm ia64 ppc ppc64 s390 s390x x86_64
39 %define build_multitarget 1
40 %else
41 %define build_multitarget 0
42 %endif
43 %define target_list alpha armv5l armv7l armv8l hppa hppa64 i686 ia64 m68k mips powerpc powerpc64 s390 s390x sh4 sparc sparc64 x86_64
44 #
45 #
46 #
47 Url:            http://www.gnu.org/software/binutils/
48 #%define binutils_version %(echo %version | sed 's/\\.[0-9]\\{8\\}$//')
49 Summary:        GNU Binutils
50 License:        GFDL-1.3 and GPL-3.0+
51 Group:          Development/Tools/Building
52 Source:         binutils-%{version}.tar.bz2
53 Source1:        pre_checkin.sh
54 Source3:        baselibs.conf
55
56 %description
57 C compiler utilities: ar, as, gprof, ld, nm, objcopy, objdump, ranlib,
58 size, strings, and strip. These utilities are needed whenever you want
59 to compile a program or kernel.
60
61
62 %package gold
63 Summary:        The gold linker
64 License:        GPL-3.0+
65 Group:          Development/Tools/Building
66 Requires:       binutils = %{version}-%{release}
67 %if 0%{!?cross:1}
68 %define gold_archs %ix86 %arm x86_64 ppc ppc64 %sparc
69 %endif
70
71 %description gold
72 gold is an ELF linker.  It is intended to have complete support for ELF
73 and to run as fast as possible on modern systems.  For normal use it is
74 a drop-in replacement for the older GNU linker.
75
76
77 %package devel
78 Summary:        GNU binutils (BFD development files)
79 License:        GPL-3.0+
80 Group:          Development/Libraries/C and C++
81 Requires:       binutils = %{version}-%{release}
82 Requires:       zlib-devel
83 Provides:       binutils:/usr/include/bfd.h
84
85 %description devel
86 This package includes header files and static libraries necessary to
87 build programs which use the GNU BFD library, which is part of
88 binutils.
89
90
91 %ifarch %arm
92 %define HOST %{_target_cpu}-tizen-linux-gnueabi
93 %else
94 %define HOST %(echo %{_target_cpu} | sed -e "s/parisc/hppa/" -e "s/i.86/i586/" -e "s/ppc/powerpc/" -e "s/sparc64v.*/sparc64/" -e "s/sparcv.*/sparc/")-tizen-linux
95 %endif 
96 %define DIST %(echo '%distribution' | sed 's/ (.*)//')
97
98 %prep
99 echo "make check will return with %{make_check_handling} in case of testsuite failures."
100 %setup -q -n binutils-%{version}
101
102 sed -i -e '/BFD_VERSION_DATE/s/$/-%(echo %release | sed 's/\.[0-9]*$//')/' bfd/version.h
103 %build
104 RPM_OPT_FLAGS="$RPM_OPT_FLAGS -Wno-error"
105 RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS |sed -e 's/atom/i686/g'`
106 %if 0%{!?cross:1}
107 # Building native binutils
108 echo "Building native binutils." 
109 %if %build_multitarget
110 EXTRA_TARGETS="%(printf ,%%s-tizen-linux %target_list)"
111 EXTRA_TARGETS="$EXTRA_TARGETS,powerpc-macos,powerpc-macos10,spu-elf,x86_64-pep"
112 %else
113 EXTRA_TARGETS=
114 %ifarch sparc
115 EXTRA_TARGETS="$EXTRA_TARGETS,sparc64-tizen-linux"
116 %endif
117 %ifarch ppc
118 EXTRA_TARGETS="$EXTRA_TARGETS,powerpc64-tizen-linux"
119 %endif
120 %ifarch s390
121 EXTRA_TARGETS="$EXTRA_TARGETS,s390x-tizen-linux"
122 %endif
123 %ifarch s390x
124 EXTRA_TARGETS="$EXTRA_TARGETS,s390-tizen-linux"
125 %endif
126 %ifarch %ix86
127 EXTRA_TARGETS="$EXTRA_TARGETS,x86_64-tizen-linux"
128 %endif
129 %ifarch ppc ppc64
130 EXTRA_TARGETS="$EXTRA_TARGETS,spu-elf"
131 %endif
132 %ifarch %arm
133 EXTRA_TARGETS="$EXTRA_TARGETS,arm-tizen-linux-gnueabi"
134 %endif
135 %endif
136 %define common_flags CFLAGS="${RPM_OPT_FLAGS}" CXXFLAGS="${RPM_OPT_FLAGS}" \\\
137         --prefix=%{_prefix} --libdir=%{_libdir} \\\
138         --infodir=%{_infodir} --mandir=%{_mandir} \\\
139         --with-bugurl=http://bugs.opensuse.org/ \\\
140         --with-pkgversion="GNU Binutils; %{DIST}" \\\
141         --disable-nls \\\
142         --with-separate-debug-dir=%{_prefix}/lib/debug \\\
143         --with-pic --build=%{HOST} 
144 mkdir build-dir
145 cd build-dir
146 ../configure %common_flags \
147         ${EXTRA_TARGETS:+--enable-targets="${EXTRA_TARGETS#,}"} \
148         --enable-plugins \
149 %ifarch %gold_archs
150         --enable-gold \
151 %endif
152         --enable-shared
153 make %{?_smp_mflags} all-bfd TARGET-bfd=headers
154 # force reconfiguring (???)
155 rm bfd/Makefile
156 make %{?_smp_mflags}
157
158 %else
159 # building cross-TARGET-binutils
160 echo "Building cross binutils." 
161 mkdir build-dir
162 cd build-dir
163 EXTRA_TARGETS=
164 %if "%{TARGET}" == "sparc"
165 EXTRA_TARGETS="$EXTRA_TARGETS,sparc64-tizen-linux"
166 %endif
167 %if "%{TARGET}" == "powerpc"
168 EXTRA_TARGETS="$EXTRA_TARGETS,powerpc64-tizen-linux"
169 %endif
170 %if "%{TARGET}" == "s390"
171 EXTRA_TARGETS="$EXTRA_TARGETS,s390x-tizen-linux"
172 %endif
173 %if "%{TARGET}" == "s390x"
174 EXTRA_TARGETS="$EXTRA_TARGETS,s390-tizen-linux"
175 %endif
176 %if "%{TARGET}" == "i586"
177 EXTRA_TARGETS="$EXTRA_TARGETS,x86_64-tizen-linux"
178 %endif
179 %if "%{TARGET}" == "hppa"
180 EXTRA_TARGETS="$EXTRA_TARGETS,hppa64-tizen-linux"
181 %endif
182 %if "%{TARGET}" == "arm"
183 EXTRA_TARGETS="$EXTRA_TARGETS,arm-tizen-linux-gnueabi"
184 %endif
185 %if "%{TARGET}" == "avr" || "%{TARGET}" == "spu"
186 TARGET_OS=%{TARGET}
187 %else
188 %if "%{TARGET}" == "arm"
189 TARGET_OS=%{TARGET}-tizen-linux-gnueabi
190 %else
191 TARGET_OS=%{TARGET}-tizen-linux
192 %endif
193 %endif
194 ../configure CFLAGS="${RPM_OPT_FLAGS}" \
195   --prefix=%{_prefix} \
196   --with-bugurl=http://bugs.opensuse.org/ \
197   --with-pkgversion="GNU Binutils; %{DIST}" \
198   --disable-nls \
199   --build=%{HOST} --target=$TARGET_OS \
200 %if "%{TARGET}" == "spu"
201   --with-sysroot=/usr/spu \
202 %else
203   --with-sysroot=%{_prefix}/$TARGET_OS/sys-root \
204 %endif
205   ${EXTRA_TARGETS:+--enable-targets="${EXTRA_TARGETS#,}"}
206 make %{?_smp_mflags} all-bfd TARGET-bfd=headers
207 # force reconfiguring
208 rm bfd/Makefile
209 make %{?_smp_mflags}
210 %if "%{TARGET}" == "avr"
211 # build an extra nesC version because nesC requires $'s in identifiers
212 cp -a gas gas-nesc
213 echo '#include "tc-%{TARGET}-nesc.h"' > gas-nesc/targ-cpu.h
214 make -C gas-nesc clean
215 make -C gas-nesc %{?_smp_mflags}
216 %endif
217 %endif
218
219 %check
220 unset LD_AS_NEEDED
221 cd build-dir
222 %if 0%{?cross:1}
223 make -k check CFLAGS="-O2 -g" CXXFLAGS="-O2 -g" || %{make_check_handling}
224 %else
225 make -k check CFLAGS="$RPM_OPT_FLAGS -Wno-unused -Wno-unprototyped-calls" || :
226 %endif
227
228 %install
229 cd build-dir
230 %if 0%{!?cross:1}
231 # installing native binutils
232 %ifarch %gold_archs
233 make DESTDIR=$RPM_BUILD_ROOT install-gold
234 ln -sf ld.gold $RPM_BUILD_ROOT%{_bindir}/gold
235 %endif
236 make DESTDIR=$RPM_BUILD_ROOT install-info install
237 make -C gas/doc DESTDIR=$RPM_BUILD_ROOT install-info-am install-am
238 make DESTDIR=$RPM_BUILD_ROOT install-bfd install-opcodes
239
240 if [ ! -f "%buildroot/%_bindir/ld.bfd" ]; then
241   mv "%buildroot/%_bindir"/{ld,ld.bfd};
242 else
243   rm -f "%buildroot/%_bindir/ld";
244 fi
245 mkdir -p "%buildroot/%_sysconfdir/alternatives";
246 ln -s "%_bindir/ld" "%buildroot/%_sysconfdir/alternatives/ld";
247 ln -s "%_sysconfdir/alternatives/ld" "%buildroot/%_bindir/ld";
248 rm -rf $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
249 mkdir -p $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
250 ln -sf ../../bin/{ar,as,ld,nm,ranlib,strip} $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
251
252 mv $RPM_BUILD_ROOT%{_prefix}/%{HOST}/lib/ldscripts $RPM_BUILD_ROOT%{_libdir}
253 ln -sf ../../%{_lib}/ldscripts $RPM_BUILD_ROOT%{_prefix}/%{HOST}/lib/ldscripts
254
255 # Install header files
256 make -C libiberty install_to_libdir target_header_dir=/usr/include DESTDIR=$RPM_BUILD_ROOT
257 # We want the PIC libiberty.a
258 install -m 644 libiberty/pic/libiberty.a $RPM_BUILD_ROOT%{_libdir}
259 #
260 chmod a+x $RPM_BUILD_ROOT%{_libdir}/libbfd-*
261 chmod a+x $RPM_BUILD_ROOT%{_libdir}/libopcodes-*
262 # No shared linking outside binutils
263 rm $RPM_BUILD_ROOT%{_libdir}/lib{bfd,opcodes}.so
264 rm $RPM_BUILD_ROOT%{_libdir}/lib{bfd,opcodes}.la
265 # Remove unwanted files to shut up rpm
266 rm $RPM_BUILD_ROOT%{_infodir}/configure* $RPM_BUILD_ROOT%{_infodir}/standards.info*
267 rm $RPM_BUILD_ROOT%{_mandir}/man1/dlltool.1 $RPM_BUILD_ROOT%{_mandir}/man1/windres.1 $RPM_BUILD_ROOT%{_mandir}/man1/windmc.1
268 cd ..
269 #%find_lang binutils
270 #%find_lang bfd binutils.lang
271 #%find_lang gas binutils.lang
272 #%find_lang ld binutils.lang
273 #%find_lang opcodes binutils.lang
274 #%find_lang gprof binutils.lang
275 %ifarch %gold_archs
276 #%find_lang gold binutils-gold.lang
277 %endif
278 mkdir -p $RPM_BUILD_ROOT%{_docdir}/%{name}
279 install -m 644 binutils/NEWS $RPM_BUILD_ROOT%{_docdir}/%{name}/NEWS-binutils
280 install -m 644 gas/NEWS $RPM_BUILD_ROOT%{_docdir}/%{name}/NEWS-gas
281 install -m 644 ld/NEWS $RPM_BUILD_ROOT%{_docdir}/%{name}/NEWS-ld
282 %else
283 # installing cross-TARGET-binutils and TARGET-binutils
284 make DESTDIR=$RPM_BUILD_ROOT install
285 # Replace hard links by symlinks, so that rpmlint doesn't complain
286 T=$(basename %buildroot/usr/%{TARGET}*)
287 for f in %buildroot/usr/$T/bin/* ; do
288    ln -sf /usr/bin/$T-$(basename $f) $f
289 done
290 %if "%{TARGET}" == "avr"
291 install -c gas-nesc/as-new $RPM_BUILD_ROOT%{_prefix}/bin/%{TARGET}-nesc-as
292 ln -sf ../../bin/%{TARGET}-nesc-as $RPM_BUILD_ROOT%{_prefix}/%{TARGET}/bin/nesc-as
293 %endif
294 rm -rf $RPM_BUILD_ROOT%{_mandir}
295 rm -rf $RPM_BUILD_ROOT%{_infodir}
296 rm -rf $RPM_BUILD_ROOT%{_prefix}/lib*
297 rm -rf $RPM_BUILD_ROOT%{_prefix}/include
298 rm -f $RPM_BUILD_ROOT%{_prefix}/bin/*-c++filt
299 > ../binutils.lang
300 %endif
301 cd $RPM_BUILD_DIR/binutils-%version
302
303
304 %if 0%{!?cross:1}
305 %docs_package
306 %post
307 "%_sbindir/update-alternatives" --install \
308     "%_bindir/ld" ld "%_bindir/ld.bfd" 1
309
310 %post gold
311 "%_sbindir/update-alternatives" --install \
312     "%_bindir/ld" ld "%_bindir/ld.gold" 2
313
314
315 %preun
316 if [ "$1" = 0 ]; then
317     "%_sbindir/update-alternatives" --remove ld "%_bindir/ld.bfd";
318 fi;
319
320 %preun gold
321 if [ "$1" = 0 ]; then
322     "%_sbindir/update-alternatives" --remove ld "%_bindir/ld.gold";
323 fi;
324
325 %endif
326
327 %files 
328 %defattr(-,root,root)
329 %if 0%{!?cross:1}
330 %{_docdir}/%{name}
331 %{_prefix}/%{HOST}/bin/*
332 %{_prefix}/%{HOST}/lib/ldscripts
333 %ghost %_sysconfdir/alternatives/ld
334 %{_libdir}/ldscripts
335 %{_bindir}/*
336 %ifarch %gold_archs
337 %exclude %{_bindir}/gold
338 %exclude %{_bindir}/ld.gold
339 %endif
340 %doc %{_infodir}/*.gz
341 %{_libdir}/lib*-%{version}*.so
342 %else
343 %{_prefix}/%{TARGET}*
344 %{_prefix}/bin/*
345 %endif
346
347 %ifarch %gold_archs
348 %files gold 
349 %defattr(-,root,root)
350 %{_bindir}/gold
351 %{_bindir}/ld.gold
352 %endif
353
354 %if 0%{!?cross:1}
355 %files devel
356 %defattr(-,root,root)
357 %{_prefix}/include/*.h
358 %{_libdir}/lib*.*a
359 %endif
360
361 %changelog