scripts/build/debug/300-gdb.sh
author Willy Tarreau <w@1wt.eu>
Tue Nov 15 19:11:57 2011 +0100 (2011-11-15)
changeset 2751 bd17cca444ae
parent 2703 bd2529ef6665
child 2765 6c5658b8b588
child 2874 741f66655e95
permissions -rw-r--r--
debug/gdb: fix tic install path, tell ncurses where to find it

ncurses 5.9 wants tic to be either one of:
- $TIC_PATH
- /usr/bin/tic

Of course, se do not want the latter, for it can be incompatible if the
ncurses in the build system is too old (eg. RHEL 5.6, Debian Lenny...).
So, force TIC_PATH to the location of our own tic.

Also, install tic alongside the other build tools, not in a sub-dir
of the toolchain installation dir.

Signed-off-by: Willy Tarreau <w@1wt.eu>
[yann.morin.1998@anciens.enib.fr: install in builtools/bin, move TIC_PATH]
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.9"
     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         extra_config+=("--with-pkgversion=${CT_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         local gcc_version
   109 
   110         CT_DoStep INFO "Installing cross-gdb"
   111         CT_DoLog EXTRA "Configuring cross-gdb"
   112 
   113         mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
   114         cd "${CT_BUILD_DIR}/build-gdb-cross"
   115 
   116         cross_extra_config=("${extra_config[@]}")
   117         case "${CT_THREADS}" in
   118             none)   cross_extra_config+=("--disable-threads");;
   119             *)      cross_extra_config+=("--enable-threads");;
   120         esac
   121         if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then
   122             cross_extra_config+=( "--with-python=yes" )
   123         else
   124             cross_extra_config+=( "--with-python=no" )
   125         fi
   126 
   127         CC_for_gdb=
   128         LD_for_gdb=
   129         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
   130             CC_for_gdb="gcc -static"
   131             LD_for_gdb="ld -static"
   132         fi
   133 
   134         gdb_cross_configure="${gdb_src_dir}/configure"
   135 
   136         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   137 
   138         CT_DoExecLog CFG                                \
   139         CC="${CC_for_gdb}"                              \
   140         LD="${LD_for_gdb}"                              \
   141         "${gdb_cross_configure}"                        \
   142             --build=${CT_BUILD}                         \
   143             --host=${CT_HOST}                           \
   144             --target=${CT_TARGET}                       \
   145             --prefix="${CT_PREFIX_DIR}"                 \
   146             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   147             --with-sysroot="${CT_SYSROOT_DIR}"          \
   148             --with-expat=yes                            \
   149             --disable-werror                            \
   150             "${cross_extra_config[@]}"
   151 
   152         CT_DoLog EXTRA "Building cross-gdb"
   153         CT_DoExecLog ALL make ${JOBSFLAGS}
   154 
   155         CT_DoLog EXTRA "Installing cross-gdb"
   156         CT_DoExecLog ALL make install
   157 
   158         if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
   159             CT_DoLog EXTRA "Install '.gdbinit' template"
   160             # See in scripts/build/internals.sh for why we do this
   161             if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
   162                 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
   163             else
   164                 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
   165                                    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c"   \
   166                              )
   167             fi
   168             ${sed} -r                                               \
   169                    -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;"             \
   170                    -e "s:@@VERSION@@:${gcc_version}:;"              \
   171                    "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in"   \
   172                    >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
   173         fi # Install gdbinit sample
   174 
   175         CT_EndStep
   176     fi
   177 
   178     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   179         local -a native_extra_config
   180         local -a ncurses_opt
   181         local -a gdb_native_CFLAGS
   182 
   183         CT_DoStep INFO "Installing native gdb"
   184 
   185         native_extra_config=("${extra_config[@]}")
   186 
   187         # GDB on Mingw depends on PDcurses, not ncurses
   188         if [ "${do_ncurses}" = "y" ]; then
   189             CT_DoLog EXTRA "Building static target ncurses"
   190 
   191             [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   192             [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   193 
   194             mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
   195             cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
   196 
   197             # Use build = CT_REAL_BUILD so that configure thinks it is
   198             # cross-compiling, and thus will use the ${CT_BUILD}-*
   199             # tools instead of searching for the native ones...
   200             CT_DoExecLog CFG                                                    \
   201             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   202                 --build=${CT_BUILD}                                             \
   203                 --host=${CT_BUILD}                                              \
   204                 --prefix=/usr                                                   \
   205                 --enable-symlinks                                               \
   206                 --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   207                 --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   208                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   209                 "${ncurses_opts[@]}"
   210 
   211             # ncurses insists on linking tic statically. It does not work
   212             # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
   213             CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
   214 
   215             # Under some operating systems (eg. Winblows), there is an
   216             # extension appended to executables. Find that.
   217             tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   218 
   219             CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   220             CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   221 
   222             CT_DoExecLog ALL install -d -m 0755 "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   223             CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   224 
   225             mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   226             cd "${CT_BUILD_DIR}/build-ncurses"
   227 
   228             CT_DoExecLog CFG                                                    \
   229             TIC_PATH="${CT_BUILDTOOLS_PREFIX_DIR}/bin/tic${tic_ext}"            \
   230             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   231                 --build=${CT_BUILD}                                             \
   232                 --host=${CT_TARGET}                                             \
   233                 --with-build-cc=${CT_BUILD}-gcc                                 \
   234                 --with-build-cpp=${CT_BUILD}-gcc                                \
   235                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   236                 --prefix="${CT_BUILD_DIR}/static-target"                        \
   237                 --without-shared                                                \
   238                 --without-sysmouse                                              \
   239                 --without-progs                                                 \
   240                 --enable-termcap                                                \
   241                 "${ncurses_opts[@]}"
   242 
   243             CT_DoExecLog ALL make ${JOBSFLAGS}
   244 
   245             CT_DoExecLog ALL make install
   246 
   247             native_extra_config+=("--with-curses")
   248             # There's no better way to tell gdb where to find -lcurses... :-(
   249             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   250             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   251         fi # do_ncurses
   252 
   253         if [ "${do_expat}" = "y" ]; then
   254             CT_DoLog EXTRA "Building static target expat"
   255 
   256             mkdir -p "${CT_BUILD_DIR}/expat-build"
   257             cd "${CT_BUILD_DIR}/expat-build"
   258 
   259             CT_DoExecLog CFG                                                \
   260             "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   261                 --build=${CT_BUILD}                                         \
   262                 --host=${CT_TARGET}                                         \
   263                 --prefix="${CT_BUILD_DIR}/static-target"                    \
   264                 --enable-static                                             \
   265                 --disable-shared
   266 
   267             CT_DoExecLog ALL make ${JOBSFLAGS}
   268             CT_DoExecLog ALL make install
   269 
   270             native_extra_config+=("--with-expat")
   271             native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   272         fi # do_expat
   273 
   274         CT_DoLog EXTRA "Configuring native gdb"
   275 
   276         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   277         cd "${CT_BUILD_DIR}/build-gdb-native"
   278 
   279         case "${CT_THREADS}" in
   280             none)   native_extra_config+=("--disable-threads");;
   281             *)      native_extra_config+=("--enable-threads");;
   282         esac
   283 
   284         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   285             CC_for_gdb="${CT_TARGET}-gcc -static"
   286             LD_for_gdb="${CT_TARGET}-ld -static"
   287         else
   288             CC_for_gdb="${CT_TARGET}-gcc"
   289             LD_for_gdb="${CT_TARGET}-ld"
   290         fi
   291 
   292         export ac_cv_func_strncmp_works=yes
   293 
   294         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   295 
   296         CT_DoExecLog CFG                                \
   297         CC="${CC_for_gdb}"                              \
   298         LD="${LD_for_gdb}"                              \
   299         CFLAGS="${gdb_native_CFLAGS[*]}"                \
   300         "${gdb_src_dir}/configure"                      \
   301             --build=${CT_BUILD}                         \
   302             --host=${CT_TARGET}                         \
   303             --target=${CT_TARGET}                       \
   304             --prefix=/usr                               \
   305             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   306             --without-uiout                             \
   307             --disable-tui                               \
   308             --disable-gdbtk                             \
   309             --without-x                                 \
   310             --disable-sim                               \
   311             --disable-werror                            \
   312             --without-included-gettext                  \
   313             --without-develop                           \
   314             "${native_extra_config[@]}"
   315 
   316         CT_DoLog EXTRA "Building native gdb"
   317         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   318 
   319         CT_DoLog EXTRA "Installing native gdb"
   320         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   321 
   322         # Building a native gdb also builds a gdbserver
   323         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   324 
   325         unset ac_cv_func_strncmp_works
   326 
   327         # GDB on Mingw depends on PDcurses, not ncurses
   328         if [ "${CT_MINGW32}" != "y" ]; then
   329             CT_DoLog EXTRA "Cleaning up ncurses"
   330             cd "${CT_BUILD_DIR}/build-ncurses"
   331             CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
   332 
   333             CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
   334         fi
   335 
   336         CT_EndStep # native gdb build
   337     fi
   338 
   339     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   340         local -a gdbserver_extra_config
   341 
   342         CT_DoStep INFO "Installing gdbserver"
   343         CT_DoLog EXTRA "Configuring gdbserver"
   344 
   345         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   346         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   347 
   348         # Workaround for bad versions, where the configure
   349         # script for gdbserver is not executable...
   350         # Bah, GNU folks strike again... :-(
   351         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   352 
   353         gdbserver_LDFLAGS=
   354         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   355             gdbserver_LDFLAGS=-static
   356         fi
   357 
   358         gdbserver_extra_config=("${extra_config[@]}")
   359 
   360         CT_DoExecLog CFG                                \
   361         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   362         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   363             --build=${CT_BUILD}                         \
   364             --host=${CT_TARGET}                         \
   365             --target=${CT_TARGET}                       \
   366             --prefix=/usr                               \
   367             --sysconfdir=/etc                           \
   368             --localstatedir=/var                        \
   369             --includedir="${CT_HEADERS_DIR}"            \
   370             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   371             --program-prefix=                           \
   372             --without-uiout                             \
   373             --disable-tui                               \
   374             --disable-gdbtk                             \
   375             --without-x                                 \
   376             --without-included-gettext                  \
   377             --without-develop                           \
   378             --disable-werror                            \
   379             "${gdbserver_extra_config[@]}"
   380 
   381         CT_DoLog EXTRA "Building gdbserver"
   382         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   383 
   384         CT_DoLog EXTRA "Installing gdbserver"
   385         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   386 
   387         CT_EndStep
   388     fi
   389 }