scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Feb 17 23:05:34 2011 +0100 (2011-02-17)
changeset 2303 88871c8621b8
parent 2275 9ab4392430ad
child 2326 3d0a8d386afd
permissions -rw-r--r--
debug/gdb: add versions from Linaro

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