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.9"
9 # Ditto for the expat library
10 CT_DEBUG_GDB_EXPAT_VERSION="2.1.0"
12 do_debug_gdb_parts() {
17 if [ "${CT_GDB_CROSS}" = y ]; then
21 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
25 if [ "${CT_GDB_NATIVE}" = "y" ]; then
27 # GDB on Mingw depends on PDcurses, not ncurses
28 if [ "${CT_MINGW32}" != "y" ]; then
38 local linaro_base_url="http://launchpad.net/gdb-linaro"
40 # Account for the Linaro versioning
41 linaro_version="$( echo "${CT_GDB_VERSION}" \
42 |sed -r -e 's/^linaro-//;' \
44 linaro_series="$( echo "${linaro_version}" \
45 |sed -r -e 's/-.*//;' \
50 if [ "${need_gdb_src}" = "y" ]; then
51 if [ "${CT_GDB_CUSTOM}" = "y" ]; then
52 CT_GetCustom "gdb" "${CT_GDB_VERSION}" "${CT_GDB_CUSTOM_LOCATION}"
54 CT_GetFile "gdb-${CT_GDB_VERSION}" \
55 {ftp,http}://ftp.gnu.org/pub/gnu/gdb \
56 ftp://sources.redhat.com/pub/gdb/{,old-}releases \
57 "${linaro_base_url}/${linaro_series}/${linaro_version}/+download"
61 if [ "${need_ncurses_src}" = "y" ]; then
62 CT_GetFile "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}" .tar.gz \
63 {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
64 ftp://invisible-island.net/ncurses
67 if [ "${need_expat_src}" = "y" ]; then
68 CT_GetFile "expat-${CT_DEBUG_GDB_EXPAT_VERSION}" .tar.gz \
69 http://downloads.sourceforge.net/project/expat/expat/${CT_DEBUG_GDB_EXPAT_VERSION}
73 do_debug_gdb_extract() {
76 if [ "${need_gdb_src}" = "y" ]; then
77 # If using custom directory location, nothing to do
78 if [ "${CT_GDB_CUSTOM}" = "y" \
79 -a -d "${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}" ]; then
82 CT_Extract "gdb-${CT_GDB_VERSION}"
83 CT_Patch "gdb" "${CT_GDB_VERSION}"
86 if [ "${need_ncurses_src}" = "y" ]; then
87 CT_Extract "ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
88 CT_DoExecLog ALL chmod -R u+w "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}"
89 CT_Patch "ncurses" "${CT_DEBUG_GDB_NCURSES_VERSION}"
92 if [ "${need_expat_src}" = "y" ]; then
93 CT_Extract "expat-${CT_DEBUG_GDB_EXPAT_VERSION}"
94 CT_Patch "expat" "${CT_DEBUG_GDB_EXPAT_VERSION}"
98 do_debug_gdb_build() {
103 gdb_src_dir="${CT_SRC_DIR}/gdb-${CT_GDB_VERSION}"
105 # Version 6.3 and below behave badly with gdbmi
106 case "${CT_GDB_VERSION}" in
107 6.2*|6.3) extra_config+=("--disable-gdbmi");;
110 if [ "${CT_GDB_HAS_PKGVERSION_BUGURL}" = "y" ]; then
111 extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
112 [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
115 if [ "${CT_GDB_CROSS}" = "y" ]; then
116 local -a cross_extra_config
119 CT_DoStep INFO "Installing cross-gdb"
120 CT_DoLog EXTRA "Configuring cross-gdb"
122 mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
123 cd "${CT_BUILD_DIR}/build-gdb-cross"
125 cross_extra_config=("${extra_config[@]}")
126 case "${CT_THREADS}" in
127 none) cross_extra_config+=("--disable-threads");;
128 *) cross_extra_config+=("--enable-threads");;
130 if [ "${CT_GDB_CROSS_PYTHON}" = "y" ]; then
131 cross_extra_config+=( "--with-python=yes" )
133 cross_extra_config+=( "--with-python=no" )
135 if [ "${CT_GDB_CROSS_SIM}" = "y" ]; then
136 cross_extra_config+=( "--enable-sim" )
138 cross_extra_config+=( "--disable-sim" )
143 if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
144 CC_for_gdb="gcc -static"
145 LD_for_gdb="ld -static"
148 cross_extra_config+=("--enable-expat")
149 cross_extra_config+=("--with-expat=yes")
151 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && \
152 cross_extra_config+=("--disable-nls")
154 gdb_cross_configure="${gdb_src_dir}/configure"
156 CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"
161 "${gdb_cross_configure}" \
162 --build=${CT_BUILD} \
164 --target=${CT_TARGET} \
165 --prefix="${CT_PREFIX_DIR}" \
166 --with-build-sysroot="${CT_SYSROOT_DIR}" \
167 --with-sysroot="${CT_SYSROOT_DIR}" \
169 "${cross_extra_config[@]}" \
170 "${CT_GDB_CROSS_EXTRA_CONFIG_ARRAY[@]}"
172 CT_DoLog EXTRA "Building cross-gdb"
173 CT_DoExecLog ALL make ${JOBSFLAGS}
175 CT_DoLog EXTRA "Installing cross-gdb"
176 CT_DoExecLog ALL make install
178 if [ "${CT_BUILD_MANUALS}" = "y" ]; then
179 CT_DoLog EXTRA "Building and installing the cross-GDB manuals"
180 CT_DoExecLog ALL make ${JOBSFLAGS} pdf html
181 CT_DoExecLog ALL make install-{pdf,html}-gdb
184 if [ "${CT_GDB_INSTALL_GDBINIT}" = "y" ]; then
185 CT_DoLog EXTRA "Install '.gdbinit' template"
186 # See in scripts/build/internals.sh for why we do this
187 if [ -f "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" ]; then
188 gcc_version=$( cat "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/BASE-VER" )
190 gcc_version=$( sed -r -e '/version_string/!d; s/^.+= "([^"]+)".*$/\1/;' \
191 "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/gcc/version.c" \
195 -e "s:@@PREFIX@@:${CT_PREFIX_DIR}:;" \
196 -e "s:@@VERSION@@:${gcc_version}:;" \
197 "${CT_LIB_DIR}/scripts/build/debug/gdbinit.in" \
198 >"${CT_PREFIX_DIR}/share/gdb/gdbinit"
199 fi # Install gdbinit sample
204 if [ "${CT_GDB_NATIVE}" = "y" ]; then
205 local -a native_extra_config
207 local -a gdb_native_CFLAGS
209 CT_DoStep INFO "Installing native gdb"
211 native_extra_config=("${extra_config[@]}")
213 # GDB on Mingw depends on PDcurses, not ncurses
214 if [ "${CT_MINGW32}" != "y" ]; then
215 CT_DoLog EXTRA "Building static target ncurses"
217 [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
218 [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")
220 mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
221 cd "${CT_BUILD_DIR}/build-ncurses-build-tic"
223 # Use build = CT_REAL_BUILD so that configure thinks it is
224 # cross-compiling, and thus will use the ${CT_BUILD}-*
225 # tools instead of searching for the native ones...
227 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
228 --build=${CT_BUILD} \
232 --with-build-cc=${CT_REAL_BUILD}-gcc \
233 --with-build-cpp=${CT_REAL_BUILD}-gcc \
234 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
237 # ncurses insists on linking tic statically. It does not work
238 # on some OSes (eg. MacOS-X/Darwin/whatever-you-call-it).
239 CT_DoExecLog DEBUG sed -r -i -e 's/-static//g;' "progs/Makefile"
241 # Under some operating systems (eg. Winblows), there is an
242 # extension appended to executables. Find that.
243 tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')
245 CT_DoExecLog ALL make ${JOBSFLAGS} -C include
246 CT_DoExecLog ALL make ${JOBSFLAGS} -C progs "tic${tic_ext}"
248 CT_DoExecLog ALL install -d -m 0755 "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
249 CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_BUILDTOOLS_PREFIX_DIR}/bin"
251 mkdir -p "${CT_BUILD_DIR}/build-ncurses"
252 cd "${CT_BUILD_DIR}/build-ncurses"
255 TIC_PATH="${CT_BUILDTOOLS_PREFIX_DIR}/bin/tic${tic_ext}" \
256 "${CT_SRC_DIR}/ncurses-${CT_DEBUG_GDB_NCURSES_VERSION}/configure" \
257 --build=${CT_BUILD} \
258 --host=${CT_TARGET} \
259 --with-build-cc=${CT_BUILD}-gcc \
260 --with-build-cpp=${CT_BUILD}-gcc \
261 --with-build-cflags="${CT_CFLAGS_FOR_HOST}" \
262 --prefix="${CT_BUILD_DIR}/static-target" \
269 CT_DoExecLog ALL make ${JOBSFLAGS}
271 CT_DoExecLog ALL make install
273 native_extra_config+=("--with-curses")
274 # There's no better way to tell gdb where to find -lcurses... :-(
275 gdb_native_CFLAGS+=("-I${CT_BUILD_DIR}/static-target/include")
276 gdb_native_CFLAGS+=("-L${CT_BUILD_DIR}/static-target/lib")
277 fi # need_ncurses_src
280 CT_DoLog EXTRA "Building static target expat"
281 CT_mkdir_pushd "${CT_BUILD_DIR}/build-expat-target-${CT_TARGET}"
282 do_gdb_expat_backend host="${CT_TARGET}" \
283 prefix="${CT_BUILD_DIR}/static-target" \
287 native_extra_config+=("--with-expat")
288 native_extra_config+=("--with-libexpat-prefix=${CT_BUILD_DIR}/static-target")
290 CT_DoLog EXTRA "Configuring native gdb"
292 mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
293 cd "${CT_BUILD_DIR}/build-gdb-native"
295 case "${CT_THREADS}" in
296 none) native_extra_config+=("--disable-threads");;
297 *) native_extra_config+=("--enable-threads");;
300 [ "${CT_TOOLCHAIN_ENABLE_NLS}" != "y" ] && \
301 native_extra_config+=("--disable-nls")
303 if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
304 CC_for_gdb="${CT_TARGET}-gcc -static"
305 LD_for_gdb="${CT_TARGET}-ld -static"
307 CC_for_gdb="${CT_TARGET}-gcc"
308 LD_for_gdb="${CT_TARGET}-ld"
311 export ac_cv_func_strncmp_works=yes
313 CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"
318 CFLAGS="${gdb_native_CFLAGS[*]}" \
319 "${gdb_src_dir}/configure" \
320 --build=${CT_BUILD} \
321 --host=${CT_TARGET} \
322 --target=${CT_TARGET} \
324 --with-build-sysroot="${CT_SYSROOT_DIR}" \
331 --without-included-gettext \
333 "${native_extra_config[@]}"
335 CT_DoLog EXTRA "Building native gdb"
336 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
338 CT_DoLog EXTRA "Installing native gdb"
339 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
341 # Building a native gdb also builds a gdbserver
342 find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL
344 unset ac_cv_func_strncmp_works
346 CT_EndStep # native gdb build
349 if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
350 local -a gdbserver_extra_config
352 CT_DoStep INFO "Installing gdbserver"
353 CT_DoLog EXTRA "Configuring gdbserver"
355 mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
356 cd "${CT_BUILD_DIR}/build-gdb-gdbserver"
358 # Workaround for bad versions, where the configure
359 # script for gdbserver is not executable...
360 # Bah, GNU folks strike again... :-(
361 chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"
364 if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
365 gdbserver_LDFLAGS=-static
368 gdbserver_extra_config=("${extra_config[@]}")
370 if [ "${CT_GDB_GDBSERVER_HAS_IPA_LIB}" = "y" ]; then
371 if [ "${CT_GDB_GDBSERVER_BUILD_IPA_LIB}" = "y" ]; then
372 gdbserver_extra_config+=( --enable-inprocess-agent )
374 gdbserver_extra_config+=( --disable-inprocess-agent )
379 LDFLAGS="${gdbserver_LDFLAGS}" \
380 "${gdb_src_dir}/gdb/gdbserver/configure" \
381 --build=${CT_BUILD} \
382 --host=${CT_TARGET} \
383 --target=${CT_TARGET} \
386 --localstatedir=/var \
387 --includedir="${CT_HEADERS_DIR}" \
388 --with-build-sysroot="${CT_SYSROOT_DIR}" \
394 --without-included-gettext \
397 "${gdbserver_extra_config[@]}"
399 CT_DoLog EXTRA "Building gdbserver"
400 CT_DoExecLog ALL make ${JOBSFLAGS} CC=${CT_TARGET}-${CT_CC}
402 CT_DoLog EXTRA "Installing gdbserver"
403 CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install
410 # Parameter : description : type : default
411 # host : machine to run on : tuple : (none)
412 # prefix : prefix to install into : dir : (none)
413 # cflags : cflags to use : string : (empty)
414 # ldflags : ldflags to use : string : (empty)
415 do_gdb_expat_backend() {
427 "${CT_SRC_DIR}/expat-${CT_DEBUG_GDB_EXPAT_VERSION}/configure" \
428 --build=${CT_BUILD} \
430 --prefix="${prefix}" \
434 CT_DoExecLog ALL make ${JOBSFLAGS}
435 CT_DoExecLog ALL make install