scripts/build/debug/300-gdb.sh
author David Holsgrove <david.holsgrove@xilinx.com>
Wed Oct 03 15:59:22 2012 +1000 (2012-10-03)
changeset 3071 5243d1b432b1
parent 3036 dd76ebcb1882
child 3072 15fa0b85025e
permissions -rw-r--r--
scripts/gdb: If not building expat for gdb, disable

--with-expat=yes is unconditionally passed to the gdb configure
stage, instead of respecting the ${do_expat} decision.

Disable if not needed. Prevents error building canadian cross;

configure: error: expat is missing or unusable

Where configure stage fails to find expat on the host compiler.

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