scripts/build/debug/300-gdb.sh
author Titus von Boxberg <titus@v9g.de>
Sat May 22 22:01:18 2010 +0200 (2010-05-22)
changeset 1970 cdd761ad2d1a
parent 1939 39fce98b3747
child 2003 b74a48609d81
permissions -rw-r--r--
scripts/build/internals.sh: compile wrapper with portable options.

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