1 # Build script for the gdb debug facility
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"
9 # Ditto for the expat library
10 CT_DEBUG_GDB_EXPAT_VERSION="2.0.1"
12 do_debug_gdb_parts() {
17 if [ "${CT_GDB_CROSS}" = y ]; then
21 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
25 if [ "${CT_GDB_NATIVE}" = "y" ]; then
27 # GDB on Mingw depends on PDcurses, not ncurses
28 if [ "${CT_MINGW32}" != "y" ]; then
38 local linaro_base_url="http://launchpad.net/gdb-linaro"
40 # Account for the Linaro versioning
41 linaro_version="$( echo "${CT_GDB_VERSION}" \
42 |sed -r -e 's/^linaro-//;' \
44 linaro_series="$( echo "${linaro_version}" \
45 |sed -r -e 's/-.*//;' \
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"
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
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}
69 do_debug_gdb_extract() {
72 if [ "${do_gdb}" = "y" ]; then
73 CT_Extract "gdb-${CT_GDB_VERSION}"
74 CT_Patch "gdb" "${CT_GDB_VERSION}"
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}"
83 if [ "${do_expat}" = "y" ]; then
84 CT_Extract "expat-${CT_DEBUG_GDB_EXPAT_VERSION}"
85 CT_Patch "expat" "${CT_DEBUG_GDB_EXPAT_VERSION}"
89 do_debug_gdb_build() {
94 gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
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");;
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}")
106 if [ "${CT_GDB_CROSS}" = "y" ]; then
107 local -a cross_extra_config
110 CT_DoStep INFO "Installing cross-gdb"
111 CT_DoLog EXTRA "Configuring cross-gdb"
113 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
114 cd "${CT_BUILD_DIR}/build-gdb-cross"
116 cross_extra_config=("${extra_config[@]}")
117 case "${CT_THREADS}" in
118 none) cross_extra_config+=("--disable-threads");;
119 *) cross_extra_config+=("--enable-threads");;
121 if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then
122 cross_extra_config+=( "--with-python=yes" )
124 cross_extra_config+=( "--with-python=no" )
129 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
130 CC_for_gdb="gcc -static"
131 LD_for_gdb="ld -static"
134 gdb_cross_configure="${gdb_src_dir}/configure"
136 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
141 "${gdb_cross_configure}" \
142 --build=${CT_BUILD} \
144 --target=${CT_TARGET} \
145 --prefix="${CT_PREFIX_DIR}" \
146 --with-build-sysroot="${CT_SYSROOT_DIR}" \
147 --with-sysroot="${CT_SYSROOT_DIR}" \
150 "${cross_extra_config[@]}" \
151 "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}"
153 CT_DoLog EXTRA "Building cross-gdb"
154 CT_DoExecLog ALL make ${JOBSFLAGS}
156 CT_DoLog EXTRA "Installing cross-gdb"
157 CT_DoExecLog ALL make install
159 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
160 CT_DoLog EXTRA "Building and installing the cross-GDB manuals"
161 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
162 CT_DoExecLog ALL make install-{pdf,html}-gdb
165 if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
166 CT_DoLog EXTRA "Install '.gdbinit' template"
167 # See in scripts/build/internals.sh for why we do this
168 if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
169 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
171 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
172 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c" \
176 -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \
177 -e "s:@@VERSION@@:${gcc_version}:;" \
178 "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \
179 >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
180 fi # Install gdbinit sample
185 if [ "${CT_GDB_NATIVE}" = "y" ]; then
186 local -a native_extra_config
188 local -a gdb_native_CFLAGS
190 CT_DoStep INFO "Installing native gdb"
192 native_extra_config=("${extra_config[@]}")
194 # GDB on Mingw depends on PDcurses, not ncurses
195 if [ "${do_ncurses}" = "y" ]; then
196 CT_DoLog EXTRA "Building static target ncurses"
198 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
199 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
201 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
202 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
204 # Use build = CT_REAL_BUILD so that configure thinks it is
205 # cross-compiling, and thus will use the ${CT_BUILD}-*
206 # tools instead of searching for the native ones...
208 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
209 --build=${CT_BUILD} \
213 --with-build-cc=${CT_REAL_BUILD}-gcc \
214 --with-build-cpp=${CT_REAL_BUILD}-gcc \
215 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
218 # ncurses insists on linking tic statically. It does not work
219 # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
220 CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
222 # Under some operating systems (eg. Winblows), there is an
223 # extension appended to executables. Find that.
224 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
226 CT_DoExecLog ALL make ${JOBSFLAGS} -C include
227 CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
229 CT_DoExecLog ALL install -d -m 0755 "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
230 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
232 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
233 cd "${CT_BUILD_DIR}/build-ncurses"
236 TIC_PATH="${CT_BUILDTOOLS_PREFIX_DIR}/bin/tic${tic_ext}" \
237 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
238 --build=${CT_BUILD} \
239 --host=${CT_TARGET} \
240 --with-build-cc=${CT_BUILD}-gcc \
241 --with-build-cpp=${CT_BUILD}-gcc \
242 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
243 --prefix="${CT_BUILD_DIR}/static-target" \
250 CT_DoExecLog ALL make ${JOBSFLAGS}
252 CT_DoExecLog ALL make install
254 native_extra_config+=("--with-curses")
255 # There's no better way to tell gdb where to find -lcurses... :-(
256 gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
257 gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
260 if [ "${do_expat}" = "y" ]; then
261 CT_DoLog EXTRA "Building static target expat"
263 mkdir -p "${CT_BUILD_DIR}/expat-build"
264 cd "${CT_BUILD_DIR}/expat-build"
267 "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure" \
268 --build=${CT_BUILD} \
269 --host=${CT_TARGET} \
270 --prefix="${CT_BUILD_DIR}/static-target" \
274 CT_DoExecLog ALL make ${JOBSFLAGS}
275 CT_DoExecLog ALL make install
277 native_extra_config+=("--with-expat")
278 native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
281 CT_DoLog EXTRA "Configuring native gdb"
283 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
284 cd "${CT_BUILD_DIR}/build-gdb-native"
286 case "${CT_THREADS}" in
287 none) native_extra_config+=("--disable-threads");;
288 *) native_extra_config+=("--enable-threads");;
291 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
292 CC_for_gdb="${CT_TARGET}-gcc -static"
293 LD_for_gdb="${CT_TARGET}-ld -static"
295 CC_for_gdb="${CT_TARGET}-gcc"
296 LD_for_gdb="${CT_TARGET}-ld"
299 export ac_cv_func_strncmp_works=yes
301 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
306 CFLAGS="${gdb_native_CFLAGS[*]}" \
307 "${gdb_src_dir}/configure" \
308 --build=${CT_BUILD} \
309 --host=${CT_TARGET} \
310 --target=${CT_TARGET} \
312 --with-build-sysroot="${CT_SYSROOT_DIR}" \
319 --without-included-gettext \
321 "${native_extra_config[@]}"
323 CT_DoLog EXTRA "Building native gdb"
324 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
326 CT_DoLog EXTRA "Installing native gdb"
327 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
329 # Building a native gdb also builds a gdbserver
330 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
332 unset ac_cv_func_strncmp_works
334 # GDB on Mingw depends on PDcurses, not ncurses
335 if [ "${CT_MINGW32}" != "y" ]; then
336 CT_DoLog EXTRA "Cleaning up ncurses"
337 cd "${CT_BUILD_DIR}/build-ncurses"
338 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
340 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
343 CT_EndStep # native gdb build
346 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
347 local -a gdbserver_extra_config
349 CT_DoStep INFO "Installing gdbserver"
350 CT_DoLog EXTRA "Configuring gdbserver"
352 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
353 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
355 # Workaround for bad versions, where the configure
356 # script for gdbserver is not executable...
357 # Bah, GNU folks strike again... :-(
358 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
361 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
362 gdbserver_LDFLAGS=-static
365 gdbserver_extra_config=("${extra_config[@]}")
368 LDFLAGS="${gdbserver_LDFLAGS}" \
369 "${gdb_src_dir}/gdb/gdbserver/configure" \
370 --build=${CT_BUILD} \
371 --host=${CT_TARGET} \
372 --target=${CT_TARGET} \
375 --localstatedir=/var \
376 --includedir="${CT_HEADERS_DIR}" \
377 --with-build-sysroot="${CT_SYSROOT_DIR}" \
383 --without-included-gettext \
386 "${gdbserver_extra_config[@]}"
388 CT_DoLog EXTRA "Building gdbserver"
389 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
391 CT_DoLog EXTRA "Installing gdbserver"
392 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install