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"
13 if [ "${CT_GDB_CROSS}" = y ]; then
17 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
21 if [ "${CT_GDB_NATIVE}" = "y" ]; then
23 # GDB on Mingw depends on PDcurses, not ncurses
24 if [ "${CT_MINGW32}" != "y" ]; then
33 if [ "${do_gdb}" = "y" ]; then
34 CT_GetFile "gdb-${CT_GDB_VERSION}" \
35 {ftp,http}://ftp.gnu.org/pub/gnu/gdb \
36 ftp://sources.redhat.com/pub/gdb/{,old-}releases
39 if [ "${do_ncurses}" = "y" ]; then
40 CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz \
41 {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
42 ftp://invisible-island.net/ncurses
46 do_debug_gdb_extract() {
49 if [ "${do_gdb}" = "y" ]; then
50 CT_Extract "gdb-${CT_GDB_VERSION}"
51 CT_Patch "gdb" "${CT_GDB_VERSION}"
54 if [ "${do_ncurses}" = "y" ]; then
55 CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
56 CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
60 do_debug_gdb_build() {
65 gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
67 # Version 6.3 and below behave badly with gdbmi
68 case "${CT_GDB_VERSION}" in
69 6.2*|6.3) extra_config+=("--disable-gdbmi");;
72 if [ "${CT_GDB_CROSS}" = "y" ]; then
73 local -a cross_extra_config
75 CT_DoStep INFO "Installing cross-gdb"
76 CT_DoLog EXTRA "Configuring cross-gdb"
78 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
79 cd "${CT_BUILD_DIR}/build-gdb-cross"
81 cross_extra_config=("${extra_config[@]}")
82 if [ "${CT_GDB_CROSS_USE_GMP_MPFR}" = "y" ]; then
83 cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}")
84 cross_extra_config+=("--with-mpfr=${CT_PREFIX_DIR}")
86 if [ "${CT_GDB_CROSS_USE_MPC}" = "y" ]; then
87 cross_extra_config+=("--with-mpc=${CT_PREFIX_DIR}")
89 case "${CT_THREADS}" in
90 none) cross_extra_config+=("--disable-threads");;
91 *) cross_extra_config+=("--enable-threads");;
96 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
97 CC_for_gdb="gcc -static"
98 LD_for_gdb="ld -static"
101 gdb_cross_configure="${gdb_src_dir}/configure"
103 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
108 "${gdb_cross_configure}" \
109 --build=${CT_BUILD} \
111 --target=${CT_TARGET} \
112 --prefix="${CT_PREFIX_DIR}" \
113 --with-build-sysroot="${CT_SYSROOT_DIR}" \
115 "${cross_extra_config[@]}"
117 CT_DoLog EXTRA "Building cross-gdb"
118 CT_DoExecLog ALL make ${PARALLELMFLAGS}
120 CT_DoLog EXTRA "Installing cross-gdb"
121 CT_DoExecLog ALL make install
126 if [ "${CT_GDB_NATIVE}" = "y" ]; then
127 local -a native_extra_config
130 CT_DoStep INFO "Installing native gdb"
132 # GDB on Mingw depends on PDcurses, not ncurses
133 if [ "${do_ncurses}" = "y" ]; then
134 CT_DoLog EXTRA "Building static target ncurses"
136 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
137 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
139 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
140 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
142 # Use build = CT_REAL_BUILD so that configure thinks it is
143 # cross-compiling, and thus will use the ${CT_BUILD}-*
144 # tools instead of searching for the native ones...
146 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
147 --build=${CT_BUILD} \
152 --with-build-cc=${CT_REAL_BUILD}-gcc \
153 --with-build-cpp=${CT_REAL_BUILD}-gcc \
154 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
157 # Under some operating systems (eg. Winblows), there is an
158 # extension appended to executables. Find that.
159 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
161 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
162 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
164 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
165 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
167 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
168 cd "${CT_BUILD_DIR}/build-ncurses"
171 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
172 --build=${CT_BUILD} \
173 --host=${CT_TARGET} \
174 --with-build-cc=${CT_BUILD}-gcc \
175 --with-build-cpp=${CT_BUILD}-gcc \
176 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
177 --prefix="${CT_BUILD_DIR}/ncurses" \
184 CT_DoExecLog ALL make ${PARALLELMFLAGS}
186 CT_DoExecLog ALL make install
188 # We no longer need the temporary tic. Remove it
189 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
192 CT_DoLog EXTRA "Configuring native gdb"
194 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
195 cd "${CT_BUILD_DIR}/build-gdb-native"
197 native_extra_config=("${extra_config[@]}")
198 case "${CT_THREADS}" in
199 none) native_extra_config+=("--disable-threads");;
200 *) native_extra_config+=("--enable-threads");;
202 if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
203 native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
204 native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
207 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
208 CC_for_gdb="${CT_TARGET}-gcc -static"
209 LD_for_gdb="${CT_TARGET}-ld -static"
211 CC_for_gdb="${CT_TARGET}-gcc"
212 LD_for_gdb="${CT_TARGET}-ld"
215 export ac_cv_func_strncmp_works=yes
217 gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
219 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
223 CFLAGS="${gdb_native_CFLAGS}" \
225 "${gdb_src_dir}/configure" \
226 --build=${CT_BUILD} \
227 --host=${CT_TARGET} \
228 --target=${CT_TARGET} \
230 --with-build-sysroot="${CT_SYSROOT_DIR}" \
237 --without-included-gettext \
239 "${native_extra_config[@]}"
241 CT_DoLog EXTRA "Building native gdb"
242 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
244 CT_DoLog EXTRA "Installing native gdb"
245 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
247 # Building a native gdb also builds a gdbserver
248 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
250 unset ac_cv_func_strncmp_works
252 # GDB on Mingw depends on PDcurses, not ncurses
253 if [ "${CT_MINGW32}" != "y" ]; then
254 CT_DoLog EXTRA "Cleaning up ncurses"
255 cd "${CT_BUILD_DIR}/build-ncurses"
256 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
258 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
261 CT_EndStep # native gdb build
264 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
265 local -a gdbserver_extra_config
267 CT_DoStep INFO "Installing gdbserver"
268 CT_DoLog EXTRA "Configuring gdbserver"
270 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
271 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
273 # Workaround for bad versions, where the configure
274 # script for gdbserver is not executable...
275 # Bah, GNU folks strike again... :-(
276 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
279 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
280 gdbserver_LDFLAGS=-static
283 gdbserver_extra_config=("${extra_config[@]}")
285 LDFLAGS="${gdbserver_LDFLAGS}" \
287 "${gdb_src_dir}/gdb/gdbserver/configure" \
288 --build=${CT_BUILD} \
289 --host=${CT_TARGET} \
290 --target=${CT_TARGET} \
293 --localstatedir=/var \
294 --includedir="${CT_HEADERS_DIR}" \
295 --with-build-sysroot="${CT_SYSROOT_DIR}" \
301 --without-included-gettext \
304 "${gdbserver_extra_config[@]}"
306 CT_DoLog EXTRA "Building gdbserver"
307 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
309 CT_DoLog EXTRA "Installing gdbserver"
310 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install