scripts/build/debug/300-gdb.sh
author Zhenqiang Chen <zhenqiang.chen@linaro.org>
Sat Sep 29 14:34:15 2012 +0800 (2012-09-29)
changeset 3072 15fa0b85025e
parent 3071 5243d1b432b1
child 3091 41967d32b54e
permissions -rw-r--r--
debug/gdb: disable nls when CT_TOOLCHAIN_ENABLE_NLS is not selected

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