scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun Mar 03 17:17:55 2013 +0100 (2013-03-03)
changeset 3193 21f521809f6f
parent 3192 d1a898bff9c6
child 3198 10059fe75e24
permissions -rw-r--r--
debug/gdb: a litle bit of trivial code-reordering

Move all options-setting code at the same place.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.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.1.0"
    11 
    12 do_debug_gdb_parts() {
    13     need_gdb_src=
    14     need_ncurses_src=
    15     need_expat_src=
    16 
    17     if [ "${CT_GDB_CROSS}" = y ]; then
    18         need_gdb_src=y
    19     fi
    20 
    21     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
    22         need_gdb_src=y
    23     fi
    24 
    25     if [ "${CT_GDB_NATIVE}" = "y" ]; then
    26         need_gdb_src=y
    27         # GDB on Mingw depends on PDcurses, not ncurses
    28         if [ "${CT_MINGW32}" != "y" ]; then
    29             need_ncurses_src=y
    30         fi
    31         need_expat_src=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 [ "${need_gdb_src}" = "y" ]; then
    51         if [ "${CT_GDB_CUSTOM}" = "y" ]; then
    52             CT_GetCustom "gdb" "${CT_GDB_VERSION}" "${CT_GDB_CUSTOM_LOCATION}"
    53         else
    54             CT_GetFile "gdb-${CT_GDB_VERSION}"                          \
    55                        {ftp,http}://ftp.gnu.org/pub/gnu/gdb             \
    56                        ftp://sources.redhat.com/pub/gdb/{,old-}releases \
    57                        "${linaro_base_url}/${linaro_series}/${linaro_version}/+download"
    58         fi
    59     fi
    60 
    61     if [ "${need_ncurses_src}" = "y" ]; then
    62         CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz  \
    63                    {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
    64                    ftp://invisible-island.net/ncurses
    65     fi
    66 
    67     if [ "${need_expat_src}" = "y" ]; then
    68         CT_GetFile "expat-${CT_DEBUG_GDB_EXPAT_VERSION}" .tar.gz    \
    69                    http://downloads.sourceforge.net/project/expat/expat/${CT_DEBUG_GDB_EXPAT_VERSION}
    70     fi
    71 }
    72 
    73 do_debug_gdb_extract() {
    74     do_debug_gdb_parts
    75 
    76     if [ "${need_gdb_src}" = "y" ]; then
    77         # If using custom directory location, nothing to do
    78         if [    "${CT_GDB_CUSTOM}" = "y" \
    79              -a -d "${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}" ]; then
    80             return 0
    81         fi
    82         CT_Extract "gdb-${CT_GDB_VERSION}"
    83         CT_Patch "gdb" "${CT_GDB_VERSION}"
    84     fi
    85 
    86     if [ "${need_ncurses_src}" = "y" ]; then
    87         CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
    88         CT_DoExecLog ALL chmod -R u+w "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
    89         CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
    90     fi
    91 
    92     if [ "${need_expat_src}" = "y" ]; then
    93         CT_Extract "expat-${CT_DEBUG_GDB_EXPAT_VERSION}"
    94         CT_Patch "expat" "${CT_DEBUG_GDB_EXPAT_VERSION}"
    95     fi
    96 }
    97 
    98 do_debug_gdb_build() {
    99     local -a extra_config
   100 
   101     do_debug_gdb_parts
   102 
   103     gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
   104 
   105     # Version 6.3 and below behave badly with gdbmi
   106     case "${CT_GDB_VERSION}" in
   107         6.2*|6.3)   extra_config+=("--disable-gdbmi");;
   108     esac
   109 
   110     if [ "${CT_GDB_HAS_PKGVERSION_BUGURL}" = "y" ]; then
   111         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
   112         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
   113     fi
   114 
   115     if [ "${CT_GDB_CROSS}" = "y" ]; then
   116         local -a cross_extra_config
   117         local gcc_version
   118 
   119         CT_DoStep INFO "Installing cross-gdb"
   120         CT_DoLog EXTRA "Configuring cross-gdb"
   121 
   122         mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
   123         cd "${CT_BUILD_DIR}/build-gdb-cross"
   124 
   125         cross_extra_config=("${extra_config[@]}")
   126         cross_extra_config+=("--enable-expat")
   127         cross_extra_config+=("--with-expat=yes")
   128         case "${CT_THREADS}" in
   129             none)   cross_extra_config+=("--disable-threads");;
   130             *)      cross_extra_config+=("--enable-threads");;
   131         esac
   132         if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then
   133             cross_extra_config+=( "--with-python=yes" )
   134         else
   135             cross_extra_config+=( "--with-python=no" )
   136         fi
   137         if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then
   138             cross_extra_config+=( "--enable-sim" )
   139         else
   140             cross_extra_config+=( "--disable-sim" )
   141         fi
   142         if [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ]; then
   143             cross_extra_config+=("--disable-nls")
   144         fi
   145 
   146         CC_for_gdb=
   147         LD_for_gdb=
   148         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
   149             CC_for_gdb="gcc -static"
   150             LD_for_gdb="ld -static"
   151         fi
   152 
   153         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   154 
   155         CT_DoExecLog CFG                                \
   156         CC="${CC_for_gdb}"                              \
   157         LD="${LD_for_gdb}"                              \
   158         "${gdb_src_dir}/configure"                      \
   159             --build=${CT_BUILD}                         \
   160             --host=${CT_HOST}                           \
   161             --target=${CT_TARGET}                       \
   162             --prefix="${CT_PREFIX_DIR}"                 \
   163             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   164             --with-sysroot="${CT_SYSROOT_DIR}"          \
   165             --disable-werror                            \
   166             "${cross_extra_config[@]}"                  \
   167             "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}"
   168 
   169         CT_DoLog EXTRA "Building cross-gdb"
   170         CT_DoExecLog ALL make ${JOBSFLAGS}
   171 
   172         CT_DoLog EXTRA "Installing cross-gdb"
   173         CT_DoExecLog ALL make install
   174 
   175         if [ "${CT_BUILD_MANUALS}" = "y" ]; then
   176             CT_DoLog EXTRA "Building and installing the cross-GDB manuals"
   177             CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
   178             CT_DoExecLog ALL make install-{pdf,html}-gdb
   179         fi
   180 
   181         if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
   182             CT_DoLog EXTRA "Installing '.gdbinit' template"
   183             # See in scripts/build/internals.sh for why we do this
   184             if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
   185                 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
   186             else
   187                 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
   188                                    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c"   \
   189                              )
   190             fi
   191             ${sed} -r                                               \
   192                    -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;"             \
   193                    -e "s:@@VERSION@@:${gcc_version}:;"              \
   194                    "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in"   \
   195                    >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
   196         fi # Install gdbinit sample
   197 
   198         CT_EndStep
   199     fi
   200 
   201     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   202         local -a native_extra_config
   203         local -a ncurses_opt
   204         local -a gdb_native_CFLAGS
   205 
   206         CT_DoStep INFO "Installing native gdb"
   207 
   208         native_extra_config=("${extra_config[@]}")
   209 
   210         # GDB on Mingw depends on PDcurses, not ncurses
   211         if [ "${CT_MINGW32}" != "y" ]; then
   212             CT_DoLog EXTRA "Building static target ncurses"
   213 
   214             CT_mkdir_pushd "${CT_BUILD_DIR}/build-ncurses-target-${CT_TARGET}"
   215             do_gdb_ncurses_backend host="${CT_TARGET}"                      \
   216                                    prefix="${CT_BUILD_DIR}/static-target"   \
   217                                    cflags="${CT_CFLAGS_FOR_HOST}"           \
   218                                    ldflags=""
   219             CT_Popd
   220             native_extra_config+=("--with-curses")
   221             # There's no better way to tell gdb where to find -lcurses... :-(
   222             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   223             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   224         fi # need_ncurses_src
   225 
   226         # Build libexpat
   227         CT_DoLog EXTRA "Building static target expat"
   228         CT_mkdir_pushd "${CT_BUILD_DIR}/build-expat-target-${CT_TARGET}"
   229         do_gdb_expat_backend host="${CT_TARGET}"                    \
   230                              prefix="${CT_BUILD_DIR}/static-target" \
   231                              cflags=""                              \
   232                              ldflags=""
   233         CT_Popd
   234         native_extra_config+=("--with-expat")
   235         native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   236 
   237         CT_DoLog EXTRA "Configuring native gdb"
   238 
   239         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   240         cd "${CT_BUILD_DIR}/build-gdb-native"
   241 
   242         case "${CT_THREADS}" in
   243             none)   native_extra_config+=("--disable-threads");;
   244             *)      native_extra_config+=("--enable-threads");;
   245         esac
   246 
   247         [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] &&    \
   248         native_extra_config+=("--disable-nls")
   249 
   250         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   251             CC_for_gdb="${CT_TARGET}-gcc -static"
   252             LD_for_gdb="${CT_TARGET}-ld -static"
   253         else
   254             CC_for_gdb="${CT_TARGET}-gcc"
   255             LD_for_gdb="${CT_TARGET}-ld"
   256         fi
   257 
   258         export ac_cv_func_strncmp_works=yes
   259 
   260         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   261 
   262         CT_DoExecLog CFG                                \
   263         CC="${CC_for_gdb}"                              \
   264         LD="${LD_for_gdb}"                              \
   265         CFLAGS="${gdb_native_CFLAGS[*]}"                \
   266         "${gdb_src_dir}/configure"                      \
   267             --build=${CT_BUILD}                         \
   268             --host=${CT_TARGET}                         \
   269             --target=${CT_TARGET}                       \
   270             --prefix=/usr                               \
   271             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   272             --without-uiout                             \
   273             --disable-tui                               \
   274             --disable-gdbtk                             \
   275             --without-x                                 \
   276             --disable-sim                               \
   277             --disable-werror                            \
   278             --without-included-gettext                  \
   279             --without-develop                           \
   280             "${native_extra_config[@]}"
   281 
   282         CT_DoLog EXTRA "Building native gdb"
   283         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   284 
   285         CT_DoLog EXTRA "Installing native gdb"
   286         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   287 
   288         # Building a native gdb also builds a gdbserver
   289         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   290 
   291         unset ac_cv_func_strncmp_works
   292 
   293         CT_EndStep # native gdb build
   294     fi
   295 
   296     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   297         local -a gdbserver_extra_config
   298 
   299         CT_DoStep INFO "Installing gdbserver"
   300         CT_DoLog EXTRA "Configuring gdbserver"
   301 
   302         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   303         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   304 
   305         # Workaround for bad versions, where the configure
   306         # script for gdbserver is not executable...
   307         # Bah, GNU folks strike again... :-(
   308         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   309 
   310         gdbserver_LDFLAGS=
   311         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   312             gdbserver_LDFLAGS=-static
   313         fi
   314 
   315         gdbserver_extra_config=("${extra_config[@]}")
   316 
   317         if [ "${CT_GDB_GDBSERVER_HAS_IPA_LIB}" = "y" ]; then
   318             if [ "${CT_GDB_GDBSERVER_BUILD_IPA_LIB}" = "y" ]; then
   319                 gdbserver_extra_config+=( --enable-inprocess-agent )
   320             else
   321                 gdbserver_extra_config+=( --disable-inprocess-agent )
   322             fi
   323         fi
   324 
   325         CT_DoExecLog CFG                                \
   326         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   327         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   328             --build=${CT_BUILD}                         \
   329             --host=${CT_TARGET}                         \
   330             --target=${CT_TARGET}                       \
   331             --prefix=/usr                               \
   332             --sysconfdir=/etc                           \
   333             --localstatedir=/var                        \
   334             --includedir="${CT_HEADERS_DIR}"            \
   335             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   336             --program-prefix=                           \
   337             --without-uiout                             \
   338             --disable-tui                               \
   339             --disable-gdbtk                             \
   340             --without-x                                 \
   341             --without-included-gettext                  \
   342             --without-develop                           \
   343             --disable-werror                            \
   344             "${gdbserver_extra_config[@]}"
   345 
   346         CT_DoLog EXTRA "Building gdbserver"
   347         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   348 
   349         CT_DoLog EXTRA "Installing gdbserver"
   350         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   351 
   352         CT_EndStep
   353     fi
   354 }
   355 
   356 # Build libncurses
   357 #   Parameter     : description               : type      : default
   358 #   host          : machine to run on         : tuple     : (none)
   359 #   prefix        : prefix to install into    : dir       : (none)
   360 #   cflags        : cflags to use             : string    : (empty)
   361 #   ldflags       : ldflags to use            : string    : (empty)
   362 do_gdb_ncurses_backend() {
   363     local host
   364     local prefix
   365     local cflags
   366     local ldflags
   367     local arg
   368 
   369     for arg in "$@"; do
   370         eval "${arg// /\\ }"
   371     done
   372 
   373     [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   374     [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   375 
   376     CT_mkdir_pushd "build-tic"
   377 
   378     # We need a tic that runs on build, not on host nor on target
   379     # Use build = CT_REAL_BUILD so that configure thinks it is
   380     # cross-compiling, and thus will use the ${CT_BUILD}-*
   381     # tools instead of searching for the native ones...
   382     CT_DoExecLog CFG                                                    \
   383     "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   384         --build=${CT_BUILD}                                             \
   385         --host=${CT_BUILD}                                              \
   386         --prefix=/usr                                                   \
   387         --enable-symlinks                                               \
   388         --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   389         --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   390         --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   391         "${ncurses_opts[@]}"
   392 
   393     # ncurses insists on linking tic statically. It does not work
   394     # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
   395     CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
   396 
   397     # Under some operating systems (eg. Winblows), there is an
   398     # extension appended to executables. Find that.
   399     tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   400 
   401     CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   402     CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   403 
   404     CT_DoExecLog ALL install -d -m 0755 "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   405     CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   406 
   407     CT_Popd
   408 
   409     CT_mkdir_pushd "ncurses"
   410 
   411     CT_DoExecLog CFG                                                    \
   412     TIC_PATH="${CT_BUILDTOOLS_PREFIX_DIR}/bin/tic${tic_ext}"            \
   413     "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   414         --build=${CT_BUILD}                                             \
   415         --host=${host}                                                  \
   416         --with-build-cc=${CT_BUILD}-gcc                                 \
   417         --with-build-cpp=${CT_BUILD}-gcc                                \
   418         --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   419         --prefix="${prefix}"                                            \
   420         --without-shared                                                \
   421         --without-sysmouse                                              \
   422         --without-progs                                                 \
   423         --enable-termcap                                                \
   424         "${ncurses_opts[@]}"
   425 
   426     CT_DoExecLog ALL make ${JOBSFLAGS}
   427     CT_DoExecLog ALL make install
   428 
   429     CT_Popd
   430 }
   431 
   432 # Build libexpat
   433 #   Parameter     : description               : type      : default
   434 #   host          : machine to run on         : tuple     : (none)
   435 #   prefix        : prefix to install into    : dir       : (none)
   436 #   cflags        : cflags to use             : string    : (empty)
   437 #   ldflags       : ldflags to use            : string    : (empty)
   438 do_gdb_expat_backend() {
   439     local host
   440     local prefix
   441     local cflags
   442     local ldflags
   443     local arg
   444 
   445     for arg in "$@"; do
   446         eval "${arg// /\\ }"
   447     done
   448 
   449     CT_DoExecLog CFG                                                \
   450     "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   451         --build=${CT_BUILD}                                         \
   452         --host=${host}                                              \
   453         --prefix="${prefix}"                                        \
   454         --enable-static                                             \
   455         --disable-shared
   456 
   457     CT_DoExecLog ALL make ${JOBSFLAGS}
   458     CT_DoExecLog ALL make install
   459 }