scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Fri Jan 15 22:21:12 2010 +0100 (2010-01-15)
changeset 1738 4baa6a9f6415
parent 1732 6b2ae7804c6f
child 1743 f9145ebb4fbc
permissions -rw-r--r--
libc/uClibc: rename patches for 0.9.30.2
     1 # Build script for the gdb debug facility
     2 
     3 do_debug_gdb_suffix() {
     4     case "${CT_GDB_VERSION}" in
     5         snapshot)   ;;
     6         *)          echo "-${CT_GDB_VERSION}";;
     7     esac
     8 }
     9 
    10 do_debug_gdb_parts() {
    11     do_gdb=
    12     do_insight=
    13     do_ncurses=
    14 
    15     if [ "${CT_GDB_CROSS}" = y ]; then
    16         if [ "${CT_GDB_CROSS_INSIGHT}" = "y" ]; then
    17             do_insight=y
    18         else
    19             do_gdb=y
    20         fi
    21     fi
    22 
    23     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
    24         do_gdb=y
    25     fi
    26 
    27     if [ "${CT_GDB_NATIVE}" = "y" ]; then
    28         do_gdb=y
    29         do_ncurses=y
    30     fi
    31 }
    32 
    33 do_debug_gdb_get() {
    34     do_debug_gdb_parts
    35 
    36     if [ "${do_gdb}" = "y" ]; then
    37         CT_GetFile "gdb$(do_debug_gdb_suffix)"              \
    38                    {ftp,http}://ftp.gnu.org/pub/gnu/gdb     \
    39                    ftp://sources.redhat.com/pub/gdb/{{,old-}releases,snapshots/current}
    40     fi
    41 
    42     if [ "${do_insight}" = "y" ]; then
    43         CT_GetFile "insight-${CT_GDB_VERSION}"                                              \
    44                    ftp://sourceware.org/pub/insight/releases                                \
    45                    {ftp,http}://ftp.twaren.net/Unix/Sourceware/insight/releases             \
    46                    {ftp,http}://ftp.gwdg.de/pub/linux/sources.redhat.com/insight/releases
    47     fi
    48 
    49     if [ "${do_ncurses}" = "y" ]; then
    50         CT_GetFile "ncurses-${CT_NCURSES_VERSION}" .tar.gz  \
    51                    {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
    52                    ftp://invisible-island.net/ncurses
    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$(do_debug_gdb_suffix)"
    61         CT_Patch "gdb$(do_debug_gdb_suffix)"
    62     fi
    63 
    64     if [ "${do_insight}" = "y" ]; then
    65         CT_Extract "insight-${CT_GDB_VERSION}"
    66         CT_Patch "insight-${CT_GDB_VERSION}"
    67     fi
    68 
    69     if [ "${do_ncurses}" = "y" ]; then
    70         CT_Extract "ncurses-${CT_NCURSES_VERSION}"
    71         CT_Patch "ncurses-${CT_NCURSES_VERSION}"
    72     fi
    73 }
    74 
    75 do_debug_gdb_build() {
    76     local -a extra_config
    77 
    78     gdb_src_dir="${CT_SRC_DIR}/gdb$(do_debug_gdb_suffix)"
    79     insight_src_dir="${CT_SRC_DIR}/insight-${CT_GDB_VERSION}"
    80 
    81     # Version 6.3 and below behave badly with gdbmi
    82     case "${CT_GDB_VERSION}" in
    83         6.2*|6.3)   extra_config+=("--disable-gdbmi");;
    84     esac
    85 
    86     if [ "${CT_GDB_CROSS}" = "y" ]; then
    87         local -a cross_extra_config
    88 
    89         CT_DoStep INFO "Installing cross-gdb"
    90         CT_DoLog EXTRA "Configuring cross-gdb"
    91 
    92         mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
    93         cd "${CT_BUILD_DIR}/build-gdb-cross"
    94 
    95         cross_extra_config=("${extra_config[@]}")
    96         if [ "${CT_GMP_MPFR}" = "y" ]; then
    97             cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}" "--with-mpfr=${CT_PREFIX_DIR}")
    98         fi
    99         case "${CT_THREADS}" in
   100             none)   cross_extra_config+=("--disable-threads");;
   101             *)      cross_extra_config+=("--enable-threads");;
   102         esac
   103 
   104         CC_for_gdb=
   105         LD_for_gdb=
   106         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
   107             CC_for_gdb="gcc -static"
   108             LD_for_gdb="ld -static"
   109         fi
   110 
   111         gdb_cross_configure="${gdb_src_dir}/configure"
   112         [ "${CT_GDB_CROSS_INSIGHT}" = "y" ] && gdb_cross_configure="${insight_src_dir}/configure"
   113 
   114         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   115 
   116         CC="${CC_for_gdb}"                              \
   117         LD="${LD_for_gdb}"                              \
   118         CT_DoExecLog ALL                                \
   119         "${gdb_cross_configure}"                        \
   120             --build=${CT_BUILD}                         \
   121             --host=${CT_HOST}                           \
   122             --target=${CT_TARGET}                       \
   123             --prefix="${CT_PREFIX_DIR}"                 \
   124             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   125             --disable-werror                            \
   126             "${cross_extra_config[@]}"
   127 
   128         CT_DoLog EXTRA "Building cross-gdb"
   129         CT_DoExecLog ALL make ${PARALLELMFLAGS}
   130 
   131         CT_DoLog EXTRA "Installing cross-gdb"
   132         CT_DoExecLog ALL make install
   133 
   134         CT_EndStep
   135     fi
   136 
   137     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   138         local -a native_extra_config
   139         local -a ncurses_opt
   140 
   141         CT_DoStep INFO "Installing native gdb"
   142 
   143         CT_DoStep INFO "Installing ncurses library"
   144 
   145         [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   146         [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   147 
   148         CT_DoStep INFO "Installing native ncurses tic"
   149         CT_DoLog EXTRA "Configuring ncurses tic"
   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 ALL                                        \
   157         "${CT_SRC_DIR}/ncurses-${CT_NCURSES_VERSION}/configure" \
   158             --build=${CT_REAL_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_DoLog EXTRA "Building ncurses tic"
   173         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
   174         CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
   175 
   176         CT_DoLog EXTRA "Installing ncurses tic"
   177         CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/bin"
   178         CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/bin"
   179 
   180         CT_EndStep # tic build
   181 
   182         CT_DoLog EXTRA "Configuring ncurses"
   183         mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   184         cd "${CT_BUILD_DIR}/build-ncurses"
   185 
   186         CT_DoExecLog ALL                                        \
   187         "${CT_SRC_DIR}/ncurses-${CT_NCURSES_VERSION}/configure" \
   188             --build=${CT_BUILD}                                 \
   189             --host=${CT_TARGET}                                 \
   190             --with-build-cc=${CT_BUILD}-gcc                     \
   191             --with-build-cpp=${CT_BUILD}-gcc                    \
   192             --with-build-cflags="${CT_CFLAGS_FOR_HOST}"         \
   193             --prefix="${CT_BUILD_DIR}/ncurses"                  \
   194             --without-shared                                    \
   195             --without-sysmouse                                  \
   196             --without-progs                                     \
   197             --enable-termcap                                    \
   198             "${ncurses_opts[@]}"
   199 
   200         CT_DoLog EXTRA "Building ncurses"
   201         CT_DoExecLog ALL make ${PARALLELMFLAGS}
   202 
   203         CT_DoLog EXTRA "Installing ncurses"
   204         CT_DoExecLog ALL make install
   205 
   206         # We no longer need the temporary tic. Remove it
   207         CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/bin/tic"
   208 
   209         CT_EndStep # ncurses build
   210 
   211         CT_DoLog EXTRA "Configuring native gdb"
   212 
   213         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   214         cd "${CT_BUILD_DIR}/build-gdb-native"
   215 
   216         native_extra_config=("${extra_config[@]}")
   217         case "${CT_THREADS}" in
   218             none)   native_extra_config+=("--disable-threads");;
   219             *)      native_extra_config+=("--enable-threads");;
   220         esac
   221         if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
   222             native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr" "--with-mpfr=${CT_SYSROOT_DIR}/usr")
   223         fi
   224 
   225         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   226             CC_for_gdb="${CT_TARGET}-gcc -static"
   227             LD_for_gdb="${CT_TARGET}-ld -static"
   228         else
   229             CC_for_gdb="${CT_TARGET}-gcc"
   230             LD_for_gdb="${CT_TARGET}-ld"
   231         fi
   232 
   233         export ac_cv_func_strncmp_works=yes
   234 
   235         gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
   236 
   237         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   238 
   239         CC="${CC_for_gdb}"                              \
   240         LD="${LD_for_gdb}"                              \
   241         CFLAGS="${gdb_native_CFLAGS}"                   \
   242         CT_DoExecLog ALL                                \
   243         "${gdb_src_dir}/configure"                      \
   244             --build=${CT_BUILD}                         \
   245             --host=${CT_TARGET}                         \
   246             --target=${CT_TARGET}                       \
   247             --prefix=/usr                               \
   248             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   249             --without-uiout                             \
   250             --disable-tui                               \
   251             --disable-gdbtk                             \
   252             --without-x                                 \
   253             --disable-sim                               \
   254             --disable-werror                            \
   255             --without-included-gettext                  \
   256             --without-develop                           \
   257             "${native_extra_config[@]}"
   258 
   259         CT_DoLog EXTRA "Building native gdb"
   260         CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
   261 
   262         CT_DoLog EXTRA "Installing native gdb"
   263         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   264 
   265         # Building a native gdb also builds a gdbserver
   266         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   267 
   268         unset ac_cv_func_strncmp_works
   269 
   270         CT_DoLog EXTRA "Cleaning up ncurses"
   271         cd "${CT_BUILD_DIR}/build-ncurses"
   272         CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
   273 
   274         CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
   275 
   276         CT_EndStep # native gdb build
   277     fi
   278 
   279     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   280         local -a gdbserver_extra_config
   281 
   282         CT_DoStep INFO "Installing gdbserver"
   283         CT_DoLog EXTRA "Configuring gdbserver"
   284 
   285         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   286         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   287 
   288         # Workaround for bad versions, where the configure
   289         # script for gdbserver is not executable...
   290         # Bah, GNU folks strike again... :-(
   291         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   292 
   293         gdbserver_LDFLAGS=
   294         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   295             gdbserver_LDFLAGS=-static
   296         fi
   297 
   298         gdbserver_extra_config=("${extra_config[@]}")
   299 
   300         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   301         CT_DoExecLog ALL                                \
   302         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   303             --build=${CT_BUILD}                         \
   304             --host=${CT_TARGET}                         \
   305             --target=${CT_TARGET}                       \
   306             --prefix=/usr                               \
   307             --sysconfdir=/etc                           \
   308             --localstatedir=/var                        \
   309             --includedir="${CT_HEADERS_DIR}"            \
   310             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   311             --program-prefix=                           \
   312             --without-uiout                             \
   313             --disable-tui                               \
   314             --disable-gdbtk                             \
   315             --without-x                                 \
   316             --without-included-gettext                  \
   317             --without-develop                           \
   318             --disable-werror                            \
   319             "${gdbserver_extra_config[@]}"
   320 
   321         CT_DoLog EXTRA "Building gdbserver"
   322         CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
   323 
   324         CT_DoLog EXTRA "Installing gdbserver"
   325         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   326 
   327         CT_EndStep
   328     fi
   329 }