scripts/build/debug/300-gdb.sh
author Remy Bohmer <linux@bohmer.net>
Sun Jul 11 22:23:34 2010 +0200 (2010-07-11)
changeset 2021 3e52a1510f87
parent 2003 b74a48609d81
child 2022 dc167f43e3dc
permissions -rw-r--r--
debug/gdb: Fix compilation for Mingw hosts

GDB requires PDcurses instead of ncurses while running on Windows.
So, do not always compile ncurses in case GDB needs to build.

PDcurses is provided by an earlier build step and is not described in
this file.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
[yann.morin.1998@anciense.nib.fr: we already have a way to detect ncurses usage]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
yann@479
     1
# Build script for the gdb debug facility
yann@479
     2
yann@1743
     3
# The version of ncurses to use. Yes, it's hard-coded.
yann@1743
     4
# It's used only internally by crosstool-NG, and is
yann@1743
     5
# not exposed outside, so we don't care about providing
yann@1743
     6
# config options for this.
yann@1743
     7
CT_DEBUG_GDB_NCURSES_VERSION="5.7"
yann@1743
     8
yann@821
     9
do_debug_gdb_parts() {
yann@821
    10
    do_gdb=
yann@821
    11
    do_ncurses=
yann@821
    12
yann@821
    13
    if [ "${CT_GDB_CROSS}" = y ]; then
yann@1916
    14
        do_gdb=y
yann@821
    15
    fi
yann@821
    16
yann@821
    17
    if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
yann@821
    18
        do_gdb=y
yann@821
    19
    fi
yann@821
    20
yann@821
    21
    if [ "${CT_GDB_NATIVE}" = "y" ]; then
yann@821
    22
        do_gdb=y
linux@2021
    23
        # GDB on Mingw depends on PDcurses, not ncurses
linux@2021
    24
        if [ "${CT_MINGW32}" != "y" ]; then
linux@2021
    25
            do_ncurses=y
linux@2021
    26
        fi
yann@821
    27
    fi
yann@821
    28
}
yann@821
    29
yann@479
    30
do_debug_gdb_get() {
yann@821
    31
    do_debug_gdb_parts
yann@821
    32
yann@821
    33
    if [ "${do_gdb}" = "y" ]; then
yann@1899
    34
        CT_GetFile "gdb-${CT_GDB_VERSION}"                          \
yann@1899
    35
                   {ftp,http}://ftp.gnu.org/pub/gnu/gdb             \
yann@1899
    36
                   ftp://sources.redhat.com/pub/gdb/{,old-}releases
yann@821
    37
    fi
yann@821
    38
yann@821
    39
    if [ "${do_ncurses}" = "y" ]; then
yann@1743
    40
        CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz  \
yann@573
    41
                   {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
yann@573
    42
                   ftp://invisible-island.net/ncurses
yann@573
    43
    fi
yann@479
    44
}
yann@479
    45
yann@479
    46
do_debug_gdb_extract() {
yann@821
    47
    do_debug_gdb_parts
yann@821
    48
yann@821
    49
    if [ "${do_gdb}" = "y" ]; then
yann@1899
    50
        CT_Extract "gdb-${CT_GDB_VERSION}"
yann@1901
    51
        CT_Patch "gdb" "${CT_GDB_VERSION}"
yann@821
    52
    fi
yann@821
    53
yann@821
    54
    if [ "${do_ncurses}" = "y" ]; then
yann@1743
    55
        CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
yann@1901
    56
        CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
yann@598
    57
    fi
yann@479
    58
}
yann@479
    59
yann@479
    60
do_debug_gdb_build() {
yann@1481
    61
    local -a extra_config
yann@1481
    62
linux@2021
    63
    do_debug_gdb_parts
linux@2021
    64
yann@1899
    65
    gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
yann@479
    66
yann@479
    67
    # Version 6.3 and below behave badly with gdbmi
yann@479
    68
    case "${CT_GDB_VERSION}" in
yann@1481
    69
        6.2*|6.3)   extra_config+=("--disable-gdbmi");;
yann@479
    70
    esac
yann@479
    71
yann@479
    72
    if [ "${CT_GDB_CROSS}" = "y" ]; then
yann@1481
    73
        local -a cross_extra_config
yann@1481
    74
yann@479
    75
        CT_DoStep INFO "Installing cross-gdb"
yann@479
    76
        CT_DoLog EXTRA "Configuring cross-gdb"
yann@479
    77
yann@479
    78
        mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
yann@479
    79
        cd "${CT_BUILD_DIR}/build-gdb-cross"
yann@479
    80
yann@1481
    81
        cross_extra_config=("${extra_config[@]}")
yann@1851
    82
        if [ "${CT_GDB_CROSS_USE_GMP_MPFR}" = "y" ]; then
yann@1851
    83
            cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}")
yann@1851
    84
            cross_extra_config+=("--with-mpfr=${CT_PREFIX_DIR}")
yann@1851
    85
        fi
yann@1853
    86
        if [ "${CT_GDB_CROSS_USE_MPC}" = "y" ]; then
yann@1853
    87
            cross_extra_config+=("--with-mpc=${CT_PREFIX_DIR}")
yann@1853
    88
        fi
yann@583
    89
        case "${CT_THREADS}" in
yann@1481
    90
            none)   cross_extra_config+=("--disable-threads");;
yann@1481
    91
            *)      cross_extra_config+=("--enable-threads");;
yann@583
    92
        esac
yann@583
    93
yann@479
    94
        CC_for_gdb=
yann@479
    95
        LD_for_gdb=
yann@583
    96
        if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
yann@479
    97
            CC_for_gdb="gcc -static"
yann@479
    98
            LD_for_gdb="ld -static"
yann@479
    99
        fi
yann@479
   100
yann@821
   101
        gdb_cross_configure="${gdb_src_dir}/configure"
yann@821
   102
yann@1481
   103
        CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
yann@602
   104
yann@479
   105
        CC="${CC_for_gdb}"                              \
yann@583
   106
        LD="${LD_for_gdb}"                              \
yann@669
   107
        CT_DoExecLog ALL                                \
yann@821
   108
        "${gdb_cross_configure}"                        \
yann@479
   109
            --build=${CT_BUILD}                         \
yann@479
   110
            --host=${CT_HOST}                           \
yann@479
   111
            --target=${CT_TARGET}                       \
yann@479
   112
            --prefix="${CT_PREFIX_DIR}"                 \
yann@479
   113
            --with-build-sysroot="${CT_SYSROOT_DIR}"    \
yann@801
   114
            --disable-werror                            \
yann@1481
   115
            "${cross_extra_config[@]}"
yann@479
   116
yann@479
   117
        CT_DoLog EXTRA "Building cross-gdb"
yann@669
   118
        CT_DoExecLog ALL make ${PARALLELMFLAGS}
yann@479
   119
yann@479
   120
        CT_DoLog EXTRA "Installing cross-gdb"
yann@669
   121
        CT_DoExecLog ALL make install
yann@479
   122
yann@479
   123
        CT_EndStep
yann@479
   124
    fi
yann@479
   125
yann@479
   126
    if [ "${CT_GDB_NATIVE}" = "y" ]; then
yann@1481
   127
        local -a native_extra_config
yann@1481
   128
        local -a ncurses_opt
yann@1481
   129
yann@573
   130
        CT_DoStep INFO "Installing native gdb"
yann@573
   131
linux@2021
   132
        # GDB on Mingw depends on PDcurses, not ncurses
linux@2021
   133
        if [ "${do_ncurses}" = "y" ]; then
linux@2021
   134
            CT_DoLog EXTRA "Building static target ncurses"
yann@1281
   135
linux@2021
   136
            [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
linux@2021
   137
            [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
yann@1281
   138
linux@2021
   139
            mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
linux@2021
   140
            cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
yann@1264
   141
linux@2021
   142
            # Use build = CT_REAL_BUILD so that configure thinks it is
linux@2021
   143
            # cross-compiling, and thus will use the ${CT_BUILD}-*
linux@2021
   144
            # tools instead of searching for the native ones...
linux@2021
   145
            CT_DoExecLog ALL                                                    \
linux@2021
   146
            "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
linux@2021
   147
                --build=${CT_BUILD}                                             \
linux@2021
   148
                --host=${CT_BUILD}                                              \
linux@2021
   149
                --prefix=/usr                                                   \
linux@2021
   150
                --without-shared                                                \
linux@2021
   151
                --enable-symlinks                                               \
linux@2021
   152
                --with-build-cc=${CT_REAL_BUILD}-gcc                            \
linux@2021
   153
                --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
linux@2021
   154
                --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
linux@2021
   155
                "${ncurses_opts[@]}"
yann@1264
   156
linux@2021
   157
            # Under some operating systems (eg. Winblows), there is an
linux@2021
   158
            # extension appended to executables. Find that.
linux@2021
   159
            tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
yann@1267
   160
linux@2021
   161
            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
linux@2021
   162
            CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
yann@1264
   163
linux@2021
   164
            CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
linux@2021
   165
            CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
yann@1264
   166
linux@2021
   167
            mkdir -p "${CT_BUILD_DIR}/build-ncurses"
linux@2021
   168
            cd "${CT_BUILD_DIR}/build-ncurses"
yann@573
   169
linux@2021
   170
            CT_DoExecLog ALL                                                    \
linux@2021
   171
            "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
linux@2021
   172
                --build=${CT_BUILD}                                             \
linux@2021
   173
                --host=${CT_TARGET}                                             \
linux@2021
   174
                --with-build-cc=${CT_BUILD}-gcc                                 \
linux@2021
   175
                --with-build-cpp=${CT_BUILD}-gcc                                \
linux@2021
   176
                --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
linux@2021
   177
                --prefix="${CT_BUILD_DIR}/ncurses"                              \
linux@2021
   178
                --without-shared                                                \
linux@2021
   179
                --without-sysmouse                                              \
linux@2021
   180
                --without-progs                                                 \
linux@2021
   181
                --enable-termcap                                                \
linux@2021
   182
                "${ncurses_opts[@]}"
yann@573
   183
linux@2021
   184
            CT_DoExecLog ALL make ${PARALLELMFLAGS}
yann@573
   185
linux@2021
   186
            CT_DoExecLog ALL make install
yann@573
   187
linux@2021
   188
            # We no longer need the temporary tic. Remove it
linux@2021
   189
            CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/bin/tic"
linux@2021
   190
        fi # do_ncurses
yann@1281
   191
yann@479
   192
        CT_DoLog EXTRA "Configuring native gdb"
yann@479
   193
yann@479
   194
        mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
yann@479
   195
        cd "${CT_BUILD_DIR}/build-gdb-native"
yann@479
   196
yann@1481
   197
        native_extra_config=("${extra_config[@]}")
yann@583
   198
        case "${CT_THREADS}" in
yann@1481
   199
            none)   native_extra_config+=("--disable-threads");;
yann@1481
   200
            *)      native_extra_config+=("--enable-threads");;
yann@583
   201
        esac
yann@622
   202
        if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
yann@1810
   203
            native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
yann@1810
   204
            native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
yann@602
   205
        fi
yann@583
   206
yann@583
   207
        if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
yann@583
   208
            CC_for_gdb="${CT_TARGET}-gcc -static"
yann@583
   209
            LD_for_gdb="${CT_TARGET}-ld -static"
yann@626
   210
        else
yann@626
   211
            CC_for_gdb="${CT_TARGET}-gcc"
yann@626
   212
            LD_for_gdb="${CT_TARGET}-ld"
yann@583
   213
        fi
yann@583
   214
yann@583
   215
        export ac_cv_func_strncmp_works=yes
yann@583
   216
yann@1733
   217
        gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
yann@1733
   218
yann@1481
   219
        CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
yann@602
   220
yann@583
   221
        CC="${CC_for_gdb}"                              \
yann@583
   222
        LD="${LD_for_gdb}"                              \
yann@1733
   223
        CFLAGS="${gdb_native_CFLAGS}"                   \
yann@669
   224
        CT_DoExecLog ALL                                \
yann@479
   225
        "${gdb_src_dir}/configure"                      \
yann@479
   226
            --build=${CT_BUILD}                         \
yann@479
   227
            --host=${CT_TARGET}                         \
yann@479
   228
            --target=${CT_TARGET}                       \
yann@479
   229
            --prefix=/usr                               \
yann@479
   230
            --with-build-sysroot="${CT_SYSROOT_DIR}"    \
yann@479
   231
            --without-uiout                             \
yann@479
   232
            --disable-tui                               \
yann@479
   233
            --disable-gdbtk                             \
yann@479
   234
            --without-x                                 \
yann@479
   235
            --disable-sim                               \
yann@583
   236
            --disable-werror                            \
yann@479
   237
            --without-included-gettext                  \
yann@583
   238
            --without-develop                           \
yann@1481
   239
            "${native_extra_config[@]}"
yann@479
   240
yann@479
   241
        CT_DoLog EXTRA "Building native gdb"
yann@669
   242
        CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
yann@479
   243
yann@479
   244
        CT_DoLog EXTRA "Installing native gdb"
yann@1219
   245
        CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
yann@479
   246
yann@583
   247
        # Building a native gdb also builds a gdbserver
yann@1219
   248
        find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
yann@583
   249
yann@583
   250
        unset ac_cv_func_strncmp_works
yann@583
   251
linux@2021
   252
        # GDB on Mingw depends on PDcurses, not ncurses
linux@2021
   253
        if [ "${CT_MINGW32}" != "y" ]; then
linux@2021
   254
            CT_DoLog EXTRA "Cleaning up ncurses"
linux@2021
   255
            cd "${CT_BUILD_DIR}/build-ncurses"
linux@2021
   256
            CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
yann@1555
   257
linux@2021
   258
            CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
linux@2021
   259
        fi
yann@1733
   260
yann@1281
   261
        CT_EndStep # native gdb build
yann@583
   262
    fi
yann@583
   263
yann@583
   264
    if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
yann@1481
   265
        local -a gdbserver_extra_config
yann@1481
   266
yann@583
   267
        CT_DoStep INFO "Installing gdbserver"
yann@583
   268
        CT_DoLog EXTRA "Configuring gdbserver"
yann@583
   269
yann@583
   270
        mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
yann@583
   271
        cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
yann@583
   272
yann@583
   273
        # Workaround for bad versions, where the configure
yann@583
   274
        # script for gdbserver is not executable...
yann@583
   275
        # Bah, GNU folks strike again... :-(
yann@583
   276
        chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
yann@583
   277
yann@583
   278
        gdbserver_LDFLAGS=
yann@583
   279
        if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
yann@583
   280
            gdbserver_LDFLAGS=-static
yann@583
   281
        fi
yann@583
   282
yann@1481
   283
        gdbserver_extra_config=("${extra_config[@]}")
yann@602
   284
yann@583
   285
        LDFLAGS="${gdbserver_LDFLAGS}"                  \
yann@669
   286
        CT_DoExecLog ALL                                \
yann@583
   287
        "${gdb_src_dir}/gdb/gdbserver/configure"        \
yann@583
   288
            --build=${CT_BUILD}                         \
yann@583
   289
            --host=${CT_TARGET}                         \
yann@583
   290
            --target=${CT_TARGET}                       \
yann@583
   291
            --prefix=/usr                               \
yann@583
   292
            --sysconfdir=/etc                           \
yann@583
   293
            --localstatedir=/var                        \
yann@583
   294
            --includedir="${CT_HEADERS_DIR}"            \
yann@583
   295
            --with-build-sysroot="${CT_SYSROOT_DIR}"    \
yann@583
   296
            --program-prefix=                           \
yann@583
   297
            --without-uiout                             \
yann@583
   298
            --disable-tui                               \
yann@583
   299
            --disable-gdbtk                             \
yann@583
   300
            --without-x                                 \
yann@583
   301
            --without-included-gettext                  \
yann@583
   302
            --without-develop                           \
yann@801
   303
            --disable-werror                            \
yann@1481
   304
            "${gdbserver_extra_config[@]}"
yann@583
   305
yann@583
   306
        CT_DoLog EXTRA "Building gdbserver"
yann@669
   307
        CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
yann@583
   308
yann@583
   309
        CT_DoLog EXTRA "Installing gdbserver"
yann@1219
   310
        CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
yann@583
   311
yann@479
   312
        CT_EndStep
yann@479
   313
    fi
yann@479
   314
}