scripts/build/debug/300-gdb.sh
author Daniel Price <daniel.price@gmail.com>
Tue Nov 20 16:59:17 2012 -0800 (2012-11-20)
changeset 3126 333d3e40cbd1
parent 3091 41967d32b54e
child 3187 575a6f1d3b52
permissions -rw-r--r--
scripts: refine static linking check to better guide the user

The current mechanism to check if static linking is possible, and the mesage
displayed on failure, can be puzzling to the unsuspecting user.

Also, the current implementation is not using the existing infrastructure,
and is thus difficult to enhance with new tests.

So, switch to using the standard CT_DoExecLog infra, and use four tests to
check for the host compiler:
- check we can run it
- check it can build a trivial program
- check it can statically link that program
- check if it statically link with libstdc++

That should cover most of the problems. Hopefully.

(At the same time, fix a typo in a comment)

Signed-off-by: Daniel Price <daniel.price@gmail.com>
[yann.morin.1998@free.fr: split original patch for self-contained changes]
[yann.morin.1998@free.fr: use steps to better see gcc's output]
[yann.morin.1998@free.fr: commit log]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Message-Id: <163f86b5216fc08c672a.1353459722@nipigon.dssd.com>
Patchwork-Id: 200536
     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         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 [ "${do_ncurses}" = "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 [ "${do_expat}" = "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 [ "${do_gdb}" = "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 [ "${do_ncurses}" = "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 [ "${do_expat}" = "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         if [ "${do_expat}" = "y" ]; then
   149             cross_extra_config+=("--with-expat=yes")
   150         else
   151             cross_extra_config+=("--disable-expat")
   152             cross_extra_config+=("--with-expat=no")
   153         fi
   154 
   155         [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] &&    \
   156         cross_extra_config+=("--disable-nls")
   157 
   158         gdb_cross_configure="${gdb_src_dir}/configure"
   159 
   160         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   161 
   162         CT_DoExecLog CFG                                \
   163         CC="${CC_for_gdb}"                              \
   164         LD="${LD_for_gdb}"                              \
   165         "${gdb_cross_configure}"                        \
   166             --build=${CT_BUILD}                         \
   167             --host=${CT_HOST}                           \
   168             --target=${CT_TARGET}                       \
   169             --prefix="${CT_PREFIX_DIR}"                 \
   170             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   171             --with-sysroot="${CT_SYSROOT_DIR}"          \
   172             --disable-werror                            \
   173             "${cross_extra_config[@]}"                  \
   174             "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}"
   175 
   176         CT_DoLog EXTRA "Building cross-gdb"
   177         CT_DoExecLog ALL make ${JOBSFLAGS}
   178 
   179         CT_DoLog EXTRA "Installing cross-gdb"
   180         CT_DoExecLog ALL make install
   181 
   182         if [ "${CT_BUILD_MANUALS}" = "y" ]; then
   183             CT_DoLog EXTRA "Building and installing the cross-GDB manuals"
   184             CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
   185             CT_DoExecLog ALL make install-{pdf,html}-gdb
   186         fi
   187 
   188         if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
   189             CT_DoLog EXTRA "Install '.gdbinit' template"
   190             # See in scripts/build/internals.sh for why we do this
   191             if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
   192                 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
   193             else
   194                 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
   195                                    "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c"   \
   196                              )
   197             fi
   198             ${sed} -r                                               \
   199                    -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;"             \
   200                    -e "s:@@VERSION@@:${gcc_version}:;"              \
   201                    "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in"   \
   202                    >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
   203         fi # Install gdbinit sample
   204 
   205         CT_EndStep
   206     fi
   207 
   208     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   209         local -a native_extra_config
   210         local -a ncurses_opt
   211         local -a gdb_native_CFLAGS
   212 
   213         CT_DoStep INFO "Installing native gdb"
   214 
   215         native_extra_config=("${extra_config[@]}")
   216 
   217         # GDB on Mingw depends on PDcurses, not ncurses
   218         if [ "${do_ncurses}" = "y" ]; then
   219             CT_DoLog EXTRA "Building static target ncurses"
   220 
   221             [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   222             [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   223 
   224             mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
   225             cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
   226 
   227             # Use build = CT_REAL_BUILD so that configure thinks it is
   228             # cross-compiling, and thus will use the ${CT_BUILD}-*
   229             # tools instead of searching for the native ones...
   230             CT_DoExecLog CFG                                                    \
   231             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   232                 --build=${CT_BUILD}                                             \
   233                 --host=${CT_BUILD}                                              \
   234                 --prefix=/usr                                                   \
   235                 --enable-symlinks                                               \
   236                 --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   237                 --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   238                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   239                 "${ncurses_opts[@]}"
   240 
   241             # ncurses insists on linking tic statically. It does not work
   242             # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
   243             CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
   244 
   245             # Under some operating systems (eg. Winblows), there is an
   246             # extension appended to executables. Find that.
   247             tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   248 
   249             CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   250             CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   251 
   252             CT_DoExecLog ALL install -d -m 0755 "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   253             CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
   254 
   255             mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   256             cd "${CT_BUILD_DIR}/build-ncurses"
   257 
   258             CT_DoExecLog CFG                                                    \
   259             TIC_PATH="${CT_BUILDTOOLS_PREFIX_DIR}/bin/tic${tic_ext}"            \
   260             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   261                 --build=${CT_BUILD}                                             \
   262                 --host=${CT_TARGET}                                             \
   263                 --with-build-cc=${CT_BUILD}-gcc                                 \
   264                 --with-build-cpp=${CT_BUILD}-gcc                                \
   265                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   266                 --prefix="${CT_BUILD_DIR}/static-target"                        \
   267                 --without-shared                                                \
   268                 --without-sysmouse                                              \
   269                 --without-progs                                                 \
   270                 --enable-termcap                                                \
   271                 "${ncurses_opts[@]}"
   272 
   273             CT_DoExecLog ALL make ${JOBSFLAGS}
   274 
   275             CT_DoExecLog ALL make install
   276 
   277             native_extra_config+=("--with-curses")
   278             # There's no better way to tell gdb where to find -lcurses... :-(
   279             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   280             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   281         fi # do_ncurses
   282 
   283         if [ "${do_expat}" = "y" ]; then
   284             CT_DoLog EXTRA "Building static target expat"
   285 
   286             mkdir -p "${CT_BUILD_DIR}/expat-build"
   287             cd "${CT_BUILD_DIR}/expat-build"
   288 
   289             CT_DoExecLog CFG                                                \
   290             "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   291                 --build=${CT_BUILD}                                         \
   292                 --host=${CT_TARGET}                                         \
   293                 --prefix="${CT_BUILD_DIR}/static-target"                    \
   294                 --enable-static                                             \
   295                 --disable-shared
   296 
   297             CT_DoExecLog ALL make ${JOBSFLAGS}
   298             CT_DoExecLog ALL make install
   299 
   300             native_extra_config+=("--with-expat")
   301             native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   302         fi # do_expat
   303 
   304         CT_DoLog EXTRA "Configuring native gdb"
   305 
   306         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   307         cd "${CT_BUILD_DIR}/build-gdb-native"
   308 
   309         case "${CT_THREADS}" in
   310             none)   native_extra_config+=("--disable-threads");;
   311             *)      native_extra_config+=("--enable-threads");;
   312         esac
   313 
   314         [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] &&    \
   315         native_extra_config+=("--disable-nls")
   316 
   317         if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
   318             CC_for_gdb="${CT_TARGET}-gcc -static"
   319             LD_for_gdb="${CT_TARGET}-ld -static"
   320         else
   321             CC_for_gdb="${CT_TARGET}-gcc"
   322             LD_for_gdb="${CT_TARGET}-ld"
   323         fi
   324 
   325         export ac_cv_func_strncmp_works=yes
   326 
   327         CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
   328 
   329         CT_DoExecLog CFG                                \
   330         CC="${CC_for_gdb}"                              \
   331         LD="${LD_for_gdb}"                              \
   332         CFLAGS="${gdb_native_CFLAGS[*]}"                \
   333         "${gdb_src_dir}/configure"                      \
   334             --build=${CT_BUILD}                         \
   335             --host=${CT_TARGET}                         \
   336             --target=${CT_TARGET}                       \
   337             --prefix=/usr                               \
   338             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   339             --without-uiout                             \
   340             --disable-tui                               \
   341             --disable-gdbtk                             \
   342             --without-x                                 \
   343             --disable-sim                               \
   344             --disable-werror                            \
   345             --without-included-gettext                  \
   346             --without-develop                           \
   347             "${native_extra_config[@]}"
   348 
   349         CT_DoLog EXTRA "Building native gdb"
   350         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   351 
   352         CT_DoLog EXTRA "Installing native gdb"
   353         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   354 
   355         # Building a native gdb also builds a gdbserver
   356         find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
   357 
   358         unset ac_cv_func_strncmp_works
   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 }