common.mk 6.9 KB

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