scripts/build/debug/300-gdb.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Mar 03 19:26:08 2011 +0100 (2011-03-03)
changeset 2326 3d0a8d386afd
parent 2303 88871c8621b8
child 2344 7b6d5c5316ab
permissions -rw-r--r--
debug/gdb: chmod ncurses files to u+w

The ncurses-5.7 tarball contains only RO files.
We have to chmod them u+w.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.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.7"
     8 
     9 # Ditto for the expat library
    10 CT_DEBUG_GDB_EXPAT_VERSION="2.0.1"
    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://mesh.dl.sourceforge.net/sourceforge/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_CROSS}" = "y" ]; then
   102         local -a cross_extra_config
   103 
   104         CT_DoStep INFO "Installing cross-gdb"
   105         CT_DoLog EXTRA "Configuring cross-gdb"
   106 
   107         mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
   108         cd "${CT_BUILD_DIR}/build-gdb-cross"
   109 
   110         cross_extra_config=("${extra_config[@]}")
   111         case "${CT_THREADS}" in
   112             none)   cross_extra_config+=("--disable-threads");;
   113             *)      cross_extra_config+=("--enable-threads");;
   114         esac
   115 
   116         CC_for_gdb=
   117         LD_for_gdb=
   118         if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
   119             CC_for_gdb="gcc -static"
   120             LD_for_gdb="ld -static"
   121         fi
   122 
   123         gdb_cross_configure="${gdb_src_dir}/configure"
   124 
   125         CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
   126 
   127         CC="${CC_for_gdb}"                              \
   128         LD="${LD_for_gdb}"                              \
   129         CT_DoExecLog CFG                                \
   130         "${gdb_cross_configure}"                        \
   131             --build=${CT_BUILD}                         \
   132             --host=${CT_HOST}                           \
   133             --target=${CT_TARGET}                       \
   134             --prefix="${CT_PREFIX_DIR}"                 \
   135             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   136             --disable-werror                            \
   137             "${cross_extra_config[@]}"
   138 
   139         CT_DoLog EXTRA "Building cross-gdb"
   140         CT_DoExecLog ALL make ${JOBSFLAGS}
   141 
   142         CT_DoLog EXTRA "Installing cross-gdb"
   143         CT_DoExecLog ALL make install
   144 
   145         CT_EndStep
   146     fi
   147 
   148     if [ "${CT_GDB_NATIVE}" = "y" ]; then
   149         local -a native_extra_config
   150         local -a ncurses_opt
   151         local -a gdb_native_CFLAGS
   152 
   153         CT_DoStep INFO "Installing native gdb"
   154 
   155         native_extra_config=("${extra_config[@]}")
   156 
   157         # GDB on Mingw depends on PDcurses, not ncurses
   158         if [ "${do_ncurses}" = "y" ]; then
   159             CT_DoLog EXTRA "Building static target ncurses"
   160 
   161             [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
   162             [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
   163 
   164             mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
   165             cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
   166 
   167             # Use build = CT_REAL_BUILD so that configure thinks it is
   168             # cross-compiling, and thus will use the ${CT_BUILD}-*
   169             # tools instead of searching for the native ones...
   170             CT_DoExecLog CFG                                                    \
   171             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   172                 --build=${CT_BUILD}                                             \
   173                 --host=${CT_BUILD}                                              \
   174                 --prefix=/usr                                                   \
   175                 --without-shared                                                \
   176                 --enable-symlinks                                               \
   177                 --with-build-cc=${CT_REAL_BUILD}-gcc                            \
   178                 --with-build-cpp=${CT_REAL_BUILD}-gcc                           \
   179                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   180                 "${ncurses_opts[@]}"
   181 
   182             # Under some operating systems (eg. Winblows), there is an
   183             # extension appended to executables. Find that.
   184             tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
   185 
   186             CT_DoExecLog ALL make ${JOBSFLAGS} -C include
   187             CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
   188 
   189             CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
   190             CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
   191 
   192             mkdir -p "${CT_BUILD_DIR}/build-ncurses"
   193             cd "${CT_BUILD_DIR}/build-ncurses"
   194 
   195             CT_DoExecLog CFG                                                    \
   196             "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure"   \
   197                 --build=${CT_BUILD}                                             \
   198                 --host=${CT_TARGET}                                             \
   199                 --with-build-cc=${CT_BUILD}-gcc                                 \
   200                 --with-build-cpp=${CT_BUILD}-gcc                                \
   201                 --with-build-cflags="${CT_CFLAGS_FOR_HOST}"                     \
   202                 --prefix="${CT_BUILD_DIR}/static-target"                        \
   203                 --without-shared                                                \
   204                 --without-sysmouse                                              \
   205                 --without-progs                                                 \
   206                 --enable-termcap                                                \
   207                 "${ncurses_opts[@]}"
   208 
   209             CT_DoExecLog ALL make ${JOBSFLAGS}
   210 
   211             CT_DoExecLog ALL make install
   212 
   213             # We no longer need the temporary tic. Remove it
   214             CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
   215 
   216             native_extra_config+=("--with-curses")
   217             # There's no better way to tell gdb where to find -lcurses... :-(
   218             gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
   219             gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
   220         fi # do_ncurses
   221 
   222         if [ "${do_expat}" = "y" ]; then
   223             CT_DoLog EXTRA "Building static target expat"
   224 
   225             mkdir -p "${CT_BUILD_DIR}/expat-build"
   226             cd "${CT_BUILD_DIR}/expat-build"
   227 
   228             CT_DoExecLog CFG                                                \
   229             "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure"   \
   230                 --build=${CT_BUILD}                                         \
   231                 --host=${CT_TARGET}                                         \
   232                 --prefix="${CT_BUILD_DIR}/static-target"                    \
   233                 --enable-static                                             \
   234                 --disable-shared
   235 
   236             CT_DoExecLog ALL make ${JOBSFLAGS}
   237             CT_DoExecLog ALL make install
   238 
   239             native_extra_config+=("--with-expat")
   240             native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
   241         fi # do_expat
   242 
   243         CT_DoLog EXTRA "Configuring native gdb"
   244 
   245         mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
   246         cd "${CT_BUILD_DIR}/build-gdb-native"
   247 
   248         case "${CT_THREADS}" in
   249             none)   native_extra_config+=("--disable-threads");;
   250             *)      native_extra_config+=("--enable-threads");;
   251         esac
   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         CC="${CC_for_gdb}"                              \
   266         LD="${LD_for_gdb}"                              \
   267         CFLAGS="${gdb_native_CFLAGS[@]}"                \
   268         CT_DoExecLog CFG                                \
   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         # GDB on Mingw depends on PDcurses, not ncurses
   297         if [ "${CT_MINGW32}" != "y" ]; then
   298             CT_DoLog EXTRA "Cleaning up ncurses"
   299             cd "${CT_BUILD_DIR}/build-ncurses"
   300             CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
   301 
   302             CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
   303         fi
   304 
   305         CT_EndStep # native gdb build
   306     fi
   307 
   308     if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
   309         local -a gdbserver_extra_config
   310 
   311         CT_DoStep INFO "Installing gdbserver"
   312         CT_DoLog EXTRA "Configuring gdbserver"
   313 
   314         mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
   315         cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
   316 
   317         # Workaround for bad versions, where the configure
   318         # script for gdbserver is not executable...
   319         # Bah, GNU folks strike again... :-(
   320         chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
   321 
   322         gdbserver_LDFLAGS=
   323         if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
   324             gdbserver_LDFLAGS=-static
   325         fi
   326 
   327         gdbserver_extra_config=("${extra_config[@]}")
   328 
   329         LDFLAGS="${gdbserver_LDFLAGS}"                  \
   330         CT_DoExecLog CFG                                \
   331         "${gdb_src_dir}/gdb/gdbserver/configure"        \
   332             --build=${CT_BUILD}                         \
   333             --host=${CT_TARGET}                         \
   334             --target=${CT_TARGET}                       \
   335             --prefix=/usr                               \
   336             --sysconfdir=/etc                           \
   337             --localstatedir=/var                        \
   338             --includedir="${CT_HEADERS_DIR}"            \
   339             --with-build-sysroot="${CT_SYSROOT_DIR}"    \
   340             --program-prefix=                           \
   341             --without-uiout                             \
   342             --disable-tui                               \
   343             --disable-gdbtk                             \
   344             --without-x                                 \
   345             --without-included-gettext                  \
   346             --without-develop                           \
   347             --disable-werror                            \
   348             "${gdbserver_extra_config[@]}"
   349 
   350         CT_DoLog EXTRA "Building gdbserver"
   351         CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
   352 
   353         CT_DoLog EXTRA "Installing gdbserver"
   354         CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
   355 
   356         CT_EndStep
   357     fi
   358 }