Annotation of /trunk/include/cross_tools.sminc
Parent Directory | Revision Log
Revision 9880 -
(hide annotations)
(download)
Sat Jan 14 01:48:34 2012 UTC (12 years, 10 months ago) by niro
File size: 12545 byte(s)
Sat Jan 14 01:48:34 2012 UTC (12 years, 10 months ago) by niro
File size: 12545 byte(s)
-imported from magellan-next
1 | niro | 11 | # $Header: /magellan-cvs/smage/include/cross_tools.sminc,v 1.3 2008/10/06 17:55:48 niro Exp $ |
2 | niro | 2 | # Cross-tools generic functions |
3 | |||
4 | niro | 11 | # needed vars: |
5 | # TARGET_DEST dir | ||
6 | : ${TARGET_DEST="/opt/cross-tools"} | ||
7 | niro | 2 | |
8 | niro | 11 | # needed vars |
9 | #TARGET_ARCH="i686" # must be set outside | ||
10 | : ${CROSS_CHOST="${ARCH}-cross-linux-gnu"} | ||
11 | : ${TARGET_CHOST="${TARGET_ARCH}-pc-linux-gnu"} | ||
12 | |||
13 | : ${PNAME="cross-tools-${TARGET_ARCH}"} | ||
14 | |||
15 | niro | 9863 | : ${PCAT="dev-cross"} |
16 | niro | 11 | |
17 | : ${DESCRIPTION="A crosscompile toolchain to compile programms for the ${TARGET_ARCH} arch."} | ||
18 | : ${HOMEPAGE="http://magellan-linux.de/"} | ||
19 | |||
20 | # binutils | ||
21 | #BINUTILS_PVER="2.16.91.0.3" | ||
22 | : ${BINUTILS_SRCFILE="binutils-${BINUTILS_PVER}.tar.bz2"} | ||
23 | : ${BINUTILS_SRCDIR="${BUILDDIR}/binutils-${BINUTILS_PVER}"} | ||
24 | |||
25 | # kernel-headers | ||
26 | #LINUX_HEADERS_PVER="2.6.12.0" | ||
27 | : ${LINUX_HEADERS_SRCFILE="linux-${LINUX_HEADERS_PVER}.tar.bz2"} | ||
28 | : ${LINUX_HEADERS_SRCDIR="${BUILDDIR}/linux-${LINUX_HEADERS_PVER}"} | ||
29 | |||
30 | # glibc-headers and libc | ||
31 | #GLIBC_PVER="2.3.5_20051107" | ||
32 | : ${GLIBC_SRCFILE="glibc-${GLIBC_PVER}.tar.bz2"} | ||
33 | #: ${GLIBC_LINUXTHREADS="glibc-linuxthreads-${GLIBC_PVER}.tar.bz2"} | ||
34 | : ${GLIBC_SRCDIR="${BUILDDIR}/glibc-${GLIBC_PVER}"} | ||
35 | |||
36 | # gcc | ||
37 | #GCC_PVER="${PVER}" | ||
38 | : ${GCC_SRCFILE="gcc-${GCC_PVER}.tar.bz2"} | ||
39 | : ${GCC_SRCDIR="${BUILDDIR}/gcc-${GCC_PVER}"} | ||
40 | |||
41 | niro | 2 | # do not get the idea to strip the resulting binaries! |
42 | # you must have build the strip program on the same arch, | ||
43 | # but this is propably not the case. so we force stripping off. | ||
44 | NOSTRIP=true | ||
45 | |||
46 | niro | 11 | # fetch sources |
47 | SRC_URI=( | ||
48 | ${SRC_URI[*]} | ||
49 | http://www.kernel.org/pub/linux/devel/binutils/${BINUTILS_SRCFILE} | ||
50 | mirror://binutils/${BINUTILS_SRCFILE} | ||
51 | http://www.kernel.org/pub/linux/kernel/v${LINUX_HEADERS_PVER:0:3}/${LINUX_HEADERS_SRCFILE} | ||
52 | mirror://linux-libc-headers/${LINUX_HEADERS_SRCFILE} | ||
53 | gnu://glibc/${GLIBC_SRCFILE} | ||
54 | mirror://glibc/${GLIBC_SRCFILE} | ||
55 | gnu://gcc/gcc-${GCC_PVER}/${GCC_SRCFILE} | ||
56 | mirror://gcc/${GCC_SRCFILE} | ||
57 | mirror://glibc/glibc-2.3.5-localedef_segfault-1.patch | ||
58 | mirror://glibc/glibc-2.3.5-libgcc_eh-1.patch | ||
59 | mirror://gcc/gcc-${GCC_PVER}-no-fixincludes.patch | ||
60 | mirror://gcc/gcc-${GCC_PVER}-magellan-version.patch | ||
61 | mirror://gcc/gcc-${GCC_PVER}-cross-search-paths.patch | ||
62 | mirror://gcc/gcc-${GCC_PVER}-specs.patch | ||
63 | ) | ||
64 | |||
65 | niro | 2 | binutils_src_prepare() |
66 | { | ||
67 | munpack ${BINUTILS_SRCFILE} || die | ||
68 | install -d ${BINUTILS_SRCDIR}/build || die | ||
69 | } | ||
70 | |||
71 | binutils_src_compile() | ||
72 | { | ||
73 | cd ${BINUTILS_SRCDIR}/build | ||
74 | |||
75 | niro | 11 | AR=ar AS=as \ |
76 | niro | 2 | ../configure \ |
77 | niro | 11 | --host=${CROSS_CHOST} \ |
78 | niro | 2 | --target=${TARGET_CHOST} \ |
79 | --prefix=${TARGET_DEST} \ | ||
80 | --with-lib-path=${TARGET_DEST}/lib \ | ||
81 | --disable-nls \ | ||
82 | --enable-shared \ | ||
83 | niro | 11 | --disable-multilib \ |
84 | niro | 2 | || die |
85 | |||
86 | make configure-host || die | ||
87 | mmake || die | ||
88 | } | ||
89 | |||
90 | binutils_src_install() | ||
91 | { | ||
92 | cd ${BINUTILS_SRCDIR}/build | ||
93 | |||
94 | make install || die | ||
95 | |||
96 | install -d ${TARGET_DEST}/include || die | ||
97 | cp ../include/libiberty.h ${TARGET_DEST}/include || die | ||
98 | } | ||
99 | |||
100 | linux_headers_src_prepare() | ||
101 | { | ||
102 | munpack ${LINUX_HEADERS_SRCFILE} || die | ||
103 | niro | 11 | } |
104 | |||
105 | linux_headers_src_compile() | ||
106 | { | ||
107 | niro | 2 | cd ${LINUX_HEADERS_SRCDIR} |
108 | niro | 11 | make mrproper || die |
109 | make ARCH=${ARCH/i*86/x86} headers_check || die | ||
110 | niro | 2 | } |
111 | |||
112 | linux_headers_src_install() | ||
113 | { | ||
114 | cd ${LINUX_HEADERS_SRCDIR} | ||
115 | niro | 11 | make ARCH=${ARCH/i*86/x86} INSTALL_HDR_PATH=${BINDIR}/${TARGET_DEST} headers_install || die |
116 | niro | 2 | } |
117 | |||
118 | # building the glibc-headers | ||
119 | glibc_headers_src_prepare() | ||
120 | { | ||
121 | glibc_generic_src_prepare | ||
122 | cd ${GLIBC_SRCDIR}/build | ||
123 | |||
124 | # remove gcc dependencies | ||
125 | sed -i 's/3.4/3.[0-9]/g' ../configure || die | ||
126 | } | ||
127 | |||
128 | glibc_headers_src_compile() | ||
129 | { | ||
130 | cd ${GLIBC_SRCDIR}/build | ||
131 | |||
132 | # do not enable addons here | ||
133 | ../configure \ | ||
134 | --host=${CHOST} \ | ||
135 | --target=${TARGET_CHOST} \ | ||
136 | --prefix=${TARGET_DEST} \ | ||
137 | --enable-kernel=2.6.0 \ | ||
138 | --without-cvs \ | ||
139 | --with-headers=${TARGET_DEST}/include \ | ||
140 | --with-binutils=${TARGET_DEST}/${TARGET_CHOST}/bin \ | ||
141 | --disable-sanity-checks \ | ||
142 | --disable-nls \ | ||
143 | || die | ||
144 | } | ||
145 | |||
146 | glibc_headers_src_install() | ||
147 | { | ||
148 | cd ${GLIBC_SRCDIR}/build | ||
149 | make install-headers || die | ||
150 | |||
151 | # needed directories | ||
152 | install -d ${TARGET_DEST}/include/{bits,gnu} || die | ||
153 | |||
154 | # using correct arch | ||
155 | local myarch=${TARGET_ARCH} | ||
156 | [[ ${myarch} = i?86 ]] && myarch=i386 | ||
157 | |||
158 | # missing headers | ||
159 | cp bits/stdio_lim.h ${TARGET_DEST}/include/bits || die | ||
160 | touch ${TARGET_DEST}/include/gnu/stubs.h || die | ||
161 | cp ../nptl/sysdeps/pthread/pthread.h ${TARGET_DEST}/include || die | ||
162 | cp ../nptl/sysdeps/unix/sysv/linux/${myarch}/bits/pthreadtypes.h \ | ||
163 | ${TARGET_DEST}/include || die | ||
164 | } | ||
165 | |||
166 | # generic glibc unpack | ||
167 | glibc_generic_src_prepare() | ||
168 | { | ||
169 | munpack ${GLIBC_SRCFILE} || die | ||
170 | cd ${GLIBC_SRCDIR} | ||
171 | |||
172 | # disable binutils -as-needed | ||
173 | sed -i 's/^have-as-needed.*/have-as-needed = no/' \ | ||
174 | ${GLIBC_SRCDIR}/config.make.in || die | ||
175 | |||
176 | niro | 11 | # fix segfault of localdef on arches beside x86-32 |
177 | mpatch glibc-2.3.5-localedef_segfault-1.patch || die | ||
178 | |||
179 | niro | 2 | # fix permissions on some of the scripts |
180 | chmod u+x ${GLIBC_SRCDIR}/scripts/*.sh || die | ||
181 | |||
182 | install -d ${GLIBC_SRCDIR}/build || die | ||
183 | } | ||
184 | |||
185 | # final glibc | ||
186 | glibc_src_prepare() | ||
187 | { | ||
188 | glibc_generic_src_prepare | ||
189 | niro | 11 | cd ${GLIBC_SRCDIR} |
190 | |||
191 | # remove dependencies on libgcc_eh | ||
192 | mpatch glibc-2.3.5-libgcc_eh-1.patch || die | ||
193 | niro | 2 | } |
194 | |||
195 | glibc_src_compile() | ||
196 | { | ||
197 | cd ${GLIBC_SRCDIR}/build | ||
198 | |||
199 | niro | 11 | local my_glibc_CFLAGS |
200 | local my_glibc_CXXFLAGS | ||
201 | # glibc-2.6.1 and above needs march CFLAGS: -march=${ARCH} -mtune=generic | ||
202 | [[ ${TARGET_ARCH} = i*86 ]] && my_glibc_CFLAGS="${CFLAGS} -march=${TARGET_ARCH}" # only i*86 | ||
203 | my_glibc_CFLAGS="${my_glibc_CFLAGS} -mtune=generic" # all arches | ||
204 | |||
205 | niro | 2 | # force nptl support (may not detected always) |
206 | echo "libc_cv_forced_unwind=yes" > config.cache || die | ||
207 | echo "libc_cv_c_cleanup=yes" >> config.cache || die | ||
208 | |||
209 | BUILD_CC="gcc" \ | ||
210 | niro | 11 | CC="${TARGET_CHOST}-gcc" \ |
211 | niro | 2 | AR="${TARGET_CHOST}-ar" \ |
212 | RANLIB="${TARGET_CHOST}-ranlib" \ | ||
213 | niro | 11 | CFLAGS="${my_glibc_CFLAGS}" \ |
214 | niro | 2 | ../configure \ |
215 | --host=${TARGET_CHOST} \ | ||
216 | niro | 11 | --build=${CROSS_CHOST} \ |
217 | niro | 2 | --prefix=${TARGET_DEST} \ |
218 | --disable-profile \ | ||
219 | --enable-add-ons=nptl --with-tls \ | ||
220 | --with-__thread \ | ||
221 | --enable-kernel=2.6.0 \ | ||
222 | --without-cvs \ | ||
223 | --with-headers=${TARGET_DEST}/include \ | ||
224 | niro | 11 | --with-binutils=${TARGET_DEST}/bin \ |
225 | niro | 2 | --cache-file=config.cache \ |
226 | || die | ||
227 | |||
228 | make PARALLELMFLAGS="-j2" || die | ||
229 | } | ||
230 | |||
231 | glibc_src_install() | ||
232 | { | ||
233 | cd ${GLIBC_SRCDIR}/build | ||
234 | make install || die | ||
235 | } | ||
236 | |||
237 | # static gcc, only c | ||
238 | gcc_static_src_prepare() | ||
239 | { | ||
240 | gcc_generic_src_prepare | ||
241 | } | ||
242 | |||
243 | gcc_static_src_compile() | ||
244 | { | ||
245 | cd ${GCC_SRCDIR}/build | ||
246 | |||
247 | ../configure \ | ||
248 | niro | 11 | --host=${CROSS_CHOST} \ |
249 | niro | 2 | --target=${TARGET_CHOST} \ |
250 | --prefix=${TARGET_DEST} \ | ||
251 | --with-local-prefix=${TARGET_DEST} \ | ||
252 | --disable-nls \ | ||
253 | --disable-shared \ | ||
254 | --disable-threads \ | ||
255 | --enable-languages=c \ | ||
256 | --disable-multilib \ | ||
257 | || die | ||
258 | |||
259 | mmake all-gcc || die | ||
260 | } | ||
261 | |||
262 | gcc_static_src_install() | ||
263 | { | ||
264 | cd ${GCC_SRCDIR}/build | ||
265 | make install-gcc || die | ||
266 | } | ||
267 | |||
268 | # final gcc, c and c++ | ||
269 | gcc_src_prepare() | ||
270 | { | ||
271 | gcc_generic_src_prepare | ||
272 | cd ${GCC_SRCDIR} | ||
273 | |||
274 | # disable -B in configure, so it doesn't pick up the host's header files | ||
275 | sed -i '/FLAGS_FOR_TARGET.*\/lib\//s@-B[^ ]*/lib/@@g' configure || die | ||
276 | } | ||
277 | |||
278 | gcc_src_compile() | ||
279 | { | ||
280 | cd ${GCC_SRCDIR}/build | ||
281 | |||
282 | ../configure \ | ||
283 | --host=${CHOST} \ | ||
284 | --target=${TARGET_CHOST} \ | ||
285 | --prefix=${TARGET_DEST} \ | ||
286 | --with-local-prefix=${TARGET_DEST} \ | ||
287 | --enable-shared \ | ||
288 | --enable-threads=posix \ | ||
289 | --enable-__cxa_atexit \ | ||
290 | --enable-c99 \ | ||
291 | --enable-long-long \ | ||
292 | --enable-languages=c,c++ \ | ||
293 | --disable-nls \ | ||
294 | --disable-multilib \ | ||
295 | || die | ||
296 | #--with-system-zlib \ | ||
297 | #--enable-clocale=gnu \ | ||
298 | #--disable-checking \ | ||
299 | #--disable-libunwind-exceptions \ | ||
300 | #--enable-cstdio=stdio \ | ||
301 | |||
302 | make \ | ||
303 | AS_FOR_TARGET="${TARGET_DEST}/bin/${TARGET_CHOST}-as" \ | ||
304 | LD_FOR_TARGET="${TARGET_DEST}/bin/${TARGET_CHOST}-ld" \ | ||
305 | || die | ||
306 | } | ||
307 | |||
308 | gcc_src_install() | ||
309 | { | ||
310 | cd ${GCC_SRCDIR}/build | ||
311 | make install || die | ||
312 | } | ||
313 | |||
314 | gcc_generic_src_prepare() | ||
315 | { | ||
316 | munpack ${GCC_SRCFILE} || die | ||
317 | cd ${GCC_SRCDIR} | ||
318 | |||
319 | niro | 11 | mpatch gcc-${GCC_PVER}-no-fixincludes.patch || die |
320 | mpatch gcc-${GCC_PVER}-magellan-version.patch || die | ||
321 | |||
322 | # fixes location of the dynamic linker and not append include | ||
323 | # search path to /usr/include | ||
324 | # but first set the location to ${TARGET_DEST} and than patch | ||
325 | sed "s:/tools/lib/:${TARGET_DEST}/lib/:g" \ | ||
326 | ${SOURCEDIR}/${PNAME}/gcc-${GCC_PVER}-specs.patch | patch -Np1 || die | ||
327 | |||
328 | # do not search the /usr directory for libgcc_s.so when cross-compiling | ||
329 | mpatch gcc-${GCC_PVER}-cross-search-paths.patch || die | ||
330 | |||
331 | niro | 2 | # suppress installation of libiberty, as we will be |
332 | # using the one from binutils | ||
333 | #sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in || die | ||
334 | |||
335 | # fix up the startfile spec to search /opt/cross-tools/lib | ||
336 | # fixes errors like this on the final cross-gcc compilation | ||
337 | # /opt/cross-tools/i686-cross-linux-gnu/bin/ld: crti.o: No such file: No such file or directory | ||
338 | # collect2: ld returned 1 exit status | ||
339 | echo " | ||
340 | #undef STARTFILE_PREFIX_SPEC | ||
341 | #define STARTFILE_PREFIX_SPEC \"${TARGET_DEST}/lib/\"" >> ${GCC_SRCDIR}/gcc/config/linux.h || die | ||
342 | |||
343 | # change header search path to look only in $TARGET_DEST/include | ||
344 | # and not the hosts own include pathes | ||
345 | sed -i "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 ${TARGET_DEST}/include@g" \ | ||
346 | ${GCC_SRCDIR}/gcc/Makefile.in || die | ||
347 | |||
348 | install -d ${GCC_SRCDIR}/build || die | ||
349 | } | ||
350 | |||
351 | cross_tools_src_prepare() | ||
352 | { | ||
353 | if [[ -e ${TARGET_DEST} ]] || [[ -L ${TARGET_DEST} ]] | ||
354 | then | ||
355 | echo | ||
356 | echo "Please uninstall any cross-tools packages first." | ||
357 | echo "To build the tools I'll create a fake symlink to ${TARGET_DEST}," | ||
358 | echo "so this directory must not exist." | ||
359 | echo | ||
360 | die "${TARGET_DEST} exists." | ||
361 | fi | ||
362 | |||
363 | if [[ ${CHOST} = ${TARGET_CHOST} ]] | ||
364 | then | ||
365 | echo | ||
366 | echo "\$CHOST and \$TARGET_CHOST have the same values." | ||
367 | echo " CHOST=${CHOST}" | ||
368 | echo " TARGET_CHOST=${TARGET_CHOST}" | ||
369 | echo | ||
370 | echo "You cannot build a cross-compiler with these settings," | ||
371 | echo "please use the native gcc-\${ARCH} builds." | ||
372 | echo | ||
373 | die "\$CHOST equal \$TARGET_CHOST." | ||
374 | fi | ||
375 | |||
376 | # create a fake build-root | ||
377 | install -d ${BINDIR}/${TARGET_DEST} || die | ||
378 | ln -snf ${BINDIR}/${TARGET_DEST} ${TARGET_DEST} || die | ||
379 | } | ||
380 | |||
381 | cross_tools_src_compile() | ||
382 | { | ||
383 | # setup a proper build environment | ||
384 | export PATH=${TARGET_DEST}/bin:${PATH} | ||
385 | |||
386 | ############################## | ||
387 | # first of all build binutils# | ||
388 | ############################## | ||
389 | binutils_src_prepare | ||
390 | binutils_src_compile | ||
391 | binutils_src_install | ||
392 | |||
393 | |||
394 | ################################# | ||
395 | # now install the linux-headers # | ||
396 | ################################# | ||
397 | linux_headers_src_prepare | ||
398 | niro | 11 | linux_headers_src_compile |
399 | niro | 2 | linux_headers_src_install |
400 | |||
401 | |||
402 | ############################ | ||
403 | # create the glibc-headers # | ||
404 | ############################ | ||
405 | glibc_headers_src_prepare | ||
406 | glibc_headers_src_compile | ||
407 | glibc_headers_src_install | ||
408 | |||
409 | # remove GLIBC_SRCDIR | ||
410 | rm -rf ${GLIBC_SRCDIR} || die | ||
411 | |||
412 | |||
413 | ############################## | ||
414 | # build a static minimal gcc # | ||
415 | ############################## | ||
416 | gcc_static_src_prepare | ||
417 | gcc_static_src_compile | ||
418 | gcc_static_src_install | ||
419 | |||
420 | # remove GCC_SRCDIR | ||
421 | rm -rf ${GCC_SRCDIR} || die | ||
422 | |||
423 | |||
424 | ################################ | ||
425 | # build the final cross-glibc # | ||
426 | ################################ | ||
427 | glibc_src_prepare | ||
428 | glibc_src_compile | ||
429 | glibc_src_install | ||
430 | |||
431 | |||
432 | ############################## | ||
433 | # build the final cross-gcc # | ||
434 | ############################## | ||
435 | gcc_src_prepare | ||
436 | gcc_src_compile | ||
437 | gcc_src_install | ||
438 | } | ||
439 | |||
440 | cross_tools_src_install() | ||
441 | { | ||
442 | # remove unneeded man and info pages to save some space | ||
443 | local dir | ||
444 | for dir in info man | ||
445 | do | ||
446 | [ -d ${BINDIR}/${dir} ] && { rm -rf ${BINDIR}/${dir} || die; } | ||
447 | done | ||
448 | |||
449 | # remove ${TARGET_DEST} fake root symlink | ||
450 | [[ -L ${TARGET_DEST} ]] && { rm ${TARGET_DEST} || die; } | ||
451 | |||
452 | # # setup environment | ||
453 | # install -d ${BINDIR}/etc/env.d || die | ||
454 | # | ||
455 | # echo "PATH=${TARGET_DEST}/bin" > ${BINDIR}/etc/env.d/99cross-${TARGET_ARCH} || die | ||
456 | # echo "ROOTPATH=${TARGET_DEST}/bin" >> ${BINDIR}/etc/env.d/99cross-${TARGET_ARCH} || die | ||
457 | # echo "LDPATH=${TARGET_DEST}/lib" >> ${BINDIR}/etc/env.d/99cross-${TARGET_ARCH} || die | ||
458 | |||
459 | niro | 11 | # # setup cross-tools script |
460 | # echo "#!/bin/sh" > ${TARGET_DEST}/bin/setup-cross-tools | ||
461 | # echo "export TARGET_CHOST=${TARGET_ARCH}-pc-linux-gnu" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
462 | # echo "export CROSS_CHOST=${ARCH}-cross-linux-gnu" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
463 | # echo "export CC=${TARGET_CHOST}-gcc" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
464 | # echo "export CXX=${TARGET_CHOST}-g++" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
465 | # echo "export AR=${TARGET_CHOST}-ar" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
466 | # echo "export AS=${TARGET_CHOST}-as" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
467 | # echo "export RANLIB=${TARGET_CHOST}-ranlib" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
468 | # echo "export LD=${TARGET_CHOST}-ld" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
469 | # echo "export STRIP=${TARGET_CHOST}-strip" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
470 | # echo "export PATH=${TARGET_DEST}/bin:${PATH}" >> ${TARGET_DEST}/bin/setup-cross-tools | ||
471 | # chmod 0755 ${TARGET_DEST}/bin/setup-cross-tools || die | ||
472 | |||
473 | niro | 2 | echo "Building of ${PNAME}-toolchain finished ..." |
474 | } | ||
475 | |||
476 | export_inherits cross_tools src_prepare src_compile src_install |