scripts/buildToolchain.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Apr 10 16:05:59 2007 +0000 (2007-04-10)
changeset 28 3a682f0237df
parent 1 eeea35fbf182
child 42 aacc012db6c4
permissions -rw-r--r--
Ah! Recent versions of binutils need some of the build system (read CT_BUILD) tools to be accessible (ar is but an example).
Fix typo.
     1 # This scripts calls each component's build script.
     2 # Copyright 2007 Yann E. MORIN
     3 # Licensed under the GPL v2. See COPYING in the root of this package
     4 
     5 # Parse all build files to have the needed functions.
     6 . "${CT_TOP_DIR}/scripts/build/kernel_${CT_KERNEL}.sh"
     7 . "${CT_TOP_DIR}/scripts/build/binutils.sh"
     8 . "${CT_TOP_DIR}/scripts/build/libc_libfloat.sh"
     9 . "${CT_TOP_DIR}/scripts/build/libc_${CT_LIBC}.sh"
    10 . "${CT_TOP_DIR}/scripts/build/cc_core_${CT_CC_CORE}.sh"
    11 . "${CT_TOP_DIR}/scripts/build/cc_${CT_CC}.sh"
    12 
    13 # Arrange paths depending on wether we use sys-root or not.
    14 if [ "${CT_USE_SYSROOT}" = "y" ]; then
    15     CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}/sys-root"
    16     CT_HEADERS_DIR="${CT_SYSROOT_DIR}/usr/include"
    17     BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
    18     CC_CORE_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
    19     CC_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
    20     LIBC_SYSROOT_ARG=""
    21     # glibc's prefix must be exactly /usr, else --with-sysroot'd gcc will get
    22     # confused when $sysroot/usr/include is not present.
    23     # Note: --prefix=/usr is magic!
    24     # See http://www.gnu.org/software/libc/FAQ.html#s-2.2
    25 else
    26     # plain old way. All libraries in prefix/target/lib
    27     CT_SYSROOT_DIR="${CT_PREFIX_DIR}/${CT_TARGET}"
    28     CT_HEADERS_DIR="${CT_SYSROOT_DIR}/include"
    29     # hack!  Always use --with-sysroot for binutils.
    30     # binutils 2.14 and later obey it, older binutils ignore it.
    31     # Lets you build a working 32->64 bit cross gcc
    32     BINUTILS_SYSROOT_ARG="--with-sysroot=${CT_SYSROOT_DIR}"
    33     # Use --with-headers, else final gcc will define disable_glibc while
    34     # building libgcc, and you'll have no profiling
    35     CC_CORE_SYSROOT_ARG="--without-headers"
    36     CC_SYSROOT_ARG="--with-headers=${CT_HEADERS_DIR}"
    37     LIBC_SYSROOT_ARG="prefix="
    38 fi
    39 
    40 # Prepare the 'lib' directories in sysroot, else the ../lib64 hack used by
    41 # 32 -> 64 bit crosscompilers won't work, and build of final gcc will fail with
    42 #  "ld: cannot open crti.o: No such file or directory"
    43 mkdir -p "${CT_SYSROOT_DIR}/lib"
    44 mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
    45 
    46 # Canadian-cross are really picky on the way they are built. Tweak the values.
    47 if [ "${CT_CANADIAN}" = "y" ]; then
    48     # Arrange so that gcc never, ever think that build system == host system
    49     CT_CANADIAN_OPT="--build=`echo \"${CT_BUILD}\" |sed -r -e 's/-/-build_/'`"
    50     # We shall have a compiler for this target!
    51     # Do test here...
    52 else
    53     CT_HOST="${CT_BUILD}"
    54     CT_CANADIAN_OPT=
    55     # Add the target toolchain in the path so that we can build the C library
    56     export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_PREFIX_DIR}/bin:${PATH}"
    57 fi
    58 
    59 # Modify GCC_HOST to never be equal to $BUILD or $TARGET
    60 # This strange operation causes gcc to always generate a cross-compiler
    61 # even if the build machine is the same kind as the host.
    62 # This is why CC has to be set when doing a canadian cross; you can't find a
    63 # host compiler by appending -gcc to our whacky $GCC_HOST
    64 # Kludge: it is reported that the above causes canadian crosses with cygwin
    65 # hosts to fail, so avoid it just in that one case.  It would be cleaner to
    66 # just move this into the non-canadian case above, but I'm afraid that might
    67 # cause some configure script somewhere to decide that since build==host, they
    68 # could run host binaries.
    69 # (Copied almost as-is from original crosstool):
    70 case "${CT_KERNEL},${CT_CANADIAN}" in
    71     cygwin,y) ;;
    72     *)        CT_HOST="`echo \"${CT_HOST}\" |sed -r -e 's/-/-host_/;'`";;
    73 esac
    74 
    75 # Ah! Recent versions of binutils need some of the build system (read CT_BUILD)
    76 # tools to be accessible (ar is but an example). Do that:
    77 CT_DoLog EXTRA "Making build system tools available"
    78 mkdir -p "${CT_PREFIX_DIR}/bin"
    79 for tool in ar; do
    80     ln -s "`which ${tool}`" "${CT_PREFIX_DIR}/bin/${CT_BUILD}-${tool}"
    81 done
    82 
    83 # Ha. cygwin host have an .exe suffix (extension) for executables.
    84 [ "${CT_KERNEL}" = "cygwin" ] && EXEEXT=".exe" || EXEEXT=""
    85 
    86 # Transform the ARCH into a kernel-understandable ARCH
    87 case "${CT_ARCH}" in
    88     x86) CT_KERNEL_ARCH=i386;;
    89     ppc) CT_KERNEL_ARCH=powerpc;;
    90     *)   CT_KERNEL_ARCH="${CT_ARCH}";;
    91 esac
    92 
    93 # Build up the TARGET_CFLAGS from user-provided options
    94 tmp_target_CFLAGS=
    95 [ -n "${CT_ARCH_CPU}" ]  && tmp_target_CFLAGS="${tmp_target_CFLAGS} -mcpu=${CT_ARCH_CPU}"
    96 [ -n "${CT_ARCH_TUNE}" ] && tmp_target_CFLAGS="${tmp_target_CFLAGS} -mtune=${CT_ARCH_TUNE}"
    97 [ -n "${CT_ARCH_ARCH}" ] && tmp_target_CFLAGS="${tmp_target_CFLAGS} -march=${CT_ARCH_ARCH}"
    98 [ -n "${CT_ARCH_FPU}" ]  && tmp_target_CFLAGS="${tmp_target_CFLAGS} -mfpu=${CT_ARCH_FPU}"
    99 # Override with user-specified CFLAGS
   100 CT_TARGET_CFLAGS="${tmp_target_CFLAGS} ${CT_TARGET_CFLAGS}"
   101 
   102 # Help gcc
   103 CT_CFLAGS_FOR_HOST=
   104 [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
   105 
   106 # And help make go faster
   107 PARALLELMFLAGS=
   108 [ ${CT_PARALLEL_JOBS} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -j${CT_PARALLEL_JOBS}"
   109 [ ${CT_LOAD} -ne 0 ] && PARALLELMFLAGS="${PARALLELMFLAGS} -l${CT_LOAD}"
   110 
   111 CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   112 CT_DoLog EXTRA "Building a toolchain for :"
   113 CT_DoLog EXTRA "  build  = ${CT_BUILD}"
   114 CT_DoLog EXTRA "  host   = ${CT_HOST}"
   115 CT_DoLog EXTRA "  target = ${CT_TARGET}"
   116 set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
   117 CT_EndStep
   118 
   119 # Now for the job by itself.
   120 # Check the C library config ASAP, before the user gets bored, and is
   121 # gone having his/her coffee
   122 do_libc_check_config
   123 do_kernel_check_config
   124 do_kernel_headers
   125 do_binutils
   126 do_libc_headers
   127 do_cc_core
   128 do_libfloat
   129 do_libc
   130 do_cc
   131 do_libc_finish