2
1

gcc.mk 12 KB

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