scripts/functions
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue May 08 12:54:06 2007 +0000 (2007-05-08)
changeset 76 5f84983926e9
parent 63 89b41dbffe8d
child 77 ccb2d742e917
permissions -rw-r--r--
Print the elapsed time alongside with the progress bar, such as below:
[02:27] \
yann@1
     1
# This file contains some usefull common functions
yann@1
     2
# Copyright 2007 Yann E. MORIN
yann@1
     3
# Licensed under the GPL v2. See COPYING in the root of this package
yann@1
     4
yann@1
     5
CT_OnError() {
yann@1
     6
    ret=$?
yann@1
     7
    CT_DoLog ERROR "Build failed in step \"${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}\""
yann@1
     8
    for((step=(CT_STEP_COUNT-1); step>1; step--)); do
yann@1
     9
        CT_DoLog ERROR "      called in step \"${CT_STEP_MESSAGE[${step}]}\""
yann@1
    10
    done
yann@1
    11
    CT_DoLog ERROR "Error happened in \"${BASH_SOURCE[1]}\" in function \"${FUNCNAME[1]}\" (line unknown, sorry)"
yann@1
    12
    for((depth=2; ${BASH_LINENO[$((${depth}-1))]}>0; depth++)); do
yann@1
    13
        CT_DoLog ERROR "      called from \"${BASH_SOURCE[${depth}]}\" at line # ${BASH_LINENO[${depth}-1]} in function \"${FUNCNAME[${depth}]}\""
yann@1
    14
    done
yann@1
    15
    CT_DoLog ERROR "Look at \"${CT_ACTUAL_LOG_FILE}\" for more info on this error."
yann@1
    16
    exit $ret
yann@1
    17
}
yann@1
    18
trap CT_OnError ERR
yann@1
    19
yann@1
    20
set -E
yann@1
    21
set -o pipefail
yann@1
    22
yann@1
    23
# This is crosstool-ng-0.0.1
yann@1
    24
CT_VERSION=ng-0.0.1
yann@1
    25
yann@1
    26
# The different log levels:
yann@1
    27
CT_LOG_LEVEL_ERROR=0
yann@1
    28
CT_LOG_LEVEL_WARN=1
yann@1
    29
CT_LOG_LEVEL_INFO=2
yann@1
    30
CT_LOG_LEVEL_EXTRA=3
yann@1
    31
CT_LOG_LEVEL_DEBUG=4
yann@1
    32
yann@1
    33
# Attributes
yann@1
    34
_A_NOR="\\033[0m"
yann@1
    35
_A_BRI="\\033[1m"
yann@1
    36
_A_DIM="\\033[2m"
yann@1
    37
_A_UND="\\033[4m"
yann@1
    38
_A_BRB="\\033[5m"
yann@1
    39
_A_REV="\\033[7m"
yann@1
    40
_A_HID="\\033[8m"
yann@1
    41
yann@1
    42
# Fore colors
yann@1
    43
_F_BLK="\\033[30m"
yann@1
    44
_F_RED="\\033[31m"
yann@1
    45
_F_GRN="\\033[32m"
yann@1
    46
_F_YEL="\\033[33m"
yann@1
    47
_F_BLU="\\033[34m"
yann@1
    48
_F_MAG="\\033[35m"
yann@1
    49
_F_CYA="\\033[36m"
yann@1
    50
_F_WHI="\\033[37m"
yann@1
    51
yann@1
    52
# A function to log what is happening
yann@1
    53
# Different log level are available:
yann@1
    54
#   - ERROR:   A serious, fatal error occurred
yann@1
    55
#   - WARN:    A non fatal, non serious error occurred, take your responsbility with the generated build
yann@1
    56
#   - INFO:    Informational messages
yann@1
    57
#   - EXTRA:   Extra informational messages
yann@1
    58
#   - DEBUG:   Debug messages
yann@1
    59
# Usage: CT_DoLog <level> [message]
yann@1
    60
# If message is empty, then stdin will be logged.
yann@1
    61
CT_DoLog() {
yann@47
    62
    local max_level LEVEL level cur_l cur_L
yann@47
    63
    local l
yann@1
    64
    eval max_level="\${CT_LOG_LEVEL_${CT_LOG_LEVEL_MAX}}"
yann@1
    65
    # Set the maximum log level to DEBUG if we have none
yann@1
    66
    [ -z ${max_level} ] && max_level=${CT_LOG_LEVEL_DEBUG}
yann@1
    67
yann@47
    68
    LEVEL="$1"; shift
yann@1
    69
    eval level="\${CT_LOG_LEVEL_${LEVEL}}"
yann@1
    70
yann@1
    71
    if [ $# -eq 0 ]; then
yann@1
    72
        cat -
yann@1
    73
    else
yann@1
    74
        echo "${1}"
yann@1
    75
    fi |( IFS="\n" # We want the full lines, even leading spaces
yann@1
    76
          cpt=0
yann@1
    77
          indent=$((2*CT_STEP_COUNT))
yann@1
    78
          while read line; do
yann@47
    79
              case "${CT_LOG_SEE_TOOLS_WARN},${line}" in
yann@47
    80
                y,*"warning:"*)         cur_L=WARN; cur_l=${CT_LOG_LEVEL_WARN};;
yann@47
    81
                *"error:"*)             cur_L=ERROR; cur_l=${CT_LOG_LEVEL_ERROR};;
yann@47
    82
                "make["?*"]:"*"Stop.")  cur_L=ERROR; cur_l=${CT_LOG_LEVEL_ERROR};;
yann@47
    83
                *)                      cur_L="${LEVEL}"; cur_l="${level}";;
yann@47
    84
              esac
yann@47
    85
              l="`printf \"[%-5s]%*s%s%s\" \"${cur_L}\" \"${indent}\" \" \" \"${line}\"`"
yann@1
    86
              # There will always be a log file, be it /dev/null
yann@1
    87
              echo -e "${l}" >>"${CT_ACTUAL_LOG_FILE}"
yann@47
    88
              color="CT_${cur_L}_COLOR"
yann@1
    89
              normal="CT_NORMAL_COLOR"
yann@47
    90
              if [ ${cur_l} -le ${max_level} ]; then
yann@76
    91
                  echo -e "\r${!color}${l}${!normal}"
yann@1
    92
              else
yann@1
    93
                  ${CT_PROG_BAR}
yann@1
    94
              fi
yann@1
    95
          done
yann@1
    96
        )
yann@1
    97
yann@1
    98
    return 0
yann@1
    99
}
yann@1
   100
yann@1
   101
# Abort the execution with a error message
yann@1
   102
# Usage: CT_Abort <message>
yann@1
   103
CT_Abort() {
yann@1
   104
    CT_DoLog ERROR "$1" >&2
yann@1
   105
    exit 1
yann@1
   106
}
yann@1
   107
yann@1
   108
# Test a condition, and print a message if satisfied
yann@1
   109
# Usage: CT_Test <message> <tests>
yann@1
   110
CT_Test() {
yann@1
   111
    local ret
yann@1
   112
    local m="$1"
yann@1
   113
    shift
yann@1
   114
    test "$@" && CT_DoLog WARN "$m"
yann@1
   115
    return 0
yann@1
   116
}
yann@1
   117
yann@1
   118
# Test a condition, and abort with an error message if satisfied
yann@1
   119
# Usage: CT_TestAndAbort <message> <tests>
yann@1
   120
CT_TestAndAbort() {
yann@1
   121
    local m="$1"
yann@1
   122
    shift
yann@1
   123
    test "$@" && CT_Abort "$m"
yann@1
   124
    return 0
yann@1
   125
}
yann@1
   126
yann@1
   127
# Test a condition, and abort with an error message if not satisfied
yann@1
   128
# Usage: CT_TestAndAbort <message> <tests>
yann@1
   129
CT_TestOrAbort() {
yann@1
   130
    local m="$1"
yann@1
   131
    shift
yann@1
   132
    test "$@" || CT_Abort "$m"
yann@1
   133
    return 0
yann@1
   134
}
yann@1
   135
yann@1
   136
# Test the presence of a tool, or abort if not found
yann@1
   137
# Usage: CT_HasOrAbort <tool>
yann@1
   138
CT_HasOrAbort() {
yann@1
   139
    CT_TestAndAbort "\"${1}\" not found and needed for successfull toolchain build." -z "`which \"${1}\"`"
yann@1
   140
    return 0
yann@1
   141
}
yann@1
   142
yann@1
   143
# Get current date with nanosecond precision
yann@1
   144
# On those system not supporting nanosecond precision, faked with rounding down
yann@1
   145
# to the highest entire second
yann@1
   146
# Usage: CT_DoDate <fmt>
yann@1
   147
CT_DoDate() {
yann@1
   148
    date "$1" |sed -r -e 's/%N$/000000000/;'
yann@1
   149
}
yann@1
   150
yann@1
   151
CT_STEP_COUNT=1
yann@1
   152
CT_STEP_MESSAGE[${CT_STEP_COUNT}]="<none>"
yann@1
   153
# Memorise a step being done so that any error is caught
yann@1
   154
# Usage: CT_DoStep <loglevel> <message>
yann@1
   155
CT_DoStep() {
yann@1
   156
    local start=`CT_DoDate +%s%N`
yann@1
   157
    CT_DoLog "$1" "================================================================="
yann@1
   158
    CT_DoLog "$1" "$2"
yann@1
   159
    CT_STEP_COUNT=$((CT_STEP_COUNT+1))
yann@1
   160
    CT_STEP_LEVEL[${CT_STEP_COUNT}]="$1"; shift
yann@1
   161
    CT_STEP_START[${CT_STEP_COUNT}]="${start}"
yann@1
   162
    CT_STEP_MESSAGE[${CT_STEP_COUNT}]="$1"
yann@1
   163
    return 0
yann@1
   164
}
yann@1
   165
yann@1
   166
# End the step just being done
yann@1
   167
# Usage: CT_EndStep
yann@1
   168
CT_EndStep() {
yann@1
   169
    local stop=`CT_DoDate +%s%N`
yann@1
   170
    local duration=`printf "%032d" $((stop-${CT_STEP_START[${CT_STEP_COUNT}]})) |sed -r -e 's/([[:digit:]]{2})[[:digit:]]{7}$/\.\1/; s/^0+//; s/^\./0\./;'`
yann@1
   171
    local level="${CT_STEP_LEVEL[${CT_STEP_COUNT}]}"
yann@1
   172
    local message="${CT_STEP_MESSAGE[${CT_STEP_COUNT}]}"
yann@1
   173
    CT_STEP_COUNT=$((CT_STEP_COUNT-1))
yann@1
   174
    CT_DoLog "${level}" "${message}: done in ${duration}s"
yann@1
   175
    return 0
yann@1
   176
}
yann@1
   177
yann@1
   178
# Pushes into a directory, and pops back
yann@1
   179
CT_Pushd() {
yann@1
   180
    pushd "$1" >/dev/null 2>&1
yann@1
   181
}
yann@1
   182
CT_Popd() {
yann@1
   183
    popd >/dev/null 2>&1
yann@1
   184
}
yann@1
   185
yann@1
   186
# Makes a path absolute
yann@1
   187
# Usage: CT_MakeAbsolutePath path
yann@1
   188
CT_MakeAbsolutePath() {
yann@1
   189
    # Try to cd in that directory
yann@1
   190
    if [ -d "$1" ]; then
yann@1
   191
        CT_Pushd "$1"
yann@1
   192
        pwd
yann@1
   193
        CT_Popd
yann@1
   194
    else
yann@1
   195
        # No such directory, fail back to guessing
yann@1
   196
        case "$1" in
yann@1
   197
            /*)  echo "$1";;
yann@1
   198
            *)   echo "`pwd`/$1";;
yann@1
   199
        esac
yann@1
   200
    fi
yann@1
   201
    
yann@1
   202
    return 0
yann@1
   203
}
yann@1
   204
yann@1
   205
# Creates a temporary directory
yann@1
   206
# $1: variable to assign to
yann@1
   207
# Usage: CT_MktempDir foo
yann@1
   208
CT_MktempDir() {
yann@1
   209
    # Some mktemp do not allow more than 6 Xs
yann@1
   210
    eval "$1"="`mktemp -q -d \"${CT_BUILD_DIR}/.XXXXXX\"`"
yann@1
   211
    CT_TestOrAbort "Could not make temporary directory" -n "${!1}" -a -d "${!1}"
yann@1
   212
}
yann@1
   213
yann@1
   214
# Echoes the specified string on stdout until the pipe breaks.
yann@1
   215
# Doesn't fail
yann@1
   216
# $1: string to echo
yann@1
   217
# Usage: CT_DoYes "" |make oldconfig
yann@1
   218
CT_DoYes() {
yann@1
   219
    yes "$1" || true
yann@1
   220
}
yann@63
   221
yann@63
   222
# Download an URL using wget
yann@63
   223
# Usage: CT_DoGetFileWget <URL>
yann@63
   224
CT_DoGetFileWget() {
yann@63
   225
    # Need to return true because it is legitimate to not find the tarball at
yann@63
   226
    # some of the provided URLs (think about snapshots, different layouts for
yann@63
   227
    # different gcc versions, etc...)
yann@63
   228
    # Some (very old!) FTP server might not support the passive mode, thus
yann@63
   229
    # retry without
yann@63
   230
    # With automated download as we are doing, it can be very dangerous to use
yann@63
   231
    # -c to continue the downloads. It's far better to simply overwrite the
yann@63
   232
    # destination file
yann@63
   233
    wget -nc --progress=dot:binary --tries=3 --passive-ftp "$1" || wget -nc --progress=dot:binary --tries=3 "$1" || true
yann@63
   234
}
yann@63
   235
yann@63
   236
# Download an URL using curl
yann@63
   237
# Usage: CT_DoGetFileCurl <URL>
yann@63
   238
CT_DoGetFileCurl() {
yann@63
   239
	# Note: comments about wget method are also valid here
yann@63
   240
	# Plus: no good progreess indicator is available with curl,
yann@63
   241
	#       so output is consigned to oblivion
yann@63
   242
	curl --ftp-pasv -O --retry 3 "$1" >/dev/null || curl -O --retry 3 "$1" >/dev/null || true
yann@63
   243
}
yann@63
   244
yann@63
   245
# Wrapper function to call one of curl or wget
yann@63
   246
# Usage: CT_DoGetFile <URL>
yann@63
   247
CT_DoGetFile() {
yann@63
   248
    local _wget=`which wget`
yann@63
   249
    local _curl=`which curl`
yann@63
   250
    case "${_wget},${_curl}" in
yann@63
   251
        ,)  CT_DoError "Could find neither wget nor curl";;
yann@63
   252
        ,*) CT_DoGetFileCurl "$1";;
yann@63
   253
        *)  CT_DoGetFileWget "$1";;
yann@63
   254
    esac
yann@63
   255
}
yann@63
   256
yann@63
   257
# Download the file from one of the URLs passed as argument
yann@63
   258
# Usage: CT_GetFile <filename> <url> [<url> ...]
yann@63
   259
CT_GetFile() {
yann@63
   260
    local got_it
yann@63
   261
    local ext
yann@63
   262
    local url
yann@63
   263
    local file="$1"
yann@63
   264
    shift
yann@63
   265
yann@63
   266
    # Do we already have it?
yann@63
   267
    ext=`CT_GetFileExtension "${file}"`
yann@63
   268
    if [ -n "${ext}" ]; then
yann@63
   269
        if [ "${CT_FORCE_DOWNLOAD}" = "y" ]; then
yann@76
   270
            CT_DoLog DEBUG "Removing already present \"${file}\""
yann@63
   271
            rm -f "${CT_TARBALLS_DIR}/${file}${ext}"
yann@63
   272
        else
yann@76
   273
            CT_DoLog EXTRA "Already have \"${file}\""
yann@63
   274
            return 0
yann@63
   275
        fi
yann@63
   276
    fi
yann@63
   277
yann@63
   278
    CT_DoLog EXTRA "Retrieving \"${file}\""
yann@63
   279
    CT_Pushd "${CT_TARBALLS_DIR}"
yann@63
   280
    # File not yet downloaded, try to get it
yann@63
   281
    got_it=0
yann@63
   282
    if [ "${got_it}" != "y" ]; then
yann@63
   283
        # We'd rather have a bzip2'ed tarball, then gzipped, and finally plain tar.
yann@63
   284
        for ext in .tar.bz2 .tar.gz .tgz .tar; do
yann@63
   285
            # Try all urls in turn
yann@63
   286
            for url in "$@"; do
yann@63
   287
                case "${url}" in
yann@63
   288
                    *)  CT_DoLog EXTRA "Trying \"${url}/${file}${ext}\""
yann@63
   289
                        CT_DoGetFile "${url}/${file}${ext}" 2>&1 |CT_DoLog DEBUG
yann@63
   290
                        ;;
yann@63
   291
                esac
yann@63
   292
                [ -f "${file}${ext}" ] && got_it=1 && break 2 || true
yann@63
   293
            done
yann@63
   294
        done
yann@63
   295
    fi
yann@63
   296
    CT_Popd
yann@63
   297
yann@63
   298
    CT_TestAndAbort "Could not download \"${file}\", and not present in \"${CT_TARBALLS_DIR}\"" ${got_it} -eq 0
yann@63
   299
}
yann@63
   300
yann@63
   301
# Get the file name extension of a component
yann@63
   302
# Usage: CT_GetFileExtension <component_name-component_version>
yann@63
   303
# If found, echoes the extension to stdout
yann@63
   304
# If not found, echoes nothing on stdout.
yann@63
   305
CT_GetFileExtension() {
yann@63
   306
    local ext
yann@63
   307
    local file="$1"
yann@63
   308
    local got_it=1
yann@63
   309
yann@63
   310
    CT_Pushd "${CT_TARBALLS_DIR}"
yann@63
   311
    for ext in .tar.gz .tar.bz2 .tgz .tar; do
yann@63
   312
        if [ -f "${file}${ext}" ]; then
yann@63
   313
            echo "${ext}"
yann@63
   314
            got_it=0
yann@63
   315
            break
yann@63
   316
        fi
yann@63
   317
    done
yann@63
   318
    CT_Popd
yann@63
   319
yann@63
   320
    return 0
yann@63
   321
}
yann@63
   322
yann@63
   323
# Extract a tarball and patch the resulting sources if necessary.
yann@63
   324
# Some tarballs need to be extracted in specific places. Eg.: glibc addons
yann@63
   325
# must be extracted in the glibc directory; uCLibc locales must be extracted
yann@63
   326
# in the extra/locale sub-directory of uClibc.
yann@63
   327
CT_ExtractAndPatch() {
yann@63
   328
    local file="$1"
yann@63
   329
    local base_file=`echo "${file}" |cut -d - -f 1`
yann@63
   330
    local ver_file=`echo "${file}" |cut -d - -f 2-`
yann@63
   331
    local official_patch_dir
yann@63
   332
    local custom_patch_dir
yann@63
   333
    local libc_addon
yann@63
   334
    local ext=`CT_GetFileExtension "${file}"`
yann@63
   335
    CT_TestAndAbort "\"${file}\" not found in \"${CT_TARBALLS_DIR}\"" -z "${ext}"
yann@63
   336
    local full_file="${CT_TARBALLS_DIR}/${file}${ext}"
yann@63
   337
yann@63
   338
    CT_Pushd "${CT_SRC_DIR}"
yann@63
   339
yann@63
   340
    # Add-ons need a little love, really.
yann@63
   341
    case "${file}" in
yann@63
   342
        glibc-[a-z]*-*)
yann@63
   343
            CT_TestAndAbort "Trying to extract the C-library addon/locales \"${file}\" when C-library not yet extracted" ! -d "${CT_LIBC_FILE}"
yann@63
   344
            cd "${CT_LIBC_FILE}"
yann@63
   345
            libc_addon=y
yann@63
   346
            [ -f ".${file}.extracted" ] && return 0
yann@63
   347
            touch ".${file}.extracted"
yann@63
   348
            ;;
yann@63
   349
        uClibc-locale-*)
yann@63
   350
            CT_TestAndAbort "Trying to extract the C-library addon/locales \"${file}\" when C-library not yet extracted" ! -d "${CT_LIBC_FILE}"
yann@63
   351
            cd "${CT_LIBC_FILE}/extra/locale"
yann@63
   352
            libc_addon=y
yann@63
   353
            [ -f ".${file}.extracted" ] && return 0
yann@63
   354
            touch ".${file}.extracted"
yann@63
   355
            ;;
yann@63
   356
    esac
yann@63
   357
yann@63
   358
    # If the directory exists, then consider extraction and patching done
yann@63
   359
    [ -d "${file}" ] && return 0
yann@63
   360
yann@63
   361
    CT_DoLog EXTRA "Extracting \"${file}\""
yann@63
   362
    case "${ext}" in
yann@63
   363
        .tar.bz2)     tar xvjf "${full_file}" |CT_DoLog DEBUG;;
yann@63
   364
        .tar.gz|.tgz) tar xvzf "${full_file}" |CT_DoLog DEBUG;;
yann@63
   365
        .tar)         tar xvf  "${full_file}" |CT_DoLog DEBUG;;
yann@63
   366
        *)            CT_Abort "Don't know how to handle \"${file}\": unknown extension" ;;
yann@63
   367
    esac
yann@63
   368
yann@63
   369
    # Snapshots might not have the version number in the extracted directory
yann@63
   370
    # name. This is also the case for some (old) packages, such as libfloat.
yann@63
   371
    # Overcome this issue by symlink'ing the directory.
yann@63
   372
    if [ ! -d "${file}" -a "${libc_addon}" != "y" ]; then
yann@63
   373
        case "${ext}" in
yann@63
   374
            .tar.bz2)     base=`tar tjf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;;
yann@63
   375
            .tar.gz|.tgz) base=`tar tzf "${full_file}" |head -n 1 |cut -d / -f 1 || true`;;
yann@63
   376
            .tar)         base=`tar tf  "${full_file}" |head -n 1 |cut -d / -f 1 || true`;;
yann@63
   377
        esac
yann@63
   378
        CT_TestOrAbort "There was a problem when extracting \"${file}\"" -d "${base}" -o "${base}" != "${file}"
yann@63
   379
        ln -s "${base}" "${file}"
yann@63
   380
    fi
yann@63
   381
yann@63
   382
    # Kludge: outside this function, we wouldn't know if we had just extracted
yann@63
   383
    # a libc addon, or a plain package. Apply patches now.
yann@63
   384
    CT_DoLog EXTRA "Patching \"${file}\""
yann@63
   385
yann@63
   386
    # If libc addon, we're already in the correct place.
yann@63
   387
    [ -z "${libc_addon}" ] && cd "${file}"
yann@63
   388
yann@63
   389
    [ "${CUSTOM_PATCH_ONLY}" = "y" ] || official_patch_dir="${CT_TOP_DIR}/patches/${base_file}/${ver_file}"
yann@63
   390
    [ "${CT_CUSTOM_PATCH}" = "y" ] && custom_patch_dir="${CT_CUSTOM_PATCH_DIR}/${base_file}/${ver_file}"
yann@63
   391
    for patch_dir in "${official_patch_dir}" "${custom_patch_dir}"; do
yann@63
   392
        if [ -n "${patch_dir}" -a -d "${patch_dir}" ]; then
yann@63
   393
            for p in "${patch_dir}"/*.patch; do
yann@63
   394
                if [ -f "${p}" ]; then
yann@63
   395
                    CT_DoLog DEBUG "Applying patch \"${p}\""
yann@63
   396
                    patch -g0 -F1 -p1 -f <"${p}" |CT_DoLog DEBUG
yann@63
   397
                    CT_TestAndAbort "Failed while applying patch file \"${p}\"" ${PIPESTATUS[0]} -ne 0
yann@63
   398
                fi
yann@63
   399
            done
yann@63
   400
        fi
yann@63
   401
    done
yann@63
   402
yann@63
   403
    CT_Popd
yann@63
   404
}
yann@63
   405
yann@63
   406
# Compute the target triplet from what is provided by the user
yann@63
   407
# Usage: CT_DoBuildTargetTriplet
yann@63
   408
# In fact this function takes the environment variables to build the target
yann@63
   409
# triplet. It is needed both by the normal build sequence, as well as the
yann@63
   410
# sample saving sequence.
yann@63
   411
CT_DoBuildTargetTriplet() {
yann@63
   412
    case "${CT_ARCH_BE},${CT_ARCH_LE}" in
yann@63
   413
        y,) target_endian_eb=eb; target_endian_el=;;
yann@63
   414
        ,y) target_endian_eb=; target_endian_el=el;;
yann@63
   415
    esac
yann@63
   416
    case "${CT_ARCH}" in
yann@63
   417
        arm)  CT_TARGET="${CT_ARCH}${target_endian_eb}";;
yann@63
   418
        mips) CT_TARGET="${CT_ARCH}${target_endian_el}";;
yann@63
   419
        x86*) # Much love for this one :-(
yann@63
   420
              # Ultimately, we should use config.sub to output the correct
yann@63
   421
              # procesor name. Work for later...
yann@63
   422
              arch="${CT_ARCH_ARCH}"
yann@63
   423
              [ -z "${arch}" ] && arch="${CT_ARCH_TUNE}"
yann@63
   424
              case "${CT_ARCH}" in
yann@63
   425
                  x86_64)      CT_TARGET=x86_64;;
yann@63
   426
              	  *)  case "${arch}" in
yann@63
   427
                          "")                                       CT_TARGET=i386;;
yann@63
   428
                          i386|i486|i586|i686)                      CT_TARGET="${arch}";;
yann@63
   429
                          winchip*)                                 CT_TARGET=i486;;
yann@63
   430
                          pentium|pentium-mmx|c3*)                  CT_TARGET=i586;;
yann@63
   431
                          nocona|athlon*64|k8|athlon-fx|opteron)    CT_TARGET=x86_64;;
yann@63
   432
                          pentiumpro|pentium*|athlon*)              CT_TARGET=i686;;
yann@63
   433
                          *)                                        CT_TARGET=i586;;
yann@63
   434
                      esac;;
yann@63
   435
              esac;;
yann@63
   436
    esac
yann@63
   437
    case "${CT_TARGET_VENDOR}" in
yann@63
   438
        "") CT_TARGET="${CT_TARGET}-unknown";;
yann@63
   439
        *)  CT_TARGET="${CT_TARGET}-${CT_TARGET_VENDOR}";;
yann@63
   440
    esac
yann@63
   441
    case "${CT_KERNEL}" in
yann@63
   442
        linux*)  CT_TARGET="${CT_TARGET}-linux";;
yann@63
   443
        cygwin*) CT_TARGET="${CT_TARGET}-cygwin";;
yann@63
   444
    esac
yann@63
   445
    case "${CT_LIBC}" in
yann@63
   446
        glibc)  CT_TARGET="${CT_TARGET}-gnu";;
yann@63
   447
        uClibc) CT_TARGET="${CT_TARGET}-uclibc";;
yann@63
   448
    esac
yann@63
   449
    case "${CT_ARCH_ABI}" in
yann@63
   450
        eabi)   CT_TARGET="${CT_TARGET}eabi";;
yann@63
   451
    esac
yann@63
   452
    CT_TARGET="`${CT_TOP_DIR}/tools/config.sub ${CT_TARGET}`"
yann@63
   453
}