scripts/build/debug/300-gdb.sh
author "Benoît THÉBAUDEAU" <benoit.thebaudeau@advansee.com>
Wed Jun 08 15:47:43 2011 +0200 (2011-06-08)
changeset 2508 9e2761e59a75
parent 2503 b5541f296b92
child 2570 2651341cc084
permissions -rw-r--r--
debug/cross-gdb: check host dependencies

Cross-gdb depends on expat and python. If either is missing, cross-gdb will
build successfully, but lacking some features.

Especially, if expat is missing, cross-gdb will be unable to parse the target
description, which may lead to runtime malfunctions and the following GDB
warning:
"Can not parse XML target description; XML support was disabled at compile time"

Hence, expat should be considered mandatory.

On the other hand, the features missing without python are not critical, so
python should not be considered mandatory.

This patch does the following:
- At configure time, warn the user if either expat or python is missing.
- In menuconfig, disable the static build options regarding cross-gdb if no
static version of expat is available, and disable cross-gdb if expat is
missing.

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