scripts/build/debug/300-gdb.sh
author "Benoît THÉBAUDEAU" <benoit.thebaudeau@advansee.com>
Tue May 31 21:03:03 2011 +0200 (2011-05-31)
changeset 2490 cce067f0448e
parent 2476 7690196856ce
child 2503 b5541f296b92
permissions -rw-r--r--
gdb: use the PKGVERSION and BUGURL options

This patch makes gdb benefit from the TOOLCHAIN_PKGVERSION and
TOOLCHAIN_BUGURL options.

Signed-off-by: "Benoît THÉBAUDEAU" <benoit.thebaudeau@advansee.com>
     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         [ -n "${CT_TOOLCHAIN_PKGVERSION}" ] && extra_config+=("--with-pkgversion=${CT_TOOLCHAIN_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             --disable-werror                            \
   143             "${cross_extra_config[@]}"
   144 
   145         CT_DoLog EXTRA "Building cross-gdb"
   146         CT_DoExecLog ALL make ${JOBSFLAGS}
   147 
   148         CT_DoLog EXTRA "Installing cross-gdb"
   149         CT_DoExecLog ALL make install
   150 
   151         CT_EndStep
   152     fi
   153 
   154     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   155         local -a native_extra_config
   156         local -a ncurses_opt
   157         local -a gdb_native_CFLAGS
   158 
   159         CT_DoStep INFO "Installing native gdb"
   160 
   161         native_extra_config=("${extra_config[@]}")
   162 
   163         # GDB on Mingw depends on PDcurses, not ncurses
   164         if [ "${do_ncurses}" = "y" ]; then
   165             CT_DoLog EXTRA "Building static target ncurses"
   166 
   167             [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   168             [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   169 
   170             mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
   171             cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
   172 
   173             # Use build = CT_REAL_BUILD so that configure thinks it is
   174             # cross-compiling, and thus will use the ${CT_BUILD}-*
   175             # tools instead of searching for the native ones...
   176             CT_DoExecLog CFG                                                    \
   177             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   178                 --build=${CT_BUILD}                                             \
   179                 --host=${CT_BUILD}                                              \
   180                 --prefix=/usr                                                   \
   181                 --without-shared                                                \
   182                 --enable-symlinks                                               \
   183                 --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   184                 --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   185                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   186                 "${ncurses_opts[@]}"
   187 
   188             # Under some operating systems (eg. Winblows), there is an
   189             # extension appended to executables. Find that.
   190             tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   191 
   192             CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   193             CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   194 
   195             CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
   196             CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
   197 
   198             mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   199             cd "${CT_BUILD_DIR}/build-ncurses"
   200 
   201             CT_DoExecLog CFG                                                    \
   202             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   203                 --build=${CT_BUILD}                                             \
   204                 --host=${CT_TARGET}                                             \
   205                 --with-build-cc=${CT_BUILD}-gcc                                 \
   206                 --with-build-cpp=${CT_BUILD}-gcc                                \
   207                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   208                 --prefix="${CT_BUILD_DIR}/static-target"                        \
   209                 --without-shared                                                \
   210                 --without-sysmouse                                              \
   211                 --without-progs                                                 \
   212                 --enable-termcap                                                \
   213                 "${ncurses_opts[@]}"
   214 
   215             CT_DoExecLog ALL make ${JOBSFLAGS}
   216 
   217             CT_DoExecLog ALL make install
   218 
   219             # We no longer need the temporary tic. Remove it
   220             CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
   221 
   222             native_extra_config+=("--with-curses")
   223             # There's no better way to tell gdb where to find -lcurses... :-(
   224             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   225             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   226         fi # do_ncurses
   227 
   228         if [ "${do_expat}" = "y" ]; then
   229             CT_DoLog EXTRA "Building static target expat"
   230 
   231             mkdir -p "${CT_BUILD_DIR}/expat-build"
   232             cd "${CT_BUILD_DIR}/expat-build"
   233 
   234             CT_DoExecLog CFG                                                \
   235             "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   236                 --build=${CT_BUILD}                                         \
   237                 --host=${CT_TARGET}                                         \
   238                 --prefix="${CT_BUILD_DIR}/static-target"                    \
   239                 --enable-static                                             \
   240                 --disable-shared
   241 
   242             CT_DoExecLog ALL make ${JOBSFLAGS}
   243             CT_DoExecLog ALL make install
   244 
   245             native_extra_config+=("--with-expat")
   246             native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   247         fi # do_expat
   248 
   249         CT_DoLog EXTRA "Configuring native gdb"
   250 
   251         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   252         cd "${CT_BUILD_DIR}/build-gdb-native"
   253 
   254         case "${CT_THREADS}" in
   255             none)   native_extra_config+=("--disable-threads");;
   256             *)      native_extra_config+=("--enable-threads");;
   257         esac
   258 
   259         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   260             CC_for_gdb="${CT_TARGET}-gcc -static"
   261             LD_for_gdb="${CT_TARGET}-ld -static"
   262         else
   263             CC_for_gdb="${CT_TARGET}-gcc"
   264             LD_for_gdb="${CT_TARGET}-ld"
   265         fi
   266 
   267         export ac_cv_func_strncmp_works=yes
   268 
   269         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   270 
   271         CT_DoExecLog CFG                                \
   272         CC="${CC_for_gdb}"                              \
   273         LD="${LD_for_gdb}"                              \
   274         CFLAGS="${gdb_native_CFLAGS[*]}"                \
   275         "${gdb_src_dir}/configure"                      \
   276             --build=${CT_BUILD}                         \
   277             --host=${CT_TARGET}                         \
   278             --target=${CT_TARGET}                       \
   279             --prefix=/usr                               \
   280             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   281             --without-uiout                             \
   282             --disable-tui                               \
   283             --disable-gdbtk                             \
   284             --without-x                                 \
   285             --disable-sim                               \
   286             --disable-werror                            \
   287             --without-included-gettext                  \
   288             --without-develop                           \
   289             "${native_extra_config[@]}"
   290 
   291         CT_DoLog EXTRA "Building native gdb"
   292         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   293 
   294         CT_DoLog EXTRA "Installing native gdb"
   295         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   296 
   297         # Building a native gdb also builds a gdbserver
   298         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   299 
   300         unset ac_cv_func_strncmp_works
   301 
   302         # GDB on Mingw depends on PDcurses, not ncurses
   303         if [ "${CT_MINGW32}" != "y" ]; then
   304             CT_DoLog EXTRA "Cleaning up ncurses"
   305             cd "${CT_BUILD_DIR}/build-ncurses"
   306             CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
   307 
   308             CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
   309         fi
   310 
   311         CT_EndStep # native gdb build
   312     fi
   313 
   314     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   315         local -a gdbserver_extra_config
   316 
   317         CT_DoStep INFO "Installing gdbserver"
   318         CT_DoLog EXTRA "Configuring gdbserver"
   319 
   320         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   321         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   322 
   323         # Workaround for bad versions, where the configure
   324         # script for gdbserver is not executable...
   325         # Bah, GNU folks strike again... :-(
   326         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   327 
   328         gdbserver_LDFLAGS=
   329         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   330             gdbserver_LDFLAGS=-static
   331         fi
   332 
   333         gdbserver_extra_config=("${extra_config[@]}")
   334 
   335         CT_DoExecLog CFG                                \
   336         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   337         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   338             --build=${CT_BUILD}                         \
   339             --host=${CT_TARGET}                         \
   340             --target=${CT_TARGET}                       \
   341             --prefix=/usr                               \
   342             --sysconfdir=/etc                           \
   343             --localstatedir=/var                        \
   344             --includedir="${CT_HEADERS_DIR}"            \
   345             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   346             --program-prefix=                           \
   347             --without-uiout                             \
   348             --disable-tui                               \
   349             --disable-gdbtk                             \
   350             --without-x                                 \
   351             --without-included-gettext                  \
   352             --without-develop                           \
   353             --disable-werror                            \
   354             "${gdbserver_extra_config[@]}"
   355 
   356         CT_DoLog EXTRA "Building gdbserver"
   357         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   358 
   359         CT_DoLog EXTRA "Installing gdbserver"
   360         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   361 
   362         CT_EndStep
   363     fi
   364 }