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