common.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_DIR:=$(PKG_NAME)-$(PKG_VERSION)
  25. PKG_SOURCE_URL:=@GNU/gcc/gcc-$(PKG_VERSION)
  26. PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
  27. ifeq ($(PKG_VERSION),8.4.0)
  28. PKG_HASH:=e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4
  29. endif
  30. ifeq ($(PKG_VERSION),10.3.0)
  31. PKG_HASH:=64f404c1a650f27fc33da242e1f2df54952e3963a49e06e73f6940f3223ac344
  32. endif
  33. ifeq ($(PKG_VERSION),11.2.0)
  34. PKG_HASH:=d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b
  35. endif
  36. PATCH_DIR=../patches/$(GCC_VERSION)
  37. BUGURL=http://bugs.openwrt.org/
  38. PKGVERSION=OpenWrt GCC $(PKG_VERSION) $(REVISION)
  39. HOST_BUILD_PARALLEL:=1
  40. include $(INCLUDE_DIR)/toolchain-build.mk
  41. HOST_SOURCE_DIR:=$(HOST_BUILD_DIR)
  42. ifeq ($(GCC_VARIANT),minimal)
  43. GCC_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
  44. else
  45. HOST_BUILD_DIR:=$(HOST_BUILD_DIR)-$(GCC_VARIANT)
  46. GCC_BUILD_DIR:=$(HOST_BUILD_DIR)
  47. endif
  48. HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared
  49. HOST_STAMP_BUILT:=$(GCC_BUILD_DIR)/.built
  50. HOST_STAMP_CONFIGURED:=$(GCC_BUILD_DIR)/.configured
  51. HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.gcc_$(GCC_VARIANT)_installed
  52. SEP:=,
  53. TARGET_LANGUAGES:="c,c++$(if $(CONFIG_INSTALL_GFORTRAN),$(SEP)fortran)$(if $(CONFIG_INSTALL_GCCGO),$(SEP)go)"
  54. TAR_OPTIONS += \
  55. --exclude-from='$(CURDIR)/../exclude-testsuite' --exclude=gcc/ada/*.ad* \
  56. --exclude=libjava
  57. export libgcc_cv_fixed_point=no
  58. ifdef CONFIG_INSTALL_GCCGO
  59. export libgo_cv_c_split_stack_supported=no
  60. endif
  61. ifdef CONFIG_GCC_USE_GRAPHITE
  62. GRAPHITE_CONFIGURE:= --with-isl=$(TOPDIR)/staging_dir/host
  63. else
  64. GRAPHITE_CONFIGURE:= --without-isl --without-cloog
  65. endif
  66. GCC_CONFIGURE:= \
  67. SHELL="$(BASH)" \
  68. $(if $(shell gcc --version 2>&1 | grep -E "Apple.(LLVM|clang)"), \
  69. CFLAGS="-O2 -fbracket-depth=512 -pipe" \
  70. CXXFLAGS="-O2 -fbracket-depth=512 -pipe" \
  71. ) \
  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-gmp=$(TOPDIR)/staging_dir/host \
  96. --with-mpfr=$(TOPDIR)/staging_dir/host \
  97. --with-mpc=$(TOPDIR)/staging_dir/host \
  98. --disable-decimal-float \
  99. --with-diagnostics-color=auto-if-env \
  100. --enable-__cxa_atexit \
  101. --disable-libstdcxx-dual-abi \
  102. --with-default-libstdcxx-abi=new
  103. ifneq ($(CONFIG_mips)$(CONFIG_mipsel),)
  104. GCC_CONFIGURE += --with-mips-plt
  105. endif
  106. ifneq ($(CONFIG_GCC_DEFAULT_PIE),)
  107. GCC_CONFIGURE+= \
  108. --enable-default-pie
  109. endif
  110. ifneq ($(CONFIG_GCC_DEFAULT_SSP),)
  111. GCC_CONFIGURE+= \
  112. --enable-default-ssp
  113. endif
  114. ifneq ($(CONFIG_EXTRA_TARGET_ARCH),)
  115. GCC_CONFIGURE+= \
  116. --enable-biarch \
  117. --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-$(TARGET_SUFFIX)
  118. endif
  119. ifdef CONFIG_sparc
  120. GCC_CONFIGURE+= \
  121. --enable-targets=all \
  122. --with-long-double-128
  123. endif
  124. ifneq ($(GCC_ARCH),)
  125. GCC_CONFIGURE+= --with-arch=$(GCC_ARCH)
  126. endif
  127. ifeq ($(CONFIG_arm),y)
  128. GCC_CONFIGURE+= \
  129. --with-cpu=$(word 1, $(subst +," ,$(CONFIG_CPU_TYPE)))
  130. ifneq ($(CONFIG_SOFT_FLOAT),y)
  131. GCC_CONFIGURE+= \
  132. --with-fpu=$(word 2, $(subst +, ",$(CONFIG_CPU_TYPE))) \
  133. --with-float=hard
  134. endif
  135. # Do not let TARGET_CFLAGS get poisoned by extra CPU optimization flags
  136. # that do not belong here. The cpu,fpu type should be specified via
  137. # --with-cpu and --with-fpu for ARM and not CFLAGS.
  138. TARGET_CFLAGS:=$(filter-out -m%,$(call qstrip,$(TARGET_CFLAGS)))
  139. endif
  140. ifeq ($(CONFIG_TARGET_x86)$(CONFIG_USE_GLIBC)$(CONFIG_INSTALL_GCCGO),yyy)
  141. TARGET_CFLAGS+=-fno-split-stack
  142. endif
  143. GCC_MAKE:= \
  144. export SHELL="$(BASH)"; \
  145. $(MAKE) \
  146. CFLAGS="$(HOST_CFLAGS)" \
  147. CFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
  148. CXXFLAGS_FOR_TARGET="$(TARGET_CFLAGS)" \
  149. GOCFLAGS_FOR_TARGET="$(TARGET_CFLAGS)"
  150. define Host/SetToolchainInfo
  151. $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
  152. $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(GCC_VERSION),' $(TOOLCHAIN_DIR)/info.mk
  153. endef
  154. ifneq ($(GCC_PREPARE),)
  155. define Host/Prepare
  156. $(call Host/SetToolchainInfo)
  157. $(call Host/Prepare/Default)
  158. ln -snf $(GCC_DIR) $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME)
  159. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_SOURCE_DIR)/
  160. $(SED) 's,^MULTILIB_OSDIRNAMES,# MULTILIB_OSDIRNAMES,' $(HOST_SOURCE_DIR)/gcc/config/*/t-*
  161. $(SED) 'd' $(HOST_SOURCE_DIR)/gcc/DEV-PHASE
  162. $(SED) 's, DATESTAMP,,' $(HOST_SOURCE_DIR)/gcc/version.c
  163. #(cd $(HOST_SOURCE_DIR)/libstdc++-v3; autoconf;);
  164. $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(HOST_SOURCE_DIR)/libstdc++-v3/configure
  165. mkdir -p $(GCC_BUILD_DIR)
  166. endef
  167. else
  168. define Host/Prepare
  169. mkdir -p $(GCC_BUILD_DIR)
  170. endef
  171. endif
  172. define Host/Configure
  173. (cd $(GCC_BUILD_DIR) && rm -f config.cache; \
  174. $(GCC_CONFIGURE) \
  175. );
  176. endef
  177. define Host/Clean
  178. rm -rf $(if $(GCC_PREPARE),$(HOST_SOURCE_DIR)) \
  179. $(HOST_BUILD_PREFIX)/stamp/.gcc_* \
  180. $(HOST_BUILD_PREFIX)/stamp/.binutils_* \
  181. $(GCC_BUILD_DIR) \
  182. $(BUILD_DIR_TOOLCHAIN)/$(PKG_NAME) \
  183. $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
  184. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
  185. $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
  186. endef