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[@]}"
152 CT_DoLog EXTRA "Building cross-gdb"
153 CT_DoExecLog ALL make ${JOBSFLAGS}
155 CT_DoLog EXTRA "Installing cross-gdb"
156 CT_DoExecLog ALL make install
158 if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
159 CT_DoLog EXTRA "Install '.gdbinit' template"
160 # See in scripts/build/internals.sh for why we do this
161 if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
162 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
164 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
165 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c" \
169 -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \
170 -e "s:@@VERSION@@:${gcc_version}:;" \
171 "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \
172 >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
173 fi # Install gdbinit sample
178 if [ "${CT_GDB_NATIVE}" = "y" ]; then
179 local -a native_extra_config
181 local -a gdb_native_CFLAGS
183 CT_DoStep INFO "Installing native gdb"
185 native_extra_config=("${extra_config[@]}")
187 # GDB on Mingw depends on PDcurses, not ncurses
188 if [ "${do_ncurses}" = "y" ]; then
189 CT_DoLog EXTRA "Building static target ncurses"
191 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
192 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
194 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
195 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
197 # Use build = CT_REAL_BUILD so that configure thinks it is
198 # cross-compiling, and thus will use the ${CT_BUILD}-*
199 # tools instead of searching for the native ones...
201 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
202 --build=${CT_BUILD} \
206 --with-build-cc=${CT_REAL_BUILD}-gcc \
207 --with-build-cpp=${CT_REAL_BUILD}-gcc \
208 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
211 # ncurses insists on linking tic statically. It does not work
212 # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
213 CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
215 # Under some operating systems (eg. Winblows), there is an
216 # extension appended to executables. Find that.
217 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
219 CT_DoExecLog ALL make ${JOBSFLAGS} -C include
220 CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
222 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
223 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
225 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
226 cd "${CT_BUILD_DIR}/build-ncurses"
229 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
230 --build=${CT_BUILD} \
231 --host=${CT_TARGET} \
232 --with-build-cc=${CT_BUILD}-gcc \
233 --with-build-cpp=${CT_BUILD}-gcc \
234 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
235 --prefix="${CT_BUILD_DIR}/static-target" \
242 CT_DoExecLog ALL make ${JOBSFLAGS}
244 CT_DoExecLog ALL make install
246 # We no longer need the temporary tic. Remove it
247 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
249 native_extra_config+=("--with-curses")
250 # There's no better way to tell gdb where to find -lcurses... :-(
251 gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
252 gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
255 if [ "${do_expat}" = "y" ]; then
256 CT_DoLog EXTRA "Building static target expat"
258 mkdir -p "${CT_BUILD_DIR}/expat-build"
259 cd "${CT_BUILD_DIR}/expat-build"
262 "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure" \
263 --build=${CT_BUILD} \
264 --host=${CT_TARGET} \
265 --prefix="${CT_BUILD_DIR}/static-target" \
269 CT_DoExecLog ALL make ${JOBSFLAGS}
270 CT_DoExecLog ALL make install
272 native_extra_config+=("--with-expat")
273 native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
276 CT_DoLog EXTRA "Configuring native gdb"
278 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
279 cd "${CT_BUILD_DIR}/build-gdb-native"
281 case "${CT_THREADS}" in
282 none) native_extra_config+=("--disable-threads");;
283 *) native_extra_config+=("--enable-threads");;
286 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
287 CC_for_gdb="${CT_TARGET}-gcc -static"
288 LD_for_gdb="${CT_TARGET}-ld -static"
290 CC_for_gdb="${CT_TARGET}-gcc"
291 LD_for_gdb="${CT_TARGET}-ld"
294 export ac_cv_func_strncmp_works=yes
296 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
301 CFLAGS="${gdb_native_CFLAGS[*]}" \
302 "${gdb_src_dir}/configure" \
303 --build=${CT_BUILD} \
304 --host=${CT_TARGET} \
305 --target=${CT_TARGET} \
307 --with-build-sysroot="${CT_SYSROOT_DIR}" \
314 --without-included-gettext \
316 "${native_extra_config[@]}"
318 CT_DoLog EXTRA "Building native gdb"
319 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
321 CT_DoLog EXTRA "Installing native gdb"
322 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
324 # Building a native gdb also builds a gdbserver
325 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
327 unset ac_cv_func_strncmp_works
329 # GDB on Mingw depends on PDcurses, not ncurses
330 if [ "${CT_MINGW32}" != "y" ]; then
331 CT_DoLog EXTRA "Cleaning up ncurses"
332 cd "${CT_BUILD_DIR}/build-ncurses"
333 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
335 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
338 CT_EndStep # native gdb build
341 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
342 local -a gdbserver_extra_config
344 CT_DoStep INFO "Installing gdbserver"
345 CT_DoLog EXTRA "Configuring gdbserver"
347 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
348 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
350 # Workaround for bad versions, where the configure
351 # script for gdbserver is not executable...
352 # Bah, GNU folks strike again... :-(
353 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
356 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
357 gdbserver_LDFLAGS=-static
360 gdbserver_extra_config=("${extra_config[@]}")
363 LDFLAGS="${gdbserver_LDFLAGS}" \
364 "${gdb_src_dir}/gdb/gdbserver/configure" \
365 --build=${CT_BUILD} \
366 --host=${CT_TARGET} \
367 --target=${CT_TARGET} \
370 --localstatedir=/var \
371 --includedir="${CT_HEADERS_DIR}" \
372 --with-build-sysroot="${CT_SYSROOT_DIR}" \
378 --without-included-gettext \
381 "${gdbserver_extra_config[@]}"
383 CT_DoLog EXTRA "Building gdbserver"
384 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
386 CT_DoLog EXTRA "Installing gdbserver"
387 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install