scripts/crosstool.sh
changeset 1041 2573519c00d6
parent 1038 33f695f7773a
child 1062 a435f445d477
     1.1 --- a/scripts/crosstool.sh	Fri Nov 07 08:09:42 2008 +0000
     1.2 +++ b/scripts/crosstool.sh	Thu Nov 13 18:22:23 2008 +0000
     1.3 @@ -223,10 +223,11 @@
     1.4  
     1.5  # Setting up the rest of the environment only if not restarting
     1.6  if [ -z "${CT_RESTART}" ]; then
     1.7 -    # Determine build system if not set by the user
     1.8 -    CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
     1.9 -    CT_BUILD="${CT_BUILD:-$(CT_DoConfigGuess)}"
    1.10 -    CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}")
    1.11 +    # What's our shell?
    1.12 +    # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
    1.13 +    # _explictly_ required using it
    1.14 +    CT_SHELL="/bin/sh"
    1.15 +    [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
    1.16  
    1.17      # Arrange paths depending on wether we use sys-root or not.
    1.18      if [ "${CT_USE_SYSROOT}" = "y" ]; then
    1.19 @@ -273,63 +274,121 @@
    1.20          ln -sf "sys-root/lib" "${CT_PREFIX_DIR}/${CT_TARGET}/lib64"
    1.21      fi
    1.22  
    1.23 -    # Canadian-cross are really picky on the way they are built. Tweak the values.
    1.24 -    CT_UNIQ_BUILD=$(echo "${CT_BUILD}" |sed -r -e 's/-/-build_/')
    1.25 -    if [ "${CT_CANADIAN}" = "y" ]; then
    1.26 -        # Arrange so that gcc never, ever think that build system == host system
    1.27 -        CT_CANADIAN_OPT="--build=${CT_UNIQ_BUILD}"
    1.28 -        # We shall have a compiler for this target!
    1.29 -        # Do test here...
    1.30 -    else
    1.31 -        CT_HOST="${CT_BUILD}"
    1.32 -        CT_CANADIAN_OPT="--build=${CT_BUILD}"
    1.33 -        # Add the target toolchain in the path so that we can build the C library
    1.34 -        # Carefully add paths in the order we want them:
    1.35 -        #  - first try in ${CT_PREFIX_DIR}/bin
    1.36 -        #  - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
    1.37 -        #  - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
    1.38 -        #  - fall back to searching user's PATH
    1.39 -        export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}"
    1.40 -    fi
    1.41 -
    1.42 -    # Modify GCC_HOST to never be equal to $BUILD or $TARGET
    1.43 -    # This strange operation causes gcc to always generate a cross-compiler
    1.44 -    # even if the build machine is the same kind as the host.
    1.45 -    # This is why CC has to be set when doing a canadian cross; you can't find a
    1.46 -    # host compiler by appending -gcc to our whacky $GCC_HOST
    1.47 -    # Kludge: it is reported that the above causes canadian crosses with cygwin
    1.48 -    # hosts to fail, so avoid it just in that one case.  It would be cleaner to
    1.49 -    # just move this into the non-canadian case above, but I'm afraid that might
    1.50 -    # cause some configure script somewhere to decide that since build==host, they
    1.51 -    # could run host binaries.
    1.52 -    # (Copied almost as-is from original crosstool):
    1.53 -    case "${CT_KERNEL},${CT_CANADIAN}" in
    1.54 -        cygwin,y) ;;
    1.55 -        *,y)      CT_HOST=$(echo "${CT_HOST}" |sed -r -e 's/-/-host_/;');;
    1.56 +    # Determine build system if not set by the user
    1.57 +    CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
    1.58 +    case "${CT_BUILD}" in
    1.59 +        "") CT_BUILD=$(gcc -dumpmachine);;
    1.60 +        *)  CT_BUILD=$(CT_DoConfigSub "${CT_BUILD}");;
    1.61      esac
    1.62  
    1.63 -    # What's our shell?
    1.64 -    # Will be plain /bin/sh on most systems, except if we have /bin/ash and we
    1.65 -    # _explictly_ required using it
    1.66 -    CT_SHELL="/bin/sh"
    1.67 -    [ "${CT_CONFIG_SHELL_ASH}" = "y" -a -x "/bin/ash" ] && CT_SHELL="/bin/ash"
    1.68 +    # Prepare mangling patterns to later modifyu BUILD and HOST (see below)
    1.69 +    case "${CT_TOOLCHAIN_TYPE}" in
    1.70 +        cross)
    1.71 +            CT_HOST="${CT_BUILD}"
    1.72 +            build_mangle="build_"
    1.73 +            host_mangle="build_"
    1.74 +            ;;
    1.75 +        *)  CT_Abort "No code for '${CT_TOOLCHAIN_TYPE}' toolchain type!"
    1.76 +            ;;
    1.77 +    esac
    1.78  
    1.79 -    # Ah! Recent versions of binutils need some of the build and/or host system
    1.80 -    # (read CT_BUILD and CT_HOST) tools to be accessible (ar is but an example).
    1.81 -    # Do that:
    1.82 +    # Save the real tuples to generate shell-wrappers to the real tools
    1.83 +    CT_REAL_BUILD="${CT_BUILD}"
    1.84 +    CT_REAL_HOST="${CT_HOST}"
    1.85 +
    1.86 +    # Make BUILD and HOST full-fledge four-part tuples (gcc -dumpmachine
    1.87 +    # might be only three-part tuple, and I don't know wether config.guess
    1.88 +    # can return 3-part tuples...)
    1.89 +    case "${CT_BUILD}" in
    1.90 +        *-*-*-*-*)  CT_Abort "Unexpected 5-part (or more) build tuple: '${CT_BUILD}'";;
    1.91 +        *-*-*-*)    ;;
    1.92 +        *-*-*)      CT_BUILD="${CT_BUILD/-/-unknown-}";;
    1.93 +        *)          CT_Abort "Unepxected 1- or 2-part build tuple: '${CT_BUILD}'";;
    1.94 +    esac
    1.95 +    case "${CT_HOST}" in
    1.96 +        *-*-*-*-*)  CT_Abort "Unexpected 5-part (or more) host tuple: '${CT_HOST}'";;
    1.97 +        *-*-*-*)    ;;
    1.98 +        *-*-*)      CT_HOST="${CT_HOST/-/-unknown-}";;
    1.99 +        *)          CT_Abort "Unepxected 1- or 2-part host tuple: '${CT_HOST}'";;
   1.100 +    esac
   1.101 +
   1.102 +    # Modify BUILD and HOST so that gcc always generate a cross-compiler
   1.103 +    # even if any of the build, host or target machines are the same.
   1.104 +    # NOTE: we'll have to mangle the (BUILD|HOST)->TARGET x-compiler to
   1.105 +    #       support canadain build, later...
   1.106 +    CT_BUILD="${CT_BUILD/-/-${build_mangle}}"
   1.107 +    CT_HOST="${CT_HOST/-/-${host_mangle}}"
   1.108 +
   1.109 +    # Now we have mangled our BUILD and HOST tuples, we must fake the new
   1.110 +    # cross-tools for those mangled tuples.
   1.111      BANG='!'
   1.112      CT_DoLog DEBUG "Making build system tools available"
   1.113      mkdir -p "${CT_PREFIX_DIR}/bin"
   1.114 -    for tool in ar as dlltool ${CT_CC_NATIVE:=gcc} gnatbind gnatmake ld nm ranlib strip windres objcopy objdump; do
   1.115 -        tmp=$(CT_Which ${tool})
   1.116 -        if [ -n "${tmp}" ]; then
   1.117 -            printf "#${BANG}${CT_SHELL}\nexec '${tmp}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${CT_BUILD}-${tool}"
   1.118 -            printf "#${BANG}${CT_SHELL}\nexec '${tmp}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${CT_UNIQ_BUILD}-${tool}"
   1.119 -            printf "#${BANG}${CT_SHELL}\nexec '${tmp}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${CT_HOST}-${tool}"
   1.120 -            chmod 700 "${CT_PREFIX_DIR}/bin/${CT_BUILD}-${tool}" "${CT_PREFIX_DIR}/bin/${CT_UNIQ_BUILD}-${tool}" "${CT_PREFIX_DIR}/bin/${CT_HOST}-${tool}"
   1.121 -        fi |CT_DoLog DEBUG
   1.122 +    for m in BUILD HOST; do
   1.123 +        r="CT_REAL_${m}"
   1.124 +        v="CT_${m}"
   1.125 +        p="CT_${m}_PREFIX"
   1.126 +        s="CT_${m}_SUFFIX"
   1.127 +        if [ -n "${!p}" ]; then
   1.128 +            t="${!p}"
   1.129 +        else
   1.130 +            t="${!r}-"
   1.131 +        fi
   1.132 +
   1.133 +        for tool in ar as dlltool gcc g++ gnatbind gnatmake ld nm objcopy objdump ranlib strip windres; do
   1.134 +            # First try with prefix + suffix
   1.135 +            # Then try with prefix only
   1.136 +            # Then try with suffix only, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   1.137 +            # Finally try with neither prefix nor suffix, but only for BUILD, and HOST iff REAL_BUILD == REAL_HOST
   1.138 +            # This is needed, because some tools have a prefix and
   1.139 +            # a suffix (eg. gcc), while others may have only one,
   1.140 +            # or even none (eg. binutils)
   1.141 +            where=$(CT_Which "${t}${tool}${!s}")
   1.142 +            [ -z "${where}" ] && where=$(CT_Which "${t}${tool}")
   1.143 +            if [    -z "${where}"                         \
   1.144 +                 -a \(    "${m}" = "BUILD"                \
   1.145 +                       -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   1.146 +                where=$(CT_Which "${tool}${!s}")
   1.147 +            fi
   1.148 +            if [ -z "${where}"                            \
   1.149 +                 -a \(    "${m}" = "BUILD"                \
   1.150 +                       -o "${CT_REAL_BUILD}" = "${!r}" \) ]; then
   1.151 +                where=$(CT_Which "${tool}")
   1.152 +            fi
   1.153 +
   1.154 +            # Not all tools are available for all platforms, but some are really,
   1.155 +            # bally needed
   1.156 +            if [ -n "${where}" ]; then
   1.157 +                CT_DoLog DEBUG "  '${!v}-${tool}' -> '${where}'"
   1.158 +                printf "#${BANG}${CT_SHELL}\nexec '${where}' \"\${@}\"\n" >"${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   1.159 +                chmod 700 "${CT_PREFIX_DIR}/bin/${!v}-${tool}"
   1.160 +            else
   1.161 +                # We'll at least need some of them...
   1.162 +                case "${tool}" in
   1.163 +                    ar|as|gcc|ld|nm|objcopy|objdump|ranlib)
   1.164 +                        CT_Abort "Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : either needed!"
   1.165 +                        ;;
   1.166 +                    *)
   1.167 +                        # It does not deserve a WARN level.
   1.168 +                        CT_DoLog DEBUG "  Missing: '${t}${tool}${!s}' or '${t}${tool}' or '${tool}' : not required."
   1.169 +                        ;;
   1.170 +                esac
   1.171 +            fi
   1.172 +        done
   1.173      done
   1.174  
   1.175 +    # Carefully add paths in the order we want them:
   1.176 +    #  - first try in ${CT_PREFIX_DIR}/bin
   1.177 +    #  - then try in ${CT_CC_CORE_SHARED_PREFIX_DIR}/bin
   1.178 +    #  - then try in ${CT_CC_CORE_STATIC_PREFIX_DIR}/bin
   1.179 +    #  - fall back to searching user's PATH
   1.180 +    # Of course, neither cross-native nor canadian can run on BUILD,
   1.181 +    # so don't add those PATHs in this case...
   1.182 +    case "${CT_TOOLCHAIN_TYPE}" in
   1.183 +        cross)  export PATH="${CT_PREFIX_DIR}/bin:${CT_CC_CORE_SHARED_PREFIX_DIR}/bin:${CT_CC_CORE_STATIC_PREFIX_DIR}/bin:${PATH}";;
   1.184 +        *)  ;;
   1.185 +    esac
   1.186 +
   1.187      # Some makeinfo versions are a pain in [put your most sensible body part here].
   1.188      # Go ahead with those, by creating a wrapper that keeps partial files, and that
   1.189      # never fails:
   1.190 @@ -359,8 +418,8 @@
   1.191  
   1.192      CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
   1.193      CT_DoLog EXTRA "Building a toolchain for:"
   1.194 -    CT_DoLog EXTRA "  build  = ${CT_BUILD}"
   1.195 -    CT_DoLog EXTRA "  host   = ${CT_HOST}"
   1.196 +    CT_DoLog EXTRA "  build  = ${CT_REAL_BUILD}"
   1.197 +    CT_DoLog EXTRA "  host   = ${CT_REAL_HOST}"
   1.198      CT_DoLog EXTRA "  target = ${CT_TARGET}"
   1.199      set |egrep '^CT_.+=' |sort |CT_DoLog DEBUG
   1.200      CT_EndStep
   1.201 @@ -434,7 +493,6 @@
   1.202  
   1.203      CT_DoLog DEBUG "Removing access to the build system tools"
   1.204      find "${CT_PREFIX_DIR}/bin" -name "${CT_BUILD}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   1.205 -    find "${CT_PREFIX_DIR}/bin" -name "${CT_UNIQ_BUILD}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   1.206      find "${CT_PREFIX_DIR}/bin" -name "${CT_HOST}-"'*' -exec rm -fv {} \; |CT_DoLog DEBUG
   1.207      rm -fv "${CT_PREFIX_DIR}/bin/makeinfo" |CT_DoLog DEBUG
   1.208