scripts/build/binutils/binutils.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun May 11 18:42:30 2014 +0200 (2014-05-11)
changeset 3316 42590ff8521c
parent 3315 464128a8fc3f
child 3317 6b2c4692f132
permissions -rw-r--r--
binutils/binutils: do not forget to extract elf2flt

In case we're using a custom (aka local) binutils source, we still
need to extract and patch elf2flt.

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