gdb.mk 9.4 KB

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