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_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}/bin"
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}/bin/tic"
184 CT_DoLog EXTRA "Configuring native gdb"
186 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
187 cd "${CT_BUILD_DIR}/build-gdb-native"
189 native_extra_config=("${extra_config[@]}")
190 case "${CT_THREADS}" in
191 none) native_extra_config+=("--disable-threads");;
192 *) native_extra_config+=("--enable-threads");;
194 if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
195 native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr")
196 native_extra_config+=("--with-mpfr=${CT_SYSROOT_DIR}/usr")
199 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
200 CC_for_gdb="${CT_TARGET}-gcc -static"
201 LD_for_gdb="${CT_TARGET}-ld -static"
203 CC_for_gdb="${CT_TARGET}-gcc"
204 LD_for_gdb="${CT_TARGET}-ld"
207 export ac_cv_func_strncmp_works=yes
209 gdb_native_CFLAGS="-I${CT_BUILD_DIR}/ncurses/include -L${CT_BUILD_DIR}/ncurses/lib"
211 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
215 CFLAGS="${gdb_native_CFLAGS}" \
217 "${gdb_src_dir}/configure" \
218 --build=${CT_BUILD} \
219 --host=${CT_TARGET} \
220 --target=${CT_TARGET} \
222 --with-build-sysroot="${CT_SYSROOT_DIR}" \
229 --without-included-gettext \
231 "${native_extra_config[@]}"
233 CT_DoLog EXTRA "Building native gdb"
234 CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}
236 CT_DoLog EXTRA "Installing native gdb"
237 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
239 # Building a native gdb also builds a gdbserver
240 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
242 unset ac_cv_func_strncmp_works
244 CT_DoLog EXTRA "Cleaning up ncurses"
245 cd "${CT_BUILD_DIR}/build-ncurses"
246 CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" uninstall
248 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