scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Aug 23 23:18:49 2010 +0200 (2010-08-23)
changeset 2099 1bb063c8a0ca
parent 2022 dc167f43e3dc
child 2100 f9fcfc002c8a
permissions -rw-r--r--
complibs: noone is using companion libs on the target; nuke them

As there's no longer any user of the companion libraries on the
target, nuke the build for the target.

Well, at least, there's libelf that's still needed by ltrace, so
we keep it.

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