common.mk 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #
  2. # Copyright (C) 2002-2003 Erik Andersen <[email protected]>
  3. # Copyright (C) 2004 Manuel Novoa III <[email protected]>
  4. # Copyright (C) 2005-2006 Felix Fietkau <[email protected]>
  5. # Copyright (C) 2006-2014 OpenWrt.org
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. include $(TOPDIR)/rules.mk
  21. PKG_NAME:=gcc
  22. GCC_VERSION:=$(call qstrip,$(CONFIG_GCC_VERSION))
  23. PKG_VERSION:=$(firstword $(subst +, ,$(GCC_VERSION)))
  24. GCC_MAJOR_VERSION:=$(word 1,$(subst ., ,$(PKG_VERSION)))
  25. GCC_DIR:=$(PKG_NAME)-$(PKG_VERSION)
  26. PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
  27. PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
  28. ifeq ($(PKG_VERSION),11.3.0)
  29. PKG_HASH:=b47cf2818691f5b1e21df2bb38c795fac2cfbd640ede2d0a5e1c89e338a3ac39
  30. endif
  31. ifeq ($(PKG_VERSION),12.3.0)
  32. PKG_HASH:=949a5d4f99e786421a93b532b22ffab5578de7321369975b91aec97adfda8c3b
  33. endif
  34. ifeq ($(PKG_VERSION),13.1.0)
  35. PKG_HASH:=61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86
  36. endif
  37. PATCH_DIR=../patches-$(GCC_MAJOR_VERSION).x
  38. BUGURL=http://bugs.openwrt.org/
  39. PKGVERSION=OpenWrt GCC $(PKG_VERSION) $(REVISION)
  40. HOST_BUILD_PARALLEL:=1
  41. include $(INCLUDE_DIR)/toolchain-build.mk
  42. HOST_SOURCE_DIR:=$(HOST_BUILD_DIR)
  43. ifeq ($(GCC_VARIANT),minimal)
  44. GCC_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
  45. else
  46. HOST_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
  47. GCC_BUILD_DIR:=$(HOST_BUILD_DIR)
  48. endif
  49. HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared
  50. HOST_STAMP_BUILT:=$(GCC_BUILD_DIR)/.built
  51. HOST_STAMP_CONFIGURED:=$(GCC_BUILD_DIR)/.configured
  52. HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.gcc_$(GCC_VARIANT)_installed
  53. SEP:=,
  54. TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GCCGO),$(SEP)go)"
  55. TAR_OPTIONS += \
  56. --exclude-from='$(CURDIR)/../exclude-testsuite' --exclude=gcc/ada/*.ad* \
  57. --exclude=libjava
  58. # this needs to be without -L/-lzstd flags or other parts fail to build
  59. # use an absolute path to ensure it really picks up our version
  60. export ac_cv_search_ZSTD_compress=$(STAGING_DIR_HOST)/lib/libzstd.a -pthread
  61. export libgcc_cv_fixed_point=no
  62. ifdef CONFIG_INSTALL_GCCGO
  63. export libgo_cv_c_split_stack_supported=no
  64. endif
  65. ifdef CONFIG_GCC_USE_GRAPHITE
  66. GRAPHITE_CONFIGURE:= --with-isl=$(STAGING_DIR_HOST)
  67. else
  68. GRAPHITE_CONFIGURE:= --without-isl --without-cloog
  69. endif
  70. GCC_CONFIGURE:= \
  71. SHELL="$(BASH)" \
  72. $(HOST_SOURCE_DIR)/configure \
  73. --with-bugurl=$(BUGURL) \
  74. --with-pkgversion="$(PKGVERSION)" \
  75. --prefix=$(TOOLCHAIN_DIR) \
  76. --build=$(GNU_HOST_NAME) \
  77. --host=$(GNU_HOST_NAME) \
  78. --target=$(REAL_GNU_TARGET_NAME) \
  79. --with-gnu-ld \
  80. --enable-target-optspace \
  81. --disable-libgomp \
  82. --disable-libmudflap \
  83. --disable-multilib \
  84. --disable-libmpx \
  85. --disable-nls \
  86. --disable-libssp \
  87. $(GRAPHITE_CONFIGURE) \
  88. --with-host-libstdcxx=-lstdc++ \
  89. $(SOFT_FLOAT_CONFIG_OPTION) \
  90. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  91. $(if $(CONFIG_mips64)$(CONFIG_mips64el),--with-arch=mips64 \
  92. --with-abi=$(call qstrip,$(CONFIG_MIPS64_ABI))) \
  93. $(if $(CONFIG_arc),--with-cpu=$(CONFIG_CPU_TYPE)) \
  94. $(if $(CONFIG_powerpc64), $(if $(CONFIG_USE_MUSL),--with-abi=elfv2)) \
  95. --with-system-zlib=$(STAGING_DIR_HOST) \
  96. --with-zstd=$(STAGING_DIR_HOST) \
  97. --with-gmp=$(STAGING_DIR_HOST) \
  98. --with-mpfr=$(STAGING_DIR_HOST) \
  99. --with-mpc=$(STAGING_DIR_HOST) \
  100. --disable-decimal-float \
  101. --with-diagnostics-color=auto-if-env \
  102. --enable-__cxa_atexit \
  103. --enable-libstdcxx-dual-abi \
  104. --with-default-libstdcxx-abi=new
  105. ifneq ($(CONFIG_mips)$(CONFIG_mipsel),)
  106. GCC_CONFIGURE += --with-mips-plt
  107. endif
  108. ifneq ($(CONFIG_GCC_DEFAULT_PIE),)
  109. GCC_CONFIGURE+= \
  110. --enable-default-pie
  111. endif
  112. ifneq ($(CONFIG_GCC_DEFAULT_SSP),)
  113. GCC_CONFIGURE+= \
  114. --enable-default-ssp
  115. endif
  116. ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
  117. GCC_CONFIGURE+= \
  118. --enable-biarch \
  119. --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
  120. endif
  121. ifdef CONFIG_sparc
  122. GCC_CONFIGURE+= \
  123. --enable-targets=all \
  124. --with-long-double-128
  125. endif
  126. ifneq ($(GCC_ARCH),)
  127. GCC_CONFIGURE+= --with-arch=$(GCC_ARCH)
  128. endif
  129. ifeq ($(CONFIG_arm),y)
  130. GCC_CONFIGURE+= \
  131. --with-cpu=$(word 1, $(subst +," ,$(CONFIG_CPU_TYPE)))
  132. ifneq ($(CONFIG_SOFT_FLOAT),y)
  133. GCC_CONFIGURE+= \
  134. --with-fpu=$(word 2, $(subst +, ",$(CONFIG_CPU_TYPE))) \
  135. --with-float=hard
  136. endif
  137. # Do not let TARGET_CFLAGS get poisoned by extra CPU optimization flags
  138. # that do not belong here. The cpu,fpu type should be specified via
  139. # --with-cpu and --with-fpu for ARM and not CFLAGS.
  140. TARGET_CFLAGS:=$(filter-out -m%,$(call qstrip,$(TARGET_CFLAGS)))
  141. endif
  142. ifeq ($(CONFIG_TARGET_x86)$(CONFIG_USE_GLIBC)$(CONFIG_INSTALL_GCCGO),yyy)
  143. TARGET_CFLAGS+=-fno-split-stack
  144. endif
  145. CFLAGS:=$(HOST_CFLAGS) -pipe
  146. ifneq ($(shell gcc --version 2>&1 | grep -E "Apple.(LLVM|clang)"),)
  147. CFLAGS+= -fbracket-depth=512
  148. endif
  149. GCC_CONFIGURE+= \
  150. CFLAGS="$(CFLAGS)" \
  151. CXXFLAGS="$(CFLAGS)" \
  152. CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
  153. CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
  154. GOCFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
  155. GCC_MAKE:= \
  156. export SHELL="$(BASH)"; \
  157. $(MAKE)
  158. define Host/SetToolchainInfo
  159. $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
  160. $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
  161. endef
  162. ifeq ($(GCC_MAJOR_VERSION),11)
  163. GCC_VERSION_FILE:=gcc/version.c
  164. else
  165. GCC_VERSION_FILE:=gcc/genversion.cc
  166. endif
  167. ifneq ($(GCC_PREPARE),)
  168. define Host/Prepare
  169. $(call Host/SetToolchainInfo)
  170. $(call Host/Prepare/Default)
  171. ln -snf $(GCC_DIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
  172. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_SOURCE_DIR)/
  173. $(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_SOURCE_DIR)/gcc/config/*/t-*
  174. $(SED) 'd' $(HOST_SOURCE_DIR)/gcc/DEV-PHASE
  175. $(SED) 's, DATESTAMP,,' $(HOST_SOURCE_DIR)/$(GCC_VERSION_FILE)
  176. $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_SOURCE_DIR)/libstdc++-v3/configure
  177. mkdir -p $(GCC_BUILD_DIR)
  178. endef
  179. else
  180. define Host/Prepare
  181. mkdir -p $(GCC_BUILD_DIR)
  182. endef
  183. endif
  184. define Host/Configure
  185. (cd $(GCC_BUILD_DIR) && rm -f config.cache; \
  186. $(GCC_CONFIGURE) \
  187. );
  188. endef
  189. define Host/Clean
  190. rm -rf $(if $(GCC_PREPARE),$(HOST_SOURCE_DIR)) \
  191. $(HOST_BUILD_PREFIX)/stamp/.gcc_* \
  192. $(HOST_BUILD_PREFIX)/stamp/.binutils_* \
  193. $(GCC_BUILD_DIR) \
  194. $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
  195. $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
  196. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
  197. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
  198. endef