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