scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@free.fr>
Sun Mar 03 16:21:51 2013 +0100 (2013-03-03)
changeset 3191 992b592dc03a
parent 3190 22556c14a09c
child 3192 d1a898bff9c6
permissions -rw-r--r--
debug/gdb: move the ncurses build to a backend

This cleans up the code a bit.

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         case "${CT_THREADS}" in
   127             none)   cross_extra_config+=("--disable-threads");;
   128             *)      cross_extra_config+=("--enable-threads");;
   129         esac
   130         if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then
   131             cross_extra_config+=( "--with-python=yes" )
   132         else
   133             cross_extra_config+=( "--with-python=no" )
   134         fi
   135         if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then
   136             cross_extra_config+=( "--enable-sim" )
   137         else
   138             cross_extra_config+=( "--disable-sim" )
   139         fi
   140 
   141         CC_for_gdb=
   142         LD_for_gdb=
   143         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
   144             CC_for_gdb="gcc -static"
   145             LD_for_gdb="ld -static"
   146         fi
   147 
   148         cross_extra_config+=("--enable-expat")
   149         cross_extra_config+=("--with-expat=yes")
   150 
   151         [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] &&    \
   152         cross_extra_config+=("--disable-nls")
   153 
   154         gdb_cross_configure="${gdb_src_dir}/configure"
   155 
   156         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   157 
   158         CT_DoExecLog CFG                                \
   159         CC="${CC_for_gdb}"                              \
   160         LD="${LD_for_gdb}"                              \
   161         "${gdb_cross_configure}"                        \
   162             --build=${CT_BUILD}                         \
   163             --host=${CT_HOST}                           \
   164             --target=${CT_TARGET}                       \
   165             --prefix="${CT_PREFIX_DIR}"                 \
   166             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   167             --with-sysroot="${CT_SYSROOT_DIR}"          \
   168             --disable-werror                            \
   169             "${cross_extra_config[@]}"                  \
   170             "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}"
   171 
   172         CT_DoLog EXTRA "Building cross-gdb"
   173         CT_DoExecLog ALL make ${JOBSFLAGS}
   174 
   175         CT_DoLog EXTRA "Installing cross-gdb"
   176         CT_DoExecLog ALL make install
   177 
   178         if [ "${CT_BUILD_MANUALS}" = "y" ]; then
   179             CT_DoLog EXTRA "Building and installing the cross-GDB manuals"
   180             CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
   181             CT_DoExecLog ALL make install-{pdf,html}-gdb
   182         fi
   183 
   184         if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
   185             CT_DoLog EXTRA "Install '.gdbinit' template"
   186             # See in scripts/build/internals.sh for why we do this
   187             if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
   188                 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
   189             else
   190                 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
   191                                    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c"   \
   192                              )
   193             fi
   194             ${sed} -r                                               \
   195                    -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;"             \
   196                    -e "s:@@VERSION@@:${gcc_version}:;"              \
   197                    "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in"   \
   198                    >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
   199         fi # Install gdbinit sample
   200 
   201         CT_EndStep
   202     fi
   203 
   204     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   205         local -a native_extra_config
   206         local -a ncurses_opt
   207         local -a gdb_native_CFLAGS
   208 
   209         CT_DoStep INFO "Installing native gdb"
   210 
   211         native_extra_config=("${extra_config[@]}")
   212 
   213         # GDB on Mingw depends on PDcurses, not ncurses
   214         if [ "${CT_MINGW32}" != "y" ]; then
   215             CT_DoLog EXTRA "Building static target ncurses"
   216 
   217             CT_mkdir_pushd "${CT_BUILD_DIR}/build-ncurses-target-${CT_TARGET}"
   218             do_gdb_ncurses_backend host="${CT_TARGET}"                      \
   219                                    prefix="${CT_BUILD_DIR}/static-target"   \
   220                                    cflags="${CT_CFLAGS_FOR_HOST}"           \
   221                                    ldflags=""
   222             CT_Popd
   223             native_extra_config+=("--with-curses")
   224             # There's no better way to tell gdb where to find -lcurses... :-(
   225             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   226             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   227         fi # need_ncurses_src
   228 
   229         # Build libexpat
   230         CT_DoLog EXTRA "Building static target expat"
   231         CT_mkdir_pushd "${CT_BUILD_DIR}/build-expat-target-${CT_TARGET}"
   232         do_gdb_expat_backend host="${CT_TARGET}"                    \
   233                              prefix="${CT_BUILD_DIR}/static-target" \
   234                              cflags=""                              \
   235                              ldflags=""
   236         CT_Popd
   237         native_extra_config+=("--with-expat")
   238         native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   239 
   240         CT_DoLog EXTRA "Configuring native gdb"
   241 
   242         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   243         cd "${CT_BUILD_DIR}/build-gdb-native"
   244 
   245         case "${CT_THREADS}" in
   246             none)   native_extra_config+=("--disable-threads");;
   247             *)      native_extra_config+=("--enable-threads");;
   248         esac
   249 
   250         [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] &&    \
   251         native_extra_config+=("--disable-nls")
   252 
   253         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   254             CC_for_gdb="${CT_TARGET}-gcc -static"
   255             LD_for_gdb="${CT_TARGET}-ld -static"
   256         else
   257             CC_for_gdb="${CT_TARGET}-gcc"
   258             LD_for_gdb="${CT_TARGET}-ld"
   259         fi
   260 
   261         export ac_cv_func_strncmp_works=yes
   262 
   263         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   264 
   265         CT_DoExecLog CFG                                \
   266         CC="${CC_for_gdb}"                              \
   267         LD="${LD_for_gdb}"                              \
   268         CFLAGS="${gdb_native_CFLAGS[*]}"                \
   269         "${gdb_src_dir}/configure"                      \
   270             --build=${CT_BUILD}                         \
   271             --host=${CT_TARGET}                         \
   272             --target=${CT_TARGET}                       \
   273             --prefix=/usr                               \
   274             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   275             --without-uiout                             \
   276             --disable-tui                               \
   277             --disable-gdbtk                             \
   278             --without-x                                 \
   279             --disable-sim                               \
   280             --disable-werror                            \
   281             --without-included-gettext                  \
   282             --without-develop                           \
   283             "${native_extra_config[@]}"
   284 
   285         CT_DoLog EXTRA "Building native gdb"
   286         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   287 
   288         CT_DoLog EXTRA "Installing native gdb"
   289         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   290 
   291         # Building a native gdb also builds a gdbserver
   292         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   293 
   294         unset ac_cv_func_strncmp_works
   295 
   296         CT_EndStep # native gdb build
   297     fi
   298 
   299     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   300         local -a gdbserver_extra_config
   301 
   302         CT_DoStep INFO "Installing gdbserver"
   303         CT_DoLog EXTRA "Configuring gdbserver"
   304 
   305         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   306         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   307 
   308         # Workaround for bad versions, where the configure
   309         # script for gdbserver is not executable...
   310         # Bah, GNU folks strike again... :-(
   311         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   312 
   313         gdbserver_LDFLAGS=
   314         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   315             gdbserver_LDFLAGS=-static
   316         fi
   317 
   318         gdbserver_extra_config=("${extra_config[@]}")
   319 
   320         if [ "${CT_GDB_GDBSERVER_HAS_IPA_LIB}" = "y" ]; then
   321             if [ "${CT_GDB_GDBSERVER_BUILD_IPA_LIB}" = "y" ]; then
   322                 gdbserver_extra_config+=( --enable-inprocess-agent )
   323             else
   324                 gdbserver_extra_config+=( --disable-inprocess-agent )
   325             fi
   326         fi
   327 
   328         CT_DoExecLog CFG                                \
   329         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   330         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   331             --build=${CT_BUILD}                         \
   332             --host=${CT_TARGET}                         \
   333             --target=${CT_TARGET}                       \
   334             --prefix=/usr                               \
   335             --sysconfdir=/etc                           \
   336             --localstatedir=/var                        \
   337             --includedir="${CT_HEADERS_DIR}"            \
   338             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   339             --program-prefix=                           \
   340             --without-uiout                             \
   341             --disable-tui                               \
   342             --disable-gdbtk                             \
   343             --without-x                                 \
   344             --without-included-gettext                  \
   345             --without-develop                           \
   346             --disable-werror                            \
   347             "${gdbserver_extra_config[@]}"
   348 
   349         CT_DoLog EXTRA "Building gdbserver"
   350         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   351 
   352         CT_DoLog EXTRA "Installing gdbserver"
   353         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   354 
   355         CT_EndStep
   356     fi
   357 }
   358 
   359 # Build libncurses
   360 #   Parameter     : description               : type      : default
   361 #   host          : machine to run on         : tuple     : (none)
   362 #   prefix        : prefix to install into    : dir       : (none)
   363 #   cflags        : cflags to use             : string    : (empty)
   364 #   ldflags       : ldflags to use            : string    : (empty)
   365 do_gdb_ncurses_backend() {
   366     local host
   367     local prefix
   368     local cflags
   369     local ldflags
   370     local arg
   371 
   372     for arg in "$@"; do
   373         eval "${arg// /\\ }"
   374     done
   375 
   376     [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   377     [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   378 
   379     CT_mkdir_pushd "build-tic"
   380 
   381     # We need a tic that runs on build, not on host nor on target
   382     # Use build = CT_REAL_BUILD so that configure thinks it is
   383     # cross-compiling, and thus will use the ${CT_BUILD}-*
   384     # tools instead of searching for the native ones...
   385     CT_DoExecLog CFG                                                    \
   386     "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   387         --build=${CT_BUILD}                                             \
   388         --host=${CT_BUILD}                                              \
   389         --prefix=/usr                                                   \
   390         --enable-symlinks                                               \
   391         --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   392         --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   393         --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   394         "${ncurses_opts[@]}"
   395 
   396     # ncurses insists on linking tic statically. It does not work
   397     # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
   398     CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
   399 
   400     # Under some operating systems (eg. Winblows), there is an
   401     # extension appended to executables. Find that.
   402     tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   403 
   404     CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   405     CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   406 
   407     CT_DoExecLog ALL install -d -m 0755 "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   408     CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   409 
   410     CT_Popd
   411 
   412     CT_mkdir_pushd "ncurses"
   413 
   414     CT_DoExecLog CFG                                                    \
   415     TIC_PATH="${CT_BUILDTOOLS_PREFIX_DIR}/bin/tic${tic_ext}"            \
   416     "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   417         --build=${CT_BUILD}                                             \
   418         --host=${host}                                                  \
   419         --with-build-cc=${CT_BUILD}-gcc                                 \
   420         --with-build-cpp=${CT_BUILD}-gcc                                \
   421         --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   422         --prefix="${prefix}"                                            \
   423         --without-shared                                                \
   424         --without-sysmouse                                              \
   425         --without-progs                                                 \
   426         --enable-termcap                                                \
   427         "${ncurses_opts[@]}"
   428 
   429     CT_DoExecLog ALL make ${JOBSFLAGS}
   430     CT_DoExecLog ALL make install
   431 
   432     CT_Popd
   433 }
   434 
   435 # Build libexpat
   436 #   Parameter     : description               : type      : default
   437 #   host          : machine to run on         : tuple     : (none)
   438 #   prefix        : prefix to install into    : dir       : (none)
   439 #   cflags        : cflags to use             : string    : (empty)
   440 #   ldflags       : ldflags to use            : string    : (empty)
   441 do_gdb_expat_backend() {
   442     local host
   443     local prefix
   444     local cflags
   445     local ldflags
   446     local arg
   447 
   448     for arg in "$@"; do
   449         eval "${arg// /\\ }"
   450     done
   451 
   452     CT_DoExecLog CFG                                                \
   453     "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   454         --build=${CT_BUILD}                                         \
   455         --host=${host}                                              \
   456         --prefix="${prefix}"                                        \
   457         --enable-static                                             \
   458         --disable-shared
   459 
   460     CT_DoExecLog ALL make ${JOBSFLAGS}
   461     CT_DoExecLog ALL make install
   462 }