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 do_debug_gdb_suffix() {
10 case "${CT_GDB_VERSION}" in
12 *) echo "-${CT_GDB_VERSION}";;
16 do_debug_gdb_parts() {
21 if [ "${CT_GDB_CROSS}" = y ]; then
22 if [ "${CT_GDB_CROSS_INSIGHT}" = "y" ]; then
29 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
33 if [ "${CT_GDB_NATIVE}" = "y" ]; then
42 if [ "${do_gdb}" = "y" ]; then
43 CT_GetFile "gdb$(do_debug_gdb_suffix)" \
44 {ftp,http}://ftp.gnu.org/pub/gnu/gdb \
45 ftp://sources.redhat.com/pub/gdb/{{,old-}releases,snapshots/current}
48 if [ "${do_insight}" = "y" ]; then
49 CT_GetFile "insight-${CT_GDB_VERSION}" \
50 ftp://sourceware.org/pub/insight/releases \
51 {ftp,http}://ftp.twaren.net/Unix/Sourceware/insight/releases \
52 {ftp,http}://ftp.gwdg.de/pub/linux/sources.redhat.com/insight/releases
55 if [ "${do_ncurses}" = "y" ]; then
56 CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz \
57 {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
58 ftp://invisible-island.net/ncurses
62 do_debug_gdb_extract() {
65 if [ "${do_gdb}" = "y" ]; then
66 CT_Extract "gdb$(do_debug_gdb_suffix)"
67 CT_Patch "gdb$(do_debug_gdb_suffix)"
70 if [ "${do_insight}" = "y" ]; then
71 CT_Extract "insight-${CT_GDB_VERSION}"
72 CT_Patch "insight-${CT_GDB_VERSION}"
75 if [ "${do_ncurses}" = "y" ]; then
76 CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
77 CT_Patch "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
81 do_debug_gdb_build() {
84 gdb_src_dir="${CT_SRC_DIR}/gdb$(do_debug_gdb_suffix)"
85 insight_src_dir="${CT_SRC_DIR}/insight-${CT_GDB_VERSION}"
87 # Version 6.3 and below behave badly with gdbmi
88 case "${CT_GDB_VERSION}" in
89 6.2*|6.3) extra_config+=("--disable-gdbmi");;
92 if [ "${CT_GDB_CROSS}" = "y" ]; then
93 local -a cross_extra_config
95 CT_DoStep INFO "Installing cross-gdb"
96 CT_DoLog EXTRA "Configuring cross-gdb"
98 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
99 cd "${CT_BUILD_DIR}/build-gdb-cross"
101 cross_extra_config=("${extra_config[@]}")
102 if [ "${CT_GDB_CROSS_USE_GMP_MPFR}" = "y" ]; then
103 cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}")
104 cross_extra_config+=("--with-mpfr=${CT_PREFIX_DIR}")
106 case "${CT_THREADS}" in
107 none) cross_extra_config+=("--disable-threads");;
108 *) cross_extra_config+=("--enable-threads");;
113 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
114 CC_for_gdb="gcc -static"
115 LD_for_gdb="ld -static"
118 gdb_cross_configure="${gdb_src_dir}/configure"
119 [ "${CT_GDB_CROSS_INSIGHT}" = "y" ] && gdb_cross_configure="${insight_src_dir}/configure"
121 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
126 "${gdb_cross_configure}" \
127 --build=${CT_BUILD} \
129 --target=${CT_TARGET} \
130 --prefix="${CT_PREFIX_DIR}" \
131 --with-build-sysroot="${CT_SYSROOT_DIR}" \
133 "${cross_extra_config[@]}"
135 CT_DoLog EXTRA "Building cross-gdb"
136 CT_DoExecLog ALL make ${PARALLELMFLAGS}
138 CT_DoLog EXTRA "Installing cross-gdb"
139 CT_DoExecLog ALL make install
144 if [ "${CT_GDB_NATIVE}" = "y" ]; then
145 local -a native_extra_config
148 CT_DoStep INFO "Installing native gdb"
150 CT_DoStep INFO "Installing ncurses library"
152 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
153 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
155 CT_DoStep INFO "Installing native ncurses tic"
156 CT_DoLog EXTRA "Configuring ncurses tic"
157 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
158 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
160 # Use build = CT_REAL_BUILD so that configure thinks it is
161 # cross-compiling, and thus will use the ${CT_BUILD}-*
162 # tools instead of searching for the native ones...
164 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
165 --build=${CT_BUILD} \
170 --with-build-cc=${CT_REAL_BUILD}-gcc \
171 --with-build-cpp=${CT_REAL_BUILD}-gcc \
172 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
175 # Under some operating systems (eg. Winblows), there is an
176 # extension appended to executables. Find that.
177 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
179 CT_DoLog EXTRA "Building ncurses tic"
180 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
181 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
183 CT_DoLog EXTRA "Installing ncurses tic"
184 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/bin"
185 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/bin"
187 CT_EndStep # tic build
189 CT_DoLog EXTRA "Configuring ncurses"
190 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
191 cd "${CT_BUILD_DIR}/build-ncurses"
194 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
195 --build=${CT_BUILD} \
196 --host=${CT_TARGET} \
197 --with-build-cc=${CT_BUILD}-gcc \
198 --with-build-cpp=${CT_BUILD}-gcc \
199 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
200 --prefix="${CT_BUILD_DIR}/ncurses" \
207 CT_DoLog EXTRA "Building ncurses"
208 CT_DoExecLog ALL make ${PARALLELMFLAGS}
210 CT_DoLog EXTRA "Installing ncurses"
211 CT_DoExecLog ALL make install
213 # We no longer need the temporary tic. Remove it
214 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/bin/tic"
216 CT_EndStep # ncurses build
218 CT_DoLog EXTRA "Configuring native gdb"
220 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
221 cd "${CT_BUILD_DIR}/build-gdb-native"
223 native_extra_config=("${extra_config[@]}")
224 case "${CT_THREADS}" in
225 none) native_extra_config+=("--disable-threads");;
226 *) native_extra_config+=("--enable-threads");;
228 if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
229 native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
230 native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
233 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
234 CC_for_gdb="${CT_TARGET}-gcc -static"
235 LD_for_gdb="${CT_TARGET}-ld -static"
237 CC_for_gdb="${CT_TARGET}-gcc"
238 LD_for_gdb="${CT_TARGET}-ld"
241 export ac_cv_func_strncmp_works=yes
243 gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
245 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
249 CFLAGS="${gdb_native_CFLAGS}" \
251 "${gdb_src_dir}/configure" \
252 --build=${CT_BUILD} \
253 --host=${CT_TARGET} \
254 --target=${CT_TARGET} \
256 --with-build-sysroot="${CT_SYSROOT_DIR}" \
263 --without-included-gettext \
265 "${native_extra_config[@]}"
267 CT_DoLog EXTRA "Building native gdb"
268 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
270 CT_DoLog EXTRA "Installing native gdb"
271 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
273 # Building a native gdb also builds a gdbserver
274 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
276 unset ac_cv_func_strncmp_works
278 CT_DoLog EXTRA "Cleaning up ncurses"
279 cd "${CT_BUILD_DIR}/build-ncurses"
280 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
282 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
284 CT_EndStep # native gdb build
287 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
288 local -a gdbserver_extra_config
290 CT_DoStep INFO "Installing gdbserver"
291 CT_DoLog EXTRA "Configuring gdbserver"
293 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
294 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
296 # Workaround for bad versions, where the configure
297 # script for gdbserver is not executable...
298 # Bah, GNU folks strike again... :-(
299 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
302 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
303 gdbserver_LDFLAGS=-static
306 gdbserver_extra_config=("${extra_config[@]}")
308 LDFLAGS="${gdbserver_LDFLAGS}" \
310 "${gdb_src_dir}/gdb/gdbserver/configure" \
311 --build=${CT_BUILD} \
312 --host=${CT_TARGET} \
313 --target=${CT_TARGET} \
316 --localstatedir=/var \
317 --includedir="${CT_HEADERS_DIR}" \
318 --with-build-sysroot="${CT_SYSROOT_DIR}" \
324 --without-included-gettext \
327 "${gdbserver_extra_config[@]}"
329 CT_DoLog EXTRA "Building gdbserver"
330 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
332 CT_DoLog EXTRA "Installing gdbserver"
333 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install