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