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.7"
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_CROSS}" = "y" ]; then
102 local -a cross_extra_config
104 CT_DoStep INFO "Installing cross-gdb"
105 CT_DoLog EXTRA "Configuring cross-gdb"
107 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
108 cd "${CT_BUILD_DIR}/build-gdb-cross"
110 cross_extra_config=("${extra_config[@]}")
111 case "${CT_THREADS}" in
112 none) cross_extra_config+=("--disable-threads");;
113 *) cross_extra_config+=("--enable-threads");;
118 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
119 CC_for_gdb="gcc -static"
120 LD_for_gdb="ld -static"
123 gdb_cross_configure="${gdb_src_dir}/configure"
125 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
130 "${gdb_cross_configure}" \
131 --build=${CT_BUILD} \
133 --target=${CT_TARGET} \
134 --prefix="${CT_PREFIX_DIR}" \
135 --with-build-sysroot="${CT_SYSROOT_DIR}" \
136 --with-sysroot="${CT_SYSROOT_DIR}" \
138 "${cross_extra_config[@]}"
140 CT_DoLog EXTRA "Building cross-gdb"
141 CT_DoExecLog ALL make ${JOBSFLAGS}
143 CT_DoLog EXTRA "Installing cross-gdb"
144 CT_DoExecLog ALL make install
149 if [ "${CT_GDB_NATIVE}" = "y" ]; then
150 local -a native_extra_config
152 local -a gdb_native_CFLAGS
154 CT_DoStep INFO "Installing native gdb"
156 native_extra_config=("${extra_config[@]}")
158 # GDB on Mingw depends on PDcurses, not ncurses
159 if [ "${do_ncurses}" = "y" ]; then
160 CT_DoLog EXTRA "Building static target ncurses"
162 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
163 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
165 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
166 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
168 # Use build = CT_REAL_BUILD so that configure thinks it is
169 # cross-compiling, and thus will use the ${CT_BUILD}-*
170 # tools instead of searching for the native ones...
172 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
173 --build=${CT_BUILD} \
178 --with-build-cc=${CT_REAL_BUILD}-gcc \
179 --with-build-cpp=${CT_REAL_BUILD}-gcc \
180 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
183 # Under some operating systems (eg. Winblows), there is an
184 # extension appended to executables. Find that.
185 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
187 CT_DoExecLog ALL make ${JOBSFLAGS} -C include
188 CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
190 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
191 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
193 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
194 cd "${CT_BUILD_DIR}/build-ncurses"
197 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
198 --build=${CT_BUILD} \
199 --host=${CT_TARGET} \
200 --with-build-cc=${CT_BUILD}-gcc \
201 --with-build-cpp=${CT_BUILD}-gcc \
202 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
203 --prefix="${CT_BUILD_DIR}/static-target" \
210 CT_DoExecLog ALL make ${JOBSFLAGS}
212 CT_DoExecLog ALL make install
214 # We no longer need the temporary tic. Remove it
215 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
217 native_extra_config+=("--with-curses")
218 # There's no better way to tell gdb where to find -lcurses... :-(
219 gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
220 gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
223 if [ "${do_expat}" = "y" ]; then
224 CT_DoLog EXTRA "Building static target expat"
226 mkdir -p "${CT_BUILD_DIR}/expat-build"
227 cd "${CT_BUILD_DIR}/expat-build"
230 "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure" \
231 --build=${CT_BUILD} \
232 --host=${CT_TARGET} \
233 --prefix="${CT_BUILD_DIR}/static-target" \
237 CT_DoExecLog ALL make ${JOBSFLAGS}
238 CT_DoExecLog ALL make install
240 native_extra_config+=("--with-expat")
241 native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
244 CT_DoLog EXTRA "Configuring native gdb"
246 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
247 cd "${CT_BUILD_DIR}/build-gdb-native"
249 case "${CT_THREADS}" in
250 none) native_extra_config+=("--disable-threads");;
251 *) native_extra_config+=("--enable-threads");;
254 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
255 CC_for_gdb="${CT_TARGET}-gcc -static"
256 LD_for_gdb="${CT_TARGET}-ld -static"
258 CC_for_gdb="${CT_TARGET}-gcc"
259 LD_for_gdb="${CT_TARGET}-ld"
262 export ac_cv_func_strncmp_works=yes
264 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
269 CFLAGS="${gdb_native_CFLAGS[*]}" \
270 "${gdb_src_dir}/configure" \
271 --build=${CT_BUILD} \
272 --host=${CT_TARGET} \
273 --target=${CT_TARGET} \
275 --with-build-sysroot="${CT_SYSROOT_DIR}" \
282 --without-included-gettext \
284 "${native_extra_config[@]}"
286 CT_DoLog EXTRA "Building native gdb"
287 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
289 CT_DoLog EXTRA "Installing native gdb"
290 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
292 # Building a native gdb also builds a gdbserver
293 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
295 unset ac_cv_func_strncmp_works
297 # GDB on Mingw depends on PDcurses, not ncurses
298 if [ "${CT_MINGW32}" != "y" ]; then
299 CT_DoLog EXTRA "Cleaning up ncurses"
300 cd "${CT_BUILD_DIR}/build-ncurses"
301 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
303 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
306 CT_EndStep # native gdb build
309 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
310 local -a gdbserver_extra_config
312 CT_DoStep INFO "Installing gdbserver"
313 CT_DoLog EXTRA "Configuring gdbserver"
315 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
316 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
318 # Workaround for bad versions, where the configure
319 # script for gdbserver is not executable...
320 # Bah, GNU folks strike again... :-(
321 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
324 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
325 gdbserver_LDFLAGS=-static
328 gdbserver_extra_config=("${extra_config[@]}")
331 LDFLAGS="${gdbserver_LDFLAGS}" \
332 "${gdb_src_dir}/gdb/gdbserver/configure" \
333 --build=${CT_BUILD} \
334 --host=${CT_TARGET} \
335 --target=${CT_TARGET} \
338 --localstatedir=/var \
339 --includedir="${CT_HEADERS_DIR}" \
340 --with-build-sysroot="${CT_SYSROOT_DIR}" \
346 --without-included-gettext \
349 "${gdbserver_extra_config[@]}"
351 CT_DoLog EXTRA "Building gdbserver"
352 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
354 CT_DoLog EXTRA "Installing gdbserver"
355 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install