gcc.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. ################################################################################
  2. #
  3. # Common variables for the gcc-initial and gcc-final packages.
  4. #
  5. ################################################################################
  6. #
  7. # Version, site and source
  8. #
  9. GCC_VERSION = $(call qstrip,$(BR2_GCC_VERSION))
  10. ifeq ($(BR2_GCC_VERSION_ARC),y)
  11. GCC_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,gcc,$(GCC_VERSION))
  12. GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
  13. else ifeq ($(BR2_or1k),y)
  14. GCC_SITE = $(call github,openrisc,or1k-gcc,$(GCC_VERSION))
  15. GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
  16. else
  17. GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
  18. # From version 5.5.0, 6.4.0, 7.2.0 and 8.1.0 a bz2 release tarball is not
  19. # provided anymore. Use the xz tarball instead.
  20. ifeq ($(BR2_GCC_VERSION_4_9_X),y)
  21. GCC_SOURCE = gcc-$(GCC_VERSION).tar.bz2
  22. else
  23. GCC_SOURCE = gcc-$(GCC_VERSION).tar.xz
  24. endif
  25. endif
  26. #
  27. # Xtensa special hook
  28. #
  29. define HOST_GCC_XTENSA_OVERLAY_EXTRACT
  30. $(call arch-xtensa-overlay-extract,$(@D),gcc)
  31. endef
  32. #
  33. # Apply patches
  34. #
  35. ifeq ($(ARCH),powerpc)
  36. ifneq ($(BR2_SOFT_FLOAT),)
  37. define HOST_GCC_APPLY_POWERPC_PATCH
  38. $(APPLY_PATCHES) $(@D) package/gcc/$(GCC_VERSION) 1000-powerpc-link-with-math-lib.patch.conditional
  39. endef
  40. endif
  41. endif
  42. # gcc is a special package, not named gcc, but gcc-initial and
  43. # gcc-final, but patches are nonetheless stored in package/gcc in the
  44. # tree, and potentially in BR2_GLOBAL_PATCH_DIR directories as well.
  45. define HOST_GCC_APPLY_PATCHES
  46. for patchdir in \
  47. package/gcc/$(GCC_VERSION) \
  48. $(addsuffix /gcc/$(GCC_VERSION),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  49. $(addsuffix /gcc,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) ; do \
  50. if test -d $${patchdir}; then \
  51. $(APPLY_PATCHES) $(@D) $${patchdir} \*.patch || exit 1; \
  52. fi; \
  53. done
  54. $(HOST_GCC_APPLY_POWERPC_PATCH)
  55. endef
  56. HOST_GCC_EXCLUDES = \
  57. libjava/* libgo/* \
  58. gcc/testsuite/* libstdc++-v3/testsuite/*
  59. define HOST_GCC_FAKE_TESTSUITE
  60. mkdir -p $(@D)/libstdc++-v3/testsuite/
  61. echo "all:" > $(@D)/libstdc++-v3/testsuite/Makefile.in
  62. echo "install:" >> $(@D)/libstdc++-v3/testsuite/Makefile.in
  63. endef
  64. #
  65. # Create 'build' directory and configure symlink
  66. #
  67. define HOST_GCC_CONFIGURE_SYMLINK
  68. mkdir -p $(@D)/build
  69. ln -sf ../configure $(@D)/build/configure
  70. endef
  71. #
  72. # Common configuration options
  73. #
  74. HOST_GCC_COMMON_DEPENDENCIES = \
  75. host-binutils \
  76. host-gmp \
  77. host-mpc \
  78. host-mpfr \
  79. $(if $(BR2_BINFMT_FLAT),host-elf2flt)
  80. HOST_GCC_COMMON_CONF_OPTS = \
  81. --target=$(GNU_TARGET_NAME) \
  82. --with-sysroot=$(STAGING_DIR) \
  83. --disable-__cxa_atexit \
  84. --with-gnu-ld \
  85. --disable-libssp \
  86. --disable-multilib \
  87. --with-gmp=$(HOST_DIR) \
  88. --with-mpc=$(HOST_DIR) \
  89. --with-mpfr=$(HOST_DIR) \
  90. --with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
  91. --with-bugurl="http://bugs.buildroot.net/"
  92. # Don't build documentation. It takes up extra space / build time,
  93. # and sometimes needs specific makeinfo versions to work
  94. HOST_GCC_COMMON_CONF_ENV = \
  95. MAKEINFO=missing
  96. GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
  97. GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
  98. # Propagate options used for target software building to GCC target libs
  99. HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
  100. HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
  101. # libitm needs sparc V9+
  102. ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
  103. HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
  104. endif
  105. # libmpx uses secure_getenv and struct _libc_fpstate not present in musl
  106. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_MUSL)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6),yy)
  107. HOST_GCC_COMMON_CONF_OPTS += --disable-libmpx
  108. endif
  109. # quadmath support requires wchar
  110. ifeq ($(BR2_USE_WCHAR)$(BR2_TOOLCHAIN_HAS_LIBQUADMATH),yy)
  111. HOST_GCC_COMMON_CONF_OPTS += --enable-libquadmath
  112. else
  113. HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath
  114. endif
  115. # libsanitizer requires wordexp, not in default uClibc config. Also
  116. # doesn't build properly with musl.
  117. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
  118. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  119. endif
  120. # libsanitizer is broken for SPARC
  121. # https://bugs.busybox.net/show_bug.cgi?id=7951
  122. ifeq ($(BR2_sparc)$(BR2_sparc64),y)
  123. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  124. endif
  125. # TLS support is not needed on uClibc/no-thread and
  126. # uClibc/linux-threads, otherwise, for all other situations (glibc,
  127. # musl and uClibc/NPTL), we need it.
  128. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_PTHREADS)$(BR2_PTHREADS_NONE),yy)
  129. HOST_GCC_COMMON_CONF_OPTS += --disable-tls
  130. else
  131. HOST_GCC_COMMON_CONF_OPTS += --enable-tls
  132. endif
  133. ifeq ($(BR2_GCC_ENABLE_LTO),y)
  134. HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto
  135. endif
  136. ifeq ($(BR2_GCC_ENABLE_LIBMUDFLAP),y)
  137. HOST_GCC_COMMON_CONF_OPTS += --enable-libmudflap
  138. else
  139. HOST_GCC_COMMON_CONF_OPTS += --disable-libmudflap
  140. endif
  141. ifeq ($(BR2_PTHREADS_NONE),y)
  142. HOST_GCC_COMMON_CONF_OPTS += \
  143. --disable-threads \
  144. --disable-libitm \
  145. --disable-libatomic
  146. else
  147. HOST_GCC_COMMON_CONF_OPTS += --enable-threads
  148. endif
  149. # gcc 5 doesn't need cloog any more, see
  150. # https://gcc.gnu.org/gcc-5/changes.html and we don't support graphite
  151. # on GCC 4.9.x, so only isl is needed.
  152. ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
  153. HOST_GCC_COMMON_DEPENDENCIES += host-isl
  154. HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)
  155. else
  156. HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
  157. endif
  158. ifeq ($(BR2_arc)$(BR2_or1k),y)
  159. HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
  160. endif
  161. ifeq ($(BR2_SOFT_FLOAT),y)
  162. # only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
  163. # powerpc seems to be needing it as well
  164. ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
  165. HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
  166. endif
  167. endif
  168. ifeq ($(BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE),y)
  169. HOST_GCC_COMMON_CONF_OPTS += --disable-decimal-float
  170. endif
  171. # Determine arch/tune/abi/cpu options
  172. ifneq ($(GCC_TARGET_ARCH),)
  173. HOST_GCC_COMMON_CONF_OPTS += --with-arch="$(GCC_TARGET_ARCH)"
  174. endif
  175. ifneq ($(GCC_TARGET_ABI),)
  176. HOST_GCC_COMMON_CONF_OPTS += --with-abi="$(GCC_TARGET_ABI)"
  177. endif
  178. ifeq ($(BR2_TOOLCHAIN_HAS_MNAN_OPTION),y)
  179. ifneq ($(GCC_TARGET_NAN),)
  180. HOST_GCC_COMMON_CONF_OPTS += --with-nan="$(GCC_TARGET_NAN)"
  181. endif
  182. endif
  183. ifneq ($(GCC_TARGET_FP32_MODE),)
  184. HOST_GCC_COMMON_CONF_OPTS += --with-fp-32="$(GCC_TARGET_FP32_MODE)"
  185. endif
  186. ifneq ($(GCC_TARGET_CPU),)
  187. HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(GCC_TARGET_CPU)
  188. endif
  189. ifneq ($(GCC_TARGET_FPU),)
  190. HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
  191. endif
  192. ifneq ($(GCC_TARGET_FLOAT_ABI),)
  193. HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
  194. endif
  195. ifneq ($(GCC_TARGET_MODE),)
  196. HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
  197. endif
  198. # Enable proper double/long double for SPE ABI
  199. ifeq ($(BR2_powerpc_SPE),y)
  200. HOST_GCC_COMMON_CONF_OPTS += \
  201. --enable-e500_double \
  202. --with-long-double-128
  203. endif
  204. # PowerPC64 big endian by default uses the elfv1 ABI, and PowerPC 64
  205. # little endian by default uses the elfv2 ABI. However, musl has
  206. # decided to use the elfv2 ABI for both, so we force the elfv2 ABI for
  207. # Power64 big endian when the selected C library is musl.
  208. ifeq ($(BR2_TOOLCHAIN_USES_MUSL)$(BR2_powerpc64),yy)
  209. HOST_GCC_COMMON_CONF_OPTS += \
  210. --with-abi=elfv2 \
  211. --without-long-double-128
  212. endif
  213. # Since glibc >= 2.26, poerpc64le requires double/long double which
  214. # requires at least gcc 6.2.
  215. # See sysdeps/powerpc/powerpc64le/configure.ac
  216. ifeq ($(BR2_TOOLCHAIN_USES_GLIBC)$(BR2_TOOLCHAIN_GCC_AT_LEAST_6)$(BR2_powerpc64le),yyy)
  217. HOST_GCC_COMMON_CONF_OPTS += \
  218. --with-long-double-128
  219. endif
  220. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
  221. # For gcc-initial, we need to tell gcc that the C library will be
  222. # providing the ssp support, as it can't guess it since the C library
  223. # hasn't been built yet.
  224. #
  225. # For gcc-final, the gcc logic to detect whether SSP support is
  226. # available or not in the C library is not working properly for
  227. # uClibc, so let's be explicit as well.
  228. HOST_GCC_COMMON_MAKE_OPTS = \
  229. gcc_cv_libc_provides_ssp=$(if $(BR2_TOOLCHAIN_HAS_SSP),yes,no)
  230. ifeq ($(BR2_CCACHE),y)
  231. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(GCC_DL_DIR)/$(GCC_SOURCE)
  232. # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned
  233. # and unversioned patches unconditionally. Moreover, to facilitate the
  234. # addition of gcc patches in BR2_GLOBAL_PATCH_DIR, we allow them to be
  235. # stored in a sub-directory called 'gcc' even if it's not technically
  236. # the name of the package.
  237. HOST_GCC_COMMON_CCACHE_HASH_FILES += \
  238. $(sort $(wildcard \
  239. package/gcc/$(GCC_VERSION)/*.patch \
  240. $(addsuffix /$($(PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  241. $(addsuffix /$($(PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  242. $(addsuffix /gcc/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  243. $(addsuffix /gcc/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR)))))
  244. ifeq ($(BR2_xtensa),y)
  245. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(ARCH_XTENSA_OVERLAY_TAR)
  246. endif
  247. ifeq ($(ARCH),powerpc)
  248. ifneq ($(BR2_SOFT_FLOAT),)
  249. HOST_GCC_COMMON_CCACHE_HASH_FILES += package/gcc/$(GCC_VERSION)/1000-powerpc-link-with-math-lib.patch.conditional
  250. endif
  251. endif
  252. # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR)
  253. # and a reference to the Buildroot git revision (BR2_VERSION_FULL),
  254. # so substitute those away.
  255. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
  256. printf '%s\n' $(subst $(HOST_DIR),@HOST_DIR@,\
  257. $(subst --with-pkgversion="Buildroot $(BR2_VERSION_FULL)",,$($(PKG)_CONF_OPTS))) \
  258. | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
  259. | cut -c -64 | tr -d '\n'`\"
  260. endif # BR2_CCACHE
  261. # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
  262. # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
  263. # *-gcc-nm and should be used instead of the real programs when -flto is
  264. # used. However, we should not add the toolchain wrapper for them, and they
  265. # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
  266. # *-ranlib and *-nm.
  267. # According to gfortran manpage, it supports all options supported by gcc, so
  268. # add gfortran to the list of the program called via the Buildroot wrapper.
  269. # Avoid that a .br_real is symlinked a second time.
  270. # Also create <arch>-linux-<tool> symlinks.
  271. define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
  272. $(Q)cd $(HOST_DIR)/bin; \
  273. for i in $(GNU_TARGET_NAME)-*; do \
  274. case "$$i" in \
  275. *.br_real) \
  276. ;; \
  277. *-ar|*-ranlib|*-nm) \
  278. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  279. ;; \
  280. *cc|*cc-*|*++|*++-*|*cpp|*-gfortran) \
  281. rm -f $$i.br_real; \
  282. mv $$i $$i.br_real; \
  283. ln -sf toolchain-wrapper $$i; \
  284. ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  285. ln -snf $$i.br_real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.br_real; \
  286. ;; \
  287. *) \
  288. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  289. ;; \
  290. esac; \
  291. done
  292. endef
  293. include $(sort $(wildcard package/gcc/*/*.mk))