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 case "${CT_THREADS}" in
83 none) cross_extra_config+=("--disable-threads");;
84 *) cross_extra_config+=("--enable-threads");;
89 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
90 CC_for_gdb="gcc -static"
91 LD_for_gdb="ld -static"
94 gdb_cross_configure="${gdb_src_dir}/configure"
96 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
101 "${gdb_cross_configure}" \
102 --build=${CT_BUILD} \
104 --target=${CT_TARGET} \
105 --prefix="${CT_PREFIX_DIR}" \
106 --with-build-sysroot="${CT_SYSROOT_DIR}" \
108 "${cross_extra_config[@]}"
110 CT_DoLog EXTRA "Building cross-gdb"
111 CT_DoExecLog ALL make ${PARALLELMFLAGS}
113 CT_DoLog EXTRA "Installing cross-gdb"
114 CT_DoExecLog ALL make install
119 if [ "${CT_GDB_NATIVE}" = "y" ]; then
120 local -a native_extra_config
123 CT_DoStep INFO "Installing native gdb"
125 # GDB on Mingw depends on PDcurses, not ncurses
126 if [ "${do_ncurses}" = "y" ]; then
127 CT_DoLog EXTRA "Building static target ncurses"
129 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
130 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
132 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
133 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
135 # Use build = CT_REAL_BUILD so that configure thinks it is
136 # cross-compiling, and thus will use the ${CT_BUILD}-*
137 # tools instead of searching for the native ones...
139 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
140 --build=${CT_BUILD} \
145 --with-build-cc=${CT_REAL_BUILD}-gcc \
146 --with-build-cpp=${CT_REAL_BUILD}-gcc \
147 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
150 # Under some operating systems (eg. Winblows), there is an
151 # extension appended to executables. Find that.
152 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
154 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
155 CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"
157 CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/buildtools"
158 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/buildtools"
160 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
161 cd "${CT_BUILD_DIR}/build-ncurses"
164 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
165 --build=${CT_BUILD} \
166 --host=${CT_TARGET} \
167 --with-build-cc=${CT_BUILD}-gcc \
168 --with-build-cpp=${CT_BUILD}-gcc \
169 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
170 --prefix="${CT_BUILD_DIR}/ncurses" \
177 CT_DoExecLog ALL make ${PARALLELMFLAGS}
179 CT_DoExecLog ALL make install
181 # We no longer need the temporary tic. Remove it
182 CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/buildtools/tic${tic_ext}"
185 CT_DoLog EXTRA "Configuring native gdb"
187 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
188 cd "${CT_BUILD_DIR}/build-gdb-native"
190 native_extra_config=("${extra_config[@]}")
191 case "${CT_THREADS}" in
192 none) native_extra_config+=("--disable-threads");;
193 *) native_extra_config+=("--enable-threads");;
196 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
197 CC_for_gdb="${CT_TARGET}-gcc -static"
198 LD_for_gdb="${CT_TARGET}-ld -static"
200 CC_for_gdb="${CT_TARGET}-gcc"
201 LD_for_gdb="${CT_TARGET}-ld"
204 export ac_cv_func_strncmp_works=yes
206 gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
208 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
212 CFLAGS="${gdb_native_CFLAGS}" \
214 "${gdb_src_dir}/configure" \
215 --build=${CT_BUILD} \
216 --host=${CT_TARGET} \
217 --target=${CT_TARGET} \
219 --with-build-sysroot="${CT_SYSROOT_DIR}" \
226 --without-included-gettext \
228 "${native_extra_config[@]}"
230 CT_DoLog EXTRA "Building native gdb"
231 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
233 CT_DoLog EXTRA "Installing native gdb"
234 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
236 # Building a native gdb also builds a gdbserver
237 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
239 unset ac_cv_func_strncmp_works
241 # GDB on Mingw depends on PDcurses, not ncurses
242 if [ "${CT_MINGW32}" != "y" ]; then
243 CT_DoLog EXTRA "Cleaning up ncurses"
244 cd "${CT_BUILD_DIR}/build-ncurses"
245 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
247 CT_DoExecLog DEBUG rm -rf "${CT_BUILD_DIR}/ncurses"
250 CT_EndStep # native gdb build
253 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
254 local -a gdbserver_extra_config
256 CT_DoStep INFO "Installing gdbserver"
257 CT_DoLog EXTRA "Configuring gdbserver"
259 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
260 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
262 # Workaround for bad versions, where the configure
263 # script for gdbserver is not executable...
264 # Bah, GNU folks strike again... :-(
265 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
268 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
269 gdbserver_LDFLAGS=-static
272 gdbserver_extra_config=("${extra_config[@]}")
274 LDFLAGS="${gdbserver_LDFLAGS}" \
276 "${gdb_src_dir}/gdb/gdbserver/configure" \
277 --build=${CT_BUILD} \
278 --host=${CT_TARGET} \
279 --target=${CT_TARGET} \
282 --localstatedir=/var \
283 --includedir="${CT_HEADERS_DIR}" \
284 --with-build-sysroot="${CT_SYSROOT_DIR}" \
290 --without-included-gettext \
293 "${gdbserver_extra_config[@]}"
295 CT_DoLog EXTRA "Building gdbserver"
296 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
298 CT_DoLog EXTRA "Installing gdbserver"
299 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install