You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
8.0 KiB

  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. PKG_RELEASE:=$(AUTORELEASE)
  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_INSTALL:=1
  29. PKG_FIXUP:=libtool
  30. PKG_BUILD_PARALLEL:=1
  31. PKG_CPE_ID:=cpe:/a:gnu:gcc
  32. ifeq ($(PKG_VERSION),8.4.0)
  33. PKG_HASH:=e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4
  34. endif
  35. ifeq ($(PKG_VERSION),10.3.0)
  36. PKG_HASH:=64f404c1a650f27fc33da242e1f2df54952e3963a49e06e73f6940f3223ac344
  37. endif
  38. ifeq ($(PKG_VERSION),11.2.0)
  39. PKG_HASH:=d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b
  40. endif
  41. PATCH_DIR=./patches/$(GCC_VERSION)
  42. include $(INCLUDE_DIR)/package.mk
  43. define Package/gcc
  44. SECTION:=devel
  45. CATEGORY:=Development
  46. TITLE:=gcc
  47. MAINTAINER:=W. Michael Petullo <mike@flyn.org>
  48. DEPENDS:= +binutils +libstdcpp +libzstd @!arc
  49. MENU:=1
  50. endef
  51. define Package/gcc/config
  52. source "$(SOURCE)/Config.in"
  53. endef
  54. ifeq ($(CONFIG_INCLUDE_STATIC_LIBC),y)
  55. COPY_STATIC_LIBC=cp -a $(TOOLCHAIN_DIR)/lib/libc.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  56. endif
  57. ifeq ($(CONFIG_INCLUDE_STATIC_LIBPTHREAD),y)
  58. COPY_STATIC_LIBPTHREAD=cp -a $(TOOLCHAIN_DIR)/lib/libpthread.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  59. endif
  60. ifeq ($(CONFIG_INCLUDE_STATIC_LIBSTDC),y)
  61. COPY_STATIC_LIBSTDC=cp -a $(TOOLCHAIN_DIR)/lib/libstdc++.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  62. endif
  63. ifeq ($(CONFIG_INCLUDE_STATIC_LINK_SPEC),y)
  64. INSTALL_STATIC_SPEC=g++ -dumpspecs |sed s/--start-group}\ %G\ %L\ /--start-group}\ %G\ %L\ -lstdc++\ -lgcc_pic\ / >/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/specs
  65. REMOVE_STATIC_SPEC=rm /usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/specs
  66. endif
  67. TARGET_LANGUAGES:="c,c++"
  68. BUGURL=https://dev.openwrt.org/
  69. PKGVERSION=OpenWrt GCC $(PKG_VERSION)
  70. TARGET_CPPFLAGS += -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS
  71. # not using sstrip here as this messes up the .so's somehow
  72. STRIP:=$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)strip
  73. RSTRIP:= \
  74. NM="$(TOOLCHAIN_DIR)/bin/$(TARGET_CROSS)nm" \
  75. STRIP="$(STRIP)" \
  76. STRIP_KMOD="$(STRIP) --strip-debug" \
  77. $(SCRIPT_DIR)/rstrip.sh
  78. ifneq ($(CONFIG_SOFT_FLOAT),y)
  79. ifeq ($(CONFIG_arm),y)
  80. ARM_FLOAT_OPTION:= --with-float=hard
  81. endif
  82. endif
  83. GMPSRC=gmp-6.1.0
  84. define Download/gmp
  85. URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
  86. FILE:=$(GMPSRC).tar.bz2
  87. HASH:=498449a994efeba527885c10405993427995d3f86b8768d8cdf8d9dd7c6b73e8
  88. endef
  89. $(eval $(call Download,gmp))
  90. MPCSRC=mpc-1.0.3
  91. define Download/mpc
  92. URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
  93. FILE:=$(MPCSRC).tar.gz
  94. HASH:=617decc6ea09889fb08ede330917a00b16809b8db88c29c31bfbb49cbf88ecc3
  95. endef
  96. $(eval $(call Download,mpc))
  97. MPFRSRC=mpfr-3.1.4
  98. define Download/mpfr
  99. URL:=ftp://gcc.gnu.org/pub/gcc/infrastructure/
  100. FILE:=$(MPFRSRC).tar.bz2
  101. HASH:=d3103a80cdad2407ed581f3618c4bed04e0c92d1cf771a65ead662cc397f7775
  102. endef
  103. $(eval $(call Download,mpfr))
  104. define Build/Prepare
  105. $(PKG_UNPACK)
  106. # we have to download and unpack additional stuff before patching
  107. tar -C $(PKG_BUILD_DIR) -xvjf $(DL_DIR)/$(GMPSRC).tar.bz2
  108. ln -sf $(PKG_BUILD_DIR)/$(GMPSRC) $(PKG_BUILD_DIR)/gmp
  109. tar -C $(PKG_BUILD_DIR) -xvzf $(DL_DIR)/$(MPCSRC).tar.gz
  110. ln -sf $(PKG_BUILD_DIR)/$(MPCSRC) $(PKG_BUILD_DIR)/mpc
  111. tar -C $(PKG_BUILD_DIR) -xvjf $(DL_DIR)/$(MPFRSRC).tar.bz2
  112. ln -sf $(PKG_BUILD_DIR)/$(MPFRSRC) $(PKG_BUILD_DIR)/mpfr
  113. $(Build/Patch)
  114. # poor man's fix for `none-openwrt-linux' not recognized when building with musl
  115. cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/mpfr/
  116. cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/gmp/
  117. chmod u+w $(PKG_BUILD_DIR)/mpc/config.sub
  118. cp $(PKG_BUILD_DIR)/config.sub $(PKG_BUILD_DIR)/mpc/
  119. endef
  120. CONFIGURE_ARGS += CXXFLAGS_FOR_TARGET="-g -O2 -D_GLIBCXX_INCLUDE_NEXT_C_HEADERS"
  121. define Build/Configure
  122. (cd $(PKG_BUILD_DIR); rm -f config.cache; \
  123. SHELL="$(BASH)" \
  124. $(TARGET_CONFIGURE_OPTS) \
  125. $(PKG_BUILD_DIR)/configure \
  126. $(CONFIGURE_ARGS) \
  127. --build=$(GNU_HOST_NAME) \
  128. --host=$(REAL_GNU_TARGET_NAME) \
  129. --target=$(REAL_GNU_TARGET_NAME) \
  130. --enable-languages=$(TARGET_LANGUAGES) \
  131. --with-bugurl=$(BUGURL) \
  132. --with-pkgversion="$(PKGVERSION)" \
  133. --enable-shared \
  134. $(if $(CONFIG_LIBC_USE_GLIBC),--enable,--disable)-__cxa_atexit \
  135. --with-default-libstdcxx-abi=gcc4-compatible \
  136. --enable-target-optspace \
  137. --with-gnu-ld \
  138. --disable-nls \
  139. --disable-libsanitizer \
  140. --disable-libvtv \
  141. --disable-libcilkrts \
  142. --disable-libmudflap \
  143. --disable-libmpx \
  144. --disable-multilib \
  145. --disable-libgomp \
  146. --disable-libquadmath \
  147. --disable-libssp \
  148. --disable-decimal-float \
  149. --disable-libstdcxx-pch \
  150. --with-host-libstdcxx=-lstdc++ \
  151. --prefix=/usr \
  152. --libexecdir=/usr/lib \
  153. --with-local-prefix=/usr \
  154. --with-stage1-ldflags=-lstdc++ \
  155. $(ARM_FLOAT_OPTION) \
  156. $(SOFT_FLOAT_CONFIG_OPTION) \
  157. $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
  158. );
  159. endef
  160. define Build/Compile
  161. export SHELL="$(BASH)"; $(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
  162. DESTDIR="$(PKG_INSTALL_DIR)" $(MAKE_ARGS) all
  163. export SHELL="$(BASH)"; $(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
  164. DESTDIR="$(PKG_INSTALL_DIR)" $(MAKE_ARGS) install
  165. endef
  166. ENVCFLAGS:="$(TARGET_OPTIMIZATION) $(EXTRA_OPTIMIZATION)
  167. ifeq ($(CONFIG_SOFT_FLOAT),y)
  168. ifeq ($(CONFIG_arm),y)
  169. ENVCFLAGS+= -mfloat-abi=soft
  170. else
  171. ENVCFLAGS+= -msoft-float
  172. endif
  173. endif
  174. ENVCFLAGS+="
  175. ENVLDFLAGS:="-Wl,-rpath=/usr/lib -Wl,--dynamic-linker=/usr/lib/$(DYNLINKER) -L/usr/lib, -lstdc++"
  176. define Package/gcc/install
  177. $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  178. cp -ar $(PKG_INSTALL_DIR)/usr/include $(1)/usr
  179. cp -a $(PKG_INSTALL_DIR)/usr/bin/{$(REAL_GNU_TARGET_NAME)-{g++,gcc},cpp,gcov} $(1)/usr/bin
  180. ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/c++
  181. ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/g++
  182. ln -s $(REAL_GNU_TARGET_NAME)-g++ $(1)/usr/bin/$(REAL_GNU_TARGET_NAME)-c++
  183. ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/gcc
  184. ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/cc
  185. ln -s $(REAL_GNU_TARGET_NAME)-gcc $(1)/usr/bin/$(REAL_GNU_TARGET_NAME)-gcc-$(PKG_VERSION)
  186. cp -ar $(PKG_INSTALL_DIR)/usr/lib/gcc $(1)/usr/lib
  187. cp -ar $(TOOLCHAIN_DIR)/include $(1)/usr
  188. cp -a $(TOOLCHAIN_DIR)/lib/*.{o,so*} $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  189. cp -a $(TOOLCHAIN_DIR)/lib/*nonshared*.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  190. cp -a $(TOOLCHAIN_DIR)/lib/libm.a $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)
  191. $(COPY_STATIC_LIBC)
  192. $(COPY_STATIC_LIBPTHREAD)
  193. $(COPY_STATIC_LIBSTDC)
  194. rm -f $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/libgo*
  195. rm -f $(1)/usr/lib/$(PKG_NAME)/$(REAL_GNU_TARGET_NAME)/$(PKG_VERSION)/libcc1*
  196. echo '#!/bin/sh' > $(1)/usr/bin/gcc_env.sh
  197. echo 'export LDFLAGS=$(ENVLDFLAGS)' >> $(1)/usr/bin/gcc_env.sh
  198. echo 'export CFLAGS=$(ENVCFLAGS)' >> $(1)/usr/bin/gcc_env.sh
  199. chmod +x $(1)/usr/bin/gcc_env.sh
  200. endef
  201. define Package/gcc/postinst
  202. #!/bin/sh
  203. $(INSTALL_STATIC_SPEC)
  204. endef
  205. define Package/gcc/postrm
  206. #!/bin/sh
  207. $(REMOVE_STATIC_SPEC)
  208. endef
  209. $(eval $(call BuildPackage,gcc))