yann@1: # This scripts calls each component's build script. yann@1: # Copyright 2007 Yann E. MORIN yann@1: # Licensed under the GPL v2. See COPYING in the root of this package yann@1: yann@1: # Parse all build files to have the needed functions. yann@1: . "${CT_TOP_DIR}/scripts/build/kernel_${CT_KERNEL}.sh" yann@1: . "${CT_TOP_DIR}/scripts/build/binutils.sh" yann@1: . "${CT_TOP_DIR}/scripts/build/libc_libfloat.sh" yann@1: . "${CT_TOP_DIR}/scripts/build/libc_${CT_LIBC}.sh" yann@1: . "${CT_TOP_DIR}/scripts/build/cc_core_${CT_CC_CORE}.sh" yann@1: . "${CT_TOP_DIR}/scripts/build/cc_${CT_CC}.sh" yann@1: yann@1: # Arrange paths depending on wether we use sys-root or not. yann@1: if [ "${CT_USE_SYSROOT}" = "y" ]; then yann@1: CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root" yann@1: CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include" yann@1: BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" yann@1: CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" yann@1: CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" yann@1: LIBC_SYSROOT_ARG="" yann@1: # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get yann@1: # confused when $sysroot/usr/include is not present. yann@1: # Note: --prefix=/usr is magic! yann@1: # See http://www.gnu.org/software/libc/FAQ.html#s-2.2 yann@1: else yann@1: # plain old way. All libraries in prefix/target/lib yann@1: CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}" yann@1: CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include" yann@1: # hack! Always use --with-sysroot for binutils. yann@1: # binutils 2.14 and later obey it, older binutils ignore it. yann@1: # Lets you build a working 32->64 bit cross gcc yann@1: BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}" yann@1: # Use --with-headers, else final gcc will define disable_glibc while yann@1: # building libgcc, and you'll have no profiling yann@1: CC_CORE_SYSROOT_ARG="--without-headers" yann@1: CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}" yann@1: LIBC_SYSROOT_ARG="prefix=" yann@1: fi yann@1: yann@1: # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by yann@1: # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with yann@1: # "ld: cannot open crti.o: No such file or directory" yann@1: mkdir -p "${CT_SYSROOT_DIR}/lib" yann@1: mkdir -p "${CT_SYSROOT_DIR}/usr/lib" yann@1: yann@1: # Canadian-cross are really picky on the way they are built. Tweak the values. yann@1: if [ "${CT_CANADIAN}" = "y" ]; then yann@1: # Arrange so that gcc never, ever think that build system == host system yann@1: CT_CANADIAN_OPT="--build=`echo \"${CT_BUILD}\" |sed -r -e 's/-/-build_/'`" yann@1: # We shall have a compiler for this target! yann@1: # Do test here... yann@1: else yann@1: CT_HOST="${CT_BUILD}" yann@1: CT_CANADIAN_OPT= yann@1: # Add the target toolchain in the path so that we can build the C library yann@1: export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_PREFIX_DIR}/bin:${PATH}" yann@1: fi yann@1: yann@1: # Modify GCC_HOST to never be equal to $BUILD or $TARGET yann@1: # This strange operation causes gcc to always generate a cross-compiler yann@1: # even if the build machine is the same kind as the host. yann@1: # This is why CC has to be set when doing a canadian cross; you can't find a yann@1: # host compiler by appending -gcc to our whacky $GCC_HOST yann@1: # Kludge: it is reported that the above causes canadian crosses with cygwin yann@1: # hosts to fail, so avoid it just in that one case. It would be cleaner to yann@1: # just move this into the non-canadian case above, but I'm afraid that might yann@1: # cause some configure script somewhere to decide that since build==host, they yann@1: # could run host binaries. yann@1: # (Copied almost as-is from original crosstool): yann@1: case "${CT_KERNEL},${CT_CANADIAN}" in yann@1: cygwin,y) ;; yann@1: *) CT_HOST="`echo \"${CT_HOST}\" |sed -r -e 's/-/-host_/;'`";; yann@1: esac yann@1: yann@42: # Ah! Recent versions of binutils need some of the build and/or host system yann@42: # (read CT_BUILD and CT_HOST) tools to be accessible (ar is but an example). yann@42: # Do that: yann@28: CT_DoLog EXTRA "Making build system tools available" yann@28: mkdir -p "${CT_PREFIX_DIR}/bin" yann@28: for tool in ar; do yann@28: ln -s "`which ${tool}`" "${CT_PREFIX_DIR}/bin/${CT_BUILD}-${tool}" yann@42: ln -s "`which ${tool}`" "${CT_PREFIX_DIR}/bin/${CT_HOST}-${tool}" yann@28: done yann@28: yann@1: # Ha. cygwin host have an .exe suffix (extension) for executables. yann@1: [ "${CT_KERNEL}" = "cygwin" ] && EXEEXT=".exe" || EXEEXT="" yann@1: yann@1: # Transform the ARCH into a kernel-understandable ARCH yann@1: case "${CT_ARCH}" in yann@1: x86) CT_KERNEL_ARCH=i386;; yann@28: ppc) CT_KERNEL_ARCH=powerpc;; yann@1: *) CT_KERNEL_ARCH="${CT_ARCH}";; yann@1: esac yann@1: yann@1: # Build up the TARGET_CFLAGS from user-provided options yann@1: tmp_target_CFLAGS= yann@1: [ -n "${CT_ARCH_CPU}" ] && tmp_target_CFLAGS="${tmp_target_CFLAGS} -mcpu=${CT_ARCH_CPU}" yann@1: [ -n "${CT_ARCH_TUNE}" ] && tmp_target_CFLAGS="${tmp_target_CFLAGS} -mtune=${CT_ARCH_TUNE}" yann@1: [ -n "${CT_ARCH_ARCH}" ] && tmp_target_CFLAGS="${tmp_target_CFLAGS} -march=${CT_ARCH_ARCH}" yann@1: [ -n "${CT_ARCH_FPU}" ] && tmp_target_CFLAGS="${tmp_target_CFLAGS} -mfpu=${CT_ARCH_FPU}" yann@1: # Override with user-specified CFLAGS yann@1: CT_TARGET_CFLAGS="${tmp_target_CFLAGS} ${CT_TARGET_CFLAGS}" yann@1: yann@1: # Help gcc yann@1: CT_CFLAGS_FOR_HOST= yann@1: [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe" yann@1: yann@1: # And help make go faster yann@1: PARALLELMFLAGS= yann@1: [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}" yann@1: [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}" yann@1: yann@1: CT_DoStep EXTRA "Dumping internal crosstool-NG configuration" yann@1: CT_DoLog EXTRA "Building a toolchain for :" yann@1: CT_DoLog EXTRA " build = ${CT_BUILD}" yann@1: CT_DoLog EXTRA " host = ${CT_HOST}" yann@1: CT_DoLog EXTRA " target = ${CT_TARGET}" yann@1: set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG yann@1: CT_EndStep yann@1: yann@1: # Now for the job by itself. yann@1: # Check the C library config ASAP, before the user gets bored, and is yann@1: # gone having his/her coffee yann@1: do_libc_check_config yann@1: do_kernel_check_config yann@1: do_kernel_headers yann@1: do_binutils yann@1: do_libc_headers yann@1: do_cc_core yann@1: do_libfloat yann@1: do_libc yann@1: do_cc yann@1: do_libc_finish