scripts/build/binutils/binutils.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun May 11 15:43:28 2014 +0200 (2014-05-11)
changeset 3315 464128a8fc3f
parent 3290 bddc642fc8eb
child 3316 42590ff8521c
permissions -rw-r--r--
binutils/elf2flt: use alternate mirror

The official elf2flt upstream has disapeared.

Switch to a mirror.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
yann@1345
     1
# This file adds functions to build binutils
yann@1345
     2
# Copyright 2007 Yann E. MORIN
yann@1345
     3
# Licensed under the GPL v2. See COPYING in the root of this package
yann@1345
     4
yann@1345
     5
# Download binutils
yann@1345
     6
do_binutils_get() {
david@3089
     7
    if [ "${CT_BINUTILS_CUSTOM}" = "y" ]; then
david@3089
     8
        CT_GetCustom "binutils" "${CT_BINUTILS_VERSION}" \
david@3089
     9
                     "${CT_BINUTILS_CUSTOM_LOCATION}"
david@3089
    10
    else
david@3089
    11
        CT_GetFile "binutils-${CT_BINUTILS_VERSION}"                                        \
david@3089
    12
                   {ftp,http}://{ftp.gnu.org/gnu,ftp.kernel.org/pub/linux/devel}/binutils   \
david@3089
    13
                   ftp://gcc.gnu.org/pub/binutils/{releases,snapshots}
david@3089
    14
    fi
diorcet@3123
    15
diorcet@3123
    16
    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
yann@3315
    17
        CT_GetGit elf2flt "${CT_ELF2FLT_GIT_CSET}" git://wh0rd.org/elf2flt.git
diorcet@3123
    18
    fi
yann@1345
    19
}
yann@1345
    20
yann@1345
    21
# Extract binutils
yann@1345
    22
do_binutils_extract() {
david@3089
    23
    # If using custom directory location, nothing to do
david@3089
    24
    if [ "${CT_BINUTILS_CUSTOM}" = "y" \
david@3089
    25
         -a -d "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" ]; then
david@3089
    26
        return 0
david@3089
    27
    fi
david@3089
    28
yann@1345
    29
    CT_Extract "binutils-${CT_BINUTILS_VERSION}"
yann@1901
    30
    CT_Patch "binutils" "${CT_BINUTILS_VERSION}"
diorcet@3123
    31
diorcet@3123
    32
    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
yann@3315
    33
        CT_Extract "elf2flt-${CT_ELF2FLT_GIT_CSET}"
yann@3315
    34
        CT_Patch "elf2flt" "${CT_ELF2FLT_GIT_CSET}"
diorcet@3123
    35
    fi
yann@1345
    36
}
yann@1345
    37
yann@2928
    38
# Build binutils for build -> target
yann@2928
    39
do_binutils_for_build() {
yann@2928
    40
    local -a binutils_opts
yann@2928
    41
yann@2928
    42
    case "${CT_TOOLCHAIN_TYPE}" in
yann@2928
    43
        native|cross)   return 0;;
yann@2928
    44
    esac
yann@2928
    45
yann@2928
    46
    CT_DoStep INFO "Installing binutils for build"
yann@2928
    47
    CT_mkdir_pushd "${CT_BUILD_DIR}/build-binutils-build-${CT_BUILD}"
yann@2928
    48
yann@2928
    49
    binutils_opts+=( "host=${CT_BUILD}" )
yann@2928
    50
    binutils_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
diorcet@3119
    51
    binutils_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
diorcet@3119
    52
    binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
yann@2928
    53
yann@2928
    54
    do_binutils_backend "${binutils_opts[@]}"
yann@2928
    55
yann@2928
    56
    CT_Popd
diorcet@3123
    57
diorcet@3123
    58
    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
diorcet@3123
    59
        # We re-use binutils' options, plus our owns
diorcet@3123
    60
        binutils_opts+=( "binutils_src=${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" )
diorcet@3123
    61
        binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-build-${CT_BUILD}" )
diorcet@3123
    62
diorcet@3123
    63
        CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-build-${CT_BUILD}"
diorcet@3123
    64
diorcet@3123
    65
        do_elf2flt_backend "${binutils_opts[@]}"
diorcet@3123
    66
diorcet@3123
    67
        CT_Popd
diorcet@3123
    68
    fi
diorcet@3123
    69
yann@2928
    70
    CT_EndStep
yann@2928
    71
}
yann@2928
    72
yann@2926
    73
# Build binutils for host -> target
yann@2926
    74
do_binutils_for_host() {
yann@2926
    75
    local -a binutils_tools
yann@2926
    76
    local -a binutils_opts
yann@2926
    77
yann@2926
    78
    CT_DoStep INFO "Installing binutils for host"
yann@2926
    79
    CT_mkdir_pushd "${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}"
yann@2926
    80
yann@2926
    81
    binutils_opts+=( "host=${CT_HOST}" )
yann@2926
    82
    binutils_opts+=( "prefix=${CT_PREFIX_DIR}" )
yann@2926
    83
    binutils_opts+=( "static_build=${CT_STATIC_TOOLCHAIN}" )
yann@2926
    84
    binutils_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
diorcet@3119
    85
    binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
yann@2926
    86
    binutils_opts+=( "build_manuals=${CT_BUILD_MANUALS}" )
yann@2926
    87
yann@2926
    88
    do_binutils_backend "${binutils_opts[@]}"
yann@2926
    89
diorcet@3123
    90
    CT_Popd
diorcet@3123
    91
diorcet@3123
    92
    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
diorcet@3123
    93
        # We re-use binutils' options, plus our owns
diorcet@3123
    94
        binutils_opts+=( "binutils_src=${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" )
diorcet@3123
    95
        binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}" )
diorcet@3123
    96
diorcet@3123
    97
        CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-host-${CT_HOST}"
diorcet@3123
    98
diorcet@3123
    99
        do_elf2flt_backend "${binutils_opts[@]}"
diorcet@3123
   100
diorcet@3123
   101
        CT_Popd
diorcet@3123
   102
    fi
diorcet@3123
   103
yann@2926
   104
    # Make those new tools available to the core C compilers to come.
mingw@3290
   105
    # Note: some components want the ${TARGET}-{ar,as,ld,ranlib,strip} commands
mingw@3290
   106
    # as well. Create that.
yann@2926
   107
    # Don't do it for canadian or cross-native, because the binutils
yann@2926
   108
    # are not executable on the build machine.
yann@2926
   109
    case "${CT_TOOLCHAIN_TYPE}" in
yann@2926
   110
        cross|native)
mingw@3290
   111
            binutils_tools=( ar as ld ranlib strip )
diorcet@3123
   112
            if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
diorcet@3123
   113
                binutils_tools+=( elf2flt flthdr )
diorcet@3123
   114
            fi
yann@2926
   115
            case "${CT_BINUTILS_LINKERS_LIST}" in
yann@2926
   116
                ld)         binutils_tools+=( ld.bfd ) ;;
yann@2926
   117
                gold)       binutils_tools+=( ld.gold ) ;;
yann@2926
   118
                ld,gold)    binutils_tools+=( ld.bfd ld.gold ) ;;
yann@2926
   119
                gold,ld)    binutils_tools+=( ld.bfd ld.gold ) ;;
yann@2926
   120
            esac
yann@2926
   121
            mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin"
yann@2926
   122
            mkdir -p "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
yann@2926
   123
            for t in "${binutils_tools[@]}"; do
yann@2926
   124
                CT_DoExecLog ALL ln -sv                                         \
yann@2926
   125
                                    "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}"    \
yann@2926
   126
                                    "${CT_BUILDTOOLS_PREFIX_DIR}/${CT_TARGET}/bin/${t}"
yann@2926
   127
                CT_DoExecLog ALL ln -sv                                         \
yann@2926
   128
                                    "${CT_PREFIX_DIR}/bin/${CT_TARGET}-${t}"    \
yann@2926
   129
                                    "${CT_BUILDTOOLS_PREFIX_DIR}/bin/${CT_TARGET}-${t}"
yann@2926
   130
            done
yann@2926
   131
            ;;
yann@2926
   132
        *)  ;;
yann@2926
   133
    esac
yann@2926
   134
yann@2926
   135
    CT_EndStep
yann@2926
   136
}
yann@2926
   137
yann@2926
   138
# Build binutils for X -> target
yann@2926
   139
#     Parameter     : description               : type      : default
yann@2926
   140
#     host          : machine to run on         : tuple     : (none)
yann@2926
   141
#     prefix        : prefix to install into    : dir       : (none)
yann@2926
   142
#     static_build  : build statcially          : bool      : no
diorcet@3119
   143
#     cflags        : cflags to use             : string    : (empty)
diorcet@3119
   144
#     ldflags       : ldflags to use            : string    : (empty)
yann@2926
   145
#     build_manuals : whether to build manuals  : bool      : no
yann@2926
   146
do_binutils_backend() {
yann@2926
   147
    local host
yann@2926
   148
    local prefix
yann@2926
   149
    local static_build
yann@2926
   150
    local cflags
diorcet@3119
   151
    local ldflags
yann@2926
   152
    local build_manuals=no
yann@1483
   153
    local -a extra_config
bryanhundven@2210
   154
    local -a extra_make_flags
michael@2765
   155
    local -a manuals_for
michael@2765
   156
    local -a manuals_install
yann@2926
   157
    local arg
yann@1483
   158
yann@2926
   159
    for arg in "$@"; do
yann@2926
   160
        eval "${arg// /\\ }"
yann@2926
   161
    done
yann@1345
   162
yann@1345
   163
    CT_DoLog EXTRA "Configuring binutils"
yann@2244
   164
yann@2244
   165
    if [ "${CT_BINUTILS_HAS_GOLD}" = "y" ]; then
yann@2244
   166
        case "${CT_BINUTILS_LINKERS_LIST}" in
yann@2244
   167
            ld)
yann@2244
   168
                extra_config+=( --enable-ld=yes --enable-gold=no )
yann@2244
   169
                ;;
yann@2244
   170
            gold)
yann@2244
   171
                extra_config+=( --enable-ld=no --enable-gold=yes )
yann@2244
   172
                ;;
yann@2244
   173
            ld,gold)
yann@2244
   174
                extra_config+=( --enable-ld=default --enable-gold=yes )
yann@2244
   175
                ;;
yann@2244
   176
            gold,ld)
yann@2244
   177
                extra_config+=( --enable-ld=yes --enable-gold=default )
yann@2244
   178
                ;;
yann@2244
   179
        esac
zhenqiang@3032
   180
        if [ "${CT_BINUTILS_GOLD_THREADS}" = "y" ]; then
yann@2246
   181
            extra_config+=( --enable-threads )
yann@2246
   182
        fi
yann@2244
   183
    fi
yann@2245
   184
    if [ "${CT_BINUTILS_PLUGINS}" = "y" ]; then
yann@2245
   185
        extra_config+=( --enable-plugins )
yann@2245
   186
    fi
benoit@2488
   187
    if [ "${CT_BINUTILS_HAS_PKGVERSION_BUGURL}" = "y" ]; then
benoit@2503
   188
        extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
benoit@2503
   189
        [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
benoit@2488
   190
    fi
yann@2816
   191
    if [ "${CT_MULTILIB}" = "y" ]; then
yann@2816
   192
        extra_config+=("--enable-multilib")
yann@2816
   193
    else
yann@2816
   194
        extra_config+=("--disable-multilib")
yann@2816
   195
    fi
yann@2244
   196
zhenqiang@2779
   197
    [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
zhenqiang@2779
   198
yann@2244
   199
    CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
yann@2244
   200
yann@2341
   201
    CT_DoExecLog CFG                                            \
yann@2926
   202
    CFLAGS="${cflags}"                                          \
yann@2926
   203
    CXXFLAGS="${cflags}"                                        \
diorcet@3119
   204
    LDFLAGS="${ldflags}"                                        \
yann@1345
   205
    "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
yann@1345
   206
        --build=${CT_BUILD}                                     \
yann@2926
   207
        --host=${host}                                          \
yann@1345
   208
        --target=${CT_TARGET}                                   \
yann@2926
   209
        --prefix=${prefix}                                      \
yann@1345
   210
        --disable-werror                                        \
yann@1483
   211
        "${extra_config[@]}"                                    \
yann@1345
   212
        ${CT_ARCH_WITH_FLOAT}                                   \
yann@2466
   213
        ${BINUTILS_SYSROOT_ARG}                                 \
yann@2467
   214
        "${CT_BINUTILS_EXTRA_CONFIG_ARRAY[@]}"
yann@1345
   215
yann@2926
   216
    if [ "${static_build}" = "y" ]; then
yann@2702
   217
        extra_make_flags+=("LDFLAGS=-static -all-static")
bryanhundven@2210
   218
        CT_DoLog EXTRA "Prepare binutils for static build"
yann@2702
   219
        CT_DoExecLog ALL make ${JOBSFLAGS} configure-host
bryanhundven@2210
   220
    fi
bryanhundven@2210
   221
yann@1345
   222
    CT_DoLog EXTRA "Building binutils"
yann@2275
   223
    CT_DoExecLog ALL make "${extra_make_flags[@]}" ${JOBSFLAGS}
yann@1345
   224
yann@1345
   225
    CT_DoLog EXTRA "Installing binutils"
yann@1345
   226
    CT_DoExecLog ALL make install
yann@1345
   227
yann@2926
   228
    if [ "${build_manuals}" = "y" ]; then
michael@2765
   229
        CT_DoLog EXTRA "Building and installing the binutils manuals"
michael@2765
   230
        manuals_for=( gas binutils ld gprof )
michael@2765
   231
        if [ "${CT_BINUTILS_LINKER_GOLD}" = "y" ]; then
michael@2765
   232
            manuals_for+=( gold )
michael@2765
   233
        fi
michael@2765
   234
        manuals_install=( "${manuals_for[@]/#/install-pdf-}" )
michael@2765
   235
        manuals_install+=( "${manuals_for[@]/#/install-html-}" )
michael@2765
   236
        CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
michael@2765
   237
        CT_DoExecLog ALL make "${manuals_install[@]}"
michael@2765
   238
    fi
michael@2765
   239
yann@2247
   240
    # Install the wrapper if needed
yann@2247
   241
    if [ "${CT_BINUTILS_LD_WRAPPER}" = "y" ]; then
yann@2247
   242
        CT_DoLog EXTRA "Installing ld wrapper"
yann@2926
   243
        rm -f "${prefix}/bin/${CT_TARGET}-ld"
yann@2926
   244
        rm -f "${prefix}/${CT_TARGET}/bin/ld"
yann@2247
   245
        sed -r -e "s/@@DEFAULT_LD@@/${CT_BINUTILS_LINKER_DEFAULT}/" \
yann@2247
   246
            "${CT_LIB_DIR}/scripts/build/binutils/binutils-ld.in"   \
yann@2926
   247
            >"${prefix}/bin/${CT_TARGET}-ld"
yann@2926
   248
        chmod +x "${prefix}/bin/${CT_TARGET}-ld"
yann@2926
   249
        cp -a "${prefix}/bin/${CT_TARGET}-ld"   \
yann@2926
   250
              "${prefix}/${CT_TARGET}/bin/ld"
yann@2376
   251
yann@2376
   252
        # If needed, force using ld.bfd during the toolchain build
yann@2376
   253
        if [ "${CT_BINUTILS_FORCE_LD_BFD}" = "y" ]; then
yann@2376
   254
            export CTNG_LD_IS=bfd
yann@2376
   255
        fi
yann@2247
   256
    fi
yann@1345
   257
}
yann@1345
   258
diorcet@3123
   259
# Build elf2flt for X -> target
diorcet@3123
   260
#     Parameter     : description               : type      : default
diorcet@3123
   261
#     host          : machine to run on         : tuple     : (none)
diorcet@3123
   262
#     prefix        : prefix to install into    : dir       : (none)
diorcet@3123
   263
#     static_build  : build statcially          : bool      : no
diorcet@3123
   264
#     cflags        : cflags to use             : string    : (empty)
diorcet@3123
   265
#     ldflags       : ldflags to use            : string    : (empty)
diorcet@3123
   266
#     binutils_src  : source dir of binutils    : dir       : (none)
diorcet@3123
   267
#     binutils_bld  : build dir of binutils     : dir       : (none)
diorcet@3123
   268
#     build_manuals : whether to build manuals  : bool      : no
diorcet@3123
   269
do_elf2flt_backend() {
diorcet@3123
   270
    local host
diorcet@3123
   271
    local prefix
diorcet@3123
   272
    local static_build
diorcet@3123
   273
    local cflags
diorcet@3123
   274
    local ldflags
diorcet@3123
   275
    local binutils_bld
diorcet@3123
   276
    local binutils_src
diorcet@3123
   277
    local build_manuals
diorcet@3123
   278
    local arg
diorcet@3123
   279
diorcet@3123
   280
    for arg in "$@"; do
diorcet@3123
   281
        eval "${arg// /\\ }"
diorcet@3123
   282
    done
diorcet@3123
   283
diorcet@3123
   284
    CT_DoLog EXTRA "Configuring elf2flt"
diorcet@3123
   285
    CT_DoExecLog CFG                                            \
diorcet@3123
   286
    CFLAGS="${cflags}"                                          \
diorcet@3123
   287
    LDFLAGS="${ldflags}"                                        \
diorcet@3123
   288
    "${CT_SRC_DIR}/elf2flt-${CT_ELF2FLT_VERSION}/configure"     \
diorcet@3123
   289
        --build=${CT_BUILD}                                     \
diorcet@3123
   290
        --host=${host}                                          \
diorcet@3123
   291
        --target=${CT_TARGET}                                   \
diorcet@3123
   292
        --prefix=${prefix}                                      \
diorcet@3123
   293
        --with-bfd-include-dir=${binutils_bld}/bfd              \
diorcet@3123
   294
        --with-binutils-include-dir=${binutils_src}/include     \
diorcet@3123
   295
        --with-libbfd=${binutils_bld}/bfd/libbfd.a              \
diorcet@3123
   296
        --with-libiberty=${binutils_bld}/libiberty/libiberty.a  \
diorcet@3123
   297
        ${elf2flt_opts}                                         \
diorcet@3123
   298
        "${CT_ELF2FLT_EXTRA_CONFIG_ARRAY[@]}"
diorcet@3123
   299
diorcet@3123
   300
    CT_DoLog EXTRA "Building elf2flt"
diorcet@3123
   301
    CT_DoExecLog ALL make ${JOBSFLAGS}
diorcet@3123
   302
diorcet@3123
   303
    CT_DoLog EXTRA "Installing elf2flt"
diorcet@3123
   304
    CT_DoExecLog ALL make install
diorcet@3123
   305
}
diorcet@3123
   306
yann@1345
   307
# Now on for the target libraries
yann@2906
   308
do_binutils_for_target() {
yann@1483
   309
    local -a extra_config
yann@1483
   310
    local -a targets
yann@1483
   311
    local -a build_targets
yann@1483
   312
    local -a install_targets
yann@1483
   313
    local t
yann@1345
   314
yann@1483
   315
    [ "${CT_BINUTILS_FOR_TARGET_IBERTY}" = "y" ] && targets+=("libiberty")
yann@1483
   316
    [ "${CT_BINUTILS_FOR_TARGET_BFD}"    = "y" ] && targets+=("bfd")
yann@1483
   317
    for t in "${targets[@]}"; do
yann@1483
   318
        build_targets+=("all-${t}")
yann@1483
   319
        install_targets+=("install-${t}")
yann@1483
   320
    done
yann@1483
   321
yann@1483
   322
    if [ "${#targets[@]}" -ne 0 ]; then
yann@1345
   323
        CT_DoStep INFO "Installing binutils for target"
yann@1345
   324
        mkdir -p "${CT_BUILD_DIR}/build-binutils-for-target"
yann@1345
   325
        CT_Pushd "${CT_BUILD_DIR}/build-binutils-for-target"
yann@1345
   326
yann@1345
   327
        CT_DoLog EXTRA "Configuring binutils for target"
benoit@2488
   328
benoit@2488
   329
        if [ "${CT_BINUTILS_HAS_PKGVERSION_BUGURL}" = "y" ]; then
benoit@2503
   330
            extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
benoit@2503
   331
            [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
benoit@2488
   332
        fi
yann@2816
   333
        if [ "${CT_MULTILIB}" = "y" ]; then
yann@2816
   334
            extra_config+=("--enable-multilib")
yann@2816
   335
        else
yann@2816
   336
            extra_config+=("--disable-multilib")
yann@2816
   337
        fi
benoit@2488
   338
zhenqiang@2779
   339
        [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && extra_config+=("--disable-nls")
zhenqiang@2779
   340
yann@2333
   341
        CT_DoExecLog CFG                                            \
yann@1345
   342
        "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
yann@1345
   343
            --build=${CT_BUILD}                                     \
yann@1345
   344
            --host=${CT_TARGET}                                     \
yann@1345
   345
            --target=${CT_TARGET}                                   \
yann@1345
   346
            --prefix=/usr                                           \
yann@1345
   347
            --disable-werror                                        \
yann@1345
   348
            --enable-shared                                         \
yann@1345
   349
            --enable-static                                         \
yann@1483
   350
            "${extra_config[@]}"                                    \
yann@1345
   351
            ${CT_ARCH_WITH_FLOAT}                                   \
benoit@2804
   352
            "${CT_BINUTILS_EXTRA_CONFIG_ARRAY[@]}"
yann@1345
   353
yann@1483
   354
        CT_DoLog EXTRA "Building binutils' libraries (${targets[*]}) for target"
yann@2275
   355
        CT_DoExecLog ALL make ${JOBSFLAGS} "${build_targets[@]}"
yann@1483
   356
        CT_DoLog EXTRA "Installing binutils' libraries (${targets[*]}) for target"
yann@1483
   357
        CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" "${install_targets[@]}"
yann@1345
   358
yann@1345
   359
        CT_Popd
yann@1345
   360
        CT_EndStep
yann@1345
   361
    fi
yann@1345
   362
}