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