common.mk 7.2 KB

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