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 if [ "${do_gdb}" = "y" ]; then
39 CT_GetFile "gdb-${CT_GDB_VERSION}" \
40 {ftp,http}://ftp.gnu.org/pub/gnu/gdb \
41 ftp://sources.redhat.com/pub/gdb/{,old-}releases
44 if [ "${do_ncurses}" = "y" ]; then
45 CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz \
46 {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
47 ftp://invisible-island.net/ncurses
50 if [ "${do_expat}" = "y" ]; then
51 CT_GetFile "expat-${CT_DEBUG_GDB_EXPAT_VERSION}" .tar.gz \
52 http://mesh.dl.sourceforge.net/sourceforge/expat/expat/${CT_DEBUG_GDB_EXPAT_VERSION}
56 do_debug_gdb_extract() {
59 if [ "${do_gdb}" = "y" ]; then
60 CT_Extract "gdb-${CT_GDB_VERSION}"
61 CT_Patch "gdb" "${CT_GDB_VERSION}"
64 if [ "${do_ncurses}" = "y" ]; then
65 CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
66 CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
69 if [ "${do_expat}" = "y" ]; then
70 CT_Extract "expat-${CT_DEBUG_GDB_EXPAT_VERSION}"
71 CT_Patch "expat" "${CT_DEBUG_GDB_EXPAT_VERSION}"
75 do_debug_gdb_build() {
80 gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
82 # Version 6.3 and below behave badly with gdbmi
83 case "${CT_GDB_VERSION}" in
84 6.2*|6.3) extra_config+=("--disable-gdbmi");;
87 if [ "${CT_GDB_CROSS}" = "y" ]; then
88 local -a cross_extra_config
90 CT_DoStep INFO "Installing cross-gdb"
91 CT_DoLog EXTRA "Configuring cross-gdb"
93 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
94 cd "${CT_BUILD_DIR}/build-gdb-cross"
96 cross_extra_config=("${extra_config[@]}")
97 case "${CT_THREADS}" in
98 none) cross_extra_config+=("--disable-threads");;
99 *) cross_extra_config+=("--enable-threads");;
104 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
105 CC_for_gdb="gcc -static"
106 LD_for_gdb="ld -static"
109 gdb_cross_configure="${gdb_src_dir}/configure"
111 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
116 "${gdb_cross_configure}" \
117 --build=${CT_BUILD} \
119 --target=${CT_TARGET} \
120 --prefix="${CT_PREFIX_DIR}" \
121 --with-build-sysroot="${CT_SYSROOT_DIR}" \
123 "${cross_extra_config[@]}"
125 CT_DoLog EXTRA "Building cross-gdb"
126 CT_DoExecLog ALL make ${PARALLELMFLAGS}
128 CT_DoLog EXTRA "Installing cross-gdb"
129 CT_DoExecLog ALL make install
134 if [ "${CT_GDB_NATIVE}" = "y" ]; then
135 local -a native_extra_config
137 local -a gdb_native_CFLAGS
139 CT_DoStep INFO "Installing native gdb"
141 native_extra_config=("${extra_config[@]}")
143 # GDB on Mingw depends on PDcurses, not ncurses
144 if [ "${do_ncurses}" = "y" ]; then
145 CT_DoLog EXTRA "Building static target ncurses"
147 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
148 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
150 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
151 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
153 # Use build = CT_REAL_BUILD so that configure thinks it is
154 # cross-compiling, and thus will use the ${CT_BUILD}-*
155 # tools instead of searching for the native ones...
157 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
158 --build=${CT_BUILD} \
163 --with-build-cc=${CT_REAL_BUILD}-gcc \
164 --with-build-cpp=${CT_REAL_BUILD}-gcc \
165 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
168 # Under some operating systems (eg. Winblows), there is an
169 # extension appended to executables. Find that.
170 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
172 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
173 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
175 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
176 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
178 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
179 cd "${CT_BUILD_DIR}/build-ncurses"
182 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
183 --build=${CT_BUILD} \
184 --host=${CT_TARGET} \
185 --with-build-cc=${CT_BUILD}-gcc \
186 --with-build-cpp=${CT_BUILD}-gcc \
187 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
188 --prefix="${CT_BUILD_DIR}/static-target" \
195 CT_DoExecLog ALL make ${PARALLELMFLAGS}
197 CT_DoExecLog ALL make install
199 # We no longer need the temporary tic. Remove it
200 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
202 native_extra_config+=("--with-curses")
203 # There's no better way to tell gdb where to find -lcurses... :-(
204 gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
205 gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
208 if [ "${do_expat}" = "y" ]; then
209 CT_DoLog EXTRA "Building static target expat"
211 mkdir -p "${CT_BUILD_DIR}/expat-build"
212 cd "${CT_BUILD_DIR}/expat-build"
215 "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure" \
216 --build=${CT_BUILD} \
217 --host=${CT_TARGET} \
218 --prefix="${CT_BUILD_DIR}/static-target" \
222 CT_DoExecLog ALL make ${PARALLELMFLAGS}
223 CT_DoExecLog ALL make install
225 native_extra_config+=("--with-expat")
226 native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
229 CT_DoLog EXTRA "Configuring native gdb"
231 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
232 cd "${CT_BUILD_DIR}/build-gdb-native"
234 case "${CT_THREADS}" in
235 none) native_extra_config+=("--disable-threads");;
236 *) native_extra_config+=("--enable-threads");;
239 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
240 CC_for_gdb="${CT_TARGET}-gcc -static"
241 LD_for_gdb="${CT_TARGET}-ld -static"
243 CC_for_gdb="${CT_TARGET}-gcc"
244 LD_for_gdb="${CT_TARGET}-ld"
247 export ac_cv_func_strncmp_works=yes
249 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
253 CFLAGS="${gdb_native_CFLAGS[@]}" \
255 "${gdb_src_dir}/configure" \
256 --build=${CT_BUILD} \
257 --host=${CT_TARGET} \
258 --target=${CT_TARGET} \
260 --with-build-sysroot="${CT_SYSROOT_DIR}" \
267 --without-included-gettext \
269 "${native_extra_config[@]}"
271 CT_DoLog EXTRA "Building native gdb"
272 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
274 CT_DoLog EXTRA "Installing native gdb"
275 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
277 # Building a native gdb also builds a gdbserver
278 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
280 unset ac_cv_func_strncmp_works
282 # GDB on Mingw depends on PDcurses, not ncurses
283 if [ "${CT_MINGW32}" != "y" ]; then
284 CT_DoLog EXTRA "Cleaning up ncurses"
285 cd "${CT_BUILD_DIR}/build-ncurses"
286 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
288 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
291 CT_EndStep # native gdb build
294 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
295 local -a gdbserver_extra_config
297 CT_DoStep INFO "Installing gdbserver"
298 CT_DoLog EXTRA "Configuring gdbserver"
300 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
301 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
303 # Workaround for bad versions, where the configure
304 # script for gdbserver is not executable...
305 # Bah, GNU folks strike again... :-(
306 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
309 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
310 gdbserver_LDFLAGS=-static
313 gdbserver_extra_config=("${extra_config[@]}")
315 LDFLAGS="${gdbserver_LDFLAGS}" \
317 "${gdb_src_dir}/gdb/gdbserver/configure" \
318 --build=${CT_BUILD} \
319 --host=${CT_TARGET} \
320 --target=${CT_TARGET} \
323 --localstatedir=/var \
324 --includedir="${CT_HEADERS_DIR}" \
325 --with-build-sysroot="${CT_SYSROOT_DIR}" \
331 --without-included-gettext \
334 "${gdbserver_extra_config[@]}"
336 CT_DoLog EXTRA "Building gdbserver"
337 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
339 CT_DoLog EXTRA "Installing gdbserver"
340 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install