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