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