scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sat Jan 22 22:35:43 2011 +0100 (2011-01-22)
changeset 2275 9ab4392430ad
parent 2154 250cdcc86441
child 2303 88871c8621b8
permissions -rw-r--r--
scripts: PARALLELMFLAGS is evil, rename

The reunification of the glibc/eglibc code paths exposed a nasty
bug in the glibc build: use of PARALLELMFLAGS breaks the build.

See the explanations in that bug report against FC6:
https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=212111

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