common.mk 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. PKG_CPE_ID:=cpe:/a:gnu:gcc
  29. ifeq ($(PKG_VERSION),11.3.0)
  30. PKG_HASH:=b47cf2818691f5b1e21df2bb38c795fac2cfbd640ede2d0a5e1c89e338a3ac39
  31. endif
  32. ifeq ($(PKG_VERSION),12.3.0)
  33. PKG_HASH:=949a5d4f99e786421a93b532b22ffab5578de7321369975b91aec97adfda8c3b
  34. endif
  35. ifeq ($(PKG_VERSION),13.3.0)
  36. PKG_HASH:=0845e9621c9543a13f484e94584a49ffc0129970e9914624235fc1d061a0c083
  37. endif
  38. ifeq ($(PKG_VERSION),14.1.0)
  39. PKG_HASH:=e283c654987afe3de9d8080bc0bd79534b5ca0d681a73a11ff2b5d3767426840
  40. endif
  41. PATCH_DIR=../patches-$(GCC_MAJOR_VERSION).x
  42. BUGURL=http://bugs.openwrt.org/
  43. PKGVERSION=OpenWrt GCC $(PKG_VERSION) $(REVISION)
  44. HOST_BUILD_PARALLEL:=1
  45. include $(INCLUDE_DIR)/toolchain-build.mk
  46. HOST_SOURCE_DIR:=$(HOST_BUILD_DIR)
  47. ifeq ($(GCC_VARIANT),minimal)
  48. GCC_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
  49. else
  50. HOST_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
  51. GCC_BUILD_DIR:=$(HOST_BUILD_DIR)
  52. endif
  53. HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared
  54. HOST_STAMP_BUILT:=$(GCC_BUILD_DIR)/.built
  55. HOST_STAMP_CONFIGURED:=$(GCC_BUILD_DIR)/.configured
  56. HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.gcc_$(GCC_VARIANT)_installed
  57. SEP:=,
  58. TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GCCGO),$(SEP)go)"
  59. TAR_OPTIONS += \
  60. --exclude-from='$(CURDIR)/../exclude-testsuite' --exclude=gcc/ada/*.ad* \
  61. --exclude=libjava
  62. # this needs to be without -L/-lzstd flags or other parts fail to build
  63. # use an absolute path to ensure it really picks up our version
  64. export ac_cv_search_ZSTD_compress=$(STAGING_DIR_HOST)/lib/libzstd.a -pthread
  65. export libgcc_cv_fixed_point=no
  66. ifdef CONFIG_INSTALL_GCCGO
  67. export libgo_cv_c_split_stack_supported=no
  68. endif
  69. ifdef CONFIG_GCC_USE_GRAPHITE
  70. GRAPHITE_CONFIGURE:= --with-isl=$(STAGING_DIR_HOST)
  71. else
  72. GRAPHITE_CONFIGURE:= --without-isl --without-cloog
  73. endif
  74. GCC_CONFIGURE:= \
  75. SHELL="$(BASH)" \
  76. $(HOST_SOURCE_DIR)/configure \
  77. --with-bugurl=$(BUGURL) \
  78. --with-pkgversion="$(PKGVERSION)" \
  79. --prefix=$(TOOLCHAIN_DIR) \
  80. --build=$(GNU_HOST_NAME) \
  81. --host=$(GNU_HOST_NAME) \
  82. --target=$(REAL_GNU_TARGET_NAME) \
  83. --with-gnu-ld \
  84. --enable-target-optspace \
  85. --disable-libgomp \
  86. --disable-libmudflap \
  87. --disable-multilib \
  88. --disable-libmpx \
  89. --disable-nls \
  90. --disable-libssp \
  91. $(GRAPHITE_CONFIGURE) \
  92. --with-host-libstdcxx=-lstdc++ \
  93. $(SOFT_FLOAT_CONFIG_OPTION) \
  94. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  95. $(if $(CONFIG_mips64)$(CONFIG_mips64el),--with-arch=mips64 \
  96. --with-abi=$(call qstrip,$(CONFIG_MIPS64_ABI))) \
  97. $(if $(CONFIG_arc),--with-cpu=$(CONFIG_CPU_TYPE)) \
  98. $(if $(CONFIG_powerpc64), $(if $(CONFIG_USE_MUSL),--with-abi=elfv2)) \
  99. --with-system-zlib=$(STAGING_DIR_HOST) \
  100. --with-zstd=$(STAGING_DIR_HOST) \
  101. --with-gmp=$(STAGING_DIR_HOST) \
  102. --with-mpfr=$(STAGING_DIR_HOST) \
  103. --with-mpc=$(STAGING_DIR_HOST) \
  104. --disable-decimal-float \
  105. --with-diagnostics-color=auto-if-env \
  106. --enable-__cxa_atexit \
  107. --enable-libstdcxx-dual-abi \
  108. --with-default-libstdcxx-abi=new
  109. ifneq ($(CONFIG_mips)$(CONFIG_mipsel),)
  110. GCC_CONFIGURE += --with-mips-plt
  111. endif
  112. ifneq ($(CONFIG_GCC_DEFAULT_PIE),)
  113. GCC_CONFIGURE+= \
  114. --enable-default-pie
  115. endif
  116. ifneq ($(CONFIG_GCC_DEFAULT_SSP),)
  117. GCC_CONFIGURE+= \
  118. --enable-default-ssp
  119. endif
  120. ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
  121. GCC_CONFIGURE+= \
  122. --enable-biarch \
  123. --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
  124. endif
  125. ifdef CONFIG_sparc
  126. GCC_CONFIGURE+= \
  127. --enable-targets=all \
  128. --with-long-double-128
  129. endif
  130. ifneq ($(GCC_ARCH),)
  131. GCC_CONFIGURE+= --with-arch=$(GCC_ARCH)
  132. endif
  133. ifeq ($(CONFIG_arm),y)
  134. GCC_CONFIGURE+= \
  135. --with-cpu=$(word 1, $(subst +," ,$(CONFIG_CPU_TYPE)))
  136. ifneq ($(CONFIG_SOFT_FLOAT),y)
  137. GCC_CONFIGURE+= \
  138. --with-fpu=$(word 2, $(subst +, ",$(CONFIG_CPU_TYPE))) \
  139. --with-float=hard
  140. endif
  141. # Do not let TARGET_CFLAGS get poisoned by extra CPU optimization flags
  142. # that do not belong here. The cpu,fpu type should be specified via
  143. # --with-cpu and --with-fpu for ARM and not CFLAGS.
  144. TARGET_CFLAGS:=$(filter-out -m%,$(call qstrip,$(TARGET_CFLAGS)))
  145. endif
  146. ifeq ($(CONFIG_TARGET_x86)$(CONFIG_USE_GLIBC)$(CONFIG_INSTALL_GCCGO),yyy)
  147. TARGET_CFLAGS+=-fno-split-stack
  148. endif
  149. CFLAGS:=$(HOST_CFLAGS) -pipe
  150. ifneq ($(shell gcc --version 2>&1 | grep -E "Apple.(LLVM|clang)"),)
  151. CFLAGS+= -fbracket-depth=512
  152. endif
  153. GCC_CONFIGURE+= \
  154. CFLAGS="$(CFLAGS)" \
  155. CXXFLAGS="$(CFLAGS)" \
  156. CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
  157. CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
  158. GOCFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
  159. GCC_MAKE:= \
  160. export SHELL="$(BASH)"; \
  161. $(MAKE)
  162. define Host/SetToolchainInfo
  163. $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
  164. $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
  165. endef
  166. ifeq ($(GCC_MAJOR_VERSION),11)
  167. GCC_VERSION_FILE:=gcc/version.c
  168. else
  169. GCC_VERSION_FILE:=gcc/genversion.cc
  170. endif
  171. ifneq ($(GCC_PREPARE),)
  172. define Host/Prepare
  173. $(call Host/SetToolchainInfo)
  174. $(call Host/Prepare/Default)
  175. ln -snf $(GCC_DIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
  176. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_SOURCE_DIR)/
  177. $(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_SOURCE_DIR)/gcc/config/*/t-*
  178. $(SED) 'd' $(HOST_SOURCE_DIR)/gcc/DEV-PHASE
  179. $(SED) 's, DATESTAMP,,' $(HOST_SOURCE_DIR)/$(GCC_VERSION_FILE)
  180. $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_SOURCE_DIR)/libstdc++-v3/configure
  181. mkdir -p $(GCC_BUILD_DIR)
  182. endef
  183. else
  184. define Host/Prepare
  185. mkdir -p $(GCC_BUILD_DIR)
  186. endef
  187. endif
  188. define Host/Configure
  189. (cd $(GCC_BUILD_DIR) && rm -f config.cache; \
  190. $(GCC_CONFIGURE) \
  191. );
  192. endef
  193. define Host/Clean
  194. rm -rf $(if $(GCC_PREPARE),$(HOST_SOURCE_DIR)) \
  195. $(HOST_BUILD_PREFIX)/stamp/.gcc_* \
  196. $(HOST_BUILD_PREFIX)/stamp/.binutils_* \
  197. $(GCC_BUILD_DIR) \
  198. $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
  199. $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
  200. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
  201. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
  202. endef