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
30 if [ "${do_gdb}" = "y" ]; then
31 CT_GetFile "gdb-${CT_GDB_VERSION}" \
32 {ftp,http}://ftp.gnu.org/pub/gnu/gdb \
33 ftp://sources.redhat.com/pub/gdb/{,old-}releases
36 if [ "${do_ncurses}" = "y" ]; then
37 CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz \
38 {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
39 ftp://invisible-island.net/ncurses
43 do_debug_gdb_extract() {
46 if [ "${do_gdb}" = "y" ]; then
47 CT_Extract "gdb-${CT_GDB_VERSION}"
48 CT_Patch "gdb" "${CT_GDB_VERSION}"
51 if [ "${do_ncurses}" = "y" ]; then
52 CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
53 CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
57 do_debug_gdb_build() {
60 gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
62 # Version 6.3 and below behave badly with gdbmi
63 case "${CT_GDB_VERSION}" in
64 6.2*|6.3) extra_config+=("--disable-gdbmi");;
67 if [ "${CT_GDB_CROSS}" = "y" ]; then
68 local -a cross_extra_config
70 CT_DoStep INFO "Installing cross-gdb"
71 CT_DoLog EXTRA "Configuring cross-gdb"
73 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
74 cd "${CT_BUILD_DIR}/build-gdb-cross"
76 cross_extra_config=("${extra_config[@]}")
77 if [ "${CT_GDB_CROSS_USE_GMP_MPFR}" = "y" ]; then
78 cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}")
79 cross_extra_config+=("--with-mpfr=${CT_PREFIX_DIR}")
81 if [ "${CT_GDB_CROSS_USE_MPC}" = "y" ]; then
82 cross_extra_config+=("--with-mpc=${CT_PREFIX_DIR}")
84 case "${CT_THREADS}" in
85 none) cross_extra_config+=("--disable-threads");;
86 *) cross_extra_config+=("--enable-threads");;
91 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
92 CC_for_gdb="gcc -static"
93 LD_for_gdb="ld -static"
96 gdb_cross_configure="${gdb_src_dir}/configure"
98 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
103 "${gdb_cross_configure}" \
104 --build=${CT_BUILD} \
106 --target=${CT_TARGET} \
107 --prefix="${CT_PREFIX_DIR}" \
108 --with-build-sysroot="${CT_SYSROOT_DIR}" \
110 "${cross_extra_config[@]}"
112 CT_DoLog EXTRA "Building cross-gdb"
113 CT_DoExecLog ALL make ${PARALLELMFLAGS}
115 CT_DoLog EXTRA "Installing cross-gdb"
116 CT_DoExecLog ALL make install
121 if [ "${CT_GDB_NATIVE}" = "y" ]; then
122 local -a native_extra_config
125 CT_DoStep INFO "Installing native gdb"
127 CT_DoStep INFO "Installing ncurses library"
129 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
130 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
132 CT_DoStep INFO "Installing native ncurses tic"
133 CT_DoLog EXTRA "Configuring ncurses tic"
134 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
135 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
137 # Use build = CT_REAL_BUILD so that configure thinks it is
138 # cross-compiling, and thus will use the ${CT_BUILD}-*
139 # tools instead of searching for the native ones...
141 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
142 --build=${CT_BUILD} \
147 --with-build-cc=${CT_REAL_BUILD}-gcc \
148 --with-build-cpp=${CT_REAL_BUILD}-gcc \
149 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
152 # Under some operating systems (eg. Winblows), there is an
153 # extension appended to executables. Find that.
154 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
156 CT_DoLog EXTRA "Building ncurses tic"
157 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
158 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
160 CT_DoLog EXTRA "Installing ncurses tic"
161 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/bin"
162 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/bin"
164 CT_EndStep # tic build
166 CT_DoLog EXTRA "Configuring ncurses"
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_DoLog EXTRA "Building ncurses"
185 CT_DoExecLog ALL make ${PARALLELMFLAGS}
187 CT_DoLog EXTRA "Installing ncurses"
188 CT_DoExecLog ALL make install
190 # We no longer need the temporary tic. Remove it
191 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/bin/tic"
193 CT_EndStep # ncurses build
195 CT_DoLog EXTRA "Configuring native gdb"
197 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
198 cd "${CT_BUILD_DIR}/build-gdb-native"
200 native_extra_config=("${extra_config[@]}")
201 case "${CT_THREADS}" in
202 none) native_extra_config+=("--disable-threads");;
203 *) native_extra_config+=("--enable-threads");;
205 if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
206 native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
207 native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
210 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
211 CC_for_gdb="${CT_TARGET}-gcc -static"
212 LD_for_gdb="${CT_TARGET}-ld -static"
214 CC_for_gdb="${CT_TARGET}-gcc"
215 LD_for_gdb="${CT_TARGET}-ld"
218 export ac_cv_func_strncmp_works=yes
220 gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
222 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
226 CFLAGS="${gdb_native_CFLAGS}" \
228 "${gdb_src_dir}/configure" \
229 --build=${CT_BUILD} \
230 --host=${CT_TARGET} \
231 --target=${CT_TARGET} \
233 --with-build-sysroot="${CT_SYSROOT_DIR}" \
240 --without-included-gettext \
242 "${native_extra_config[@]}"
244 CT_DoLog EXTRA "Building native gdb"
245 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
247 CT_DoLog EXTRA "Installing native gdb"
248 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
250 # Building a native gdb also builds a gdbserver
251 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
253 unset ac_cv_func_strncmp_works
255 CT_DoLog EXTRA "Cleaning up ncurses"
256 cd "${CT_BUILD_DIR}/build-ncurses"
257 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
259 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