gcc.mk 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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
  14. GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
  15. endif
  16. GCC_SOURCE ?= gcc-$(GCC_VERSION).tar.bz2
  17. #
  18. # Xtensa special hook
  19. #
  20. HOST_GCC_XTENSA_OVERLAY_TAR = $(BR2_XTENSA_OVERLAY_DIR)/xtensa_$(call qstrip,$(BR2_XTENSA_CORE_NAME)).tar
  21. define HOST_GCC_XTENSA_OVERLAY_EXTRACT
  22. tar xf $(HOST_GCC_XTENSA_OVERLAY_TAR) -C $(@D) --strip-components=1 gcc
  23. endef
  24. #
  25. # Apply patches
  26. #
  27. ifeq ($(ARCH),powerpc)
  28. ifneq ($(BR2_SOFT_FLOAT),)
  29. define HOST_GCC_APPLY_POWERPC_PATCH
  30. $(APPLY_PATCHES) $(@D) package/gcc/$(GCC_VERSION) 1000-powerpc-link-with-math-lib.patch.conditional
  31. endef
  32. endif
  33. endif
  34. define HOST_GCC_APPLY_PATCHES
  35. if test -d package/gcc/$(GCC_VERSION); then \
  36. $(APPLY_PATCHES) $(@D) package/gcc/$(GCC_VERSION) \*.patch ; \
  37. fi;
  38. $(HOST_GCC_APPLY_POWERPC_PATCH)
  39. endef
  40. #
  41. # Custom extract command to save disk space
  42. #
  43. define HOST_GCC_EXTRACT_CMDS
  44. $(call suitable-extractor,$(GCC_SOURCE)) $(DL_DIR)/$(GCC_SOURCE) | \
  45. $(TAR) --strip-components=1 -C $(@D) \
  46. --exclude='libjava/*' \
  47. --exclude='libgo/*' \
  48. --exclude='gcc/testsuite/*' \
  49. --exclude='libstdc++-v3/testsuite/*' \
  50. $(TAR_OPTIONS) -
  51. mkdir -p $(@D)/libstdc++-v3/testsuite/
  52. echo "all:" > $(@D)/libstdc++-v3/testsuite/Makefile.in
  53. echo "install:" >> $(@D)/libstdc++-v3/testsuite/Makefile.in
  54. endef
  55. #
  56. # Create 'build' directory and configure symlink
  57. #
  58. define HOST_GCC_CONFIGURE_SYMLINK
  59. mkdir -p $(@D)/build
  60. ln -sf ../configure $(@D)/build/configure
  61. endef
  62. #
  63. # Common configuration options
  64. #
  65. HOST_GCC_COMMON_DEPENDENCIES = \
  66. host-binutils \
  67. host-gmp \
  68. host-mpfr \
  69. $(if $(BR2_BINFMT_FLAT),host-elf2flt)
  70. HOST_GCC_COMMON_CONF_OPTS = \
  71. --target=$(GNU_TARGET_NAME) \
  72. --with-sysroot=$(STAGING_DIR) \
  73. --disable-__cxa_atexit \
  74. --with-gnu-ld \
  75. --disable-libssp \
  76. --disable-multilib \
  77. --with-gmp=$(HOST_DIR)/usr \
  78. --with-mpfr=$(HOST_DIR)/usr \
  79. --with-pkgversion="Buildroot $(BR2_VERSION_FULL)" \
  80. --with-bugurl="http://bugs.buildroot.net/"
  81. # Don't build documentation. It takes up extra space / build time,
  82. # and sometimes needs specific makeinfo versions to work
  83. HOST_GCC_COMMON_CONF_ENV = \
  84. MAKEINFO=missing
  85. GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
  86. GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
  87. # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43810
  88. # Workaround until it's fixed in 4.5.4 or later
  89. ifeq ($(ARCH),powerpc)
  90. ifeq ($(findstring x4.5.,x$(GCC_VERSION)),x4.5.)
  91. GCC_COMMON_TARGET_CFLAGS = $(filter-out -Os,$(GCC_COMMON_TARGET_CFLAGS))
  92. GCC_COMMON_TARGET_CXXFLAGS = $(filter-out -Os,$(GCC_COMMON_TARGET_CXXFLAGS))
  93. endif
  94. endif
  95. # Xtensa libgcc can't be built with -mtext-section-literals
  96. # because of the trick used to generate .init/.fini sections.
  97. ifeq ($(BR2_xtensa),y)
  98. GCC_COMMON_TARGET_CFLAGS = $(filter-out -mtext-section-literals,$(TARGET_CFLAGS))
  99. GCC_COMMON_TARGET_CXXFLAGS = $(filter-out -mtext-section-literals,$(TARGET_CXXFLAGS))
  100. endif
  101. # Propagate options used for target software building to GCC target libs
  102. HOST_GCC_COMMON_CONF_ENV += CFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CFLAGS)"
  103. HOST_GCC_COMMON_CONF_ENV += CXXFLAGS_FOR_TARGET="$(GCC_COMMON_TARGET_CXXFLAGS)"
  104. # libitm needs sparc V9+
  105. ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
  106. HOST_GCC_COMMON_CONF_OPTS += --disable-libitm
  107. endif
  108. # gcc 4.6.x quadmath requires wchar
  109. ifneq ($(BR2_TOOLCHAIN_BUILDROOT_WCHAR),y)
  110. HOST_GCC_COMMON_CONF_OPTS += --disable-libquadmath
  111. endif
  112. # libsanitizer requires wordexp, not in default uClibc config. Also
  113. # doesn't build properly with musl.
  114. ifeq ($(BR2_TOOLCHAIN_BUILDROOT_UCLIBC)$(BR2_TOOLCHAIN_BUILDROOT_MUSL),y)
  115. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  116. endif
  117. # libsanitizer is broken for SPARC
  118. # https://bugs.busybox.net/show_bug.cgi?id=7951
  119. ifeq ($(BR2_sparc),y)
  120. HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
  121. endif
  122. ifeq ($(BR2_GCC_ENABLE_TLS),y)
  123. HOST_GCC_COMMON_CONF_OPTS += --enable-tls
  124. else
  125. HOST_GCC_COMMON_CONF_OPTS += --disable-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_NEEDS_MPC),y)
  144. HOST_GCC_COMMON_DEPENDENCIES += host-mpc
  145. HOST_GCC_COMMON_CONF_OPTS += --with-mpc=$(HOST_DIR)/usr
  146. endif
  147. ifeq ($(BR2_GCC_ENABLE_GRAPHITE),y)
  148. HOST_GCC_COMMON_DEPENDENCIES += host-isl host-cloog
  149. HOST_GCC_COMMON_CONF_OPTS += --with-isl=$(HOST_DIR)/usr --with-cloog=$(HOST_DIR)/usr
  150. else
  151. HOST_GCC_COMMON_CONF_OPTS += --without-isl --without-cloog
  152. endif
  153. ifeq ($(BR2_arc),y)
  154. HOST_GCC_COMMON_DEPENDENCIES += host-flex host-bison
  155. endif
  156. ifeq ($(BR2_SOFT_FLOAT),y)
  157. # only mips*-*-*, arm*-*-* and sparc*-*-* accept --with-float
  158. # powerpc seems to be needing it as well
  159. ifeq ($(BR2_arm)$(BR2_armeb)$(BR2_mips)$(BR2_mipsel)$(BR2_mips64)$(BR2_mips64el)$(BR2_powerpc)$(BR2_sparc),y)
  160. HOST_GCC_COMMON_CONF_OPTS += --with-float=soft
  161. endif
  162. endif
  163. ifeq ($(BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE),y)
  164. HOST_GCC_COMMON_CONF_OPTS += --disable-decimal-float
  165. endif
  166. # Determine arch/tune/abi/cpu options
  167. ifneq ($(call qstrip,$(BR2_GCC_TARGET_ARCH)),)
  168. HOST_GCC_COMMON_CONF_OPTS += --with-arch=$(BR2_GCC_TARGET_ARCH)
  169. endif
  170. ifneq ($(call qstrip,$(BR2_GCC_TARGET_ABI)),)
  171. HOST_GCC_COMMON_CONF_OPTS += --with-abi=$(BR2_GCC_TARGET_ABI)
  172. endif
  173. ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU)),)
  174. ifneq ($(call qstrip,$(BR2_GCC_TARGET_CPU_REVISION)),)
  175. HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU)-$(BR2_GCC_TARGET_CPU_REVISION))
  176. else
  177. HOST_GCC_COMMON_CONF_OPTS += --with-cpu=$(call qstrip,$(BR2_GCC_TARGET_CPU))
  178. endif
  179. endif
  180. GCC_TARGET_FPU = $(call qstrip,$(BR2_GCC_TARGET_FPU))
  181. ifneq ($(GCC_TARGET_FPU),)
  182. HOST_GCC_COMMON_CONF_OPTS += --with-fpu=$(GCC_TARGET_FPU)
  183. endif
  184. GCC_TARGET_FLOAT_ABI = $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
  185. ifneq ($(GCC_TARGET_FLOAT_ABI),)
  186. HOST_GCC_COMMON_CONF_OPTS += --with-float=$(GCC_TARGET_FLOAT_ABI)
  187. endif
  188. GCC_TARGET_MODE = $(call qstrip,$(BR2_GCC_TARGET_MODE))
  189. ifneq ($(GCC_TARGET_MODE),)
  190. HOST_GCC_COMMON_CONF_OPTS += --with-mode=$(GCC_TARGET_MODE)
  191. endif
  192. # Enable proper double/long double for SPE ABI
  193. ifeq ($(BR2_powerpc_SPE),y)
  194. HOST_GCC_COMMON_CONF_OPTS += \
  195. --enable-e500_double \
  196. --with-long-double-128
  197. endif
  198. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".real"'
  199. ifeq ($(BR2_CCACHE),y)
  200. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(DL_DIR)/$(GCC_SOURCE)
  201. # Cfr. PATCH_BASE_DIRS in .stamp_patched, but we catch both versioned and
  202. # unversioned patches unconditionally
  203. HOST_GCC_COMMON_CCACHE_HASH_FILES += \
  204. $(wildcard \
  205. package/gcc/$(GCC_VERSION)/*.patch \
  206. $(addsuffix $((PKG)_RAWNAME)/$(GCC_VERSION)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \
  207. $(addsuffix $((PKG)_RAWNAME)/*.patch,$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))))
  208. ifeq ($(BR2_xtensa),y)
  209. HOST_GCC_COMMON_CCACHE_HASH_FILES += $(HOST_GCC_XTENSA_OVERLAY_TAR)
  210. endif
  211. ifeq ($(ARCH),powerpc)
  212. ifneq ($(BR2_SOFT_FLOAT),)
  213. HOST_GCC_COMMON_CCACHE_HASH_FILES += package/gcc/$(GCC_VERSION)/1000-powerpc-link-with-math-lib.patch.conditional
  214. endif
  215. endif
  216. # _CONF_OPTS contains some references to the absolute path of $(HOST_DIR),
  217. # so substitute those away.
  218. HOST_GCC_COMMON_TOOLCHAIN_WRAPPER_ARGS += -DBR_CCACHE_HASH=\"`\
  219. printf '%s' $(subst $(HOST_DIR),@HOST_DIR@,$($(PKG)_CONF_OPTS)) \
  220. | sha256sum - $(HOST_GCC_COMMON_CCACHE_HASH_FILES) \
  221. | cut -c -64 | tr -d '\n'`\"
  222. endif # BR2_CCACHE
  223. # The LTO support in gcc creates wrappers for ar, ranlib and nm which load
  224. # the lto plugin. These wrappers are called *-gcc-ar, *-gcc-ranlib, and
  225. # *-gcc-nm and should be used instead of the real programs when -flto is
  226. # used. However, we should not add the toolchain wrapper for them, and they
  227. # match the *cc-* pattern. Therefore, an additional case is added for *-ar,
  228. # *-ranlib and *-nm.
  229. # Avoid that a .real is symlinked a second time.
  230. # Also create <arch>-linux-<tool> symlinks.
  231. define HOST_GCC_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
  232. $(Q)cd $(HOST_DIR)/usr/bin; \
  233. for i in $(GNU_TARGET_NAME)-*; do \
  234. case "$$i" in \
  235. *.real) \
  236. ;; \
  237. *-ar|*-ranlib|*-nm) \
  238. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  239. ;; \
  240. *cc|*cc-*|*++|*++-*|*cpp) \
  241. rm -f $$i.real; \
  242. mv $$i $$i.real; \
  243. ln -sf toolchain-wrapper $$i; \
  244. ln -sf toolchain-wrapper $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  245. ln -snf $$i.real $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}.real; \
  246. ;; \
  247. *) \
  248. ln -snf $$i $(ARCH)-linux$${i##$(GNU_TARGET_NAME)}; \
  249. ;; \
  250. esac; \
  251. done
  252. endef
  253. include $(sort $(wildcard package/gcc/*/*.mk))