6b8093f98456147fefe1a6d6a8d7e74f0975fa5f
[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
10 BuildRequires:  zlib-devel-static
11 Requires(pre):  update-alternatives
12 Version:        2.24.90
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 -Wno-error"
109 RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS |sed -e 's/atom/i686/g'`
110 %if 0%{!?cross:1}
111 # Building native binutils
112 echo "Building native binutils." 
113 %if %build_multitarget
114 EXTRA_TARGETS="%(printf ,%%s-tizen-linux %target_list)"
115 EXTRA_TARGETS="$EXTRA_TARGETS,powerpc-macos,powerpc-macos10,spu-elf,x86_64-pep"
116 %else
117 EXTRA_TARGETS=
118 %ifarch sparc
119 EXTRA_TARGETS="$EXTRA_TARGETS,sparc64-tizen-linux"
120 %endif
121 %ifarch ppc
122 EXTRA_TARGETS="$EXTRA_TARGETS,powerpc64-tizen-linux"
123 %endif
124 %ifarch s390
125 EXTRA_TARGETS="$EXTRA_TARGETS,s390x-tizen-linux"
126 %endif
127 %ifarch s390x
128 EXTRA_TARGETS="$EXTRA_TARGETS,s390-tizen-linux"
129 %endif
130 %ifarch %ix86
131 EXTRA_TARGETS="$EXTRA_TARGETS,x86_64-tizen-linux"
132 %endif
133 %ifarch ppc ppc64
134 EXTRA_TARGETS="$EXTRA_TARGETS,spu-elf"
135 %endif
136 %ifarch %arm
137 EXTRA_TARGETS="$EXTRA_TARGETS,arm-tizen-linux-gnueabi"
138 %endif
139 %ifarch aarch64
140 EXTRA_TARGETS="$EXTRA_TARGETS,aarch64-tizen-linux"
141 %endif
142 %endif
143 %define common_flags CFLAGS="${RPM_OPT_FLAGS}" CXXFLAGS="${RPM_OPT_FLAGS}" \\\
144         --prefix=%{_prefix} --libdir=%{_libdir} \\\
145         --infodir=%{_infodir} --mandir=%{_mandir} \\\
146         --with-bugurl=http://bugs.opensuse.org/ \\\
147         --with-pkgversion="GNU Binutils; %{DIST}" \\\
148         --disable-nls \\\
149         --with-separate-debug-dir=%{_prefix}/lib/debug \\\
150         --with-pic --build=%{HOST} 
151 mkdir build-dir
152 cd build-dir
153
154 %ifarch %arm
155 export CONFIG_SHELL="/bin/bash"
156 export SHELL="/bin/bash"
157 %endif
158
159 ../configure %common_flags \
160         ${EXTRA_TARGETS:+--enable-targets="${EXTRA_TARGETS#,}"} \
161         --enable-plugins \
162 %ifarch %gold_archs
163         --enable-gold \
164 %endif
165         --enable-shared
166 make %{?_smp_mflags} all-bfd TARGET-bfd=headers
167 # force reconfiguring (???)
168 rm bfd/Makefile
169 make %{?_smp_mflags}
170
171 %else
172 # building cross-TARGET-binutils
173 echo "Building cross binutils." 
174 mkdir build-dir
175 cd build-dir
176 EXTRA_TARGETS=
177 %if "%{TARGET}" == "sparc"
178 EXTRA_TARGETS="$EXTRA_TARGETS,sparc64-tizen-linux"
179 %endif
180 %if "%{TARGET}" == "powerpc"
181 EXTRA_TARGETS="$EXTRA_TARGETS,powerpc64-tizen-linux"
182 %endif
183 %if "%{TARGET}" == "s390"
184 EXTRA_TARGETS="$EXTRA_TARGETS,s390x-tizen-linux"
185 %endif
186 %if "%{TARGET}" == "s390x"
187 EXTRA_TARGETS="$EXTRA_TARGETS,s390-tizen-linux"
188 %endif
189 %if "%{TARGET}" == "i586"
190 EXTRA_TARGETS="$EXTRA_TARGETS,x86_64-tizen-linux"
191 %endif
192 %if "%{TARGET}" == "hppa"
193 EXTRA_TARGETS="$EXTRA_TARGETS,hppa64-tizen-linux"
194 %endif
195 %if "%{TARGET}" == "arm"
196 EXTRA_TARGETS="$EXTRA_TARGETS,arm-tizen-linux-gnueabi"
197 %endif
198 %if "%{TARGET}" == "aarch64"
199 EXTRA_TARGETS="$EXTRA_TARGETS,aarch64-tizen-linux"
200 %endif
201 %if "%{TARGET}" == "avr" || "%{TARGET}" == "spu"
202 TARGET_OS=%{TARGET}
203 %else
204 %if "%{TARGET}" == "arm"
205 TARGET_OS=%{TARGET}-tizen-linux-gnueabi
206 %else
207 TARGET_OS=%{TARGET}-tizen-linux
208 %endif
209 %endif
210 ../configure CFLAGS="${RPM_OPT_FLAGS}" \
211   --enable-plugins \
212 %ifarch %gold_archs
213   --enable-gold \
214 %endif
215   --prefix=%{_prefix} \
216   --with-bugurl=http://bugs.opensuse.org/ \
217   --with-pkgversion="GNU Binutils; %{DIST}" \
218   --disable-nls \
219   --build=%{HOST} --target=$TARGET_OS \
220 %if "%{TARGET}" == "spu"
221   --with-sysroot=/usr/spu \
222 %else
223   --with-sysroot=%{_prefix}/$TARGET_OS/sys-root \
224 %endif
225   ${EXTRA_TARGETS:+--enable-targets="${EXTRA_TARGETS#,}"}
226 make %{?_smp_mflags} all-bfd TARGET-bfd=headers
227 # force reconfiguring
228 rm bfd/Makefile
229 make %{?_smp_mflags}
230 %if "%{TARGET}" == "avr"
231 # build an extra nesC version because nesC requires $'s in identifiers
232 cp -a gas gas-nesc
233 echo '#include "tc-%{TARGET}-nesc.h"' > gas-nesc/targ-cpu.h
234 make -C gas-nesc clean
235 make -C gas-nesc %{?_smp_mflags}
236 %endif
237 %endif
238
239 %check
240 unset LD_AS_NEEDED
241 cd build-dir
242 %if 0%{?cross:1}
243 make -k check CFLAGS="-O2 -g" CXXFLAGS="-O2 -g" || %{make_check_handling}
244 %else
245 make -k check CFLAGS="$RPM_OPT_FLAGS -Wno-unused -Wno-unprototyped-calls" || :
246 %endif
247
248 %install
249 cd build-dir
250 %if 0%{!?cross:1}
251 # installing native binutils
252 %ifarch %gold_archs
253 make DESTDIR=$RPM_BUILD_ROOT install-gold
254 ln -sf ld.gold $RPM_BUILD_ROOT%{_bindir}/gold
255 %endif
256
257 make DESTDIR=$RPM_BUILD_ROOT install-info install
258 make -C gas/doc DESTDIR=$RPM_BUILD_ROOT install-info-am install-am
259 make DESTDIR=$RPM_BUILD_ROOT install-bfd install-opcodes
260
261 if [ ! -f "%buildroot/%_bindir/ld.bfd" ]; then
262   mv "%buildroot/%_bindir"/{ld,ld.bfd};
263 else
264   rm -f "%buildroot/%_bindir/ld";
265 fi
266 mkdir -p "%buildroot/%_sysconfdir/alternatives";
267 ln -s "%_bindir/ld" "%buildroot/%_sysconfdir/alternatives/ld";
268 ln -s "%_sysconfdir/alternatives/ld" "%buildroot/%_bindir/ld";
269 rm -rf $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
270 mkdir -p $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
271 ln -sf ../../bin/{ar,as,ld,nm,ranlib,strip} $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
272 %ifarch %gold_archs
273 ln -sf ../../bin/ld.gold $RPM_BUILD_ROOT%{_prefix}/%{HOST}/bin
274 %endif
275
276 mv $RPM_BUILD_ROOT%{_prefix}/%{HOST}/lib/ldscripts $RPM_BUILD_ROOT%{_libdir}
277 ln -sf ../../%{_lib}/ldscripts $RPM_BUILD_ROOT%{_prefix}/%{HOST}/lib/ldscripts
278
279 # Install header files
280 make -C libiberty install_to_libdir target_header_dir=/usr/include DESTDIR=$RPM_BUILD_ROOT
281 # We want the PIC libiberty.a
282 install -m 644 libiberty/pic/libiberty.a $RPM_BUILD_ROOT%{_libdir}
283 #
284 chmod a+x $RPM_BUILD_ROOT%{_libdir}/libbfd-*
285 chmod a+x $RPM_BUILD_ROOT%{_libdir}/libopcodes-*
286 # No shared linking outside binutils
287 rm $RPM_BUILD_ROOT%{_libdir}/lib{bfd,opcodes}.so
288 rm $RPM_BUILD_ROOT%{_libdir}/lib{bfd,opcodes}.la
289 # Remove unwanted files to shut up rpm
290 rm $RPM_BUILD_ROOT%{_mandir}/man1/dlltool.1 $RPM_BUILD_ROOT%{_mandir}/man1/windres.1 $RPM_BUILD_ROOT%{_mandir}/man1/windmc.1
291 cd ..
292 #%find_lang binutils
293 #%find_lang bfd binutils.lang
294 #%find_lang gas binutils.lang
295 #%find_lang ld binutils.lang
296 #%find_lang opcodes binutils.lang
297 #%find_lang gprof binutils.lang
298 %ifarch %gold_archs
299 #%find_lang gold binutils-gold.lang
300 %endif
301 mkdir -p $RPM_BUILD_ROOT%{_docdir}/%{name}
302 install -m 644 binutils/NEWS $RPM_BUILD_ROOT%{_docdir}/%{name}/NEWS-binutils
303 install -m 644 gas/NEWS $RPM_BUILD_ROOT%{_docdir}/%{name}/NEWS-gas
304 install -m 644 ld/NEWS $RPM_BUILD_ROOT%{_docdir}/%{name}/NEWS-ld
305 %else
306 # installing cross-TARGET-binutils and TARGET-binutils
307 make DESTDIR=$RPM_BUILD_ROOT install
308 # Replace hard links by symlinks, so that rpmlint doesn't complain
309 T=$(basename %buildroot/usr/%{TARGET}*)
310 for f in %buildroot/usr/$T/bin/* ; do
311    ln -sf /usr/bin/$T-$(basename $f) $f
312 done
313 %if "%{TARGET}" == "avr"
314 install -c gas-nesc/as-new $RPM_BUILD_ROOT%{_prefix}/bin/%{TARGET}-nesc-as
315 ln -sf ../../bin/%{TARGET}-nesc-as $RPM_BUILD_ROOT%{_prefix}/%{TARGET}/bin/nesc-as
316 %endif
317 rm -rf $RPM_BUILD_ROOT%{_mandir}
318 rm -rf $RPM_BUILD_ROOT%{_infodir}
319 rm -rf $RPM_BUILD_ROOT%{_prefix}/lib*
320 rm -rf $RPM_BUILD_ROOT%{_prefix}/include
321 rm -f $RPM_BUILD_ROOT%{_prefix}/bin/*-c++filt
322 > ../binutils.lang
323 %endif
324 cd $RPM_BUILD_DIR/binutils-%version
325
326
327 %if 0%{!?cross:1}
328 %docs_package
329 %post
330 "%_sbindir/update-alternatives" --install \
331     "%_bindir/ld" ld "%_bindir/ld.bfd" 1
332
333 %post gold
334 "%_sbindir/update-alternatives" --install \
335     "%_bindir/ld" ld "%_bindir/ld.gold" 2
336
337
338 %preun
339 if [ "$1" = 0 ]; then
340     "%_sbindir/update-alternatives" --remove ld "%_bindir/ld.bfd";
341 fi;
342
343 %preun gold
344 if [ "$1" = 0 ]; then
345     "%_sbindir/update-alternatives" --remove ld "%_bindir/ld.gold";
346 fi;
347
348 %endif
349
350 %files 
351 %manifest %{name}.manifest
352 %defattr(-,root,root)
353 %if 0%{!?cross:1}
354 %{_docdir}/%{name}
355 %{_prefix}/%{HOST}/bin/*
356 %{_prefix}/%{HOST}/lib/ldscripts
357 %ghost %_sysconfdir/alternatives/ld
358 %{_libdir}/ldscripts
359 %{_bindir}/*
360 %ifarch %gold_archs
361 %exclude %{_bindir}/*gold
362 %endif
363 %doc %{_infodir}/*.gz
364 %{_libdir}/lib*-%{version}*.so
365 %else
366 %{_prefix}/%{TARGET}*
367 %{_prefix}/bin/*
368 %endif
369
370 %ifarch %gold_archs
371 %files gold 
372 %manifest %{name}.manifest
373 %defattr(-,root,root)
374 %{_bindir}/*gold
375 %if 0%{?cross:1}
376 %if "%{TARGET}" == "arm"
377 %{_prefix}/%{TARGET}-tizen-linux-gnueabi/bin/*gold
378 %else
379 %{_prefix}/%{TARGET}-tizen-linux/bin/*gold
380 %endif
381 %else
382 %{_prefix}/%{HOST}/bin/*gold
383 %endif
384 %endif
385
386 %if 0%{!?cross:1}
387 %files devel
388 %manifest %{name}.manifest
389 %defattr(-,root,root)
390 %{_prefix}/include/*.h
391 %{_libdir}/lib*.*a
392 %endif
393
394 %changelog