scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jul 11 22:26:29 2010 +0200 (2010-07-11)
changeset 2022 dc167f43e3dc
parent 2021 3e52a1510f87
child 2098 9a8f0e3fe605
permissions -rw-r--r--
debug/gdb: properly remove build tic

tic is isntalled in buildtools, not in the toolchain's bin dir.
Plus, it may have an extension...
     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         if [ "${CT_GDB_CROSS_USE_GMP_MPFR}" = "y" ]; then
    83             cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}")
    84             cross_extra_config+=("--with-mpfr=${CT_PREFIX_DIR}")
    85         fi
    86         if [ "${CT_GDB_CROSS_USE_MPC}" = "y" ]; then
    87             cross_extra_config+=("--with-mpc=${CT_PREFIX_DIR}")
    88         fi
    89         case "${CT_THREADS}" in
    90             none)   cross_extra_config+=("--disable-threads");;
    91             *)      cross_extra_config+=("--enable-threads");;
    92         esac
    93 
    94         CC_for_gdb=
    95         LD_for_gdb=
    96         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
    97             CC_for_gdb="gcc -static"
    98             LD_for_gdb="ld -static"
    99         fi
   100 
   101         gdb_cross_configure="${gdb_src_dir}/configure"
   102 
   103         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   104 
   105         CC="${CC_for_gdb}"                              \
   106         LD="${LD_for_gdb}"                              \
   107         CT_DoExecLog ALL                                \
   108         "${gdb_cross_configure}"                        \
   109             --build=${CT_BUILD}                         \
   110             --host=${CT_HOST}                           \
   111             --target=${CT_TARGET}                       \
   112             --prefix="${CT_PREFIX_DIR}"                 \
   113             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   114             --disable-werror                            \
   115             "${cross_extra_config[@]}"
   116 
   117         CT_DoLog EXTRA "Building cross-gdb"
   118         CT_DoExecLog ALL make ${PARALLELMFLAGS}
   119 
   120         CT_DoLog EXTRA "Installing cross-gdb"
   121         CT_DoExecLog ALL make install
   122 
   123         CT_EndStep
   124     fi
   125 
   126     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   127         local -a native_extra_config
   128         local -a ncurses_opt
   129 
   130         CT_DoStep INFO "Installing native gdb"
   131 
   132         # GDB on Mingw depends on PDcurses, not ncurses
   133         if [ "${do_ncurses}" = "y" ]; then
   134             CT_DoLog EXTRA "Building static target ncurses"
   135 
   136             [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   137             [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   138 
   139             mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
   140             cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
   141 
   142             # Use build = CT_REAL_BUILD so that configure thinks it is
   143             # cross-compiling, and thus will use the ${CT_BUILD}-*
   144             # tools instead of searching for the native ones...
   145             CT_DoExecLog ALL                                                    \
   146             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   147                 --build=${CT_BUILD}                                             \
   148                 --host=${CT_BUILD}                                              \
   149                 --prefix=/usr                                                   \
   150                 --without-shared                                                \
   151                 --enable-symlinks                                               \
   152                 --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   153                 --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   154                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   155                 "${ncurses_opts[@]}"
   156 
   157             # Under some operating systems (eg. Winblows), there is an
   158             # extension appended to executables. Find that.
   159             tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   160 
   161             CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
   162             CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
   163 
   164             CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
   165             CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
   166 
   167             mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   168             cd "${CT_BUILD_DIR}/build-ncurses"
   169 
   170             CT_DoExecLog ALL                                                    \
   171             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   172                 --build=${CT_BUILD}                                             \
   173                 --host=${CT_TARGET}                                             \
   174                 --with-build-cc=${CT_BUILD}-gcc                                 \
   175                 --with-build-cpp=${CT_BUILD}-gcc                                \
   176                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   177                 --prefix="${CT_BUILD_DIR}/ncurses"                              \
   178                 --without-shared                                                \
   179                 --without-sysmouse                                              \
   180                 --without-progs                                                 \
   181                 --enable-termcap                                                \
   182                 "${ncurses_opts[@]}"
   183 
   184             CT_DoExecLog ALL make ${PARALLELMFLAGS}
   185 
   186             CT_DoExecLog ALL make install
   187 
   188             # We no longer need the temporary tic. Remove it
   189             CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
   190         fi # do_ncurses
   191 
   192         CT_DoLog EXTRA "Configuring native gdb"
   193 
   194         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   195         cd "${CT_BUILD_DIR}/build-gdb-native"
   196 
   197         native_extra_config=("${extra_config[@]}")
   198         case "${CT_THREADS}" in
   199             none)   native_extra_config+=("--disable-threads");;
   200             *)      native_extra_config+=("--enable-threads");;
   201         esac
   202         if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
   203             native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
   204             native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
   205         fi
   206 
   207         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   208             CC_for_gdb="${CT_TARGET}-gcc -static"
   209             LD_for_gdb="${CT_TARGET}-ld -static"
   210         else
   211             CC_for_gdb="${CT_TARGET}-gcc"
   212             LD_for_gdb="${CT_TARGET}-ld"
   213         fi
   214 
   215         export ac_cv_func_strncmp_works=yes
   216 
   217         gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
   218 
   219         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   220 
   221         CC="${CC_for_gdb}"                              \
   222         LD="${LD_for_gdb}"                              \
   223         CFLAGS="${gdb_native_CFLAGS}"                   \
   224         CT_DoExecLog ALL                                \
   225         "${gdb_src_dir}/configure"                      \
   226             --build=${CT_BUILD}                         \
   227             --host=${CT_TARGET}                         \
   228             --target=${CT_TARGET}                       \
   229             --prefix=/usr                               \
   230             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   231             --without-uiout                             \
   232             --disable-tui                               \
   233             --disable-gdbtk                             \
   234             --without-x                                 \
   235             --disable-sim                               \
   236             --disable-werror                            \
   237             --without-included-gettext                  \
   238             --without-develop                           \
   239             "${native_extra_config[@]}"
   240 
   241         CT_DoLog EXTRA "Building native gdb"
   242         CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
   243 
   244         CT_DoLog EXTRA "Installing native gdb"
   245         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   246 
   247         # Building a native gdb also builds a gdbserver
   248         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   249 
   250         unset ac_cv_func_strncmp_works
   251 
   252         # GDB on Mingw depends on PDcurses, not ncurses
   253         if [ "${CT_MINGW32}" != "y" ]; then
   254             CT_DoLog EXTRA "Cleaning up ncurses"
   255             cd "${CT_BUILD_DIR}/build-ncurses"
   256             CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
   257 
   258             CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
   259         fi
   260 
   261         CT_EndStep # native gdb build
   262     fi
   263 
   264     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   265         local -a gdbserver_extra_config
   266 
   267         CT_DoStep INFO "Installing gdbserver"
   268         CT_DoLog EXTRA "Configuring gdbserver"
   269 
   270         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   271         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   272 
   273         # Workaround for bad versions, where the configure
   274         # script for gdbserver is not executable...
   275         # Bah, GNU folks strike again... :-(
   276         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   277 
   278         gdbserver_LDFLAGS=
   279         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   280             gdbserver_LDFLAGS=-static
   281         fi
   282 
   283         gdbserver_extra_config=("${extra_config[@]}")
   284 
   285         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   286         CT_DoExecLog ALL                                \
   287         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   288             --build=${CT_BUILD}                         \
   289             --host=${CT_TARGET}                         \
   290             --target=${CT_TARGET}                       \
   291             --prefix=/usr                               \
   292             --sysconfdir=/etc                           \
   293             --localstatedir=/var                        \
   294             --includedir="${CT_HEADERS_DIR}"            \
   295             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   296             --program-prefix=                           \
   297             --without-uiout                             \
   298             --disable-tui                               \
   299             --disable-gdbtk                             \
   300             --without-x                                 \
   301             --without-included-gettext                  \
   302             --without-develop                           \
   303             --disable-werror                            \
   304             "${gdbserver_extra_config[@]}"
   305 
   306         CT_DoLog EXTRA "Building gdbserver"
   307         CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
   308 
   309         CT_DoLog EXTRA "Installing gdbserver"
   310         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   311 
   312         CT_EndStep
   313     fi
   314 }