# $Header: /magellan-cvs/smage/include/cross_tools.sminc,v 1.1 2005/12/24 14:03:26 niro Exp $ # Cross-tools generic functions # # needed vars # TARGET_ARCH="i686" # TARGET_CHOST="${TARGET_ARCH}-cross-linux-gnu" # # PNAME="cross-tools-${TARGET_ARCH}" # # # version of the compiler # PVER="4.0.2" # PBUILD="r2" # # PCATEGORIE="dev-misc" # STATE="unstable" # # DESCRIPTION="A crosscompile toolchain to compile programms for the ${TARGET_ARCH} arch." # HOMEPAGE="http://magellan-linux.de/" # # DEPEND="" # # # binutils # BINUTILS_PVER="2.16.91.0.3" # BINUTILS_SRCFILE="binutils-${BINUTILS_PVER}.tar.bz2" # BINUTILS_SRCDIR="${BUILDDIR}/binutils-${BINUTILS_PVER}" # # # kernel-headers # LINUX_HEADERS_PVER="2.6.12.0" # LINUX_HEADERS_SRCFILE="linux-libc-headers-${LINUX_HEADERS_PVER}.tar.bz2" # LINUX_HEADERS_SRCDIR="${BUILDDIR}/linux-libc-headers-${LINUX_HEADERS_PVER}" # # # glibc-headers and libc # GLIBC_PVER="2.3.5_20051107" # GLIBC_SRCFILE="glibc-${GLIBC_PVER/*_/}.tar.bz2" # GLIBC_LINUXTHREADS="glibc-linuxthreads-${GLIBC_PVER/*_/}.tar.bz2" # GLIBC_SRCDIR="${BUILDDIR}/glibc-${GLIBC_PVER/*_/}" # # # gcc # GCC_PVER="${PVER}" # GCC_SRCFILE="gcc-${GCC_PVER}.tar.bz2" # GCC_SRCDIR="${BUILDDIR}/gcc-${GCC_PVER}" # # # TARGET_DEST dir # TARGET_DEST=/opt/cross-tools # # do not get the idea to strip the resulting binaries! # you must have build the strip program on the same arch, # but this is propably not the case. so we force stripping off. NOSTRIP=true binutils_src_prepare() { munpack ${BINUTILS_SRCFILE} || die install -d ${BINUTILS_SRCDIR}/build || die } binutils_src_compile() { cd ${BINUTILS_SRCDIR}/build ../configure \ --host=${CHOST} \ --target=${TARGET_CHOST} \ --prefix=${TARGET_DEST} \ --with-lib-path=${TARGET_DEST}/lib \ --disable-nls \ --enable-shared \ --enable-64-bit-bfd \ || die make configure-host || die mmake || die } binutils_src_install() { cd ${BINUTILS_SRCDIR}/build make install || die install -d ${TARGET_DEST}/include || die cp ../include/libiberty.h ${TARGET_DEST}/include || die } linux_headers_src_prepare() { munpack ${LINUX_HEADERS_SRCFILE} || die cd ${LINUX_HEADERS_SRCDIR} # set correct permissions chown -R root:root * || die chmod -R a+r-w+X,u+w * || die } linux_headers_src_install() { cd ${LINUX_HEADERS_SRCDIR} # using correct arch local myarch=${TARGET_ARCH} [[ ${myarch} = i?86 ]] && myarch=i386 # needed directories install -d ${TARGET_DEST}/include/{asm,linux} || die cp -ax ${LINUX_HEADERS_SRCDIR}/include/linux/* \ ${TARGET_DEST}/include/linux || die cp -ax ${LINUX_HEADERS_SRCDIR}/include/asm-${myarch}/* \ ${TARGET_DEST}/include/asm || die } # building the glibc-headers glibc_headers_src_prepare() { glibc_generic_src_prepare cd ${GLIBC_SRCDIR}/build # remove gcc dependencies sed -i 's/3.4/3.[0-9]/g' ../configure || die } glibc_headers_src_compile() { cd ${GLIBC_SRCDIR}/build # do not enable addons here ../configure \ --host=${CHOST} \ --target=${TARGET_CHOST} \ --prefix=${TARGET_DEST} \ --enable-kernel=2.6.0 \ --without-cvs \ --with-headers=${TARGET_DEST}/include \ --with-binutils=${TARGET_DEST}/${TARGET_CHOST}/bin \ --disable-sanity-checks \ --disable-nls \ || die } glibc_headers_src_install() { cd ${GLIBC_SRCDIR}/build make install-headers || die # needed directories install -d ${TARGET_DEST}/include/{bits,gnu} || die # using correct arch local myarch=${TARGET_ARCH} [[ ${myarch} = i?86 ]] && myarch=i386 # missing headers cp bits/stdio_lim.h ${TARGET_DEST}/include/bits || die touch ${TARGET_DEST}/include/gnu/stubs.h || die cp ../nptl/sysdeps/pthread/pthread.h ${TARGET_DEST}/include || die cp ../nptl/sysdeps/unix/sysv/linux/${myarch}/bits/pthreadtypes.h \ ${TARGET_DEST}/include || die } # generic glibc unpack glibc_generic_src_prepare() { munpack ${GLIBC_SRCFILE} || die cd ${GLIBC_SRCDIR} # disable binutils -as-needed sed -i 's/^have-as-needed.*/have-as-needed = no/' \ ${GLIBC_SRCDIR}/config.make.in || die # fix permissions on some of the scripts chmod u+x ${GLIBC_SRCDIR}/scripts/*.sh || die install -d ${GLIBC_SRCDIR}/build || die } # final glibc glibc_src_prepare() { glibc_generic_src_prepare } glibc_src_compile() { cd ${GLIBC_SRCDIR}/build # force nptl support (may not detected always) echo "libc_cv_forced_unwind=yes" > config.cache || die echo "libc_cv_c_cleanup=yes" >> config.cache || die BUILD_CC="gcc" \ CC="${TARGET_CHOST}-gcc -m32" \ AR="${TARGET_CHOST}-ar" \ RANLIB="${TARGET_CHOST}-ranlib" \ ../configure \ --host=${TARGET_CHOST} \ --build=${CHOST} \ --prefix=${TARGET_DEST} \ --disable-profile \ --enable-add-ons=nptl --with-tls \ --with-__thread \ --enable-kernel=2.6.0 \ --without-cvs \ --with-headers=${TARGET_DEST}/include \ --with-binutils=${TARGET_DEST}/${TARGET_CHOST}/bin \ --cache-file=config.cache \ || die make PARALLELMFLAGS="-j2" || die } glibc_src_install() { cd ${GLIBC_SRCDIR}/build make install || die } # static gcc, only c gcc_static_src_prepare() { gcc_generic_src_prepare } gcc_static_src_compile() { cd ${GCC_SRCDIR}/build ../configure \ --host=${CHOST} \ --target=${TARGET_CHOST} \ --prefix=${TARGET_DEST} \ --with-local-prefix=${TARGET_DEST} \ --disable-nls \ --disable-shared \ --disable-threads \ --enable-languages=c \ --disable-multilib \ || die mmake all-gcc || die } gcc_static_src_install() { cd ${GCC_SRCDIR}/build make install-gcc || die } # final gcc, c and c++ gcc_src_prepare() { gcc_generic_src_prepare cd ${GCC_SRCDIR} # disable -B in configure, so it doesn't pick up the host's header files sed -i '/FLAGS_FOR_TARGET.*\/lib\//s@-B[^ ]*/lib/@@g' configure || die } gcc_src_compile() { cd ${GCC_SRCDIR}/build ../configure \ --host=${CHOST} \ --target=${TARGET_CHOST} \ --prefix=${TARGET_DEST} \ --with-local-prefix=${TARGET_DEST} \ --enable-shared \ --enable-threads=posix \ --enable-__cxa_atexit \ --enable-c99 \ --enable-long-long \ --enable-languages=c,c++ \ --disable-nls \ --disable-multilib \ || die #--with-system-zlib \ #--enable-clocale=gnu \ #--disable-checking \ #--disable-libunwind-exceptions \ #--enable-cstdio=stdio \ make \ AS_FOR_TARGET="${TARGET_DEST}/bin/${TARGET_CHOST}-as" \ LD_FOR_TARGET="${TARGET_DEST}/bin/${TARGET_CHOST}-ld" \ || die } gcc_src_install() { cd ${GCC_SRCDIR}/build make install || die } gcc_generic_src_prepare() { munpack ${GCC_SRCFILE} || die cd ${GCC_SRCDIR} # suppress installation of libiberty, as we will be # using the one from binutils #sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in || die # fix up the startfile spec to search /opt/cross-tools/lib # fixes errors like this on the final cross-gcc compilation # /opt/cross-tools/i686-cross-linux-gnu/bin/ld: crti.o: No such file: No such file or directory # collect2: ld returned 1 exit status echo " #undef STARTFILE_PREFIX_SPEC #define STARTFILE_PREFIX_SPEC \"${TARGET_DEST}/lib/\"" >> ${GCC_SRCDIR}/gcc/config/linux.h || die # change header search path to look only in $TARGET_DEST/include # and not the hosts own include pathes sed -i "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 ${TARGET_DEST}/include@g" \ ${GCC_SRCDIR}/gcc/Makefile.in || die install -d ${GCC_SRCDIR}/build || die } cross_tools_src_prepare() { if [[ -e ${TARGET_DEST} ]] || [[ -L ${TARGET_DEST} ]] then echo echo "Please uninstall any cross-tools packages first." echo "To build the tools I'll create a fake symlink to ${TARGET_DEST}," echo "so this directory must not exist." echo die "${TARGET_DEST} exists." fi if [[ ${CHOST} = ${TARGET_CHOST} ]] then echo echo "\$CHOST and \$TARGET_CHOST have the same values." echo " CHOST=${CHOST}" echo " TARGET_CHOST=${TARGET_CHOST}" echo echo "You cannot build a cross-compiler with these settings," echo "please use the native gcc-\${ARCH} builds." echo die "\$CHOST equal \$TARGET_CHOST." fi # create a fake build-root install -d ${BINDIR}/${TARGET_DEST} || die ln -snf ${BINDIR}/${TARGET_DEST} ${TARGET_DEST} || die } cross_tools_src_compile() { # setup a proper build environment export PATH=${TARGET_DEST}/bin:${PATH} ############################## # first of all build binutils# ############################## binutils_src_prepare binutils_src_compile binutils_src_install ################################# # now install the linux-headers # ################################# linux_headers_src_prepare linux_headers_src_install ############################ # create the glibc-headers # ############################ glibc_headers_src_prepare glibc_headers_src_compile glibc_headers_src_install # remove GLIBC_SRCDIR rm -rf ${GLIBC_SRCDIR} || die ############################## # build a static minimal gcc # ############################## gcc_static_src_prepare gcc_static_src_compile gcc_static_src_install # remove GCC_SRCDIR rm -rf ${GCC_SRCDIR} || die ################################ # build the final cross-glibc # ################################ glibc_src_prepare glibc_src_compile glibc_src_install ############################## # build the final cross-gcc # ############################## gcc_src_prepare gcc_src_compile gcc_src_install } cross_tools_src_install() { # remove unneeded man and info pages to save some space local dir for dir in info man do [ -d ${BINDIR}/${dir} ] && { rm -rf ${BINDIR}/${dir} || die; } done # remove ${TARGET_DEST} fake root symlink [[ -L ${TARGET_DEST} ]] && { rm ${TARGET_DEST} || die; } # # setup environment # install -d ${BINDIR}/etc/env.d || die # # echo "PATH=${TARGET_DEST}/bin" > ${BINDIR}/etc/env.d/99cross-${TARGET_ARCH} || die # echo "ROOTPATH=${TARGET_DEST}/bin" >> ${BINDIR}/etc/env.d/99cross-${TARGET_ARCH} || die # echo "LDPATH=${TARGET_DEST}/lib" >> ${BINDIR}/etc/env.d/99cross-${TARGET_ARCH} || die echo "Building of ${PNAME}-toolchain finished ..." } export_inherits cross_tools src_prepare src_compile src_install