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