# $Header: /magellan-cvs/smage/include/cross_tools.sminc,v 1.3 2008/10/06 17:55:48 niro Exp $ # Cross-tools generic functions # needed vars: # TARGET_DEST dir : ${TARGET_DEST="/opt/cross-tools"} # needed vars #TARGET_ARCH="i686" # must be set outside : ${CROSS_CHOST="${ARCH}-cross-linux-gnu"} : ${TARGET_CHOST="${TARGET_ARCH}-pc-linux-gnu"} : ${PNAME="cross-tools-${TARGET_ARCH}"} : ${PCAT="dev-cross"} : ${DESCRIPTION="A crosscompile toolchain to compile programms for the ${TARGET_ARCH} arch."} : ${HOMEPAGE="http://magellan-linux.de/"} # 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-${LINUX_HEADERS_PVER}.tar.bz2"} : ${LINUX_HEADERS_SRCDIR="${BUILDDIR}/linux-${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}"} # 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 # fetch sources SRC_URI=( ${SRC_URI[*]} http://www.kernel.org/pub/linux/devel/binutils/${BINUTILS_SRCFILE} mirror://binutils/${BINUTILS_SRCFILE} http://www.kernel.org/pub/linux/kernel/v${LINUX_HEADERS_PVER:0:3}/${LINUX_HEADERS_SRCFILE} mirror://linux-libc-headers/${LINUX_HEADERS_SRCFILE} gnu://glibc/${GLIBC_SRCFILE} mirror://glibc/${GLIBC_SRCFILE} gnu://gcc/gcc-${GCC_PVER}/${GCC_SRCFILE} mirror://gcc/${GCC_SRCFILE} mirror://glibc/glibc-2.3.5-localedef_segfault-1.patch mirror://glibc/glibc-2.3.5-libgcc_eh-1.patch mirror://gcc/gcc-${GCC_PVER}-no-fixincludes.patch mirror://gcc/gcc-${GCC_PVER}-magellan-version.patch mirror://gcc/gcc-${GCC_PVER}-cross-search-paths.patch mirror://gcc/gcc-${GCC_PVER}-specs.patch ) binutils_src_prepare() { munpack ${BINUTILS_SRCFILE} || die install -d ${BINUTILS_SRCDIR}/build || die } binutils_src_compile() { cd ${BINUTILS_SRCDIR}/build AR=ar AS=as \ ../configure \ --host=${CROSS_CHOST} \ --target=${TARGET_CHOST} \ --prefix=${TARGET_DEST} \ --with-lib-path=${TARGET_DEST}/lib \ --disable-nls \ --enable-shared \ --disable-multilib \ || 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 } linux_headers_src_compile() { cd ${LINUX_HEADERS_SRCDIR} make mrproper || die make ARCH=${ARCH/i*86/x86} headers_check || die } linux_headers_src_install() { cd ${LINUX_HEADERS_SRCDIR} make ARCH=${ARCH/i*86/x86} INSTALL_HDR_PATH=${BINDIR}/${TARGET_DEST} headers_install || 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 segfault of localdef on arches beside x86-32 mpatch glibc-2.3.5-localedef_segfault-1.patch || 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 cd ${GLIBC_SRCDIR} # remove dependencies on libgcc_eh mpatch glibc-2.3.5-libgcc_eh-1.patch || die } glibc_src_compile() { cd ${GLIBC_SRCDIR}/build local my_glibc_CFLAGS local my_glibc_CXXFLAGS # glibc-2.6.1 and above needs march CFLAGS: -march=${ARCH} -mtune=generic [[ ${TARGET_ARCH} = i*86 ]] && my_glibc_CFLAGS="${CFLAGS} -march=${TARGET_ARCH}" # only i*86 my_glibc_CFLAGS="${my_glibc_CFLAGS} -mtune=generic" # all arches # 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" \ AR="${TARGET_CHOST}-ar" \ RANLIB="${TARGET_CHOST}-ranlib" \ CFLAGS="${my_glibc_CFLAGS}" \ ../configure \ --host=${TARGET_CHOST} \ --build=${CROSS_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}/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=${CROSS_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} mpatch gcc-${GCC_PVER}-no-fixincludes.patch || die mpatch gcc-${GCC_PVER}-magellan-version.patch || die # fixes location of the dynamic linker and not append include # search path to /usr/include # but first set the location to ${TARGET_DEST} and than patch sed "s:/tools/lib/:${TARGET_DEST}/lib/:g" \ ${SOURCEDIR}/${PNAME}/gcc-${GCC_PVER}-specs.patch | patch -Np1 || die # do not search the /usr directory for libgcc_s.so when cross-compiling mpatch gcc-${GCC_PVER}-cross-search-paths.patch || die # 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_compile 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 # # setup cross-tools script # echo "#!/bin/sh" > ${TARGET_DEST}/bin/setup-cross-tools # echo "export TARGET_CHOST=${TARGET_ARCH}-pc-linux-gnu" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export CROSS_CHOST=${ARCH}-cross-linux-gnu" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export CC=${TARGET_CHOST}-gcc" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export CXX=${TARGET_CHOST}-g++" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export AR=${TARGET_CHOST}-ar" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export AS=${TARGET_CHOST}-as" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export RANLIB=${TARGET_CHOST}-ranlib" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export LD=${TARGET_CHOST}-ld" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export STRIP=${TARGET_CHOST}-strip" >> ${TARGET_DEST}/bin/setup-cross-tools # echo "export PATH=${TARGET_DEST}/bin:${PATH}" >> ${TARGET_DEST}/bin/setup-cross-tools # chmod 0755 ${TARGET_DEST}/bin/setup-cross-tools || die echo "Building of ${PNAME}-toolchain finished ..." } export_inherits cross_tools src_prepare src_compile src_install