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"
14 if [ "${CT_GDB_CROSS}" = y ]; then
15 if [ "${CT_GDB_CROSS_INSIGHT}" = "y" ]; then
22 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
26 if [ "${CT_GDB_NATIVE}" = "y" ]; then
35 if [ "${do_gdb}" = "y" ]; then
36 CT_GetFile "gdb-${CT_GDB_VERSION}" \
37 {ftp,http}://ftp.gnu.org/pub/gnu/gdb \
38 ftp://sources.redhat.com/pub/gdb/{,old-}releases
41 if [ "${do_insight}" = "y" ]; then
42 CT_GetFile "insight-${CT_GDB_VERSION}" \
43 ftp://sourceware.org/pub/insight/releases \
44 {ftp,http}://ftp.twaren.net/Unix/Sourceware/insight/releases \
45 {ftp,http}://ftp.gwdg.de/pub/linux/sources.redhat.com/insight/releases
48 if [ "${do_ncurses}" = "y" ]; then
49 CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz \
50 {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
51 ftp://invisible-island.net/ncurses
55 do_debug_gdb_extract() {
58 if [ "${do_gdb}" = "y" ]; then
59 CT_Extract "gdb-${CT_GDB_VERSION}"
60 CT_Patch "gdb-${CT_GDB_VERSION}"
63 if [ "${do_insight}" = "y" ]; then
64 CT_Extract "insight-${CT_GDB_VERSION}"
65 CT_Patch "insight-${CT_GDB_VERSION}"
68 if [ "${do_ncurses}" = "y" ]; then
69 CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
70 CT_Patch "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
74 do_debug_gdb_build() {
77 gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
78 insight_src_dir="${CT_SRC_DIR}/insight-${CT_GDB_VERSION}"
80 # Version 6.3 and below behave badly with gdbmi
81 case "${CT_GDB_VERSION}" in
82 6.2*|6.3) extra_config+=("--disable-gdbmi");;
85 if [ "${CT_GDB_CROSS}" = "y" ]; then
86 local -a cross_extra_config
88 CT_DoStep INFO "Installing cross-gdb"
89 CT_DoLog EXTRA "Configuring cross-gdb"
91 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
92 cd "${CT_BUILD_DIR}/build-gdb-cross"
94 cross_extra_config=("${extra_config[@]}")
95 if [ "${CT_GDB_CROSS_USE_GMP_MPFR}" = "y" ]; then
96 cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}")
97 cross_extra_config+=("--with-mpfr=${CT_PREFIX_DIR}")
99 if [ "${CT_GDB_CROSS_USE_MPC}" = "y" ]; then
100 cross_extra_config+=("--with-mpc=${CT_PREFIX_DIR}")
102 case "${CT_THREADS}" in
103 none) cross_extra_config+=("--disable-threads");;
104 *) cross_extra_config+=("--enable-threads");;
109 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
110 CC_for_gdb="gcc -static"
111 LD_for_gdb="ld -static"
114 gdb_cross_configure="${gdb_src_dir}/configure"
115 [ "${CT_GDB_CROSS_INSIGHT}" = "y" ] && gdb_cross_configure="${insight_src_dir}/configure"
117 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
122 "${gdb_cross_configure}" \
123 --build=${CT_BUILD} \
125 --target=${CT_TARGET} \
126 --prefix="${CT_PREFIX_DIR}" \
127 --with-build-sysroot="${CT_SYSROOT_DIR}" \
129 "${cross_extra_config[@]}"
131 CT_DoLog EXTRA "Building cross-gdb"
132 CT_DoExecLog ALL make ${PARALLELMFLAGS}
134 CT_DoLog EXTRA "Installing cross-gdb"
135 CT_DoExecLog ALL make install
140 if [ "${CT_GDB_NATIVE}" = "y" ]; then
141 local -a native_extra_config
144 CT_DoStep INFO "Installing native gdb"
146 CT_DoStep INFO "Installing ncurses library"
148 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
149 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
151 CT_DoStep INFO "Installing native ncurses tic"
152 CT_DoLog EXTRA "Configuring ncurses tic"
153 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
154 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
156 # Use build = CT_REAL_BUILD so that configure thinks it is
157 # cross-compiling, and thus will use the ${CT_BUILD}-*
158 # tools instead of searching for the native ones...
160 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
161 --build=${CT_BUILD} \
166 --with-build-cc=${CT_REAL_BUILD}-gcc \
167 --with-build-cpp=${CT_REAL_BUILD}-gcc \
168 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
171 # Under some operating systems (eg. Winblows), there is an
172 # extension appended to executables. Find that.
173 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
175 CT_DoLog EXTRA "Building ncurses tic"
176 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
177 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
179 CT_DoLog EXTRA "Installing ncurses tic"
180 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/bin"
181 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/bin"
183 CT_EndStep # tic build
185 CT_DoLog EXTRA "Configuring ncurses"
186 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
187 cd "${CT_BUILD_DIR}/build-ncurses"
190 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
191 --build=${CT_BUILD} \
192 --host=${CT_TARGET} \
193 --with-build-cc=${CT_BUILD}-gcc \
194 --with-build-cpp=${CT_BUILD}-gcc \
195 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
196 --prefix="${CT_BUILD_DIR}/ncurses" \
203 CT_DoLog EXTRA "Building ncurses"
204 CT_DoExecLog ALL make ${PARALLELMFLAGS}
206 CT_DoLog EXTRA "Installing ncurses"
207 CT_DoExecLog ALL make install
209 # We no longer need the temporary tic. Remove it
210 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/bin/tic"
212 CT_EndStep # ncurses build
214 CT_DoLog EXTRA "Configuring native gdb"
216 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
217 cd "${CT_BUILD_DIR}/build-gdb-native"
219 native_extra_config=("${extra_config[@]}")
220 case "${CT_THREADS}" in
221 none) native_extra_config+=("--disable-threads");;
222 *) native_extra_config+=("--enable-threads");;
224 if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
225 native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
226 native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
229 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
230 CC_for_gdb="${CT_TARGET}-gcc -static"
231 LD_for_gdb="${CT_TARGET}-ld -static"
233 CC_for_gdb="${CT_TARGET}-gcc"
234 LD_for_gdb="${CT_TARGET}-ld"
237 export ac_cv_func_strncmp_works=yes
239 gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
241 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
245 CFLAGS="${gdb_native_CFLAGS}" \
247 "${gdb_src_dir}/configure" \
248 --build=${CT_BUILD} \
249 --host=${CT_TARGET} \
250 --target=${CT_TARGET} \
252 --with-build-sysroot="${CT_SYSROOT_DIR}" \
259 --without-included-gettext \
261 "${native_extra_config[@]}"
263 CT_DoLog EXTRA "Building native gdb"
264 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
266 CT_DoLog EXTRA "Installing native gdb"
267 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
269 # Building a native gdb also builds a gdbserver
270 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
272 unset ac_cv_func_strncmp_works
274 CT_DoLog EXTRA "Cleaning up ncurses"
275 cd "${CT_BUILD_DIR}/build-ncurses"
276 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
278 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
280 CT_EndStep # native gdb build
283 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
284 local -a gdbserver_extra_config
286 CT_DoStep INFO "Installing gdbserver"
287 CT_DoLog EXTRA "Configuring gdbserver"
289 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
290 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
292 # Workaround for bad versions, where the configure
293 # script for gdbserver is not executable...
294 # Bah, GNU folks strike again... :-(
295 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
298 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
299 gdbserver_LDFLAGS=-static
302 gdbserver_extra_config=("${extra_config[@]}")
304 LDFLAGS="${gdbserver_LDFLAGS}" \
306 "${gdb_src_dir}/gdb/gdbserver/configure" \
307 --build=${CT_BUILD} \
308 --host=${CT_TARGET} \
309 --target=${CT_TARGET} \
312 --localstatedir=/var \
313 --includedir="${CT_HEADERS_DIR}" \
314 --with-build-sysroot="${CT_SYSROOT_DIR}" \
320 --without-included-gettext \
323 "${gdbserver_extra_config[@]}"
325 CT_DoLog EXTRA "Building gdbserver"
326 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
328 CT_DoLog EXTRA "Installing gdbserver"
329 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install