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