gdb.mk 10 KB

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