xref: /OK3568_Linux_fs/buildroot/package/gdb/gdb.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1################################################################################
2#
3# gdb
4#
5################################################################################
6
7GDB_VERSION = $(call qstrip,$(BR2_GDB_VERSION))
8GDB_SITE = $(BR2_GNU_MIRROR)/gdb
9GDB_SOURCE = gdb-$(GDB_VERSION).tar.xz
10
11ifeq ($(BR2_arc),y)
12GDB_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,binutils-gdb,$(GDB_VERSION))
13GDB_SOURCE = gdb-$(GDB_VERSION).tar.gz
14GDB_FROM_GIT = y
15endif
16
17GDB_LICENSE = GPL-2.0+, LGPL-2.0+, GPL-3.0+, LGPL-3.0+
18GDB_LICENSE_FILES = COPYING COPYING.LIB COPYING3 COPYING3.LIB
19GDB_CPE_ID_VENDOR = gnu
20
21# Out of tree build is mandatory, so we create a 'build' subdirectory
22# in the gdb sources, and build from there.
23GDB_SUBDIR = build
24define GDB_CONFIGURE_SYMLINK
25	mkdir -p $(@D)/$(GDB_SUBDIR)
26	ln -sf ../configure $(@D)/$(GDB_SUBDIR)/configure
27endef
28GDB_PRE_CONFIGURE_HOOKS += GDB_CONFIGURE_SYMLINK
29
30# For the host variant, we really want to build with XML support,
31# which is needed to read XML descriptions of target architectures. We
32# also need ncurses.
33# As for libiberty, gdb may use a system-installed one if present, so
34# we must ensure ours is installed first.
35GDB_DEPENDENCIES = zlib
36HOST_GDB_DEPENDENCIES = host-expat host-libiberty host-ncurses host-zlib
37
38# Disable building documentation
39GDB_MAKE_OPTS += MAKEINFO=true
40GDB_INSTALL_TARGET_OPTS += MAKEINFO=true DESTDIR=$(TARGET_DIR) install
41HOST_GDB_MAKE_OPTS += MAKEINFO=true
42HOST_GDB_INSTALL_OPTS += MAKEINFO=true install
43
44# Apply the Xtensa specific patches
45ifneq ($(ARCH_XTENSA_OVERLAY_FILE),)
46define GDB_XTENSA_OVERLAY_EXTRACT
47	$(call arch-xtensa-overlay-extract,$(@D),gdb)
48endef
49GDB_POST_EXTRACT_HOOKS += GDB_XTENSA_OVERLAY_EXTRACT
50GDB_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
51HOST_GDB_POST_EXTRACT_HOOKS += GDB_XTENSA_OVERLAY_EXTRACT
52HOST_GDB_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
53endif
54
55ifeq ($(GDB_FROM_GIT),y)
56GDB_DEPENDENCIES += host-flex host-bison
57HOST_GDB_DEPENDENCIES += host-flex host-bison
58endif
59
60# All newer versions of GDB need host-gmp, so it's only for older
61# versions that the dependency can be avoided.
62ifeq ($(BR2_GDB_VERSION_10)$(BR2_arc),)
63HOST_GDB_DEPENDENCIES += host-gmp
64endif
65
66# When gdb sources are fetched from the binutils-gdb repository, they
67# also contain the binutils sources, but binutils shouldn't be built,
68# so we disable it (additionally the option --disable-install-libbfd
69# prevents the un-wanted installation of libobcodes.so and libbfd.so).
70GDB_DISABLE_BINUTILS_CONF_OPTS = \
71	--disable-binutils \
72	--disable-install-libbfd \
73	--disable-ld \
74	--disable-gas \
75	--disable-gprof
76
77GDB_CONF_ENV = \
78	ac_cv_type_uintptr_t=yes \
79	gt_cv_func_gettext_libintl=yes \
80	ac_cv_func_dcgettext=yes \
81	gdb_cv_func_sigsetjmp=yes \
82	bash_cv_func_strcoll_broken=no \
83	bash_cv_must_reinstall_sighandlers=no \
84	bash_cv_func_sigsetjmp=present \
85	bash_cv_have_mbstate_t=yes \
86	gdb_cv_func_sigsetjmp=yes
87
88# Starting with gdb 7.11, the bundled gnulib tries to use
89# rpl_gettimeofday (gettimeofday replacement) due to the code being
90# unable to determine if the replacement function should be used or
91# not when cross-compiling with uClibc or musl as C libraries. So use
92# gl_cv_func_gettimeofday_clobber=no to not use rpl_gettimeofday,
93# assuming musl and uClibc have a properly working gettimeofday
94# implementation. It needs to be passed to GDB_CONF_ENV to build
95# gdbserver only but also to GDB_MAKE_ENV, because otherwise it does
96# not get passed to the configure script of nested packages while
97# building gdbserver with full debugger.
98GDB_CONF_ENV += gl_cv_func_gettimeofday_clobber=no
99GDB_MAKE_ENV += gl_cv_func_gettimeofday_clobber=no
100
101# Similarly, starting with gdb 8.1, the bundled gnulib tries to use
102# rpl_strerror. Let's tell gnulib the C library implementation works
103# well enough.
104GDB_CONF_ENV += \
105	gl_cv_func_working_strerror=yes \
106	gl_cv_func_strerror_0_works=yes
107GDB_MAKE_ENV += \
108	gl_cv_func_working_strerror=yes \
109	gl_cv_func_strerror_0_works=yes
110
111# Starting with glibc 2.25, the proc_service.h header has been copied
112# from gdb to glibc so other tools can use it. However, that makes it
113# necessary to make sure that declaration of prfpregset_t declaration
114# is consistent between gdb and glibc. In gdb, however, there is a
115# workaround for a broken prfpregset_t declaration in glibc 2.3 which
116# uses AC_TRY_RUN to detect if it's needed, which doesn't work in
117# cross-compilation. So pass the cache option to configure.
118# It needs to be passed to GDB_CONF_ENV to build gdbserver only but
119# also to GDB_MAKE_ENV, because otherwise it does not get passed to the
120# configure script of nested packages while building gdbserver with full
121# debugger.
122GDB_CONF_ENV += gdb_cv_prfpregset_t_broken=no
123GDB_MAKE_ENV += gdb_cv_prfpregset_t_broken=no
124
125# The shared only build is not supported by gdb, so enable static build for
126# build-in libraries with --enable-static.
127GDB_CONF_OPTS = \
128	--without-uiout \
129	--disable-gdbtk \
130	--without-x \
131	--disable-sim \
132	$(GDB_DISABLE_BINUTILS_CONF_OPTS) \
133	--without-included-gettext \
134	--with-system-zlib \
135	--disable-werror \
136	--enable-static \
137	--without-mpfr
138
139ifeq ($(BR2_PACKAGE_GDB_DEBUGGER),y)
140GDB_CONF_OPTS += \
141	--enable-gdb \
142	--with-curses
143GDB_DEPENDENCIES += ncurses \
144	$(if $(BR2_PACKAGE_LIBICONV),libiconv)
145else
146GDB_CONF_OPTS += \
147	--disable-gdb \
148	--without-curses
149endif
150
151# Starting from GDB 11.x, gmp is needed as a dependency to build full
152# gdb. So we avoid the dependency only for GDB 10.x and the special
153# version used on ARC.
154ifeq ($(BR2_GDB_VERSION_10)$(BR2_arc):$(BR2_PACKAGE_GDB_DEBUGGER),:y)
155GDB_CONF_OPTS += \
156	--with-libgmp-prefix=$(STAGING_DIR)/usr
157GDB_DEPENDENCIES += gmp
158
159ifneq ($(BR2_STATIC_LIBS)$(BR2_PACKAGE_GDB_STATIC),)
160GDB_CONF_OPTS += --with-libgmp-type=static
161endif
162endif
163
164ifeq ($(BR2_PACKAGE_GDB_SERVER),y)
165GDB_CONF_OPTS += --enable-gdbserver
166GDB_DEPENDENCIES += $(TARGET_NLS_DEPENDENCIES)
167else
168GDB_CONF_OPTS += --disable-gdbserver
169endif
170
171# When gdb is built as C++ application for ARC it segfaults at runtime
172# So we pass --disable-build-with-cxx config option to force gdb not to
173# be built as C++ app.
174ifeq ($(BR2_arc),y)
175GDB_CONF_OPTS += --disable-build-with-cxx
176endif
177
178# gdb 7.12+ by default builds with a C++ compiler, which doesn't work
179# when we don't have C++ support in the toolchain
180ifneq ($(BR2_INSTALL_LIBSTDCPP),y)
181GDB_CONF_OPTS += --disable-build-with-cxx
182endif
183
184# inprocess-agent can't be built statically
185ifneq ($(BR2_STATIC_LIBS)$(BR2_PACKAGE_GDB_STATIC),)
186GDB_CONF_OPTS += --disable-inprocess-agent
187endif
188
189ifeq ($(BR2_PACKAGE_GDB_TUI),y)
190GDB_CONF_OPTS += --enable-tui
191else
192GDB_CONF_OPTS += --disable-tui
193endif
194
195ifeq ($(BR2_PACKAGE_GDB_PYTHON),y)
196# CONF_ENV: for top-level configure; MAKE_ENV: for sub-projects' configure.
197GDB_CONF_ENV += BR_PYTHON_VERSION=$(PYTHON3_VERSION_MAJOR)
198GDB_MAKE_ENV += BR_PYTHON_VERSION=$(PYTHON3_VERSION_MAJOR)
199GDB_DEPENDENCIES += python3
200GDB_CONF_OPTS += --with-python=$(TOPDIR)/package/gdb/gdb-python-config
201else
202GDB_CONF_OPTS += --without-python
203endif
204
205ifeq ($(BR2_PACKAGE_EXPAT),y)
206GDB_CONF_OPTS += --with-expat
207GDB_CONF_OPTS += --with-libexpat-prefix=$(STAGING_DIR)/usr
208GDB_DEPENDENCIES += expat
209else
210GDB_CONF_OPTS += --without-expat
211endif
212
213ifeq ($(BR2_PACKAGE_XZ),y)
214GDB_CONF_OPTS += --with-lzma
215GDB_CONF_OPTS += --with-liblzma-prefix=$(STAGING_DIR)/usr
216GDB_DEPENDENCIES += xz
217
218ifneq ($(BR2_STATIC_LIBS)$(BR2_PACKAGE_GDB_STATIC),)
219GDB_CONF_OPTS += --with-liblzma-type=static
220endif
221
222else
223GDB_CONF_OPTS += --without-lzma
224endif
225
226ifeq ($(BR2_PACKAGE_GDB_STATIC),y)
227GDB_CONF_ENV += CFLAGS="$(TARGET_CFLAGS) -static"
228GDB_CONF_ENV += CXXFLAGS="$(TARGET_CXXFLAGS) -static"
229GDB_CONF_ENV += FCFLAGS="$(TARGET_FCFLAGS) -static"
230GDB_CONF_ENV += LDFLAGS="$(TARGET_LDFLAGS) -static"
231GDB_CONF_OPTS += --disable-shared
232GDB_CONF_OPTS += --without-expat
233endif
234
235ifeq ($(BR2_PACKAGE_GDB_PYTHON),)
236# This removes some unneeded Python scripts and XML target description
237# files that are not useful for a normal usage of the debugger.
238define GDB_REMOVE_UNNEEDED_FILES
239	$(RM) -rf $(TARGET_DIR)/usr/share/gdb
240endef
241
242GDB_POST_INSTALL_TARGET_HOOKS += GDB_REMOVE_UNNEEDED_FILES
243endif
244
245# This installs the gdbserver somewhere into the $(HOST_DIR) so that
246# it becomes an integral part of the SDK, if the toolchain generated
247# by Buildroot is later used as an external toolchain. We install it
248# in debug-root/usr/bin/gdbserver so that it matches what Crosstool-NG
249# does.
250define GDB_SDK_INSTALL_GDBSERVER
251	$(INSTALL) -D -m 0755 $(TARGET_DIR)/usr/bin/gdbserver \
252		$(HOST_DIR)/$(GNU_TARGET_NAME)/debug-root/usr/bin/gdbserver
253endef
254
255ifeq ($(BR2_PACKAGE_GDB_SERVER),y)
256GDB_POST_INSTALL_TARGET_HOOKS += GDB_SDK_INSTALL_GDBSERVER
257endif
258
259# A few notes:
260#  * --target, because we're doing a cross build rather than a real
261#    host build.
262#  * --enable-static because gdb really wants to use libbfd.a
263HOST_GDB_CONF_OPTS = \
264	--target=$(GNU_TARGET_NAME) \
265	--enable-static \
266	--without-uiout \
267	--disable-gdbtk \
268	--without-x \
269	--enable-threads \
270	--disable-werror \
271	--without-included-gettext \
272	--with-system-zlib \
273	--with-curses \
274	--without-mpfr \
275	$(GDB_DISABLE_BINUTILS_CONF_OPTS)
276
277ifeq ($(BR2_PACKAGE_HOST_GDB_TUI),y)
278HOST_GDB_CONF_OPTS += --enable-tui
279else
280HOST_GDB_CONF_OPTS += --disable-tui
281endif
282
283ifeq ($(BR2_PACKAGE_HOST_GDB_PYTHON3),y)
284HOST_GDB_CONF_OPTS += --with-python=$(HOST_DIR)/bin/python3
285HOST_GDB_DEPENDENCIES += host-python3
286else
287HOST_GDB_CONF_OPTS += --without-python
288endif
289
290ifeq ($(BR2_PACKAGE_HOST_GDB_SIM),y)
291HOST_GDB_CONF_OPTS += --enable-sim
292else
293HOST_GDB_CONF_OPTS += --disable-sim
294endif
295
296# Since gdb 9, in-tree builds for GDB are not allowed anymore,
297# so we create a 'build' subdirectory in the gdb sources, and
298# build from there.
299HOST_GDB_SUBDIR = build
300
301define HOST_GDB_CONFIGURE_SYMLINK
302	mkdir -p $(@D)/build
303	ln -sf ../configure $(@D)/build/configure
304endef
305HOST_GDB_PRE_CONFIGURE_HOOKS += HOST_GDB_CONFIGURE_SYMLINK
306
307# legacy $arch-linux-gdb symlink
308define HOST_GDB_ADD_SYMLINK
309	cd $(HOST_DIR)/bin && \
310		ln -snf $(GNU_TARGET_NAME)-gdb $(ARCH)-linux-gdb
311endef
312
313HOST_GDB_POST_INSTALL_HOOKS += HOST_GDB_ADD_SYMLINK
314
315HOST_GDB_POST_INSTALL_HOOKS += gen_gdbinit_file
316
317$(eval $(autotools-package))
318$(eval $(host-autotools-package))
319